From d23a08c51d0f275b07668bfbc3f818c563b9b956 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Thu, 7 Feb 2013 17:02:48 +0100 Subject: BB10 systemProxyForQuery: query system proxy also for non-URL requests ... like e.g. in QAbstractSocket::connectToHost(). We can set the scheme on the query URL based on well-known ports; even if the port is not well-known, we can just query the URL anyhow and let the netstatus API resolve the right proxy for us. In addition, return early for local schemes like "file" and "qrc". Task-number: QTBUG-29425 (cherry picked from commit 28d526db74c50977215133159e565e7c15fd18e3) Change-Id: I40a4865aa7765aad9145e956c0069e78c54670e7 Reviewed-by: Rafael Roquetto --- src/network/kernel/qnetworkproxy.cpp | 2 +- src/network/kernel/qnetworkproxy_blackberry.cpp | 30 ++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp index f2101f0..2e6b8dd 100644 --- a/src/network/kernel/qnetworkproxy.cpp +++ b/src/network/kernel/qnetworkproxy.cpp @@ -1420,7 +1420,7 @@ void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *fact \o On Windows platforms, this function may take several seconds to execute depending on the configuration of the user's system. - \li On BlackBerry, only UrlRequest queries are supported. SOCKS is + \li On BlackBerry, only UrlRequest and TcpSocket queries are supported. SOCKS is not supported. The proxy credentials are only retrieved for the default configuration. \endlist diff --git a/src/network/kernel/qnetworkproxy_blackberry.cpp b/src/network/kernel/qnetworkproxy_blackberry.cpp index cbc2533..ac8cfcc 100644 --- a/src/network/kernel/qnetworkproxy_blackberry.cpp +++ b/src/network/kernel/qnetworkproxy_blackberry.cpp @@ -62,14 +62,36 @@ QT_BEGIN_NAMESPACE QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) { - QNetworkProxy proxy; + if (query.url().scheme() == QLatin1String("file") + || query.url().scheme() == QLatin1String("qrc")) + return QList() << QNetworkProxy(QNetworkProxy::NoProxy); - if (query.queryType() != QNetworkProxyQuery::UrlRequest) { + if (query.queryType() != QNetworkProxyQuery::UrlRequest + && query.queryType() != QNetworkProxyQuery::TcpSocket) { qWarning("Unsupported query type: %d", query.queryType()); return QList() << QNetworkProxy(QNetworkProxy::NoProxy); } - QUrl url = query.url(); + QUrl url; + if (query.queryType() == QNetworkProxyQuery::UrlRequest) { + url = query.url(); + } else if (query.queryType() == QNetworkProxyQuery::TcpSocket + && !query.peerHostName().isEmpty()) { + url.setHost(query.peerHostName()); + switch (query.peerPort()) { + case 443: + url.setScheme(QLatin1String("https")); + break; + case 21: + url.setScheme(QLatin1String("ftp")); + break; + default: + // for unknown ports, we just pretend we are dealing + // with a HTTP URL, otherwise we will not get a proxy + // from the netstatus API + url.setScheme(QLatin1String("http")); + } + } if (!url.isValid()) { qWarning("Invalid URL: %s", qPrintable(url.toString())); @@ -111,6 +133,8 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro return QList() << QNetworkProxy(QNetworkProxy::NoProxy); } + QNetworkProxy proxy; + QString protocol = query.protocolTag(); if (protocol.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { // http, https proxy.setType((QNetworkProxy::HttpProxy)); -- cgit v0.12