| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 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 Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qnetworkproxy.h" | - |
| 43 | | - |
| 44 | #include <QtCore/QByteArray> | - |
| 45 | #include <QtCore/QUrl> | - |
| 46 | | - |
| 47 | #ifndef QT_NO_NETWORKPROXY | - |
| 48 | | - |
| 49 | /* | - |
| 50 | * Construct a proxy from the environment variables http_proxy and no_proxy. | - |
| 51 | * Or no system proxy. Just return a list with NoProxy. | - |
| 52 | */ | - |
| 53 | | - |
| 54 | QT_BEGIN_NAMESPACE | - |
| 55 | | - |
| 56 | static bool ignoreProxyFor(const QNetworkProxyQuery &query) | - |
| 57 | { | - |
| 58 | const QList<QByteArray> noProxyTokens = qgetenv("no_proxy").split(','); executed (the execution status of this line is deduced): const QList<QByteArray> noProxyTokens = qgetenv("no_proxy").split(','); | - |
| 59 | | - |
| 60 | foreach (const QByteArray &rawToken, noProxyTokens) { executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(noProxyTokens)> _container_(noProxyTokens); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QByteArray &rawToken = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 61 | QByteArray token = rawToken.trimmed(); executed (the execution status of this line is deduced): QByteArray token = rawToken.trimmed(); | - |
| 62 | QString peerHostName = query.peerHostName(); executed (the execution status of this line is deduced): QString peerHostName = query.peerHostName(); | - |
| 63 | | - |
| 64 | // Since we use suffix matching, "*" is our 'default' behaviour | - |
| 65 | if (token.startsWith("*")) partially evaluated: token.startsWith("*")| no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
| 66 | token = token.mid(1); never executed: token = token.mid(1); | 0 |
| 67 | | - |
| 68 | // Harmonize trailing dot notation | - |
| 69 | if (token.endsWith('.') && !peerHostName.endsWith('.')) partially evaluated: token.endsWith('.')| no Evaluation Count:0 | yes Evaluation Count:41 |
never evaluated: !peerHostName.endsWith('.') | 0-41 |
| 70 | token = token.left(token.length()-1); never executed: token = token.left(token.length()-1); | 0 |
| 71 | | - |
| 72 | // We prepend a dot to both values, so that when we do a suffix match, | - |
| 73 | // we don't match "donotmatch.com" with "match.com" | - |
| 74 | if (!token.startsWith('.')) partially evaluated: !token.startsWith('.')| yes Evaluation Count:41 | no Evaluation Count:0 |
| 0-41 |
| 75 | token.prepend('.'); executed: token.prepend('.');Execution Count:41 | 41 |
| 76 | | - |
| 77 | if (!peerHostName.startsWith('.')) partially evaluated: !peerHostName.startsWith('.')| yes Evaluation Count:41 | no Evaluation Count:0 |
| 0-41 |
| 78 | peerHostName.prepend('.'); executed: peerHostName.prepend('.');Execution Count:41 | 41 |
| 79 | | - |
| 80 | if (peerHostName.endsWith(QString::fromLatin1(token))) evaluated: peerHostName.endsWith(QString::fromLatin1(token))| yes Evaluation Count:9 | yes Evaluation Count:32 |
| 9-32 |
| 81 | return true; executed: return true;Execution Count:9 | 9 |
| 82 | } executed: }Execution Count:32 | 32 |
| 83 | | - |
| 84 | return false; executed: return false;Execution Count:32 | 32 |
| 85 | } | - |
| 86 | | - |
| 87 | QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) | - |
| 88 | { | - |
| 89 | QList<QNetworkProxy> proxyList; executed (the execution status of this line is deduced): QList<QNetworkProxy> proxyList; | - |
| 90 | | - |
| 91 | if (ignoreProxyFor(query)) evaluated: ignoreProxyFor(query)| yes Evaluation Count:9 | yes Evaluation Count:32 |
| 9-32 |
| 92 | return proxyList << QNetworkProxy::NoProxy; executed: return proxyList << QNetworkProxy::NoProxy;Execution Count:9 | 9 |
| 93 | | - |
| 94 | // No need to care about casing here, QUrl lowercases values already | - |
| 95 | const QString queryProtocol = query.protocolTag(); executed (the execution status of this line is deduced): const QString queryProtocol = query.protocolTag(); | - |
| 96 | QByteArray proxy_env; executed (the execution status of this line is deduced): QByteArray proxy_env; | - |
| 97 | | - |
| 98 | if (queryProtocol == QLatin1String("http")) evaluated: queryProtocol == QLatin1String("http")| yes Evaluation Count:20 | yes Evaluation Count:12 |
| 12-20 |
| 99 | proxy_env = qgetenv("http_proxy"); executed: proxy_env = qgetenv("http_proxy");Execution Count:20 | 20 |
| 100 | else if (queryProtocol == QLatin1String("https")) evaluated: queryProtocol == QLatin1String("https")| yes Evaluation Count:2 | yes Evaluation Count:10 |
| 2-10 |
| 101 | proxy_env = qgetenv("https_proxy"); executed: proxy_env = qgetenv("https_proxy");Execution Count:2 | 2 |
| 102 | else if (queryProtocol == QLatin1String("ftp")) evaluated: queryProtocol == QLatin1String("ftp")| yes Evaluation Count:2 | yes Evaluation Count:8 |
| 2-8 |
| 103 | proxy_env = qgetenv("ftp_proxy"); executed: proxy_env = qgetenv("ftp_proxy");Execution Count:2 | 2 |
| 104 | else | - |
| 105 | proxy_env = qgetenv("all_proxy"); executed: proxy_env = qgetenv("all_proxy");Execution Count:8 | 8 |
| 106 | | - |
| 107 | // Fallback to http_proxy is no protocol specific proxy was found | - |
| 108 | if (proxy_env.isEmpty()) partially evaluated: proxy_env.isEmpty()| yes Evaluation Count:32 | no Evaluation Count:0 |
| 0-32 |
| 109 | proxy_env = qgetenv("http_proxy"); executed: proxy_env = qgetenv("http_proxy");Execution Count:32 | 32 |
| 110 | | - |
| 111 | if (!proxy_env.isEmpty()) { partially evaluated: !proxy_env.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:32 |
| 0-32 |
| 112 | QUrl url = QUrl(QString::fromLocal8Bit(proxy_env)); never executed (the execution status of this line is deduced): QUrl url = QUrl(QString::fromLocal8Bit(proxy_env)); | - |
| 113 | if (url.scheme() == QLatin1String("socks5")) { never evaluated: url.scheme() == QLatin1String("socks5") | 0 |
| 114 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(), never executed (the execution status of this line is deduced): QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(), | - |
| 115 | url.port() ? url.port() : 1080, url.userName(), url.password()); never executed (the execution status of this line is deduced): url.port() ? url.port() : 1080, url.userName(), url.password()); | - |
| 116 | proxyList << proxy; never executed (the execution status of this line is deduced): proxyList << proxy; | - |
| 117 | } else if (url.scheme() == QLatin1String("socks5h")) { never executed: } never evaluated: url.scheme() == QLatin1String("socks5h") | 0 |
| 118 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(), never executed (the execution status of this line is deduced): QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(), | - |
| 119 | url.port() ? url.port() : 1080, url.userName(), url.password()); never executed (the execution status of this line is deduced): url.port() ? url.port() : 1080, url.userName(), url.password()); | - |
| 120 | proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability); never executed (the execution status of this line is deduced): proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability); | - |
| 121 | proxyList << proxy; never executed (the execution status of this line is deduced): proxyList << proxy; | - |
| 122 | } else if ((url.scheme() == QLatin1String("http") || url.scheme().isEmpty()) never executed: } never evaluated: url.scheme() == QLatin1String("http") never evaluated: url.scheme().isEmpty() | 0 |
| 123 | && query.queryType() != QNetworkProxyQuery::UdpSocket never evaluated: query.queryType() != QNetworkProxyQuery::UdpSocket | 0 |
| 124 | && query.queryType() != QNetworkProxyQuery::TcpServer) { never evaluated: query.queryType() != QNetworkProxyQuery::TcpServer | 0 |
| 125 | QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(), never executed (the execution status of this line is deduced): QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(), | - |
| 126 | url.port() ? url.port() : 8080, url.userName(), url.password()); never executed (the execution status of this line is deduced): url.port() ? url.port() : 8080, url.userName(), url.password()); | - |
| 127 | proxyList << proxy; never executed (the execution status of this line is deduced): proxyList << proxy; | - |
| 128 | } | 0 |
| 129 | } | - |
| 130 | if (proxyList.isEmpty()) partially evaluated: proxyList.isEmpty()| yes Evaluation Count:32 | no Evaluation Count:0 |
| 0-32 |
| 131 | proxyList << QNetworkProxy::NoProxy; executed: proxyList << QNetworkProxy::NoProxy;Execution Count:32 | 32 |
| 132 | | - |
| 133 | return proxyList; executed: return proxyList;Execution Count:32 | 32 |
| 134 | } | - |
| 135 | | - |
| 136 | QT_END_NAMESPACE | - |
| 137 | | - |
| 138 | #endif | - |
| 139 | | - |
| | |