qftp.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qftp.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40//#define QFTPPI_DEBUG-
41//#define QFTPDTP_DEBUG-
42-
43#include "private/qftp_p.h"-
44#include "qabstractsocket.h"-
45-
46#ifndef QT_NO_FTP-
47-
48#include "qcoreapplication.h"-
49#include "qtcpsocket.h"-
50#include "qurlinfo_p.h"-
51#include "qstringlist.h"-
52#include "qregexp.h"-
53#include "qtimer.h"-
54#include "qfileinfo.h"-
55#include "qtcpserver.h"-
56#include "qlocale.h"-
57-
58QT_BEGIN_NAMESPACE-
59-
60class QFtpPI;-
61-
62/*-
63 The QFtpDTP (DTP = Data Transfer Process) controls all client side-
64 data transfer between the client and server.-
65*/-
66class QFtpDTP : public QObject-
67{-
68 Q_OBJECT-
69-
70public:-
71 enum ConnectState {-
72 CsHostFound,-
73 CsConnected,-
74 CsClosed,-
75 CsHostNotFound,-
76 CsConnectionRefused-
77 };-
78-
79 QFtpDTP(QFtpPI *p, QObject *parent = 0);-
80-
81 void setData(QByteArray *);-
82 void setDevice(QIODevice *);-
83 void writeData();-
84 void setBytesTotal(qint64 bytes);-
85-
86 bool hasError() const;-
87 QString errorMessage() const;-
88 void clearError();-
89-
90 void connectToHost(const QString & host, quint16 port);-
91 int setupListener(const QHostAddress &address);-
92 void waitForConnection();-
93-
94 QTcpSocket::SocketState state() const;-
95 qint64 bytesAvailable() const;-
96 qint64 read(char *data, qint64 maxlen);-
97 QByteArray readAll();-
98-
99 void abortConnection();-
100-
101 static bool parseDir(const QByteArray &buffer, const QString &userName, QUrlInfo *info);-
102-
103signals:-
104 void listInfo(const QUrlInfo&);-
105 void readyRead();-
106 void dataTransferProgress(qint64, qint64);-
107-
108 void connectState(int);-
109-
110private slots:-
111 void socketConnected();-
112 void socketReadyRead();-
113 void socketError(QAbstractSocket::SocketError);-
114 void socketConnectionClosed();-
115 void socketBytesWritten(qint64);-
116 void setupSocket();-
117-
118 void dataReadyRead();-
119-
120private:-
121 void clearData();-
122-
123 QTcpSocket *socket;-
124 QTcpServer listener;-
125-
126 QFtpPI *pi;-
127 QString err;-
128 qint64 bytesDone;-
129 qint64 bytesTotal;-
130 bool callWriteData;-
131-
132 // If is_ba is true, ba is used; ba is never 0.-
133 // Otherwise dev is used; dev can be 0 or not.-
134 union {-
135 QByteArray *ba;-
136 QIODevice *dev;-
137 } data;-
138 bool is_ba;-
139-
140 QByteArray bytesFromSocket;-
141};-
142-
143/**********************************************************************-
144 *-
145 * QFtpPI - Protocol Interpreter-
146 *-
147 *********************************************************************/-
148-
149class QFtpPI : public QObject-
150{-
151 Q_OBJECT-
152-
153public:-
154 QFtpPI(QObject *parent = 0);-
155-
156 void connectToHost(const QString &host, quint16 port);-
157-
158 bool sendCommands(const QStringList &cmds);-
159 bool sendCommand(const QString &cmd)-
160 { return sendCommands(QStringList(cmd)); }
never executed: return sendCommands(QStringList(cmd));
0
161-
162 void clearPendingCommands();-
163 void abort();-
164-
165 QString currentCommand() const-
166 { return currentCmd; }
executed 3234 times by 2 tests: return currentCmd;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3234
167-
168 bool rawCommand;-
169 bool transferConnectionExtended;-
170-
171 QFtpDTP dtp; // the PI has a DTP which is not the design of RFC 959, but it-
172 // makes the design simpler this way-
173signals:-
174 void connectState(int);-
175 void finished(const QString&);-
176 void error(int, const QString&);-
177 void rawFtpReply(int, const QString&);-
178-
179private slots:-
180 void hostFound();-
181 void connected();-
182 void connectionClosed();-
183 void delayedCloseFinished();-
184 void readyRead();-
185 void error(QAbstractSocket::SocketError);-
186-
187 void dtpConnectState(int);-
188-
189private:-
190 // the states are modelled after the generalized state diagram of RFC 959,-
191 // page 58-
192 enum State {-
193 Begin,-
194 Idle,-
195 Waiting,-
196 Success,-
197 Failure-
198 };-
199-
200 enum AbortState {-
201 None,-
202 AbortStarted,-
203 WaitForAbortToFinish-
204 };-
205-
206 bool processReply();-
207 bool startNextCmd();-
208-
209 QTcpSocket commandSocket;-
210 QString replyText;-
211 char replyCode[3];-
212 State state;-
213 AbortState abortState;-
214 QStringList pendingCommands;-
215 QString currentCmd;-
216-
217 bool waitForDtpToConnect;-
218 bool waitForDtpToClose;-
219-
220 QByteArray bytesFromSocket;-
221-
222 friend class QFtpDTP;-
223};-
224-
225/**********************************************************************-
226 *-
227 * QFtpCommand implemenatation-
228 *-
229 *********************************************************************/-
230class QFtpCommand-
231{-
232public:-
233 QFtpCommand(QFtp::Command cmd, const QStringList &raw, const QByteArray &ba);-
234 QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev = 0);-
235 ~QFtpCommand();-
236-
237 int id;-
238 QFtp::Command command;-
239 QStringList rawCmds;-
240-
241 // If is_ba is true, ba is used; ba is never 0.-
242 // Otherwise dev is used; dev can be 0 or not.-
243 union {-
244 QByteArray *ba;-
245 QIODevice *dev;-
246 } data;-
247 bool is_ba;-
248-
249 static QBasicAtomicInt idCounter;-
250};-
251-
252QBasicAtomicInt QFtpCommand::idCounter = Q_BASIC_ATOMIC_INITIALIZER(1);-
253-
254QFtpCommand::QFtpCommand(QFtp::Command cmd, const QStringList &raw, const QByteArray &ba)-
255 : command(cmd), rawCmds(raw), is_ba(true)-
256{-
257 id = idCounter.fetchAndAddRelaxed(1);-
258 data.ba = new QByteArray(ba);-
259}
executed 28 times by 1 test: end of block
Executed by:
  • tst_QFtp
28
260-
261QFtpCommand::QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev)-
262 : command(cmd), rawCmds(raw), is_ba(false)-
263{-
264 id = idCounter.fetchAndAddRelaxed(1);-
265 data.dev = dev;-
266}
executed 3395 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3395
267-
268QFtpCommand::~QFtpCommand()-
269{-
270 if (is_ba)
is_baDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 3391 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
28-3391
271 delete data.ba;
executed 28 times by 1 test: delete data.ba;
Executed by:
  • tst_QFtp
28
272}
executed 3419 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3419
273-
274/**********************************************************************-
275 *-
276 * QFtpDTP implemenatation-
277 *-
278 *********************************************************************/-
279QFtpDTP::QFtpDTP(QFtpPI *p, QObject *parent) :-
280 QObject(parent),-
281 socket(0),-
282 listener(this),-
283 pi(p),-
284 callWriteData(false)-
285{-
286 clearData();-
287 listener.setObjectName(QLatin1String("QFtpDTP active state server"));-
288 connect(&listener, SIGNAL(newConnection()), SLOT(setupSocket()));-
289}
executed 661 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
661
290-
291void QFtpDTP::setData(QByteArray *ba)-
292{-
293 is_ba = true;-
294 data.ba = ba;-
295}
executed 28 times by 1 test: end of block
Executed by:
  • tst_QFtp
