|
|
|
@ -85,7 +85,9 @@ namespace proxy { |
|
|
|
|
//! Keep your instance as long as possible, because of caching.
|
|
|
|
|
Interface() { |
|
|
|
|
#ifdef QT_NETWORK_LIB |
|
|
|
|
if (!connect(&_timeout, SIGNAL(timeout()), SLOT(timeout()))) |
|
|
|
|
if (!connect(&_timeout1, SIGNAL(timeout()), SLOT(timeout()))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
if (!connect(&_timeout2, SIGNAL(timeout()), SLOT(timeout()))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
@ -104,10 +106,11 @@ namespace proxy { |
|
|
|
|
|
|
|
|
|
@param url the url to find a proxy for |
|
|
|
|
@param timeout [ms] time to give up search */ |
|
|
|
|
void proxy(const std::string& url, int timeout=2000) { |
|
|
|
|
void proxy(const std::string& url, int timeout1=1000, int timeout2=9000) { |
|
|
|
|
qDebug()<<"Search proxy for URL, direct and default" |
|
|
|
|
<<"url="<<url.data()<<"timeout="<<timeout; |
|
|
|
|
for (Requests::iterator it(_requests.begin()); it!=_requests.end(); ++it) |
|
|
|
|
<<"url="<<url.data()<<"timeout1="<<timeout1; |
|
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
it!=_requests.end(); ++it) |
|
|
|
|
delete it->second.first; |
|
|
|
|
_requests.clear(); |
|
|
|
|
_direct = true; // first try direct access
|
|
|
|
@ -115,19 +118,21 @@ namespace proxy { |
|
|
|
|
setupProxyCheck(directProxy, url); |
|
|
|
|
QNetworkProxy defaultProxy; |
|
|
|
|
setupProxyCheck(defaultProxy, url); |
|
|
|
|
_timeout.setSingleShot(true); |
|
|
|
|
_timeout.setInterval(timeout); |
|
|
|
|
_timeout.start(); |
|
|
|
|
_timeout2.setSingleShot(true); |
|
|
|
|
_timeout2.setInterval(timeout2); |
|
|
|
|
_timeout1.setSingleShot(true); |
|
|
|
|
_timeout1.setInterval(timeout1); |
|
|
|
|
_timeout1.start(); |
|
|
|
|
} |
|
|
|
|
//! If Qt Network is available you may check the proxies found
|
|
|
|
|
/*! @copydoc proxy(const std::string&, int) */ |
|
|
|
|
void proxy(const QUrl& url, int timeout=2000) { |
|
|
|
|
proxy(url.toString().toStdString(), timeout); |
|
|
|
|
void proxy(const QUrl& url, int timeout1=1000, int timeout2=9000) { |
|
|
|
|
proxy(url.toString().toStdString(), timeout1, timeout2); |
|
|
|
|
} |
|
|
|
|
//! If Qt Network is available you may check the proxies found
|
|
|
|
|
/*! @copydoc proxy(const std::string&, int) */ |
|
|
|
|
void proxy(const QString& url, int timeout=2000) { |
|
|
|
|
proxy(url.toStdString(), timeout); |
|
|
|
|
void proxy(const QString& url, int timeout1=1000, int timeout2=9000) { |
|
|
|
|
proxy(url.toStdString(), timeout1, timeout2); |
|
|
|
|
} |
|
|
|
|
static QString toString(const QNetworkProxy& p) { |
|
|
|
|
switch (p.type()) { |
|
|
|
@ -174,7 +179,8 @@ namespace proxy { |
|
|
|
|
} |
|
|
|
|
private Q_SLOTS: |
|
|
|
|
void timeout() { |
|
|
|
|
_timeout.stop(); |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
std::string url; |
|
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
it!=_requests.end(); ++it) { |
|
|
|
@ -196,7 +202,11 @@ namespace proxy { |
|
|
|
|
QString::fromStdString(it->host), it->port); |
|
|
|
|
setupProxyCheck(prxy, url); |
|
|
|
|
} |
|
|
|
|
_timeout.start(); |
|
|
|
|
QNetworkProxy directProxy(QNetworkProxy::NoProxy); |
|
|
|
|
setupProxyCheck(directProxy, url); |
|
|
|
|
QNetworkProxy defaultProxy; |
|
|
|
|
setupProxyCheck(defaultProxy, url); |
|
|
|
|
_timeout2.start(); |
|
|
|
|
} else { |
|
|
|
|
qDebug()<<"No proxy at all, giving up - offline?"; |
|
|
|
|
proxyError(QNetworkReply::TimeoutError); |
|
|
|
@ -206,7 +216,8 @@ namespace proxy { |
|
|
|
|
qDebug()<<"Proxydetection got reply with status:" |
|
|
|
|
<<reply->error()<<reply->errorString(); |
|
|
|
|
if (reply->error()!=QNetworkReply::NoError) return; // wait for timeout
|
|
|
|
|
_timeout.stop(); |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
QNetworkProxy prxy(_requests[reply].second); |
|
|
|
|
QUrl url(reply->url()); |
|
|
|
|
for (Requests::iterator it(_requests.begin()); it!=_requests.end(); ++it) |
|
|
|
@ -222,7 +233,8 @@ namespace proxy { |
|
|
|
|
Requests; |
|
|
|
|
Requests _requests; |
|
|
|
|
bool _direct; |
|
|
|
|
QTimer _timeout; |
|
|
|
|
QTimer _timeout1; |
|
|
|
|
QTimer _timeout2; |
|
|
|
|
#endif |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|