qnetworkproxy_generic.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qnetworkproxy_generic.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qnetworkproxy.h"-
35-
36#include <QtCore/QByteArray>-
37#include <QtCore/QUrl>-
38-
39#ifndef QT_NO_NETWORKPROXY-
40-
41/*-
42 * Construct a proxy from the environment variables http_proxy and no_proxy.-
43 * Or no system proxy. Just return a list with NoProxy.-
44 */-
45-
46QT_BEGIN_NAMESPACE-
47-
48static bool ignoreProxyFor(const QNetworkProxyQuery &query)-
49{-
50 const QByteArray noProxy = qgetenv("no_proxy").trimmed();-
51 if (noProxy.isEmpty())
noProxy.isEmpty()Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-39
52 return false;
executed 39 times by 1 test: return false;
Executed by:
  • tst_QNetworkProxyFactory
39
53-
54 const QList<QByteArray> noProxyTokens = noProxy.split(',');-
55-
56 foreach (const QByteArray &rawToken, noProxyTokens) {-
57 QByteArray token = rawToken.trimmed();-
58 QString peerHostName = query.peerHostName();-
59-
60 // Since we use suffix matching, "*" is our 'default' behaviour-
61 if (token.startsWith('*'))
token.startsWith('*')Description
TRUEnever evaluated
FALSEnever evaluated
0
62 token = token.mid(1);
never executed: token = token.mid(1);
0
63-
64 // Harmonize trailing dot notation-
65 if (token.endsWith('.') && !peerHostName.endsWith('.'))
token.endsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
!peerHostName.endsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
0
66 token = token.left(token.length()-1);
never executed: token = token.left(token.length()-1);
0
67-
68 // We prepend a dot to both values, so that when we do a suffix match,-
69 // we don't match "donotmatch.com" with "match.com"-
70 if (!token.startsWith('.'))
!token.startsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
0
71 token.prepend('.');
never executed: token.prepend('.');
0
72-
73 if (!peerHostName.startsWith('.'))
!peerHostName.startsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
0
74 peerHostName.prepend('.');
never executed: peerHostName.prepend('.');
0
75-
76 if (peerHostName.endsWith(QString::fromLatin1(token)))
peerHostName.e...Latin1(token))Description
TRUEnever evaluated
FALSEnever evaluated
0
77 return true;
never executed: return true;
0
78 }
never executed: end of block
0
79-
80 return false;
never executed: return false;
0
81}-
82-
83QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query)-
84{-
85 QList<QNetworkProxy> proxyList;-
86-
87 if (ignoreProxyFor(query))
ignoreProxyFor(query)Description
TRUEnever evaluated
FALSEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
0-39
88 return proxyList << QNetworkProxy::NoProxy;
never executed: return proxyList << QNetworkProxy::NoProxy;
0
89-
90 // No need to care about casing here, QUrl lowercases values already-
91 const QString queryProtocol = query.protocolTag();-
92 QByteArray proxy_env;-
93-
94 if (queryProtocol == QLatin1String("http"))
queryProtocol ...String("http")Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 21 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
18-21
95 proxy_env = qgetenv("http_proxy");
executed 18 times by 1 test: proxy_env = qgetenv("http_proxy");
Executed by:
  • tst_QNetworkProxyFactory
18
96 else if (queryProtocol == QLatin1String("https"))
queryProtocol ...tring("https")Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
2-19
97 proxy_env = qgetenv("https_proxy");
executed 2 times by 1 test: proxy_env = qgetenv("https_proxy");
Executed by:
  • tst_QNetworkProxyFactory
2
98 else if (queryProtocol == QLatin1String("ftp"))
queryProtocol ...1String("ftp")Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
3-16
99 proxy_env = qgetenv("ftp_proxy");
executed 3 times by 1 test: proxy_env = qgetenv("ftp_proxy");
Executed by:
  • tst_QNetworkProxyFactory
3
100 else-
101 proxy_env = qgetenv("all_proxy");
executed 16 times by 1 test: proxy_env = qgetenv("all_proxy");
Executed by:
  • tst_QNetworkProxyFactory
16
102-
103 // Fallback to http_proxy is no protocol specific proxy was found-
104 if (proxy_env.isEmpty())
proxy_env.isEmpty()Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-39
105 proxy_env = qgetenv("http_proxy");
executed 39 times by 1 test: proxy_env = qgetenv("http_proxy");
Executed by:
  • tst_QNetworkProxyFactory
39
106-
107 if (!proxy_env.isEmpty()) {
!proxy_env.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 37 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
2-37
108 QUrl url = QUrl(QString::fromLocal8Bit(proxy_env));-
109 if (url.scheme() == QLatin1String("socks5")) {
url.scheme() =...ring("socks5")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
1
110 QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(),-
111 url.port() ? url.port() : 1080, url.userName(), url.password());-
112 proxyList << proxy;-
113 } else if (url.scheme() == QLatin1String("socks5h")) {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkProxyFactory
url.scheme() =...ing("socks5h")Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
0-1
114 QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(),-
115 url.port() ? url.port() : 1080, url.userName(), url.password());-
116 proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability);-
117 proxyList << proxy;-
118 } else if ((url.scheme() == QLatin1String("http") || url.scheme().isEmpty())
never executed: end of block
url.scheme() =...String("http")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
url.scheme().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0-1
119 && query.queryType() != QNetworkProxyQuery::UdpSocket
query.queryTyp...ery::UdpSocketDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-1
120 && query.queryType() != QNetworkProxyQuery::TcpServer) {
query.queryTyp...ery::TcpServerDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-1
121 QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(),-
122 url.port() ? url.port() : 8080, url.userName(), url.password());-
123 proxyList << proxy;-
124 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkProxyFactory
1
125 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QNetworkProxyFactory
2
126 if (proxyList.isEmpty())
proxyList.isEmpty()Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
2-37
127 proxyList << QNetworkProxy::NoProxy;
executed 37 times by 1 test: proxyList << QNetworkProxy::NoProxy;
Executed by:
  • tst_QNetworkProxyFactory
37
128-
129 return proxyList;
executed 39 times by 1 test: return proxyList;
Executed by:
  • tst_QNetworkProxyFactory
39
130}-
131-
132QT_END_NAMESPACE-
133-
134#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9