Changeset View
Standalone View
src/ioslaves/ftp/ftp.h
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries | ||
---|---|---|---|---|---|
2 | Copyright (C) 2000 David Faure <faure@kde.org> | 2 | Copyright (C) 2000 David Faure <faure@kde.org> | ||
3 | Copyright (C) 2019 Harald Sitter <sitter@kde.org> | ||||
3 | 4 | | |||
4 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. | ||
8 | 9 | | |||
9 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 27 Lines | 35 | struct FtpEntry { | |||
38 | QString link; | 39 | QString link; | ||
39 | 40 | | |||
40 | KIO::filesize_t size; | 41 | KIO::filesize_t size; | ||
41 | mode_t type; | 42 | mode_t type; | ||
42 | mode_t access; | 43 | mode_t access; | ||
43 | QDateTime date; | 44 | QDateTime date; | ||
44 | }; | 45 | }; | ||
45 | 46 | | |||
47 | class FtpInternal; | ||||
48 | | ||||
49 | /** | ||||
50 | * Login Mode for ftpOpenConnection | ||||
51 | */ | ||||
52 | enum class LoginMode { | ||||
53 | Defered, | ||||
54 | Explicit, | ||||
55 | Implicit | ||||
56 | }; | ||||
57 | | ||||
58 | /** | ||||
59 | * Result type for returning error context. | ||||
60 | * | ||||
61 | * This is meant to be returned by functions that do not have a simple | ||||
62 | * error conditions that could be represented by returning a bool, or | ||||
63 | * when the contextual error string can only be correctly constructed | ||||
64 | * inside the function. When using the Result type always mark the | ||||
65 | * function Q_REQUIRED_RESULT to enforce handling of the Result. | ||||
66 | * | ||||
67 | * The Result is forwared all the way to the frontend API where it is | ||||
68 | * turned into an error() or finished() call. | ||||
69 | */ | ||||
70 | struct Result | ||||
dfaure: I think you can make all members const?
(This will prevent bypassing the "factory methods"...) | |||||
It's a good idea. Would that work though? Currently the results rely on the implicit move operator when collecting the returned result result = ftpGet() if the members are const we couldn't move/copy like that anymore. If we consider the mutability a problem I think I'd just make the members private and give them getters. I don't mind much either way. sitter: It's a good idea. Would that work though?
Currently the results rely on the implicit move… | |||||
Copying bool+int+QString seems rather cheap, we lived with that until C++11 move semantics ;-) Private members and inline getters sounds good to me. But yeah, no big deal, we can also trust the programmer :-) dfaure: Copying bool+int+QString seems rather cheap, we lived with that until C++11 move semantics ;-)… | |||||
71 | { | ||||
72 | bool success; | ||||
73 | int error; | ||||
74 | QString errorString; | ||||
75 | | ||||
76 | inline static Result fail(int _error = KIO::ERR_UNKNOWN, | ||||
77 | const QString &_errorString = QString()) | ||||
78 | { | ||||
79 | return Result { false, _error, _errorString }; | ||||
80 | } | ||||
81 | | ||||
82 | inline static Result pass() | ||||
83 | { | ||||
84 | return Result { true, 0, QString() }; | ||||
85 | } | ||||
86 | }; | ||||
87 | | ||||
88 | /** | ||||
89 | * Special Result composite for errors during connection. | ||||
90 | */ | ||||
91 | struct ConnectionResult | ||||
92 | { | ||||
93 | QTcpSocket *socket; | ||||
94 | Result result; | ||||
95 | }; | ||||
This class is an aggregate, so you could probably remove this ctor and use Result{...} syntax in the above three methods. dfaure: This class is an aggregate, so you could probably remove this ctor and use `Result{...}` syntax… | |||||
96 | | ||||
97 | QDebug operator<<(QDebug dbg, const Result &r); | ||||
98 | | ||||
46 | //=============================================================================== | 99 | //=============================================================================== | ||
47 | // Ftp | 100 | // Ftp | ||
101 | // The API class. This class should not contain *any* FTP logic. It acts | ||||
102 | // as a container for FtpInternal to prevent the latter from directly doing | ||||
103 | // state manipulation via error/finished/opened etc. | ||||
48 | //=============================================================================== | 104 | //=============================================================================== | ||
49 | class Ftp : public QObject, public KIO::SlaveBase | 105 | class Ftp : public KIO::SlaveBase | ||
anthonyfieroni: That's BIC we cannot remove, reorder nor insert parent(s) | |||||
This is a kioslave, built as plugin. There is no such thing as BC for this kind of stuff. pino: > That's BIC we cannot remove, reorder nor insert parent(s)
This is a kioslave, built as… | |||||
50 | { | 106 | { | ||
51 | Q_OBJECT | | |||
52 | | ||||
53 | public: | 107 | public: | ||
54 | Ftp(const QByteArray &pool, const QByteArray &app); | 108 | Ftp(const QByteArray &pool, const QByteArray &app); | ||
55 | virtual ~Ftp(); | 109 | ~Ftp() override; | ||
56 | 110 | | |||
57 | void setHost(const QString &host, quint16 port, const QString &user, const QString &pass) override; | 111 | void setHost(const QString &host, quint16 port, const QString &user, const QString &pass) override; | ||
58 | 112 | | |||
59 | /** | 113 | /** | ||
60 | * Connects to a ftp server and logs us in | 114 | * Connects to a ftp server and logs us in | ||
61 | * m_bLoggedOn is set to true if logging on was successful. | 115 | * m_bLoggedOn is set to true if logging on was successful. | ||
62 | * It is set to false if the connection becomes closed. | 116 | * It is set to false if the connection becomes closed. | ||
63 | * | 117 | * | ||
Show All 10 Lines | |||||
74 | void listDir(const QUrl &url) override; | 128 | void listDir(const QUrl &url) override; | ||
75 | void mkdir(const QUrl &url, int permissions) override; | 129 | void mkdir(const QUrl &url, int permissions) override; | ||
76 | void rename(const QUrl &src, const QUrl &dst, KIO::JobFlags flags) override; | 130 | void rename(const QUrl &src, const QUrl &dst, KIO::JobFlags flags) override; | ||
77 | void del(const QUrl &url, bool isfile) override; | 131 | void del(const QUrl &url, bool isfile) override; | ||
78 | void chmod(const QUrl &url, int permissions) override; | 132 | void chmod(const QUrl &url, int permissions) override; | ||
79 | 133 | | |||
80 | void get(const QUrl &url) override; | 134 | void get(const QUrl &url) override; | ||
81 | void put(const QUrl &url, int permissions, KIO::JobFlags flags) override; | 135 | void put(const QUrl &url, int permissions, KIO::JobFlags flags) override; | ||
82 | //virtual void mimetype( const QUrl& url ); | | |||
83 | 136 | | |||
84 | void slave_status() override; | 137 | void slave_status() override; | ||
85 | 138 | | |||
86 | /** | 139 | /** | ||
87 | * Handles the case that one side of the job is a local file | 140 | * Handles the case that one side of the job is a local file | ||
88 | */ | 141 | */ | ||
89 | void copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) override; | 142 | void copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) override; | ||
90 | 143 | | |||
91 | private: | 144 | private: | ||
92 | // ------------------------------------------------------------------------ | 145 | // WARNING: All members and all logic not confined to one of the public functions | ||
93 | // All the methods named ftpXyz are lowlevel methods that are not exported. | 146 | // must go into FtpInternal! | ||
94 | // The implement functionality used by the public high-level methods. Some | | |||
95 | // low-level methods still use error() to emit errors. This behaviour is not | | |||
96 | // recommended - please return a boolean status or an error code instead! | | |||
97 | // ------------------------------------------------------------------------ | | |||
98 | | ||||
99 | /** | | |||
100 | * Status Code returned from ftpPut() and ftpGet(), used to select | | |||
101 | * source or destination url for error messages | | |||
102 | */ | | |||
103 | typedef enum { | | |||
104 | statusSuccess, | | |||
105 | statusClientError, | | |||
106 | statusServerError | | |||
107 | } StatusCode; | | |||
108 | 147 | | |||
109 | /** | 148 | /** | ||
110 | * Login Mode for ftpOpenConnection | 149 | * Overridden to prevent FtpInternal from easily calling | ||
150 | * q->opened(). Use a Result return type on error conditions | ||||
151 | * instead. When there was no error Result the | ||||
152 | * connection is considered opened. | ||||
153 | * | ||||
dfaure: Does this method serve any purpose? | |||||
Its sole purpose is to make it harder to call q->finished() in the internal class (and that way bypass the result system). Same for error() above. sitter: Its sole purpose is to make it harder to call
`q->finished()` in the internal class (and that… | |||||
154 | * FtpInternal must not call any state-changing signals! | ||||
155 | */ | ||||
156 | void opened() | ||||
157 | { | ||||
158 | SlaveBase::opened(); | ||||
159 | } | ||||
160 | | ||||
161 | /** | ||||
162 | * @see opened() | ||||
163 | */ | ||||
164 | void error(int _errid, const QString &_text) | ||||
anthonyfieroni: Should be hidden? | |||||
sitter: Does that make a useful difference for a plugin? | |||||
165 | { | ||||
166 | SlaveBase::error(_errid, _text); | ||||
167 | } | ||||
168 | | ||||
169 | /** | ||||
170 | * @see opened() | ||||
171 | */ | ||||
172 | void finished() | ||||
173 | { | ||||
174 | SlaveBase::finished(); | ||||
175 | } | ||||
176 | | ||||
177 | /** | ||||
178 | * Calls finished() or error() as appropriate | ||||
179 | */ | ||||
180 | void finalize(const Result &result); | ||||
181 | | ||||
182 | QScopedPointer<FtpInternal> d; | ||||
183 | }; | ||||
184 | | ||||
185 | /** | ||||
186 | * Internal logic class. | ||||
187 | * | ||||
188 | * This class implements strict separation between the API (Ftp) and | ||||
189 | * the logic behind the API (FtpInternal). This class' functions | ||||
190 | * are meant to return Result objects up the call stack to Ftp where | ||||
191 | * they will be turned into command results (e.g. error(), | ||||
192 | * finished(), etc.). This class cannot and must not call these signals | ||||
193 | * directly as it leads to unclear states. | ||||
194 | */ | ||||
195 | class FtpInternal : public QObject | ||||
196 | { | ||||
197 | Q_OBJECT | ||||
198 | public: | ||||
199 | explicit FtpInternal(Ftp *qptr); | ||||
200 | ~FtpInternal(); | ||||
201 | | ||||
202 | // ---------------------------------------- API | ||||
203 | | ||||
204 | void setHost(const QString &host, quint16 port, const QString &user, const QString &pass); | ||||
205 | | ||||
206 | /** | ||||
207 | * Connects to a ftp server and logs us in | ||||
208 | * m_bLoggedOn is set to true if logging on was successful. | ||||
209 | * It is set to false if the connection becomes closed. | ||||
210 | * | ||||
111 | */ | 211 | */ | ||
112 | typedef enum { | 212 | Result openConnection() Q_REQUIRED_RESULT; | ||
113 | loginDefered, | 213 | | ||
114 | loginExplicit, | 214 | /** | ||
115 | loginImplicit | 215 | * Closes the connection | ||
116 | } LoginMode; | 216 | */ | ||
217 | void closeConnection(); | ||||
218 | | ||||
219 | Result stat(const QUrl &url) Q_REQUIRED_RESULT; | ||||
220 | | ||||
221 | Result listDir(const QUrl &url); | ||||
222 | Result mkdir(const QUrl &url, int permissions) Q_REQUIRED_RESULT; | ||||
223 | Result rename(const QUrl &src, const QUrl &dst, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||||
224 | Result del(const QUrl &url, bool isfile) Q_REQUIRED_RESULT; | ||||
225 | Result chmod(const QUrl &url, int permissions) Q_REQUIRED_RESULT; | ||||
226 | | ||||
227 | Result get(const QUrl &url) Q_REQUIRED_RESULT; | ||||
228 | Result put(const QUrl &url, int permissions, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||||
229 | //virtual void mimetype( const QUrl& url ); | ||||
230 | | ||||
231 | void slave_status(); | ||||
232 | | ||||
233 | /** | ||||
234 | * Handles the case that one side of the job is a local file | ||||
235 | */ | ||||
236 | Result copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||||
237 | | ||||
238 | // ---------------------------------------- END API | ||||
239 | | ||||
240 | static bool isSocksProxyScheme(const QString &scheme); | ||||
241 | bool isSocksProxy() const; | ||||
117 | 242 | | |||
118 | /** | 243 | /** | ||
119 | * Connect and login to the FTP server. | 244 | * Connect and login to the FTP server. | ||
120 | * | 245 | * | ||
121 | * @param loginMode controls if login info should be sent<br> | 246 | * @param loginMode controls if login info should be sent<br> | ||
122 | * loginDefered - must not be logged on, no login info is sent<br> | 247 | * loginDefered - must not be logged on, no login info is sent<br> | ||
123 | * loginExplicit - must not be logged on, login info is sent<br> | 248 | * loginExplicit - must not be logged on, login info is sent<br> | ||
124 | * loginImplicit - login info is sent if not logged on | 249 | * loginImplicit - login info is sent if not logged on | ||
125 | * | 250 | * | ||
126 | * @return true on success (a login failure would return false). | 251 | * @return true on success (a login failure would return false). | ||
127 | */ | 252 | */ | ||
128 | bool ftpOpenConnection(LoginMode loginMode); | 253 | Result ftpOpenConnection(LoginMode loginMode) Q_REQUIRED_RESULT; | ||
129 | 254 | | |||
130 | /** | 255 | /** | ||
131 | * Executes any auto login macro's as specified in a .netrc file. | 256 | * Executes any auto login macro's as specified in a .netrc file. | ||
132 | */ | 257 | */ | ||
133 | void ftpAutoLoginMacro(); | 258 | void ftpAutoLoginMacro(); | ||
134 | 259 | | |||
135 | /** | 260 | /** | ||
136 | * Called by openConnection. It logs us in. | 261 | * Called by openConnection. It logs us in. | ||
137 | * m_initialPath is set to the current working directory | 262 | * m_initialPath is set to the current working directory | ||
138 | * if logging on was successful. | 263 | * if logging on was successful. | ||
139 | * | 264 | * | ||
140 | * @param userChanged if not nullptr, will be set to true if the user name | 265 | * @param userChanged if not nullptr, will be set to true if the user name | ||
141 | * was changed during login. | 266 | * was changed during login. | ||
142 | * @return true on success. | 267 | * @return true on success. | ||
143 | */ | 268 | */ | ||
144 | bool ftpLogin(bool *userChanged = nullptr); | 269 | Result ftpLogin(bool *userChanged = nullptr) Q_REQUIRED_RESULT; | ||
145 | 270 | | |||
146 | /** | 271 | /** | ||
147 | * ftpSendCmd - send a command (@p cmd) and read response | 272 | * ftpSendCmd - send a command (@p cmd) and read response | ||
148 | * | 273 | * | ||
149 | * @param maxretries number of time it should retry. Since it recursively | 274 | * @param maxretries number of time it should retry. Since it recursively | ||
150 | * calls itself if it can't read the answer (this happens especially after | 275 | * calls itself if it can't read the answer (this happens especially after | ||
151 | * timeouts), we need to limit the recursiveness ;-) | 276 | * timeouts), we need to limit the recursiveness ;-) | ||
152 | * | 277 | * | ||
153 | * return true if any response received, false on error | 278 | * return true if any response received, false on error | ||
154 | */ | 279 | */ | ||
155 | bool ftpSendCmd(const QByteArray &cmd, int maxretries = 1); | 280 | bool ftpSendCmd(const QByteArray &cmd, int maxretries = 1) Q_REQUIRED_RESULT; | ||
156 | 281 | | |||
157 | /** | 282 | /** | ||
158 | * Use the SIZE command to get the file size. | 283 | * Use the SIZE command to get the file size. | ||
159 | * @param mode the size depends on the transfer mode, hence this arg. | 284 | * @param mode the size depends on the transfer mode, hence this arg. | ||
160 | * @return true on success | 285 | * @return true on success | ||
161 | * Gets the size into m_size. | 286 | * Gets the size into m_size. | ||
162 | */ | 287 | */ | ||
163 | bool ftpSize(const QString &path, char mode); | 288 | bool ftpSize(const QString &path, char mode); | ||
164 | 289 | | |||
165 | /** | 290 | /** | ||
166 | * Returns true if the file exists. | 291 | * Returns true if the file exists. | ||
167 | * Implemented using the SIZE command. | 292 | * Implemented using the SIZE command. | ||
168 | */ | 293 | */ | ||
169 | bool ftpFileExists(const QString &path); | 294 | bool ftpFileExists(const QString &path); | ||
170 | 295 | | |||
171 | /** | 296 | /** | ||
172 | * Set the current working directory, but only if not yet current | 297 | * Set the current working directory, but only if not yet current | ||
173 | */ | 298 | */ | ||
174 | bool ftpFolder(const QString &path, bool bReportError); | 299 | bool ftpFolder(const QString &path) Q_REQUIRED_RESULT; | ||
175 | 300 | | |||
176 | /** | 301 | /** | ||
177 | * Runs a command on the ftp server like "list" or "retr". In contrast to | 302 | * Runs a command on the ftp server like "list" or "retr". In contrast to | ||
178 | * ftpSendCmd a data connection is opened. The corresponding socket | 303 | * ftpSendCmd a data connection is opened. The corresponding socket | ||
179 | * sData is available for reading/writing on success. | 304 | * sData is available for reading/writing on success. | ||
180 | * The connection must be closed afterwards with ftpCloseCommand. | 305 | * The connection must be closed afterwards with ftpCloseCommand. | ||
181 | * | 306 | * | ||
182 | * @param mode is 'A' or 'I'. 'A' means ASCII transfer, 'I' means binary transfer. | 307 | * @param mode is 'A' or 'I'. 'A' means ASCII transfer, 'I' means binary transfer. | ||
183 | * @param errorcode the command-dependent error code to emit on error | 308 | * @param errorcode the command-dependent error code to emit on error | ||
184 | * | 309 | * | ||
185 | * @return true if the command was accepted by the server. | 310 | * @return true if the command was accepted by the server. | ||
186 | */ | 311 | */ | ||
187 | bool ftpOpenCommand(const char *command, const QString &path, char mode, | 312 | Result ftpOpenCommand(const char *command, const QString &path, char mode, | ||
188 | int errorcode, KIO::fileoffset_t offset = 0); | 313 | int errorcode, KIO::fileoffset_t offset = 0) Q_REQUIRED_RESULT; | ||
189 | 314 | | |||
190 | /** | 315 | /** | ||
191 | * The counterpart to openCommand. | 316 | * The counterpart to openCommand. | ||
192 | * Closes data sockets and then reads line sent by server at | 317 | * Closes data sockets and then reads line sent by server at | ||
193 | * end of command. | 318 | * end of command. | ||
194 | * @return false on error (line doesn't start with '2') | 319 | * @return false on error (line doesn't start with '2') | ||
195 | */ | 320 | */ | ||
196 | bool ftpCloseCommand(); | 321 | bool ftpCloseCommand(); | ||
Show All 29 Lines | |||||
226 | /** | 351 | /** | ||
227 | * Helper for ftpOpenDataConnection | 352 | * Helper for ftpOpenDataConnection | ||
228 | */ | 353 | */ | ||
229 | int ftpOpenPortDataConnection(); | 354 | int ftpOpenPortDataConnection(); | ||
230 | 355 | | |||
231 | bool ftpChmod(const QString &path, int permissions); | 356 | bool ftpChmod(const QString &path, int permissions); | ||
232 | 357 | | |||
233 | // used by listDir | 358 | // used by listDir | ||
234 | bool ftpOpenDir(const QString &path); | 359 | Result ftpOpenDir(const QString &path) Q_REQUIRED_RESULT; | ||
235 | /** | 360 | /** | ||
236 | * Called to parse directory listings, call this until it returns false | 361 | * Called to parse directory listings, call this until it returns false | ||
237 | */ | 362 | */ | ||
238 | bool ftpReadDir(FtpEntry &ftpEnt); | 363 | bool ftpReadDir(FtpEntry &ftpEnt); | ||
239 | 364 | | |||
240 | /** | 365 | /** | ||
241 | * Helper to fill an UDSEntry | 366 | * Helper to fill an UDSEntry | ||
242 | */ | 367 | */ | ||
243 | void ftpCreateUDSEntry(const QString &filename, const FtpEntry &ftpEnt, KIO::UDSEntry &entry, bool isDir); | 368 | void ftpCreateUDSEntry(const QString &filename, const FtpEntry &ftpEnt, KIO::UDSEntry &entry, bool isDir); | ||
244 | 369 | | |||
245 | void ftpShortStatAnswer(const QString &filename, bool isDir); | 370 | void ftpShortStatAnswer(const QString &filename, bool isDir); | ||
dfaure: Q_REQUIRED_RESULT on a method returning void?? | |||||
246 | 371 | | |||
247 | void ftpStatAnswerNotFound(const QString &path, const QString &filename); | 372 | Result ftpStatAnswerNotFound(const QString &path, const QString &filename) Q_REQUIRED_RESULT; | ||
248 | 373 | | |||
249 | /** | 374 | /** | ||
250 | * This is the internal implementation of rename() - set put(). | 375 | * This is the internal implementation of rename() - set put(). | ||
251 | * | 376 | * | ||
252 | * @return true on success. | 377 | * @return true on success. | ||
253 | */ | 378 | */ | ||
254 | bool ftpRename(const QString &src, const QString &dst, KIO::JobFlags flags); | 379 | Result ftpRename(const QString &src, const QString &dst, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||
255 | 380 | | |||
256 | /** | 381 | /** | ||
257 | * Called by openConnection. It opens the control connection to the ftp server. | 382 | * Called by openConnection. It opens the control connection to the ftp server. | ||
258 | * | 383 | * | ||
259 | * @return true on success. | 384 | * @return true on success. | ||
260 | */ | 385 | */ | ||
261 | bool ftpOpenControlConnection(); | 386 | Result ftpOpenControlConnection() Q_REQUIRED_RESULT; | ||
262 | bool ftpOpenControlConnection(const QString &host, int port); | 387 | Result ftpOpenControlConnection(const QString &host, int port) Q_REQUIRED_RESULT; | ||
263 | 388 | | |||
264 | /** | 389 | /** | ||
265 | * closes the socket holding the control connection (see ftpOpenControlConnection) | 390 | * closes the socket holding the control connection (see ftpOpenControlConnection) | ||
266 | */ | 391 | */ | ||
267 | void ftpCloseControlConnection(); | 392 | void ftpCloseControlConnection(); | ||
268 | 393 | | |||
269 | /** | 394 | /** | ||
270 | * read a response from the server (a trailing CR gets stripped) | 395 | * read a response from the server (a trailing CR gets stripped) | ||
Show All 11 Lines | |||||
282 | * IMPORTANT: the caller should call ftpCloseCommand() on return. | 407 | * IMPORTANT: the caller should call ftpCloseCommand() on return. | ||
283 | * The function does not call error(), the caller should do this. | 408 | * The function does not call error(), the caller should do this. | ||
284 | * | 409 | * | ||
285 | * @param iError set to an ERR_xxxx code on error | 410 | * @param iError set to an ERR_xxxx code on error | ||
286 | * @param iCopyFile -1 -or- handle of a local destination file | 411 | * @param iCopyFile -1 -or- handle of a local destination file | ||
287 | * @param hCopyOffset local file only: non-zero for resume | 412 | * @param hCopyOffset local file only: non-zero for resume | ||
288 | * @return 0 for success, -1 for server error, -2 for client error | 413 | * @return 0 for success, -1 for server error, -2 for client error | ||
289 | */ | 414 | */ | ||
290 | StatusCode ftpGet(int &iError, int iCopyFile, const QUrl &url, KIO::fileoffset_t hCopyOffset); | 415 | Result ftpGet(int iCopyFile, const QString &sCopyFile, const QUrl &url, KIO::fileoffset_t hCopyOffset) Q_REQUIRED_RESULT; | ||
291 | 416 | | |||
292 | /** | 417 | /** | ||
293 | * This is the internal implementation of put() - see copy(). | 418 | * This is the internal implementation of put() - see copy(). | ||
294 | * | 419 | * | ||
295 | * IMPORTANT: the caller should call ftpCloseCommand() on return. | 420 | * IMPORTANT: the caller should call ftpCloseCommand() on return. | ||
296 | * The function does not call error(), the caller should do this. | 421 | * The function does not call error(), the caller should do this. | ||
297 | * | 422 | * | ||
298 | * @param iError set to an ERR_xxxx code on error | 423 | * @param iError set to an ERR_xxxx code on error | ||
299 | * @param iCopyFile -1 -or- handle of a local source file | 424 | * @param iCopyFile -1 -or- handle of a local source file | ||
300 | * @return 0 for success, -1 for server error, -2 for client error | 425 | * @return 0 for success, -1 for server error, -2 for client error | ||
301 | */ | 426 | */ | ||
302 | StatusCode ftpPut(int &iError, int iCopyFile, const QUrl &url, int permissions, KIO::JobFlags flags); | 427 | Result ftpPut(int iCopyFile, const QUrl &url, int permissions, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||
303 | 428 | | |||
304 | /** | 429 | /** | ||
305 | * helper called from copy() to implement FILE -> FTP transfers | 430 | * helper called from copy() to implement FILE -> FTP transfers | ||
306 | * | 431 | * | ||
307 | * @param iError set to an ERR_xxxx code on error | 432 | * @param iError set to an ERR_xxxx code on error | ||
308 | * @param iCopyFile [out] handle of a local source file | 433 | * @param iCopyFile [out] handle of a local source file | ||
309 | * @param sCopyFile path of the local source file | 434 | * @param sCopyFile path of the local source file | ||
310 | * @return 0 for success, -1 for server error, -2 for client error | 435 | * @return 0 for success, -1 for server error, -2 for client error | ||
311 | */ | 436 | */ | ||
312 | StatusCode ftpCopyPut(int &iError, int &iCopyFile, const QString &sCopyFile, const QUrl &url, int permissions, KIO::JobFlags flags); | 437 | Result ftpCopyPut(int &iCopyFile, const QString &sCopyFile, const QUrl &url, int permissions, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||
313 | 438 | | |||
314 | /** | 439 | /** | ||
315 | * helper called from copy() to implement FTP -> FILE transfers | 440 | * helper called from copy() to implement FTP -> FILE transfers | ||
316 | * | 441 | * | ||
317 | * @param iError set to an ERR_xxxx code on error | 442 | * @param iError set to an ERR_xxxx code on error | ||
318 | * @param iCopyFile [out] handle of a local source file | 443 | * @param iCopyFile [out] handle of a local source file | ||
319 | * @param sCopyFile path of the local destination file | 444 | * @param sCopyFile path of the local destination file | ||
320 | * @return 0 for success, -1 for server error, -2 for client error | 445 | * @return 0 for success, -1 for server error, -2 for client error | ||
321 | */ | 446 | */ | ||
322 | StatusCode ftpCopyGet(int &iError, int &iCopyFile, const QString &sCopyFile, const QUrl &url, int permissions, KIO::JobFlags flags); | 447 | Result ftpCopyGet(int &iCopyFile, const QString &sCopyFile, const QUrl &url, int permissions, KIO::JobFlags flags) Q_REQUIRED_RESULT; | ||
323 | 448 | | |||
324 | /** | 449 | /** | ||
325 | * Sends the mime type of the content to retrieved. | 450 | * Sends the mime type of the content to retrieved. | ||
326 | * | 451 | * | ||
327 | * @param iError set to an ERR_xxxx code on error | 452 | * @param iError set to an ERR_xxxx code on error | ||
328 | * @return 0 for success, -1 for server error, -2 for client error | 453 | * @return 0 for success, -1 for server error, -2 for client error | ||
329 | */ | 454 | */ | ||
330 | StatusCode ftpSendMimeType(int &iError, const QUrl &url); | 455 | Result ftpSendMimeType(const QUrl &url) Q_REQUIRED_RESULT; | ||
331 | 456 | | |||
332 | /** | 457 | /** | ||
333 | * Fixes up an entry name so that extraneous whitespaces do not cause | 458 | * Fixes up an entry name so that extraneous whitespaces do not cause | ||
334 | * problems. See bug# 88575 and bug# 300988. | 459 | * problems. See bug# 88575 and bug# 300988. | ||
335 | */ | 460 | */ | ||
336 | void fixupEntryName(FtpEntry *ftpEnt); | 461 | void fixupEntryName(FtpEntry *ftpEnt); | ||
337 | 462 | | |||
338 | /** | 463 | /** | ||
339 | * Calls @ref statEntry. | 464 | * Calls @ref statEntry. | ||
340 | */ | 465 | */ | ||
341 | bool maybeEmitStatEntry(FtpEntry &ftpEnt, const QString &search, const QString &filename, bool isDir); | 466 | bool maybeEmitStatEntry(FtpEntry &ftpEnt, const QString &search, const QString &filename, bool isDir); | ||
342 | 467 | | |||
343 | /** | 468 | /** | ||
344 | * Setup the connection to the server | 469 | * Setup the connection to the server. | ||
345 | */ | 470 | */ | ||
346 | QTcpSocket *synchronousConnectToHost(const QString &host, quint16 port); | 471 | ConnectionResult synchronousConnectToHost(const QString &host, quint16 port) Q_REQUIRED_RESULT; | ||
347 | | ||||
348 | private Q_SLOTS: | | |||
349 | void proxyAuthentication(const QNetworkProxy &, QAuthenticator *); | | |||
350 | void saveProxyAuthentication(); | | |||
351 | 472 | | |||
352 | private: // data members | 473 | private: // data members | ||
474 | Ftp *const q; | ||||
353 | 475 | | |||
354 | QString m_host; | 476 | QString m_host; | ||
355 | int m_port; | 477 | int m_port = 0; | ||
356 | QString m_user; | 478 | QString m_user; | ||
357 | QString m_pass; | 479 | QString m_pass; | ||
358 | /** | 480 | /** | ||
359 | * Where we end up after connecting | 481 | * Where we end up after connecting | ||
360 | */ | 482 | */ | ||
361 | QString m_initialPath; | 483 | QString m_initialPath; | ||
362 | QUrl m_proxyURL; | 484 | QUrl m_proxyURL; | ||
363 | QStringList m_proxyUrls; | 485 | QStringList m_proxyUrls; | ||
364 | 486 | | |||
365 | /** | 487 | /** | ||
366 | * the current working directory - see ftpFolder | 488 | * the current working directory - see ftpFolder | ||
367 | */ | 489 | */ | ||
368 | QString m_currentPath; | 490 | QString m_currentPath; | ||
369 | 491 | | |||
370 | /** | 492 | /** | ||
371 | * the status returned by the FTP protocol, set in ftpResponse() | 493 | * the status returned by the FTP protocol, set in ftpResponse() | ||
372 | */ | 494 | */ | ||
373 | int m_iRespCode; | 495 | int m_iRespCode = 0; | ||
374 | 496 | | |||
375 | /** | 497 | /** | ||
376 | * the status/100 returned by the FTP protocol, set in ftpResponse() | 498 | * the status/100 returned by the FTP protocol, set in ftpResponse() | ||
377 | */ | 499 | */ | ||
378 | int m_iRespType; | 500 | int m_iRespType = 0; | ||
379 | 501 | | |||
380 | /** | 502 | /** | ||
381 | * This flag is maintained by ftpDataMode() and contains I or A after | 503 | * This flag is maintained by ftpDataMode() and contains I or A after | ||
382 | * ftpDataMode() has successfully set the mode. | 504 | * ftpDataMode() has successfully set the mode. | ||
383 | */ | 505 | */ | ||
384 | char m_cDataMode; | 506 | char m_cDataMode; | ||
385 | 507 | | |||
386 | /** | 508 | /** | ||
Show All 32 Lines | 536 | enum { | |||
419 | pasvUnknown = 0x20, | 541 | pasvUnknown = 0x20, | ||
420 | chmodUnknown = 0x100 | 542 | chmodUnknown = 0x100 | ||
421 | }; | 543 | }; | ||
422 | int m_extControl; | 544 | int m_extControl; | ||
423 | 545 | | |||
424 | /** | 546 | /** | ||
425 | * control connection socket, only set if openControl() succeeded | 547 | * control connection socket, only set if openControl() succeeded | ||
426 | */ | 548 | */ | ||
427 | QTcpSocket *m_control; | 549 | QTcpSocket *m_control = nullptr; | ||
428 | QByteArray m_lastControlLine; | 550 | QByteArray m_lastControlLine; | ||
429 | 551 | | |||
430 | /** | 552 | /** | ||
431 | * data connection socket | 553 | * data connection socket | ||
432 | */ | 554 | */ | ||
433 | QTcpSocket *m_data; | 555 | QTcpSocket *m_data = nullptr; | ||
434 | 556 | | |||
435 | /** | 557 | /** | ||
436 | * active mode server socket | 558 | * active mode server socket | ||
437 | */ | 559 | */ | ||
438 | QTcpServer *m_server; | 560 | QTcpServer *m_server = nullptr; | ||
439 | | ||||
440 | /** | | |||
441 | * proxy server authenticator | | |||
442 | */ | | |||
443 | QAuthenticator *m_socketProxyAuth; | | |||
444 | }; | 561 | }; | ||
445 | 562 | | |||
563 | | ||||
446 | #endif // KDELIBS_FTP_H | 564 | #endif // KDELIBS_FTP_H | ||
447 | 565 | |
I think you can make all members const?
(This will prevent bypassing the "factory methods"...)