|
|
|
@ -111,7 +111,7 @@ 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 timeout1=1000, int timeout2=30000) { |
|
|
|
|
int timeout1=5000, int timeout2=30000) { |
|
|
|
|
qDebug()<<"Search proxy for URL, direct and default" |
|
|
|
|
<<"url="<<url.data()<<"timeout1="<<timeout1; |
|
|
|
|
_url = url; |
|
|
|
@ -132,12 +132,12 @@ namespace proxy { |
|
|
|
|
} |
|
|
|
|
//! If Qt Network is available you may check the proxies found
|
|
|
|
|
/*! @copydoc proxy(const std::string&, int) */ |
|
|
|
|
void proxy(const QUrl& url, int timeout1=1000, int timeout2=30000) { |
|
|
|
|
void proxy(const QUrl& url, int timeout1=5000, int timeout2=30000) { |
|
|
|
|
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 timeout1=1000, int timeout2=30000) { |
|
|
|
|
void proxy(const QString& url, int timeout1=5000, int timeout2=30000) { |
|
|
|
|
proxy(url.toStdString(), timeout1, timeout2); |
|
|
|
|
} |
|
|
|
|
static QString toString(const QNetworkProxy& p) { |
|
|
|
@ -170,13 +170,15 @@ namespace proxy { |
|
|
|
|
void proxyFound(const QUrl&, const QNetworkProxy&); |
|
|
|
|
//! Signals a timeout, and no valid proxy for the URL requested earlier.
|
|
|
|
|
void proxyError(QNetworkReply::NetworkError); |
|
|
|
|
//! Signals an error during proxy detection.
|
|
|
|
|
void temporaryError(QNetworkReply::NetworkError, QString, QString); |
|
|
|
|
private: |
|
|
|
|
void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) { |
|
|
|
|
qDebug()<<"Testing proxy for url:"<<toString(prxy)<<"url="<<url.data(); |
|
|
|
|
QNetworkAccessManager* manager(new QNetworkAccessManager); |
|
|
|
|
manager->setProxy(prxy); |
|
|
|
|
if (!connect(manager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
|
SLOT(replyFinished(QNetworkReply*)))) |
|
|
|
|
SLOT(replyFinished(QNetworkReply*)))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
connect(manager, |
|
|
|
|
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), |
|
|
|
@ -226,7 +228,11 @@ namespace proxy { |
|
|
|
|
void replyFinished(QNetworkReply* reply) { |
|
|
|
|
qDebug()<<"Proxydetection got reply with status:" |
|
|
|
|
<<reply->error()<<reply->errorString(); |
|
|
|
|
if (reply->error()!=QNetworkReply::NoError) return; // wait for timeout
|
|
|
|
|
if (reply->error()!=QNetworkReply::NoError) { |
|
|
|
|
temporaryError(reply->error(), reply->errorString(), |
|
|
|
|
toString(_requests[reply].second)); |
|
|
|
|
return; // wait for timeout
|
|
|
|
|
} |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
QNetworkProxy prxy(_requests[reply].second); |
|
|
|
@ -284,18 +290,29 @@ namespace proxy { |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
|
|
/*
|
|
|
|
|
#ifdef QT_WEBKIT_LIB |
|
|
|
|
// use plain QT implementation
|
|
|
|
|
# include <proxyface/plainqt.hxx> |
|
|
|
|
namespace proxy { |
|
|
|
|
typedef Qt Face; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
# error no QT_WEBKIT_LIB |
|
|
|
|
*/ |
|
|
|
|
# ifdef WIN32 |
|
|
|
|
// use windoze proprietary winhttp
|
|
|
|
|
#include <proxyface/windoze.hxx> |
|
|
|
|
# include <proxyface/windoze.hxx> |
|
|
|
|
namespace proxy { |
|
|
|
|
typedef Windoze Face; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
# else |
|
|
|
|
// normal operating systems: use http://code.google.com/p/libproxy
|
|
|
|
|
#include <proxyface/unix.hxx> |
|
|
|
|
namespace proxy { |
|
|
|
|
typedef Unix Face; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
# endif |
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|