Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qnetworkproxy_generic.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 | #include "qnetworkproxy.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <QtCore/QByteArray> | - | ||||||||||||
43 | #include <QtCore/QUrl> | - | ||||||||||||
44 | - | |||||||||||||
45 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||
46 | - | |||||||||||||
47 | /* | - | ||||||||||||
48 | * Construct a proxy from the environment variables http_proxy and no_proxy. | - | ||||||||||||
49 | * Or no system proxy. Just return a list with NoProxy. | - | ||||||||||||
50 | */ | - | ||||||||||||
51 | - | |||||||||||||
52 | QT_BEGIN_NAMESPACE | - | ||||||||||||
53 | - | |||||||||||||
54 | static bool ignoreProxyFor(const QNetworkProxyQuery &query) | - | ||||||||||||
55 | { | - | ||||||||||||
56 | const QByteArray noProxy = qgetenv("no_proxy").trimmed(); | - | ||||||||||||
57 | if (noProxy.isEmpty())
| 0-39 | ||||||||||||
58 | return false; executed 39 times by 1 test: return false; Executed by:
| 39 | ||||||||||||
59 | - | |||||||||||||
60 | const QList<QByteArray> noProxyTokens = noProxy.split(','); | - | ||||||||||||
61 | - | |||||||||||||
62 | for (const QByteArray &rawToken : noProxyTokens) { | - | ||||||||||||
63 | QByteArray token = rawToken.trimmed(); | - | ||||||||||||
64 | QString peerHostName = query.peerHostName(); | - | ||||||||||||
65 | - | |||||||||||||
66 | // Since we use suffix matching, "*" is our 'default' behaviour | - | ||||||||||||
67 | if (token.startsWith('*'))
| 0 | ||||||||||||
68 | token = token.mid(1); never executed: token = token.mid(1); | 0 | ||||||||||||
69 | - | |||||||||||||
70 | // Harmonize trailing dot notation | - | ||||||||||||
71 | if (token.endsWith('.') && !peerHostName.endsWith('.'))
| 0 | ||||||||||||
72 | token = token.left(token.length()-1); never executed: token = token.left(token.length()-1); | 0 | ||||||||||||
73 | - | |||||||||||||
74 | // We prepend a dot to both values, so that when we do a suffix match, | - | ||||||||||||
75 | // we don't match "donotmatch.com" with "match.com" | - | ||||||||||||
76 | if (!token.startsWith('.'))
| 0 | ||||||||||||
77 | token.prepend('.'); never executed: token.prepend('.'); | 0 | ||||||||||||
78 | - | |||||||||||||
79 | if (!peerHostName.startsWith('.'))
| 0 | ||||||||||||
80 | peerHostName.prepend('.'); never executed: peerHostName.prepend('.'); | 0 | ||||||||||||
81 | - | |||||||||||||
82 | if (peerHostName.endsWith(QString::fromLatin1(token)))
| 0 | ||||||||||||
83 | return true; never executed: return true; | 0 | ||||||||||||
84 | } never executed: end of block | 0 | ||||||||||||
85 | - | |||||||||||||
86 | return false; never executed: return false; | 0 | ||||||||||||
87 | } | - | ||||||||||||
88 | - | |||||||||||||
89 | QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) | - | ||||||||||||
90 | { | - | ||||||||||||
91 | QList<QNetworkProxy> proxyList; | - | ||||||||||||
92 | - | |||||||||||||
93 | if (ignoreProxyFor(query))
| 0-39 | ||||||||||||
94 | return proxyList << QNetworkProxy::NoProxy; never executed: return proxyList << QNetworkProxy::NoProxy; | 0 | ||||||||||||
95 | - | |||||||||||||
96 | // No need to care about casing here, QUrl lowercases values already | - | ||||||||||||
97 | const QString queryProtocol = query.protocolTag(); | - | ||||||||||||
98 | QByteArray proxy_env; | - | ||||||||||||
99 | - | |||||||||||||
100 | if (queryProtocol == QLatin1String("http"))
| 18-21 | ||||||||||||
101 | proxy_env = qgetenv("http_proxy"); executed 18 times by 1 test: proxy_env = qgetenv("http_proxy"); Executed by:
| 18 | ||||||||||||
102 | else if (queryProtocol == QLatin1String("https"))
| 2-19 | ||||||||||||
103 | proxy_env = qgetenv("https_proxy"); executed 2 times by 1 test: proxy_env = qgetenv("https_proxy"); Executed by:
| 2 | ||||||||||||
104 | else if (queryProtocol == QLatin1String("ftp"))
| 3-16 | ||||||||||||
105 | proxy_env = qgetenv("ftp_proxy"); executed 3 times by 1 test: proxy_env = qgetenv("ftp_proxy"); Executed by:
| 3 | ||||||||||||
106 | else | - | ||||||||||||
107 | proxy_env = qgetenv("all_proxy"); executed 16 times by 1 test: proxy_env = qgetenv("all_proxy"); Executed by:
| 16 | ||||||||||||
108 | - | |||||||||||||
109 | // Fallback to http_proxy is no protocol specific proxy was found | - | ||||||||||||
110 | if (proxy_env.isEmpty())
| 0-39 | ||||||||||||
111 | proxy_env = qgetenv("http_proxy"); executed 39 times by 1 test: proxy_env = qgetenv("http_proxy"); Executed by:
| 39 | ||||||||||||
112 | - | |||||||||||||
113 | if (!proxy_env.isEmpty()) {
| 2-37 | ||||||||||||
114 | QUrl url = QUrl(QString::fromLocal8Bit(proxy_env)); | - | ||||||||||||
115 | const QString scheme = url.scheme(); | - | ||||||||||||
116 | if (scheme == QLatin1String("socks5")) {
| 1 | ||||||||||||
117 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(), | - | ||||||||||||
118 | url.port() ? url.port() : 1080, url.userName(), url.password()); | - | ||||||||||||
119 | proxyList << proxy; | - | ||||||||||||
120 | } else if (scheme == QLatin1String("socks5h")) { executed 1 time by 1 test: end of block Executed by:
| 0-1 | ||||||||||||
121 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(), | - | ||||||||||||
122 | url.port() ? url.port() : 1080, url.userName(), url.password()); | - | ||||||||||||
123 | proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability); | - | ||||||||||||
124 | proxyList << proxy; | - | ||||||||||||
125 | } else if ((scheme.isEmpty() || scheme == QLatin1String("http")) never executed: end of block
| 0-1 | ||||||||||||
126 | && query.queryType() != QNetworkProxyQuery::UdpSocket
| 0-1 | ||||||||||||
127 | && query.queryType() != QNetworkProxyQuery::TcpServer) {
| 0-1 | ||||||||||||
128 | QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(), | - | ||||||||||||
129 | url.port() ? url.port() : 8080, url.userName(), url.password()); | - | ||||||||||||
130 | proxyList << proxy; | - | ||||||||||||
131 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
132 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
133 | if (proxyList.isEmpty())
| 2-37 | ||||||||||||
134 | proxyList << QNetworkProxy::NoProxy; executed 37 times by 1 test: proxyList << QNetworkProxy::NoProxy; Executed by:
| 37 | ||||||||||||
135 | - | |||||||||||||
136 | return proxyList; executed 39 times by 1 test: return proxyList; Executed by:
| 39 | ||||||||||||
137 | } | - | ||||||||||||
138 | - | |||||||||||||
139 | QT_END_NAMESPACE | - | ||||||||||||
140 | - | |||||||||||||
141 | #endif | - | ||||||||||||
Source code | Switch to Preprocessed file |