OpenCoverage

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) 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-
52QT_BEGIN_NAMESPACE-
53-
54static bool ignoreProxyFor(const QNetworkProxyQuery &query)-
55{-
56 const QByteArray noProxy = qgetenv("no_proxy").trimmed();-
57 if (noProxy.isEmpty())
noProxy.isEmpty()Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-39
58 return false;
executed 39 times by 1 test: return false;
Executed by:
  • tst_QNetworkProxyFactory
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('*'))
token.startsWith('*')Description
TRUEnever evaluated
FALSEnever evaluated
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('.'))
token.endsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
!peerHostName.endsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
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('.'))
!token.startsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
0
77 token.prepend('.');
never executed: token.prepend('.');
0
78-
79 if (!peerHostName.startsWith('.'))
!peerHostName.startsWith('.')Description
TRUEnever evaluated
FALSEnever evaluated
0
80 peerHostName.prepend('.');
never executed: peerHostName.prepend('.');
0
81-
82 if (peerHostName.endsWith(QString::fromLatin1(token)))
peerHostName.e...Latin1(token))Description
TRUEnever evaluated
FALSEnever evaluated
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-
89QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query)-
90{-
91 QList<QNetworkProxy> proxyList;-
92-
93 if (ignoreProxyFor(query))
ignoreProxyFor(query)Description
TRUEnever evaluated
FALSEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
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"))
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
101 proxy_env = qgetenv("http_proxy");
executed 18 times by 1 test: proxy_env = qgetenv("http_proxy");
Executed by:
  • tst_QNetworkProxyFactory
18
102 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
103 proxy_env = qgetenv("https_proxy");
executed 2 times by 1 test: proxy_env = qgetenv("https_proxy");
Executed by:
  • tst_QNetworkProxyFactory
2
104 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
105 proxy_env = qgetenv("ftp_proxy");
executed 3 times by 1 test: proxy_env = qgetenv("ftp_proxy");
Executed by:
  • tst_QNetworkProxyFactory
3
106 else-
107 proxy_env = qgetenv("all_proxy");
executed 16 times by 1 test: proxy_env = qgetenv("all_proxy");
Executed by:
  • tst_QNetworkProxyFactory
16
108-
109 // Fallback to http_proxy is no protocol specific proxy was found-
110 if (proxy_env.isEmpty())
proxy_env.isEmpty()Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-39
111 proxy_env = qgetenv("http_proxy");
executed 39 times by 1 test: proxy_env = qgetenv("http_proxy");
Executed by:
  • tst_QNetworkProxyFactory
39
112-
113 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
114 QUrl url = QUrl(QString::fromLocal8Bit(proxy_env));-
115 const QString scheme = url.scheme();-
116 if (scheme == QLatin1String("socks5")) {
scheme == QLat...ring("socks5")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
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:
  • tst_QNetworkProxyFactory
scheme == QLat...ing("socks5h")Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
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
scheme.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
scheme == QLat...String("http")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-1
126 && query.queryType() != QNetworkProxyQuery::UdpSocket
query.queryTyp...ery::UdpSocketDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
0-1
127 && query.queryType() != QNetworkProxyQuery::TcpServer) {
query.queryTyp...ery::TcpServerDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkProxyFactory
FALSEnever evaluated
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:
  • tst_QNetworkProxyFactory
1
132 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QNetworkProxyFactory
2
133 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
134 proxyList << QNetworkProxy::NoProxy;
executed 37 times by 1 test: proxyList << QNetworkProxy::NoProxy;
Executed by:
  • tst_QNetworkProxyFactory
37
135-
136 return proxyList;
executed 39 times by 1 test: return proxyList;
Executed by:
  • tst_QNetworkProxyFactory
39
137}-
138-
139QT_END_NAMESPACE-
140-
141#endif-
Source codeSwitch to Preprocessed file

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