28
296-
297void QFtpDTP::setDevice(QIODevice *dev)-
298{-
299 is_ba = false;-
300 data.dev = dev;-
301}
executed 55 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
55
302-
303void QFtpDTP::setBytesTotal(qint64 bytes)-
304{-
305 bytesTotal = bytes;-
306 bytesDone = 0;-
307 emit dataTransferProgress(bytesDone, bytesTotal);-
308}
executed 153 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
153
309-
310void QFtpDTP::connectToHost(const QString & host, quint16 port)-
311{-
312 bytesFromSocket.clear();-
313-
314 if (socket) {
socketDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 354 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
1-354
315 delete socket;-
316 socket = 0;-
317 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkReply
1
318 socket = new QTcpSocket(this);-
319#ifndef QT_NO_BEARERMANAGEMENT-
320 //copy network session down to the socket-
321 socket->setProperty("_q_networksession", property("_q_networksession"));-
322#endif-
323 socket->setObjectName(QLatin1String("QFtpDTP Passive state socket"));-
324 connect(socket, SIGNAL(connected()), SLOT(socketConnected()));-
325 connect(socket, SIGNAL(readyRead()), SLOT(socketReadyRead()));-
326 connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError)));-
327 connect(socket, SIGNAL(disconnected()), SLOT(socketConnectionClosed()));-
328 connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64)));-
329-
330 socket->connectToHost(host, port);-
331}
executed 355 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
332-
333int QFtpDTP::setupListener(const QHostAddress &address)-
334{-
335#ifndef QT_NO_BEARERMANAGEMENT-
336 //copy network session down to the socket-
337 listener.setProperty("_q_networksession", property("_q_networksession"));-
338#endif-
339 if (!listener.isListening() && !listener.listen(address, 0))
!listener.isListening()Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
!listener.listen(address, 0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
0-8
340 return -1;
never executed: return -1;
0
341 return listener.serverPort();
executed 8 times by 1 test: return listener.serverPort();
Executed by:
  • tst_QFtp
8
342}-
343-
344void QFtpDTP::waitForConnection()-
345{-
346 // This function is only interesting in Active transfer mode; it works-
347 // around a limitation in QFtp's design by blocking, waiting for an-
348 // incoming connection. For the default Passive mode, it does nothing.-
349 if (listener.isListening())
listener.isListening()Description
TRUEnever evaluated
FALSEevaluated 43 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-43
350 listener.waitForNewConnection();
never executed: listener.waitForNewConnection();
0
351}
executed 43 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
43
352-
353QTcpSocket::SocketState QFtpDTP::state() const-
354{-
355 return socket ? socket->state() : QTcpSocket::UnconnectedState;
executed 346 times by 2 tests: return socket ? socket->state() : QTcpSocket::UnconnectedState;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
346
356}-
357-
358qint64 QFtpDTP::bytesAvailable() const-
359{-
360 if (!socket || socket->state() != QTcpSocket::ConnectedState)
!socketDescription
TRUEevaluated 4292 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1879 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
socket->state(...ConnectedStateDescription
TRUEevaluated 1299 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 580 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
580-4292
361 return (qint64) bytesFromSocket.size();
executed 5591 times by 2 tests: return (qint64) bytesFromSocket.size();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
5591
362 return socket->bytesAvailable();
executed 580 times by 2 tests: return socket->bytesAvailable();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
580
363}-
364-
365qint64 QFtpDTP::read(char *data, qint64 maxlen)-
366{-
367 qint64 read;-
368 if (socket && socket->state() == QTcpSocket::ConnectedState) {
socketDescription
TRUEnever evaluated
FALSEnever evaluated
socket->state(...ConnectedStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
369 read = socket->read(data, maxlen);-
370 } else {
never executed: end of block
0
371 read = qMin(maxlen, qint64(bytesFromSocket.size()));-
372 memcpy(data, bytesFromSocket.data(), read);-
373 bytesFromSocket.remove(0, read);-
374 }
never executed: end of block
0
375-
376 bytesDone += read;-
377 return read;
never executed: return read;
0
378}-
379-
380QByteArray QFtpDTP::readAll()-
381{-
382 QByteArray tmp;-
383 if (socket && socket->state() == QTcpSocket::ConnectedState) {
socketDescription
TRUEevaluated 611 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
socket->state(...ConnectedStateDescription
TRUEevaluated 587 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 24 times by 1 test
Evaluated by:
  • tst_QFtp
0-611
384 tmp = socket->readAll();-
385 bytesDone += tmp.size();-
386 } else {
executed 587 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
587
387 tmp = bytesFromSocket;-
388 bytesFromSocket.clear();-
389 }
executed 24 times by 1 test: end of block
Executed by:
  • tst_QFtp
24
390 return tmp;
executed 611 times by 2 tests: return tmp;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
611
391}-
392-
393void QFtpDTP::writeData()-
394{-
395 if (!socket)
!socketDescription
TRUEnever evaluated
FALSEevaluated 198 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-198
396 return;
never executed: return;
0
397-
398 if (is_ba) {
is_baDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 170 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
28-170
399#if defined(QFTPDTP_DEBUG)-
400 qDebug("QFtpDTP::writeData: write %d bytes", data.ba->size());-
401#endif-
402 if (data.ba->size() == 0)
data.ba->size() == 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
8-20
403 emit dataTransferProgress(0, bytesTotal);
executed 20 times by 1 test: dataTransferProgress(0, bytesTotal);
Executed by:
  • tst_QFtp
20
404 else-
405 socket->write(data.ba->data(), data.ba->size());
executed 8 times by 1 test: socket->write(data.ba->data(), data.ba->size());
Executed by:
  • tst_QFtp
8
406-
407 socket->close();-
408-
409 clearData();-
410 } else if (data.dev) {
executed 28 times by 1 test: end of block
Executed by:
  • tst_QFtp
data.devDescription
TRUEevaluated 170 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-170
411 callWriteData = false;-
412 const qint64 blockSize = 16*1024;-
413 char buf[16*1024];-
414 qint64 read = data.dev->read(buf, blockSize);-
415#if defined(QFTPDTP_DEBUG)-
416 qDebug("QFtpDTP::writeData: write() of size %lli bytes", read);-
417#endif-
418 if (read > 0) {
read > 0Description
TRUEevaluated 155 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
15-155
419 socket->write(buf, read);-
420 } else if (read == -1 || (!data.dev->isSequential() && data.dev->atEnd())) {
executed 155 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
read == -1Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
!data.dev->isSequential()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
data.dev->atEnd()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-155
421 // error or EOF-
422 if (bytesDone == 0 && socket->bytesToWrite() == 0)
bytesDone == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 13 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
socket->bytesToWrite() == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-13
423 emit dataTransferProgress(0, bytesTotal);
executed 2 times by 1 test: dataTransferProgress(0, bytesTotal);
Executed by:
  • tst_QNetworkReply
2
424 socket->close();-
425 clearData();-
426 }
executed 15 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
15
427-
428 // do we continue uploading?-
429 callWriteData = data.dev != 0;-
430 }
executed 170 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
170
431}
executed 198 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
198
432-
433void QFtpDTP::dataReadyRead()-
434{-
435 writeData();-
436}
never executed: end of block
0
437-
438inline bool QFtpDTP::hasError() const-
439{-
440 return !err.isNull();
executed 3282 times by 2 tests: return !err.isNull();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3282
441}-
442-
443inline QString QFtpDTP::errorMessage() const-
444{-
445 return err;
never executed: return err;
0
446}-
447-
448inline void QFtpDTP::clearError()-
449{-
450 err.clear();-
451}
never executed: end of block
0
452-
453void QFtpDTP::abortConnection()-
454{-
455#if defined(QFTPDTP_DEBUG)-
456 qDebug("QFtpDTP::abortConnection, bytesAvailable == %lli",-
457 socket ? socket->bytesAvailable() : (qint64) 0);-
458#endif-
459 callWriteData = false;-
460 clearData();-
461-
462 if (socket)
socketDescription
TRUEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 144 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
19-144
463 socket->abort();
executed 19 times by 2 tests: socket->abort();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
19
464}
executed 163 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
163
465-
466static void _q_fixupDateTime(QDateTime *dateTime)-
467{-
468 // Adjust for future tolerance.-
469 const int futureTolerance = 86400;-
470 if (dateTime->secsTo(QDateTime::currentDateTime()) < -futureTolerance) {
dateTime->secs...utureToleranceDescription
TRUEnever evaluated
FALSEevaluated 116 times by 1 test
Evaluated by:
  • tst_QFtp
0-116
471 QDate d = dateTime->date();-
472 d.setDate(d.year() - 1, d.month(), d.day());-
473 dateTime->setDate(d);-
474 }
never executed: end of block
0
475}
executed 116 times by 1 test: end of block
Executed by:
  • tst_QFtp
116
476-
477static void _q_parseUnixDir(const QStringList &tokens, const QString &userName, QUrlInfo *info)-
478{-
479 // Unix style, 7 + 1 entries-
480 // -rw-r--r-- 1 ftp ftp 17358091 Aug 10 2004 qt-x11-free-3.3.3.tar.gz-
481 // drwxr-xr-x 3 ftp ftp 4096 Apr 14 2000 compiled-examples-
482 // lrwxrwxrwx 1 ftp ftp 9 Oct 29 2005 qtscape -> qtmozilla-
483 if (tokens.size() != 8)
tokens.size() != 8Description
TRUEnever evaluated
FALSEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
0-372
484 return;
never executed: return;
0
485-
486 char first = tokens.at(1).at(0).toLatin1();-
487 if (first == 'd') {
first == 'd'Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 216 times by 1 test
Evaluated by:
  • tst_QFtp
156-216
488 info->setDir(true);-
489 info->setFile(false);-
490 info->setSymLink(false);-
491 } else if (first == '-') {
executed 156 times by 1 test: end of block
Executed by:
  • tst_QFtp
first == '-'Description
TRUEevaluated 216 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-216
492 info->setDir(false);-
493 info->setFile(true);-
494 info->setSymLink(false);-
495 } else if (first == 'l') {
executed 216 times by 1 test: end of block
Executed by:
  • tst_QFtp
first == 'l'Description
TRUEnever evaluated
FALSEnever evaluated
0-216
496 info->setDir(true);-
497 info->setFile(false);-
498 info->setSymLink(true);-
499 }
never executed: end of block
0
500-
501 // Resolve filename-
502 QString name = tokens.at(7);-
503 if (info->isSymLink()) {
info->isSymLink()Description
TRUEnever evaluated
FALSEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
0-372
504 int linkPos = name.indexOf(QLatin1String(" ->"));-
505 if (linkPos != -1)
linkPos != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
506 name.resize(linkPos);
never executed: name.resize(linkPos);
0
507 }
never executed: end of block
0
508 info->setName(name);-
509-
510 // Resolve owner & group-
511 info->setOwner(tokens.at(3));-
512 info->setGroup(tokens.at(4));-
513-
514 // Resolve size-
515 info->setSize(tokens.at(5).toLongLong());-
516-
517 QStringList formats;-
518 formats << QLatin1String("MMM dd yyyy") << QLatin1String("MMM dd hh:mm") << QLatin1String("MMM d yyyy")-
519 << QLatin1String("MMM d hh:mm") << QLatin1String("MMM d yyyy") << QLatin1String("MMM dd yyyy");-
520-
521 QString dateString = tokens.at(6);-
522 dateString[0] = dateString[0].toUpper();-
523-
524 // Resolve the modification date by parsing all possible formats-
525 QDateTime dateTime;-
526 int n = 0;-
527#ifndef QT_NO_DATESTRING-
528 do {-
529 dateTime = QLocale::c().toDateTime(dateString, formats.at(n++));-
530 } while (n < formats.size() && (!dateTime.isValid()));
executed 496 times by 1 test: end of block
Executed by:
  • tst_QFtp
n < formats.size()Description
TRUEevaluated 496 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
(!dateTime.isValid())Description
TRUEevaluated 124 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
0-496
531#endif-
532-
533 if (n == 2 || n == 4) {
n == 2Description
TRUEevaluated 116 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 256 times by 1 test
Evaluated by:
  • tst_QFtp
n == 4Description
TRUEnever evaluated
FALSEevaluated 256 times by 1 test
Evaluated by:
  • tst_QFtp
0-256
534 // Guess the year.-
535 dateTime.setDate(QDate(QDate::currentDate().year(),-
536 dateTime.date().month(),-
537 dateTime.date().day()));-
538 _q_fixupDateTime(&dateTime);-
539 }
executed 116 times by 1 test: end of block
Executed by:
  • tst_QFtp
116
540 if (dateTime.isValid())
dateTime.isValid()Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-372
541 info->setLastModified(dateTime);
executed 372 times by 1 test: info->setLastModified(dateTime);
Executed by:
  • tst_QFtp
372
542-
543 // Resolve permissions-
544 int permissions = 0;-
545 const QString &p = tokens.at(2);-
546 permissions |= (p[0] == QLatin1Char('r') ? QUrlInfo::ReadOwner : 0);
p[0] == QLatin1Char('r')Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-372
547 permissions |= (p[1] == QLatin1Char('w') ? QUrlInfo::WriteOwner : 0);
p[1] == QLatin1Char('w')Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-372
548 permissions |= (p[2] == QLatin1Char('x') ? QUrlInfo::ExeOwner : 0);
p[2] == QLatin1Char('x')Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 216 times by 1 test
Evaluated by:
  • tst_QFtp
156-216
549 permissions |= (p[3] == QLatin1Char('r') ? QUrlInfo::ReadGroup : 0);
p[3] == QLatin1Char('r')Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-372
550 permissions |= (p[4] == QLatin1Char('w') ? QUrlInfo::WriteGroup : 0);
p[4] == QLatin1Char('w')Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 324 times by 1 test
Evaluated by:
  • tst_QFtp
48-324
551 permissions |= (p[5] == QLatin1Char('x') ? QUrlInfo::ExeGroup : 0);
p[5] == QLatin1Char('x')Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 216 times by 1 test
Evaluated by:
  • tst_QFtp
156-216
552 permissions |= (p[6] == QLatin1Char('r') ? QUrlInfo::ReadOther : 0);
p[6] == QLatin1Char('r')Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-372
553 permissions |= (p[7] == QLatin1Char('w') ? QUrlInfo::WriteOther : 0);
p[7] == QLatin1Char('w')Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 324 times by 1 test
Evaluated by:
  • tst_QFtp
48-324
554 permissions |= (p[8] == QLatin1Char('x') ? QUrlInfo::ExeOther : 0);
p[8] == QLatin1Char('x')Description
TRUEevaluated 108 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 264 times by 1 test
Evaluated by:
  • tst_QFtp
108-264
555 info->setPermissions(permissions);-
556-
557 bool isOwner = info->owner() == userName;-
558 info->setReadable((permissions & QUrlInfo::ReadOther) || ((permissions & QUrlInfo::ReadOwner) && isOwner));-
559 info->setWritable((permissions & QUrlInfo::WriteOther) || ((permissions & QUrlInfo::WriteOwner) && isOwner));-
560}
executed 372 times by 1 test: end of block
Executed by:
  • tst_QFtp
372
561-
562static void _q_parseDosDir(const QStringList &tokens, const QString &userName, QUrlInfo *info)-
563{-
564 // DOS style, 3 + 1 entries-
565 // 01-16-02 11:14AM <DIR> epsgroup-
566 // 06-05-03 03:19PM 1973 readme.txt-
567 if (tokens.size() != 4)
tokens.size() != 4Description
TRUEnever evaluated
FALSEnever evaluated
0
568 return;
never executed: return;
0
569-
570 Q_UNUSED(userName);-
571-
572 QString name = tokens.at(3);-
573 info->setName(name);-
574 info->setSymLink(name.toLower().endsWith(QLatin1String(".lnk")));-
575-
576 if (tokens.at(2) == QLatin1String("<DIR>")) {
tokens.at(2) =...tring("<DIR>")Description
TRUEnever evaluated
FALSEnever evaluated
0
577 info->setFile(false);-
578 info->setDir(true);-
579 } else {
never executed: end of block
0
580 info->setFile(true);-
581 info->setDir(false);-
582 info->setSize(tokens.at(2).toLongLong());-
583 }
never executed: end of block
0
584-
585 // Note: We cannot use QFileInfo; permissions are for the server-side-
586 // machine, and QFileInfo's behavior depends on the local platform.-
587 int permissions = QUrlInfo::ReadOwner | QUrlInfo::WriteOwner-
588 | QUrlInfo::ReadGroup | QUrlInfo::WriteGroup-
589 | QUrlInfo::ReadOther | QUrlInfo::WriteOther;-
590 QStringRef ext;-
591 int extIndex = name.lastIndexOf(QLatin1Char('.'));-
592 if (extIndex != -1)
extIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
593 ext = name.midRef(extIndex + 1);
never executed: ext = name.midRef(extIndex + 1);
0
594 if (ext == QLatin1String("exe") || ext == QLatin1String("bat") || ext == QLatin1String("com"))
ext == QLatin1String("exe")Description
TRUEnever evaluated
FALSEnever evaluated
ext == QLatin1String("bat")Description
TRUEnever evaluated
FALSEnever evaluated
ext == QLatin1String("com")Description
TRUEnever evaluated
FALSEnever evaluated
0
595 permissions |= QUrlInfo::ExeOwner | QUrlInfo::ExeGroup | QUrlInfo::ExeOther;
never executed: permissions |= QUrlInfo::ExeOwner | QUrlInfo::ExeGroup | QUrlInfo::ExeOther;
0
596 info->setPermissions(permissions);-
597-
598 info->setReadable(true);-
599 info->setWritable(info->isFile());-
600-
601 QDateTime dateTime;-
602#ifndef QT_NO_DATESTRING-
603 dateTime = QLocale::c().toDateTime(tokens.at(1), QLatin1String("MM-dd-yy hh:mmAP"));-
604 if (dateTime.date().year() < 1971) {
dateTime.date().year() < 1971Description
TRUEnever evaluated
FALSEnever evaluated
0
605 dateTime.setDate(QDate(dateTime.date().year() + 100,-
606 dateTime.date().month(),-
607 dateTime.date().day()));-
608 }
never executed: end of block
0
609#endif-
610-
611 info->setLastModified(dateTime);-
612-
613}
never executed: end of block
0
614-
615bool QFtpDTP::parseDir(const QByteArray &buffer, const QString &userName, QUrlInfo *info)-
616{-
617 if (buffer.isEmpty())
buffer.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 374 times by 1 test
Evaluated by:
  • tst_QFtp
0-374
618 return false;
never executed: return false;
0
619-
620 QString bufferStr = QString::fromUtf8(buffer).trimmed();-
621-
622 // Unix style FTP servers-
623 QRegExp unixPattern(QLatin1String("^([\\-dl])([a-zA-Z\\-]{9,9})\\s+\\d+\\s+(\\S*)\\s+"-
624 "(\\S*)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+\\S+)\\s+(\\S.*)"));-
625 if (unixPattern.indexIn(bufferStr) == 0) {
unixPattern.in...ufferStr) == 0Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
2-372
626 _q_parseUnixDir(unixPattern.capturedTexts(), userName, info);-
627 return true;
executed 372 times by 1 test: return true;
Executed by:
  • tst_QFtp
372
628 }-
629-
630 // DOS style FTP servers-
631 QRegExp dosPattern(QLatin1String("^(\\d\\d-\\d\\d-\\d\\d\\ \\ \\d\\d:\\d\\d[AP]M)\\s+"-
632 "(<DIR>|\\d+)\\s+(\\S.*)$"));-
633 if (dosPattern.indexIn(bufferStr) == 0) {
dosPattern.ind...ufferStr) == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
0-2
634 _q_parseDosDir(dosPattern.capturedTexts(), userName, info);-
635 return true;
never executed: return true;
0
636 }-
637-
638 // Unsupported-
639 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QFtp
2
640}-
641-
642void QFtpDTP::socketConnected()-
643{-
644 bytesDone = 0;-
645#if defined(QFTPDTP_DEBUG)-
646 qDebug("QFtpDTP::connectState(CsConnected)");-
647#endif-
648 emit connectState(QFtpDTP::CsConnected);-
649}
executed 355 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
650-
651void QFtpDTP::socketReadyRead()-
652{-
653 if (!socket)
!socketDescription
TRUEnever evaluated
FALSEevaluated 1579 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-1579
654 return;
never executed: return;
0
655-
656 if (pi->currentCommand().isEmpty()) {
pi->currentCommand().isEmpty()Description
TRUEnever evaluated
FALSEevaluated 1579 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-1579
657 socket->close();-
658#if defined(QFTPDTP_DEBUG)-
659 qDebug("QFtpDTP::connectState(CsClosed)");-
660#endif-
661 emit connectState(QFtpDTP::CsClosed);-
662 return;
never executed: return;
0
663 }-
664-
665 if (pi->abortState != QFtpPI::None) {
pi->abortState != QFtpPI::NoneDescription
TRUEnever evaluated
FALSEevaluated 1579 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-1579
666 // discard data-
667 socket->readAll();-
668 return;
never executed: return;
0
669 }-
670-
671 if (pi->currentCommand().startsWith(QLatin1String("LIST"))) {
pi->currentCom...tring("LIST"))Description
TRUEevaluated 142 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 1437 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
142-1437
672 while (socket->canReadLine()) {
socket->canReadLine()Description
TRUEevaluated 374 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 142 times by 1 test
Evaluated by:
  • tst_QFtp
142-374
673 QUrlInfo i;-
674 QByteArray line = socket->readLine();-
675#if defined(QFTPDTP_DEBUG)-
676 qDebug("QFtpDTP read (list): '%s'", line.constData());-
677#endif-
678 if (parseDir(line, QLatin1String(""), &i)) {
parseDir(line,...tring(""), &i)Description
TRUEevaluated 372 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
2-372
679 emit listInfo(i);-
680 } else {
executed 372 times by 1 test: end of block
Executed by:
  • tst_QFtp
372
681 // some FTP servers don't return a 550 if the file or directory-
682 // does not exist, but rather write a text to the data socket-
683 // -- try to catch these cases-
684 if (line.endsWith("No such file or directory\r\n"))
line.endsWith(...irectory\r\n")Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
0-2
685 err = QString::fromUtf8(line);
never executed: err = QString::fromUtf8(line);
0
686 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QFtp
2
687 }-
688 } else {
executed 142 times by 1 test: end of block
Executed by:
  • tst_QFtp
142
689 if (!is_ba && data.dev) {
!is_baDescription
TRUEevaluated 1437 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
data.devDescription
TRUEevaluated 236 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 1201 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-1437
690 do {-
691 QByteArray ba;-
692 ba.resize(socket->bytesAvailable());-
693 qint64 bytesRead = socket->read(ba.data(), ba.size());-
694 if (bytesRead < 0) {
bytesRead < 0Description
TRUEnever evaluated
FALSEevaluated 236 times by 1 test
Evaluated by:
  • tst_QFtp
0-236
695 // a read following a readyRead() signal will-
696 // never fail.-
697 return;
never executed: return;
0
698 }-
699 ba.resize(bytesRead);-
700 bytesDone += bytesRead;-
701#if defined(QFTPDTP_DEBUG)-
702 qDebug("QFtpDTP read: %lli bytes (total %lli bytes)", bytesRead, bytesDone);-
703#endif-
704 if (data.dev) // make sure it wasn't deleted in the slot
data.devDescription
TRUEevaluated 236 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-236
705 data.dev->write(ba);
executed 236 times by 1 test: data.dev->write(ba);
Executed by:
  • tst_QFtp
236
706 emit dataTransferProgress(bytesDone, bytesTotal);-
707-
708 // Need to loop; dataTransferProgress is often connected to-
709 // slots that update the GUI (e.g., progress bar values), and-
710 // if events are processed, more data may have arrived.-
711 } while (socket->bytesAvailable());
executed 236 times by 1 test: end of block
Executed by:
  • tst_QFtp
socket->bytesAvailable()Description
TRUEnever evaluated
FALSEevaluated 236 times by 1 test
Evaluated by:
  • tst_QFtp
0-236
712 } else {
executed 236 times by 1 test: end of block
Executed by:
  • tst_QFtp
236
713#if defined(QFTPDTP_DEBUG)-
714 qDebug("QFtpDTP readyRead: %lli bytes available (total %lli bytes read)",-
715 bytesAvailable(), bytesDone);-
716#endif-
717 emit dataTransferProgress(bytesDone+socket->bytesAvailable(), bytesTotal);-
718 emit readyRead();-
719 }
executed 1201 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1201
720 }-
721}-
722-
723void QFtpDTP::socketError(QAbstractSocket::SocketError e)-
724{-
725 if (e == QTcpSocket::HostNotFoundError) {
e == QTcpSocke...tNotFoundErrorDescription
TRUEnever evaluated
FALSEevaluated 301 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-301
726#if defined(QFTPDTP_DEBUG)-
727 qDebug("QFtpDTP::connectState(CsHostNotFound)");-
728#endif-
729 emit connectState(QFtpDTP::CsHostNotFound);-
730 } else if (e == QTcpSocket::ConnectionRefusedError) {
never executed: end of block
e == QTcpSocke...onRefusedErrorDescription
TRUEnever evaluated
FALSEevaluated 301 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-301
731#if defined(QFTPDTP_DEBUG)-
732 qDebug("QFtpDTP::connectState(CsConnectionRefused)");-
733#endif-
734 emit connectState(QFtpDTP::CsConnectionRefused);-
735 }
never executed: end of block
0
736}
executed 301 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
301
737-
738void QFtpDTP::socketConnectionClosed()-
739{-
740 if (!is_ba && data.dev) {
!is_baDescription
TRUEevaluated 343 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_QFtp
data.devDescription
TRUEevaluated 47 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 296 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
20-343
741 clearData();-
742 }
executed 47 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
47
743-
744 if (socket->isOpen())
socket->isOpen()Description
TRUEevaluated 301 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 62 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
62-301
745 bytesFromSocket = socket->readAll();
executed 301 times by 2 tests: bytesFromSocket = socket->readAll();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
301
746 else-
747 bytesFromSocket.clear();
executed 62 times by 2 tests: bytesFromSocket.clear();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
62
748#if defined(QFTPDTP_DEBUG)-
749 qDebug("QFtpDTP::connectState(CsClosed)");-
750#endif-
751 emit connectState(QFtpDTP::CsClosed);-
752}
executed 363 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
363
753-
754void QFtpDTP::socketBytesWritten(qint64 bytes)-
755{-
756 bytesDone += bytes;-
757#if defined(QFTPDTP_DEBUG)-
758 qDebug("QFtpDTP::bytesWritten(%lli)", bytesDone);-
759#endif-
760 emit dataTransferProgress(bytesDone, bytesTotal);-
761 if (callWriteData)
callWriteDataDescription
TRUEevaluated 155 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
8-155
762 writeData();
executed 155 times by 2 tests: writeData();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
155
763}
executed 163 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
163
764-
765void QFtpDTP::setupSocket()-
766{-
767 socket = listener.nextPendingConnection();-
768 socket->setObjectName(QLatin1String("QFtpDTP Active state socket"));-
769 connect(socket, SIGNAL(connected()), SLOT(socketConnected()));-
770 connect(socket, SIGNAL(readyRead()), SLOT(socketReadyRead()));-
771 connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError)));-
772 connect(socket, SIGNAL(disconnected()), SLOT(socketConnectionClosed()));-
773 connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64)));-
774-
775 listener.close();-
776}
executed 8 times by 1 test: end of block
Executed by:
  • tst_QFtp
