| 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) 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 | - | |||||||||||||
| 46 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | static bool ignoreProxyFor(const QNetworkProxyQuery &query) | - | ||||||||||||
| 49 | { | - | ||||||||||||
| 50 | const QByteArray noProxy = qgetenv("no_proxy").trimmed(); | - | ||||||||||||
| 51 | if (noProxy.isEmpty())
| 0-39 | ||||||||||||
| 52 | return false; executed 39 times by 1 test: return false;Executed by:
| 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('*'))
| 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('.'))
| 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('.'))
| 0 | ||||||||||||
| 71 | token.prepend('.'); never executed: token.prepend('.'); | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | if (!peerHostName.startsWith('.'))
| 0 | ||||||||||||
| 74 | peerHostName.prepend('.'); never executed: peerHostName.prepend('.'); | 0 | ||||||||||||
| 75 | - | |||||||||||||
| 76 | if (peerHostName.endsWith(QString::fromLatin1(token)))
| 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 | - | |||||||||||||
| 83 | QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) | - | ||||||||||||
| 84 | { | - | ||||||||||||
| 85 | QList<QNetworkProxy> proxyList; | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | if (ignoreProxyFor(query))
| 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"))
| 18-21 | ||||||||||||
| 95 | proxy_env = qgetenv("http_proxy"); executed 18 times by 1 test: proxy_env = qgetenv("http_proxy");Executed by:
| 18 | ||||||||||||
| 96 | else if (queryProtocol == QLatin1String("https"))
| 2-19 | ||||||||||||
| 97 | proxy_env = qgetenv("https_proxy"); executed 2 times by 1 test: proxy_env = qgetenv("https_proxy");Executed by:
| 2 | ||||||||||||
| 98 | else if (queryProtocol == QLatin1String("ftp"))
| 3-16 | ||||||||||||
| 99 | proxy_env = qgetenv("ftp_proxy"); executed 3 times by 1 test: proxy_env = qgetenv("ftp_proxy");Executed by:
| 3 | ||||||||||||
| 100 | else | - | ||||||||||||
| 101 | proxy_env = qgetenv("all_proxy"); executed 16 times by 1 test: proxy_env = qgetenv("all_proxy");Executed by:
| 16 | ||||||||||||
| 102 | - | |||||||||||||
| 103 | // Fallback to http_proxy is no protocol specific proxy was found | - | ||||||||||||
| 104 | if (proxy_env.isEmpty())
| 0-39 | ||||||||||||
| 105 | proxy_env = qgetenv("http_proxy"); executed 39 times by 1 test: proxy_env = qgetenv("http_proxy");Executed by:
| 39 | ||||||||||||
| 106 | - | |||||||||||||
| 107 | if (!proxy_env.isEmpty()) {
| 2-37 | ||||||||||||
| 108 | QUrl url = QUrl(QString::fromLocal8Bit(proxy_env)); | - | ||||||||||||
| 109 | if (url.scheme() == QLatin1String("socks5")) {
| 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 blockExecuted by:
| 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
| 0-1 | ||||||||||||
| 119 | && query.queryType() != QNetworkProxyQuery::UdpSocket
| 0-1 | ||||||||||||
| 120 | && query.queryType() != QNetworkProxyQuery::TcpServer) {
| 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 blockExecuted by:
| 1 | ||||||||||||
| 125 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 126 | if (proxyList.isEmpty())
| 2-37 | ||||||||||||
| 127 | proxyList << QNetworkProxy::NoProxy; executed 37 times by 1 test: proxyList << QNetworkProxy::NoProxy;Executed by:
| 37 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | return proxyList; executed 39 times by 1 test: return proxyList;Executed by:
| 39 | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | QT_END_NAMESPACE | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | #endif | - | ||||||||||||
| Source code | Switch to Preprocessed file |