Changeset 561 for trunk/src/network/access/qnetworkaccessftpbackend.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/network/access/qnetworkaccessftpbackend.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtNetwork module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 43 43 #include "qnetworkaccessmanager_p.h" 44 44 #include "QtNetwork/qauthenticator.h" 45 45 46 46 47 #ifndef QT_NO_FTP … … 82 83 } 83 84 84 class QNetworkAccessFtpIODevice: public QIODevice 85 { 86 //Q_OBJECT 87 public: 88 QNetworkAccessFtpBackend *backend; 89 bool eof; 90 91 inline QNetworkAccessFtpIODevice(QNetworkAccessFtpBackend *parent) 92 : QIODevice(parent), backend(parent), eof(false) 93 { open(ReadOnly); } 94 95 bool isSequential() const { return true; } 96 bool atEnd() const { return backend->upstreamBytesAvailable() == 0; } 97 98 qint64 bytesAvailable() const { return backend->upstreamBytesAvailable(); } 99 qint64 bytesToWrite() const { return backend->downstreamBytesToConsume(); } 100 protected: 101 qint64 readData(char *data, qint64 maxlen) 102 { 103 const QByteArray toSend = backend->readUpstream(); 104 maxlen = qMin<qint64>(maxlen, toSend.size()); 105 if (!maxlen) 106 return eof ? -1 : 0; 107 108 backend->upstreamBytesConsumed(maxlen); 109 memcpy(data, toSend.constData(), maxlen); 110 return maxlen; 111 } 112 113 qint64 writeData(const char *, qint64) 114 { return -1; } 115 116 friend class QNetworkAccessFtpBackend; 117 }; 118 119 class QNetworkAccessFtpFtp: public QFtp, public QNetworkAccessCache::CacheableObject 85 class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject 120 86 { 121 87 // Q_OBJECT 122 88 public: 123 QNetworkAccess FtpFtp()89 QNetworkAccess() 124 90 { 125 91 setExpires(true); … … 183 149 state = LoggingIn; 184 150 185 QNetworkAccessCache* cache = QNetworkAccessManagerPrivate::getCache(this);151 QNetworkAccessCache* tCache(this); 186 152 QByteArray cacheKey = makeCacheKey(url); 187 if (! cache->requestEntry(cacheKey, this,153 if (!ache->requestEntry(cacheKey, this, 188 154 SLOT(ftpConnectionReady(QNetworkAccessCache::CacheableObject*)))) { 189 ftp = new QNetworkAccess FtpFtp;155 ftp = new QNetworkAccess; 190 156 #ifndef QT_NO_NETWORKPROXY 191 157 if (proxy.type() == QNetworkProxy::FtpCachingProxy) … … 195 161 ftp->login(url.userName(), url.password()); 196 162 197 cache->addEntry(cacheKey, ftp);163 ache->addEntry(cacheKey, ftp); 198 164 ftpConnectionReady(ftp); 199 165 } 200 166 201 uploadDevice = new QNetworkAccessFtpIODevice(this); 167 // Put operation 168 if (operation() == QNetworkAccessManager::PutOperation) { 169 uploadDevice = QNonContiguousByteDeviceFactory::wrap(createUploadByteDevice()); 170 uploadDevice->setParent(this); 171 } 202 172 } 203 173 … … 213 183 } 214 184 215 void QNetworkAccessFtpBackend::closeUpstreamChannel()216 {217 if (operation() == QNetworkAccessManager::PutOperation) {218 Q_ASSERT(uploadDevice);219 uploadDevice->eof = true;220 if (!upstreamBytesAvailable())221 emit uploadDevice->readyRead();222 }223 }224 225 185 bool QNetworkAccessFtpBackend::waitForDownstreamReadyRead(int ms) 226 186 { … … 240 200 } 241 201 242 bool QNetworkAccessFtpBackend::waitForUpstreamBytesWritten(int ms)243 {244 Q_UNUSED(ms);245 qCritical("QNetworkAccess: FTP backend does not support waitForBytesWritten()");246 return false;247 }248 249 void QNetworkAccessFtpBackend::upstreamReadyRead()250 {251 // uh... how does QFtp operate?252 }253 254 202 void QNetworkAccessFtpBackend::downstreamReadyWrite() 255 203 { … … 260 208 void QNetworkAccessFtpBackend::ftpConnectionReady(QNetworkAccessCache::CacheableObject *o) 261 209 { 262 ftp = static_cast<QNetworkAccess FtpFtp*>(o);210 ftp = static_cast<QNetworkAccess *>(o); 263 211 connect(ftp, SIGNAL(done(bool)), SLOT(ftpDone())); 264 212 connect(ftp, SIGNAL(rawCommandReply(int,QString)), SLOT(ftpRawCommandReply(int,QString))); … … 280 228 281 229 QByteArray key = makeCacheKey(url()); 282 QNetworkAccessManagerPrivate::get Cache(this)->releaseEntry(key);230 QNetworkAccessManagerPrivate::getCache(this)->releaseEntry(key); 283 231 284 232 ftp = 0; … … 331 279 // we're not connected, so remove the cache entry: 332 280 QByteArray key = makeCacheKey(url()); 333 QNetworkAccessManagerPrivate::get Cache(this)->removeEntry(key);281 QNetworkAccessManagerPrivate::getCache(this)->removeEntry(key); 334 282 335 283 disconnect(ftp, 0, this, 0); … … 408 356 void QNetworkAccessFtpBackend::ftpReadyRead() 409 357 { 410 writeDownstreamData(ftp->readAll()); 358 QByteArray data = ftp->readAll(); 359 QByteDataBuffer list; 360 list.append(data); 361 data.clear(); // important because of implicit sharing! 362 writeDownstreamData(list); 411 363 } 412 364
Note:
See TracChangeset
for help on using the changeset viewer.