8
777-
778void QFtpDTP::clearData()-
779{-
780 is_ba = false;-
781 data.dev = 0;-
782}
executed 914 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
914
783-
784/**********************************************************************-
785 *-
786 * QFtpPI implemenatation-
787 *-
788 *********************************************************************/-
789QFtpPI::QFtpPI(QObject *parent) :-
790 QObject(parent),-
791 rawCommand(false),-
792 transferConnectionExtended(true),-
793 dtp(this),-
794 commandSocket(0),-
795 state(Begin), abortState(None),-
796 currentCmd(QString()),-
797 waitForDtpToConnect(false),-
798 waitForDtpToClose(false)-
799{-
800 commandSocket.setObjectName(QLatin1String("QFtpPI_socket"));-
801 connect(&commandSocket, SIGNAL(hostFound()),-
802 SLOT(hostFound()));-
803 connect(&commandSocket, SIGNAL(connected()),-
804 SLOT(connected()));-
805 connect(&commandSocket, SIGNAL(disconnected()),-
806 SLOT(connectionClosed()));-
807 connect(&commandSocket, SIGNAL(readyRead()),-
808 SLOT(readyRead()));-
809 connect(&commandSocket, SIGNAL(error(QAbstractSocket::SocketError)),-
810 SLOT(error(QAbstractSocket::SocketError)));-
811-
812 connect(&dtp, SIGNAL(connectState(int)),-
813 SLOT(dtpConnectState(int)));-
814}
executed 661 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
661
815-
816void QFtpPI::connectToHost(const QString &host, quint16 port)-
817{-
818 emit connectState(QFtp::HostLookup);-
819#ifndef QT_NO_BEARERMANAGEMENT-
820 //copy network session down to the socket & DTP-
821 commandSocket.setProperty("_q_networksession", property("_q_networksession"));-
822 dtp.setProperty("_q_networksession", property("_q_networksession"));-
823#endif-
824 commandSocket.connectToHost(host, port);-
825}
executed 657 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
657
826-
827/*-
828 \internal-
829-
830 Sends the sequence of commands \a cmds to the FTP server. When the commands-
831 are all done the finished() signal is emitted. When an error occurs, the-
832 error() signal is emitted.-
833-
834 If there are pending commands in the queue this functions returns \c false and-
835 the \a cmds are not added to the queue; otherwise it returns \c true.-
836*/-
837bool QFtpPI::sendCommands(const QStringList &cmds)-
838{-
839 if (!pendingCommands.isEmpty())
!pendingCommands.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 1956 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-1956
840 return false;
never executed: return false;
0
841-
842 if (commandSocket.state() != QTcpSocket::ConnectedState || state!=Idle) {
commandSocket....ConnectedStateDescription
TRUEevaluated 21 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1935 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
state!=IdleDescription
TRUEnever evaluated
FALSEevaluated 1935 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-1935
843 emit error(QFtp::NotConnected, QFtp::tr("Not connected"));-
844 return true; // there are no pending commands
executed 21 times by 2 tests: return true;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
21
845 }-
846-
847 pendingCommands = cmds;-
848 startNextCmd();-
849 return true;
executed 1935 times by 2 tests: return true;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1935
850}-
851-
852void QFtpPI::clearPendingCommands()-
853{-
854 pendingCommands.clear();-
855 dtp.abortConnection();-
856 currentCmd.clear();-
857 state = Idle;-
858}
executed 161 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
161
859-
860void QFtpPI::abort()-
861{-
862 pendingCommands.clear();-
863-
864 if (abortState != None)
abortState != NoneDescription
TRUEnever evaluated
FALSEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-4
865 // ABOR already sent-
866 return;
never executed: return;
0
867-
868 if (currentCmd.isEmpty())
currentCmd.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
2
869 return; //no command in progress
executed 2 times by 1 test: return;
Executed by:
  • tst_QFtp
2
870-
871 if (currentCmd.startsWith(QLatin1String("STOR "))) {
currentCmd.sta...ring("STOR "))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-2
872 abortState = AbortStarted;-
873#if defined(QFTPPI_DEBUG)-
874 qDebug("QFtpPI send: ABOR");-
875#endif-
876 commandSocket.write("ABOR\r\n", 6);-
877-
878 dtp.abortConnection();-
879 } else {
never executed: end of block
0
880 //Deviation from RFC 959:-
881 //Most FTP servers do not support ABOR, or require the telnet-
882 //IP & synch sequence (TCP urgent data) which is not supported by QTcpSocket.-
883 //Following what most FTP clients do, just reset the data connection and wait for 426-
884 abortState = WaitForAbortToFinish;-
885 dtp.abortConnection();-
886 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
2
887}-
888-
889void QFtpPI::hostFound()-
890{-
891 emit connectState(QFtp::Connecting);-
892}
executed 354 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
354
893-
894void QFtpPI::connected()-
895{-
896 state = Begin;-
897#if defined(QFTPPI_DEBUG)-
898// qDebug("QFtpPI state: %d [connected()]", state);-
899#endif-
900 // try to improve performance by setting TCP_NODELAY-
901 commandSocket.setSocketOption(QAbstractSocket::LowDelayOption, 1);-
902-
903 emit connectState(QFtp::Connected);-
904}
executed 637 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
637
905-
906void QFtpPI::connectionClosed()-
907{-
908 commandSocket.close();-
909 emit connectState(QFtp::Unconnected);-
910}
executed 635 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
635
911-
912void QFtpPI::delayedCloseFinished()-
913{-
914 emit connectState(QFtp::Unconnected);-
915}
never executed: end of block
0
916-
917void QFtpPI::error(QAbstractSocket::SocketError e)-
918{-
919 if (e == QTcpSocket::HostNotFoundError) {
e == QTcpSocke...tNotFoundErrorDescription
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 482 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
7-482
920 emit connectState(QFtp::Unconnected);-
921 emit error(QFtp::HostNotFound,-
922 QFtp::tr("Host %1 not found").arg(commandSocket.peerName()));-
923 } else if (e == QTcpSocket::ConnectionRefusedError) {
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
e == QTcpSocke...onRefusedErrorDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 470 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
7-470
924 emit connectState(QFtp::Unconnected);-
925 emit error(QFtp::ConnectionRefused,-
926 QFtp::tr("Connection refused to host %1").arg(commandSocket.peerName()));-
927 } else if (e == QTcpSocket::SocketTimeoutError) {
executed 12 times by 1 test: end of block
Executed by:
  • tst_QFtp
e == QTcpSocke...etTimeoutErrorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 469 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
1-469
928 emit connectState(QFtp::Unconnected);-
929 emit error(QFtp::ConnectionRefused,-
930 QFtp::tr("Connection timed out to host %1").arg(commandSocket.peerName()));-
931 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFtp
1
932}
executed 489 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
489
933-
934void QFtpPI::readyRead()-
935{-
936 if (waitForDtpToClose)
waitForDtpToCloseDescription
TRUEnever evaluated
FALSEevaluated 4900 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-4900
937 return;
never executed: return;
0
938-
939 while (commandSocket.canReadLine()) {
commandSocket.canReadLine()Description
TRUEevaluated 4537 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4801 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
4537-4801
940 // read line with respect to line continuation-
941 QString line = QString::fromUtf8(commandSocket.readLine());-
942 if (replyText.isEmpty()) {
replyText.isEmpty()Description
TRUEevaluated 4438 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 99 times by 1 test
Evaluated by:
  • tst_QNetworkReply
99-4438
943 if (line.length() < 3) {
line.length() < 3Description
TRUEnever evaluated
FALSEevaluated 4438 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-4438
944 // protocol error-
945 return;
never executed: return;
0
946 }-
947 const int lowerLimit[3] = {1,0,0};-
948 const int upperLimit[3] = {5,5,9};-
949 for (int i=0; i<3; i++) {
i<3Description
TRUEevaluated 13314 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4438 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
4438-13314
950 replyCode[i] = line.at(i).digitValue();-
951 if (replyCode[i]<lowerLimit[i] || replyCode[i]>upperLimit[i]) {
replyCode[i]<lowerLimit[i]Description
TRUEnever evaluated
FALSEevaluated 13314 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
replyCode[i]>upperLimit[i]Description
TRUEnever evaluated
FALSEevaluated 13314 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-13314
952 // protocol error-
953 return;
never executed: return;
0
954 }-
955 }
executed 13314 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
13314
956 }
executed 4438 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4438
957 QString endOfMultiLine;-
958 endOfMultiLine[0] = '0' + replyCode[0];-
959 endOfMultiLine[1] = '0' + replyCode[1];-
960 endOfMultiLine[2] = '0' + replyCode[2];-
961 endOfMultiLine[3] = QLatin1Char(' ');-
962 QString lineCont(endOfMultiLine);-
963 lineCont[3] = QLatin1Char('-');-
964 QStringRef lineLeft4 = line.leftRef(4);-
965-
966 while (lineLeft4 != endOfMultiLine) {
lineLeft4 != endOfMultiLineDescription
TRUEevaluated 242 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4438 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
242-4438
967 if (lineLeft4 == lineCont)
lineLeft4 == lineContDescription
TRUEevaluated 106 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 136 times by 1 test
Evaluated by:
  • tst_QNetworkReply
106-136
968 replyText += line.midRef(4); // strip 'xyz-'
executed 106 times by 2 tests: replyText += line.midRef(4);
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
106
969 else-
970 replyText += line;
executed 136 times by 1 test: replyText += line;
Executed by:
  • tst_QNetworkReply
136
971 if (!commandSocket.canReadLine())
!commandSocket.canReadLine()Description
TRUEevaluated 99 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 143 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
99-143
972 return;
executed 99 times by 1 test: return;
Executed by:
  • tst_QNetworkReply
99
973 line = QString::fromUtf8(commandSocket.readLine());-
974 lineLeft4 = line.leftRef(4);-
975 }
executed 143 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
143
976 replyText += line.midRef(4); // strip reply code 'xyz '-
977 if (replyText.endsWith(QLatin1String("\r\n")))
replyText.ends...tring("\r\n"))Description
TRUEevaluated 4438 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-4438
978 replyText.chop(2);
executed 4438 times by 2 tests: replyText.chop(2);
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4438
979-
980 if (processReply())
processReply()Description
TRUEevaluated 4436 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
2-4436
981 replyText = QLatin1String("");
executed 4436 times by 2 tests: replyText = QLatin1String("");
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4436
982 }
executed 4438 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4438
983}
executed 4801 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4801
984-
985/*-
986 \internal-
987-
988 Process a reply from the FTP server.-
989-
990 Returns \c true if the reply was processed or false if the reply has to be-
991 processed at a later point.-
992*/-
993bool QFtpPI::processReply()-
994{-
995#if defined(QFTPPI_DEBUG)-
996// qDebug("QFtpPI state: %d [processReply() begin]", state);-
997 if (replyText.length() < 400)-
998 qDebug("QFtpPI recv: %d %s", 100*replyCode[0]+10*replyCode[1]+replyCode[2], replyText.toLatin1().constData());-
999 else-
1000 qDebug("QFtpPI recv: %d (text skipped)", 100*replyCode[0]+10*replyCode[1]+replyCode[2]);-
1001#endif-
1002-
1003 int replyCodeInt = 100*replyCode[0] + 10*replyCode[1] + replyCode[2];-
1004-
1005 // process 226 replies ("Closing Data Connection") only when the data-
1006 // connection is really closed to avoid short reads of the DTP-
1007 if (replyCodeInt == 226 || (replyCodeInt == 250 && currentCmd.startsWith(QLatin1String("RETR")))) {
replyCodeInt == 226Description
TRUEevaluated 346 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4094 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
replyCodeInt == 250Description
TRUEevaluated 240 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 3854 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
currentCmd.sta...tring("RETR"))Description
TRUEnever evaluated
FALSEevaluated 240 times by 1 test
Evaluated by:
  • tst_QFtp
0-4094
1008 if (dtp.state() != QTcpSocket::UnconnectedState) {
dtp.state() !=...connectedStateDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 344 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
2-344
1009 waitForDtpToClose = true;-
1010 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QFtp
2
1011 }-
1012 }
executed 344 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
344
1013-
1014 switch (abortState) {-
1015 case AbortStarted:
never executed: case AbortStarted:
0
1016 abortState = WaitForAbortToFinish;-
1017 break;
never executed: break;
0
1018 case WaitForAbortToFinish:
executed 2 times by 1 test: case WaitForAbortToFinish:
Executed by:
  • tst_QNetworkReply
2
1019 abortState = None;-
1020 return true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
2
1021 default:
executed 4436 times by 2 tests: default:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4436
1022 break;
executed 4436 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4436
1023 }-
1024-
1025 // get new state-
1026 static const State table[5] = {-
1027 /* 1yz 2yz 3yz 4yz 5yz */-
1028 Waiting, Success, Idle, Failure, Failure-
1029 };-
1030 switch (state) {-
1031 case Begin:
executed 637 times by 2 tests: case Begin:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
637
1032 if (replyCode[0] == 1) {
replyCode[0] == 1Description
TRUEnever evaluated
FALSEevaluated 637 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-637
1033 return true;
never executed: return true;
0
1034 } else if (replyCode[0] == 2) {
replyCode[0] == 2Description
TRUEevaluated 637 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-637
1035 state = Idle;-
1036 emit finished(QFtp::tr("Connected to host %1").arg(commandSocket.peerName()));-
1037 break;
executed 637 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
637
1038 }-
1039 // reply codes not starting with 1 or 2 are not handled.-
1040 return true;
never executed: return true;
0
1041 case Waiting:
executed 3799 times by 2 tests: case Waiting:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3799
1042 if (static_cast<signed char>(replyCode[0]) < 0 || replyCode[0] > 5)
static_cast<si...lyCode[0]) < 0Description
TRUEnever evaluated
FALSEevaluated 3799 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
replyCode[0] > 5Description
TRUEnever evaluated
FALSEevaluated 3799 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-3799
1043 state = Failure;
never executed: state = Failure;
0
1044 else-
1045 if (replyCodeInt == 202)
replyCodeInt == 202Description
TRUEevaluated 43 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 3756 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
43-3756
1046 state = Failure;
executed 43 times by 2 tests: state = Failure;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
43
1047 else-
1048 state = table[replyCode[0] - 1];
executed 3756 times by 2 tests: state = table[replyCode[0] - 1];
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3756
1049 break;
executed 3799 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3799
1050 default:
never executed: default:
0
1051 // ignore unrequested message-
1052 return true;
never executed: return true;
0
1053 }-
1054#if defined(QFTPPI_DEBUG)-
1055// qDebug("QFtpPI state: %d [processReply() intermediate]", state);-
1056#endif-
1057-
1058 // special actions on certain replies-
1059 emit rawFtpReply(replyCodeInt, replyText);-
1060 if (rawCommand) {
rawCommandDescription
TRUEevaluated 132 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 4304 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
132-4304
1061 rawCommand = false;-
1062 } else if (replyCodeInt == 227) {
executed 132 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
replyCodeInt == 227Description
TRUEevaluated 355 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 3949 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
132-3949
1063 // 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)-
1064 // rfc959 does not define this response precisely, and gives-
1065 // both examples where the parenthesis are used, and where-
1066 // they are missing. We need to scan for the address and host-
1067 // info.-
1068 QRegExp addrPortPattern(QLatin1String("(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)"));-
1069 if (addrPortPattern.indexIn(replyText) == -1) {
addrPortPatter...plyText) == -1Description
TRUEnever evaluated
FALSEevaluated 355 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-355
1070#if defined(QFTPPI_DEBUG)-
1071 qDebug("QFtp: bad 227 response -- address and port information missing");-
1072#endif-
1073 // this error should be reported-
1074 } else {
never executed: end of block
0
1075 const QStringList lst = addrPortPattern.capturedTexts();-
1076 QString host = lst[1] + QLatin1Char('.') + lst[2] + QLatin1Char('.') + lst[3] + QLatin1Char('.') + lst[4];-
1077 quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt();-
1078 waitForDtpToConnect = true;-
1079 dtp.connectToHost(host, port);-
1080 }
executed 355 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
1081 } else if (replyCodeInt == 229) {
replyCodeInt == 229Description
TRUEnever evaluated
FALSEevaluated 3949 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-3949
1082 // 229 Extended Passive mode OK (|||10982|)-
1083 int portPos = replyText.indexOf(QLatin1Char('('));-
1084 if (portPos == -1) {
portPos == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1085#if defined(QFTPPI_DEBUG)-
1086 qDebug("QFtp: bad 229 response -- port information missing");-
1087#endif-
1088 // this error should be reported-
1089 } else {
never executed: end of block
0
1090 ++portPos;-
1091 QChar delimiter = replyText.at(portPos);-
1092 const auto epsvParameters = replyText.midRef(portPos).split(delimiter);-
1093-
1094 waitForDtpToConnect = true;-
1095 dtp.connectToHost(commandSocket.peerAddress().toString(),-
1096 epsvParameters.at(3).toInt());-
1097 }
never executed: end of block
0
1098-
1099 } else if (replyCodeInt == 230) {
replyCodeInt == 230Description
TRUEevaluated 610 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 3339 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
610-3339
1100 if (currentCmd.startsWith(QLatin1String("USER ")) && pendingCommands.count()>0 &&
currentCmd.sta...ring("USER "))Description
TRUEnever evaluated
FALSEevaluated 610 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
pendingCommands.count()>0Description
TRUEnever evaluated
FALSEnever evaluated
0-610
1101 pendingCommands.constFirst().startsWith(QLatin1String("PASS "))) {
pendingCommand...ring("PASS "))Description
TRUEnever evaluated
FALSEnever evaluated
0
1102 // no need to send the PASS -- we are already logged in-
1103 pendingCommands.pop_front();-
1104 }
never executed: end of block
0
1105 // 230 User logged in, proceed.-
1106 emit connectState(QFtp::LoggedIn);-
1107 } else if (replyCodeInt == 213) {
executed 610 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
replyCodeInt == 213Description
TRUEevaluated 94 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 3245 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
94-3245
1108 // 213 File status.-
1109 if (currentCmd.startsWith(QLatin1String("SIZE ")))
currentCmd.sta...ring("SIZE "))Description
TRUEevaluated 94 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-94
1110 dtp.setBytesTotal(replyText.simplified().toLongLong());
executed 94 times by 2 tests: dtp.setBytesTotal(replyText.simplified().toLongLong());
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
94
1111 } else if (replyCode[0]==1 && currentCmd.startsWith(QLatin1String("STOR "))) {
executed 94 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
replyCode[0]==1Description
TRUEevaluated 346 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 2899 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
currentCmd.sta...ring("STOR "))Description
TRUEevaluated 43 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 303 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
43-2899
1112 dtp.waitForConnection();-
1113 dtp.writeData();-
1114 }
executed 43 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
43
1115-
1116 // react on new state-
1117 switch (state) {-
1118 case Begin:
never executed: case Begin:
0
1119 // should never happen-
1120 break;
never executed: break;
0
1121 case Success:
executed 2633 times by 2 tests: case Success:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
2633
1122 // success handling-
1123 state = Idle;-
1124 // no break!-
1125 case Idle:
code before this statement executed 2633 times by 2 tests: case Idle:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
executed 649 times by 2 tests: case Idle:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
649-2633
1126 if (dtp.hasError()) {
dtp.hasError()Description
TRUEnever evaluated
FALSEevaluated 3282 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-3282
1127 emit error(QFtp::UnknownError, dtp.errorMessage());-
1128 dtp.clearError();-
1129 }
never executed: end of block
0
1130 startNextCmd();-
1131 break;
executed 3282 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3282
1132 case Waiting:
executed 975 times by 2 tests: case Waiting:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
975
1133 // do nothing-
1134 break;
executed 975 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
975
1135 case Failure:
executed 179 times by 2 tests: case Failure:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
179
1136 // If the EPSV or EPRT commands fail, replace them with-
1137 // the old PASV and PORT instead and try again.-
1138 if (currentCmd.startsWith(QLatin1String("EPSV"))) {
currentCmd.sta...tring("EPSV"))Description
TRUEnever evaluated
FALSEevaluated 179 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-179
1139 transferConnectionExtended = false;-
1140 pendingCommands.prepend(QLatin1String("PASV\r\n"));-
1141 } else if (currentCmd.startsWith(QLatin1String("EPRT"))) {
never executed: end of block
currentCmd.sta...tring("EPRT"))Description
TRUEnever evaluated
FALSEevaluated 179 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-179
1142 transferConnectionExtended = false;-
1143 pendingCommands.prepend(QLatin1String("PORT\r\n"));-
1144 } else {
never executed: end of block
0
1145 emit error(QFtp::UnknownError, replyText);-
1146 }
executed 179 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
179
1147 if (state != Waiting) {
state != WaitingDescription
TRUEevaluated 175 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
4-175
1148 state = Idle;-
1149 startNextCmd();-
1150 }
executed 175 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
175
1151 break;
executed 179 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
179
1152 }-
1153#if defined(QFTPPI_DEBUG)-
1154// qDebug("QFtpPI state: %d [processReply() end]", state);-
1155#endif-
1156 return true;
executed 4436 times by 2 tests: return true;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4436
1157}-
1158-
1159/*-
1160 \internal-
1161-
1162 Starts next pending command. Returns \c false if there are no pending commands,-
1163 otherwise it returns \c true.-
1164*/-
1165bool QFtpPI::startNextCmd()-
1166{-
1167 if (waitForDtpToConnect)
waitForDtpToConnectDescription
TRUEevaluated 355 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 5392 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
355-5392
1168 // don't process any new commands until we are connected-
1169 return true;
executed 355 times by 2 tests: return true;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
1170-
1171#if defined(QFTPPI_DEBUG)-
1172 if (state != Idle)-
1173 qDebug("QFtpPI startNextCmd: Internal error! QFtpPI called in non-Idle state %d", state);-
1174#endif-
1175 if (pendingCommands.isEmpty()) {
pendingCommands.isEmpty()Description
TRUEevaluated 1937 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 3455 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
1937-3455
1176 currentCmd.clear();-
1177 emit finished(replyText);-
1178 return false;
executed 1937 times by 2 tests: return false;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1937
1179 }-
1180 currentCmd = pendingCommands.constFirst();-
1181-
1182 // PORT and PASV are edited in-place, depending on whether we-
1183 // should try the extended transfer connection commands EPRT and-
1184 // EPSV. The PORT command also triggers setting up a listener, and-
1185 // the address/port arguments are edited in.-
1186 QHostAddress address = commandSocket.localAddress();-
1187 if (currentCmd.startsWith(QLatin1String("PORT"))) {
currentCmd.sta...tring("PORT"))Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 3447 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
8-3447
1188 if ((address.protocol() == QTcpSocket::IPv6Protocol) && transferConnectionExtended) {
(address.proto...:IPv6Protocol)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
transferConnectionExtendedDescription
TRUEnever evaluated
FALSEnever evaluated
0-8
1189 int port = dtp.setupListener(address);-
1190 currentCmd = QLatin1String("EPRT |");-
1191 currentCmd += (address.protocol() == QTcpSocket::IPv4Protocol) ? QLatin1Char('1') : QLatin1Char('2');
(address.proto...:IPv4Protocol)Description
TRUEnever evaluated
FALSEnever evaluated
0
1192 currentCmd += QLatin1Char('|') + address.toString() + QLatin1Char('|') + QString::number(port);-
1193 currentCmd += QLatin1Char('|');-
1194 } else if (address.protocol() == QTcpSocket::IPv4Protocol) {
never executed: end of block
address.protoc...::IPv4ProtocolDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-8
1195 int port = dtp.setupListener(address);-
1196 QString portArg;-
1197 quint32 ip = address.toIPv4Address();-
1198 portArg += QString::number((ip & 0xff000000) >> 24);-
1199 portArg += QLatin1Char(',') + QString::number((ip & 0xff0000) >> 16);-
1200 portArg += QLatin1Char(',') + QString::number((ip & 0xff00) >> 8);-
1201 portArg += QLatin1Char(',') + QString::number(ip & 0xff);-
1202 portArg += QLatin1Char(',') + QString::number((port & 0xff00) >> 8);-
1203 portArg += QLatin1Char(',') + QString::number(port & 0xff);-
1204-
1205 currentCmd = QLatin1String("PORT ");-
1206 currentCmd += portArg;-
1207 } else {
executed 8 times by 1 test: end of block
Executed by:
  • tst_QFtp
8
1208 // No IPv6 connection can be set up with the PORT-
1209 // command.-
1210 return false;
never executed: return false;
0
1211 }-
1212-
1213 currentCmd += QLatin1String("\r\n");-
1214 } else if (currentCmd.startsWith(QLatin1String("PASV"))) {
executed 8 times by 1 test: end of block
Executed by:
  • tst_QFtp
currentCmd.sta...tring("PASV"))Description
TRUEevaluated 355 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 3092 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
8-3092
1215 if ((address.protocol() == QTcpSocket::IPv6Protocol) && transferConnectionExtended)
(address.proto...:IPv6Protocol)Description
TRUEnever evaluated
FALSEevaluated 355 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
transferConnectionExtendedDescription
TRUEnever evaluated
FALSEnever evaluated
0-355
1216 currentCmd = QLatin1String("EPSV\r\n");
never executed: currentCmd = QLatin1String("EPSV\r\n");
0
1217 }
executed 355 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
1218-
1219 pendingCommands.pop_front();-
1220#if defined(QFTPPI_DEBUG)-
1221 qDebug("QFtpPI send: %s", currentCmd.leftRef(currentCmd.length() - 2).toLatin1().constData());-
1222#endif-
1223 state = Waiting;-
1224 commandSocket.write(currentCmd.toUtf8());-
1225 return true;
executed 3455 times by 2 tests: return true;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3455
1226}-
1227-
1228void QFtpPI::dtpConnectState(int s)-
1229{-
1230 switch (s) {-
1231 case QFtpDTP::CsClosed:
executed 363 times by 2 tests: case QFtpDTP::CsClosed:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
363
1232 if (waitForDtpToClose) {
waitForDtpToCloseDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 361 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
2-361
1233 // there is an unprocessed reply-
1234 if (processReply())
processReply()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEnever evaluated
0-2
1235 replyText = QLatin1String("");
executed 2 times by 1 test: replyText = QLatin1String("");
Executed by:
  • tst_QFtp
2
1236 else-
1237 return;
never executed: return;
0
1238 }-
1239 waitForDtpToClose = false;-
1240 readyRead();-
1241 return;
executed 363 times by 2 tests: return;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
363
1242 case QFtpDTP::CsConnected:
executed 355 times by 2 tests: case QFtpDTP::CsConnected:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
1243 waitForDtpToConnect = false;-
1244 startNextCmd();-
1245 return;
executed 355 times by 2 tests: return;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
355
1246 case QFtpDTP::CsHostNotFound:
never executed: case QFtpDTP::CsHostNotFound:
0
1247 case QFtpDTP::CsConnectionRefused:
never executed: case QFtpDTP::CsConnectionRefused:
0
1248 emit error(QFtp::ConnectionRefused,-
1249 QFtp::tr("Data Connection refused"));-
1250 startNextCmd();-
1251 return;
never executed: return;
0
1252 default:
never executed: default:
0
1253 return;
never executed: return;
0
1254 }-
1255}-
1256-
1257/**********************************************************************-
1258 *-
1259 * QFtpPrivate-
1260 *-
1261 *********************************************************************/-
1262-
1263QT_BEGIN_INCLUDE_NAMESPACE-
1264#include <private/qobject_p.h>-
1265QT_END_INCLUDE_NAMESPACE-
1266-
1267class QFtpPrivate : public QObjectPrivate-
1268{-
1269 Q_DECLARE_PUBLIC(QFtp)-
1270public:-
1271-
1272 inline QFtpPrivate() : close_waitForStateChange(false), state(QFtp::Unconnected),-
1273 transferMode(QFtp::Passive), error(QFtp::NoError)-
1274 { }
executed 661 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
661
1275-
1276 ~QFtpPrivate() { while (!pending.isEmpty()) delete pending.takeFirst(); }
executed 659 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
executed 661 times by 2 tests: delete pending.takeFirst();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
!pending.isEmpty()Description
TRUEevaluated 661 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 659 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
659-661
1277-
1278 // private slots-
1279 void _q_startNextCommand();-
1280 void _q_piFinished(const QString&);-
1281 void _q_piError(int, const QString&);-
1282 void _q_piConnectState(int);-
1283 void _q_piFtpReply(int, const QString&);-
1284-
1285 int addCommand(QFtpCommand *cmd);-
1286-
1287 QFtpPI pi;-
1288 QList<QFtpCommand *> pending;-
1289 bool close_waitForStateChange;-
1290 QFtp::State state;-
1291 QFtp::TransferMode transferMode;-
1292 QFtp::Error error;-
1293 QString errorString;-
1294-
1295 QString host;-
1296 quint16 port;-
1297 QString proxyHost;-
1298 quint16 proxyPort;-
1299};-
1300-
1301int QFtpPrivate::addCommand(QFtpCommand *cmd)-
1302{-
1303 pending.append(cmd);-
1304-
1305 if (pending.count() == 1) {
pending.count() == 1Description
TRUEevaluated 1481 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1942 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
1481-1942
1306 // don't emit the commandStarted() signal before the ID is returned-
1307 QTimer::singleShot(0, q_func(), SLOT(_q_startNextCommand()));-
1308 }
executed 1481 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1481
1309 return cmd->id;
executed 3423 times by 2 tests: return cmd->id;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
3423
1310}-
1311-
1312/**********************************************************************-
1313 *-
1314 * QFtp implementation-
1315 *-
1316 *********************************************************************/-
1317/*!-
1318 \internal-
1319 \class QFtp-
1320 \brief The QFtp class provides an implementation of the client side of FTP protocol.-
1321-
1322 \ingroup network-
1323 \inmodule QtNetwork-
1324-
1325-
1326 This class provides a direct interface to FTP that allows you to-
1327 have more control over the requests. However, for new-
1328 applications, it is recommended to use QNetworkAccessManager and-
1329 QNetworkReply, as those classes possess a simpler, yet more-
1330 powerful API.-
1331-
1332 The class works asynchronously, so there are no blocking-
1333 functions. If an operation cannot be executed immediately, the-
1334 function will still return straight away and the operation will be-
1335 scheduled for later execution. The results of scheduled operations-
1336 are reported via signals. This approach depends on the event loop-
1337 being in operation.-
1338-
1339 The operations that can be scheduled (they are called "commands"-
1340 in the rest of the documentation) are the following:-
1341 connectToHost(), login(), close(), list(), cd(), get(), put(),-
1342 remove(), mkdir(), rmdir(), rename() and rawCommand().-
1343-
1344 All of these commands return a unique identifier that allows you-
1345 to keep track of the command that is currently being executed.-
1346 When the execution of a command starts, the commandStarted()-
1347 signal with the command's identifier is emitted. When the command-
1348 is finished, the commandFinished() signal is emitted with the-
1349 command's identifier and a bool that indicates whether the command-
1350 finished with an error.-
1351-
1352 In some cases, you might want to execute a sequence of commands,-
1353 e.g. if you want to connect and login to a FTP server. This is-
1354 simply achieved:-
1355-
1356 \snippet code/src_network_access_qftp.cpp 0-
1357-
1358 In this case two FTP commands have been scheduled. When the last-
1359 scheduled command has finished, a done() signal is emitted with-
1360 a bool argument that tells you whether the sequence finished with-
1361 an error.-
1362-
1363 If an error occurs during the execution of one of the commands in-
1364 a sequence of commands, all the pending commands (i.e. scheduled,-
1365 but not yet executed commands) are cleared and no signals are-
1366 emitted for them.-
1367-
1368 Some commands, e.g. list(), emit additional signals to report-
1369 their results.-
1370-
1371 Example: If you want to download the INSTALL file from the Qt-
1372 FTP server, you would write this:-
1373-
1374 \snippet code/src_network_access_qftp.cpp 1-
1375-
1376 For this example the following sequence of signals is emitted-
1377 (with small variations, depending on network traffic, etc.):-
1378-
1379 \snippet code/src_network_access_qftp.cpp 2-
1380-
1381 The dataTransferProgress() signal in the above example is useful-
1382 if you want to show a \l{QProgressBar}{progress bar} to-
1383 inform the user about the progress of the download. The-
1384 readyRead() signal tells you that there is data ready to be read.-
1385 The amount of data can be queried then with the bytesAvailable()-
1386 function and it can be read with the read() or readAll()-
1387 function.-
1388-
1389 If the login fails for the above example, the signals would look-
1390 like this:-
1391-
1392 \snippet code/src_network_access_qftp.cpp 3-
1393-
1394 You can then get details about the error with the error() and-
1395 errorString() functions.-
1396-
1397 For file transfer, QFtp can use both active or passive mode, and-
1398 it uses passive file transfer mode by default; see the-
1399 documentation for setTransferMode() for more details about this.-
1400-
1401 Call setProxy() to make QFtp connect via an FTP proxy server.-
1402-
1403 The functions currentId() and currentCommand() provide more-
1404 information about the currently executing command.-
1405-
1406 The functions hasPendingCommands() and clearPendingCommands()-
1407 allow you to query and clear the list of pending commands.-
1408-
1409 If you are an experienced network programmer and want to have-
1410 complete control you can use rawCommand() to execute arbitrary FTP-
1411 commands.-
1412-
1413 \warning The current version of QFtp doesn't fully support-
1414 non-Unix FTP servers.-
1415-
1416 \sa QNetworkAccessManager, QNetworkRequest, QNetworkReply,-
1417 {FTP Example}-
1418*/-
1419-
1420-
1421/*!-
1422 \internal-
1423 Constructs a QFtp object with the given \a parent.-
1424*/-
1425QFtp::QFtp(QObject *parent)-
1426 : QObject(*new QFtpPrivate, parent)-
1427{-
1428 Q_D(QFtp);-
1429 d->errorString = tr("Unknown error");-
1430-
1431 connect(&d->pi, SIGNAL(connectState(int)),-
1432 SLOT(_q_piConnectState(int)));-
1433 connect(&d->pi, SIGNAL(finished(QString)),-
1434 SLOT(_q_piFinished(QString)));-
1435 connect(&d->pi, SIGNAL(error(int,QString)),-
1436 SLOT(_q_piError(int,QString)));-
1437 connect(&d->pi, SIGNAL(rawFtpReply(int,QString)),-
1438 SLOT(_q_piFtpReply(int,QString)));-
1439-
1440 connect(&d->pi.dtp, SIGNAL(readyRead()),-
1441 SIGNAL(readyRead()));-
1442 connect(&d->pi.dtp, SIGNAL(dataTransferProgress(qint64,qint64)),-
1443 SIGNAL(dataTransferProgress(qint64,qint64)));-
1444 connect(&d->pi.dtp, SIGNAL(listInfo(QUrlInfo)),-
1445 SIGNAL(listInfo(QUrlInfo)));-
1446}
executed 661 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
661
1447-
1448/*!-
1449 \internal-
1450 \enum QFtp::State-
1451-
1452 This enum defines the connection state:-
1453-
1454 \value Unconnected There is no connection to the host.-
1455 \value HostLookup A host name lookup is in progress.-
1456 \value Connecting An attempt to connect to the host is in progress.-
1457 \value Connected Connection to the host has been achieved.-
1458 \value LoggedIn Connection and user login have been achieved.-
1459 \value Closing The connection is closing down, but it is not yet-
1460 closed. (The state will be \c Unconnected when the connection is-
1461 closed.)-
1462-
1463 \sa stateChanged(), state()-
1464*/-
1465/*!-
1466 \internal-
1467 \enum QFtp::TransferMode-
1468-
1469 FTP works with two socket connections; one for commands and-
1470 another for transmitting data. While the command connection is-
1471 always initiated by the client, the second connection can be-
1472 initiated by either the client or the server.-
1473-
1474 This enum defines whether the client (Passive mode) or the server-
1475 (Active mode) should set up the data connection.-
1476-
1477 \value Passive The client connects to the server to transmit its-
1478 data.-
1479-
1480 \value Active The server connects to the client to transmit its-
1481 data.-
1482*/-
1483/*!-
1484 \internal-
1485 \enum QFtp::TransferType-
1486-
1487 This enum identifies the data transfer type used with get and-
1488 put commands.-
1489-
1490 \value Binary The data will be transferred in Binary mode.-
1491-
1492 \value Ascii The data will be transferred in Ascii mode and new line-
1493 characters will be converted to the local format.-
1494*/-
1495/*!-
1496 \internal-
1497 \enum QFtp::Error-
1498-
1499 This enum identifies the error that occurred.-
1500-
1501 \value NoError No error occurred.-
1502 \value HostNotFound The host name lookup failed.-
1503 \value ConnectionRefused The server refused the connection.-
1504 \value NotConnected Tried to send a command, but there is no connection to-
1505 a server.-
1506 \value UnknownError An error other than those specified above-
1507 occurred.-
1508-
1509 \sa error()-
1510*/-
1511-
1512/*!-
1513 \internal-
1514 \enum QFtp::Command-
1515-
1516 This enum is used as the return value for the currentCommand() function.-
1517 This allows you to perform specific actions for particular-
1518 commands, e.g. in a FTP client, you might want to clear the-
1519 directory view when a list() command is started; in this case you-
1520 can simply check in the slot connected to the start() signal if-
1521 the currentCommand() is \c List.-
1522-
1523 \value None No command is being executed.-
1524 \value SetTransferMode set the \l{TransferMode}{transfer} mode.-
1525 \value SetProxy switch proxying on or off.-
1526 \value ConnectToHost connectToHost() is being executed.-
1527 \value Login login() is being executed.-
1528 \value Close close() is being executed.-
1529 \value List list() is being executed.-
1530 \value Cd cd() is being executed.-
1531 \value Get get() is being executed.-
1532 \value Put put() is being executed.-
1533 \value Remove remove() is being executed.-
1534 \value Mkdir mkdir() is being executed.-
1535 \value Rmdir rmdir() is being executed.-
1536 \value Rename rename() is being executed.-
1537 \value RawCommand rawCommand() is being executed.-
1538-
1539 \sa currentCommand()-
1540*/-
1541-
1542/*!-
1543 \internal-
1544 \fn void QFtp::stateChanged(int state)-
1545-
1546 This signal is emitted when the state of the connection changes.-
1547 The argument \a state is the new state of the connection; it is-
1548 one of the \l State values.-
1549-
1550 It is usually emitted in response to a connectToHost() or close()-
1551 command, but it can also be emitted "spontaneously", e.g. when the-
1552 server closes the connection unexpectedly.-
1553-
1554 \sa connectToHost(), close(), state(), State-
1555*/-
1556-
1557/*!-
1558 \internal-
1559 \fn void QFtp::listInfo(const QUrlInfo &i);-
1560-
1561 This signal is emitted for each directory entry the list() command-
1562 finds. The details of the entry are stored in \a i.-
1563-
1564 \sa list()-
1565*/-
1566-
1567/*!-
1568 \internal-
1569 \fn void QFtp::commandStarted(int id)-
1570-
1571 This signal is emitted when processing the command identified by-
1572 \a id starts.-
1573-
1574 \sa commandFinished(), done()-
1575*/-
1576-
1577/*!-
1578 \internal-
1579 \fn void QFtp::commandFinished(int id, bool error)-
1580-
1581 This signal is emitted when processing the command identified by-
1582 \a id has finished. \a error is true if an error occurred during-
1583 the processing; otherwise \a error is false.-
1584-
1585 \sa commandStarted(), done(), error(), errorString()-
1586*/-
1587-
1588/*!-
1589 \internal-
1590 \fn void QFtp::done(bool error)-
1591-
1592 This signal is emitted when the last pending command has finished;-
1593 (it is emitted after the last command's commandFinished() signal).-
1594 \a error is true if an error occurred during the processing;-
1595 otherwise \a error is false.-
1596-
1597 \sa commandFinished(), error(), errorString()-
1598*/-
1599-
1600/*!-
1601 \internal-
1602 \fn void QFtp::readyRead()-
1603-
1604 This signal is emitted in response to a get() command when there-
1605 is new data to read.-
1606-
1607 If you specify a device as the second argument in the get()-
1608 command, this signal is \e not emitted; instead the data is-
1609 written directly to the device.-
1610-
1611 You can read the data with the readAll() or read() functions.-
1612-
1613 This signal is useful if you want to process the data in chunks as-
1614 soon as it becomes available. If you are only interested in the-
1615 complete data, just connect to the commandFinished() signal and-
1616 read the data then instead.-
1617-
1618 \sa get(), read(), readAll(), bytesAvailable()-
1619*/-
1620-
1621/*!-
1622 \internal-
1623 \fn void QFtp::dataTransferProgress(qint64 done, qint64 total)-
1624-
1625 This signal is emitted in response to a get() or put() request to-
1626 indicate the current progress of the download or upload.-
1627-
1628 \a done is the amount of data that has already been transferred-
1629 and \a total is the total amount of data to be read or written. It-
1630 is possible that the QFtp class is not able to determine the total-
1631 amount of data that should be transferred, in which case \a total-
1632 is 0. (If you connect this signal to a QProgressBar, the progress-
1633 bar shows a busy indicator if the total is 0).-
1634-
1635 \warning \a done and \a total are not necessarily the size in-
1636 bytes, since for large files these values might need to be-
1637 "scaled" to avoid overflow.-
1638-
1639 \sa get(), put(), QProgressBar-
1640*/-
1641-
1642/*!-
1643 \internal-
1644 \fn void QFtp::rawCommandReply(int replyCode, const QString &detail);-
1645-
1646 This signal is emitted in response to the rawCommand() function.-
1647 \a replyCode is the 3 digit reply code and \a detail is the text-
1648 that follows the reply code.-
1649-
1650 \sa rawCommand()-
1651*/-
1652-
1653/*!-
1654 \internal-
1655 Connects to the FTP server \a host using port \a port.-
1656-
1657 The stateChanged() signal is emitted when the state of the-
1658 connecting process changes, e.g. to \c HostLookup, then \c-
1659 Connecting, then \c Connected.-
1660-
1661 The function does not block and returns immediately. The command-
1662 is scheduled, and its execution is performed asynchronously. The-
1663 function returns a unique identifier which is passed by-
1664 commandStarted() and commandFinished().-
1665-
1666 When the command is started the commandStarted() signal is-
1667 emitted. When it is finished the commandFinished() signal is-
1668 emitted.-
1669-
1670 \sa stateChanged(), commandStarted(), commandFinished()-
1671*/-
1672int QFtp::connectToHost(const QString &host, quint16 port)-
1673{-
1674 QStringList cmds;-
1675 cmds << host;-
1676 cmds << QString::number((uint)port);-
1677 int id = d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds));-
1678 d_func()->pi.transferConnectionExtended = true;-
1679 return id;
executed 657 times by 2 tests: return id;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
657
1680}-
1681-
1682/*!-
1683 \internal-
1684 Logs in to the FTP server with the username \a user and the-
1685 password \a password.-
1686-
1687 The stateChanged() signal is emitted when the state of the-
1688 connecting process changes, e.g. to \c LoggedIn.-
1689-
1690 The function does not block and returns immediately. The command-
1691 is scheduled, and its execution is performed asynchronously. The-
1692 function returns a unique identifier which is passed by-
1693 commandStarted() and commandFinished().-
1694-
1695 When the command is started the commandStarted() signal is-
1696 emitted. When it is finished the commandFinished() signal is-
1697 emitted.-
1698-
1699 \sa commandStarted(), commandFinished()-
1700*/-
1701int QFtp::login(const QString &user, const QString &password)-
1702{-
1703 QStringList cmds;-
1704 cmds << (QLatin1String("USER ") + (user.isNull() ? QLatin1String("anonymous") : user) + QLatin1String("\r\n"));-
1705 cmds << (QLatin1String("PASS ") + (password.isNull() ? QLatin1String("anonymous@") : password) + QLatin1String("\r\n"));-
1706 return d_func()->addCommand(new QFtpCommand(Login, cmds));
executed 636 times by 2 tests: return d_func()->addCommand(new QFtpCommand(Login, cmds));
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
636
1707}-
1708-
1709/*!-
1710 \internal-
1711 Closes the connection to the FTP server.-
1712-
1713 The stateChanged() signal is emitted when the state of the-
1714 connecting process changes, e.g. to \c Closing, then \c-
1715 Unconnected.-
1716-
1717 The function does not block and returns immediately. The command-
1718 is scheduled, and its execution is performed asynchronously. The-
1719 function returns a unique identifier which is passed by-
1720 commandStarted() and commandFinished().-
1721-
1722 When the command is started the commandStarted() signal is-
1723 emitted. When it is finished the commandFinished() signal is-
1724 emitted.-
1725-
1726 \sa stateChanged(), commandStarted(), commandFinished()-
1727*/-
1728int QFtp::close()-
1729{-
1730 return d_func()->addCommand(new QFtpCommand(Close, QStringList(QLatin1String("QUIT\r\n"))));
executed 1235 times by 2 tests: return d_func()->addCommand(new QFtpCommand(Close, QStringList(QLatin1String("QUIT\r\n"))));
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1235
1731}-
1732-
1733/*!-
1734 \internal-
1735 Sets the current FTP transfer mode to \a mode. The default is QFtp::Passive.-
1736-
1737 \sa QFtp::TransferMode-
1738*/-
1739int QFtp::setTransferMode(TransferMode mode)-
1740{-
1741 int id = d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList()));-
1742 d_func()->pi.transferConnectionExtended = true;-
1743 d_func()->transferMode = mode;-
1744 return id;
executed 4 times by 1 test: return id;
Executed by:
  • tst_QFtp
