summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkaccessmanager.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-04-16 12:04:34 +0200
committerLars Knoll <lars.knoll@nokia.com>2012-04-16 12:04:34 +0200
commit9bd032355163d92cda5e7e59ecd21214b131f187 (patch)
tree002fa12558505683143c7eb08949a3d225bf0712 /src/network/access/qnetworkaccessmanager.cpp
parentd037d25c3d5236623371cf051aaf6a9e59792ba7 (diff)
parent41673c45dde2eb95ee21dd918235218399f2be2c (diff)
Merge remote-tracking branch 'origin/master' into api_changes
Conflicts: configure src/corelib/io/qurl.cpp src/gui/kernel/qwindow.cpp src/tools/moc/generator.cpp src/widgets/kernel/qwidget_qpa.cpp src/widgets/styles/qstyle.h src/widgets/widgets/qtabbar.cpp tests/auto/corelib/codecs/utf8/tst_utf8.cpp Change-Id: Ia457228d6f684ec8184e13e8fcc9d25857b1751e
Diffstat (limited to 'src/network/access/qnetworkaccessmanager.cpp')
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 7f1f819436..8d68f439f1 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -82,6 +82,64 @@ Q_GLOBAL_STATIC(QNetworkAccessFtpBackendFactory, ftpBackend)
Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend)
#endif
+#ifdef Q_OS_MAC
+
+#include <CoreServices/CoreServices.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <Security/SecKeychain.h>
+
+bool getProxyAuth(const QString& proxyHostname, const QString &scheme, QString& username, QString& password)
+{
+ OSStatus err;
+ SecKeychainItemRef itemRef;
+ bool retValue = false;
+ SecProtocolType protocolType = kSecProtocolTypeAny;
+ if (scheme.compare(QLatin1String("ftp"),Qt::CaseInsensitive)==0) {
+ protocolType = kSecProtocolTypeFTP;
+ } else if (scheme.compare(QLatin1String("http"),Qt::CaseInsensitive)==0) {
+ protocolType = kSecProtocolTypeHTTP;
+ } else if (scheme.compare(QLatin1String("https"),Qt::CaseInsensitive)==0) {
+ protocolType = kSecProtocolTypeHTTPS;
+ }
+ QByteArray proxyHostnameUtf8(proxyHostname.toUtf8());
+ err = SecKeychainFindInternetPassword(NULL,
+ proxyHostnameUtf8.length(), proxyHostnameUtf8.constData(),
+ 0,NULL,
+ 0, NULL,
+ 0, NULL,
+ 0,
+ protocolType,
+ kSecAuthenticationTypeAny,
+ 0, NULL,
+ &itemRef);
+ if (err == noErr) {
+
+ SecKeychainAttribute attr;
+ SecKeychainAttributeList attrList;
+ UInt32 length;
+ void *outData;
+
+ attr.tag = kSecAccountItemAttr;
+ attr.length = 0;
+ attr.data = NULL;
+
+ attrList.count = 1;
+ attrList.attr = &attr;
+
+ if (SecKeychainItemCopyContent(itemRef, NULL, &attrList, &length, &outData) == noErr) {
+ username = QString::fromUtf8((const char*)attr.data, attr.length);
+ password = QString::fromUtf8((const char*)outData, length);
+ SecKeychainItemFreeContent(&attrList,outData);
+ retValue = true;
+ }
+ CFRelease(itemRef);
+ }
+ return retValue;
+}
+#endif
+
+
+
static void ensureInitialized()
{
#ifndef QT_NO_FTP
@@ -1128,6 +1186,18 @@ void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authen
return;
}
}
+#ifdef Q_OS_MAC
+ //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
// if we emit a signal here in synchronous mode, the user might spin
// an event loop, which might recurse and lead to problems