diff options
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection_p.h | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessbackend.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 44 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager_p.h | 3 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 12 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl_p.h | 3 | ||||
-rw-r--r-- | src/network/access/qnetworkreplynsurlconnectionimpl.mm | 13 |
8 files changed, 57 insertions, 28 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index accad6e4c0..7ff6bffed3 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -1219,8 +1219,8 @@ QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QS d->init(); } #else -QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent, - QHttpNetworkConnection::ConnectionType connectionType) +QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, + QHttpNetworkConnection::ConnectionType connectionType, QObject *parent) : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt , connectionType)), parent) { Q_D(QHttpNetworkConnection); diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 9d4257e217..42114ae9d6 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -110,8 +110,8 @@ public: ConnectionType connectionType = ConnectionTypeHTTP); #else explicit QHttpNetworkConnection(const QString &hostName, quint16 port = 80, bool encrypt = false, - QObject *parent = 0, - ConnectionType connectionType = ConnectionTypeHTTP); + ConnectionType connectionType = ConnectionTypeHTTP, + QObject *parent = 0); QHttpNetworkConnection(quint16 channelCount, const QString &hostName, quint16 port = 80, bool encrypt = false, QObject *parent = 0, ConnectionType connectionType = ConnectionTypeHTTP); diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index f387559cb3..acaba33dee 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -338,7 +338,7 @@ void QNetworkAccessBackend::error(QNetworkReply::NetworkError code, const QStrin void QNetworkAccessBackend::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) { - manager->proxyAuthenticationRequired(proxy, synchronous, authenticator, &reply->lastProxyAuthentication); + manager->proxyAuthenticationRequired(QUrl(), proxy, synchronous, authenticator, &reply->lastProxyAuthentication); } #endif diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 473acc5f22..cc61f27cfb 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -99,13 +99,13 @@ bool getProxyAuth(const QString& proxyHostname, const QString &scheme, QString& bool retValue = false; SecProtocolType protocolType = kSecProtocolTypeAny; if (scheme.compare(QLatin1String("ftp"),Qt::CaseInsensitive)==0) { - protocolType = kSecProtocolTypeFTP; + protocolType = kSecProtocolTypeFTPProxy; } else if (scheme.compare(QLatin1String("http"),Qt::CaseInsensitive)==0 || scheme.compare(QLatin1String("preconnect-http"),Qt::CaseInsensitive)==0) { - protocolType = kSecProtocolTypeHTTP; + protocolType = kSecProtocolTypeHTTPProxy; } else if (scheme.compare(QLatin1String("https"),Qt::CaseInsensitive)==0 || scheme.compare(QLatin1String("preconnect-https"),Qt::CaseInsensitive)==0) { - protocolType = kSecProtocolTypeHTTPS; + protocolType = kSecProtocolTypeHTTPSProxy; } QByteArray proxyHostnameUtf8(proxyHostname.toUtf8()); err = SecKeychainFindInternetPassword(NULL, @@ -1392,21 +1392,6 @@ void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authen } } -#ifndef QT_NO_NETWORKPROXY -#if defined(Q_OS_MACX) - //now we try to get the username and password from keychain - //if not successful signal will be emitted - QString username; - QString password; - if (getProxyAuth(proxy.hostName(),reply->request().url().scheme(),username,password)) { - authenticator->setUser(username); - authenticator->setPassword(password); - authenticationManager->cacheProxyCredentials(proxy, authenticator); - return; - } -#endif -#endif //QT_NO_NETWORKPROXY - // if we emit a signal here in synchronous mode, the user might spin // an event loop, which might recurse and lead to problems if (synchronous) @@ -1419,7 +1404,8 @@ void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authen } #ifndef QT_NO_NETWORKPROXY -void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QNetworkProxy &proxy, +void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QUrl &url, + const QNetworkProxy &proxy, bool synchronous, QAuthenticator *authenticator, QNetworkProxy *lastProxyAuthentication) @@ -1435,6 +1421,26 @@ void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QNetworkPro } } +#if defined(Q_OS_OSX) + //now we try to get the username and password from keychain + //if not successful signal will be emitted + QString username; + QString password; + if (getProxyAuth(proxy.hostName(), url.scheme(), username, password)) { + // only cache the system credentials if they are correct (or if they have changed) + // to not run into an endless loop in case they are wrong + QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedProxyCredentials(proxy); + if (!priv->hasFailed || cred.user != username || cred.password != password) { + authenticator->setUser(username); + authenticator->setPassword(password); + authenticationManager->cacheProxyCredentials(proxy, authenticator); + return; + } + } +#else + Q_UNUSED(url); +#endif + // if we emit a signal here in synchronous mode, the user might spin // an event loop, which might recurse and lead to problems if (synchronous) diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 92762d3ed4..bd5a6faeef 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -113,7 +113,8 @@ public: const QAuthenticator *auth = 0); #ifndef QT_NO_NETWORKPROXY - void proxyAuthenticationRequired(const QNetworkProxy &proxy, + void proxyAuthenticationRequired(const QUrl &url, + const QNetworkProxy &proxy, bool synchronous, QAuthenticator *authenticator, QNetworkProxy *lastProxyAuthentication); diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index f56c77505a..a85480c56b 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -975,6 +975,9 @@ void QNetworkReplyHttpImplPrivate::initCacheSaveDevice() cacheSaveDevice = managerPrivate->networkCache->prepare(metaData); + if (cacheSaveDevice) + q->connect(cacheSaveDevice, SIGNAL(aboutToClose()), SLOT(_q_cacheSaveDeviceAboutToClose())); + if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { if (cacheSaveDevice && !cacheSaveDevice->isOpen()) qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " @@ -1220,7 +1223,7 @@ void QNetworkReplyHttpImplPrivate::httpAuthenticationRequired(const QHttpNetwork void QNetworkReplyHttpImplPrivate::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) { - managerPrivate->proxyAuthenticationRequired(proxy, synchronous, authenticator, &lastProxyAuthentication); + managerPrivate->proxyAuthenticationRequired(request.url(), proxy, synchronous, authenticator, &lastProxyAuthentication); } #endif @@ -1708,6 +1711,13 @@ void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingDataFinished() QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } +void QNetworkReplyHttpImplPrivate::_q_cacheSaveDeviceAboutToClose() +{ + // do not keep a dangling pointer to the device around (device + // is closing because e.g. QAbstractNetworkCache::remove() was called). + cacheSaveDevice = 0; +} + void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData() { Q_Q(QNetworkReplyHttpImpl); diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h index aa2d6f0ec9..d21659ce82 100644 --- a/src/network/access/qnetworkreplyhttpimpl_p.h +++ b/src/network/access/qnetworkreplyhttpimpl_p.h @@ -130,6 +130,7 @@ public: Q_PRIVATE_SLOT(d_func(), void wantUploadDataSlot(qint64)) Q_PRIVATE_SLOT(d_func(), void sentUploadDataSlot(qint64)) Q_PRIVATE_SLOT(d_func(), void emitReplyUploadProgress(qint64, qint64)) + Q_PRIVATE_SLOT(d_func(), void _q_cacheSaveDeviceAboutToClose()) #ifndef QT_NO_SSL @@ -179,6 +180,8 @@ public: void _q_bufferOutgoingData(); void _q_bufferOutgoingDataFinished(); + void _q_cacheSaveDeviceAboutToClose(); + #ifndef QT_NO_BEARERMANAGEMENT void _q_networkSessionConnected(); void _q_networkSessionFailed(); diff --git a/src/network/access/qnetworkreplynsurlconnectionimpl.mm b/src/network/access/qnetworkreplynsurlconnectionimpl.mm index d49324918e..f93f18357a 100644 --- a/src/network/access/qnetworkreplynsurlconnectionimpl.mm +++ b/src/network/access/qnetworkreplynsurlconnectionimpl.mm @@ -90,6 +90,7 @@ public: void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); void setRawHeader(const QByteArray &headerName, const QByteArray &value); void setError(QNetworkReply::NetworkError errorCode, const QString &errorString); + void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); }; @interface QtNSURLConnectionDelegate : NSObject @@ -140,6 +141,7 @@ QNetworkReplyNSURLConnectionImplPrivate::~QNetworkReplyNSURLConnectionImplPrivat void QNetworkReplyNSURLConnectionImplPrivate::setFinished() { q_func()->setFinished(true); + QMetaObject::invokeMethod(q_func(), "finished", Qt::QueuedConnection); } void QNetworkReplyNSURLConnectionImplPrivate::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) @@ -157,6 +159,11 @@ void QNetworkReplyNSURLConnectionImplPrivate::setError(QNetworkReply::NetworkErr q_func()->setError(errorCode, errorString); } +void QNetworkReplyNSURLConnectionImplPrivate::setAttribute(QNetworkRequest::Attribute code, const QVariant &value) +{ + q_func()->setAttribute(code, value); +} + void QNetworkReplyNSURLConnectionImpl::readyReadOutgoingData() { Q_D(QNetworkReplyNSURLConnectionImpl); @@ -269,6 +276,9 @@ void QNetworkReplyNSURLConnectionImpl::readyReadOutgoingData() NSString *value = [headers objectForKey:key]; replyprivate->setRawHeader(QString::fromNSString(key).toUtf8(), QString::fromNSString(value).toUtf8()); } + + int code = [httpResponse statusCode]; + replyprivate->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, code); } else { if ([aResponse expectedContentLength] != NSURLResponseUnknownLength) replyprivate->setHeader(QNetworkRequest::ContentLengthHeader, [aResponse expectedContentLength]); @@ -317,8 +327,7 @@ void QNetworkReplyNSURLConnectionImpl::readyReadOutgoingData() - (void)connectionDidFinishLoading:(NSURLConnection*)connection { Q_UNUSED(connection) - replyprivate->setFinished(); - QMetaObject::invokeMethod(replyprivate->q_func(), "finished", Qt::QueuedConnection); + replyprivate->setFinished(); } - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection*)connection |