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