diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2009-06-17 15:01:45 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2009-06-17 15:17:49 (GMT) |
commit | 652b2ca3379715f757776654b406c1ac08573f22 (patch) | |
tree | 3be7c3c6be00992d60a7aa448e643f20914392db /src/network | |
parent | 38ef45edb1955b07c537be37bc4283749d8f28b2 (diff) | |
download | Qt-652b2ca3379715f757776654b406c1ac08573f22.zip Qt-652b2ca3379715f757776654b406c1ac08573f22.tar.gz Qt-652b2ca3379715f757776654b406c1ac08573f22.tar.bz2 |
QNAM: More comments, some renamings
Renamed some classes and member variables.
Their names were causing confusion before because.
Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qnetworkaccesscache_p.h | 3 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessftpbackend.cpp | 18 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessftpbackend_p.h | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend.cpp | 19 | ||||
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend_p.h | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 24 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager_p.h | 12 |
7 files changed, 50 insertions, 34 deletions
diff --git a/src/network/access/qnetworkaccesscache_p.h b/src/network/access/qnetworkaccesscache_p.h index 3fdfbb4..439b3a0 100644 --- a/src/network/access/qnetworkaccesscache_p.h +++ b/src/network/access/qnetworkaccesscache_p.h @@ -64,6 +64,9 @@ QT_BEGIN_NAMESPACE class QNetworkRequest; class QUrl; +// this class is not about caching files but about +// caching objects used by QNetworkAccessManager, e.g. existing TCP connections +// or credentials. class QNetworkAccessCache: public QObject { Q_OBJECT diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp index 9be433d..d6276a3 100644 --- a/src/network/access/qnetworkaccessftpbackend.cpp +++ b/src/network/access/qnetworkaccessftpbackend.cpp @@ -82,11 +82,11 @@ QNetworkAccessFtpBackendFactory::create(QNetworkAccessManager::Operation op, return 0; } -class QNetworkAccessFtpFtp: public QFtp, public QNetworkAccessCache::CacheableObject +class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject { // Q_OBJECT public: - QNetworkAccessFtpFtp() + QNetworkAccessCachedFtpConnection() { setExpires(true); setShareable(false); @@ -148,11 +148,11 @@ void QNetworkAccessFtpBackend::open() } state = LoggingIn; - QNetworkAccessCache* cache = QNetworkAccessManagerPrivate::getCache(this); + QNetworkAccessCache* objectCache = QNetworkAccessManagerPrivate::getObjectCache(this); QByteArray cacheKey = makeCacheKey(url); - if (!cache->requestEntry(cacheKey, this, + if (!objectCache->requestEntry(cacheKey, this, SLOT(ftpConnectionReady(QNetworkAccessCache::CacheableObject*)))) { - ftp = new QNetworkAccessFtpFtp; + ftp = new QNetworkAccessCachedFtpConnection; #ifndef QT_NO_NETWORKPROXY if (proxy.type() == QNetworkProxy::FtpCachingProxy) ftp->setProxy(proxy.hostName(), proxy.port()); @@ -160,7 +160,7 @@ void QNetworkAccessFtpBackend::open() ftp->connectToHost(url.host(), url.port(DefaultFtpPort)); ftp->login(url.userName(), url.password()); - cache->addEntry(cacheKey, ftp); + objectCache->addEntry(cacheKey, ftp); ftpConnectionReady(ftp); } @@ -207,7 +207,7 @@ void QNetworkAccessFtpBackend::downstreamReadyWrite() void QNetworkAccessFtpBackend::ftpConnectionReady(QNetworkAccessCache::CacheableObject *o) { - ftp = static_cast<QNetworkAccessFtpFtp *>(o); + ftp = static_cast<QNetworkAccessCachedFtpConnection *>(o); connect(ftp, SIGNAL(done(bool)), SLOT(ftpDone())); connect(ftp, SIGNAL(rawCommandReply(int,QString)), SLOT(ftpRawCommandReply(int,QString))); connect(ftp, SIGNAL(readyRead()), SLOT(ftpReadyRead())); @@ -227,7 +227,7 @@ void QNetworkAccessFtpBackend::disconnectFromFtp() disconnect(ftp, 0, this, 0); QByteArray key = makeCacheKey(url()); - QNetworkAccessManagerPrivate::getCache(this)->releaseEntry(key); + QNetworkAccessManagerPrivate::getObjectCache(this)->releaseEntry(key); ftp = 0; } @@ -278,7 +278,7 @@ void QNetworkAccessFtpBackend::ftpDone() // we're not connected, so remove the cache entry: QByteArray key = makeCacheKey(url()); - QNetworkAccessManagerPrivate::getCache(this)->removeEntry(key); + QNetworkAccessManagerPrivate::getObjectCache(this)->removeEntry(key); disconnect(ftp, 0, this, 0); ftp->dispose(); diff --git a/src/network/access/qnetworkaccessftpbackend_p.h b/src/network/access/qnetworkaccessftpbackend_p.h index 9626403..bb6d766 100644 --- a/src/network/access/qnetworkaccessftpbackend_p.h +++ b/src/network/access/qnetworkaccessftpbackend_p.h @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE class QNetworkAccessFtpIODevice; -class QNetworkAccessFtpFtp; +class QNetworkAccessCachedFtpConnection; class QNetworkAccessFtpBackend: public QNetworkAccessBackend { @@ -101,7 +101,7 @@ public slots: private: friend class QNetworkAccessFtpIODevice; - QPointer<QNetworkAccessFtpFtp> ftp; + QPointer<QNetworkAccessCachedFtpConnection> ftp; QIODevice *uploadDevice; qint64 totalBytes; int helpId, sizeId, mdtmId; diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 8a6f27a..71808d4 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -270,12 +270,12 @@ static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const return code; } -class QNetworkAccessHttpBackendCache: public QHttpNetworkConnection, +class QNetworkAccessCachedHttpConnection: public QHttpNetworkConnection, public QNetworkAccessCache::CacheableObject { // Q_OBJECT public: - QNetworkAccessHttpBackendCache(const QString &hostName, quint16 port, bool encrypt) + QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt) : QHttpNetworkConnection(hostName, port, encrypt) { setExpires(true); @@ -311,8 +311,11 @@ QNetworkAccessHttpBackend::~QNetworkAccessHttpBackend() void QNetworkAccessHttpBackend::disconnectFromHttp() { if (http) { + // This is abut disconnecting signals, not about disconnecting TCP connections disconnect(http, 0, this, 0); - QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this); + + // Get the object cache that stores our QHttpNetworkConnection objects + QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getObjectCache(this); cache->releaseEntry(cacheKey); } @@ -583,16 +586,20 @@ void QNetworkAccessHttpBackend::open() // check if we have an open connection to this host cacheKey = makeCacheKey(this, theProxy); - QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this); - if ((http = static_cast<QNetworkAccessHttpBackendCache *>(cache->requestEntryNow(cacheKey))) == 0) { + QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getObjectCache(this); + // the http object is actually a QHttpNetworkConnection + http = static_cast<QNetworkAccessCachedHttpConnection *>(cache->requestEntryNow(cacheKey)); + if (http == 0) { // no entry in cache; create an object - http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt); + // the http object is actually a QHttpNetworkConnection + http = new QNetworkAccessCachedHttpConnection(url.host(), url.port(), encrypt); #ifndef QT_NO_NETWORKPROXY http->setTransparentProxy(transparentProxy); http->setCacheProxy(cacheProxy); #endif + // cache the QHttpNetworkConnection corresponding to this cache key cache->addEntry(cacheKey, http); } diff --git a/src/network/access/qnetworkaccesshttpbackend_p.h b/src/network/access/qnetworkaccesshttpbackend_p.h index e0801ce..dec69d0 100644 --- a/src/network/access/qnetworkaccesshttpbackend_p.h +++ b/src/network/access/qnetworkaccesshttpbackend_p.h @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE -class QNetworkAccessHttpBackendCache; +class QNetworkAccessCachedHttpConnection; class QNetworkAccessHttpBackendIODevice; @@ -106,7 +106,7 @@ private slots: private: QHttpNetworkReply *httpReply; - QPointer<QNetworkAccessHttpBackendCache> http; + QPointer<QNetworkAccessCachedHttpConnection> http; QByteArray cacheKey; QNetworkAccessBackendUploadIODevice *uploadDevice; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 0ae920b..ed2f220 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -836,7 +836,7 @@ void QNetworkAccessManagerPrivate::addCredentials(const QNetworkProxy &p, QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; auth->insert(QString(), authenticator->user(), authenticator->password()); - cache.addEntry(cacheKey, auth); // replace the existing one, if there's any + objectCache.addEntry(cacheKey, auth); // replace the existing one, if there's any if (realm.isEmpty()) { break; @@ -870,13 +870,13 @@ QNetworkAccessManagerPrivate::fetchCachedCredentials(const QNetworkProxy &p, QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); if (cacheKey.isEmpty()) return 0; - if (!cache.hasEntry(cacheKey)) + if (!objectCache.hasEntry(cacheKey)) return 0; QNetworkAuthenticationCache *auth = - static_cast<QNetworkAuthenticationCache *>(cache.requestEntryNow(cacheKey)); + static_cast<QNetworkAuthenticationCache *>(objectCache.requestEntryNow(cacheKey)); QNetworkAuthenticationCredential *cred = auth->findClosestMatch(QString()); - cache.releaseEntry(cacheKey); + objectCache.releaseEntry(cacheKey); // proxy cache credentials always have exactly one item Q_ASSERT_X(cred, "QNetworkAccessManager", @@ -917,15 +917,15 @@ void QNetworkAccessManagerPrivate::addCredentials(const QUrl &url, copy.setUserName(authenticator->user()); do { QByteArray cacheKey = authenticationKey(copy, realm); - if (cache.hasEntry(cacheKey)) { + if (objectCache.hasEntry(cacheKey)) { QNetworkAuthenticationCache *auth = - static_cast<QNetworkAuthenticationCache *>(cache.requestEntryNow(cacheKey)); + static_cast<QNetworkAuthenticationCache *>(objectCache.requestEntryNow(cacheKey)); auth->insert(domain, authenticator->user(), authenticator->password()); - cache.releaseEntry(cacheKey); + objectCache.releaseEntry(cacheKey); } else { QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; auth->insert(domain, authenticator->user(), authenticator->password()); - cache.addEntry(cacheKey, auth); + objectCache.addEntry(cacheKey, auth); } if (copy.userName().isEmpty()) { @@ -959,19 +959,19 @@ QNetworkAccessManagerPrivate::fetchCachedCredentials(const QUrl &url, realm = authentication->realm(); QByteArray cacheKey = authenticationKey(url, realm); - if (!cache.hasEntry(cacheKey)) + if (!objectCache.hasEntry(cacheKey)) return 0; QNetworkAuthenticationCache *auth = - static_cast<QNetworkAuthenticationCache *>(cache.requestEntryNow(cacheKey)); + static_cast<QNetworkAuthenticationCache *>(objectCache.requestEntryNow(cacheKey)); QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path()); - cache.releaseEntry(cacheKey); + objectCache.releaseEntry(cacheKey); return cred; } void QNetworkAccessManagerPrivate::clearCache(QNetworkAccessManager *manager) { - manager->d_func()->cache.clear(); + manager->d_func()->objectCache.clear(); } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index c80613b..bcf9a2b 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -98,10 +98,12 @@ public: QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request); + // this is the cache for storing downloaded files QAbstractNetworkCache *networkCache; + QNetworkCookieJar *cookieJar; - QNetworkAccessCache cache; + #ifndef QT_NO_NETWORKPROXY QNetworkProxy proxy; QNetworkProxyFactory *proxyFactory; @@ -109,8 +111,12 @@ public: bool cookieJarCreated; - static inline QNetworkAccessCache *getCache(QNetworkAccessBackend *backend) - { return &backend->manager->cache; } + + // this cache can be used by individual backends to cache e.g. their TCP connections to a server + // and use the connections for multiple requests. + QNetworkAccessCache objectCache; + static inline QNetworkAccessCache *getObjectCache(QNetworkAccessBackend *backend) + { return &backend->manager->objectCache; } Q_AUTOTEST_EXPORT static void clearCache(QNetworkAccessManager *manager); Q_DECLARE_PUBLIC(QNetworkAccessManager) |