4
1745}-
1746-
1747/*!-
1748 \internal-
1749 Enables use of the FTP proxy on host \a host and port \a-
1750 port. Calling this function with \a host empty disables proxying.-
1751-
1752 QFtp does not support FTP-over-HTTP proxy servers. Use-
1753 QNetworkAccessManager for this.-
1754*/-
1755int QFtp::setProxy(const QString &host, quint16 port)-
1756{-
1757 QStringList args;-
1758 args << host << QString::number(port);-
1759 return d_func()->addCommand(new QFtpCommand(SetProxy, args));
executed 26 times by 2 tests: return d_func()->addCommand(new QFtpCommand(SetProxy, args));
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
26
1760}-
1761-
1762/*!-
1763 \internal-
1764 Lists the contents of directory \a dir on the FTP server. If \a-
1765 dir is empty, it lists the contents of the current directory.-
1766-
1767 The listInfo() signal is emitted for each directory entry found.-
1768-
1769 The function does not block and returns immediately. The command-
1770 is scheduled, and its execution is performed asynchronously. The-
1771 function returns a unique identifier which is passed by-
1772 commandStarted() and commandFinished().-
1773-
1774 When the command is started the commandStarted() signal is-
1775 emitted. When it is finished the commandFinished() signal is-
1776 emitted.-
1777-
1778 \sa listInfo(), commandStarted(), commandFinished()-
1779*/-
1780int QFtp::list(const QString &dir)-
1781{-
1782 QStringList cmds;-
1783 cmds << QLatin1String("TYPE A\r\n");-
1784 cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");-
1785 if (dir.isEmpty())
dir.isEmpty()Description
TRUEevaluated 72 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 156 times by 1 test
Evaluated by:
  • tst_QFtp
72-156
1786 cmds << QLatin1String("LIST\r\n");
executed 72 times by 1 test: cmds << QLatin1String("LIST\r\n");
Executed by:
  • tst_QFtp
72
1787 else-
1788 cmds << (QLatin1String("LIST ") + dir + QLatin1String("\r\n"));
executed 156 times by 1 test: cmds << (QLatin1String("LIST ") + dir + QLatin1String("\r\n"));
Executed by:
  • tst_QFtp
156
1789 return d_func()->addCommand(new QFtpCommand(List, cmds));
executed 228 times by 1 test: return d_func()->addCommand(new QFtpCommand(List, cmds));
Executed by:
  • tst_QFtp
228
1790}-
1791-
1792/*!-
1793 \internal-
1794 Changes the working directory of the server to \a dir.-
1795-
1796 The function does not block and returns immediately. The command-
1797 is scheduled, and its execution is performed asynchronously. The-
1798 function returns a unique identifier which is passed by-
1799 commandStarted() and commandFinished().-
1800-
1801 When the command is started the commandStarted() signal is-
1802 emitted. When it is finished the commandFinished() signal is-
1803 emitted.-
1804-
1805 \sa commandStarted(), commandFinished()-
1806*/-
1807int QFtp::cd(const QString &dir)-
1808{-
1809 return d_func()->addCommand(new QFtpCommand(Cd, QStringList(QLatin1String("CWD ") + dir + QLatin1String("\r\n"))));
executed 216 times by 1 test: return d_func()->addCommand(new QFtpCommand(Cd, QStringList(QLatin1String("CWD ") + dir + QLatin1String("\r\n"))));
Executed by:
  • tst_QFtp
216
1810}-
1811-
1812/*!-
1813 \internal-
1814 Downloads the file \a file from the server.-
1815-
1816 If \a dev is 0, then the readyRead() signal is emitted when there-
1817 is data available to read. You can then read the data with the-
1818 read() or readAll() functions.-
1819-
1820 If \a dev is not 0, the data is written directly to the device \a-
1821 dev. Make sure that the \a dev pointer is valid for the duration-
1822 of the operation (it is safe to delete it when the-
1823 commandFinished() signal is emitted). In this case the readyRead()-
1824 signal is \e not emitted and you cannot read data with the-
1825 read() or readAll() functions.-
1826-
1827 If you don't read the data immediately it becomes available, i.e.-
1828 when the readyRead() signal is emitted, it is still available-
1829 until the next command is started.-
1830-
1831 For example, if you want to present the data to the user as soon-
1832 as there is something available, connect to the readyRead() signal-
1833 and read the data immediately. On the other hand, if you only want-
1834 to work with the complete data, you can connect to the-
1835 commandFinished() signal and read the data when the get() command-
1836 is finished.-
1837-
1838 The data is transferred as Binary or Ascii depending on the value-
1839 of \a type.-
1840-
1841 The function does not block and returns immediately. The command-
1842 is scheduled, and its execution is performed asynchronously. The-
1843 function returns a unique identifier which is passed by-
1844 commandStarted() and commandFinished().-
1845-
1846 When the command is started the commandStarted() signal is-
1847 emitted. When it is finished the commandFinished() signal is-
1848 emitted.-
1849-
1850 \sa readyRead(), dataTransferProgress(), commandStarted(),-
1851 commandFinished()-
1852*/-
1853int QFtp::get(const QString &file, QIODevice *dev, TransferType type)-
1854{-
1855 QStringList cmds;-
1856 if (type == Binary)
type == BinaryDescription
TRUEevaluated 110 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-110
1857 cmds << QLatin1String("TYPE I\r\n");
executed 110 times by 2 tests: cmds << QLatin1String("TYPE I\r\n");
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
110
1858 else-
1859 cmds << QLatin1String("TYPE A\r\n");
never executed: cmds << QLatin1String("TYPE A\r\n");
0
1860 cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n");-
1861 cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");-
1862 cmds << QLatin1String("RETR ") + file + QLatin1String("\r\n");-
1863 return d_func()->addCommand(new QFtpCommand(Get, cmds, dev));
executed 110 times by 2 tests: return d_func()->addCommand(new QFtpCommand(Get, cmds, dev));
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
110
1864}-
1865-
1866/*!-
1867 \internal-
1868 \overload-
1869-
1870 Writes a copy of the given \a data to the file called \a file on-
1871 the server. The progress of the upload is reported by the-
1872 dataTransferProgress() signal.-
1873-
1874 The data is transferred as Binary or Ascii depending on the value-
1875 of \a type.-
1876-
1877 The function does not block and returns immediately. The command-
1878 is scheduled, and its execution is performed asynchronously. The-
1879 function returns a unique identifier which is passed by-
1880 commandStarted() and commandFinished().-
1881-
1882 When the command is started the commandStarted() signal is-
1883 emitted. When it is finished the commandFinished() signal is-
1884 emitted.-
1885-
1886 Since this function takes a copy of the \a data, you can discard-
1887 your own copy when this function returns.-
1888-
1889 \sa dataTransferProgress(), commandStarted(), commandFinished()-
1890*/-
1891int QFtp::put(const QByteArray &data, const QString &file, TransferType type)-
1892{-
1893 QStringList cmds;-
1894 if (type == Binary)
type == BinaryDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
4-24
1895 cmds << QLatin1String("TYPE I\r\n");
executed 24 times by 1 test: cmds << QLatin1String("TYPE I\r\n");
Executed by:
  • tst_QFtp
24
1896 else-
1897 cmds << QLatin1String("TYPE A\r\n");
executed 4 times by 1 test: cmds << QLatin1String("TYPE A\r\n");
Executed by:
  • tst_QFtp
4
1898 cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");-
1899 cmds << QLatin1String("ALLO ") + QString::number(data.size()) + QLatin1String("\r\n");-
1900 cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n");-
1901 return d_func()->addCommand(new QFtpCommand(Put, cmds, data));
executed 28 times by 1 test: return d_func()->addCommand(new QFtpCommand(Put, cmds, data));
Executed by:
  • tst_QFtp
28
1902}-
1903-
1904/*!-
1905 \internal-
1906 Reads the data from the IO device \a dev, and writes it to the-
1907 file called \a file on the server. The data is read in chunks from-
1908 the IO device, so this overload allows you to transmit large-
1909 amounts of data without the need to read all the data into memory-
1910 at once.-
1911-
1912 The data is transferred as Binary or Ascii depending on the value-
1913 of \a type.-
1914-
1915 Make sure that the \a dev pointer is valid for the duration of the-
1916 operation (it is safe to delete it when the commandFinished() is-
1917 emitted).-
1918*/-
1919int QFtp::put(QIODevice *dev, const QString &file, TransferType type)-
1920{-
1921 QStringList cmds;-
1922 if (type == Binary)
type == BinaryDescription
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-15
1923 cmds << QLatin1String("TYPE I\r\n");
executed 15 times by 2 tests: cmds << QLatin1String("TYPE I\r\n");
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
15
1924 else-
1925 cmds << QLatin1String("TYPE A\r\n");
never executed: cmds << QLatin1String("TYPE A\r\n");
0
1926 cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");-
1927 if (!dev->isSequential())
!dev->isSequential()Description
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-15
1928 cmds << QLatin1String("ALLO ") + QString::number(dev->size()) + QLatin1String("\r\n");
executed 15 times by 2 tests: cmds << QLatin1String("ALLO ") + QString::number(dev->size()) + QLatin1String("\r\n");
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
15
1929 cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n");-
1930 return d_func()->addCommand(new QFtpCommand(Put, cmds, dev));
executed 15 times by 2 tests: return d_func()->addCommand(new QFtpCommand(Put, cmds, dev));
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
15
1931}-
1932-
1933/*!-
1934 \internal-
1935 Deletes the file called \a file from the server.-
1936-
1937 The function does not block and returns immediately. The command-
1938 is scheduled, and its execution is performed asynchronously. The-
1939 function returns a unique identifier which is passed by-
1940 commandStarted() and commandFinished().-
1941-
1942 When the command is started the commandStarted() signal is-
1943 emitted. When it is finished the commandFinished() signal is-
1944 emitted.-
1945-
1946 \sa commandStarted(), commandFinished()-
1947*/-
1948int QFtp::remove(const QString &file)-
1949{-
1950 return d_func()->addCommand(new QFtpCommand(Remove, QStringList(QLatin1String("DELE ") + file + QLatin1String("\r\n"))));
executed 32 times by 1 test: return d_func()->addCommand(new QFtpCommand(Remove, QStringList(QLatin1String("DELE ") + file + QLatin1String("\r\n"))));
Executed by:
  • tst_QFtp
32
1951}-
1952-
1953/*!-
1954 \internal-
1955 Creates a directory called \a dir on the server.-
1956-
1957 The function does not block and returns immediately. The command-
1958 is scheduled, and its execution is performed asynchronously. The-
1959 function returns a unique identifier which is passed by-
1960 commandStarted() and commandFinished().-
1961-
1962 When the command is started the commandStarted() signal is-
1963 emitted. When it is finished the commandFinished() signal is-
1964 emitted.-
1965-
1966 \sa commandStarted(), commandFinished()-
1967*/-
1968int QFtp::mkdir(const QString &dir)-
1969{-
1970 return d_func()->addCommand(new QFtpCommand(Mkdir, QStringList(QLatin1String("MKD ") + dir + QLatin1String("\r\n"))));
executed 52 times by 1 test: return d_func()->addCommand(new QFtpCommand(Mkdir, QStringList(QLatin1String("MKD ") + dir + QLatin1String("\r\n"))));
Executed by:
  • tst_QFtp
52
1971}-
1972-
1973/*!-
1974 \internal-
1975 Removes the directory called \a dir from the server.-
1976-
1977 The function does not block and returns immediately. The command-
1978 is scheduled, and its execution is performed asynchronously. The-
1979 function returns a unique identifier which is passed by-
1980 commandStarted() and commandFinished().-
1981-
1982 When the command is started the commandStarted() signal is-
1983 emitted. When it is finished the commandFinished() signal is-
1984 emitted.-
1985-
1986 \sa commandStarted(), commandFinished()-
1987*/-
1988int QFtp::rmdir(const QString &dir)-
1989{-
1990 return d_func()->addCommand(new QFtpCommand(Rmdir, QStringList(QLatin1String("RMD ") + dir + QLatin1String("\r\n"))));
executed 20 times by 1 test: return d_func()->addCommand(new QFtpCommand(Rmdir, QStringList(QLatin1String("RMD ") + dir + QLatin1String("\r\n"))));
Executed by:
  • tst_QFtp
20
1991}-
1992-
1993/*!-
1994 \internal-
1995 Renames the file called \a oldname to \a newname on the server.-
1996-
1997 The function does not block and returns immediately. The command-
1998 is scheduled, and its execution is performed asynchronously. The-
1999 function returns a unique identifier which is passed by-
2000 commandStarted() and commandFinished().-
2001-
2002 When the command is started the commandStarted() signal is-
2003 emitted. When it is finished the commandFinished() signal is-
2004 emitted.-
2005-
2006 \sa commandStarted(), commandFinished()-
2007*/-
2008int QFtp::rename(const QString &oldname, const QString &newname)-
2009{-
2010 QStringList cmds;-
2011 cmds << QLatin1String("RNFR ") + oldname + QLatin1String("\r\n");-
2012 cmds << QLatin1String("RNTO ") + newname + QLatin1String("\r\n");-
2013 return d_func()->addCommand(new QFtpCommand(Rename, cmds));
executed 28 times by 1 test: return d_func()->addCommand(new QFtpCommand(Rename, cmds));
Executed by:
  • tst_QFtp
28
2014}-
2015-
2016/*!-
2017 \internal-
2018 Sends the raw FTP command \a command to the FTP server. This is-
2019 useful for low-level FTP access. If the operation you wish to-
2020 perform has an equivalent QFtp function, we recommend using the-
2021 function instead of raw FTP commands since the functions are-
2022 easier and safer.-
2023-
2024 The function does not block and returns immediately. The command-
2025 is scheduled, and its execution is performed asynchronously. The-
2026 function returns a unique identifier which is passed by-
2027 commandStarted() and commandFinished().-
2028-
2029 When the command is started the commandStarted() signal is-
2030 emitted. When it is finished the commandFinished() signal is-
2031 emitted.-
2032-
2033 \sa rawCommandReply(), commandStarted(), commandFinished()-
2034*/-
2035int QFtp::rawCommand(const QString &command)-
2036{-
2037 const QString cmd = QStringRef(&command).trimmed() + QLatin1String("\r\n");-
2038 return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd)));
executed 136 times by 1 test: return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd)));
Executed by:
  • tst_QNetworkReply
