Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | class QFtpPI; | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | class QFtpDTP : public QObject | - |
14 | { | - |
15 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
16 | | - |
17 | public: | - |
18 | enum ConnectState { | - |
19 | CsHostFound, | - |
20 | CsConnected, | - |
21 | CsClosed, | - |
22 | CsHostNotFound, | - |
23 | CsConnectionRefused | - |
24 | }; | - |
25 | | - |
26 | QFtpDTP(QFtpPI *p, QObject *parent = 0); | - |
27 | | - |
28 | void setData(QByteArray *); | - |
29 | void setDevice(QIODevice *); | - |
30 | void writeData(); | - |
31 | void setBytesTotal(qint64 bytes); | - |
32 | | - |
33 | bool hasError() const; | - |
34 | QString errorMessage() const; | - |
35 | void clearError(); | - |
36 | | - |
37 | void connectToHost(const QString & host, quint16 port); | - |
38 | int setupListener(const QHostAddress &address); | - |
39 | void waitForConnection(); | - |
40 | | - |
41 | QTcpSocket::SocketState state() const; | - |
42 | qint64 bytesAvailable() const; | - |
43 | qint64 read(char *data, qint64 maxlen); | - |
44 | QByteArray readAll(); | - |
45 | | - |
46 | void abortConnection(); | - |
47 | | - |
48 | static bool parseDir(const QByteArray &buffer, const QString &userName, QUrlInfo *info); | - |
49 | | - |
50 | public: | - |
51 | void listInfo(const QUrlInfo&); | - |
52 | void readyRead(); | - |
53 | void dataTransferProgress(qint64, qint64); | - |
54 | | - |
55 | void connectState(int); | - |
56 | | - |
57 | private : | - |
58 | void socketConnected(); | - |
59 | void socketReadyRead(); | - |
60 | void socketError(QAbstractSocket::SocketError); | - |
61 | void socketConnectionClosed(); | - |
62 | void socketBytesWritten(qint64); | - |
63 | void setupSocket(); | - |
64 | | - |
65 | void dataReadyRead(); | - |
66 | | - |
67 | private: | - |
68 | void clearData(); | - |
69 | | - |
70 | QTcpSocket *socket; | - |
71 | QTcpServer listener; | - |
72 | | - |
73 | QFtpPI *pi; | - |
74 | QString err; | - |
75 | qint64 bytesDone; | - |
76 | qint64 bytesTotal; | - |
77 | bool callWriteData; | - |
78 | | - |
79 | | - |
80 | | - |
81 | union { | - |
82 | QByteArray *ba; | - |
83 | QIODevice *dev; | - |
84 | } data; | - |
85 | bool is_ba; | - |
86 | | - |
87 | QByteArray bytesFromSocket; | - |
88 | }; | - |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | class QFtpPI : public QObject | - |
97 | { | - |
98 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
99 | | - |
100 | public: | - |
101 | QFtpPI(QObject *parent = 0); | - |
102 | | - |
103 | void connectToHost(const QString &host, quint16 port); | - |
104 | | - |
105 | bool sendCommands(const QStringList &cmds); | - |
106 | bool sendCommand(const QString &cmd) | - |
107 | { return sendCommands(QStringList(cmd)); } never executed: return sendCommands(QStringList(cmd)); | 0 |
108 | | - |
109 | void clearPendingCommands(); | - |
110 | void abort(); | - |
111 | | - |
112 | QString currentCommand() const | - |
113 | { return currentCmd; } executed: return currentCmd; Execution Count:1588 | 1588 |
114 | | - |
115 | bool rawCommand; | - |
116 | bool transferConnectionExtended; | - |
117 | | - |
118 | QFtpDTP dtp; | - |
119 | | - |
120 | public: | - |
121 | void connectState(int); | - |
122 | void finished(const QString&); | - |
123 | void error(int, const QString&); | - |
124 | void rawFtpReply(int, const QString&); | - |
125 | | - |
126 | private : | - |
127 | void hostFound(); | - |
128 | void connected(); | - |
129 | void connectionClosed(); | - |
130 | void delayedCloseFinished(); | - |
131 | void readyRead(); | - |
132 | void error(QAbstractSocket::SocketError); | - |
133 | | - |
134 | void dtpConnectState(int); | - |
135 | | - |
136 | private: | - |
137 | | - |
138 | | - |
139 | enum State { | - |
140 | Begin, | - |
141 | Idle, | - |
142 | Waiting, | - |
143 | Success, | - |
144 | Failure | - |
145 | }; | - |
146 | | - |
147 | enum AbortState { | - |
148 | None, | - |
149 | AbortStarted, | - |
150 | WaitForAbortToFinish | - |
151 | }; | - |
152 | | - |
153 | bool processReply(); | - |
154 | bool startNextCmd(); | - |
155 | | - |
156 | QTcpSocket commandSocket; | - |
157 | QString replyText; | - |
158 | char replyCode[3]; | - |
159 | State state; | - |
160 | AbortState abortState; | - |
161 | QStringList pendingCommands; | - |
162 | QString currentCmd; | - |
163 | | - |
164 | bool waitForDtpToConnect; | - |
165 | bool waitForDtpToClose; | - |
166 | | - |
167 | QByteArray bytesFromSocket; | - |
168 | | - |
169 | friend class QFtpDTP; | - |
170 | }; | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | class QFtpCommand | - |
178 | { | - |
179 | public: | - |
180 | QFtpCommand(QFtp::Command cmd, QStringList raw, const QByteArray &ba); | - |
181 | QFtpCommand(QFtp::Command cmd, QStringList raw, QIODevice *dev = 0); | - |
182 | ~QFtpCommand(); | - |
183 | | - |
184 | int id; | - |
185 | QFtp::Command command; | - |
186 | QStringList rawCmds; | - |
187 | | - |
188 | | - |
189 | | - |
190 | union { | - |
191 | QByteArray *ba; | - |
192 | QIODevice *dev; | - |
193 | } data; | - |
194 | bool is_ba; | - |
195 | | - |
196 | static QBasicAtomicInt idCounter; | - |
197 | }; | - |
198 | | - |
199 | QBasicAtomicInt QFtpCommand::idCounter = { (1) }; | - |
200 | | - |
201 | QFtpCommand::QFtpCommand(QFtp::Command cmd, QStringList raw, const QByteArray &ba) | - |
202 | : command(cmd), rawCmds(raw), is_ba(true) | - |
203 | { | - |
204 | id = idCounter.fetchAndAddRelaxed(1); | - |
205 | data.ba = new QByteArray(ba); | - |
206 | } | 0 |
207 | | - |
208 | QFtpCommand::QFtpCommand(QFtp::Command cmd, QStringList raw, QIODevice *dev) | - |
209 | : command(cmd), rawCmds(raw), is_ba(false) | - |
210 | { | - |
211 | id = idCounter.fetchAndAddRelaxed(1); | - |
212 | data.dev = dev; | - |
213 | } executed: } Execution Count:281 | 281 |
214 | | - |
215 | QFtpCommand::~QFtpCommand() | - |
216 | { | - |
217 | if (is_ba) partially evaluated: is_ba no Evaluation Count:0 | yes Evaluation Count:278 |
| 0-278 |
218 | delete data.ba; never executed: delete data.ba; | 0 |
219 | } executed: } Execution Count:278 | 278 |
220 | | - |
221 | | - |
222 | | - |
223 | | - |
224 | | - |
225 | | - |
226 | QFtpDTP::QFtpDTP(QFtpPI *p, QObject *parent) : | - |
227 | QObject(parent), | - |
228 | socket(0), | - |
229 | listener(this), | - |
230 | pi(p), | - |
231 | callWriteData(false) | - |
232 | { | - |
233 | clearData(); | - |
234 | listener.setObjectName(QLatin1String("QFtpDTP active state server")); | - |
235 | connect(&listener, "2""newConnection()", "1""setupSocket()"); | - |
236 | } executed: } Execution Count:37 | 37 |
237 | | - |
238 | void QFtpDTP::setData(QByteArray *ba) | - |
239 | { | - |
240 | is_ba = true; | - |
241 | data.ba = ba; | - |
242 | } | 0 |
243 | | - |
244 | void QFtpDTP::setDevice(QIODevice *dev) | - |
245 | { | - |
246 | is_ba = false; | - |
247 | data.dev = dev; | - |
248 | } executed: } Execution Count:11 | 11 |
249 | | - |
250 | void QFtpDTP::setBytesTotal(qint64 bytes) | - |
251 | { | - |
252 | bytesTotal = bytes; | - |
253 | bytesDone = 0; | - |
254 | dataTransferProgress(bytesDone, bytesTotal); | - |
255 | } executed: } Execution Count:33 | 33 |
256 | | - |
257 | void QFtpDTP::connectToHost(const QString & host, quint16 port) | - |
258 | { | - |
259 | bytesFromSocket.clear(); | - |
260 | | - |
261 | if (socket) { evaluated: socket yes Evaluation Count:1 | yes Evaluation Count:32 |
| 1-32 |
262 | delete socket; | - |
263 | socket = 0; | - |
264 | } executed: } Execution Count:1 | 1 |
265 | socket = new QTcpSocket(this); | - |
266 | | - |
267 | | - |
268 | socket->setProperty("_q_networksession", property("_q_networksession")); | - |
269 | | - |
270 | socket->setObjectName(QLatin1String("QFtpDTP Passive state socket")); | - |
271 | connect(socket, "2""connected()", "1""socketConnected()"); | - |
272 | connect(socket, "2""readyRead()", "1""socketReadyRead()"); | - |
273 | connect(socket, "2""error(QAbstractSocket::SocketError)", "1""socketError(QAbstractSocket::SocketError)"); | - |
274 | connect(socket, "2""disconnected()", "1""socketConnectionClosed()"); | - |
275 | connect(socket, "2""bytesWritten(qint64)", "1""socketBytesWritten(qint64)"); | - |
276 | | - |
277 | socket->connectToHost(host, port); | - |
278 | } executed: } Execution Count:33 | 33 |
279 | | - |
280 | int QFtpDTP::setupListener(const QHostAddress &address) | - |
281 | { | - |
282 | | - |
283 | | - |
284 | listener.setProperty("_q_networksession", property("_q_networksession")); | - |
285 | | - |
286 | if (!listener.isListening() && !listener.listen(address, 0)) never evaluated: !listener.isListening() never evaluated: !listener.listen(address, 0) | 0 |
287 | return -1; never executed: return -1; | 0 |
288 | return listener.serverPort(); never executed: return listener.serverPort(); | 0 |
289 | } | - |
290 | | - |
291 | void QFtpDTP::waitForConnection() | - |
292 | { | - |
293 | | - |
294 | | - |
295 | | - |
296 | if (listener.isListening()) partially evaluated: listener.isListening() no Evaluation Count:0 | yes Evaluation Count:11 |
| 0-11 |
297 | listener.waitForNewConnection(); never executed: listener.waitForNewConnection(); | 0 |
298 | } executed: } Execution Count:11 | 11 |
299 | | - |
300 | QTcpSocket::SocketState QFtpDTP::state() const | - |
301 | { | - |
302 | return socket ? socket->state() : QTcpSocket::UnconnectedState; executed: return socket ? socket->state() : QTcpSocket::UnconnectedState; Execution Count:31 | 31 |
303 | } | - |
304 | | - |
305 | qint64 QFtpDTP::bytesAvailable() const | - |
306 | { | - |
307 | if (!socket || socket->state() != QTcpSocket::ConnectedState) evaluated: !socket yes Evaluation Count:205 | yes Evaluation Count:822 |
evaluated: socket->state() != QTcpSocket::ConnectedState yes Evaluation Count:35 | yes Evaluation Count:787 |
| 35-822 |
308 | return (qint64) bytesFromSocket.size(); executed: return (qint64) bytesFromSocket.size(); Execution Count:240 | 240 |
309 | return socket->bytesAvailable(); executed: return socket->bytesAvailable(); Execution Count:787 | 787 |
310 | } | - |
311 | | - |
312 | qint64 QFtpDTP::read(char *data, qint64 maxlen) | - |
313 | { | - |
314 | qint64 read; | - |
315 | if (socket && socket->state() == QTcpSocket::ConnectedState) { never evaluated: socket->state() == QTcpSocket::ConnectedState | 0 |
316 | read = socket->read(data, maxlen); | - |
317 | } else { | 0 |
318 | read = qMin(maxlen, qint64(bytesFromSocket.size())); | - |
319 | memcpy(data, bytesFromSocket.data(), read); | - |
320 | bytesFromSocket.remove(0, read); | - |
321 | } | 0 |
322 | | - |
323 | bytesDone += read; | - |
324 | return read; never executed: return read; | 0 |
325 | } | - |
326 | | - |
327 | QByteArray QFtpDTP::readAll() | - |
328 | { | - |
329 | QByteArray tmp; | - |
330 | if (socket && socket->state() == QTcpSocket::ConnectedState) { partially evaluated: socket yes Evaluation Count:788 | no Evaluation Count:0 |
partially evaluated: socket->state() == QTcpSocket::ConnectedState yes Evaluation Count:788 | no Evaluation Count:0 |
| 0-788 |
331 | tmp = socket->readAll(); | - |
332 | bytesDone += tmp.size(); | - |
333 | } else { executed: } Execution Count:788 | 788 |
334 | tmp = bytesFromSocket; | - |
335 | bytesFromSocket.clear(); | - |
336 | } | 0 |
337 | return tmp; executed: return tmp; Execution Count:788 | 788 |
338 | } | - |
339 | | - |
340 | void QFtpDTP::writeData() | - |
341 | { | - |
342 | if (!socket) partially evaluated: !socket no Evaluation Count:0 | yes Evaluation Count:158 |
| 0-158 |
343 | return; | 0 |
344 | | - |
345 | if (is_ba) { partially evaluated: is_ba no Evaluation Count:0 | yes Evaluation Count:158 |
| 0-158 |
346 | | - |
347 | | - |
348 | | - |
349 | if (data.ba->size() == 0) never evaluated: data.ba->size() == 0 | 0 |
350 | dataTransferProgress(0, bytesTotal); never executed: dataTransferProgress(0, bytesTotal); | 0 |
351 | else | - |
352 | socket->write(data.ba->data(), data.ba->size()); never executed: socket->write(data.ba->data(), data.ba->size()); | 0 |
353 | | - |
354 | socket->close(); | - |
355 | | - |
356 | clearData(); | - |
357 | } else if (data.dev) { partially evaluated: data.dev yes Evaluation Count:158 | no Evaluation Count:0 |
| 0-158 |
358 | callWriteData = false; | - |
359 | const qint64 blockSize = 16*1024; | - |
360 | char buf[16*1024]; | - |
361 | qint64 read = data.dev->read(buf, blockSize); | - |
362 | | - |
363 | | - |
364 | | - |
365 | if (read > 0) { evaluated: read > 0 yes Evaluation Count:147 | yes Evaluation Count:11 |
| 11-147 |
366 | socket->write(buf, read); | - |
367 | } else if (read == -1 || (!data.dev->isSequential() && data.dev->atEnd())) { executed: } Execution Count:147 partially evaluated: read == -1 yes Evaluation Count:11 | no Evaluation Count:0 |
never evaluated: !data.dev->isSequential() never evaluated: data.dev->atEnd() | 0-147 |
368 | | - |
369 | if (bytesDone == 0 && socket->bytesToWrite() == 0) evaluated: bytesDone == 0 yes Evaluation Count:2 | yes Evaluation Count:9 |
partially evaluated: socket->bytesToWrite() == 0 yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-9 |
370 | dataTransferProgress(0, bytesTotal); executed: dataTransferProgress(0, bytesTotal); Execution Count:2 | 2 |
371 | socket->close(); | - |
372 | clearData(); | - |
373 | } executed: } Execution Count:11 | 11 |
374 | | - |
375 | | - |
376 | callWriteData = data.dev != 0; | - |
377 | } executed: } Execution Count:158 | 158 |
378 | } | - |
379 | | - |
380 | void QFtpDTP::dataReadyRead() | - |
381 | { | - |
382 | writeData(); | - |
383 | } | 0 |
384 | | - |
385 | inline bool QFtpDTP::hasError() const | - |
386 | { | - |
387 | return !err.isNull(); executed: return !err.isNull(); Execution Count:318 | 318 |
388 | } | - |
389 | | - |
390 | inline QString QFtpDTP::errorMessage() const | - |
391 | { | - |
392 | return err; never executed: return err; | 0 |
393 | } | - |
394 | | - |
395 | inline void QFtpDTP::clearError() | - |
396 | { | - |
397 | err.clear(); | - |
398 | } | 0 |
399 | | - |
400 | void QFtpDTP::abortConnection() | - |
401 | { | - |
402 | | - |
403 | | - |
404 | | - |
405 | | - |
406 | callWriteData = false; | - |
407 | clearData(); | - |
408 | | - |
409 | if (socket) evaluated: socket yes Evaluation Count:2 | yes Evaluation Count:6 |
| 2-6 |
410 | socket->abort(); executed: socket->abort(); Execution Count:2 | 2 |
411 | } executed: } Execution Count:8 | 8 |
412 | | - |
413 | static void _q_fixupDateTime(QDateTime *dateTime) | - |
414 | { | - |
415 | | - |
416 | const int futureTolerance = 86400; | - |
417 | if (dateTime->secsTo(QDateTime::currentDateTime()) < -futureTolerance) { never evaluated: dateTime->secsTo(QDateTime::currentDateTime()) < -futureTolerance | 0 |
418 | QDate d = dateTime->date(); | - |
419 | d.setDate(d.year() - 1, d.month(), d.day()); | - |
420 | dateTime->setDate(d); | - |
421 | } | 0 |
422 | } | 0 |
423 | | - |
424 | static void _q_parseUnixDir(const QStringList &tokens, const QString &userName, QUrlInfo *info) | - |
425 | { | - |
426 | | - |
427 | | - |
428 | | - |
429 | | - |
430 | if (tokens.size() != 8) never evaluated: tokens.size() != 8 | 0 |
431 | return; | 0 |
432 | | - |
433 | char first = tokens.at(1).at(0).toLatin1(); | - |
434 | if (first == 'd') { never evaluated: first == 'd' | 0 |
435 | info->setDir(true); | - |
436 | info->setFile(false); | - |
437 | info->setSymLink(false); | - |
438 | } else if (first == '-') { never evaluated: first == '-' | 0 |
439 | info->setDir(false); | - |
440 | info->setFile(true); | - |
441 | info->setSymLink(false); | - |
442 | } else if (first == 'l') { never evaluated: first == 'l' | 0 |
443 | info->setDir(true); | - |
444 | info->setFile(false); | - |
445 | info->setSymLink(true); | - |
446 | } | 0 |
447 | | - |
448 | | - |
449 | QString name = tokens.at(7); | - |
450 | if (info->isSymLink()) { never evaluated: info->isSymLink() | 0 |
451 | int linkPos = name.indexOf(QLatin1String(" ->")); | - |
452 | if (linkPos != -1) never evaluated: linkPos != -1 | 0 |
453 | name.resize(linkPos); never executed: name.resize(linkPos); | 0 |
454 | } | 0 |
455 | info->setName(name); | - |
456 | | - |
457 | | - |
458 | info->setOwner(tokens.at(3)); | - |
459 | info->setGroup(tokens.at(4)); | - |
460 | | - |
461 | | - |
462 | info->setSize(tokens.at(5).toLongLong()); | - |
463 | | - |
464 | QStringList formats; | - |
465 | formats << QLatin1String("MMM dd yyyy") << QLatin1String("MMM dd hh:mm") << QLatin1String("MMM d yyyy") | - |
466 | << QLatin1String("MMM d hh:mm") << QLatin1String("MMM d yyyy") << QLatin1String("MMM dd yyyy"); | - |
467 | | - |
468 | QString dateString = tokens.at(6); | - |
469 | dateString[0] = dateString[0].toUpper(); | - |
470 | | - |
471 | | - |
472 | QDateTime dateTime; | - |
473 | int n = 0; | - |
474 | | - |
475 | do { | - |
476 | dateTime = QLocale::c().toDateTime(dateString, formats.at(n++)); | - |
477 | } while (n < formats.size() && (!dateTime.isValid())); never evaluated: n < formats.size() never evaluated: (!dateTime.isValid()) | 0 |
478 | | - |
479 | | - |
480 | if (n == 2 || n == 4) { | 0 |
481 | | - |
482 | dateTime.setDate(QDate(QDate::currentDate().year(), | - |
483 | dateTime.date().month(), | - |
484 | dateTime.date().day())); | - |
485 | _q_fixupDateTime(&dateTime); | - |
486 | } | 0 |
487 | if (dateTime.isValid()) never evaluated: dateTime.isValid() | 0 |
488 | info->setLastModified(dateTime); never executed: info->setLastModified(dateTime); | 0 |
489 | | - |
490 | | - |
491 | int permissions = 0; | - |
492 | QString p = tokens.at(2); | - |
493 | permissions |= (p[0] == QLatin1Char('r') ? QUrlInfo::ReadOwner : 0); never evaluated: p[0] == QLatin1Char('r') | 0 |
494 | permissions |= (p[1] == QLatin1Char('w') ? QUrlInfo::WriteOwner : 0); never evaluated: p[1] == QLatin1Char('w') | 0 |
495 | permissions |= (p[2] == QLatin1Char('x') ? QUrlInfo::ExeOwner : 0); never evaluated: p[2] == QLatin1Char('x') | 0 |
496 | permissions |= (p[3] == QLatin1Char('r') ? QUrlInfo::ReadGroup : 0); never evaluated: p[3] == QLatin1Char('r') | 0 |
497 | permissions |= (p[4] == QLatin1Char('w') ? QUrlInfo::WriteGroup : 0); never evaluated: p[4] == QLatin1Char('w') | 0 |
498 | permissions |= (p[5] == QLatin1Char('x') ? QUrlInfo::ExeGroup : 0); never evaluated: p[5] == QLatin1Char('x') | 0 |
499 | permissions |= (p[6] == QLatin1Char('r') ? QUrlInfo::ReadOther : 0); never evaluated: p[6] == QLatin1Char('r') | 0 |
500 | permissions |= (p[7] == QLatin1Char('w') ? QUrlInfo::WriteOther : 0); never evaluated: p[7] == QLatin1Char('w') | 0 |
501 | permissions |= (p[8] == QLatin1Char('x') ? QUrlInfo::ExeOther : 0); never evaluated: p[8] == QLatin1Char('x') | 0 |
502 | info->setPermissions(permissions); | - |
503 | | - |
504 | bool isOwner = info->owner() == userName; | - |
505 | info->setReadable((permissions & QUrlInfo::ReadOther) || ((permissions & QUrlInfo::ReadOwner) && isOwner)); | - |
506 | info->setWritable((permissions & QUrlInfo::WriteOther) || ((permissions & QUrlInfo::WriteOwner) && isOwner)); | - |
507 | } | 0 |
508 | | - |
509 | static void _q_parseDosDir(const QStringList &tokens, const QString &userName, QUrlInfo *info) | - |
510 | { | - |
511 | | - |
512 | | - |
513 | | - |
514 | if (tokens.size() != 4) never evaluated: tokens.size() != 4 | 0 |
515 | return; | 0 |
516 | | - |
517 | (void)userName;; | - |
518 | | - |
519 | QString name = tokens.at(3); | - |
520 | info->setName(name); | - |
521 | info->setSymLink(name.toLower().endsWith(QLatin1String(".lnk"))); | - |
522 | | - |
523 | if (tokens.at(2) == QLatin1String("<DIR>")) { never evaluated: tokens.at(2) == QLatin1String("<DIR>") | 0 |
524 | info->setFile(false); | - |
525 | info->setDir(true); | - |
526 | } else { | 0 |
527 | info->setFile(true); | - |
528 | info->setDir(false); | - |
529 | info->setSize(tokens.at(2).toLongLong()); | - |
530 | } | 0 |
531 | | - |
532 | | - |
533 | | - |
534 | int permissions = QUrlInfo::ReadOwner | QUrlInfo::WriteOwner | - |
535 | | QUrlInfo::ReadGroup | QUrlInfo::WriteGroup | - |
536 | | QUrlInfo::ReadOther | QUrlInfo::WriteOther; | - |
537 | QString ext; | - |
538 | int extIndex = name.lastIndexOf(QLatin1Char('.')); | - |
539 | if (extIndex != -1) never evaluated: extIndex != -1 | 0 |
540 | ext = name.mid(extIndex + 1); never executed: ext = name.mid(extIndex + 1); | 0 |
541 | if (ext == QLatin1String("exe") || ext == QLatin1String("bat") || ext == QLatin1String("com")) never evaluated: ext == QLatin1String("exe") never evaluated: ext == QLatin1String("bat") never evaluated: ext == QLatin1String("com") | 0 |
542 | permissions |= QUrlInfo::ExeOwner | QUrlInfo::ExeGroup | QUrlInfo::ExeOther; never executed: permissions |= QUrlInfo::ExeOwner | QUrlInfo::ExeGroup | QUrlInfo::ExeOther; | 0 |
543 | info->setPermissions(permissions); | - |
544 | | - |
545 | info->setReadable(true); | - |
546 | info->setWritable(info->isFile()); | - |
547 | | - |
548 | QDateTime dateTime; | - |
549 | | - |
550 | dateTime = QLocale::c().toDateTime(tokens.at(1), QLatin1String("MM-dd-yy hh:mmAP")); | - |
551 | if (dateTime.date().year() < 1971) { never evaluated: dateTime.date().year() < 1971 | 0 |
552 | dateTime.setDate(QDate(dateTime.date().year() + 100, | - |
553 | dateTime.date().month(), | - |
554 | dateTime.date().day())); | - |
555 | } | 0 |
556 | | - |
557 | | - |
558 | info->setLastModified(dateTime); | - |
559 | | - |
560 | } | 0 |
561 | | - |
562 | bool QFtpDTP::parseDir(const QByteArray &buffer, const QString &userName, QUrlInfo *info) | - |
563 | { | - |
564 | if (buffer.isEmpty()) never evaluated: buffer.isEmpty() | 0 |
565 | return false; never executed: return false; | 0 |
566 | | - |
567 | QString bufferStr = QString::fromLatin1(buffer).trimmed(); | - |
568 | | - |
569 | | - |
570 | QRegExp unixPattern(QLatin1String("^([\\-dl])([a-zA-Z\\-]{9,9})\\s+\\d+\\s+(\\S*)\\s+" | - |
571 | "(\\S*)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+\\S+)\\s+(\\S.*)")); | - |
572 | if (unixPattern.indexIn(bufferStr) == 0) { never evaluated: unixPattern.indexIn(bufferStr) == 0 | 0 |
573 | _q_parseUnixDir(unixPattern.capturedTexts(), userName, info); | - |
574 | return true; never executed: return true; | 0 |
575 | } | - |
576 | | - |
577 | | - |
578 | QRegExp dosPattern(QLatin1String("^(\\d\\d-\\d\\d-\\d\\d\\ \\ \\d\\d:\\d\\d[AP]M)\\s+" | - |
579 | "(<DIR>|\\d+)\\s+(\\S.*)$")); | - |
580 | if (dosPattern.indexIn(bufferStr) == 0) { never evaluated: dosPattern.indexIn(bufferStr) == 0 | 0 |
581 | _q_parseDosDir(dosPattern.capturedTexts(), userName, info); | - |
582 | return true; never executed: return true; | 0 |
583 | } | - |
584 | | - |
585 | | - |
586 | return false; never executed: return false; | 0 |
587 | } | - |
588 | | - |
589 | void QFtpDTP::socketConnected() | - |
590 | { | - |
591 | bytesDone = 0; | - |
592 | | - |
593 | | - |
594 | | - |
595 | connectState(QFtpDTP::CsConnected); | - |
596 | } executed: } Execution Count:33 | 33 |
597 | | - |
598 | void QFtpDTP::socketReadyRead() | - |
599 | { | - |
600 | if (!socket) partially evaluated: !socket no Evaluation Count:0 | yes Evaluation Count:788 |
| 0-788 |
601 | return; | 0 |
602 | | - |
603 | if (pi->currentCommand().isEmpty()) { partially evaluated: pi->currentCommand().isEmpty() no Evaluation Count:0 | yes Evaluation Count:788 |
| 0-788 |
604 | socket->close(); | - |
605 | | - |
606 | | - |
607 | | - |
608 | connectState(QFtpDTP::CsClosed); | - |
609 | return; | 0 |
610 | } | - |
611 | | - |
612 | if (pi->abortState != QFtpPI::None) { partially evaluated: pi->abortState != QFtpPI::None no Evaluation Count:0 | yes Evaluation Count:788 |
| 0-788 |
613 | | - |
614 | socket->readAll(); | - |
615 | return; | 0 |
616 | } | - |
617 | | - |
618 | if (pi->currentCommand().startsWith(QLatin1String("LIST"))) { partially evaluated: pi->currentCommand().startsWith(QLatin1String("LIST")) no Evaluation Count:0 | yes Evaluation Count:788 |
| 0-788 |
619 | while (socket->canReadLine()) { never evaluated: socket->canReadLine() | 0 |
620 | QUrlInfo i; | - |
621 | QByteArray line = socket->readLine(); | - |
622 | | - |
623 | | - |
624 | | - |
625 | if (parseDir(line, QLatin1String(""), &i)) { never evaluated: parseDir(line, QLatin1String(""), &i) | 0 |
626 | listInfo(i); | - |
627 | } else { | 0 |
628 | | - |
629 | | - |
630 | | - |
631 | if (line.endsWith("No such file or directory\r\n")) never evaluated: line.endsWith("No such file or directory\r\n") | 0 |
632 | err = QString::fromLatin1(line); never executed: err = QString::fromLatin1(line); | 0 |
633 | } | 0 |
634 | } | - |
635 | } else { | 0 |
636 | if (!is_ba && data.dev) { partially evaluated: !is_ba yes Evaluation Count:788 | no Evaluation Count:0 |
partially evaluated: data.dev no Evaluation Count:0 | yes Evaluation Count:788 |
| 0-788 |
637 | do { | - |
638 | QByteArray ba; | - |
639 | ba.resize(socket->bytesAvailable()); | - |
640 | qint64 bytesRead = socket->read(ba.data(), ba.size()); | - |
641 | if (bytesRead < 0) { never evaluated: bytesRead < 0 | 0 |
642 | | - |
643 | | - |
644 | return; | 0 |
645 | } | - |
646 | ba.resize(bytesRead); | - |
647 | bytesDone += bytesRead; | - |
648 | | - |
649 | | - |
650 | | - |
651 | if (data.dev) never evaluated: data.dev | 0 |
652 | data.dev->write(ba); never executed: data.dev->write(ba); | 0 |
653 | dataTransferProgress(bytesDone, bytesTotal); | - |
654 | | - |
655 | | - |
656 | | - |
657 | | - |
658 | } while (socket->bytesAvailable()); never evaluated: socket->bytesAvailable() | 0 |
659 | } else { | 0 |
660 | | - |
661 | | - |
662 | | - |
663 | | - |
664 | dataTransferProgress(bytesDone+socket->bytesAvailable(), bytesTotal); | - |
665 | readyRead(); | - |
666 | } executed: } Execution Count:788 | 788 |
667 | } | - |
668 | } | - |
669 | | - |
670 | void QFtpDTP::socketError(QAbstractSocket::SocketError e) | - |
671 | { | - |
672 | if (e == QTcpSocket::HostNotFoundError) { partially evaluated: e == QTcpSocket::HostNotFoundError no Evaluation Count:0 | yes Evaluation Count:20 |
| 0-20 |
673 | | - |
674 | | - |
675 | | - |
676 | connectState(QFtpDTP::CsHostNotFound); | - |
677 | } else if (e == QTcpSocket::ConnectionRefusedError) { partially evaluated: e == QTcpSocket::ConnectionRefusedError no Evaluation Count:0 | yes Evaluation Count:20 |
| 0-20 |
678 | | - |
679 | | - |
680 | | - |
681 | connectState(QFtpDTP::CsConnectionRefused); | - |
682 | } | 0 |
683 | } | - |
684 | | - |
685 | void QFtpDTP::socketConnectionClosed() | - |
686 | { | - |
687 | if (!is_ba && data.dev) { partially evaluated: !is_ba yes Evaluation Count:33 | no Evaluation Count:0 |
evaluated: data.dev yes Evaluation Count:11 | yes Evaluation Count:22 |
| 0-33 |
688 | clearData(); | - |
689 | } executed: } Execution Count:11 | 11 |
690 | | - |
691 | bytesFromSocket = socket->readAll(); | - |
692 | | - |
693 | | - |
694 | | - |
695 | connectState(QFtpDTP::CsClosed); | - |
696 | } executed: } Execution Count:33 | 33 |
697 | | - |
698 | void QFtpDTP::socketBytesWritten(qint64 bytes) | - |
699 | { | - |
700 | bytesDone += bytes; | - |
701 | | - |
702 | | - |
703 | | - |
704 | dataTransferProgress(bytesDone, bytesTotal); | - |
705 | if (callWriteData) partially evaluated: callWriteData yes Evaluation Count:147 | no Evaluation Count:0 |
| 0-147 |
706 | writeData(); executed: writeData(); Execution Count:147 | 147 |
707 | } executed: } Execution Count:147 | 147 |
708 | | - |
709 | void QFtpDTP::setupSocket() | - |
710 | { | - |
711 | socket = listener.nextPendingConnection(); | - |
712 | socket->setObjectName(QLatin1String("QFtpDTP Active state socket")); | - |
713 | connect(socket, "2""connected()", "1""socketConnected()"); | - |
714 | connect(socket, "2""readyRead()", "1""socketReadyRead()"); | - |
715 | connect(socket, "2""error(QAbstractSocket::SocketError)", "1""socketError(QAbstractSocket::SocketError)"); | - |
716 | connect(socket, "2""disconnected()", "1""socketConnectionClosed()"); | - |
717 | connect(socket, "2""bytesWritten(qint64)", "1""socketBytesWritten(qint64)"); | - |
718 | | - |
719 | listener.close(); | - |
720 | } | 0 |
721 | | - |
722 | void QFtpDTP::clearData() | - |
723 | { | - |
724 | is_ba = false; | - |
725 | data.dev = 0; | - |
726 | } executed: } Execution Count:67 | 67 |
727 | | - |
728 | | - |
729 | | - |
730 | | - |
731 | | - |
732 | | - |
733 | QFtpPI::QFtpPI(QObject *parent) : | - |
734 | QObject(parent), | - |
735 | rawCommand(false), | - |
736 | transferConnectionExtended(true), | - |
737 | dtp(this), | - |
738 | commandSocket(0), | - |
739 | state(Begin), abortState(None), | - |
740 | currentCmd(QString()), | - |
741 | waitForDtpToConnect(false), | - |
742 | waitForDtpToClose(false) | - |
743 | { | - |
744 | commandSocket.setObjectName(QLatin1String("QFtpPI_socket")); | - |
745 | connect(&commandSocket, "2""hostFound()", | - |
746 | "1""hostFound()"); | - |
747 | connect(&commandSocket, "2""connected()", | - |
748 | "1""connected()"); | - |
749 | connect(&commandSocket, "2""disconnected()", | - |
750 | "1""connectionClosed()"); | - |
751 | connect(&commandSocket, "2""readyRead()", | - |
752 | "1""readyRead()"); | - |
753 | connect(&commandSocket, "2""error(QAbstractSocket::SocketError)", | - |
754 | "1""error(QAbstractSocket::SocketError)"); | - |
755 | | - |
756 | connect(&dtp, "2""connectState(int)", | - |
757 | "1""dtpConnectState(int)"); | - |
758 | } executed: } Execution Count:37 | 37 |
759 | | - |
760 | void QFtpPI::connectToHost(const QString &host, quint16 port) | - |
761 | { | - |
762 | connectState(QFtp::HostLookup); | - |
763 | | - |
764 | | - |
765 | commandSocket.setProperty("_q_networksession", property("_q_networksession")); | - |
766 | dtp.setProperty("_q_networksession", property("_q_networksession")); | - |
767 | | - |
768 | commandSocket.connectToHost(host, port); | - |
769 | } executed: } Execution Count:37 | 37 |
770 | bool QFtpPI::sendCommands(const QStringList &cmds) | - |
771 | { | - |
772 | if (!pendingCommands.isEmpty()) partially evaluated: !pendingCommands.isEmpty() no Evaluation Count:0 | yes Evaluation Count:201 |
| 0-201 |
773 | return false; never executed: return false; | 0 |
774 | | - |
775 | if (commandSocket.state() != QTcpSocket::ConnectedState || state!=Idle) { evaluated: commandSocket.state() != QTcpSocket::ConnectedState yes Evaluation Count:1 | yes Evaluation Count:200 |
partially evaluated: state!=Idle no Evaluation Count:0 | yes Evaluation Count:200 |
| 0-200 |
776 | error(QFtp::NotConnected, QFtp::tr("Not connected")); | - |
777 | return true; executed: return true; Execution Count:1 | 1 |
778 | } | - |
779 | | - |
780 | pendingCommands = cmds; | - |
781 | startNextCmd(); | - |
782 | return true; executed: return true; Execution Count:200 | 200 |
783 | } | - |
784 | | - |
785 | void QFtpPI::clearPendingCommands() | - |
786 | { | - |
787 | pendingCommands.clear(); | - |
788 | dtp.abortConnection(); | - |
789 | currentCmd.clear(); | - |
790 | state = Idle; | - |
791 | } executed: } Execution Count:7 | 7 |
792 | | - |
793 | void QFtpPI::abort() | - |
794 | { | - |
795 | pendingCommands.clear(); | - |
796 | | - |
797 | if (abortState != None) partially evaluated: abortState != None no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
798 | | - |
799 | return; | 0 |
800 | | - |
801 | if (currentCmd.isEmpty()) partially evaluated: currentCmd.isEmpty() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
802 | return; | 0 |
803 | | - |
804 | if (currentCmd.startsWith(QLatin1String("STOR "))) { partially evaluated: currentCmd.startsWith(QLatin1String("STOR ")) no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
805 | abortState = AbortStarted; | - |
806 | | - |
807 | | - |
808 | | - |
809 | commandSocket.write("ABOR\r\n", 6); | - |
810 | | - |
811 | dtp.abortConnection(); | - |
812 | } else { | 0 |
813 | | - |
814 | | - |
815 | | - |
816 | | - |
817 | abortState = WaitForAbortToFinish; | - |
818 | dtp.abortConnection(); | - |
819 | } executed: } Execution Count:1 | 1 |
820 | } | - |
821 | | - |
822 | void QFtpPI::hostFound() | - |
823 | { | - |
824 | connectState(QFtp::Connecting); | - |
825 | } executed: } Execution Count:36 | 36 |
826 | | - |
827 | void QFtpPI::connected() | - |
828 | { | - |
829 | state = Begin; | - |
830 | | - |
831 | | - |
832 | | - |
833 | | - |
834 | commandSocket.setSocketOption(QAbstractSocket::LowDelayOption, 1); | - |
835 | | - |
836 | connectState(QFtp::Connected); | - |
837 | } executed: } Execution Count:36 | 36 |
838 | | - |
839 | void QFtpPI::connectionClosed() | - |
840 | { | - |
841 | commandSocket.close(); | - |
842 | connectState(QFtp::Unconnected); | - |
843 | } executed: } Execution Count:34 | 34 |
844 | | - |
845 | void QFtpPI::delayedCloseFinished() | - |
846 | { | - |
847 | connectState(QFtp::Unconnected); | - |
848 | } | 0 |
849 | | - |
850 | void QFtpPI::error(QAbstractSocket::SocketError e) | - |
851 | { | - |
852 | if (e == QTcpSocket::HostNotFoundError) { evaluated: e == QTcpSocket::HostNotFoundError yes Evaluation Count:1 | yes Evaluation Count:34 |
| 1-34 |
853 | connectState(QFtp::Unconnected); | - |
854 | error(QFtp::HostNotFound, | - |
855 | QFtp::tr("Host %1 not found").arg(commandSocket.peerName())); | - |
856 | } else if (e == QTcpSocket::ConnectionRefusedError) { partially evaluated: e == QTcpSocket::ConnectionRefusedError no Evaluation Count:0 | yes Evaluation Count:34 |
executed: } Execution Count:1 | 0-34 |
857 | connectState(QFtp::Unconnected); | - |
858 | error(QFtp::ConnectionRefused, | - |
859 | QFtp::tr("Connection refused to host %1").arg(commandSocket.peerName())); | - |
860 | } else if (e == QTcpSocket::SocketTimeoutError) { partially evaluated: e == QTcpSocket::SocketTimeoutError no Evaluation Count:0 | yes Evaluation Count:34 |
| 0-34 |
861 | connectState(QFtp::Unconnected); | - |
862 | error(QFtp::ConnectionRefused, | - |
863 | QFtp::tr("Connection timed out to host %1").arg(commandSocket.peerName())); | - |
864 | } | 0 |
865 | } | - |
866 | | - |
867 | void QFtpPI::readyRead() | - |
868 | { | - |
869 | if (waitForDtpToClose) partially evaluated: waitForDtpToClose no Evaluation Count:0 | yes Evaluation Count:531 |
| 0-531 |
870 | return; | 0 |
871 | | - |
872 | while (commandSocket.canReadLine()) { evaluated: commandSocket.canReadLine() yes Evaluation Count:498 | yes Evaluation Count:436 |
| 436-498 |
873 | | - |
874 | QString line = QString::fromLatin1(commandSocket.readLine()); | - |
875 | if (replyText.isEmpty()) { evaluated: replyText.isEmpty() yes Evaluation Count:403 | yes Evaluation Count:95 |
| 95-403 |
876 | if (line.length() < 3) { partially evaluated: line.length() < 3 no Evaluation Count:0 | yes Evaluation Count:403 |
| 0-403 |
877 | | - |
878 | return; | 0 |
879 | } | - |
880 | const int lowerLimit[3] = {1,0,0}; | - |
881 | const int upperLimit[3] = {5,5,9}; | - |
882 | for (int i=0; i<3; i++) { evaluated: i<3 yes Evaluation Count:1209 | yes Evaluation Count:403 |
| 403-1209 |
883 | replyCode[i] = line[i].digitValue(); | - |
884 | if (replyCode[i]<lowerLimit[i] || replyCode[i]>upperLimit[i]) { partially evaluated: replyCode[i]<lowerLimit[i] no Evaluation Count:0 | yes Evaluation Count:1209 |
partially evaluated: replyCode[i]>upperLimit[i] no Evaluation Count:0 | yes Evaluation Count:1209 |
| 0-1209 |
885 | | - |
886 | return; | 0 |
887 | } | - |
888 | } executed: } Execution Count:1209 | 1209 |
889 | } executed: } Execution Count:403 | 403 |
890 | QString endOfMultiLine; | - |
891 | endOfMultiLine[0] = '0' + replyCode[0]; | - |
892 | endOfMultiLine[1] = '0' + replyCode[1]; | - |
893 | endOfMultiLine[2] = '0' + replyCode[2]; | - |
894 | endOfMultiLine[3] = QLatin1Char(' '); | - |
895 | QString lineCont(endOfMultiLine); | - |
896 | lineCont[3] = QLatin1Char('-'); | - |
897 | QString lineLeft4 = line.left(4); | - |
898 | | - |
899 | while (lineLeft4 != endOfMultiLine) { evaluated: lineLeft4 != endOfMultiLine yes Evaluation Count:125 | yes Evaluation Count:403 |
| 125-403 |
900 | if (lineLeft4 == lineCont) evaluated: lineLeft4 == lineCont yes Evaluation Count:25 | yes Evaluation Count:100 |
| 25-100 |
901 | replyText += line.mid(4); executed: replyText += line.mid(4); Execution Count:25 | 25 |
902 | else | - |
903 | replyText += line; executed: replyText += line; Execution Count:100 | 100 |
904 | if (!commandSocket.canReadLine()) evaluated: !commandSocket.canReadLine() yes Evaluation Count:95 | yes Evaluation Count:30 |
| 30-95 |
905 | return; executed: return; Execution Count:95 | 95 |
906 | line = QString::fromLatin1(commandSocket.readLine()); | - |
907 | lineLeft4 = line.left(4); | - |
908 | } executed: } Execution Count:30 | 30 |
909 | replyText += line.mid(4); | - |
910 | if (replyText.endsWith(QLatin1String("\r\n"))) partially evaluated: replyText.endsWith(QLatin1String("\r\n")) yes Evaluation Count:403 | no Evaluation Count:0 |
| 0-403 |
911 | replyText.chop(2); executed: replyText.chop(2); Execution Count:403 | 403 |
912 | | - |
913 | if (processReply()) partially evaluated: processReply() yes Evaluation Count:403 | no Evaluation Count:0 |
| 0-403 |
914 | replyText = QLatin1String(""); executed: replyText = QLatin1String(""); Execution Count:403 | 403 |
915 | } executed: } Execution Count:403 | 403 |
916 | } executed: } Execution Count:436 | 436 |
917 | bool QFtpPI::processReply() | - |
918 | { | - |
919 | int replyCodeInt = 100*replyCode[0] + 10*replyCode[1] + replyCode[2]; | - |
920 | | - |
921 | | - |
922 | | - |
923 | if (replyCodeInt == 226 || (replyCodeInt == 250 && currentCmd.startsWith(QLatin1String("RETR")))) { evaluated: replyCodeInt == 226 yes Evaluation Count:31 | yes Evaluation Count:372 |
partially evaluated: replyCodeInt == 250 no Evaluation Count:0 | yes Evaluation Count:372 |
never evaluated: currentCmd.startsWith(QLatin1String("RETR")) | 0-372 |
924 | if (dtp.state() != QTcpSocket::UnconnectedState) { partially evaluated: dtp.state() != QTcpSocket::UnconnectedState no Evaluation Count:0 | yes Evaluation Count:31 |
| 0-31 |
925 | waitForDtpToClose = true; | - |
926 | return false; never executed: return false; | 0 |
927 | } | - |
928 | } executed: } Execution Count:31 | 31 |
929 | | - |
930 | switch (abortState) { | - |
931 | case AbortStarted: | - |
932 | abortState = WaitForAbortToFinish; | - |
933 | break; | 0 |
934 | case WaitForAbortToFinish: | - |
935 | abortState = None; | - |
936 | return true; executed: return true; Execution Count:1 | 1 |
937 | default: | - |
938 | break; executed: break; Execution Count:402 | 402 |
939 | } | - |
940 | | - |
941 | | - |
942 | static const State table[5] = { | - |
943 | | - |
944 | Waiting, Success, Idle, Failure, Failure | - |
945 | }; | - |
946 | switch (state) { | - |
947 | case Begin: | - |
948 | if (replyCode[0] == 1) { partially evaluated: replyCode[0] == 1 no Evaluation Count:0 | yes Evaluation Count:36 |
| 0-36 |
949 | return true; never executed: return true; | 0 |
950 | } else if (replyCode[0] == 2) { partially evaluated: replyCode[0] == 2 yes Evaluation Count:36 | no Evaluation Count:0 |
| 0-36 |
951 | state = Idle; | - |
952 | finished(QFtp::tr("Connected to host %1").arg(commandSocket.peerName())); | - |
953 | break; executed: break; Execution Count:36 | 36 |
954 | } | - |
955 | | - |
956 | return true; never executed: return true; | 0 |
957 | case Waiting: | - |
958 | if (static_cast<signed char>(replyCode[0]) < 0 || replyCode[0] > 5) partially evaluated: static_cast<signed char>(replyCode[0]) < 0 no Evaluation Count:0 | yes Evaluation Count:366 |
partially evaluated: replyCode[0] > 5 no Evaluation Count:0 | yes Evaluation Count:366 |
| 0-366 |
959 | state = Failure; never executed: state = Failure; | 0 |
960 | else | - |
961 | | - |
962 | | - |
963 | | - |
964 | | - |
965 | | - |
966 | | - |
967 | | - |
968 | if (replyCodeInt == 202) evaluated: replyCodeInt == 202 yes Evaluation Count:11 | yes Evaluation Count:355 |
| 11-355 |
969 | state = Failure; executed: state = Failure; Execution Count:11 | 11 |
970 | else | - |
971 | state = table[replyCode[0] - 1]; executed: state = table[replyCode[0] - 1]; Execution Count:355 | 355 |
972 | | - |
973 | break; executed: break; Execution Count:366 | 366 |
974 | default: | - |
975 | | - |
976 | return true; never executed: return true; | 0 |
977 | } | - |
978 | | - |
979 | | - |
980 | | - |
981 | | - |
982 | | - |
983 | rawFtpReply(replyCodeInt, replyText); | - |
984 | if (rawCommand) { evaluated: rawCommand yes Evaluation Count:97 | yes Evaluation Count:305 |
| 97-305 |
985 | rawCommand = false; | - |
986 | } else if (replyCodeInt == 227) { executed: } Execution Count:97 evaluated: replyCodeInt == 227 yes Evaluation Count:33 | yes Evaluation Count:272 |
| 33-272 |
987 | | - |
988 | | - |
989 | | - |
990 | | - |
991 | | - |
992 | QRegExp addrPortPattern(QLatin1String("(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)")); | - |
993 | if (addrPortPattern.indexIn(replyText) == -1) { partially evaluated: addrPortPattern.indexIn(replyText) == -1 no Evaluation Count:0 | yes Evaluation Count:33 |
| 0-33 |
994 | | - |
995 | | - |
996 | | - |
997 | | - |
998 | } else { | 0 |
999 | QStringList lst = addrPortPattern.capturedTexts(); | - |
1000 | QString host = lst[1] + QLatin1Char('.') + lst[2] + QLatin1Char('.') + lst[3] + QLatin1Char('.') + lst[4]; | - |
1001 | quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt(); | - |
1002 | waitForDtpToConnect = true; | - |
1003 | dtp.connectToHost(host, port); | - |
1004 | } executed: } Execution Count:33 | 33 |
1005 | } else if (replyCodeInt == 229) { partially evaluated: replyCodeInt == 229 no Evaluation Count:0 | yes Evaluation Count:272 |
| 0-272 |
1006 | | - |
1007 | int portPos = replyText.indexOf(QLatin1Char('(')); | - |
1008 | if (portPos == -1) { never evaluated: portPos == -1 | 0 |
1009 | | - |
1010 | | - |
1011 | | - |
1012 | | - |
1013 | } else { | 0 |
1014 | ++portPos; | - |
1015 | QChar delimiter = replyText.at(portPos); | - |
1016 | QStringList epsvParameters = replyText.mid(portPos).split(delimiter); | - |
1017 | | - |
1018 | waitForDtpToConnect = true; | - |
1019 | dtp.connectToHost(commandSocket.peerAddress().toString(), | - |
1020 | epsvParameters.at(3).toInt()); | - |
1021 | } | 0 |
1022 | | - |
1023 | } else if (replyCodeInt == 230) { evaluated: replyCodeInt == 230 yes Evaluation Count:35 | yes Evaluation Count:237 |
| 35-237 |
1024 | if (currentCmd.startsWith(QLatin1String("USER ")) && pendingCommands.count()>0 && partially evaluated: currentCmd.startsWith(QLatin1String("USER ")) no Evaluation Count:0 | yes Evaluation Count:35 |
never evaluated: pendingCommands.count()>0 | 0-35 |
1025 | pendingCommands.first().startsWith(QLatin1String("PASS "))) { never evaluated: pendingCommands.first().startsWith(QLatin1String("PASS ")) | 0 |
1026 | | - |
1027 | pendingCommands.pop_front(); | - |
1028 | } | 0 |
1029 | | - |
1030 | connectState(QFtp::LoggedIn); | - |
1031 | } else if (replyCodeInt == 213) { executed: } Execution Count:35 evaluated: replyCodeInt == 213 yes Evaluation Count:22 | yes Evaluation Count:215 |
| 22-215 |
1032 | | - |
1033 | if (currentCmd.startsWith(QLatin1String("SIZE "))) partially evaluated: currentCmd.startsWith(QLatin1String("SIZE ")) yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-22 |
1034 | dtp.setBytesTotal(replyText.simplified().toLongLong()); executed: dtp.setBytesTotal(replyText.simplified().toLongLong()); Execution Count:22 | 22 |
1035 | } else if (replyCode[0]==1 && currentCmd.startsWith(QLatin1String("STOR "))) { executed: } Execution Count:22 evaluated: replyCode[0]==1 yes Evaluation Count:32 | yes Evaluation Count:183 |
evaluated: currentCmd.startsWith(QLatin1String("STOR ")) yes Evaluation Count:11 | yes Evaluation Count:21 |
| 11-183 |
1036 | dtp.waitForConnection(); | - |
1037 | dtp.writeData(); | - |
1038 | } executed: } Execution Count:11 | 11 |
1039 | | - |
1040 | | - |
1041 | switch (state) { | - |
1042 | case Begin: | - |
1043 | | - |
1044 | break; | 0 |
1045 | case Success: | - |
1046 | | - |
1047 | state = Idle; | - |
1048 | | - |
1049 | case Idle: code before this statement executed: case Idle: Execution Count:282 | 282 |
1050 | if (dtp.hasError()) { partially evaluated: dtp.hasError() no Evaluation Count:0 | yes Evaluation Count:318 |
| 0-318 |
1051 | error(QFtp::UnknownError, dtp.errorMessage()); | - |
1052 | dtp.clearError(); | - |
1053 | } | 0 |
1054 | startNextCmd(); | - |
1055 | break; executed: break; Execution Count:318 | 318 |
1056 | case Waiting: | - |
1057 | | - |
1058 | break; executed: break; Execution Count:68 | 68 |
1059 | case Failure: | - |
1060 | | - |
1061 | | - |
1062 | if (currentCmd.startsWith(QLatin1String("EPSV"))) { partially evaluated: currentCmd.startsWith(QLatin1String("EPSV")) no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
1063 | transferConnectionExtended = false; | - |
1064 | pendingCommands.prepend(QLatin1String("PASV\r\n")); | - |
1065 | } else if (currentCmd.startsWith(QLatin1String("EPRT"))) { partially evaluated: currentCmd.startsWith(QLatin1String("EPRT")) no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
1066 | transferConnectionExtended = false; | - |
1067 | pendingCommands.prepend(QLatin1String("PORT\r\n")); | - |
1068 | } else { | 0 |
1069 | error(QFtp::UnknownError, replyText); | - |
1070 | } executed: } Execution Count:16 | 16 |
1071 | if (state != Waiting) { partially evaluated: state != Waiting yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
1072 | state = Idle; | - |
1073 | startNextCmd(); | - |
1074 | } executed: } Execution Count:16 | 16 |
1075 | break; executed: break; Execution Count:16 | 16 |
1076 | } | - |
1077 | | - |
1078 | | - |
1079 | | - |
1080 | return true; executed: return true; Execution Count:402 | 402 |
1081 | } | - |
1082 | | - |
1083 | | - |
1084 | | - |
1085 | | - |
1086 | | - |
1087 | | - |
1088 | | - |
1089 | bool QFtpPI::startNextCmd() | - |
1090 | { | - |
1091 | if (waitForDtpToConnect) evaluated: waitForDtpToConnect yes Evaluation Count:33 | yes Evaluation Count:534 |
| 33-534 |
1092 | | - |
1093 | return true; executed: return true; Execution Count:33 | 33 |
1094 | | - |
1095 | | - |
1096 | | - |
1097 | | - |
1098 | | - |
1099 | if (pendingCommands.isEmpty()) { evaluated: pendingCommands.isEmpty() yes Evaluation Count:199 | yes Evaluation Count:335 |
| 199-335 |
1100 | currentCmd.clear(); | - |
1101 | finished(replyText); | - |
1102 | return false; executed: return false; Execution Count:199 | 199 |
1103 | } | - |
1104 | currentCmd = pendingCommands.first(); | - |
1105 | | - |
1106 | | - |
1107 | | - |
1108 | | - |
1109 | | - |
1110 | QHostAddress address = commandSocket.localAddress(); | - |
1111 | if (currentCmd.startsWith(QLatin1String("PORT"))) { partially evaluated: currentCmd.startsWith(QLatin1String("PORT")) no Evaluation Count:0 | yes Evaluation Count:335 |
| 0-335 |
1112 | if ((address.protocol() == QTcpSocket::IPv6Protocol) && transferConnectionExtended) { never evaluated: (address.protocol() == QTcpSocket::IPv6Protocol) never evaluated: transferConnectionExtended | 0 |
1113 | int port = dtp.setupListener(address); | - |
1114 | currentCmd = QLatin1String("EPRT |"); | - |
1115 | currentCmd += (address.protocol() == QTcpSocket::IPv4Protocol) ? QLatin1Char('1') : QLatin1Char('2'); never evaluated: (address.protocol() == QTcpSocket::IPv4Protocol) | 0 |
1116 | currentCmd += QLatin1Char('|') + address.toString() + QLatin1Char('|') + QString::number(port); | - |
1117 | currentCmd += QLatin1Char('|'); | - |
1118 | } else if (address.protocol() == QTcpSocket::IPv4Protocol) { never evaluated: address.protocol() == QTcpSocket::IPv4Protocol | 0 |
1119 | int port = dtp.setupListener(address); | - |
1120 | QString portArg; | - |
1121 | quint32 ip = address.toIPv4Address(); | - |
1122 | portArg += QString::number((ip & 0xff000000) >> 24); | - |
1123 | portArg += QLatin1Char(',') + QString::number((ip & 0xff0000) >> 16); | - |
1124 | portArg += QLatin1Char(',') + QString::number((ip & 0xff00) >> 8); | - |
1125 | portArg += QLatin1Char(',') + QString::number(ip & 0xff); | - |
1126 | portArg += QLatin1Char(',') + QString::number((port & 0xff00) >> 8); | - |
1127 | portArg += QLatin1Char(',') + QString::number(port & 0xff); | - |
1128 | | - |
1129 | currentCmd = QLatin1String("PORT "); | - |
1130 | currentCmd += portArg; | - |
1131 | } else { | 0 |
1132 | | - |
1133 | | - |
1134 | return false; never executed: return false; | 0 |
1135 | } | - |
1136 | | - |
1137 | currentCmd += QLatin1String("\r\n"); | - |
1138 | } else if (currentCmd.startsWith(QLatin1String("PASV"))) { evaluated: currentCmd.startsWith(QLatin1String("PASV")) yes Evaluation Count:33 | yes Evaluation Count:302 |
| 0-302 |
1139 | if ((address.protocol() == QTcpSocket::IPv6Protocol) && transferConnectionExtended) partially evaluated: (address.protocol() == QTcpSocket::IPv6Protocol) no Evaluation Count:0 | yes Evaluation Count:33 |
never evaluated: transferConnectionExtended | 0-33 |
1140 | currentCmd = QLatin1String("EPSV\r\n"); never executed: currentCmd = QLatin1String("EPSV\r\n"); | 0 |
1141 | } executed: } Execution Count:33 | 33 |
1142 | | - |
1143 | pendingCommands.pop_front(); | - |
1144 | | - |
1145 | | - |
1146 | | - |
1147 | state = Waiting; | - |
1148 | commandSocket.write(currentCmd.toLatin1()); | - |
1149 | return true; executed: return true; Execution Count:335 | 335 |
1150 | } | - |
1151 | | - |
1152 | void QFtpPI::dtpConnectState(int s) | - |
1153 | { | - |
1154 | switch (s) { | - |
1155 | case QFtpDTP::CsClosed: | - |
1156 | if (waitForDtpToClose) { partially evaluated: waitForDtpToClose no Evaluation Count:0 | yes Evaluation Count:33 |
| 0-33 |
1157 | | - |
1158 | if (processReply()) never evaluated: processReply() | 0 |
1159 | replyText = QLatin1String(""); never executed: replyText = QLatin1String(""); | 0 |
1160 | else | - |
1161 | return; | 0 |
1162 | } | - |
1163 | waitForDtpToClose = false; | - |
1164 | readyRead(); | - |
1165 | return; executed: return; Execution Count:33 | 33 |
1166 | case QFtpDTP::CsConnected: | - |
1167 | waitForDtpToConnect = false; | - |
1168 | startNextCmd(); | - |
1169 | return; executed: return; Execution Count:33 | 33 |
1170 | case QFtpDTP::CsHostNotFound: | - |
1171 | case QFtpDTP::CsConnectionRefused: | - |
1172 | error(QFtp::ConnectionRefused, | - |
1173 | QFtp::tr("Data Connection refused")); | - |
1174 | startNextCmd(); | - |
1175 | return; | 0 |
1176 | default: | - |
1177 | return; | 0 |
1178 | } | - |
1179 | } | 0 |
1180 | | - |
1181 | | - |
1182 | | - |
1183 | | - |
1184 | | - |
1185 | | - |
1186 | | - |
1187 | | - |
1188 | | - |
1189 | | - |
1190 | class QFtpPrivate : public QObjectPrivate | - |
1191 | { | - |
1192 | inline QFtp* q_func() { return static_cast<QFtp *>(q_ptr); } inline const QFtp* q_func() const { return static_cast<const QFtp *>(q_ptr); } friend class QFtp; | - |
1193 | public: | - |
1194 | | - |
1195 | inline QFtpPrivate() : close_waitForStateChange(false), state(QFtp::Unconnected), | - |
1196 | transferMode(QFtp::Passive), error(QFtp::NoError) | - |
1197 | { } executed: } Execution Count:37 | 37 |
1198 | | - |
1199 | ~QFtpPrivate() { while (!pending.isEmpty()) delete pending.takeFirst(); } executed: delete pending.takeFirst(); Execution Count:35 executed: } Execution Count:35 evaluated: !pending.isEmpty() yes Evaluation Count:35 | yes Evaluation Count:35 |
| 35 |
1200 | | - |
1201 | | - |
1202 | void _q_startNextCommand(); | - |
1203 | void _q_piFinished(const QString&); | - |
1204 | void _q_piError(int, const QString&); | - |
1205 | void _q_piConnectState(int); | - |
1206 | void _q_piFtpReply(int, const QString&); | - |
1207 | | - |
1208 | int addCommand(QFtpCommand *cmd); | - |
1209 | | - |
1210 | QFtpPI pi; | - |
1211 | QList<QFtpCommand *> pending; | - |
1212 | bool close_waitForStateChange; | - |
1213 | QFtp::State state; | - |
1214 | QFtp::TransferMode transferMode; | - |
1215 | QFtp::Error error; | - |
1216 | QString errorString; | - |
1217 | | - |
1218 | QString host; | - |
1219 | quint16 port; | - |
1220 | QString proxyHost; | - |
1221 | quint16 proxyPort; | - |
1222 | }; | - |
1223 | | - |
1224 | int QFtpPrivate::addCommand(QFtpCommand *cmd) | - |
1225 | { | - |
1226 | pending.append(cmd); | - |
1227 | | - |
1228 | if (pending.count() == 1) { evaluated: pending.count() == 1 yes Evaluation Count:191 | yes Evaluation Count:90 |
| 90-191 |
1229 | | - |
1230 | QTimer::singleShot(0, q_func(), "1""_q_startNextCommand()"); | - |
1231 | } executed: } Execution Count:191 | 191 |
1232 | return cmd->id; executed: return cmd->id; Execution Count:281 | 281 |
1233 | } | - |
1234 | QFtp::QFtp(QObject *parent) | - |
1235 | : QObject(*new QFtpPrivate, parent) | - |
1236 | { | - |
1237 | QFtpPrivate * const d = d_func(); | - |
1238 | d->errorString = tr("Unknown error"); | - |
1239 | | - |
1240 | connect(&d->pi, "2""connectState(int)", | - |
1241 | "1""_q_piConnectState(int)"); | - |
1242 | connect(&d->pi, "2""finished(QString)", | - |
1243 | "1""_q_piFinished(QString)"); | - |
1244 | connect(&d->pi, "2""error(int,QString)", | - |
1245 | "1""_q_piError(int,QString)"); | - |
1246 | connect(&d->pi, "2""rawFtpReply(int,QString)", | - |
1247 | "1""_q_piFtpReply(int,QString)"); | - |
1248 | | - |
1249 | connect(&d->pi.dtp, "2""readyRead()", | - |
1250 | "2""readyRead()"); | - |
1251 | connect(&d->pi.dtp, "2""dataTransferProgress(qint64,qint64)", | - |
1252 | "2""dataTransferProgress(qint64,qint64)"); | - |
1253 | connect(&d->pi.dtp, "2""listInfo(QUrlInfo)", | - |
1254 | "2""listInfo(QUrlInfo)"); | - |
1255 | } executed: } Execution Count:37 | 37 |
1256 | int QFtp::connectToHost(const QString &host, quint16 port) | - |
1257 | { | - |
1258 | QStringList cmds; | - |
1259 | cmds << host; | - |
1260 | cmds << QString::number((uint)port); | - |
1261 | int id = d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds)); | - |
1262 | d_func()->pi.transferConnectionExtended = true; | - |
1263 | return id; executed: return id; Execution Count:37 | 37 |
1264 | } | - |
1265 | int QFtp::login(const QString &user, const QString &password) | - |
1266 | { | - |
1267 | QStringList cmds; | - |
1268 | cmds << (QLatin1String("USER ") + (user.isNull() ? QLatin1String("anonymous") : user) + QLatin1String("\r\n")); | - |
1269 | cmds << (QLatin1String("PASS ") + (password.isNull() ? QLatin1String("anonymous@") : password) + QLatin1String("\r\n")); | - |
1270 | return d_func()->addCommand(new QFtpCommand(Login, cmds)); executed: return d_func()->addCommand(new QFtpCommand(Login, cmds)); Execution Count:37 | 37 |
1271 | } | - |
1272 | int QFtp::close() | - |
1273 | { | - |
1274 | return d_func()->addCommand(new QFtpCommand(Close, QStringList(QLatin1String("QUIT\r\n")))); executed: return d_func()->addCommand(new QFtpCommand(Close, QStringList(QLatin1String("QUIT\r\n")))); Execution Count:72 | 72 |
1275 | } | - |
1276 | | - |
1277 | | - |
1278 | | - |
1279 | | - |
1280 | | - |
1281 | | - |
1282 | | - |
1283 | int QFtp::setTransferMode(TransferMode mode) | - |
1284 | { | - |
1285 | int id = d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList())); | - |
1286 | d_func()->pi.transferConnectionExtended = true; | - |
1287 | d_func()->transferMode = mode; | - |
1288 | return id; never executed: return id; | 0 |
1289 | } | - |
1290 | int QFtp::setProxy(const QString &host, quint16 port) | - |
1291 | { | - |
1292 | QStringList args; | - |
1293 | args << host << QString::number(port); | - |
1294 | return d_func()->addCommand(new QFtpCommand(SetProxy, args)); executed: return d_func()->addCommand(new QFtpCommand(SetProxy, args)); Execution Count:2 | 2 |
1295 | } | - |
1296 | int QFtp::list(const QString &dir) | - |
1297 | { | - |
1298 | QStringList cmds; | - |
1299 | cmds << QLatin1String("TYPE A\r\n"); | - |
1300 | cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); | - |
1301 | if (dir.isEmpty()) never evaluated: dir.isEmpty() | 0 |
1302 | cmds << QLatin1String("LIST\r\n"); never executed: cmds << QLatin1String("LIST\r\n"); | 0 |
1303 | else | - |
1304 | cmds << (QLatin1String("LIST ") + dir + QLatin1String("\r\n")); never executed: cmds << (QLatin1String("LIST ") + dir + QLatin1String("\r\n")); | 0 |
1305 | return d_func()->addCommand(new QFtpCommand(List, cmds)); never executed: return d_func()->addCommand(new QFtpCommand(List, cmds)); | 0 |
1306 | } | - |
1307 | int QFtp::cd(const QString &dir) | - |
1308 | { | - |
1309 | return d_func()->addCommand(new QFtpCommand(Cd, QStringList(QLatin1String("CWD ") + dir + QLatin1String("\r\n")))); never executed: return d_func()->addCommand(new QFtpCommand(Cd, QStringList(QLatin1String("CWD ") + dir + QLatin1String("\r\n")))); | 0 |
1310 | } | - |
1311 | int QFtp::get(const QString &file, QIODevice *dev, TransferType type) | - |
1312 | { | - |
1313 | QStringList cmds; | - |
1314 | if (type == Binary) partially evaluated: type == Binary yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-22 |
1315 | cmds << QLatin1String("TYPE I\r\n"); executed: cmds << QLatin1String("TYPE I\r\n"); Execution Count:22 | 22 |
1316 | else | - |
1317 | cmds << QLatin1String("TYPE A\r\n"); never executed: cmds << QLatin1String("TYPE A\r\n"); | 0 |
1318 | cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n"); | - |
1319 | cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); | - |
1320 | cmds << QLatin1String("RETR ") + file + QLatin1String("\r\n"); | - |
1321 | return d_func()->addCommand(new QFtpCommand(Get, cmds, dev)); executed: return d_func()->addCommand(new QFtpCommand(Get, cmds, dev)); Execution Count:22 | 22 |
1322 | } | - |
1323 | int QFtp::put(const QByteArray &data, const QString &file, TransferType type) | - |
1324 | { | - |
1325 | QStringList cmds; | - |
1326 | if (type == Binary) never evaluated: type == Binary | 0 |
1327 | cmds << QLatin1String("TYPE I\r\n"); never executed: cmds << QLatin1String("TYPE I\r\n"); | 0 |
1328 | else | - |
1329 | cmds << QLatin1String("TYPE A\r\n"); never executed: cmds << QLatin1String("TYPE A\r\n"); | 0 |
1330 | cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); | - |
1331 | cmds << QLatin1String("ALLO ") + QString::number(data.size()) + QLatin1String("\r\n"); | - |
1332 | cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n"); | - |
1333 | return d_func()->addCommand(new QFtpCommand(Put, cmds, data)); never executed: return d_func()->addCommand(new QFtpCommand(Put, cmds, data)); | 0 |
1334 | } | - |
1335 | int QFtp::put(QIODevice *dev, const QString &file, TransferType type) | - |
1336 | { | - |
1337 | QStringList cmds; | - |
1338 | if (type == Binary) partially evaluated: type == Binary yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
1339 | cmds << QLatin1String("TYPE I\r\n"); executed: cmds << QLatin1String("TYPE I\r\n"); Execution Count:11 | 11 |
1340 | else | - |
1341 | cmds << QLatin1String("TYPE A\r\n"); never executed: cmds << QLatin1String("TYPE A\r\n"); | 0 |
1342 | cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); | - |
1343 | if (!dev->isSequential()) partially evaluated: !dev->isSequential() yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
1344 | cmds << QLatin1String("ALLO ") + QString::number(dev->size()) + QLatin1String("\r\n"); executed: cmds << QLatin1String("ALLO ") + QString::number(dev->size()) + QLatin1String("\r\n"); Execution Count:11 | 11 |
1345 | cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n"); | - |
1346 | return d_func()->addCommand(new QFtpCommand(Put, cmds, dev)); executed: return d_func()->addCommand(new QFtpCommand(Put, cmds, dev)); Execution Count:11 | 11 |
1347 | } | - |
1348 | int QFtp::remove(const QString &file) | - |
1349 | { | - |
1350 | return d_func()->addCommand(new QFtpCommand(Remove, QStringList(QLatin1String("DELE ") + file + QLatin1String("\r\n")))); never executed: return d_func()->addCommand(new QFtpCommand(Remove, QStringList(QLatin1String("DELE ") + file + QLatin1String("\r\n")))); | 0 |
1351 | } | - |
1352 | int QFtp::mkdir(const QString &dir) | - |
1353 | { | - |
1354 | return d_func()->addCommand(new QFtpCommand(Mkdir, QStringList(QLatin1String("MKD ") + dir + QLatin1String("\r\n")))); never executed: return d_func()->addCommand(new QFtpCommand(Mkdir, QStringList(QLatin1String("MKD ") + dir + QLatin1String("\r\n")))); | 0 |
1355 | } | - |
1356 | int QFtp::rmdir(const QString &dir) | - |
1357 | { | - |
1358 | return d_func()->addCommand(new QFtpCommand(Rmdir, QStringList(QLatin1String("RMD ") + dir + QLatin1String("\r\n")))); never executed: return d_func()->addCommand(new QFtpCommand(Rmdir, QStringList(QLatin1String("RMD ") + dir + QLatin1String("\r\n")))); | 0 |
1359 | } | - |
1360 | int QFtp::rename(const QString &oldname, const QString &newname) | - |
1361 | { | - |
1362 | QStringList cmds; | - |
1363 | cmds << QLatin1String("RNFR ") + oldname + QLatin1String("\r\n"); | - |
1364 | cmds << QLatin1String("RNTO ") + newname + QLatin1String("\r\n"); | - |
1365 | return d_func()->addCommand(new QFtpCommand(Rename, cmds)); never executed: return d_func()->addCommand(new QFtpCommand(Rename, cmds)); | 0 |
1366 | } | - |
1367 | int QFtp::rawCommand(const QString &command) | - |
1368 | { | - |
1369 | QString cmd = command.trimmed() + QLatin1String("\r\n"); | - |
1370 | return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd))); executed: return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd))); Execution Count:100 | 100 |
1371 | } | - |
1372 | qint64 QFtp::bytesAvailable() const | - |
1373 | { | - |
1374 | return d_func()->pi.dtp.bytesAvailable(); executed: return d_func()->pi.dtp.bytesAvailable(); Execution Count:1027 | 1027 |
1375 | } | - |
1376 | qint64 QFtp::read(char *data, qint64 maxlen) | - |
1377 | { | - |
1378 | return d_func()->pi.dtp.read(data, maxlen); never executed: return d_func()->pi.dtp.read(data, maxlen); | 0 |
1379 | } | - |
1380 | QByteArray QFtp::readAll() | - |
1381 | { | - |
1382 | return d_func()->pi.dtp.readAll(); executed: return d_func()->pi.dtp.readAll(); Execution Count:788 | 788 |
1383 | } | - |
1384 | void QFtp::abort() | - |
1385 | { | - |
1386 | if (d_func()->pending.isEmpty()) evaluated: d_func()->pending.isEmpty() yes Evaluation Count:35 | yes Evaluation Count:1 |
| 1-35 |
1387 | return; executed: return; Execution Count:35 | 35 |
1388 | | - |
1389 | clearPendingCommands(); | - |
1390 | d_func()->pi.abort(); | - |
1391 | } executed: } Execution Count:1 | 1 |
1392 | int QFtp::currentId() const | - |
1393 | { | - |
1394 | if (d_func()->pending.isEmpty()) partially evaluated: d_func()->pending.isEmpty() no Evaluation Count:0 | yes Evaluation Count:97 |
| 0-97 |
1395 | return 0; never executed: return 0; | 0 |
1396 | return d_func()->pending.first()->id; executed: return d_func()->pending.first()->id; Execution Count:97 | 97 |
1397 | } | - |
1398 | QFtp::Command QFtp::currentCommand() const | - |
1399 | { | - |
1400 | if (d_func()->pending.isEmpty()) partially evaluated: d_func()->pending.isEmpty() no Evaluation Count:0 | yes Evaluation Count:409 |
| 0-409 |
1401 | return None; never executed: return None; | 0 |
1402 | return d_func()->pending.first()->command; executed: return d_func()->pending.first()->command; Execution Count:409 | 409 |
1403 | } | - |
1404 | QIODevice* QFtp::currentDevice() const | - |
1405 | { | - |
1406 | if (d_func()->pending.isEmpty()) never evaluated: d_func()->pending.isEmpty() | 0 |
1407 | return 0; never executed: return 0; | 0 |
1408 | QFtpCommand *c = d_func()->pending.first(); | - |
1409 | if (c->is_ba) never evaluated: c->is_ba | 0 |
1410 | return 0; never executed: return 0; | 0 |
1411 | return c->data.dev; never executed: return c->data.dev; | 0 |
1412 | } | - |
1413 | bool QFtp::hasPendingCommands() const | - |
1414 | { | - |
1415 | return d_func()->pending.count() > 1; never executed: return d_func()->pending.count() > 1; | 0 |
1416 | } | - |
1417 | void QFtp::clearPendingCommands() | - |
1418 | { | - |
1419 | | - |
1420 | while (d_func()->pending.count() > 1) evaluated: d_func()->pending.count() > 1 yes Evaluation Count:4 | yes Evaluation Count:8 |
| 4-8 |
1421 | delete d_func()->pending.takeLast(); executed: delete d_func()->pending.takeLast(); Execution Count:4 | 4 |
1422 | } executed: } Execution Count:8 | 8 |
1423 | QFtp::State QFtp::state() const | - |
1424 | { | - |
1425 | return d_func()->state; executed: return d_func()->state; Execution Count:78 | 78 |
1426 | } | - |
1427 | QFtp::Error QFtp::error() const | - |
1428 | { | - |
1429 | return d_func()->error; executed: return d_func()->error; Execution Count:141 | 141 |
1430 | } | - |
1431 | QString QFtp::errorString() const | - |
1432 | { | - |
1433 | return d_func()->errorString; executed: return d_func()->errorString; Execution Count:5 | 5 |
1434 | } | - |
1435 | | - |
1436 | | - |
1437 | | - |
1438 | void QFtpPrivate::_q_startNextCommand() | - |
1439 | { | - |
1440 | QFtp * const q = q_func(); | - |
1441 | if (pending.isEmpty()) partially evaluated: pending.isEmpty() no Evaluation Count:0 | yes Evaluation Count:240 |
| 0-240 |
1442 | return; | 0 |
1443 | QFtpCommand *c = pending.first(); | - |
1444 | | - |
1445 | error = QFtp::NoError; | - |
1446 | errorString = QLatin1String("Unknown error"); | - |
1447 | | - |
1448 | if (q->bytesAvailable()) partially evaluated: q->bytesAvailable() no Evaluation Count:0 | yes Evaluation Count:240 |
| 0-240 |
1449 | q->readAll(); never executed: q->readAll(); | 0 |
1450 | q->commandStarted(c->id); | - |
1451 | | - |
1452 | | - |
1453 | | - |
1454 | if (c->command == QFtp::Login && !proxyHost.isEmpty()) { evaluated: c->command == QFtp::Login yes Evaluation Count:36 | yes Evaluation Count:204 |
evaluated: !proxyHost.isEmpty() yes Evaluation Count:2 | yes Evaluation Count:34 |
| 2-204 |
1455 | QString loginString = c->rawCmds.first().trimmed(); | - |
1456 | loginString += QLatin1Char('@') + host; | - |
1457 | if (port && port != 21) partially evaluated: port yes Evaluation Count:2 | no Evaluation Count:0 |
partially evaluated: port != 21 no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
1458 | loginString += QLatin1Char(':') + QString::number(port); never executed: loginString += QLatin1Char(':') + QString::number(port); | 0 |
1459 | loginString += QLatin1String("\r\n"); | - |
1460 | c->rawCmds[0] = loginString; | - |
1461 | } executed: } Execution Count:2 | 2 |
1462 | | - |
1463 | if (c->command == QFtp::SetTransferMode) { partially evaluated: c->command == QFtp::SetTransferMode no Evaluation Count:0 | yes Evaluation Count:240 |
| 0-240 |
1464 | _q_piFinished(QLatin1String("Transfer mode set")); | - |
1465 | } else if (c->command == QFtp::SetProxy) { evaluated: c->command == QFtp::SetProxy yes Evaluation Count:2 | yes Evaluation Count:238 |
| 0-238 |
1466 | proxyHost = c->rawCmds[0]; | - |
1467 | proxyPort = c->rawCmds[1].toUInt(); | - |
1468 | c->rawCmds.clear(); | - |
1469 | _q_piFinished(QLatin1String("Proxy set to ") + proxyHost + QLatin1Char(':') + QString::number(proxyPort)); | - |
1470 | } else if (c->command == QFtp::ConnectToHost) { executed: } Execution Count:2 evaluated: c->command == QFtp::ConnectToHost yes Evaluation Count:37 | yes Evaluation Count:201 |
| 2-201 |
1471 | | - |
1472 | | - |
1473 | pi.setProperty("_q_networksession", q->property("_q_networksession")); | - |
1474 | | - |
1475 | if (!proxyHost.isEmpty()) { evaluated: !proxyHost.isEmpty() yes Evaluation Count:2 | yes Evaluation Count:35 |
| 2-35 |
1476 | host = c->rawCmds[0]; | - |
1477 | port = c->rawCmds[1].toUInt(); | - |
1478 | pi.connectToHost(proxyHost, proxyPort); | - |
1479 | } else { executed: } Execution Count:2 | 2 |
1480 | pi.connectToHost(c->rawCmds[0], c->rawCmds[1].toUInt()); | - |
1481 | } executed: } Execution Count:35 | 35 |
1482 | } else { | - |
1483 | if (c->command == QFtp::Put) { evaluated: c->command == QFtp::Put yes Evaluation Count:11 | yes Evaluation Count:190 |
| 11-190 |
1484 | if (c->is_ba) { partially evaluated: c->is_ba no Evaluation Count:0 | yes Evaluation Count:11 |
| 0-11 |
1485 | pi.dtp.setData(c->data.ba); | - |
1486 | pi.dtp.setBytesTotal(c->data.ba->size()); | - |
1487 | } else if (c->data.dev && (c->data.dev->isOpen() || c->data.dev->open(QIODevice::ReadOnly))) { partially evaluated: c->data.dev yes Evaluation Count:11 | no Evaluation Count:0 |
partially evaluated: c->data.dev->isOpen() yes Evaluation Count:11 | no Evaluation Count:0 |
never evaluated: c->data.dev->open(QIODevice::ReadOnly) | 0-11 |
1488 | pi.dtp.setDevice(c->data.dev); | - |
1489 | if (c->data.dev->isSequential()) { partially evaluated: c->data.dev->isSequential() no Evaluation Count:0 | yes Evaluation Count:11 |
| 0-11 |
1490 | pi.dtp.setBytesTotal(0); | - |
1491 | pi.dtp.connect(c->data.dev, "2""readyRead()", "1""dataReadyRead()"); | - |
1492 | pi.dtp.connect(c->data.dev, "2""readChannelFinished()", "1""dataReadyRead()"); | - |
1493 | } else { | 0 |
1494 | pi.dtp.setBytesTotal(c->data.dev->size()); | - |
1495 | } executed: } Execution Count:11 | 11 |
1496 | } | - |
1497 | } else if (c->command == QFtp::Get) { evaluated: c->command == QFtp::Get yes Evaluation Count:22 | yes Evaluation Count:168 |
| 22-168 |
1498 | if (!c->is_ba && c->data.dev) { partially evaluated: !c->is_ba yes Evaluation Count:22 | no Evaluation Count:0 |
partially evaluated: c->data.dev no Evaluation Count:0 | yes Evaluation Count:22 |
| 0-22 |
1499 | pi.dtp.setDevice(c->data.dev); | - |
1500 | } | 0 |
1501 | } else if (c->command == QFtp::Close) { executed: } Execution Count:22 evaluated: c->command == QFtp::Close yes Evaluation Count:35 | yes Evaluation Count:133 |
| 22-133 |
1502 | state = QFtp::Closing; | - |
1503 | q->stateChanged(state); | - |
1504 | } executed: } Execution Count:35 | 35 |
1505 | pi.sendCommands(c->rawCmds); | - |
1506 | } executed: } Execution Count:201 | 201 |
1507 | } | - |
1508 | | - |
1509 | | - |
1510 | | - |
1511 | void QFtpPrivate::_q_piFinished(const QString&) | - |
1512 | { | - |
1513 | if (pending.isEmpty()) evaluated: pending.isEmpty() yes Evaluation Count:4 | yes Evaluation Count:267 |
| 4-267 |
1514 | return; executed: return; Execution Count:4 | 4 |
1515 | QFtpCommand *c = pending.first(); | - |
1516 | | - |
1517 | if (c->command == QFtp::Close) { evaluated: c->command == QFtp::Close yes Evaluation Count:69 | yes Evaluation Count:198 |
| 69-198 |
1518 | | - |
1519 | | - |
1520 | | - |
1521 | | - |
1522 | if (state != QFtp::Unconnected) { evaluated: state != QFtp::Unconnected yes Evaluation Count:35 | yes Evaluation Count:34 |
| 34-35 |
1523 | close_waitForStateChange = true; | - |
1524 | return; executed: return; Execution Count:35 | 35 |
1525 | } | - |
1526 | } executed: } Execution Count:34 | 34 |
1527 | q_func()->commandFinished(c->id, false); | - |
1528 | pending.removeFirst(); | - |
1529 | | - |
1530 | delete c; | - |
1531 | | - |
1532 | if (pending.isEmpty()) { evaluated: pending.isEmpty() yes Evaluation Count:147 | yes Evaluation Count:85 |
| 85-147 |
1533 | q_func()->done(false); | - |
1534 | } else { executed: } Execution Count:147 | 147 |
1535 | _q_startNextCommand(); | - |
1536 | } executed: } Execution Count:85 | 85 |
1537 | } | - |
1538 | | - |
1539 | | - |
1540 | | - |
1541 | void QFtpPrivate::_q_piError(int errorCode, const QString &text) | - |
1542 | { | - |
1543 | QFtp * const q = q_func(); | - |
1544 | | - |
1545 | if (pending.isEmpty()) { partially evaluated: pending.isEmpty() no Evaluation Count:0 | yes Evaluation Count:18 |
| 0-18 |
1546 | QMessageLogger("access/qftp.cpp", 2355, __PRETTY_FUNCTION__).warning("QFtpPrivate::_q_piError was called without pending command!"); | - |
1547 | return; | 0 |
1548 | } | - |
1549 | | - |
1550 | QFtpCommand *c = pending.first(); | - |
1551 | | - |
1552 | | - |
1553 | if (c->command == QFtp::Get && pi.currentCommand().startsWith(QLatin1String("SIZE "))) { evaluated: c->command == QFtp::Get yes Evaluation Count:1 | yes Evaluation Count:17 |
partially evaluated: pi.currentCommand().startsWith(QLatin1String("SIZE ")) no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-17 |
1554 | pi.dtp.setBytesTotal(0); | - |
1555 | return; | 0 |
1556 | } else if (c->command==QFtp::Put && pi.currentCommand().startsWith(QLatin1String("ALLO "))) { evaluated: c->command==QFtp::Put yes Evaluation Count:11 | yes Evaluation Count:7 |
partially evaluated: pi.currentCommand().startsWith(QLatin1String("ALLO ")) yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
1557 | return; executed: return; Execution Count:11 | 11 |
1558 | } | - |
1559 | | - |
1560 | error = QFtp::Error(errorCode); | - |
1561 | switch (q->currentCommand()) { | - |
1562 | case QFtp::ConnectToHost: | - |
1563 | errorString = QString::fromLatin1("Connecting to host failed:\n%1") | - |
1564 | .arg(text); | - |
1565 | break; executed: break; Execution Count:1 | 1 |
1566 | case QFtp::Login: | - |
1567 | errorString = QString::fromLatin1("Login failed:\n%1") | - |
1568 | .arg(text); | - |
1569 | break; executed: break; Execution Count:1 | 1 |
1570 | case QFtp::List: | - |
1571 | errorString = QString::fromLatin1("Listing directory failed:\n%1") | - |
1572 | .arg(text); | - |
1573 | break; | 0 |
1574 | case QFtp::Cd: | - |
1575 | errorString = QString::fromLatin1("Changing directory failed:\n%1") | - |
1576 | .arg(text); | - |
1577 | break; | 0 |
1578 | case QFtp::Get: | - |
1579 | errorString = QString::fromLatin1("Downloading file failed:\n%1") | - |
1580 | .arg(text); | - |
1581 | break; executed: break; Execution Count:1 | 1 |
1582 | case QFtp::Put: | - |
1583 | errorString = QString::fromLatin1("Uploading file failed:\n%1") | - |
1584 | .arg(text); | - |
1585 | break; | 0 |
1586 | case QFtp::Remove: | - |
1587 | errorString = QString::fromLatin1("Removing file failed:\n%1") | - |
1588 | .arg(text); | - |
1589 | break; | 0 |
1590 | case QFtp::Mkdir: | - |
1591 | errorString = QString::fromLatin1("Creating directory failed:\n%1") | - |
1592 | .arg(text); | - |
1593 | break; | 0 |
1594 | case QFtp::Rmdir: | - |
1595 | errorString = QString::fromLatin1("Removing directory failed:\n%1") | - |
1596 | .arg(text); | - |
1597 | break; | 0 |
1598 | default: | - |
1599 | errorString = text; | - |
1600 | break; executed: break; Execution Count:4 | 4 |
1601 | } | - |
1602 | | - |
1603 | pi.clearPendingCommands(); | - |
1604 | q->clearPendingCommands(); | - |
1605 | q->commandFinished(c->id, true); | - |
1606 | | - |
1607 | pending.removeFirst(); | - |
1608 | delete c; | - |
1609 | if (pending.isEmpty()) partially evaluated: pending.isEmpty() yes Evaluation Count:7 | no Evaluation Count:0 |
| 0-7 |
1610 | q->done(true); executed: q->done(true); Execution Count:7 | 7 |
1611 | else | - |
1612 | _q_startNextCommand(); never executed: _q_startNextCommand(); | 0 |
1613 | } | - |
1614 | | - |
1615 | | - |
1616 | | - |
1617 | void QFtpPrivate::_q_piConnectState(int connectState) | - |
1618 | { | - |
1619 | state = QFtp::State(connectState); | - |
1620 | q_func()->stateChanged(state); | - |
1621 | if (close_waitForStateChange) { evaluated: close_waitForStateChange yes Evaluation Count:34 | yes Evaluation Count:145 |
| 34-145 |
1622 | close_waitForStateChange = false; | - |
1623 | _q_piFinished(QLatin1String("Connection closed")); | - |
1624 | } executed: } Execution Count:34 | 34 |
1625 | } executed: } Execution Count:179 | 179 |
1626 | | - |
1627 | | - |
1628 | | - |
1629 | void QFtpPrivate::_q_piFtpReply(int code, const QString &text) | - |
1630 | { | - |
1631 | if (q_func()->currentCommand() == QFtp::RawCommand) { evaluated: q_func()->currentCommand() == QFtp::RawCommand yes Evaluation Count:97 | yes Evaluation Count:305 |
| 97-305 |
1632 | pi.rawCommand = true; | - |
1633 | q_func()->rawCommandReply(code, text); | - |
1634 | } executed: } Execution Count:97 | 97 |
1635 | } executed: } Execution Count:402 | 402 |
1636 | | - |
1637 | | - |
1638 | | - |
1639 | | - |
1640 | | - |
1641 | QFtp::~QFtp() | - |
1642 | { | - |
1643 | abort(); executed: abort(); Execution Count:35 | 35 |
1644 | close(); | - |
1645 | } executed: } Execution Count:35 | 35 |
1646 | | - |
1647 | | - |
1648 | | - |
1649 | | - |
1650 | | - |
| | |