| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | #include "gate/net/ftpclients.hpp" | ||
| 29 | |||
| 30 | namespace gate | ||
| 31 | { | ||
| 32 | namespace net | ||
| 33 | { | ||
| 34 | |||
| 35 | enumint_t const FtpClient::Flag_Passive = GATE_FTPCLIENT_FLAG_PASSIVE; | ||
| 36 | |||
| 37 | 1 | FtpClient::FtpClient(String const& server, uint16_t port, String const& user, String const& password, enumint_t flags) | |
| 38 | { | ||
| 39 | 1 | result_t result = gate_ftpclient_create(&this->impl, server.c_impl(), port, user.c_impl(), password.c_impl(), flags); | |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 41 | 1 | } | |
| 42 | |||
| 43 | 2 | FtpClient::~FtpClient() noexcept | |
| 44 | { | ||
| 45 | 1 | gate_ftpclient_release(&this->impl); | |
| 46 | 1 | } | |
| 47 | |||
| 48 | struct GATE_API_LOCAL FtpClient_listDirectoryParam | ||
| 49 | { | ||
| 50 | FtpClient::ListCallback* callback; | ||
| 51 | void* param; | ||
| 52 | }; | ||
| 53 | |||
| 54 | ✗ | static gate_bool_t FtpClient_listDirectory_Callback(gate_file_entry_t const* entry, void* userparam) | |
| 55 | { | ||
| 56 | ✗ | FtpClient_listDirectoryParam* param = static_cast<FtpClient_listDirectoryParam*>(userparam); | |
| 57 | ✗ | FtpClient::Entry ftpEntry(*entry); | |
| 58 | try | ||
| 59 | { | ||
| 60 | ✗ | param->callback->invoke(&ftpEntry, userparam); | |
| 61 | ✗ | return true; | |
| 62 | } | ||
| 63 | ✗ | catch (...) | |
| 64 | { | ||
| 65 | ✗ | return false; | |
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | ✗ | void FtpClient::listDirectory(String const& path, ListCallback& callback, void* userParam) | |
| 70 | { | ||
| 71 | FtpClient_listDirectoryParam ftpParam; | ||
| 72 | ✗ | ftpParam.callback = &callback; | |
| 73 | ✗ | ftpParam.param = userParam; | |
| 74 | ✗ | result_t result = gate_ftpclient_list_files(&this->impl, path.c_impl(), &FtpClient_listDirectory_Callback, &ftpParam); | |
| 75 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 76 | ✗ | } | |
| 77 | |||
| 78 | 16 | static gate_bool_t FtpClient_listDirectory_Callback2(gate_file_entry_t const* entry, void* userparam) | |
| 79 | { | ||
| 80 | 16 | Map<String, FtpClient::Properties>* param = static_cast<Map<String, FtpClient::Properties>*>(userparam); | |
| 81 | |||
| 82 | try | ||
| 83 | { | ||
| 84 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
32 | String entryPath(entry->path); |
| 85 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | FtpClient::Properties entryProps(entry->props); |
| 86 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | param->add(entryPath, entryProps); |
| 87 | 16 | return true; | |
| 88 | } | ||
| 89 | ✗ | catch (...) | |
| 90 | { | ||
| 91 | ✗ | return false; | |
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | 1 | Map<String, FtpClient::Properties> FtpClient::listDirectory(String const& path) | |
| 96 | { | ||
| 97 | 1 | Map<String, FtpClient::Properties> ret; | |
| 98 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_ftpclient_list_files(&this->impl, path.c_impl(), &FtpClient_listDirectory_Callback2, &ret); |
| 99 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 100 | 1 | return ret; | |
| 101 | } | ||
| 102 | ✗ | void FtpClient::createDirectory(String const& parentPath, String const& newDirName) | |
| 103 | { | ||
| 104 | ✗ | result_t result = gate_ftpclient_create_directory(&this->impl, parentPath.c_impl(), newDirName.c_impl()); | |
| 105 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 106 | ✗ | } | |
| 107 | ✗ | void FtpClient::deleteDirectory(String const& path) | |
| 108 | { | ||
| 109 | ✗ | result_t result = gate_ftpclient_delete_directory(&this->impl, path.c_impl()); | |
| 110 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 111 | ✗ | } | |
| 112 | ✗ | void FtpClient::deleteFile(String const& path) | |
| 113 | { | ||
| 114 | ✗ | result_t result = gate_ftpclient_delete_file(&this->impl, path.c_impl()); | |
| 115 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 116 | ✗ | } | |
| 117 | ✗ | void FtpClient::rename(String const& oldPath, String const& newPath) | |
| 118 | { | ||
| 119 | ✗ | result_t result = gate_ftpclient_rename(&this->impl, oldPath.c_impl(), newPath.c_impl()); | |
| 120 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 121 | ✗ | } | |
| 122 | 1 | String FtpClient::getCurrentDirectory() | |
| 123 | { | ||
| 124 | 1 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 125 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ftpclient_get_current_directory(&this->impl, &tmp); |
| 126 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 127 | 2 | return String::createFrom(tmp); | |
| 128 | } | ||
| 129 | ✗ | void FtpClient::setCurrentDirectory(String const& path) | |
| 130 | { | ||
| 131 | ✗ | result_t result = gate_ftpclient_set_current_directory(&this->impl, path.c_impl()); | |
| 132 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 133 | ✗ | } | |
| 134 | |||
| 135 | ✗ | Stream FtpClient::openStream(String const& path, uint32_t openFlags) | |
| 136 | { | ||
| 137 | ✗ | gate_stream_t* ptrStream = NULL; | |
| 138 | ✗ | result_t result = gate_ftpclient_open_stream(&this->impl, path.c_impl(), openFlags, &ptrStream); | |
| 139 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 140 | ✗ | return Stream(ptrStream); | |
| 141 | } | ||
| 142 | ✗ | void FtpClient::upload(Stream& sourceStream, String const& destinationPath) | |
| 143 | { | ||
| 144 | ✗ | result_t result = gate_ftpclient_upload(&this->impl, sourceStream.c_impl(), destinationPath.c_impl()); | |
| 145 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 146 | ✗ | } | |
| 147 | ✗ | void FtpClient::uploadFile(String const& localFilePath, String const& destinationPath) | |
| 148 | { | ||
| 149 | ✗ | result_t result = gate_ftpclient_upload_file(&this->impl, localFilePath.c_impl(), destinationPath.c_impl()); | |
| 150 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 151 | ✗ | } | |
| 152 | 1 | void FtpClient::download(String const& sourcePath, Stream& downloadTo) | |
| 153 | { | ||
| 154 | 1 | result_t result = gate_ftpclient_download(&this->impl, sourcePath.c_impl(), downloadTo.c_impl()); | |
| 155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 156 | 1 | } | |
| 157 | ✗ | void FtpClient::downloadFile(String const& sourcePath, String const& downloadToFilePath) | |
| 158 | { | ||
| 159 | ✗ | result_t result = gate_ftpclient_download_file(&this->impl, sourcePath.c_impl(), downloadToFilePath.c_impl()); | |
| 160 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 161 | ✗ | } | |
| 162 | |||
| 163 | |||
| 164 | } // end of namespace net | ||
| 165 | } // end of namespace gate | ||
| 166 |