Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessftpbackend.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qnetworkaccessftpbackend_p.h" | - | ||||||||||||||||||
35 | #include "qnetworkaccessmanager_p.h" | - | ||||||||||||||||||
36 | #include "QtNetwork/qauthenticator.h" | - | ||||||||||||||||||
37 | #include "private/qnoncontiguousbytedevice_p.h" | - | ||||||||||||||||||
38 | #include <QStringList> | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #ifndef QT_NO_FTP | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | enum { | - | ||||||||||||||||||
45 | DefaultFtpPort = 21 | - | ||||||||||||||||||
46 | }; | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | static QByteArray makeCacheKey(const QUrl &url) | - | ||||||||||||||||||
49 | { | - | ||||||||||||||||||
50 | QUrl copy = url; | - | ||||||||||||||||||
51 | copy.setPort(url.port(DefaultFtpPort)); | - | ||||||||||||||||||
52 | return "ftp-connection:" + executed 98 times by 1 test: return "ftp-connection:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment); Executed by:
| 98 | ||||||||||||||||||
53 | copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery | executed 98 times by 1 test: return "ftp-connection:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment); Executed by:
| 98 | ||||||||||||||||||
54 | QUrl::RemoveFragment); executed 98 times by 1 test: return "ftp-connection:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment); Executed by:
| 98 | ||||||||||||||||||
55 | } | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | QStringList QNetworkAccessFtpBackendFactory::supportedSchemes() const | - | ||||||||||||||||||
58 | { | - | ||||||||||||||||||
59 | return QStringList(QStringLiteral("ftp")); never executed: return QStringList(([]() -> QString { enum { Size = sizeof(u"" "ftp")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ftp" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
60 | } | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | QNetworkAccessBackend * | - | ||||||||||||||||||
63 | QNetworkAccessFtpBackendFactory::create(QNetworkAccessManager::Operation op, | - | ||||||||||||||||||
64 | const QNetworkRequest &request) const | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | // is it an operation we know of? | - | ||||||||||||||||||
67 | switch (op) { | - | ||||||||||||||||||
68 | case QNetworkAccessManager::GetOperation: executed 49 times by 1 test: case QNetworkAccessManager::GetOperation: Executed by:
| 49 | ||||||||||||||||||
69 | case QNetworkAccessManager::PutOperation: executed 59 times by 1 test: case QNetworkAccessManager::PutOperation: Executed by:
| 59 | ||||||||||||||||||
70 | break; executed 108 times by 1 test: break; Executed by:
| 108 | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | default: never executed: default: | 0 | ||||||||||||||||||
73 | // no, we can't handle this operation | - | ||||||||||||||||||
74 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
75 | } | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | QUrl url = request.url(); | - | ||||||||||||||||||
78 | if (url.scheme().compare(QLatin1String("ftp"), Qt::CaseInsensitive) == 0)
| 54 | ||||||||||||||||||
79 | return new QNetworkAccessFtpBackend; executed 54 times by 1 test: return new QNetworkAccessFtpBackend; Executed by:
| 54 | ||||||||||||||||||
80 | return 0; executed 54 times by 1 test: return 0; Executed by:
| 54 | ||||||||||||||||||
81 | } | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject | - | ||||||||||||||||||
84 | { | - | ||||||||||||||||||
85 | // Q_OBJECT | - | ||||||||||||||||||
86 | public: | - | ||||||||||||||||||
87 | QNetworkAccessCachedFtpConnection() | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | setExpires(true); | - | ||||||||||||||||||
90 | setShareable(false); | - | ||||||||||||||||||
91 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | void dispose() Q_DECL_OVERRIDE | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | connect(this, SIGNAL(done(bool)), this, SLOT(deleteLater())); | - | ||||||||||||||||||
96 | close(); | - | ||||||||||||||||||
97 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||
98 | }; | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | QNetworkAccessFtpBackend::QNetworkAccessFtpBackend() | - | ||||||||||||||||||
101 | : ftp(0), uploadDevice(0), totalBytes(0), helpId(-1), sizeId(-1), mdtmId(-1), | - | ||||||||||||||||||
102 | supportsSize(false), supportsMdtm(false), state(Idle) | - | ||||||||||||||||||
103 | { | - | ||||||||||||||||||
104 | } executed 54 times by 1 test: end of block Executed by:
| 54 | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | QNetworkAccessFtpBackend::~QNetworkAccessFtpBackend() | - | ||||||||||||||||||
107 | { | - | ||||||||||||||||||
108 | //if backend destroyed while in use, then abort (this is the code path from QNetworkReply::abort) | - | ||||||||||||||||||
109 | if (ftp && state != Disconnecting)
| 1 | ||||||||||||||||||
110 | ftp->abort(); executed 1 time by 1 test: ftp->abort(); Executed by:
| 1 | ||||||||||||||||||
111 | disconnectFromFtp(); | - | ||||||||||||||||||
112 | } executed 54 times by 1 test: end of block Executed by:
| 54 | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | void QNetworkAccessFtpBackend::open() | - | ||||||||||||||||||
115 | { | - | ||||||||||||||||||
116 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
117 | QNetworkProxy proxy; | - | ||||||||||||||||||
118 | foreach (const QNetworkProxy &p, proxyList()) { | - | ||||||||||||||||||
119 | // use the first FTP proxy | - | ||||||||||||||||||
120 | // or no proxy at all | - | ||||||||||||||||||
121 | if (p.type() == QNetworkProxy::FtpCachingProxy
| 2-53 | ||||||||||||||||||
122 | || p.type() == QNetworkProxy::NoProxy) {
| 5-48 | ||||||||||||||||||
123 | proxy = p; | - | ||||||||||||||||||
124 | break; executed 50 times by 1 test: break; Executed by:
| 50 | ||||||||||||||||||
125 | } | - | ||||||||||||||||||
126 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | // did we find an FTP proxy or a NoProxy? | - | ||||||||||||||||||
129 | if (proxy.type() == QNetworkProxy::DefaultProxy) {
| 3-50 | ||||||||||||||||||
130 | // unsuitable proxies | - | ||||||||||||||||||
131 | error(QNetworkReply::ProxyNotFoundError, | - | ||||||||||||||||||
132 | tr("No suitable proxy found")); | - | ||||||||||||||||||
133 | finished(); | - | ||||||||||||||||||
134 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||||||||
135 | } | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | #endif | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | QUrl url = this->url(); | - | ||||||||||||||||||
140 | if (url.path().isEmpty()) {
| 1-49 | ||||||||||||||||||
141 | url.setPath(QLatin1String("/")); | - | ||||||||||||||||||
142 | setUrl(url); | - | ||||||||||||||||||
143 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
144 | if (url.path().endsWith(QLatin1Char('/'))) {
| 1-49 | ||||||||||||||||||
145 | error(QNetworkReply::ContentOperationNotPermittedError, | - | ||||||||||||||||||
146 | tr("Cannot open %1: is a directory").arg(url.toString())); | - | ||||||||||||||||||
147 | finished(); | - | ||||||||||||||||||
148 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
149 | } | - | ||||||||||||||||||
150 | state = LoggingIn; | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | QNetworkAccessCache* objectCache = QNetworkAccessManagerPrivate::getObjectCache(this); | - | ||||||||||||||||||
153 | QByteArray cacheKey = makeCacheKey(url); | - | ||||||||||||||||||
154 | if (!objectCache->requestEntry(cacheKey, this,
| 1-48 | ||||||||||||||||||
155 | SLOT(ftpConnectionReady(QNetworkAccessCache::CacheableObject*)))) {
| 1-48 | ||||||||||||||||||
156 | ftp = new QNetworkAccessCachedFtpConnection; | - | ||||||||||||||||||
157 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
158 | //copy network session down to the QFtp | - | ||||||||||||||||||
159 | ftp->setProperty("_q_networksession", property("_q_networksession")); | - | ||||||||||||||||||
160 | #endif | - | ||||||||||||||||||
161 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
162 | if (proxy.type() == QNetworkProxy::FtpCachingProxy)
| 2-46 | ||||||||||||||||||
163 | ftp->setProxy(proxy.hostName(), proxy.port()); executed 2 times by 1 test: ftp->setProxy(proxy.hostName(), proxy.port()); Executed by:
| 2 | ||||||||||||||||||
164 | #endif | - | ||||||||||||||||||
165 | ftp->connectToHost(url.host(), url.port(DefaultFtpPort)); | - | ||||||||||||||||||
166 | ftp->login(url.userName(), url.password()); | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | objectCache->addEntry(cacheKey, ftp); | - | ||||||||||||||||||
169 | ftpConnectionReady(ftp); | - | ||||||||||||||||||
170 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | // Put operation | - | ||||||||||||||||||
173 | if (operation() == QNetworkAccessManager::PutOperation) {
| 13-36 | ||||||||||||||||||
174 | uploadDevice = QNonContiguousByteDeviceFactory::wrap(createUploadByteDevice()); | - | ||||||||||||||||||
175 | uploadDevice->setParent(this); | - | ||||||||||||||||||
176 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
177 | } executed 49 times by 1 test: end of block Executed by:
| 49 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | void QNetworkAccessFtpBackend::closeDownstreamChannel() | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | state = Disconnecting; | - | ||||||||||||||||||
182 | if (operation() == QNetworkAccessManager::GetOperation)
| 0-1 | ||||||||||||||||||
183 | ftp->abort(); executed 1 time by 1 test: ftp->abort(); Executed by:
| 1 | ||||||||||||||||||
184 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | void QNetworkAccessFtpBackend::downstreamReadyWrite() | - | ||||||||||||||||||
187 | { | - | ||||||||||||||||||
188 | if (state == Transferring && ftp && ftp->bytesAvailable())
| 0-562 | ||||||||||||||||||
189 | ftpReadyRead(); never executed: ftpReadyRead(); | 0 | ||||||||||||||||||
190 | } executed 600 times by 1 test: end of block Executed by:
| 600 | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | void QNetworkAccessFtpBackend::ftpConnectionReady(QNetworkAccessCache::CacheableObject *o) | - | ||||||||||||||||||
193 | { | - | ||||||||||||||||||
194 | ftp = static_cast<QNetworkAccessCachedFtpConnection *>(o); | - | ||||||||||||||||||
195 | connect(ftp, SIGNAL(done(bool)), SLOT(ftpDone())); | - | ||||||||||||||||||
196 | connect(ftp, SIGNAL(rawCommandReply(int,QString)), SLOT(ftpRawCommandReply(int,QString))); | - | ||||||||||||||||||
197 | connect(ftp, SIGNAL(readyRead()), SLOT(ftpReadyRead())); | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | // is the login process done already? | - | ||||||||||||||||||
200 | if (ftp->state() == QFtp::LoggedIn)
| 1-48 | ||||||||||||||||||
201 | ftpDone(); executed 1 time by 1 test: ftpDone(); Executed by:
| 1 | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | // no, defer the actual operation until after we've logged in | - | ||||||||||||||||||
204 | } executed 49 times by 1 test: end of block Executed by:
| 49 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | void QNetworkAccessFtpBackend::disconnectFromFtp(CacheCleanupMode mode) | - | ||||||||||||||||||
207 | { | - | ||||||||||||||||||
208 | state = Disconnecting; | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | if (ftp) {
| 49-52 | ||||||||||||||||||
211 | disconnect(ftp, 0, this, 0); | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | QByteArray key = makeCacheKey(url()); | - | ||||||||||||||||||
214 | if (mode == RemoveCachedConnection) {
| 9-40 | ||||||||||||||||||
215 | QNetworkAccessManagerPrivate::getObjectCache(this)->removeEntry(key); | - | ||||||||||||||||||
216 | ftp->dispose(); | - | ||||||||||||||||||
217 | } else { executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
218 | QNetworkAccessManagerPrivate::getObjectCache(this)->releaseEntry(key); | - | ||||||||||||||||||
219 | } executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | ftp = 0; | - | ||||||||||||||||||
222 | } executed 49 times by 1 test: end of block Executed by:
| 49 | ||||||||||||||||||
223 | } executed 101 times by 1 test: end of block Executed by:
| 101 | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | void QNetworkAccessFtpBackend::ftpDone() | - | ||||||||||||||||||
226 | { | - | ||||||||||||||||||
227 | // the last command we sent is done | - | ||||||||||||||||||
228 | if (state == LoggingIn && ftp->state() != QFtp::LoggedIn) {
| 4-129 | ||||||||||||||||||
229 | if (ftp->state() == QFtp::Connected) {
| 1-3 | ||||||||||||||||||
230 | // the login did not succeed | - | ||||||||||||||||||
231 | QUrl newUrl = url(); | - | ||||||||||||||||||
232 | QString userInfo = newUrl.userInfo(); | - | ||||||||||||||||||
233 | newUrl.setUserInfo(QString()); | - | ||||||||||||||||||
234 | setUrl(newUrl); | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | QAuthenticator auth; | - | ||||||||||||||||||
237 | authenticationRequired(&auth); | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | if (!auth.isNull()) {
| 0-3 | ||||||||||||||||||
240 | // try again: | - | ||||||||||||||||||
241 | newUrl.setUserName(auth.user()); | - | ||||||||||||||||||
242 | ftp->login(auth.user(), auth.password()); | - | ||||||||||||||||||
243 | return; never executed: return; | 0 | ||||||||||||||||||
244 | } | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | // Re insert the user info so that we can remove the cache entry. | - | ||||||||||||||||||
247 | newUrl.setUserInfo(userInfo); | - | ||||||||||||||||||
248 | setUrl(newUrl); | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | error(QNetworkReply::AuthenticationRequiredError, | - | ||||||||||||||||||
251 | tr("Logging in to %1 failed: authentication required") | - | ||||||||||||||||||
252 | .arg(url().host())); | - | ||||||||||||||||||
253 | } else { executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
254 | // we did not connect | - | ||||||||||||||||||
255 | QNetworkReply::NetworkError code; | - | ||||||||||||||||||
256 | switch (ftp->error()) { | - | ||||||||||||||||||
257 | case QFtp::HostNotFound: executed 1 time by 1 test: case QFtp::HostNotFound: Executed by:
| 1 | ||||||||||||||||||
258 | code = QNetworkReply::HostNotFoundError; | - | ||||||||||||||||||
259 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | case QFtp::ConnectionRefused: never executed: case QFtp::ConnectionRefused: | 0 | ||||||||||||||||||
262 | code = QNetworkReply::ConnectionRefusedError; | - | ||||||||||||||||||
263 | break; never executed: break; | 0 | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | default: never executed: default: | 0 | ||||||||||||||||||
266 | code = QNetworkReply::ProtocolFailure; | - | ||||||||||||||||||
267 | break; never executed: break; | 0 | ||||||||||||||||||
268 | } | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | error(code, ftp->errorString()); | - | ||||||||||||||||||
271 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | // we're not connected, so remove the cache entry: | - | ||||||||||||||||||
274 | disconnectFromFtp(RemoveCachedConnection); | - | ||||||||||||||||||
275 | finished(); | - | ||||||||||||||||||
276 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
277 | } | - | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | // check for errors: | - | ||||||||||||||||||
280 | if (ftp->error() != QFtp::NoError) {
| 5-169 | ||||||||||||||||||
281 | QString msg; | - | ||||||||||||||||||
282 | if (operation() == QNetworkAccessManager::GetOperation)
| 0-5 | ||||||||||||||||||
283 | msg = tr("Error while downloading %1: %2"); executed 5 times by 1 test: msg = tr("Error while downloading %1: %2"); Executed by:
| 5 | ||||||||||||||||||
284 | else | - | ||||||||||||||||||
285 | msg = tr("Error while uploading %1: %2"); never executed: msg = tr("Error while uploading %1: %2"); | 0 | ||||||||||||||||||
286 | msg = msg.arg(url().toString(), ftp->errorString()); | - | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | if (state == Statting)
| 1-4 | ||||||||||||||||||
289 | // file probably doesn't exist | - | ||||||||||||||||||
290 | error(QNetworkReply::ContentNotFoundError, msg); executed 4 times by 1 test: error(QNetworkReply::ContentNotFoundError, msg); Executed by:
| 4 | ||||||||||||||||||
291 | else | - | ||||||||||||||||||
292 | error(QNetworkReply::ContentAccessDenied, msg); executed 1 time by 1 test: error(QNetworkReply::ContentAccessDenied, msg); Executed by:
| 1 | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | disconnectFromFtp(RemoveCachedConnection); | - | ||||||||||||||||||
295 | finished(); | - | ||||||||||||||||||
296 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | if (state == LoggingIn) {
| 45-129 | ||||||||||||||||||
299 | state = CheckingFeatures; | - | ||||||||||||||||||
300 | if (operation() == QNetworkAccessManager::GetOperation) {
| 11-34 | ||||||||||||||||||
301 | // send help command to find out if server supports "SIZE" and "MDTM" | - | ||||||||||||||||||
302 | QString command = url().path(); | - | ||||||||||||||||||
303 | command.prepend(QLatin1String("%1 ")); | - | ||||||||||||||||||
304 | helpId = ftp->rawCommand(QLatin1String("HELP")); // get supported commands | - | ||||||||||||||||||
305 | } else { executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
306 | ftpDone(); | - | ||||||||||||||||||
307 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||
308 | } else if (state == CheckingFeatures) {
| 45-84 | ||||||||||||||||||
309 | state = Statting; | - | ||||||||||||||||||
310 | if (operation() == QNetworkAccessManager::GetOperation) {
| 11-34 | ||||||||||||||||||
311 | // logged in successfully, send the stat requests (if supported) | - | ||||||||||||||||||
312 | QString command = url().path(); | - | ||||||||||||||||||
313 | command.prepend(QLatin1String("%1 ")); | - | ||||||||||||||||||
314 | if (supportsSize) {
| 0-34 | ||||||||||||||||||
315 | ftp->rawCommand(QLatin1String("TYPE I")); | - | ||||||||||||||||||
316 | sizeId = ftp->rawCommand(command.arg(QLatin1String("SIZE"))); // get size | - | ||||||||||||||||||
317 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
318 | if (supportsMdtm)
| 0-34 | ||||||||||||||||||
319 | mdtmId = ftp->rawCommand(command.arg(QLatin1String("MDTM"))); // get modified time executed 34 times by 1 test: mdtmId = ftp->rawCommand(command.arg(QLatin1String("MDTM"))); Executed by:
| 34 | ||||||||||||||||||
320 | if (!supportsSize && !supportsMdtm)
| 0-34 | ||||||||||||||||||
321 | ftpDone(); // no commands sent, move to the next state never executed: ftpDone(); | 0 | ||||||||||||||||||
322 | } else { executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
323 | ftpDone(); | - | ||||||||||||||||||
324 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||
325 | } else if (state == Statting) {
| 41-43 | ||||||||||||||||||
326 | // statted successfully, send the actual request | - | ||||||||||||||||||
327 | emit metaDataChanged(); | - | ||||||||||||||||||
328 | state = Transferring; | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | QFtp::TransferType type = QFtp::Binary; | - | ||||||||||||||||||
331 | if (operation() == QNetworkAccessManager::GetOperation) {
| 11-30 | ||||||||||||||||||
332 | setCachingEnabled(true); | - | ||||||||||||||||||
333 | ftp->get(url().path(), 0, type); | - | ||||||||||||||||||
334 | } else { executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||
335 | ftp->put(uploadDevice, url().path(), type); | - | ||||||||||||||||||
336 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | } else if (state == Transferring) {
| 5-38 | ||||||||||||||||||
339 | // upload or download finished | - | ||||||||||||||||||
340 | disconnectFromFtp(); | - | ||||||||||||||||||
341 | finished(); | - | ||||||||||||||||||
342 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||||||||||||||
343 | } executed 174 times by 1 test: end of block Executed by:
| 174 | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | void QNetworkAccessFtpBackend::ftpReadyRead() | - | ||||||||||||||||||
346 | { | - | ||||||||||||||||||
347 | QByteArray data = ftp->readAll(); | - | ||||||||||||||||||
348 | QByteDataBuffer list; | - | ||||||||||||||||||
349 | list.append(data); | - | ||||||||||||||||||
350 | data.clear(); // important because of implicit sharing! | - | ||||||||||||||||||
351 | writeDownstreamData(list); | - | ||||||||||||||||||
352 | } executed 568 times by 1 test: end of block Executed by:
| 568 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | void QNetworkAccessFtpBackend::ftpRawCommandReply(int code, const QString &text) | - | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | //qDebug() << "FTP reply:" << code << text; | - | ||||||||||||||||||
357 | int id = ftp->currentId(); | - | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | if ((id == helpId) && ((code == 200) || (code == 214))) { // supported commands
| 0-98 | ||||||||||||||||||
360 | // the "FEAT" ftp command would be nice here, but it is not part of the | - | ||||||||||||||||||
361 | // initial FTP RFC 959, neither ar "SIZE" nor "MDTM" (they are all specified | - | ||||||||||||||||||
362 | // in RFC 3659) | - | ||||||||||||||||||
363 | if (text.contains(QLatin1String("SIZE"), Qt::CaseSensitive))
| 0-34 | ||||||||||||||||||
364 | supportsSize = true; executed 34 times by 1 test: supportsSize = true; Executed by:
| 34 | ||||||||||||||||||
365 | if (text.contains(QLatin1String("MDTM"), Qt::CaseSensitive))
| 0-34 | ||||||||||||||||||
366 | supportsMdtm = true; executed 34 times by 1 test: supportsMdtm = true; Executed by:
| 34 | ||||||||||||||||||
367 | } else if (code == 213) { // file status executed 34 times by 1 test: end of block Executed by:
| 34-60 | ||||||||||||||||||
368 | if (id == sizeId) {
| 30 | ||||||||||||||||||
369 | // reply to the size command | - | ||||||||||||||||||
370 | setHeader(QNetworkRequest::ContentLengthHeader, text.toLongLong()); | - | ||||||||||||||||||
371 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||
372 | } else if (id == mdtmId) { executed 30 times by 1 test: end of block Executed by:
| 0-30 | ||||||||||||||||||
373 | QDateTime dt = QDateTime::fromString(text, QLatin1String("yyyyMMddHHmmss")); | - | ||||||||||||||||||
374 | setHeader(QNetworkRequest::LastModifiedHeader, dt); | - | ||||||||||||||||||
375 | #endif | - | ||||||||||||||||||
376 | } executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||
377 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
378 | } executed 132 times by 1 test: end of block Executed by:
| 132 | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | QT_END_NAMESPACE | - | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | #endif // QT_NO_FTP | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |