| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qnetworkproxy.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 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 The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | - | |||||||||||||
| 35 | /*! | - | ||||||||||||
| 36 | \class QNetworkProxy | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | \since 4.1 | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | \brief The QNetworkProxy class provides a network layer proxy. | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | \reentrant | - | ||||||||||||
| 43 | \ingroup network | - | ||||||||||||
| 44 | \ingroup shared | - | ||||||||||||
| 45 | \inmodule QtNetwork | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QNetworkProxy provides the method for configuring network layer | - | ||||||||||||
| 48 | proxy support to the Qt network classes. The currently supported | - | ||||||||||||
| 49 | classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer | - | ||||||||||||
| 50 | and QNetworkAccessManager. The proxy support is designed to | - | ||||||||||||
| 51 | be as transparent as possible. This means that existing | - | ||||||||||||
| 52 | network-enabled applications that you have written should | - | ||||||||||||
| 53 | automatically support network proxy using the following code. | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | \snippet code/src_network_kernel_qnetworkproxy.cpp 0 | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | An alternative to setting an application wide proxy is to specify | - | ||||||||||||
| 58 | the proxy for individual sockets using QAbstractSocket::setProxy() | - | ||||||||||||
| 59 | and QTcpServer::setProxy(). In this way, it is possible to disable | - | ||||||||||||
| 60 | the use of a proxy for specific sockets using the following code: | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | \snippet code/src_network_kernel_qnetworkproxy.cpp 1 | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | Network proxy is not used if the address used in \l | - | ||||||||||||
| 65 | {QAbstractSocket::connectToHost()}{connectToHost()}, \l | - | ||||||||||||
| 66 | {QUdpSocket::bind()}{bind()} or \l | - | ||||||||||||
| 67 | {QTcpServer::listen()}{listen()} is equivalent to | - | ||||||||||||
| 68 | QHostAddress::LocalHost or QHostAddress::LocalHostIPv6. | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | Each type of proxy support has certain restrictions associated with it. | - | ||||||||||||
| 71 | You should read the \l{ProxyType} documentation carefully before | - | ||||||||||||
| 72 | selecting a proxy type to use. | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | \note Changes made to currently connected sockets do not take effect. | - | ||||||||||||
| 75 | If you need to change a connected socket, you should reconnect it. | - | ||||||||||||
| 76 | - | |||||||||||||
| 77 | \section1 SOCKS5 | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | The SOCKS5 support in Qt 4 is based on \l{http://www.rfc-editor.org/rfc/rfc1928.txt}{RFC 1928} and \l{http://www.rfc-editor.org/rfc/rfc1929.txt}{RFC 1929}. | - | ||||||||||||
| 80 | The supported authentication methods are no authentication and | - | ||||||||||||
| 81 | username/password authentication. Both IPv4 and IPv6 are | - | ||||||||||||
| 82 | supported. Domain names are resolved through the SOCKS5 server if | - | ||||||||||||
| 83 | the QNetworkProxy::HostNameLookupCapability is enabled, otherwise | - | ||||||||||||
| 84 | they are resolved locally and the IP address is sent to the | - | ||||||||||||
| 85 | server. There are several things to remember when using SOCKS5 | - | ||||||||||||
| 86 | with QUdpSocket and QTcpServer: | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | With QUdpSocket, a call to \l {QUdpSocket::bind()}{bind()} may fail | - | ||||||||||||
| 89 | with a timeout error. If a port number other than 0 is passed to | - | ||||||||||||
| 90 | \l {QUdpSocket::bind()}{bind()}, it is not guaranteed that it is the | - | ||||||||||||
| 91 | specified port that will be used. | - | ||||||||||||
| 92 | Use \l{QUdpSocket::localPort()}{localPort()} and | - | ||||||||||||
| 93 | \l{QUdpSocket::localAddress()}{localAddress()} to get the actual | - | ||||||||||||
| 94 | address and port number in use. Because proxied UDP goes through | - | ||||||||||||
| 95 | two UDP connections, it is more likely that packets will be dropped. | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | With QTcpServer a call to \l{QTcpServer::listen()}{listen()} may | - | ||||||||||||
| 98 | fail with a timeout error. If a port number other than 0 is passed | - | ||||||||||||
| 99 | to \l{QTcpServer::listen()}{listen()}, then it is not guaranteed | - | ||||||||||||
| 100 | that it is the specified port that will be used. | - | ||||||||||||
| 101 | Use \l{QTcpServer::serverPort()}{serverPort()} and | - | ||||||||||||
| 102 | \l{QTcpServer::serverAddress()}{serverAddress()} to get the actual | - | ||||||||||||
| 103 | address and port used to listen for connections. SOCKS5 only supports | - | ||||||||||||
| 104 | one accepted connection per call to \l{QTcpServer::listen()}{listen()}, | - | ||||||||||||
| 105 | and each call is likely to result in a different | - | ||||||||||||
| 106 | \l{QTcpServer::serverPort()}{serverPort()} being used. | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | \sa QAbstractSocket, QTcpServer | - | ||||||||||||
| 109 | */ | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | /*! | - | ||||||||||||
| 112 | \enum QNetworkProxy::ProxyType | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | This enum describes the types of network proxying provided in Qt. | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | There are two types of proxies that Qt understands: | - | ||||||||||||
| 117 | transparent proxies and caching proxies. The first group consists | - | ||||||||||||
| 118 | of proxies that can handle any arbitrary data transfer, while the | - | ||||||||||||
| 119 | second can only handle specific requests. The caching proxies only | - | ||||||||||||
| 120 | make sense for the specific classes where they can be used. | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | \value NoProxy No proxying is used | - | ||||||||||||
| 123 | \value DefaultProxy Proxy is determined based on the application proxy set using setApplicationProxy() | - | ||||||||||||
| 124 | \value Socks5Proxy \l Socks5 proxying is used | - | ||||||||||||
| 125 | \value HttpProxy HTTP transparent proxying is used | - | ||||||||||||
| 126 | \value HttpCachingProxy Proxying for HTTP requests only | - | ||||||||||||
| 127 | \value FtpCachingProxy Proxying for FTP requests only | - | ||||||||||||
| 128 | - | |||||||||||||
| 129 | The table below lists different proxy types and their | - | ||||||||||||
| 130 | capabilities. Since each proxy type has different capabilities, it | - | ||||||||||||
| 131 | is important to understand them before choosing a proxy type. | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | \table | - | ||||||||||||
| 134 | \header | - | ||||||||||||
| 135 | \li Proxy type | - | ||||||||||||
| 136 | \li Description | - | ||||||||||||
| 137 | \li Default capabilities | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | \row | - | ||||||||||||
| 140 | \li SOCKS 5 | - | ||||||||||||
| 141 | \li Generic proxy for any kind of connection. Supports TCP, | - | ||||||||||||
| 142 | UDP, binding to a port (incoming connections) and | - | ||||||||||||
| 143 | authentication. | - | ||||||||||||
| 144 | \li TunnelingCapability, ListeningCapability, | - | ||||||||||||
| 145 | UdpTunnelingCapability, HostNameLookupCapability | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | \row | - | ||||||||||||
| 148 | \li HTTP | - | ||||||||||||
| 149 | \li Implemented using the "CONNECT" command, supports only | - | ||||||||||||
| 150 | outgoing TCP connections; supports authentication. | - | ||||||||||||
| 151 | \li TunnelingCapability, CachingCapability, HostNameLookupCapability | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | \row | - | ||||||||||||
| 154 | \li Caching-only HTTP | - | ||||||||||||
| 155 | \li Implemented using normal HTTP commands, it is useful only | - | ||||||||||||
| 156 | in the context of HTTP requests (see QNetworkAccessManager) | - | ||||||||||||
| 157 | \li CachingCapability, HostNameLookupCapability | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | \row | - | ||||||||||||
| 160 | \li Caching FTP | - | ||||||||||||
| 161 | \li Implemented using an FTP proxy, it is useful only in the | - | ||||||||||||
| 162 | context of FTP requests (see QNetworkAccessManager) | - | ||||||||||||
| 163 | \li CachingCapability, HostNameLookupCapability | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | \endtable | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | Also note that you shouldn't set the application default proxy | - | ||||||||||||
| 168 | (setApplicationProxy()) to a proxy that doesn't have the | - | ||||||||||||
| 169 | TunnelingCapability capability. If you do, QTcpSocket will not | - | ||||||||||||
| 170 | know how to open connections. | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | \sa setType(), type(), capabilities(), setCapabilities() | - | ||||||||||||
| 173 | */ | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | /*! | - | ||||||||||||
| 176 | \enum QNetworkProxy::Capability | - | ||||||||||||
| 177 | \since 4.5 | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | These flags indicate the capabilities that a given proxy server | - | ||||||||||||
| 180 | supports. | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | QNetworkProxy sets different capabilities by default when the | - | ||||||||||||
| 183 | object is created (see QNetworkProxy::ProxyType for a list of the | - | ||||||||||||
| 184 | defaults). However, it is possible to change the capabitilies | - | ||||||||||||
| 185 | after the object has been created with setCapabilities(). | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | The capabilities that QNetworkProxy supports are: | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | \value TunnelingCapability Ability to open transparent, tunneled | - | ||||||||||||
| 190 | TCP connections to a remote host. The proxy server relays the | - | ||||||||||||
| 191 | transmission verbatim from one side to the other and does no | - | ||||||||||||
| 192 | caching. | - | ||||||||||||
| 193 | - | |||||||||||||
| 194 | \value ListeningCapability Ability to create a listening socket | - | ||||||||||||
| 195 | and wait for an incoming TCP connection from a remote host. | - | ||||||||||||
| 196 | - | |||||||||||||
| 197 | \value UdpTunnelingCapability Ability to relay UDP datagrams via | - | ||||||||||||
| 198 | the proxy server to and from a remote host. | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | \value CachingCapability Ability to cache the contents of the | - | ||||||||||||
| 201 | transfer. This capability is specific to each protocol and proxy | - | ||||||||||||
| 202 | type. For example, HTTP proxies can cache the contents of web data | - | ||||||||||||
| 203 | transferred with "GET" commands. | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | \value HostNameLookupCapability Ability to connect to perform the | - | ||||||||||||
| 206 | lookup on a remote host name and connect to it, as opposed to | - | ||||||||||||
| 207 | requiring the application to perform the name lookup and request | - | ||||||||||||
| 208 | connection to IP addresses only. | - | ||||||||||||
| 209 | */ | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | #include "qnetworkproxy.h" | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
| 214 | - | |||||||||||||
| 215 | #include "private/qnetworkproxy_p.h" | - | ||||||||||||
| 216 | #include "private/qnetworkrequest_p.h" | - | ||||||||||||
| 217 | #include "private/qsocks5socketengine_p.h" | - | ||||||||||||
| 218 | #include "private/qhttpsocketengine_p.h" | - | ||||||||||||
| 219 | #include "qauthenticator.h" | - | ||||||||||||
| 220 | #include "qdebug.h" | - | ||||||||||||
| 221 | #include "qmutex.h" | - | ||||||||||||
| 222 | #include "qstringlist.h" | - | ||||||||||||
| 223 | #include "qurl.h" | - | ||||||||||||
| 224 | - | |||||||||||||
| 225 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||
| 226 | #include <QtNetwork/QNetworkConfiguration> | - | ||||||||||||
| 227 | #endif | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | class QSocks5SocketEngineHandler; | - | ||||||||||||
| 232 | class QHttpSocketEngineHandler; | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | class QGlobalNetworkProxy | - | ||||||||||||
| 235 | { | - | ||||||||||||
| 236 | public: | - | ||||||||||||
| 237 | QGlobalNetworkProxy() | - | ||||||||||||
| 238 | : mutex(QMutex::Recursive) | - | ||||||||||||
| 239 | , applicationLevelProxy(0) | - | ||||||||||||
| 240 | , applicationLevelProxyFactory(0) | - | ||||||||||||
| 241 | #ifndef QT_NO_SOCKS5 | - | ||||||||||||
| 242 | , socks5SocketEngineHandler(0) | - | ||||||||||||
| 243 | #endif | - | ||||||||||||
| 244 | #ifndef QT_NO_HTTP | - | ||||||||||||
| 245 | , httpSocketEngineHandler(0) | - | ||||||||||||
| 246 | #endif | - | ||||||||||||
| 247 | { | - | ||||||||||||
| 248 | #ifdef QT_USE_SYSTEM_PROXIES | - | ||||||||||||
| 249 | setApplicationProxyFactory(new QSystemConfigurationProxyFactory); | - | ||||||||||||
| 250 | #endif | - | ||||||||||||
| 251 | #ifndef QT_NO_SOCKS5 | - | ||||||||||||
| 252 | socks5SocketEngineHandler = new QSocks5SocketEngineHandler(); | - | ||||||||||||
| 253 | #endif | - | ||||||||||||
| 254 | #ifndef QT_NO_HTTP | - | ||||||||||||
| 255 | httpSocketEngineHandler = new QHttpSocketEngineHandler(); | - | ||||||||||||
| 256 | #endif | - | ||||||||||||
| 257 | } executed 36 times by 36 tests: end of blockExecuted by:
| 36 | ||||||||||||
| 258 | - | |||||||||||||
| 259 | ~QGlobalNetworkProxy() | - | ||||||||||||
| 260 | { | - | ||||||||||||
| 261 | delete applicationLevelProxy; | - | ||||||||||||
| 262 | delete applicationLevelProxyFactory; | - | ||||||||||||
| 263 | #ifndef QT_NO_SOCKS5 | - | ||||||||||||
| 264 | delete socks5SocketEngineHandler; | - | ||||||||||||
| 265 | #endif | - | ||||||||||||
| 266 | #ifndef QT_NO_HTTP | - | ||||||||||||
| 267 | delete httpSocketEngineHandler; | - | ||||||||||||
| 268 | #endif | - | ||||||||||||
| 269 | } executed 37 times by 37 tests: end of blockExecuted by:
| 37 | ||||||||||||
| 270 | - | |||||||||||||
| 271 | void setApplicationProxy(const QNetworkProxy &proxy) | - | ||||||||||||
| 272 | { | - | ||||||||||||
| 273 | QMutexLocker lock(&mutex); | - | ||||||||||||
| 274 | if (!applicationLevelProxy)
| 8-2880 | ||||||||||||
| 275 | applicationLevelProxy = new QNetworkProxy; executed 8 times by 8 tests: applicationLevelProxy = new QNetworkProxy;Executed by:
| 8 | ||||||||||||
| 276 | *applicationLevelProxy = proxy; | - | ||||||||||||
| 277 | delete applicationLevelProxyFactory; | - | ||||||||||||
| 278 | applicationLevelProxyFactory = 0; | - | ||||||||||||
| 279 | } executed 2888 times by 8 tests: end of blockExecuted by:
| 2888 | ||||||||||||
| 280 | - | |||||||||||||
| 281 | void setApplicationProxyFactory(QNetworkProxyFactory *factory) | - | ||||||||||||
| 282 | { | - | ||||||||||||
| 283 | QMutexLocker lock(&mutex); | - | ||||||||||||
| 284 | if (factory == applicationLevelProxyFactory)
| 0-22 | ||||||||||||
| 285 | return; never executed: return; | 0 | ||||||||||||
| 286 | if (applicationLevelProxy)
| 1-21 | ||||||||||||
| 287 | *applicationLevelProxy = QNetworkProxy(); executed 21 times by 2 tests: *applicationLevelProxy = QNetworkProxy();Executed by:
| 21 | ||||||||||||
| 288 | delete applicationLevelProxyFactory; | - | ||||||||||||
| 289 | applicationLevelProxyFactory = factory; | - | ||||||||||||
| 290 | } executed 22 times by 3 tests: end of blockExecuted by:
| 22 | ||||||||||||
| 291 | - | |||||||||||||
| 292 | QNetworkProxy applicationProxy() | - | ||||||||||||
| 293 | { | - | ||||||||||||
| 294 | return proxyForQuery(QNetworkProxyQuery()).first(); executed 2575 times by 19 tests: return proxyForQuery(QNetworkProxyQuery()).first();Executed by:
| 2575 | ||||||||||||
| 295 | } | - | ||||||||||||
| 296 | - | |||||||||||||
| 297 | QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query); | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | private: | - | ||||||||||||
| 300 | QMutex mutex; | - | ||||||||||||
| 301 | QNetworkProxy *applicationLevelProxy; | - | ||||||||||||
| 302 | QNetworkProxyFactory *applicationLevelProxyFactory; | - | ||||||||||||
| 303 | #ifndef QT_NO_SOCKS5 | - | ||||||||||||
| 304 | QSocks5SocketEngineHandler *socks5SocketEngineHandler; | - | ||||||||||||
| 305 | #endif | - | ||||||||||||
| 306 | #ifndef QT_NO_HTTP | - | ||||||||||||
| 307 | QHttpSocketEngineHandler *httpSocketEngineHandler; | - | ||||||||||||
| 308 | #endif | - | ||||||||||||
| 309 | }; | - | ||||||||||||
| 310 | - | |||||||||||||
| 311 | QList<QNetworkProxy> QGlobalNetworkProxy::proxyForQuery(const QNetworkProxyQuery &query) | - | ||||||||||||
| 312 | { | - | ||||||||||||
| 313 | QMutexLocker locker(&mutex); | - | ||||||||||||
| 314 | - | |||||||||||||
| 315 | QList<QNetworkProxy> result; | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | // don't look for proxies for a local connection | - | ||||||||||||
| 318 | QHostAddress parsed; | - | ||||||||||||
| 319 | QString hostname = query.url().host(); | - | ||||||||||||
| 320 | if (hostname == QLatin1String("localhost")
| 1152-8416 | ||||||||||||
| 321 | || hostname.startsWith(QLatin1String("localhost."))
| 0-8416 | ||||||||||||
| 322 | || (parsed.setAddress(hostname)
| 956-7460 | ||||||||||||
| 323 | && (parsed.isLoopback()))) {
| 384-572 | ||||||||||||
| 324 | result << QNetworkProxy(QNetworkProxy::NoProxy); | - | ||||||||||||
| 325 | return result; executed 1724 times by 17 tests: return result;Executed by:
| 1724 | ||||||||||||
| 326 | } | - | ||||||||||||
| 327 | - | |||||||||||||
| 328 | if (!applicationLevelProxyFactory) {
| 21-7823 | ||||||||||||
| 329 | if (applicationLevelProxy
| 3356-4467 | ||||||||||||
| 330 | && applicationLevelProxy->type() != QNetworkProxy::DefaultProxy)
| 0-3356 | ||||||||||||
| 331 | result << *applicationLevelProxy; executed 3356 times by 8 tests: result << *applicationLevelProxy;Executed by:
| 3356 | ||||||||||||
| 332 | else | - | ||||||||||||
| 333 | result << QNetworkProxy(QNetworkProxy::NoProxy); executed 4467 times by 22 tests: result << QNetworkProxy(QNetworkProxy::NoProxy);Executed by:
| 4467 | ||||||||||||
| 334 | return result; executed 7823 times by 25 tests: return result;Executed by:
| 7823 | ||||||||||||
| 335 | } | - | ||||||||||||
| 336 | - | |||||||||||||
| 337 | // we have a factory | - | ||||||||||||
| 338 | result = applicationLevelProxyFactory->queryProxy(query); | - | ||||||||||||
| 339 | if (result.isEmpty()) {
| 0-21 | ||||||||||||
| 340 | qWarning("QNetworkProxyFactory: factory %p has returned an empty result set", | - | ||||||||||||
| 341 | applicationLevelProxyFactory); | - | ||||||||||||
| 342 | result << QNetworkProxy(QNetworkProxy::NoProxy); | - | ||||||||||||
| 343 | } never executed: end of block | 0 | ||||||||||||
| 344 | return result; executed 21 times by 2 tests: return result;Executed by:
| 21 | ||||||||||||
| 345 | } | - | ||||||||||||
| 346 | - | |||||||||||||
| 347 | Q_GLOBAL_STATIC(QGlobalNetworkProxy, globalNetworkProxy) executed 37 times by 37 tests: end of blockExecuted by:
executed 37 times by 37 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 75414 times by 38 tests: return &holder.value;Executed by:
| 0-75414 | ||||||||||||
| 348 | - | |||||||||||||
| 349 | namespace { | - | ||||||||||||
| 350 | template<bool> struct StaticAssertTest; | - | ||||||||||||
| 351 | template<> struct StaticAssertTest<true> { enum { Value = 1 }; }; | - | ||||||||||||
| 352 | } | - | ||||||||||||
| 353 | - | |||||||||||||
| 354 | static inline void qt_noop_with_arg(int) {} | - | ||||||||||||
| 355 | #define q_static_assert(expr) qt_noop_with_arg(sizeof(StaticAssertTest< expr >::Value)) | - | ||||||||||||
| 356 | - | |||||||||||||
| 357 | static QNetworkProxy::Capabilities defaultCapabilitiesForType(QNetworkProxy::ProxyType type) | - | ||||||||||||
| 358 | { | - | ||||||||||||
| 359 | q_static_assert(int(QNetworkProxy::DefaultProxy) == 0); | - | ||||||||||||
| 360 | q_static_assert(int(QNetworkProxy::FtpCachingProxy) == 5); | - | ||||||||||||
| 361 | static const int defaults[] = | - | ||||||||||||
| 362 | { | - | ||||||||||||
| 363 | /* [QNetworkProxy::DefaultProxy] = */ | - | ||||||||||||
| 364 | (int(QNetworkProxy::ListeningCapability) | | - | ||||||||||||
| 365 | int(QNetworkProxy::TunnelingCapability) | | - | ||||||||||||
| 366 | int(QNetworkProxy::UdpTunnelingCapability)), | - | ||||||||||||
| 367 | /* [QNetworkProxy::Socks5Proxy] = */ | - | ||||||||||||
| 368 | (int(QNetworkProxy::TunnelingCapability) | | - | ||||||||||||
| 369 | int(QNetworkProxy::ListeningCapability) | | - | ||||||||||||
| 370 | int(QNetworkProxy::UdpTunnelingCapability) | | - | ||||||||||||
| 371 | int(QNetworkProxy::HostNameLookupCapability)), | - | ||||||||||||
| 372 | // it's weird to talk about the proxy capabilities of a "not proxy"... | - | ||||||||||||
| 373 | /* [QNetworkProxy::NoProxy] = */ | - | ||||||||||||
| 374 | (int(QNetworkProxy::ListeningCapability) | | - | ||||||||||||
| 375 | int(QNetworkProxy::TunnelingCapability) | | - | ||||||||||||
| 376 | int(QNetworkProxy::UdpTunnelingCapability)), | - | ||||||||||||
| 377 | /* [QNetworkProxy::HttpProxy] = */ | - | ||||||||||||
| 378 | (int(QNetworkProxy::TunnelingCapability) | | - | ||||||||||||
| 379 | int(QNetworkProxy::CachingCapability) | | - | ||||||||||||
| 380 | int(QNetworkProxy::HostNameLookupCapability)), | - | ||||||||||||
| 381 | /* [QNetworkProxy::HttpCachingProxy] = */ | - | ||||||||||||
| 382 | (int(QNetworkProxy::CachingCapability) | | - | ||||||||||||
| 383 | int(QNetworkProxy::HostNameLookupCapability)), | - | ||||||||||||
| 384 | /* [QNetworkProxy::FtpCachingProxy] = */ | - | ||||||||||||
| 385 | (int(QNetworkProxy::CachingCapability) | | - | ||||||||||||
| 386 | int(QNetworkProxy::HostNameLookupCapability)), | - | ||||||||||||
| 387 | }; | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | if (int(type) < 0 || int(type) > int(QNetworkProxy::FtpCachingProxy))
| 0-14379 | ||||||||||||
| 390 | type = QNetworkProxy::DefaultProxy; never executed: type = QNetworkProxy::DefaultProxy; | 0 | ||||||||||||
| 391 | return QNetworkProxy::Capabilities(defaults[int(type)]); executed 14379 times by 30 tests: return QNetworkProxy::Capabilities(defaults[int(type)]);Executed by:
| 14379 | ||||||||||||
| 392 | } | - | ||||||||||||
| 393 | - | |||||||||||||
| 394 | class QNetworkProxyPrivate: public QSharedData | - | ||||||||||||
| 395 | { | - | ||||||||||||
| 396 | public: | - | ||||||||||||
| 397 | QString hostName; | - | ||||||||||||
| 398 | QString user; | - | ||||||||||||
| 399 | QString password; | - | ||||||||||||
| 400 | QNetworkProxy::Capabilities capabilities; | - | ||||||||||||
| 401 | quint16 port; | - | ||||||||||||
| 402 | QNetworkProxy::ProxyType type; | - | ||||||||||||
| 403 | bool capabilitiesSet; | - | ||||||||||||
| 404 | QNetworkHeadersPrivate headers; | - | ||||||||||||
| 405 | - | |||||||||||||
| 406 | inline QNetworkProxyPrivate(QNetworkProxy::ProxyType t = QNetworkProxy::DefaultProxy, | - | ||||||||||||
| 407 | const QString &h = QString(), quint16 p = 0, | - | ||||||||||||
| 408 | const QString &u = QString(), const QString &pw = QString()) | - | ||||||||||||
| 409 | : hostName(h), | - | ||||||||||||
| 410 | user(u), | - | ||||||||||||
| 411 | password(pw), | - | ||||||||||||
| 412 | capabilities(defaultCapabilitiesForType(t)), | - | ||||||||||||
| 413 | port(p), | - | ||||||||||||
| 414 | type(t), | - | ||||||||||||
| 415 | capabilitiesSet(false) | - | ||||||||||||
| 416 | { } executed 14342 times by 30 tests: end of blockExecuted by:
| 14342 | ||||||||||||
| 417 | - | |||||||||||||
| 418 | inline bool operator==(const QNetworkProxyPrivate &other) const | - | ||||||||||||
| 419 | { | - | ||||||||||||
| 420 | return type == other.type && executed 1 time by 1 test: return type == other.type && port == other.port && hostName == other.hostName && user == other.user && password == other.password && capabilities == other.capabilities;Executed by:
| 0-1 | ||||||||||||
| 421 | port == other.port && executed 1 time by 1 test: return type == other.type && port == other.port && hostName == other.hostName && user == other.user && password == other.password && capabilities == other.capabilities;Executed by:
| 0-1 | ||||||||||||
| 422 | hostName == other.hostName && executed 1 time by 1 test: return type == other.type && port == other.port && hostName == other.hostName && user == other.user && password == other.password && capabilities == other.capabilities;Executed by:
| 0-1 | ||||||||||||
| 423 | user == other.user && executed 1 time by 1 test: return type == other.type && port == other.port && hostName == other.hostName && user == other.user && password == other.password && capabilities == other.capabilities;Executed by:
| 0-1 | ||||||||||||
| 424 | password == other.password && executed 1 time by 1 test: return type == other.type && port == other.port && hostName == other.hostName && user == other.user && password == other.password && capabilities == other.capabilities;Executed by:
| 0-1 | ||||||||||||
| 425 | capabilities == other.capabilities; executed 1 time by 1 test: return type == other.type && port == other.port && hostName == other.hostName && user == other.user && password == other.password && capabilities == other.capabilities;Executed by:
| 0-1 | ||||||||||||
| 426 | } | - | ||||||||||||
| 427 | }; | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | template<> void QSharedDataPointer<QNetworkProxyPrivate>::detach() | - | ||||||||||||
| 430 | { | - | ||||||||||||
| 431 | if (d && d->ref.load() == 1)
| 1-316 | ||||||||||||
| 432 | return; executed 166 times by 8 tests: return;Executed by:
| 166 | ||||||||||||
| 433 | QNetworkProxyPrivate *x = (d ? new QNetworkProxyPrivate(*d)
| 1-150 | ||||||||||||
| 434 | : new QNetworkProxyPrivate); | - | ||||||||||||
| 435 | x->ref.ref(); | - | ||||||||||||
| 436 | if (d && !d->ref.deref())
| 0-150 | ||||||||||||
| 437 | delete d; never executed: delete d; | 0 | ||||||||||||
| 438 | d = x; | - | ||||||||||||
| 439 | } executed 151 times by 7 tests: end of blockExecuted by:
| 151 | ||||||||||||
| 440 | - | |||||||||||||
| 441 | /*! | - | ||||||||||||
| 442 | Constructs a QNetworkProxy with DefaultProxy type; the proxy type is | - | ||||||||||||
| 443 | determined by applicationProxy(), which defaults to NoProxy. | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | \sa setType(), setApplicationProxy() | - | ||||||||||||
| 446 | */ | - | ||||||||||||
| 447 | QNetworkProxy::QNetworkProxy() | - | ||||||||||||
| 448 | : d(0) | - | ||||||||||||
| 449 | { | - | ||||||||||||
| 450 | // make sure we have QGlobalNetworkProxy singleton created, otherwise | - | ||||||||||||
| 451 | // you don't have any socket engine handler created when directly setting | - | ||||||||||||
| 452 | // a proxy to a socket | - | ||||||||||||
| 453 | globalNetworkProxy(); | - | ||||||||||||
| 454 | } executed 36117 times by 38 tests: end of blockExecuted by:
| 36117 | ||||||||||||
| 455 | - | |||||||||||||
| 456 | /*! | - | ||||||||||||
| 457 | Constructs a QNetworkProxy with \a type, \a hostName, \a port, | - | ||||||||||||
| 458 | \a user and \a password. | - | ||||||||||||
| 459 | - | |||||||||||||
| 460 | The default capabilities for proxy type \a type are set automatically. | - | ||||||||||||
| 461 | - | |||||||||||||
| 462 | \sa capabilities() | - | ||||||||||||
| 463 | */ | - | ||||||||||||
| 464 | QNetworkProxy::QNetworkProxy(ProxyType type, const QString &hostName, quint16 port, | - | ||||||||||||
| 465 | const QString &user, const QString &password) | - | ||||||||||||
| 466 | : d(new QNetworkProxyPrivate(type, hostName, port, user, password)) | - | ||||||||||||
| 467 | { | - | ||||||||||||
| 468 | // make sure we have QGlobalNetworkProxy singleton created, otherwise | - | ||||||||||||
| 469 | // you don't have any socket engine handler created when directly setting | - | ||||||||||||
| 470 | // a proxy to a socket | - | ||||||||||||
| 471 | globalNetworkProxy(); | - | ||||||||||||
| 472 | } executed 14341 times by 30 tests: end of blockExecuted by:
| 14341 | ||||||||||||
| 473 | - | |||||||||||||
| 474 | /*! | - | ||||||||||||
| 475 | Constructs a copy of \a other. | - | ||||||||||||
| 476 | */ | - | ||||||||||||
| 477 | QNetworkProxy::QNetworkProxy(const QNetworkProxy &other) | - | ||||||||||||
| 478 | : d(other.d) | - | ||||||||||||
| 479 | { | - | ||||||||||||
| 480 | } executed 24962 times by 30 tests: end of blockExecuted by:
| 24962 | ||||||||||||
| 481 | - | |||||||||||||
| 482 | /*! | - | ||||||||||||
| 483 | Destroys the QNetworkProxy object. | - | ||||||||||||
| 484 | */ | - | ||||||||||||
| 485 | QNetworkProxy::~QNetworkProxy() | - | ||||||||||||
| 486 | { | - | ||||||||||||
| 487 | // QSharedDataPointer takes care of deleting for us | - | ||||||||||||
| 488 | } | - | ||||||||||||
| 489 | - | |||||||||||||
| 490 | /*! | - | ||||||||||||
| 491 | \since 4.4 | - | ||||||||||||
| 492 | - | |||||||||||||
| 493 | Compares the value of this network proxy to \a other and returns \c true | - | ||||||||||||
| 494 | if they are equal (same proxy type, server as well as username and password) | - | ||||||||||||
| 495 | */ | - | ||||||||||||
| 496 | bool QNetworkProxy::operator==(const QNetworkProxy &other) const | - | ||||||||||||
| 497 | { | - | ||||||||||||
| 498 | return d == other.d || (d && other.d && *d == *other.d); executed 79 times by 3 tests: return d == other.d || (d && other.d && *d == *other.d);Executed by:
| 0-79 | ||||||||||||
| 499 | } | - | ||||||||||||
| 500 | - | |||||||||||||
| 501 | /*! | - | ||||||||||||
| 502 | \fn bool QNetworkProxy::operator!=(const QNetworkProxy &other) const | - | ||||||||||||
| 503 | \since 4.4 | - | ||||||||||||
| 504 | - | |||||||||||||
| 505 | Compares the value of this network proxy to \a other and returns \c true | - | ||||||||||||
| 506 | if they differ. | - | ||||||||||||
| 507 | \*/ | - | ||||||||||||
| 508 | - | |||||||||||||
| 509 | /*! | - | ||||||||||||
| 510 | \since 4.2 | - | ||||||||||||
| 511 | - | |||||||||||||
| 512 | Assigns the value of the network proxy \a other to this network proxy. | - | ||||||||||||
| 513 | */ | - | ||||||||||||
| 514 | QNetworkProxy &QNetworkProxy::operator=(const QNetworkProxy &other) | - | ||||||||||||
| 515 | { | - | ||||||||||||
| 516 | d = other.d; | - | ||||||||||||
| 517 | return *this; executed 21883 times by 30 tests: return *this;Executed by:
| 21883 | ||||||||||||
| 518 | } | - | ||||||||||||
| 519 | - | |||||||||||||
| 520 | /*! | - | ||||||||||||
| 521 | \fn void QNetworkProxy::swap(QNetworkProxy &other) | - | ||||||||||||
| 522 | \since 5.0 | - | ||||||||||||
| 523 | - | |||||||||||||
| 524 | Swaps this network proxy instance with \a other. This function is | - | ||||||||||||
| 525 | very fast and never fails. | - | ||||||||||||
| 526 | */ | - | ||||||||||||
| 527 | - | |||||||||||||
| 528 | /*! | - | ||||||||||||
| 529 | Sets the proxy type for this instance to be \a type. | - | ||||||||||||
| 530 | - | |||||||||||||
| 531 | Note that changing the type of a proxy does not change | - | ||||||||||||
| 532 | the set of capabilities this QNetworkProxy object holds if any | - | ||||||||||||
| 533 | capabilities have been set with setCapabilities(). | - | ||||||||||||
| 534 | - | |||||||||||||
| 535 | \sa type(), setCapabilities() | - | ||||||||||||
| 536 | */ | - | ||||||||||||
| 537 | void QNetworkProxy::setType(QNetworkProxy::ProxyType type) | - | ||||||||||||
| 538 | { | - | ||||||||||||
| 539 | d->type = type; | - | ||||||||||||
| 540 | if (!d->capabilitiesSet)
| 1-5 | ||||||||||||
| 541 | d->capabilities = defaultCapabilitiesForType(type); executed 5 times by 1 test: d->capabilities = defaultCapabilitiesForType(type);Executed by:
| 5 | ||||||||||||
| 542 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 543 | - | |||||||||||||
| 544 | /*! | - | ||||||||||||
| 545 | Returns the proxy type for this instance. | - | ||||||||||||
| 546 | - | |||||||||||||
| 547 | \sa setType() | - | ||||||||||||
| 548 | */ | - | ||||||||||||
| 549 | QNetworkProxy::ProxyType QNetworkProxy::type() const | - | ||||||||||||
| 550 | { | - | ||||||||||||
| 551 | return d ? d->type : DefaultProxy; executed 75483 times by 31 tests: return d ? d->type : DefaultProxy;Executed by:
| 9721-75483 | ||||||||||||
| 552 | } | - | ||||||||||||
| 553 | - | |||||||||||||
| 554 | /*! | - | ||||||||||||
| 555 | \since 4.5 | - | ||||||||||||
| 556 | - | |||||||||||||
| 557 | Sets the capabilities of this proxy to \a capabilities. | - | ||||||||||||
| 558 | - | |||||||||||||
| 559 | \sa setType(), capabilities() | - | ||||||||||||
| 560 | */ | - | ||||||||||||
| 561 | void QNetworkProxy::setCapabilities(Capabilities capabilities) | - | ||||||||||||
| 562 | { | - | ||||||||||||
| 563 | d->capabilities = capabilities; | - | ||||||||||||
| 564 | d->capabilitiesSet = true; | - | ||||||||||||
| 565 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 566 | - | |||||||||||||
| 567 | /*! | - | ||||||||||||
| 568 | \since 4.5 | - | ||||||||||||
| 569 | - | |||||||||||||
| 570 | Returns the capabilities of this proxy server. | - | ||||||||||||
| 571 | - | |||||||||||||
| 572 | \sa setCapabilities(), type() | - | ||||||||||||
| 573 | */ | - | ||||||||||||
| 574 | QNetworkProxy::Capabilities QNetworkProxy::capabilities() const | - | ||||||||||||
| 575 | { | - | ||||||||||||
| 576 | return d ? d->capabilities : defaultCapabilitiesForType(DefaultProxy); executed 16857 times by 31 tests: return d ? d->capabilities : defaultCapabilitiesForType(DefaultProxy);Executed by:
| 32-16857 | ||||||||||||
| 577 | } | - | ||||||||||||
| 578 | - | |||||||||||||
| 579 | /*! | - | ||||||||||||
| 580 | \since 4.4 | - | ||||||||||||
| 581 | - | |||||||||||||
| 582 | Returns \c true if this proxy supports the | - | ||||||||||||
| 583 | QNetworkProxy::CachingCapability capability. | - | ||||||||||||
| 584 | - | |||||||||||||
| 585 | In Qt 4.4, the capability was tied to the proxy type, but since Qt | - | ||||||||||||
| 586 | 4.5 it is possible to remove the capability of caching from a | - | ||||||||||||
| 587 | proxy by calling setCapabilities(). | - | ||||||||||||
| 588 | - | |||||||||||||
| 589 | \sa capabilities(), type(), isTransparentProxy() | - | ||||||||||||
| 590 | */ | - | ||||||||||||
| 591 | bool QNetworkProxy::isCachingProxy() const | - | ||||||||||||
| 592 | { | - | ||||||||||||
| 593 | return capabilities() & CachingCapability; never executed: return capabilities() & CachingCapability; | 0 | ||||||||||||
| 594 | } | - | ||||||||||||
| 595 | - | |||||||||||||
| 596 | /*! | - | ||||||||||||
| 597 | \since 4.4 | - | ||||||||||||
| 598 | - | |||||||||||||
| 599 | Returns \c true if this proxy supports transparent tunneling of TCP | - | ||||||||||||
| 600 | connections. This matches the QNetworkProxy::TunnelingCapability | - | ||||||||||||
| 601 | capability. | - | ||||||||||||
| 602 | - | |||||||||||||
| 603 | In Qt 4.4, the capability was tied to the proxy type, but since Qt | - | ||||||||||||
| 604 | 4.5 it is possible to remove the capability of caching from a | - | ||||||||||||
| 605 | proxy by calling setCapabilities(). | - | ||||||||||||
| 606 | - | |||||||||||||
| 607 | \sa capabilities(), type(), isCachingProxy() | - | ||||||||||||
| 608 | */ | - | ||||||||||||
| 609 | bool QNetworkProxy::isTransparentProxy() const | - | ||||||||||||
| 610 | { | - | ||||||||||||
| 611 | return capabilities() & TunnelingCapability; executed 840 times by 8 tests: return capabilities() & TunnelingCapability;Executed by:
| 840 | ||||||||||||
| 612 | } | - | ||||||||||||
| 613 | - | |||||||||||||
| 614 | /*! | - | ||||||||||||
| 615 | Sets the user name for proxy authentication to be \a user. | - | ||||||||||||
| 616 | - | |||||||||||||
| 617 | \sa user(), setPassword(), password() | - | ||||||||||||
| 618 | */ | - | ||||||||||||
| 619 | void QNetworkProxy::setUser(const QString &user) | - | ||||||||||||
| 620 | { | - | ||||||||||||
| 621 | d->user = user; | - | ||||||||||||
| 622 | } executed 199 times by 7 tests: end of blockExecuted by:
| 199 | ||||||||||||
| 623 | - | |||||||||||||
| 624 | /*! | - | ||||||||||||
| 625 | Returns the user name used for authentication. | - | ||||||||||||
| 626 | - | |||||||||||||
| 627 | \sa setUser(), setPassword(), password() | - | ||||||||||||
| 628 | */ | - | ||||||||||||
| 629 | QString QNetworkProxy::user() const | - | ||||||||||||
| 630 | { | - | ||||||||||||
| 631 | return d ? d->user : QString(); executed 2249 times by 16 tests: return d ? d->user : QString();Executed by:
| 0-2249 | ||||||||||||
| 632 | } | - | ||||||||||||
| 633 | - | |||||||||||||
| 634 | /*! | - | ||||||||||||
| 635 | Sets the password for proxy authentication to be \a password. | - | ||||||||||||
| 636 | - | |||||||||||||
| 637 | \sa user(), setUser(), password() | - | ||||||||||||
| 638 | */ | - | ||||||||||||
| 639 | void QNetworkProxy::setPassword(const QString &password) | - | ||||||||||||
| 640 | { | - | ||||||||||||
| 641 | d->password = password; | - | ||||||||||||
| 642 | } executed 85 times by 7 tests: end of blockExecuted by:
| 85 | ||||||||||||
| 643 | - | |||||||||||||
| 644 | /*! | - | ||||||||||||
| 645 | Returns the password used for authentication. | - | ||||||||||||
| 646 | - | |||||||||||||
| 647 | \sa user(), setPassword(), setUser() | - | ||||||||||||
| 648 | */ | - | ||||||||||||
| 649 | QString QNetworkProxy::password() const | - | ||||||||||||
| 650 | { | - | ||||||||||||
| 651 | return d ? d->password : QString(); executed 1243 times by 10 tests: return d ? d->password : QString();Executed by:
| 0-1243 | ||||||||||||
| 652 | } | - | ||||||||||||
| 653 | - | |||||||||||||
| 654 | /*! | - | ||||||||||||
| 655 | Sets the host name of the proxy host to be \a hostName. | - | ||||||||||||
| 656 | - | |||||||||||||
| 657 | \sa hostName(), setPort(), port() | - | ||||||||||||
| 658 | */ | - | ||||||||||||
| 659 | void QNetworkProxy::setHostName(const QString &hostName) | - | ||||||||||||
| 660 | { | - | ||||||||||||
| 661 | d->hostName = hostName; | - | ||||||||||||
| 662 | } never executed: end of block | 0 | ||||||||||||
| 663 | - | |||||||||||||
| 664 | /*! | - | ||||||||||||
| 665 | Returns the host name of the proxy host. | - | ||||||||||||
| 666 | - | |||||||||||||
| 667 | \sa setHostName(), setPort(), port() | - | ||||||||||||
| 668 | */ | - | ||||||||||||
| 669 | QString QNetworkProxy::hostName() const | - | ||||||||||||
| 670 | { | - | ||||||||||||
| 671 | return d ? d->hostName : QString(); executed 1925 times by 11 tests: return d ? d->hostName : QString();Executed by:
| 0-1925 | ||||||||||||
| 672 | } | - | ||||||||||||
| 673 | - | |||||||||||||
| 674 | /*! | - | ||||||||||||
| 675 | Sets the port of the proxy host to be \a port. | - | ||||||||||||
| 676 | - | |||||||||||||
| 677 | \sa hostName(), setHostName(), port() | - | ||||||||||||
| 678 | */ | - | ||||||||||||
| 679 | void QNetworkProxy::setPort(quint16 port) | - | ||||||||||||
| 680 | { | - | ||||||||||||
| 681 | d->port = port; | - | ||||||||||||
| 682 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 683 | - | |||||||||||||
| 684 | /*! | - | ||||||||||||
| 685 | Returns the port of the proxy host. | - | ||||||||||||
| 686 | - | |||||||||||||
| 687 | \sa setHostName(), setPort(), hostName() | - | ||||||||||||
| 688 | */ | - | ||||||||||||
| 689 | quint16 QNetworkProxy::port() const | - | ||||||||||||
| 690 | { | - | ||||||||||||
| 691 | return d ? d->port : 0; executed 1827 times by 12 tests: return d ? d->port : 0;Executed by:
| 0-1827 | ||||||||||||
| 692 | } | - | ||||||||||||
| 693 | - | |||||||||||||
| 694 | /*! | - | ||||||||||||
| 695 | Sets the application level network proxying to be \a networkProxy. | - | ||||||||||||
| 696 | - | |||||||||||||
| 697 | If a QAbstractSocket or QTcpSocket has the | - | ||||||||||||
| 698 | QNetworkProxy::DefaultProxy type, then the QNetworkProxy set with | - | ||||||||||||
| 699 | this function is used. If you want more flexibility in determining | - | ||||||||||||
| 700 | which proxy is used, use the QNetworkProxyFactory class. | - | ||||||||||||
| 701 | - | |||||||||||||
| 702 | Setting a default proxy value with this function will override the | - | ||||||||||||
| 703 | application proxy factory set with | - | ||||||||||||
| 704 | QNetworkProxyFactory::setApplicationProxyFactory. | - | ||||||||||||
| 705 | - | |||||||||||||
| 706 | \sa QNetworkProxyFactory, applicationProxy(), QAbstractSocket::setProxy(), QTcpServer::setProxy() | - | ||||||||||||
| 707 | */ | - | ||||||||||||
| 708 | void QNetworkProxy::setApplicationProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||
| 709 | { | - | ||||||||||||
| 710 | if (globalNetworkProxy()) {
| 0-2888 | ||||||||||||
| 711 | // don't accept setting the proxy to DefaultProxy | - | ||||||||||||
| 712 | if (networkProxy.type() == DefaultProxy)
| 1298-1590 | ||||||||||||
| 713 | globalNetworkProxy()->setApplicationProxy(QNetworkProxy::NoProxy); executed 1590 times by 7 tests: globalNetworkProxy()->setApplicationProxy(QNetworkProxy::NoProxy);Executed by:
| 1590 | ||||||||||||
| 714 | else | - | ||||||||||||
| 715 | globalNetworkProxy()->setApplicationProxy(networkProxy); executed 1298 times by 7 tests: globalNetworkProxy()->setApplicationProxy(networkProxy);Executed by:
| 1298 | ||||||||||||
| 716 | } | - | ||||||||||||
| 717 | } executed 2888 times by 8 tests: end of blockExecuted by:
| 2888 | ||||||||||||
| 718 | - | |||||||||||||
| 719 | /*! | - | ||||||||||||
| 720 | Returns the application level network proxying. | - | ||||||||||||
| 721 | - | |||||||||||||
| 722 | If a QAbstractSocket or QTcpSocket has the | - | ||||||||||||
| 723 | QNetworkProxy::DefaultProxy type, then the QNetworkProxy returned | - | ||||||||||||
| 724 | by this function is used. | - | ||||||||||||
| 725 | - | |||||||||||||
| 726 | \sa QNetworkProxyFactory, setApplicationProxy(), QAbstractSocket::proxy(), QTcpServer::proxy() | - | ||||||||||||
| 727 | */ | - | ||||||||||||
| 728 | QNetworkProxy QNetworkProxy::applicationProxy() | - | ||||||||||||
| 729 | { | - | ||||||||||||
| 730 | if (globalNetworkProxy())
| 0-2575 | ||||||||||||
| 731 | return globalNetworkProxy()->applicationProxy(); executed 2575 times by 19 tests: return globalNetworkProxy()->applicationProxy();Executed by:
| 2575 | ||||||||||||
| 732 | return QNetworkProxy(); never executed: return QNetworkProxy(); | 0 | ||||||||||||
| 733 | } | - | ||||||||||||
| 734 | - | |||||||||||||
| 735 | /*! | - | ||||||||||||
| 736 | \since 5.0 | - | ||||||||||||
| 737 | Returns the value of the known network header \a header if it is | - | ||||||||||||
| 738 | in use for this proxy. If it is not present, returns QVariant() | - | ||||||||||||
| 739 | (i.e., an invalid variant). | - | ||||||||||||
| 740 | - | |||||||||||||
| 741 | \sa QNetworkRequest::KnownHeaders, rawHeader(), setHeader() | - | ||||||||||||
| 742 | */ | - | ||||||||||||
| 743 | QVariant QNetworkProxy::header(QNetworkRequest::KnownHeaders header) const | - | ||||||||||||
| 744 | { | - | ||||||||||||
| 745 | if (d->type != HttpProxy && d->type != HttpCachingProxy)
| 0 | ||||||||||||
| 746 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
| 747 | return d->headers.cookedHeaders.value(header); never executed: return d->headers.cookedHeaders.value(header); | 0 | ||||||||||||
| 748 | } | - | ||||||||||||
| 749 | - | |||||||||||||
| 750 | /*! | - | ||||||||||||
| 751 | \since 5.0 | - | ||||||||||||
| 752 | Sets the value of the known header \a header to be \a value, | - | ||||||||||||
| 753 | overriding any previously set headers. This operation also sets | - | ||||||||||||
| 754 | the equivalent raw HTTP header. | - | ||||||||||||
| 755 | - | |||||||||||||
| 756 | If the proxy is not of type HttpProxy or HttpCachingProxy this has no | - | ||||||||||||
| 757 | effect. | - | ||||||||||||
| 758 | - | |||||||||||||
| 759 | \sa QNetworkRequest::KnownHeaders, setRawHeader(), header() | - | ||||||||||||
| 760 | */ | - | ||||||||||||
| 761 | void QNetworkProxy::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) | - | ||||||||||||
| 762 | { | - | ||||||||||||
| 763 | if (d->type == HttpProxy || d->type == HttpCachingProxy)
| 0 | ||||||||||||
| 764 | d->headers.setCookedHeader(header, value); never executed: d->headers.setCookedHeader(header, value); | 0 | ||||||||||||
| 765 | } never executed: end of block | 0 | ||||||||||||
| 766 | - | |||||||||||||
| 767 | /*! | - | ||||||||||||
| 768 | \since 5.0 | - | ||||||||||||
| 769 | Returns \c true if the raw header \a headerName is in use for this | - | ||||||||||||
| 770 | proxy. Returns \c false if the proxy is not of type HttpProxy or | - | ||||||||||||
| 771 | HttpCachingProxy. | - | ||||||||||||
| 772 | - | |||||||||||||
| 773 | \sa rawHeader(), setRawHeader() | - | ||||||||||||
| 774 | */ | - | ||||||||||||
| 775 | bool QNetworkProxy::hasRawHeader(const QByteArray &headerName) const | - | ||||||||||||
| 776 | { | - | ||||||||||||
| 777 | if (d->type != HttpProxy && d->type != HttpCachingProxy)
| 0-530 | ||||||||||||
| 778 | return false; never executed: return false; | 0 | ||||||||||||
| 779 | return d->headers.findRawHeader(headerName) != d->headers.rawHeaders.constEnd(); executed 530 times by 7 tests: return d->headers.findRawHeader(headerName) != d->headers.rawHeaders.constEnd();Executed by:
| 530 | ||||||||||||
| 780 | } | - | ||||||||||||
| 781 | - | |||||||||||||
| 782 | /*! | - | ||||||||||||
| 783 | \since 5.0 | - | ||||||||||||
| 784 | Returns the raw form of header \a headerName. If no such header is | - | ||||||||||||
| 785 | present or the proxy is not of type HttpProxy or HttpCachingProxy, | - | ||||||||||||
| 786 | an empty QByteArray is returned, which may be indistinguishable | - | ||||||||||||
| 787 | from a header that is present but has no content (use hasRawHeader() | - | ||||||||||||
| 788 | to find out if the header exists or not). | - | ||||||||||||
| 789 | - | |||||||||||||
| 790 | Raw headers can be set with setRawHeader() or with setHeader(). | - | ||||||||||||
| 791 | - | |||||||||||||
| 792 | \sa header(), setRawHeader() | - | ||||||||||||
| 793 | */ | - | ||||||||||||
| 794 | QByteArray QNetworkProxy::rawHeader(const QByteArray &headerName) const | - | ||||||||||||
| 795 | { | - | ||||||||||||
| 796 | if (d->type != HttpProxy && d->type != HttpCachingProxy)
| 0-13 | ||||||||||||
| 797 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
| 798 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it = | - | ||||||||||||
| 799 | d->headers.findRawHeader(headerName); | - | ||||||||||||
| 800 | if (it != d->headers.rawHeaders.constEnd())
| 0-13 | ||||||||||||
| 801 | return it->second; executed 13 times by 1 test: return it->second;Executed by:
| 13 | ||||||||||||
| 802 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
| 803 | } | - | ||||||||||||
| 804 | - | |||||||||||||
| 805 | /*! | - | ||||||||||||
| 806 | \since 5.0 | - | ||||||||||||
| 807 | Returns a list of all raw headers that are set in this network | - | ||||||||||||
| 808 | proxy. The list is in the order that the headers were set. | - | ||||||||||||
| 809 | - | |||||||||||||
| 810 | If the proxy is not of type HttpProxy or HttpCachingProxy an empty | - | ||||||||||||
| 811 | QList is returned. | - | ||||||||||||
| 812 | - | |||||||||||||
| 813 | \sa hasRawHeader(), rawHeader() | - | ||||||||||||
| 814 | */ | - | ||||||||||||
| 815 | QList<QByteArray> QNetworkProxy::rawHeaderList() const | - | ||||||||||||
| 816 | { | - | ||||||||||||
| 817 | if (d->type != HttpProxy && d->type != HttpCachingProxy)
| 0-530 | ||||||||||||
| 818 | return QList<QByteArray>(); never executed: return QList<QByteArray>(); | 0 | ||||||||||||
| 819 | return d->headers.rawHeadersKeys(); executed 530 times by 7 tests: return d->headers.rawHeadersKeys();Executed by:
| 530 | ||||||||||||
| 820 | } | - | ||||||||||||
| 821 | - | |||||||||||||
| 822 | /*! | - | ||||||||||||
| 823 | \since 5.0 | - | ||||||||||||
| 824 | Sets the header \a headerName to be of value \a headerValue. If \a | - | ||||||||||||
| 825 | headerName corresponds to a known header (see | - | ||||||||||||
| 826 | QNetworkRequest::KnownHeaders), the raw format will be parsed and | - | ||||||||||||
| 827 | the corresponding "cooked" header will be set as well. | - | ||||||||||||
| 828 | - | |||||||||||||
| 829 | For example: | - | ||||||||||||
| 830 | \snippet code/src_network_access_qnetworkrequest.cpp 0 | - | ||||||||||||
| 831 | - | |||||||||||||
| 832 | will also set the known header LastModifiedHeader to be the | - | ||||||||||||
| 833 | QDateTime object of the parsed date. | - | ||||||||||||
| 834 | - | |||||||||||||
| 835 | \note Setting the same header twice overrides the previous | - | ||||||||||||
| 836 | setting. To accomplish the behaviour of multiple HTTP headers of | - | ||||||||||||
| 837 | the same name, you should concatenate the two values, separating | - | ||||||||||||
| 838 | them with a comma (",") and set one single raw header. | - | ||||||||||||
| 839 | - | |||||||||||||
| 840 | If the proxy is not of type HttpProxy or HttpCachingProxy this has no | - | ||||||||||||
| 841 | effect. | - | ||||||||||||
| 842 | - | |||||||||||||
| 843 | \sa QNetworkRequest::KnownHeaders, setHeader(), hasRawHeader(), rawHeader() | - | ||||||||||||
| 844 | */ | - | ||||||||||||
| 845 | void QNetworkProxy::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue) | - | ||||||||||||
| 846 | { | - | ||||||||||||
| 847 | if (d->type == HttpProxy || d->type == HttpCachingProxy)
| 0-6 | ||||||||||||
| 848 | d->headers.setRawHeader(headerName, headerValue); executed 6 times by 1 test: d->headers.setRawHeader(headerName, headerValue);Executed by:
| 6 | ||||||||||||
| 849 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 850 | - | |||||||||||||
| 851 | class QNetworkProxyQueryPrivate: public QSharedData | - | ||||||||||||
| 852 | { | - | ||||||||||||
| 853 | public: | - | ||||||||||||
| 854 | inline QNetworkProxyQueryPrivate() | - | ||||||||||||
| 855 | : localPort(-1), type(QNetworkProxyQuery::TcpSocket) | - | ||||||||||||
| 856 | { } executed 7241 times by 29 tests: end of blockExecuted by:
| 7241 | ||||||||||||
| 857 | - | |||||||||||||
| 858 | bool operator==(const QNetworkProxyQueryPrivate &other) const | - | ||||||||||||
| 859 | { | - | ||||||||||||
| 860 | return type == other.type && executed 40 times by 3 tests: return type == other.type && localPort == other.localPort && remote == other.remote;Executed by:
| 0-40 | ||||||||||||
| 861 | localPort == other.localPort && executed 40 times by 3 tests: return type == other.type && localPort == other.localPort && remote == other.remote;Executed by:
| 0-40 | ||||||||||||
| 862 | remote == other.remote; executed 40 times by 3 tests: return type == other.type && localPort == other.localPort && remote == other.remote;Executed by:
| 0-40 | ||||||||||||
| 863 | } | - | ||||||||||||
| 864 | - | |||||||||||||
| 865 | QUrl remote; | - | ||||||||||||
| 866 | int localPort; | - | ||||||||||||
| 867 | QNetworkProxyQuery::QueryType type; | - | ||||||||||||
| 868 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||
| 869 | QNetworkConfiguration config; | - | ||||||||||||
| 870 | #endif | - | ||||||||||||
| 871 | }; | - | ||||||||||||
| 872 | - | |||||||||||||
| 873 | template<> void QSharedDataPointer<QNetworkProxyQueryPrivate>::detach() | - | ||||||||||||
| 874 | { | - | ||||||||||||
| 875 | if (d && d->ref.load() == 1)
| 0-19062 | ||||||||||||
| 876 | return; executed 19062 times by 29 tests: return;Executed by:
| 19062 | ||||||||||||
| 877 | QNetworkProxyQueryPrivate *x = (d ? new QNetworkProxyQueryPrivate(*d)
| 0-7241 | ||||||||||||
| 878 | : new QNetworkProxyQueryPrivate); | - | ||||||||||||
| 879 | x->ref.ref(); | - | ||||||||||||
| 880 | if (d && !d->ref.deref())
| 0-7241 | ||||||||||||
| 881 | delete d; never executed: delete d; | 0 | ||||||||||||
| 882 | d = x; | - | ||||||||||||
| 883 | } executed 7241 times by 29 tests: end of blockExecuted by:
| 7241 | ||||||||||||
| 884 | - | |||||||||||||
| 885 | /*! | - | ||||||||||||
| 886 | \class QNetworkProxyQuery | - | ||||||||||||
| 887 | \since 4.5 | - | ||||||||||||
| 888 | \ingroup shared | - | ||||||||||||
| 889 | \inmodule QtNetwork | - | ||||||||||||
| 890 | \brief The QNetworkProxyQuery class is used to query the proxy | - | ||||||||||||
| 891 | settings for a socket. | - | ||||||||||||
| 892 | - | |||||||||||||
| 893 | QNetworkProxyQuery holds the details of a socket being created or | - | ||||||||||||
| 894 | request being made. It is used by QNetworkProxy and | - | ||||||||||||
| 895 | QNetworkProxyFactory to allow applications to have a more | - | ||||||||||||
| 896 | fine-grained control over which proxy servers are used, depending | - | ||||||||||||
| 897 | on the details of the query. This allows an application to apply | - | ||||||||||||
| 898 | different settings, according to the protocol or destination | - | ||||||||||||
| 899 | hostname, for instance. | - | ||||||||||||
| 900 | - | |||||||||||||
| 901 | QNetworkProxyQuery supports the following criteria for selecting | - | ||||||||||||
| 902 | the proxy: | - | ||||||||||||
| 903 | - | |||||||||||||
| 904 | \list | - | ||||||||||||
| 905 | \li the type of query | - | ||||||||||||
| 906 | \li the local port number to use | - | ||||||||||||
| 907 | \li the destination host name | - | ||||||||||||
| 908 | \li the destination port number | - | ||||||||||||
| 909 | \li the protocol name, such as "http" or "ftp" | - | ||||||||||||
| 910 | \li the URL being requested | - | ||||||||||||
| 911 | \endlist | - | ||||||||||||
| 912 | - | |||||||||||||
| 913 | The destination host name is the host in the connection in the | - | ||||||||||||
| 914 | case of outgoing connection sockets. It is the \c hostName | - | ||||||||||||
| 915 | parameter passed to QTcpSocket::connectToHost() or the host | - | ||||||||||||
| 916 | component of a URL requested with QNetworkRequest. | - | ||||||||||||
| 917 | - | |||||||||||||
| 918 | The destination port number is the requested port to connect to in | - | ||||||||||||
| 919 | the case of outgoing sockets, while the local port number is the | - | ||||||||||||
| 920 | port the socket wishes to use locally before attempting the | - | ||||||||||||
| 921 | external connection. In most cases, the local port number is used | - | ||||||||||||
| 922 | by listening sockets only (QTcpSocket) or by datagram sockets | - | ||||||||||||
| 923 | (QUdpSocket). | - | ||||||||||||
| 924 | - | |||||||||||||
| 925 | The protocol name is an arbitrary string that indicates the type | - | ||||||||||||
| 926 | of connection being attempted. For example, it can match the | - | ||||||||||||
| 927 | scheme of a URL, like "http", "https" and "ftp". In most cases, | - | ||||||||||||
| 928 | the proxy selection will not change depending on the protocol, but | - | ||||||||||||
| 929 | this information is provided in case a better choice can be made, | - | ||||||||||||
| 930 | like choosing an caching HTTP proxy for HTTP-based connections, | - | ||||||||||||
| 931 | but a more powerful SOCKSv5 proxy for all others. | - | ||||||||||||
| 932 | - | |||||||||||||
| 933 | The network configuration specifies which configuration to use, | - | ||||||||||||
| 934 | when bearer management is used. For example on a mobile phone | - | ||||||||||||
| 935 | the proxy settings are likely to be different for the cellular | - | ||||||||||||
| 936 | network vs WLAN. | - | ||||||||||||
| 937 | - | |||||||||||||
| 938 | Some of the criteria may not make sense in all of the types of | - | ||||||||||||
| 939 | query. The following table lists the criteria that are most | - | ||||||||||||
| 940 | commonly used, according to the type of query. | - | ||||||||||||
| 941 | - | |||||||||||||
| 942 | \table | - | ||||||||||||
| 943 | \header | - | ||||||||||||
| 944 | \li Query type | - | ||||||||||||
| 945 | \li Description | - | ||||||||||||
| 946 | - | |||||||||||||
| 947 | \row | - | ||||||||||||
| 948 | \li TcpSocket | - | ||||||||||||
| 949 | \li Normal sockets requesting a connection to a remote server, | - | ||||||||||||
| 950 | like QTcpSocket. The peer hostname and peer port match the | - | ||||||||||||
| 951 | values passed to QTcpSocket::connectToHost(). The local port | - | ||||||||||||
| 952 | is usually -1, indicating the socket has no preference in | - | ||||||||||||
| 953 | which port should be used. The URL component is not used. | - | ||||||||||||
| 954 | - | |||||||||||||
| 955 | \row | - | ||||||||||||
| 956 | \li UdpSocket | - | ||||||||||||
| 957 | \li Datagram-based sockets, which can both send and | - | ||||||||||||
| 958 | receive. The local port, remote host or remote port fields | - | ||||||||||||
| 959 | can all be used or be left unused, depending on the | - | ||||||||||||
| 960 | characteristics of the socket. The URL component is not used. | - | ||||||||||||
| 961 | - | |||||||||||||
| 962 | \row | - | ||||||||||||
| 963 | \li TcpServer | - | ||||||||||||
| 964 | \li Passive server sockets that listen on a port and await | - | ||||||||||||
| 965 | incoming connections from the network. Normally, only the | - | ||||||||||||
| 966 | local port is used, but the remote address could be used in | - | ||||||||||||
| 967 | specific circumstances, for example to indicate which remote | - | ||||||||||||
| 968 | host a connection is expected from. The URL component is not used. | - | ||||||||||||
| 969 | - | |||||||||||||
| 970 | \row | - | ||||||||||||
| 971 | \li UrlRequest | - | ||||||||||||
| 972 | \li A more high-level request, such as those coming from | - | ||||||||||||
| 973 | QNetworkAccessManager. These requests will inevitably use an | - | ||||||||||||
| 974 | outgoing TCP socket, but the this query type is provided to | - | ||||||||||||
| 975 | indicate that more detailed information is present in the URL | - | ||||||||||||
| 976 | component. For ease of implementation, the URL's host and | - | ||||||||||||
| 977 | port are set as the destination address. | - | ||||||||||||
| 978 | \endtable | - | ||||||||||||
| 979 | - | |||||||||||||
| 980 | It should be noted that any of the criteria may be missing or | - | ||||||||||||
| 981 | unknown (an empty QString for the hostname or protocol name, -1 | - | ||||||||||||
| 982 | for the port numbers). If that happens, the functions executing | - | ||||||||||||
| 983 | the query should make their best guess or apply some | - | ||||||||||||
| 984 | implementation-defined default values. | - | ||||||||||||
| 985 | - | |||||||||||||
| 986 | \sa QNetworkProxy, QNetworkProxyFactory, QNetworkAccessManager, | - | ||||||||||||
| 987 | QAbstractSocket::setProxy() | - | ||||||||||||
| 988 | */ | - | ||||||||||||
| 989 | - | |||||||||||||
| 990 | /*! | - | ||||||||||||
| 991 | \enum QNetworkProxyQuery::QueryType | - | ||||||||||||
| 992 | - | |||||||||||||
| 993 | Describes the type of one QNetworkProxyQuery query. | - | ||||||||||||
| 994 | - | |||||||||||||
| 995 | \value TcpSocket a normal, outgoing TCP socket | - | ||||||||||||
| 996 | \value UdpSocket a datagram-based UDP socket, which could send | - | ||||||||||||
| 997 | to multiple destinations | - | ||||||||||||
| 998 | \value TcpServer a TCP server that listens for incoming | - | ||||||||||||
| 999 | connections from the network | - | ||||||||||||
| 1000 | \value UrlRequest a more complex request which involves loading | - | ||||||||||||
| 1001 | of a URL | - | ||||||||||||
| 1002 | - | |||||||||||||
| 1003 | \sa queryType(), setQueryType() | - | ||||||||||||
| 1004 | */ | - | ||||||||||||
| 1005 | - | |||||||||||||
| 1006 | /*! | - | ||||||||||||
| 1007 | Constructs a default QNetworkProxyQuery object. By default, the | - | ||||||||||||
| 1008 | query type will be QNetworkProxyQuery::TcpSocket. | - | ||||||||||||
| 1009 | */ | - | ||||||||||||
| 1010 | QNetworkProxyQuery::QNetworkProxyQuery() | - | ||||||||||||
| 1011 | { | - | ||||||||||||
| 1012 | } | - | ||||||||||||
| 1013 | - | |||||||||||||
| 1014 | /*! | - | ||||||||||||
| 1015 | Constructs a QNetworkProxyQuery with the URL \a requestUrl and | - | ||||||||||||
| 1016 | sets the query type to \a queryType. | - | ||||||||||||
| 1017 | - | |||||||||||||
| 1018 | \sa protocolTag(), peerHostName(), peerPort() | - | ||||||||||||
| 1019 | */ | - | ||||||||||||
| 1020 | QNetworkProxyQuery::QNetworkProxyQuery(const QUrl &requestUrl, QueryType queryType) | - | ||||||||||||
| 1021 | { | - | ||||||||||||
| 1022 | d->remote = requestUrl; | - | ||||||||||||
| 1023 | d->type = queryType; | - | ||||||||||||
| 1024 | } executed 924 times by 8 tests: end of blockExecuted by:
| 924 | ||||||||||||
| 1025 | - | |||||||||||||
| 1026 | /*! | - | ||||||||||||
| 1027 | Constructs a QNetworkProxyQuery of type \a queryType and sets the | - | ||||||||||||
| 1028 | protocol tag to be \a protocolTag. This constructor is suitable | - | ||||||||||||
| 1029 | for QNetworkProxyQuery::TcpSocket queries, because it sets the | - | ||||||||||||
| 1030 | peer hostname to \a hostname and the peer's port number to \a | - | ||||||||||||
| 1031 | port. | - | ||||||||||||
| 1032 | */ | - | ||||||||||||
| 1033 | QNetworkProxyQuery::QNetworkProxyQuery(const QString &hostname, int port, | - | ||||||||||||
| 1034 | const QString &protocolTag, | - | ||||||||||||
| 1035 | QueryType queryType) | - | ||||||||||||
| 1036 | { | - | ||||||||||||
| 1037 | d->remote.setScheme(protocolTag); | - | ||||||||||||
| 1038 | d->remote.setHost(hostname); | - | ||||||||||||
| 1039 | d->remote.setPort(port); | - | ||||||||||||
| 1040 | d->type = queryType; | - | ||||||||||||
| 1041 | } executed 5504 times by 24 tests: end of blockExecuted by:
| 5504 | ||||||||||||
| 1042 | - | |||||||||||||
| 1043 | /*! | - | ||||||||||||
| 1044 | Constructs a QNetworkProxyQuery of type \a queryType and sets the | - | ||||||||||||
| 1045 | protocol tag to be \a protocolTag. This constructor is suitable | - | ||||||||||||
| 1046 | for QNetworkProxyQuery::TcpSocket queries because it sets the | - | ||||||||||||
| 1047 | local port number to \a bindPort. | - | ||||||||||||
| 1048 | - | |||||||||||||
| 1049 | Note that \a bindPort is of type quint16 to indicate the exact | - | ||||||||||||
| 1050 | port number that is requested. The value of -1 (unknown) is not | - | ||||||||||||
| 1051 | allowed in this context. | - | ||||||||||||
| 1052 | - | |||||||||||||
| 1053 | \sa localPort() | - | ||||||||||||
| 1054 | */ | - | ||||||||||||
| 1055 | QNetworkProxyQuery::QNetworkProxyQuery(quint16 bindPort, const QString &protocolTag, | - | ||||||||||||
| 1056 | QueryType queryType) | - | ||||||||||||
| 1057 | { | - | ||||||||||||
| 1058 | d->remote.setScheme(protocolTag); | - | ||||||||||||
| 1059 | d->localPort = bindPort; | - | ||||||||||||
| 1060 | d->type = queryType; | - | ||||||||||||
| 1061 | } executed 688 times by 12 tests: end of blockExecuted by:
| 688 | ||||||||||||
| 1062 | - | |||||||||||||
| 1063 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||
| 1064 | /*! | - | ||||||||||||
| 1065 | Constructs a QNetworkProxyQuery with the URL \a requestUrl and | - | ||||||||||||
| 1066 | sets the query type to \a queryType. The specified \a networkConfiguration | - | ||||||||||||
| 1067 | is used to resolve the proxy settings. | - | ||||||||||||
| 1068 | - | |||||||||||||
| 1069 | \sa protocolTag(), peerHostName(), peerPort(), networkConfiguration() | - | ||||||||||||
| 1070 | */ | - | ||||||||||||
| 1071 | QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration, | - | ||||||||||||
| 1072 | const QUrl &requestUrl, QueryType queryType) | - | ||||||||||||
| 1073 | { | - | ||||||||||||
| 1074 | d->config = networkConfiguration; | - | ||||||||||||
| 1075 | d->remote = requestUrl; | - | ||||||||||||
| 1076 | d->type = queryType; | - | ||||||||||||
| 1077 | } executed 125 times by 3 tests: end of blockExecuted by:
| 125 | ||||||||||||
| 1078 | - | |||||||||||||
| 1079 | /*! | - | ||||||||||||
| 1080 | Constructs a QNetworkProxyQuery of type \a queryType and sets the | - | ||||||||||||
| 1081 | protocol tag to be \a protocolTag. This constructor is suitable | - | ||||||||||||
| 1082 | for QNetworkProxyQuery::TcpSocket queries, because it sets the | - | ||||||||||||
| 1083 | peer hostname to \a hostname and the peer's port number to \a | - | ||||||||||||
| 1084 | port. The specified \a networkConfiguration | - | ||||||||||||
| 1085 | is used to resolve the proxy settings. | - | ||||||||||||
| 1086 | - | |||||||||||||
| 1087 | \sa networkConfiguration() | - | ||||||||||||
| 1088 | */ | - | ||||||||||||
| 1089 | QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration, | - | ||||||||||||
| 1090 | const QString &hostname, int port, | - | ||||||||||||
| 1091 | const QString &protocolTag, | - | ||||||||||||
| 1092 | QueryType queryType) | - | ||||||||||||
| 1093 | { | - | ||||||||||||
| 1094 | d->config = networkConfiguration; | - | ||||||||||||
| 1095 | d->remote.setScheme(protocolTag); | - | ||||||||||||
| 1096 | d->remote.setHost(hostname); | - | ||||||||||||
| 1097 | d->remote.setPort(port); | - | ||||||||||||
| 1098 | d->type = queryType; | - | ||||||||||||
| 1099 | } never executed: end of block | 0 | ||||||||||||
| 1100 | - | |||||||||||||
| 1101 | /*! | - | ||||||||||||
| 1102 | Constructs a QNetworkProxyQuery of type \a queryType and sets the | - | ||||||||||||
| 1103 | protocol tag to be \a protocolTag. This constructor is suitable | - | ||||||||||||
| 1104 | for QNetworkProxyQuery::TcpSocket queries because it sets the | - | ||||||||||||
| 1105 | local port number to \a bindPort. The specified \a networkConfiguration | - | ||||||||||||
| 1106 | is used to resolve the proxy settings. | - | ||||||||||||
| 1107 | - | |||||||||||||
| 1108 | Note that \a bindPort is of type quint16 to indicate the exact | - | ||||||||||||
| 1109 | port number that is requested. The value of -1 (unknown) is not | - | ||||||||||||
| 1110 | allowed in this context. | - | ||||||||||||
| 1111 | - | |||||||||||||
| 1112 | \sa localPort(), networkConfiguration() | - | ||||||||||||
| 1113 | */ | - | ||||||||||||
| 1114 | QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration, | - | ||||||||||||
| 1115 | quint16 bindPort, const QString &protocolTag, | - | ||||||||||||
| 1116 | QueryType queryType) | - | ||||||||||||
| 1117 | { | - | ||||||||||||
| 1118 | d->config = networkConfiguration; | - | ||||||||||||
| 1119 | d->remote.setScheme(protocolTag); | - | ||||||||||||
| 1120 | d->localPort = bindPort; | - | ||||||||||||
| 1121 | d->type = queryType; | - | ||||||||||||
| 1122 | } never executed: end of block | 0 | ||||||||||||
| 1123 | #endif | - | ||||||||||||
| 1124 | - | |||||||||||||
| 1125 | /*! | - | ||||||||||||
| 1126 | Constructs a QNetworkProxyQuery object that is a copy of \a other. | - | ||||||||||||
| 1127 | */ | - | ||||||||||||
| 1128 | QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkProxyQuery &other) | - | ||||||||||||
| 1129 | : d(other.d) | - | ||||||||||||
| 1130 | { | - | ||||||||||||
| 1131 | } never executed: end of block | 0 | ||||||||||||
| 1132 | - | |||||||||||||
| 1133 | /*! | - | ||||||||||||
| 1134 | Destroys this QNetworkProxyQuery object. | - | ||||||||||||
| 1135 | */ | - | ||||||||||||
| 1136 | QNetworkProxyQuery::~QNetworkProxyQuery() | - | ||||||||||||
| 1137 | { | - | ||||||||||||
| 1138 | // QSharedDataPointer automatically deletes | - | ||||||||||||
| 1139 | } | - | ||||||||||||
| 1140 | - | |||||||||||||
| 1141 | /*! | - | ||||||||||||
| 1142 | Copies the contents of \a other. | - | ||||||||||||
| 1143 | */ | - | ||||||||||||
| 1144 | QNetworkProxyQuery &QNetworkProxyQuery::operator=(const QNetworkProxyQuery &other) | - | ||||||||||||
| 1145 | { | - | ||||||||||||
| 1146 | d = other.d; | - | ||||||||||||
| 1147 | return *this; executed 42 times by 4 tests: return *this;Executed by:
| 42 | ||||||||||||
| 1148 | } | - | ||||||||||||
| 1149 | - | |||||||||||||
| 1150 | /*! | - | ||||||||||||
| 1151 | \fn void QNetworkProxyQuery::swap(QNetworkProxyQuery &other) | - | ||||||||||||
| 1152 | \since 5.0 | - | ||||||||||||
| 1153 | - | |||||||||||||
| 1154 | Swaps this network proxy query instance with \a other. This | - | ||||||||||||
| 1155 | function is very fast and never fails. | - | ||||||||||||
| 1156 | */ | - | ||||||||||||
| 1157 | - | |||||||||||||
| 1158 | /*! | - | ||||||||||||
| 1159 | Returns \c true if this QNetworkProxyQuery object contains the same | - | ||||||||||||
| 1160 | data as \a other. | - | ||||||||||||
| 1161 | */ | - | ||||||||||||
| 1162 | bool QNetworkProxyQuery::operator==(const QNetworkProxyQuery &other) const | - | ||||||||||||
| 1163 | { | - | ||||||||||||
| 1164 | return d == other.d || (d && other.d && *d == *other.d); executed 40 times by 3 tests: return d == other.d || (d && other.d && *d == *other.d);Executed by:
| 0-40 | ||||||||||||
| 1165 | } | - | ||||||||||||
| 1166 | - | |||||||||||||
| 1167 | /*! | - | ||||||||||||
| 1168 | \fn bool QNetworkProxyQuery::operator!=(const QNetworkProxyQuery &other) const | - | ||||||||||||
| 1169 | - | |||||||||||||
| 1170 | Returns \c true if this QNetworkProxyQuery object does not contain | - | ||||||||||||
| 1171 | the same data as \a other. | - | ||||||||||||
| 1172 | */ | - | ||||||||||||
| 1173 | - | |||||||||||||
| 1174 | /*! | - | ||||||||||||
| 1175 | Returns the query type. | - | ||||||||||||
| 1176 | */ | - | ||||||||||||
| 1177 | QNetworkProxyQuery::QueryType QNetworkProxyQuery::queryType() const | - | ||||||||||||
| 1178 | { | - | ||||||||||||
| 1179 | return d ? d->type : TcpSocket; executed 2 times by 1 test: return d ? d->type : TcpSocket;Executed by:
| 0-2 | ||||||||||||
| 1180 | } | - | ||||||||||||
| 1181 | - | |||||||||||||
| 1182 | /*! | - | ||||||||||||
| 1183 | Sets the query type of this object to be \a type. | - | ||||||||||||
| 1184 | */ | - | ||||||||||||
| 1185 | void QNetworkProxyQuery::setQueryType(QueryType type) | - | ||||||||||||
| 1186 | { | - | ||||||||||||
| 1187 | d->type = type; | - | ||||||||||||
| 1188 | } never executed: end of block | 0 | ||||||||||||
| 1189 | - | |||||||||||||
| 1190 | /*! | - | ||||||||||||
| 1191 | Returns the port number for the outgoing request or -1 if the port | - | ||||||||||||
| 1192 | number is not known. | - | ||||||||||||
| 1193 | - | |||||||||||||
| 1194 | If the query type is QNetworkProxyQuery::UrlRequest, this function | - | ||||||||||||
| 1195 | returns the port number of the URL being requested. In general, | - | ||||||||||||
| 1196 | frameworks will fill in the port number from their default values. | - | ||||||||||||
| 1197 | - | |||||||||||||
| 1198 | \sa peerHostName(), localPort(), setPeerPort() | - | ||||||||||||
| 1199 | */ | - | ||||||||||||
| 1200 | int QNetworkProxyQuery::peerPort() const | - | ||||||||||||
| 1201 | { | - | ||||||||||||
| 1202 | return d ? d->remote.port() : -1; never executed: return d ? d->remote.port() : -1;
| 0 | ||||||||||||
| 1203 | } | - | ||||||||||||
| 1204 | - | |||||||||||||
| 1205 | /*! | - | ||||||||||||
| 1206 | Sets the requested port number for the outgoing connection to be | - | ||||||||||||
| 1207 | \a port. Valid values are 1 to 65535, or -1 to indicate that the | - | ||||||||||||
| 1208 | remote port number is unknown. | - | ||||||||||||
| 1209 | - | |||||||||||||
| 1210 | The peer port number can also be used to indicate the expected | - | ||||||||||||
| 1211 | port number of an incoming connection in the case of | - | ||||||||||||
| 1212 | QNetworkProxyQuery::UdpSocket or QNetworkProxyQuery::TcpServer | - | ||||||||||||
| 1213 | query types. | - | ||||||||||||
| 1214 | - | |||||||||||||
| 1215 | \sa peerPort(), setPeerHostName(), setLocalPort() | - | ||||||||||||
| 1216 | */ | - | ||||||||||||
| 1217 | void QNetworkProxyQuery::setPeerPort(int port) | - | ||||||||||||
| 1218 | { | - | ||||||||||||
| 1219 | d->remote.setPort(port); | - | ||||||||||||
| 1220 | } never executed: end of block | 0 | ||||||||||||
| 1221 | - | |||||||||||||
| 1222 | /*! | - | ||||||||||||
| 1223 | Returns the host name or IP address being of the outgoing | - | ||||||||||||
| 1224 | connection being requested, or an empty string if the remote | - | ||||||||||||
| 1225 | hostname is not known. | - | ||||||||||||
| 1226 | - | |||||||||||||
| 1227 | If the query type is QNetworkProxyQuery::UrlRequest, this function | - | ||||||||||||
| 1228 | returns the host component of the URL being requested. | - | ||||||||||||
| 1229 | - | |||||||||||||
| 1230 | \sa peerPort(), localPort(), setPeerHostName() | - | ||||||||||||
| 1231 | */ | - | ||||||||||||
| 1232 | QString QNetworkProxyQuery::peerHostName() const | - | ||||||||||||
| 1233 | { | - | ||||||||||||
| 1234 | return d ? d->remote.host() : QString(); never executed: return d ? d->remote.host() : QString();
| 0 | ||||||||||||
| 1235 | } | - | ||||||||||||
| 1236 | - | |||||||||||||
| 1237 | /*! | - | ||||||||||||
| 1238 | Sets the hostname of the outgoing connection being requested to \a | - | ||||||||||||
| 1239 | hostname. An empty hostname can be used to indicate that the | - | ||||||||||||
| 1240 | remote host is unknown. | - | ||||||||||||
| 1241 | - | |||||||||||||
| 1242 | The peer host name can also be used to indicate the expected | - | ||||||||||||
| 1243 | source address of an incoming connection in the case of | - | ||||||||||||
| 1244 | QNetworkProxyQuery::UdpSocket or QNetworkProxyQuery::TcpServer | - | ||||||||||||
| 1245 | query types. | - | ||||||||||||
| 1246 | - | |||||||||||||
| 1247 | \sa peerHostName(), setPeerPort(), setLocalPort() | - | ||||||||||||
| 1248 | */ | - | ||||||||||||
| 1249 | void QNetworkProxyQuery::setPeerHostName(const QString &hostname) | - | ||||||||||||
| 1250 | { | - | ||||||||||||
| 1251 | d->remote.setHost(hostname); | - | ||||||||||||
| 1252 | } never executed: end of block | 0 | ||||||||||||
| 1253 | - | |||||||||||||
| 1254 | /*! | - | ||||||||||||
| 1255 | Returns the port number of the socket that will accept incoming | - | ||||||||||||
| 1256 | packets from remote servers or -1 if the port is not known. | - | ||||||||||||
| 1257 | - | |||||||||||||
| 1258 | \sa peerPort(), peerHostName(), setLocalPort() | - | ||||||||||||
| 1259 | */ | - | ||||||||||||
| 1260 | int QNetworkProxyQuery::localPort() const | - | ||||||||||||
| 1261 | { | - | ||||||||||||
| 1262 | return d ? d->localPort : -1; never executed: return d ? d->localPort : -1;
| 0 | ||||||||||||
| 1263 | } | - | ||||||||||||
| 1264 | - | |||||||||||||
| 1265 | /*! | - | ||||||||||||
| 1266 | Sets the port number that the socket wishes to use locally to | - | ||||||||||||
| 1267 | accept incoming packets from remote servers to \a port. The local | - | ||||||||||||
| 1268 | port is most often used with the QNetworkProxyQuery::TcpServer | - | ||||||||||||
| 1269 | and QNetworkProxyQuery::UdpSocket query types. | - | ||||||||||||
| 1270 | - | |||||||||||||
| 1271 | Valid values are 0 to 65535 (with 0 indicating that any port | - | ||||||||||||
| 1272 | number will be acceptable) or -1, which means the local port | - | ||||||||||||
| 1273 | number is unknown or not applicable. | - | ||||||||||||
| 1274 | - | |||||||||||||
| 1275 | In some circumstances, for special protocols, it's the local port | - | ||||||||||||
| 1276 | number can also be used with a query of type | - | ||||||||||||
| 1277 | QNetworkProxyQuery::TcpSocket. When that happens, the socket is | - | ||||||||||||
| 1278 | indicating it wishes to use the port number \a port when | - | ||||||||||||
| 1279 | connecting to a remote host. | - | ||||||||||||
| 1280 | - | |||||||||||||
| 1281 | \sa localPort(), setPeerPort(), setPeerHostName() | - | ||||||||||||
| 1282 | */ | - | ||||||||||||
| 1283 | void QNetworkProxyQuery::setLocalPort(int port) | - | ||||||||||||
| 1284 | { | - | ||||||||||||
| 1285 | d->localPort = port; | - | ||||||||||||
| 1286 | } never executed: end of block | 0 | ||||||||||||
| 1287 | - | |||||||||||||
| 1288 | /*! | - | ||||||||||||
| 1289 | Returns the protocol tag for this QNetworkProxyQuery object, or an | - | ||||||||||||
| 1290 | empty QString in case the protocol tag is unknown. | - | ||||||||||||
| 1291 | - | |||||||||||||
| 1292 | In the case of queries of type QNetworkProxyQuery::UrlRequest, | - | ||||||||||||
| 1293 | this function returns the value of the scheme component of the | - | ||||||||||||
| 1294 | URL. | - | ||||||||||||
| 1295 | - | |||||||||||||
| 1296 | \sa setProtocolTag(), url() | - | ||||||||||||
| 1297 | */ | - | ||||||||||||
| 1298 | QString QNetworkProxyQuery::protocolTag() const | - | ||||||||||||
| 1299 | { | - | ||||||||||||
| 1300 | return d ? d->remote.scheme() : QString(); executed 39 times by 1 test: return d ? d->remote.scheme() : QString();Executed by:
| 3-39 | ||||||||||||
| 1301 | } | - | ||||||||||||
| 1302 | - | |||||||||||||
| 1303 | /*! | - | ||||||||||||
| 1304 | Sets the protocol tag for this QNetworkProxyQuery object to be \a | - | ||||||||||||
| 1305 | protocolTag. | - | ||||||||||||
| 1306 | - | |||||||||||||
| 1307 | The protocol tag is an arbitrary string that indicates which | - | ||||||||||||
| 1308 | protocol is being talked over the socket, such as "http", "xmpp", | - | ||||||||||||
| 1309 | "telnet", etc. The protocol tag is used by the backend to | - | ||||||||||||
| 1310 | return a request that is more specific to the protocol in | - | ||||||||||||
| 1311 | question: for example, a HTTP connection could be use a caching | - | ||||||||||||
| 1312 | HTTP proxy server, while all other connections use a more powerful | - | ||||||||||||
| 1313 | SOCKSv5 proxy server. | - | ||||||||||||
| 1314 | - | |||||||||||||
| 1315 | \sa protocolTag() | - | ||||||||||||
| 1316 | */ | - | ||||||||||||
| 1317 | void QNetworkProxyQuery::setProtocolTag(const QString &protocolTag) | - | ||||||||||||
| 1318 | { | - | ||||||||||||
| 1319 | d->remote.setScheme(protocolTag); | - | ||||||||||||
| 1320 | } never executed: end of block | 0 | ||||||||||||
| 1321 | - | |||||||||||||
| 1322 | /*! | - | ||||||||||||
| 1323 | Returns the URL component of this QNetworkProxyQuery object in | - | ||||||||||||
| 1324 | case of a query of type QNetworkProxyQuery::UrlRequest. | - | ||||||||||||
| 1325 | - | |||||||||||||
| 1326 | \sa setUrl() | - | ||||||||||||
| 1327 | */ | - | ||||||||||||
| 1328 | QUrl QNetworkProxyQuery::url() const | - | ||||||||||||
| 1329 | { | - | ||||||||||||
| 1330 | return d ? d->remote : QUrl(); executed 9568 times by 29 tests: return d ? d->remote : QUrl();Executed by:
| 2575-9568 | ||||||||||||
| 1331 | } | - | ||||||||||||
| 1332 | - | |||||||||||||
| 1333 | /*! | - | ||||||||||||
| 1334 | Sets the URL component of this QNetworkProxyQuery object to be \a | - | ||||||||||||
| 1335 | url. Setting the URL will also set the protocol tag, the remote | - | ||||||||||||
| 1336 | host name and port number. This is done so as to facilitate the | - | ||||||||||||
| 1337 | implementation of the code that determines the proxy server to be | - | ||||||||||||
| 1338 | used. | - | ||||||||||||
| 1339 | - | |||||||||||||
| 1340 | \sa url(), peerHostName(), peerPort() | - | ||||||||||||
| 1341 | */ | - | ||||||||||||
| 1342 | void QNetworkProxyQuery::setUrl(const QUrl &url) | - | ||||||||||||
| 1343 | { | - | ||||||||||||
| 1344 | d->remote = url; | - | ||||||||||||
| 1345 | } never executed: end of block | 0 | ||||||||||||
| 1346 | - | |||||||||||||
| 1347 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||
| 1348 | /*! | - | ||||||||||||
| 1349 | Returns the network configuration component of the query. | - | ||||||||||||
| 1350 | - | |||||||||||||
| 1351 | \sa setNetworkConfiguration() | - | ||||||||||||
| 1352 | */ | - | ||||||||||||
| 1353 | QNetworkConfiguration QNetworkProxyQuery::networkConfiguration() const | - | ||||||||||||
| 1354 | { | - | ||||||||||||
| 1355 | return d ? d->config : QNetworkConfiguration(); never executed: return d ? d->config : QNetworkConfiguration();
| 0 | ||||||||||||
| 1356 | } | - | ||||||||||||
| 1357 | - | |||||||||||||
| 1358 | /*! | - | ||||||||||||
| 1359 | Sets the network configuration component of this QNetworkProxyQuery | - | ||||||||||||
| 1360 | object to be \a networkConfiguration. The network configuration can | - | ||||||||||||
| 1361 | be used to return different proxy settings based on the network in | - | ||||||||||||
| 1362 | use, for example WLAN vs cellular networks on a mobile phone. | - | ||||||||||||
| 1363 | - | |||||||||||||
| 1364 | In the case of "user choice" or "service network" configurations, | - | ||||||||||||
| 1365 | you should first start the QNetworkSession and obtain the active | - | ||||||||||||
| 1366 | configuration from its properties. | - | ||||||||||||
| 1367 | - | |||||||||||||
| 1368 | \sa networkConfiguration() | - | ||||||||||||
| 1369 | */ | - | ||||||||||||
| 1370 | void QNetworkProxyQuery::setNetworkConfiguration(const QNetworkConfiguration &networkConfiguration) | - | ||||||||||||
| 1371 | { | - | ||||||||||||
| 1372 | d->config = networkConfiguration; | - | ||||||||||||
| 1373 | } never executed: end of block | 0 | ||||||||||||
| 1374 | #endif | - | ||||||||||||
| 1375 | - | |||||||||||||
| 1376 | /*! | - | ||||||||||||
| 1377 | \class QNetworkProxyFactory | - | ||||||||||||
| 1378 | \brief The QNetworkProxyFactory class provides fine-grained proxy selection. | - | ||||||||||||
| 1379 | \since 4.5 | - | ||||||||||||
| 1380 | - | |||||||||||||
| 1381 | \ingroup network | - | ||||||||||||
| 1382 | \inmodule QtNetwork | - | ||||||||||||
| 1383 | - | |||||||||||||
| 1384 | QNetworkProxyFactory is an extension to QNetworkProxy, allowing | - | ||||||||||||
| 1385 | applications to have a more fine-grained control over which proxy | - | ||||||||||||
| 1386 | servers are used, depending on the socket requesting the | - | ||||||||||||
| 1387 | proxy. This allows an application to apply different settings, | - | ||||||||||||
| 1388 | according to the protocol or destination hostname, for instance. | - | ||||||||||||
| 1389 | - | |||||||||||||
| 1390 | QNetworkProxyFactory can be set globally for an application, in | - | ||||||||||||
| 1391 | which case it will override any global proxies set with | - | ||||||||||||
| 1392 | QNetworkProxy::setApplicationProxy(). If set globally, any sockets | - | ||||||||||||
| 1393 | created with Qt will query the factory to determine the proxy to | - | ||||||||||||
| 1394 | be used. | - | ||||||||||||
| 1395 | - | |||||||||||||
| 1396 | A factory can also be set in certain frameworks that support | - | ||||||||||||
| 1397 | multiple connections, such as QNetworkAccessManager. When set on | - | ||||||||||||
| 1398 | such object, the factory will be queried for sockets created by | - | ||||||||||||
| 1399 | that framework only. | - | ||||||||||||
| 1400 | - | |||||||||||||
| 1401 | \section1 System Proxies | - | ||||||||||||
| 1402 | - | |||||||||||||
| 1403 | You can configure a factory to use the system proxy's settings. | - | ||||||||||||
| 1404 | Call the setUseSystemConfiguration() function with true to enable | - | ||||||||||||
| 1405 | this behavior, or false to disable it. | - | ||||||||||||
| 1406 | - | |||||||||||||
| 1407 | Similarly, you can use a factory to make queries directly to the | - | ||||||||||||
| 1408 | system proxy by calling its systemProxyForQuery() function. | - | ||||||||||||
| 1409 | - | |||||||||||||
| 1410 | \warning Depending on the configuration of the user's system, the | - | ||||||||||||
| 1411 | use of system proxy features on certain platforms may be subject | - | ||||||||||||
| 1412 | to limitations. The systemProxyForQuery() documentation contains a | - | ||||||||||||
| 1413 | list of these limitations for those platforms that are affected. | - | ||||||||||||
| 1414 | */ | - | ||||||||||||
| 1415 | - | |||||||||||||
| 1416 | /*! | - | ||||||||||||
| 1417 | Creates a QNetworkProxyFactory object. | - | ||||||||||||
| 1418 | - | |||||||||||||
| 1419 | Since QNetworkProxyFactory is an abstract class, you cannot create | - | ||||||||||||
| 1420 | objects of type QNetworkProxyFactory directly. | - | ||||||||||||
| 1421 | */ | - | ||||||||||||
| 1422 | QNetworkProxyFactory::QNetworkProxyFactory() | - | ||||||||||||
| 1423 | { | - | ||||||||||||
| 1424 | } | - | ||||||||||||
| 1425 | - | |||||||||||||
| 1426 | /*! | - | ||||||||||||
| 1427 | Destroys the QNetworkProxyFactory object. | - | ||||||||||||
| 1428 | */ | - | ||||||||||||
| 1429 | QNetworkProxyFactory::~QNetworkProxyFactory() | - | ||||||||||||
| 1430 | { | - | ||||||||||||
| 1431 | } | - | ||||||||||||
| 1432 | - | |||||||||||||
| 1433 | - | |||||||||||||
| 1434 | /*! | - | ||||||||||||
| 1435 | \since 4.6 | - | ||||||||||||
| 1436 | - | |||||||||||||
| 1437 | Enables the use of the platform-specific proxy settings, and only those. | - | ||||||||||||
| 1438 | See systemProxyForQuery() for more information. | - | ||||||||||||
| 1439 | - | |||||||||||||
| 1440 | Internally, this method (when called with \a enable set to true) | - | ||||||||||||
| 1441 | sets an application-wide proxy factory. For this reason, this method | - | ||||||||||||
| 1442 | is mutually exclusive with setApplicationProxyFactory(): calling | - | ||||||||||||
| 1443 | setApplicationProxyFactory() overrides the use of the system-wide proxy, | - | ||||||||||||
| 1444 | and calling setUseSystemConfiguration() overrides any | - | ||||||||||||
| 1445 | application proxy or proxy factory that was previously set. | - | ||||||||||||
| 1446 | - | |||||||||||||
| 1447 | \note See the systemProxyForQuery() documentation for a list of | - | ||||||||||||
| 1448 | limitations related to the use of system proxies. | - | ||||||||||||
| 1449 | */ | - | ||||||||||||
| 1450 | void QNetworkProxyFactory::setUseSystemConfiguration(bool enable) | - | ||||||||||||
| 1451 | { | - | ||||||||||||
| 1452 | if (enable) {
| 0 | ||||||||||||
| 1453 | setApplicationProxyFactory(new QSystemConfigurationProxyFactory); | - | ||||||||||||
| 1454 | } else { never executed: end of block | 0 | ||||||||||||
| 1455 | setApplicationProxyFactory(0); | - | ||||||||||||
| 1456 | } never executed: end of block | 0 | ||||||||||||
| 1457 | } | - | ||||||||||||
| 1458 | - | |||||||||||||
| 1459 | /*! | - | ||||||||||||
| 1460 | Sets the application-wide proxy factory to be \a factory. This | - | ||||||||||||
| 1461 | function will take ownership of that object and will delete it | - | ||||||||||||
| 1462 | when necessary. | - | ||||||||||||
| 1463 | - | |||||||||||||
| 1464 | The application-wide proxy is used as a last-resort when all other | - | ||||||||||||
| 1465 | proxy selection requests returned QNetworkProxy::DefaultProxy. For | - | ||||||||||||
| 1466 | example, QTcpSocket objects can have a proxy set with | - | ||||||||||||
| 1467 | QTcpSocket::setProxy, but if none is set, the proxy factory class | - | ||||||||||||
| 1468 | set with this function will be queried. | - | ||||||||||||
| 1469 | - | |||||||||||||
| 1470 | If you set a proxy factory with this function, any application | - | ||||||||||||
| 1471 | level proxies set with QNetworkProxy::setApplicationProxy will be | - | ||||||||||||
| 1472 | overridden. | - | ||||||||||||
| 1473 | - | |||||||||||||
| 1474 | \sa QNetworkProxy::setApplicationProxy(), | - | ||||||||||||
| 1475 | QAbstractSocket::proxy(), QAbstractSocket::setProxy() | - | ||||||||||||
| 1476 | */ | - | ||||||||||||
| 1477 | void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *factory) | - | ||||||||||||
| 1478 | { | - | ||||||||||||
| 1479 | if (globalNetworkProxy())
| 0-22 | ||||||||||||
| 1480 | globalNetworkProxy()->setApplicationProxyFactory(factory); executed 22 times by 3 tests: globalNetworkProxy()->setApplicationProxyFactory(factory);Executed by:
| 22 | ||||||||||||
| 1481 | } executed 22 times by 3 tests: end of blockExecuted by:
| 22 | ||||||||||||
| 1482 | - | |||||||||||||
| 1483 | /*! | - | ||||||||||||
| 1484 | \fn QList<QNetworkProxy> QNetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query) | - | ||||||||||||
| 1485 | - | |||||||||||||
| 1486 | This function takes the query request, \a query, | - | ||||||||||||
| 1487 | examines the details of the type of socket or request and returns | - | ||||||||||||
| 1488 | a list of QNetworkProxy objects that indicate the proxy servers to | - | ||||||||||||
| 1489 | be used, in order of preference. | - | ||||||||||||
| 1490 | - | |||||||||||||
| 1491 | When reimplementing this class, take care to return at least one | - | ||||||||||||
| 1492 | element. | - | ||||||||||||
| 1493 | - | |||||||||||||
| 1494 | If you cannot determine a better proxy alternative, use | - | ||||||||||||
| 1495 | QNetworkProxy::DefaultProxy, which tells the code querying for a | - | ||||||||||||
| 1496 | proxy to use a higher alternative. For example, if this factory is | - | ||||||||||||
| 1497 | set to a QNetworkAccessManager object, DefaultProxy will tell it | - | ||||||||||||
| 1498 | to query the application-level proxy settings. | - | ||||||||||||
| 1499 | - | |||||||||||||
| 1500 | If this factory is set as the application proxy factory, | - | ||||||||||||
| 1501 | DefaultProxy and NoProxy will have the same meaning. | - | ||||||||||||
| 1502 | */ | - | ||||||||||||
| 1503 | - | |||||||||||||
| 1504 | /*! | - | ||||||||||||
| 1505 | \fn QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) | - | ||||||||||||
| 1506 | - | |||||||||||||
| 1507 | This function takes the query request, \a query, | - | ||||||||||||
| 1508 | examines the details of the type of socket or request and returns | - | ||||||||||||
| 1509 | a list of QNetworkProxy objects that indicate the proxy servers to | - | ||||||||||||
| 1510 | be used, in order of preference. | - | ||||||||||||
| 1511 | - | |||||||||||||
| 1512 | This function can be used to determine the platform-specific proxy | - | ||||||||||||
| 1513 | settings. This function will use the libraries provided by the | - | ||||||||||||
| 1514 | operating system to determine the proxy for a given connection, if | - | ||||||||||||
| 1515 | such libraries exist. If they don't, this function will just return a | - | ||||||||||||
| 1516 | QNetworkProxy of type QNetworkProxy::NoProxy. | - | ||||||||||||
| 1517 | - | |||||||||||||
| 1518 | On Windows, this function will use the WinHTTP DLL functions. Despite | - | ||||||||||||
| 1519 | its name, Microsoft suggests using it for all applications that | - | ||||||||||||
| 1520 | require network connections, not just HTTP. This will respect the | - | ||||||||||||
| 1521 | proxy settings set on the registry with the proxycfg.exe tool. If | - | ||||||||||||
| 1522 | those settings are not found, this function will attempt to obtain | - | ||||||||||||
| 1523 | Internet Explorer's settings and use them. | - | ||||||||||||
| 1524 | - | |||||||||||||
| 1525 | On \macos, this function will obtain the proxy settings using the | - | ||||||||||||
| 1526 | SystemConfiguration framework from Apple. It will apply the FTP, | - | ||||||||||||
| 1527 | HTTP and HTTPS proxy configurations for queries that contain the | - | ||||||||||||
| 1528 | protocol tag "ftp", "http" and "https", respectively. If the SOCKS | - | ||||||||||||
| 1529 | proxy is enabled in that configuration, this function will use the | - | ||||||||||||
| 1530 | SOCKS server for all queries. If SOCKS isn't enabled, it will use | - | ||||||||||||
| 1531 | the HTTPS proxy for all TcpSocket and UrlRequest queries. | - | ||||||||||||
| 1532 | - | |||||||||||||
| 1533 | On BlackBerry, this function obtains proxy settings for the default | - | ||||||||||||
| 1534 | configuration using system configuration. The type will be set based on | - | ||||||||||||
| 1535 | protocol tag "http", "https", "ftp", respectively. By default, it | - | ||||||||||||
| 1536 | assumes http type. Proxy username and password are also set during | - | ||||||||||||
| 1537 | the query using system configuration. | - | ||||||||||||
| 1538 | - | |||||||||||||
| 1539 | On other systems, this function will pick up proxy settings from | - | ||||||||||||
| 1540 | the "http_proxy" environment variable. This variable must be a URL | - | ||||||||||||
| 1541 | using one of the following schemes: "http", "socks5" or "socks5h". | - | ||||||||||||
| 1542 | - | |||||||||||||
| 1543 | \section1 Limitations | - | ||||||||||||
| 1544 | - | |||||||||||||
| 1545 | These are the limitations for the current version of this | - | ||||||||||||
| 1546 | function. Future versions of Qt may lift some of the limitations | - | ||||||||||||
| 1547 | listed here. | - | ||||||||||||
| 1548 | - | |||||||||||||
| 1549 | \list | - | ||||||||||||
| 1550 | \li On \macos, this function will ignore the Proxy Auto Configuration | - | ||||||||||||
| 1551 | settings, since it cannot execute the associated ECMAScript code. | - | ||||||||||||
| 1552 | - | |||||||||||||
| 1553 | \li On Windows platforms, this function may take several seconds to | - | ||||||||||||
| 1554 | execute depending on the configuration of the user's system. | - | ||||||||||||
| 1555 | - | |||||||||||||
| 1556 | \li On BlackBerry, only UrlRequest and TcpSocket queries are supported. SOCKS is | - | ||||||||||||
| 1557 | not supported. The proxy credentials are only retrieved for the | - | ||||||||||||
| 1558 | default configuration. | - | ||||||||||||
| 1559 | \endlist | - | ||||||||||||
| 1560 | */ | - | ||||||||||||
| 1561 | - | |||||||||||||
| 1562 | /*! | - | ||||||||||||
| 1563 | This function takes the query request, \a query, | - | ||||||||||||
| 1564 | examines the details of the type of socket or request and returns | - | ||||||||||||
| 1565 | a list of QNetworkProxy objects that indicate the proxy servers to | - | ||||||||||||
| 1566 | be used, in order of preference. | - | ||||||||||||
| 1567 | */ | - | ||||||||||||
| 1568 | QList<QNetworkProxy> QNetworkProxyFactory::proxyForQuery(const QNetworkProxyQuery &query) | - | ||||||||||||
| 1569 | { | - | ||||||||||||
| 1570 | if (!globalNetworkProxy())
| 0-6993 | ||||||||||||
| 1571 | return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); never executed: return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); | 0 | ||||||||||||
| 1572 | return globalNetworkProxy()->proxyForQuery(query); executed 6993 times by 29 tests: return globalNetworkProxy()->proxyForQuery(query);Executed by:
| 6993 | ||||||||||||
| 1573 | } | - | ||||||||||||
| 1574 | - | |||||||||||||
| 1575 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||
| 1576 | /*! | - | ||||||||||||
| 1577 | \since 5.0 | - | ||||||||||||
| 1578 | Outputs a QNetworkProxy details to a debug stream | - | ||||||||||||
| 1579 | */ | - | ||||||||||||
| 1580 | QDebug operator<<(QDebug debug, const QNetworkProxy &proxy) | - | ||||||||||||
| 1581 | { | - | ||||||||||||
| 1582 | QDebugStateSaver saver(debug); | - | ||||||||||||
| 1583 | debug.resetFormat().nospace(); | - | ||||||||||||
| 1584 | QNetworkProxy::ProxyType type = proxy.type(); | - | ||||||||||||
| 1585 | switch (type) { | - | ||||||||||||
| 1586 | case QNetworkProxy::NoProxy: executed 23 times by 1 test: case QNetworkProxy::NoProxy:Executed by:
| 23 | ||||||||||||
| 1587 | debug << "NoProxy "; | - | ||||||||||||
| 1588 | break; executed 23 times by 1 test: break;Executed by:
| 23 | ||||||||||||
| 1589 | case QNetworkProxy::DefaultProxy: never executed: case QNetworkProxy::DefaultProxy: | 0 | ||||||||||||
| 1590 | debug << "DefaultProxy "; | - | ||||||||||||
| 1591 | break; never executed: break; | 0 | ||||||||||||
| 1592 | case QNetworkProxy::Socks5Proxy: never executed: case QNetworkProxy::Socks5Proxy: | 0 | ||||||||||||
| 1593 | debug << "Socks5Proxy "; | - | ||||||||||||
| 1594 | break; never executed: break; | 0 | ||||||||||||
| 1595 | case QNetworkProxy::HttpProxy: never executed: case QNetworkProxy::HttpProxy: | 0 | ||||||||||||
| 1596 | debug << "HttpProxy "; | - | ||||||||||||
| 1597 | break; never executed: break; | 0 | ||||||||||||
| 1598 | case QNetworkProxy::HttpCachingProxy: never executed: case QNetworkProxy::HttpCachingProxy: | 0 | ||||||||||||
| 1599 | debug << "HttpCachingProxy "; | - | ||||||||||||
| 1600 | break; never executed: break; | 0 | ||||||||||||
| 1601 | case QNetworkProxy::FtpCachingProxy: never executed: case QNetworkProxy::FtpCachingProxy: | 0 | ||||||||||||
| 1602 | debug << "FtpCachingProxy "; | - | ||||||||||||
| 1603 | break; never executed: break; | 0 | ||||||||||||
| 1604 | default: never executed: default: | 0 | ||||||||||||
| 1605 | debug << "Unknown proxy " << int(type); | - | ||||||||||||
| 1606 | break; never executed: break; | 0 | ||||||||||||
| 1607 | } | - | ||||||||||||
| 1608 | debug << '"' << proxy.hostName() << ':' << proxy.port() << "\" "; | - | ||||||||||||
| 1609 | QNetworkProxy::Capabilities caps = proxy.capabilities(); | - | ||||||||||||
| 1610 | QStringList scaps; | - | ||||||||||||
| 1611 | if (caps & QNetworkProxy::TunnelingCapability)
| 0-23 | ||||||||||||
| 1612 | scaps << QStringLiteral("Tunnel"); executed 23 times by 1 test: scaps << ([]() -> QString { enum { Size = sizeof(u"" "Tunnel")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Tunnel" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 23 times by 1 test: return qstring_literal_temp;Executed by:
| 23 | ||||||||||||
| 1613 | if (caps & QNetworkProxy::ListeningCapability)
| 0-23 | ||||||||||||
| 1614 | scaps << QStringLiteral("Listen"); executed 23 times by 1 test: scaps << ([]() -> QString { enum { Size = sizeof(u"" "Listen")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Listen" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 23 times by 1 test: return qstring_literal_temp;Executed by:
| 23 | ||||||||||||
| 1615 | if (caps & QNetworkProxy::UdpTunnelingCapability)
| 0-23 | ||||||||||||
| 1616 | scaps << QStringLiteral("UDP"); executed 23 times by 1 test: scaps << ([]() -> QString { enum { Size = sizeof(u"" "UDP")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "UDP" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 23 times by 1 test: return qstring_literal_temp;Executed by:
| 23 | ||||||||||||
| 1617 | if (caps & QNetworkProxy::CachingCapability)
| 0-23 | ||||||||||||
| 1618 | scaps << QStringLiteral("Caching"); never executed: scaps << ([]() -> QString { enum { Size = sizeof(u"" "Caching")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Caching" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||
| 1619 | if (caps & QNetworkProxy::HostNameLookupCapability)
| 0-23 | ||||||||||||
| 1620 | scaps << QStringLiteral("NameLookup"); never executed: scaps << ([]() -> QString { enum { Size = sizeof(u"" "NameLookup")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "NameLookup" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||
| 1621 | debug << '[' << scaps.join(QLatin1Char(' ')) << ']'; | - | ||||||||||||
| 1622 | return debug; executed 23 times by 1 test: return debug;Executed by:
| 23 | ||||||||||||
| 1623 | } | - | ||||||||||||
| 1624 | #endif | - | ||||||||||||
| 1625 | - | |||||||||||||
| 1626 | QT_END_NAMESPACE | - | ||||||||||||
| 1627 | - | |||||||||||||
| 1628 | #endif // QT_NO_NETWORKPROXY | - | ||||||||||||
| Source code | Switch to Preprocessed file |