Implementation of the BlackBerry Qt Proxy support.

An implementation for BlackBerry devices based on the BPS netstatus API.

Change-Id: I89deed031d2a867bbd6628bee97f61345b58f1ab
Reviewed-by: Peter Hartmann <phartmann@rim.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Andrey Leonov 2012-10-04 19:37:00 -04:00 committed by The Qt Project
parent f884a73fcb
commit e4a6f44ce1
3 changed files with 140 additions and 0 deletions

View File

@ -42,4 +42,7 @@ integrity:SOURCES += kernel/qdnslookup_unix.cpp kernel/qhostinfo_unix.cpp kernel
mac:LIBS_PRIVATE += -framework SystemConfiguration -framework CoreFoundation -framework CoreServices
mac:!ios:SOURCES += kernel/qnetworkproxy_mac.cpp
else:win32:SOURCES += kernel/qnetworkproxy_win.cpp
else:blackberry:SOURCES += kernel/qnetworkproxy_blackberry.cpp
else:SOURCES += kernel/qnetworkproxy_generic.cpp
blackberry: LIBS_PRIVATE += -lbps

View File

@ -1534,6 +1534,12 @@ void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *fact
SOCKS server for all queries. If SOCKS isn't enabled, it will use
the HTTPS proxy for all TcpSocket and UrlRequest queries.
On BlackBerry, this function obtains proxy settings for the default
configuration using system configuration. The type will be set based on
protocol tag "http", "https", "ftp", respectively. By default, it
assumes http type. Proxy username and password are also set during
the query using system configuration.
On other systems, this function will pick up proxy settings from
the "http_proxy" environment variable. This variable must be a URL
using one of the following schemes: "http", "socks5" or "socks5h".
@ -1550,6 +1556,11 @@ void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *fact
\li On Windows platforms, this function may take several seconds to
execute depending on the configuration of the user's system.
\li On BlackBerry, this function ignores network configuration specified
in \a query. Only UrlRequest quieries are supported. SOCKS is not supported.
The proxy information is retrieved only for the default configuration.
Also, PAC and exclusion lists are currently not supported.
\endlist
*/

View File

@ -0,0 +1,126 @@
/****************************************************************************
**
** Copyright (C) 2012 Research In Motion
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/**
* Some notes about the code:
*
* ** It is assumed that the system proxies are for url based requests
* ie. HTTP/HTTPS based.
*/
#include <QtNetwork/qnetworkproxy.h>
#ifndef QT_NO_NETWORKPROXY
#include <QtCore/qflags.h>
#include <QtCore/qurl.h>
#include <QtNetwork/qnetworkconfiguration.h>
#include <bps/netstatus.h>
#include <errno.h>
QT_BEGIN_NAMESPACE
QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query)
{
QNetworkProxy proxy;
if (query.queryType() != QNetworkProxyQuery::UrlRequest) {
qWarning("Unsupported query type: %d", query.queryType());
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QUrl url = query.url();
if (!url.isValid()) {
qWarning("Invalid URL: %s", qPrintable(url.toString()));
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
netstatus_proxy_details_t details;
memset(&details, 0, sizeof(netstatus_proxy_details_t));
if (netstatus_get_proxy_details(&details) != BPS_SUCCESS) {
qWarning("netstatus_get_proxy_details failed! errno: %d", errno);
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
if (details.http_proxy_host == NULL) { // No proxy
netstatus_free_proxy_details(&details);
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QString protocol = query.protocolTag();
if (protocol.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { // http, https
proxy.setType((QNetworkProxy::HttpProxy));
} else if (protocol == QLatin1String("ftp")) {
proxy.setType(QNetworkProxy::FtpCachingProxy);
} else { // assume http proxy
qDebug("Proxy type: %s assumed to be http proxy", qPrintable(protocol));
proxy.setType((QNetworkProxy::HttpProxy));
}
// Set host
// Note: ftp and https proxy type fields *are* obsolete.
// The user interface allows only one host/port which gets duplicated
// to all proxy type fields.
proxy.setHostName(QString::fromUtf8(details.http_proxy_host));
// Set port
proxy.setPort(details.http_proxy_port);
// Set username
if (details.http_proxy_login_user)
proxy.setUser(QString::fromUtf8(details.http_proxy_login_user));
// Set password
if (details.http_proxy_login_password)
proxy.setPassword(QString::fromUtf8(details.http_proxy_login_password));
netstatus_free_proxy_details(&details);
return QList<QNetworkProxy>() << proxy;
}
QT_END_NAMESPACE
#endif