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