136
2039}-
2040-
2041/*!-
2042 \internal-
2043 Returns the number of bytes that can be read from the data socket-
2044 at the moment.-
2045-
2046 \sa get(), readyRead(), read(), readAll()-
2047*/-
2048qint64 QFtp::bytesAvailable() const-
2049{-
2050 return d_func()->pi.dtp.bytesAvailable();
executed 6171 times by 2 tests: return d_func()->pi.dtp.bytesAvailable();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
6171
2051}-
2052-
2053/*!-
2054 \internal-
2055 Reads \a maxlen bytes from the data socket into \a data and-
2056 returns the number of bytes read. Returns -1 if an error occurred.-
2057-
2058 \sa get(), readyRead(), bytesAvailable(), readAll()-
2059*/-
2060qint64 QFtp::read(char *data, qint64 maxlen)-
2061{-
2062 return d_func()->pi.dtp.read(data, maxlen);
never executed: return d_func()->pi.dtp.read(data, maxlen);
0
2063}-
2064-
2065/*!-
2066 \internal-
2067 Reads all the bytes available from the data socket and returns-
2068 them.-
2069-
2070 \sa get(), readyRead(), bytesAvailable(), read()-
2071*/-
2072QByteArray QFtp::readAll()-
2073{-
2074 return d_func()->pi.dtp.readAll();
executed 611 times by 2 tests: return d_func()->pi.dtp.readAll();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
611
2075}-
2076-
2077/*!-
2078 \internal-
2079 Aborts the current command and deletes all scheduled commands.-
2080-
2081 If there is an unfinished command (i.e. a command for which the-
2082 commandStarted() signal has been emitted, but for which the-
2083 commandFinished() signal has not been emitted), this function-
2084 sends an \c ABORT command to the server. When the server replies-
2085 that the command is aborted, the commandFinished() signal with the-
2086 \c error argument set to \c true is emitted for the command. Due-
2087 to timing issues, it is possible that the command had already-
2088 finished before the abort request reached the server, in which-
2089 case, the commandFinished() signal is emitted with the \c error-
2090 argument set to \c false.-
2091-
2092 For all other commands that are affected by the abort(), no-
2093 signals are emitted.-
2094-
2095 If you don't start further FTP commands directly after the-
2096 abort(), there won't be any scheduled commands and the done()-
2097 signal is emitted.-
2098-
2099 \warning Some FTP servers, for example the BSD FTP daemon (version-
2100 0.3), wrongly return a positive reply even when an abort has-
2101 occurred. For these servers the commandFinished() signal has its-
2102 error flag set to \c false, even though the command did not-
2103 complete successfully.-
2104-
2105 \sa clearPendingCommands()-
2106*/-
2107void QFtp::abort()-
2108{-
2109 if (d_func()->pending.isEmpty())
d_func()->pending.isEmpty()Description
TRUEevaluated 657 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
4-657
2110 return;
executed 657 times by 2 tests: return;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
657
2111-
2112 clearPendingCommands();-
2113 d_func()->pi.abort();-
2114}
executed 4 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4
2115-
2116/*!-
2117 \internal-
2118 Returns the identifier of the FTP command that is being executed-
2119 or 0 if there is no command being executed.-
2120-
2121 \sa currentCommand()-
2122*/-
2123int QFtp::currentId() const-
2124{-
2125 if (d_func()->pending.isEmpty())
d_func()->pending.isEmpty()Description
TRUEevaluated 731 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 48388 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
731-48388
2126 return 0;
executed 731 times by 1 test: return 0;
Executed by:
  • tst_QFtp
731
2127 return d_func()->pending.first()->id;
executed 48388 times by 2 tests: return d_func()->pending.first()->id;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
48388
2128}-
2129-
2130/*!-
2131 \internal-
2132 Returns the command type of the FTP command being executed or \c-
2133 None if there is no command being executed.-
2134-
2135 \sa currentId()-
2136*/-
2137QFtp::Command QFtp::currentCommand() const-
2138{-
2139 if (d_func()->pending.isEmpty())
d_func()->pending.isEmpty()Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 20744 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
24-20744
2140 return None;
executed 24 times by 1 test: return None;
Executed by:
  • tst_QFtp
24
2141 return d_func()->pending.first()->command;
executed 20744 times by 2 tests: return d_func()->pending.first()->command;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
20744
2142}-
2143-
2144/*!-
2145 \internal-
2146 Returns the QIODevice pointer that is used by the FTP command to read data-
2147 from or store data to. If there is no current FTP command being executed or-
2148 if the command does not use an IO device, this function returns 0.-
2149-
2150 This function can be used to delete the QIODevice in the slot connected to-
2151 the commandFinished() signal.-
2152-
2153 \sa get(), put()-
2154*/-
2155QIODevice* QFtp::currentDevice() const-
2156{-
2157 if (d_func()->pending.isEmpty())
d_func()->pending.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2158 return 0;
never executed: return 0;
0
2159 QFtpCommand *c = d_func()->pending.first();-
2160 if (c->is_ba)
c->is_baDescription
TRUEnever evaluated
FALSEnever evaluated
0
2161 return 0;
never executed: return 0;
0
2162 return c->data.dev;
never executed: return c->data.dev;
0
2163}-
2164-
2165/*!-
2166 \internal-
2167 Returns \c true if there are any commands scheduled that have not yet-
2168 been executed; otherwise returns \c false.-
2169-
2170 The command that is being executed is \e not considered as a-
2171 scheduled command.-
2172-
2173 \sa clearPendingCommands(), currentId(), currentCommand()-
2174*/-
2175bool QFtp::hasPendingCommands() const-
2176{-
2177 return d_func()->pending.count() > 1;
executed 7303 times by 1 test: return d_func()->pending.count() > 1;
Executed by:
  • tst_QFtp
7303
2178}-
2179-
2180/*!-
2181 \internal-
2182 Deletes all pending commands from the list of scheduled commands.-
2183 This does not affect the command that is being executed. If you-
2184 want to stop this as well, use abort().-
2185-
2186 \sa hasPendingCommands(), abort()-
2187*/-
2188void QFtp::clearPendingCommands()-
2189{-
2190 // delete all entires except the first one-
2191 while (d_func()->pending.count() > 1)
d_func()->pending.count() > 1Description
TRUEevaluated 119 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 165 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
119-165
2192 delete d_func()->pending.takeLast();
executed 119 times by 2 tests: delete d_func()->pending.takeLast();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
119
2193}
executed 165 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
165
2194-
2195/*!-
2196 \internal-
2197 Returns the current state of the object. When the state changes,-
2198 the stateChanged() signal is emitted.-
2199-
2200 \sa State, stateChanged()-
2201*/-
2202QFtp::State QFtp::state() const-
2203{-
2204 return d_func()->state;
executed 10413 times by 2 tests: return d_func()->state;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
10413
2205}-
2206-
2207/*!-
2208 \internal-
2209 Returns the last error that occurred. This is useful to find out-
2210 what went wrong when receiving a commandFinished() or a done()-
2211 signal with the \c error argument set to \c true.-
2212-
2213 If you start a new command, the error status is reset to \c NoError.-
2214*/-
2215QFtp::Error QFtp::error() const-
2216{-
2217 return d_func()->error;
executed 5556 times by 2 tests: return d_func()->error;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
5556
2218}-
2219-
2220/*!-
2221 \internal-
2222 Returns a human-readable description of the last error that-
2223 occurred. This is useful for presenting a error message to the-
2224 user when receiving a commandFinished() or a done() signal with-
2225 the \c error argument set to \c true.-
2226-
2227 The error string is often (but not always) the reply from the-
2228 server, so it is not always possible to translate the string. If-
2229 the message comes from Qt, the string has already passed through-
2230 tr().-
2231*/-
2232QString QFtp::errorString() const-
2233{-
2234 return d_func()->errorString;
executed 6 times by 1 test: return d_func()->errorString;
Executed by:
  • tst_QNetworkReply
6
2235}-
2236-
2237/*! \internal-
2238*/-
2239void QFtpPrivate::_q_startNextCommand()-
2240{-
2241 Q_Q(QFtp);-
2242 if (pending.isEmpty())
pending.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 2643 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-2643
2243 return;
never executed: return;
0
2244 QFtpCommand *c = pending.constFirst();-
2245-
2246 error = QFtp::NoError;-
2247 errorString = QT_TRANSLATE_NOOP(QFtp, QLatin1String("Unknown error"));-
2248-
2249 if (q->bytesAvailable())
q->bytesAvailable()Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 2635 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
8-2635
2250 q->readAll(); // clear the data
executed 8 times by 1 test: q->readAll();
Executed by:
  • tst_QFtp
8
2251 emit q->commandStarted(c->id);-
2252-
2253 // Proxy support, replace the Login argument in place, then fall-
2254 // through.-
2255 if (c->command == QFtp::Login && !proxyHost.isEmpty()) {
c->command == QFtp::LoginDescription
TRUEevaluated 633 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 2010 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
!proxyHost.isEmpty()Description
TRUEevaluated 26 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 607 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
26-2010
2256 QString loginString;-
2257 loginString += QStringRef(&c->rawCmds.constFirst()).trimmed() + QLatin1Char('@') + host;-
2258 if (port && port != 21)
portDescription
TRUEevaluated 26 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
port != 21Description
TRUEnever evaluated
FALSEevaluated 26 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-26
2259 loginString += QLatin1Char(':') + QString::number(port);
never executed: loginString += QLatin1Char(':') + QString::number(port);
0
2260 loginString += QLatin1String("\r\n");-
2261 c->rawCmds[0] = loginString;-
2262 }
executed 26 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
26
2263-
2264 if (c->command == QFtp::SetTransferMode) {
c->command == ...etTransferModeDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 2639 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
4-2639
2265 _q_piFinished(QLatin1String("Transfer mode set"));-
2266 } else if (c->command == QFtp::SetProxy) {
executed 4 times by 1 test: end of block
Executed by:
  • tst_QFtp
c->command == QFtp::SetProxyDescription
TRUEevaluated 26 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 2613 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
4-2613
2267 proxyHost = c->rawCmds.at(0);-
2268 proxyPort = c->rawCmds.at(1).toUInt();-
2269 c->rawCmds.clear();-
2270 _q_piFinished(QLatin1String("Proxy set to ") + proxyHost + QLatin1Char(':') + QString::number(proxyPort));-
2271 } else if (c->command == QFtp::ConnectToHost) {
executed 26 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
c->command == ...:ConnectToHostDescription
TRUEevaluated 657 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1956 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
26-1956
2272#ifndef QT_NO_BEARERMANAGEMENT-
2273 //copy network session down to the PI-
2274 pi.setProperty("_q_networksession", q->property("_q_networksession"));-
2275#endif-
2276 if (!proxyHost.isEmpty()) {
!proxyHost.isEmpty()Description
TRUEevaluated 26 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 631 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
26-631
2277 host = c->rawCmds.at(0);-
2278 port = c->rawCmds.at(1).toUInt();-
2279 pi.connectToHost(proxyHost, proxyPort);-
2280 } else {
executed 26 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
26
2281 pi.connectToHost(c->rawCmds.at(0), c->rawCmds.at(1).toUInt());-
2282 }
executed 631 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
631
2283 } else {-
2284 if (c->command == QFtp::Put) {
c->command == QFtp::PutDescription
TRUEevaluated 43 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1913 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
43-1913
2285 if (c->is_ba) {
c->is_baDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
15-28
2286 pi.dtp.setData(c->data.ba);-
2287 pi.dtp.setBytesTotal(c->data.ba->size());-
2288 } else if (c->data.dev && (c->data.dev->isOpen() || c->data.dev->open(QIODevice::ReadOnly))) {
executed 28 times by 1 test: end of block
Executed by:
  • tst_QFtp
c->data.devDescription
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
c->data.dev->isOpen()Description
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
c->data.dev->o...ice::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0-28
2289 pi.dtp.setDevice(c->data.dev);-
2290 if (c->data.dev->isSequential()) {
c->data.dev->isSequential()Description
TRUEnever evaluated
FALSEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-15
2291 pi.dtp.setBytesTotal(0);-
2292 pi.dtp.connect(c->data.dev, SIGNAL(readyRead()), SLOT(dataReadyRead()));-
2293 pi.dtp.connect(c->data.dev, SIGNAL(readChannelFinished()), SLOT(dataReadyRead()));-
2294 } else {
never executed: end of block
0
2295 pi.dtp.setBytesTotal(c->data.dev->size());-
2296 }
executed 15 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
15
2297 }-
2298 } else if (c->command == QFtp::Get) {
executed 43 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
c->command == QFtp::GetDescription
TRUEevaluated 110 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1803 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
43-1803
2299 if (!c->is_ba && c->data.dev) {
!c->is_baDescription
TRUEevaluated 110 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
c->data.devDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 70 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-110
2300 pi.dtp.setDevice(c->data.dev);-
2301 }
executed 40 times by 1 test: end of block
Executed by:
  • tst_QFtp
40
2302 } else if (c->command == QFtp::Close) {
executed 110 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
c->command == QFtp::CloseDescription
TRUEevaluated 480 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1323 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
110-1323
2303 state = QFtp::Closing;-
2304 emit q->stateChanged(state);-
2305 }
executed 480 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
480
2306 pi.sendCommands(c->rawCmds);-
2307 }
executed 1956 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1956
2308}-
2309-
2310/*! \internal-
2311*/-
2312void QFtpPrivate::_q_piFinished(const QString&)-
2313{-
2314 if (pending.isEmpty())
pending.isEmpty()Description
TRUEevaluated 116 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 2957 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
116-2957
2315 return;
executed 116 times by 1 test: return;
Executed by:
  • tst_QFtp
116
2316 QFtpCommand *c = pending.constFirst();-
2317-
2318 if (c->command == QFtp::Close) {
c->command == QFtp::CloseDescription
TRUEevaluated 948 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 2009 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
948-2009
2319 // The order of in which the slots are called is arbitrary, so-
2320 // disconnect the SIGNAL-SIGNAL temporary to make sure that we-
2321 // don't get the commandFinished() signal before the stateChanged()-
2322 // signal.-
2323 if (state != QFtp::Unconnected) {
state != QFtp::UnconnectedDescription
TRUEevaluated 479 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 469 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
469-479
2324 close_waitForStateChange = true;-
2325 return;
executed 479 times by 2 tests: return;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
479
2326 }-
2327 }
executed 469 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
469
2328 emit q_func()->commandFinished(c->id, false);-
2329 pending.removeFirst();-
2330-
2331 delete c;-
2332-
2333 if (pending.isEmpty()) {
pending.isEmpty()Description
TRUEevaluated 663 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 1815 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
663-1815
2334 emit q_func()->done(false);-
2335 } else {
executed 663 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
663
2336 _q_startNextCommand();-
2337 }
executed 1815 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
1815
2338}-
2339-
2340/*! \internal-
2341*/-
2342void QFtpPrivate::_q_piError(int errorCode, const QString &text)-
2343{-
2344 Q_Q(QFtp);-
2345-
2346 if (pending.isEmpty()) {
pending.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 220 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
0-220
2347 qWarning("QFtpPrivate::_q_piError was called without pending command!");-
2348 return;
never executed: return;
0
2349 }-
2350-
2351 QFtpCommand *c = pending.constFirst();-
2352-
2353 // non-fatal errors-
2354 if (c->command == QFtp::Get && pi.currentCommand().startsWith(QLatin1String("SIZE "))) {
c->command == QFtp::GetDescription
TRUEevaluated 33 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 187 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
pi.currentComm...ring("SIZE "))Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QFtp
FALSEevaluated 17 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
16-187
2355 pi.dtp.setBytesTotal(0);-
2356 return;
executed 16 times by 1 test: return;
Executed by:
  • tst_QFtp
16
2357 } else if (c->command==QFtp::Put && pi.currentCommand().startsWith(QLatin1String("ALLO "))) {
c->command==QFtp::PutDescription
TRUEevaluated 43 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 161 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
pi.currentComm...ring("ALLO "))Description
TRUEevaluated 43 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEnever evaluated
0-161
2358 return;
executed 43 times by 2 tests: return;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
43
2359 }-
2360-
2361 error = QFtp::Error(errorCode);-
2362 switch (q->currentCommand()) {-
2363 case QFtp::ConnectToHost:
executed 20 times by 2 tests: case QFtp::ConnectToHost:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
20
2364 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Connecting to host failed:\n%1"))-
2365 .arg(text);-
2366 break;
executed 20 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
20
2367 case QFtp::Login:
executed 23 times by 2 tests: case QFtp::Login:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
23
2368 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Login failed:\n%1"))-
2369 .arg(text);-
2370 break;
executed 23 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
23
2371 case QFtp::List:
never executed: case QFtp::List:
0
2372 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Listing directory failed:\n%1"))-
2373 .arg(text);-
2374 break;
never executed: break;
0
2375 case QFtp::Cd:
executed 48 times by 1 test: case QFtp::Cd:
Executed by:
  • tst_QFtp
48
2376 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Changing directory failed:\n%1"))-
2377 .arg(text);-
2378 break;
executed 48 times by 1 test: break;
Executed by:
  • tst_QFtp
48
2379 case QFtp::Get:
executed 17 times by 2 tests: case QFtp::Get:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
17
2380 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Downloading file failed:\n%1"))-
2381 .arg(text);-
2382 break;
executed 17 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
17
2383 case QFtp::Put:
never executed: case QFtp::Put:
0
2384 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Uploading file failed:\n%1"))-
2385 .arg(text);-
2386 break;
never executed: break;
0
2387 case QFtp::Remove:
never executed: case QFtp::Remove:
0
2388 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Removing file failed:\n%1"))-
2389 .arg(text);-
2390 break;
never executed: break;
0
2391 case QFtp::Mkdir:
executed 32 times by 1 test: case QFtp::Mkdir:
Executed by:
  • tst_QFtp
32
2392 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Creating directory failed:\n%1"))-
2393 .arg(text);-
2394 break;
executed 32 times by 1 test: break;
Executed by:
  • tst_QFtp
32
2395 case QFtp::Rmdir:
never executed: case QFtp::Rmdir:
0
2396 errorString = QString::fromLatin1(QT_TRANSLATE_NOOP("QFtp", "Removing directory failed:\n%1"))-
2397 .arg(text);-
2398 break;
never executed: break;
0
2399 default:
executed 21 times by 2 tests: default:
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
21
2400 errorString = text;-
2401 break;
executed 21 times by 2 tests: break;
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
21
2402 }-
2403-
2404 pi.clearPendingCommands();-
2405 q->clearPendingCommands();-
2406 emit q->commandFinished(c->id, true);-
2407-
2408 pending.removeFirst();-
2409 delete c;-
2410 if (pending.isEmpty())
pending.isEmpty()Description
TRUEevaluated 157 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFtp
4-157
2411 emit q->done(true);
executed 157 times by 2 tests: q->done(true);
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
157
2412 else-
2413 _q_startNextCommand();
executed 4 times by 1 test: _q_startNextCommand();
Executed by:
  • tst_QFtp
4
2414}-
2415-
2416/*! \internal-
2417*/-
2418void QFtpPrivate::_q_piConnectState(int connectState)-
2419{-
2420 state = QFtp::State(connectState);-
2421 emit q_func()->stateChanged(state);-
2422 if (close_waitForStateChange) {
close_waitForStateChangeDescription
TRUEevaluated 469 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
FALSEevaluated 2278 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
469-2278
2423 close_waitForStateChange = false;-
2424 _q_piFinished(QLatin1String(QT_TRANSLATE_NOOP("QFtp", "Connection closed")));-
2425 }
executed 469 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
469
2426}
executed 2747 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
2747
2427-
2428/*! \internal-
2429*/-
2430void QFtpPrivate::_q_piFtpReply(int code, const QString &text)-
2431{-
2432 if (q_func()->currentCommand() == QFtp::RawCommand) {
q_func()->curr...tp::RawCommandDescription
TRUEevaluated 132 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 4304 times by 2 tests
Evaluated by:
  • tst_QFtp
  • tst_QNetworkReply
132-4304
2433 pi.rawCommand = true;-
2434 emit q_func()->rawCommandReply(code, text);-
2435 }
executed 132 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
132
2436}
executed 4436 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
4436
2437-
2438/*!-
2439 \internal-
2440 Destructor.-
2441*/-
2442QFtp::~QFtp()-
2443{-
2444 abort();
executed 659 times by 2 tests: abort();
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
659
2445 close();-
2446}
executed 659 times by 2 tests: end of block
Executed by:
  • tst_QFtp
  • tst_QNetworkReply
659
2447-
2448QT_END_NAMESPACE-
2449-
2450#include "qftp.moc"-
2451-
2452#include "moc_qftp_p.cpp"-
2453-
2454#endif // QT_NO_FTP-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9