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