diff options
author | Andrey Leonov <aleonov@rim.com> | 2012-10-04 19:37:00 -0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-08 11:14:28 +0200 |
commit | e4a6f44ce1a35986c445c40ff2793456782f58fa (patch) | |
tree | f6d6f8e931d28c07551f222a19db74448e77f85a /src/network/kernel/qnetworkproxy_blackberry.cpp | |
parent | f884a73fcbf4012a086a7b471b7914c2ef1ae68d (diff) |
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>
Diffstat (limited to 'src/network/kernel/qnetworkproxy_blackberry.cpp')
-rw-r--r-- | src/network/kernel/qnetworkproxy_blackberry.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/network/kernel/qnetworkproxy_blackberry.cpp b/src/network/kernel/qnetworkproxy_blackberry.cpp new file mode 100644 index 0000000000..c257f085ff --- /dev/null +++ b/src/network/kernel/qnetworkproxy_blackberry.cpp @@ -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 |