| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, 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 GATE_CALL 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 | ✗ | ExceptionInfo xcptInfo; | |
| 59 | ✗ | GATEXX_TRY_CATCHINFO(xcptInfo, { | |
| 60 | param->callback->invoke(&ftpEntry, userparam); | ||
| 61 | }); | ||
| 62 | ✗ | return xcptInfo.succeeded(); | |
| 63 | } | ||
| 64 | |||
| 65 | ✗ | void FtpClient::listDirectory(String const& path, ListCallback& callback, void* userParam) | |
| 66 | { | ||
| 67 | FtpClient_listDirectoryParam ftpParam; | ||
| 68 | ✗ | ftpParam.callback = &callback; | |
| 69 | ✗ | ftpParam.param = userParam; | |
| 70 | ✗ | result_t result = gate_ftpclient_list_files(&this->impl, path.c_impl(), &FtpClient_listDirectory_Callback, &ftpParam); | |
| 71 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 72 | ✗ | } | |
| 73 | |||
| 74 | 16 | static gate_bool_t GATE_CALL FtpClient_listDirectory_Callback2(gate_file_entry_t const* entry, void* userparam) | |
| 75 | { | ||
| 76 | 16 | Map<String, FtpClient::Properties>* param = static_cast<Map<String, FtpClient::Properties>*>(userparam); | |
| 77 | |||
| 78 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | ExceptionInfo xcptInfo; |
| 79 |
4/12✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
16 | GATEXX_TRY_CATCHINFO(xcptInfo, { |
| 80 | String entryPath(entry->path); | ||
| 81 | FtpClient::Properties entryProps(entry->props); | ||
| 82 | param->add(entryPath, entryProps); | ||
| 83 | }); | ||
| 84 | 32 | return xcptInfo.succeeded(); | |
| 85 | } | ||
| 86 | |||
| 87 | 1 | Map<String, FtpClient::Properties> FtpClient::listDirectory(String const& path) | |
| 88 | { | ||
| 89 | 1 | Map<String, FtpClient::Properties> ret; | |
| 90 |
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); |
| 91 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 92 | 1 | return ret; | |
| 93 | } | ||
| 94 | ✗ | void FtpClient::createDirectory(String const& parentPath, String const& newDirName) | |
| 95 | { | ||
| 96 | ✗ | result_t result = gate_ftpclient_create_directory(&this->impl, parentPath.c_impl(), newDirName.c_impl()); | |
| 97 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 98 | ✗ | } | |
| 99 | ✗ | void FtpClient::deleteDirectory(String const& path) | |
| 100 | { | ||
| 101 | ✗ | result_t result = gate_ftpclient_delete_directory(&this->impl, path.c_impl()); | |
| 102 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 103 | ✗ | } | |
| 104 | ✗ | void FtpClient::deleteFile(String const& path) | |
| 105 | { | ||
| 106 | ✗ | result_t result = gate_ftpclient_delete_file(&this->impl, path.c_impl()); | |
| 107 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 108 | ✗ | } | |
| 109 | ✗ | void FtpClient::rename(String const& oldPath, String const& newPath) | |
| 110 | { | ||
| 111 | ✗ | result_t result = gate_ftpclient_rename(&this->impl, oldPath.c_impl(), newPath.c_impl()); | |
| 112 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 113 | ✗ | } | |
| 114 | 1 | String FtpClient::getCurrentDirectory() | |
| 115 | { | ||
| 116 | 1 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 117 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ftpclient_get_current_directory(&this->impl, &tmp); |
| 118 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 119 | 2 | return String::createFrom(tmp); | |
| 120 | } | ||
| 121 | ✗ | void FtpClient::setCurrentDirectory(String const& path) | |
| 122 | { | ||
| 123 | ✗ | result_t result = gate_ftpclient_set_current_directory(&this->impl, path.c_impl()); | |
| 124 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 125 | ✗ | } | |
| 126 | |||
| 127 | ✗ | Stream FtpClient::openStream(String const& path, uint32_t openFlags) | |
| 128 | { | ||
| 129 | ✗ | gate_stream_t* ptrStream = NULL; | |
| 130 | ✗ | result_t result = gate_ftpclient_open_stream(&this->impl, path.c_impl(), openFlags, &ptrStream); | |
| 131 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 132 | ✗ | return Stream(ptrStream); | |
| 133 | } | ||
| 134 | ✗ | void FtpClient::upload(Stream& sourceStream, String const& destinationPath) | |
| 135 | { | ||
| 136 | ✗ | result_t result = gate_ftpclient_upload(&this->impl, sourceStream.c_impl(), destinationPath.c_impl()); | |
| 137 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 138 | ✗ | } | |
| 139 | ✗ | void FtpClient::uploadFile(String const& localFilePath, String const& destinationPath) | |
| 140 | { | ||
| 141 | ✗ | result_t result = gate_ftpclient_upload_file(&this->impl, localFilePath.c_impl(), destinationPath.c_impl()); | |
| 142 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 143 | ✗ | } | |
| 144 | 1 | void FtpClient::download(String const& sourcePath, Stream& downloadTo) | |
| 145 | { | ||
| 146 | 1 | result_t result = gate_ftpclient_download(&this->impl, sourcePath.c_impl(), downloadTo.c_impl()); | |
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 148 | 1 | } | |
| 149 | ✗ | void FtpClient::downloadFile(String const& sourcePath, String const& downloadToFilePath) | |
| 150 | { | ||
| 151 | ✗ | result_t result = gate_ftpclient_download_file(&this->impl, sourcePath.c_impl(), downloadToFilePath.c_impl()); | |
| 152 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 153 | ✗ | } | |
| 154 | |||
| 155 | |||
| 156 | } // end of namespace net | ||
| 157 | } // end of namespace gate | ||
| 158 |