Qt 4.8
qnetworkproxy_blackberry.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Research In Motion
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
49 #include <QtNetwork/qnetworkproxy.h>
50 
51 #ifndef QT_NO_NETWORKPROXY
52 
53 
54 #include <QtCore/qurl.h>
55 #include <QtNetwork/qnetworkconfiguration.h>
56 
57 #include <bps/netstatus.h>
58 #include <errno.h>
59 
60 
62 
64 {
65  if (query.url().scheme() == QLatin1String("file")
66  || query.url().scheme() == QLatin1String("qrc"))
68 
71  qWarning("Unsupported query type: %d", query.queryType());
73  }
74 
75  QUrl url;
77  url = query.url();
78  } else if (query.queryType() == QNetworkProxyQuery::TcpSocket
79  && !query.peerHostName().isEmpty()) {
80  url.setHost(query.peerHostName());
81  switch (query.peerPort()) {
82  case 443:
83  url.setScheme(QLatin1String("https"));
84  break;
85  case 21:
86  url.setScheme(QLatin1String("ftp"));
87  break;
88  default:
89  // for unknown ports, we just pretend we are dealing
90  // with a HTTP URL, otherwise we will not get a proxy
91  // from the netstatus API
92  url.setScheme(QLatin1String("http"));
93  }
94  }
95 
96  if (!url.isValid()) {
97  qWarning("Invalid URL: %s", qPrintable(url.toString()));
99  }
100 
101  netstatus_proxy_details_t details;
102  memset(&details, 0, sizeof(netstatus_proxy_details_t));
103 
104 #if BPS_VERSION >= 3001001
105 
106  QByteArray bUrl(url.toEncoded());
107  QString sInterface(query.networkConfiguration().name());
108  QByteArray bInterface;
109  if (!sInterface.isEmpty()) {
111  qWarning("Unsupported configuration type: %d", query.networkConfiguration().type());
113  }
114  bInterface = sInterface.toUtf8();
115  }
116 
117  if (netstatus_get_proxy_details_for_url(bUrl.constData(), (bInterface.isEmpty() ? NULL : bInterface.constData()), &details) != BPS_SUCCESS) {
118  qWarning("netstatus_get_proxy_details_for_url failed! errno: %d", errno);
120  }
121 
122 #else
123 
124  if (netstatus_get_proxy_details(&details) != BPS_SUCCESS) {
125  qWarning("netstatus_get_proxy_details failed! errno: %d", errno);
127  }
128 
129 #endif
130 
131  if (details.http_proxy_host == NULL) { // No proxy
132  netstatus_free_proxy_details(&details);
134  }
135 
136  QNetworkProxy proxy;
137 
138  QString protocol = query.protocolTag();
139  if (protocol.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { // http, https
141  } else if (protocol == QLatin1String("ftp")) {
143  } else { // assume http proxy
144  qDebug("Proxy type: %s assumed to be http proxy", qPrintable(protocol));
146  }
147 
148  // Set host
149  // Note: ftp and https proxy type fields *are* obsolete.
150  // The user interface allows only one host/port which gets duplicated
151  // to all proxy type fields.
152  proxy.setHostName(QString::fromUtf8(details.http_proxy_host));
153 
154  // Set port
155  proxy.setPort(details.http_proxy_port);
156 
157  // Set username
158  if (details.http_proxy_login_user)
159  proxy.setUser(QString::fromUtf8(details.http_proxy_login_user));
160 
161  // Set password
162  if (details.http_proxy_login_password)
163  proxy.setPassword(QString::fromUtf8(details.http_proxy_login_password));
164 
165  netstatus_free_proxy_details(&details);
166 
167  return QList<QNetworkProxy>() << proxy;
168 }
169 
171 
172 #endif
int peerPort() const
Returns the port number for the outgoing request or -1 if the port number is not known.
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QString peerHostName() const
Returns the host name or IP address being of the outgoing connection being requested, or an empty string if the remote hostname is not known.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static QList< QNetworkProxy > systemProxyForQuery(const QNetworkProxyQuery &query=QNetworkProxyQuery())
This function takes the query request, query, examines the details of the type of socket or request a...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setUser(const QString &userName)
Sets the user name for proxy authentication to be user.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setHost(const QString &host)
Sets the host of the URL to host.
Definition: qurl.cpp:4821
Q_CORE_EXPORT void qDebug(const char *,...)
The QNetworkProxy class provides a network layer proxy.
QueryType queryType() const
Returns the query type.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString protocolTag() const
Returns the protocol tag for this QNetworkProxyQuery object, or an empty QString in case the protocol...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
Q_CORE_EXPORT void qWarning(const char *,...)
void setHostName(const QString &hostName)
Sets the host name of the proxy host to be hostName.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
Definition: qnetworkproxy.h:60
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
QNetworkConfiguration networkConfiguration() const
Returns the network configuration of the proxy query.
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QString name() const
Returns the user visible name of this configuration.
void setType(QNetworkProxy::ProxyType type)
Sets the proxy type for this instance to be type.
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
QUrl url() const
Returns the URL component of this QNetworkProxyQuery object in case of a query of type QNetworkProxyQ...
void setPassword(const QString &password)
Sets the password for proxy authentication to be password.
#define qPrintable(string)
Definition: qglobal.h:1750
void setPort(quint16 port)
Sets the port of the proxy host to be port.
int errno
Type type() const
Returns the type of the configuration.