QNAM: Improve internal authenticationRequired()

Make it independant from the backend architecture
to improve refactorability.

Reviewed-by: Peter Hartmann
This commit is contained in:
Markus Goetz 2011-04-05 16:24:01 +02:00
parent 0c637cb07b
commit 856da3ee19
3 changed files with 17 additions and 13 deletions

View File

@ -321,7 +321,7 @@ void QNetworkAccessBackend::proxyAuthenticationRequired(const QNetworkProxy &pro
void QNetworkAccessBackend::authenticationRequired(QAuthenticator *authenticator)
{
manager->authenticationRequired(this, authenticator);
manager->authenticationRequired(authenticator, reply->q_func(), synchronous, reply->url, &reply->urlForLastAuthentication);
}
void QNetworkAccessBackend::metaDataChanged()

View File

@ -1055,35 +1055,35 @@ void QNetworkAccessManagerPrivate::createCookieJar() const
}
}
void QNetworkAccessManagerPrivate::authenticationRequired(QNetworkAccessBackend *backend,
QAuthenticator *authenticator)
void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authenticator,
QNetworkReply *reply,
bool synchronous,
QUrl &url,
QUrl *urlForLastAuthentication)
{
Q_Q(QNetworkAccessManager);
// FIXME: Add support for domains (i.e., the leading path)
QUrl url = backend->reply->url;
// don't try the cache for the same URL twice in a row
// being called twice for the same URL means the authentication failed
// also called when last URL is empty, e.g. on first call
if (backend->reply->urlForLastAuthentication.isEmpty()
|| url != backend->reply->urlForLastAuthentication) {
if (urlForLastAuthentication->isEmpty()
|| url != *urlForLastAuthentication) {
QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedCredentials(url, authenticator);
if (!cred.isNull()) {
authenticator->setUser(cred.user);
authenticator->setPassword(cred.password);
backend->reply->urlForLastAuthentication = url;
*urlForLastAuthentication = url;
return;
}
}
// if we emit a signal here in synchronous mode, the user might spin
// an event loop, which might recurse and lead to problems
if (backend->isSynchronous())
if (synchronous)
return;
backend->reply->urlForLastAuthentication = url;
emit q->authenticationRequired(backend->reply->q_func(), authenticator);
*urlForLastAuthentication = url;
emit q->authenticationRequired(reply, authenticator);
authenticationManager->cacheCredentials(url, authenticator);
}

View File

@ -94,7 +94,11 @@ public:
QNetworkReply *postProcess(QNetworkReply *reply);
void createCookieJar() const;
void authenticationRequired(QNetworkAccessBackend *backend, QAuthenticator *authenticator);
void authenticationRequired(QAuthenticator *authenticator,
QNetworkReply *reply,
bool synchronous,
QUrl &url,
QUrl *urlForLastAuthentication);
void cacheCredentials(const QUrl &url, const QAuthenticator *auth);
QNetworkAuthenticationCredential *fetchCachedCredentials(const QUrl &url,
const QAuthenticator *auth = 0);