|
|
|
@ -13,6 +13,7 @@ |
|
|
|
|
#include <QtNetwork/QNetworkAccessManager> |
|
|
|
|
#include <QtNetwork/QNetworkReply> |
|
|
|
|
#include <QtNetwork/QSslError> |
|
|
|
|
#include <QtNetwork/QHostInfo> |
|
|
|
|
#include <QtCore/QTimer> |
|
|
|
|
#include <QtCore/QDebug> |
|
|
|
|
#ifndef Q_OS_WIN32 |
|
|
|
@ -111,6 +112,32 @@ namespace proxy { |
|
|
|
|
//! Get list of proxies for a given URL.
|
|
|
|
|
virtual List proxies(const std::string& url) = 0; |
|
|
|
|
#ifdef QT_NETWORK_LIB |
|
|
|
|
//! Reset, stop all outstanding checks
|
|
|
|
|
void reset() { |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
it!=_requests.end(); ++it) |
|
|
|
|
clean(it->second.first); |
|
|
|
|
_requests.clear(); |
|
|
|
|
} |
|
|
|
|
//! Network Ping: Check access to a given address using default proxy.
|
|
|
|
|
void ping(const std::string& url, int timeout2=30000) { |
|
|
|
|
reset(); |
|
|
|
|
_timeout2.setSingleShot(true); |
|
|
|
|
_timeout2.setInterval(timeout2); |
|
|
|
|
_url = url; |
|
|
|
|
_direct = false; // simulate second try
|
|
|
|
|
QNetworkProxy defaultProxy; |
|
|
|
|
setupProxyCheck(defaultProxy, url); |
|
|
|
|
_timeout2.start(); |
|
|
|
|
} |
|
|
|
|
void ping(const QUrl& url, int timeout2=30000) { |
|
|
|
|
ping(url.toString().toStdString(), timeout2); |
|
|
|
|
} |
|
|
|
|
void ping(const QString& url, int timeout2=30000) { |
|
|
|
|
ping(url.toStdString(), timeout2); |
|
|
|
|
} |
|
|
|
|
//! If Qt Network is available you may check the proxies found
|
|
|
|
|
/*! First checks for direct access to the target. If this is not
|
|
|
|
|
possible, starts scan for proxies. |
|
|
|
@ -127,11 +154,8 @@ namespace proxy { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
qDebug()<<"Search proxy for URL, direct and default" |
|
|
|
|
<<"url="<<url.data()<<"timeout1="<<timeout1; |
|
|
|
|
reset(); |
|
|
|
|
_url = url; |
|
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
it!=_requests.end(); ++it) |
|
|
|
|
clean(it->second.first); |
|
|
|
|
_requests.clear(); |
|
|
|
|
_direct = true; // first try direct access
|
|
|
|
|
QNetworkProxy directProxy(QNetworkProxy::NoProxy); |
|
|
|
|
setupProxyCheck(directProxy, url); |
|
|
|
@ -238,21 +262,12 @@ namespace proxy { |
|
|
|
|
private Q_SLOTS: |
|
|
|
|
void timeout() { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
std::string url; |
|
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
it!=_requests.end(); ++it) { |
|
|
|
|
url = it->first->url().toString().toStdString(); |
|
|
|
|
clean(it->second.first); |
|
|
|
|
} |
|
|
|
|
_requests.clear(); |
|
|
|
|
qDebug()<<"Proxy detection timed out"<<"url="<<url.data(); |
|
|
|
|
if (_direct && url.size()) { |
|
|
|
|
reset(); |
|
|
|
|
qDebug()<<"Proxy detection timed out"<<"url="<<_url.data(); |
|
|
|
|
if (_direct) { |
|
|
|
|
qDebug()<<"Direct or preconfigured proxy not available," |
|
|
|
|
" try autoproxy negotiation"; |
|
|
|
|
_direct = false; |
|
|
|
|
_url = url; |
|
|
|
|
#ifndef Q_OS_WIN32 |
|
|
|
|
start(); // autoproxy detection in own thread
|
|
|
|
|
#else |
|
|
|
@ -272,14 +287,9 @@ namespace proxy { |
|
|
|
|
toString(_requests[reply].second)); |
|
|
|
|
return; // wait for timeout
|
|
|
|
|
} |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
QNetworkProxy prxy(_requests[reply].second); |
|
|
|
|
QUrl url(reply->url()); |
|
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
it!=_requests.end(); ++it) |
|
|
|
|
clean(it->second.first); |
|
|
|
|
_requests.clear(); |
|
|
|
|
reset(); |
|
|
|
|
qDebug()<<"SUCCESS - Valid proxy found for url:" |
|
|
|
|
<<"url="<<url<<"proxy="<<toString(prxy); |
|
|
|
|
proxyFound(url, prxy); |
|
|
|
|