diff --git a/proxyface/autoproxy.hxx b/proxyface/autoproxy.hxx index 8d562bc..faf2cc2 100644 --- a/proxyface/autoproxy.hxx +++ b/proxyface/autoproxy.hxx @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include #include #endif @@ -91,6 +91,8 @@ namespace proxy { qFatal("connect failed"); if (!connect(&_timeout2, SIGNAL(timeout()), SLOT(timeout()))) qFatal("connect failed"); + if (!connect(this, SIGNAL(finished()), SLOT(threadFinished()))) + qFatal("connect failed"); #endif } virtual ~Interface() {} @@ -110,12 +112,23 @@ namespace proxy { @param timeout [ms] time to give up search */ void proxy(const std::string& url, int timeout1=1000, int timeout2=30000) { + qDebug()<<"Search proxy for URL, direct and default" + <<"url="<second.first; + _requests.clear(); + _direct = true; // first try direct access + QNetworkProxy directProxy(QNetworkProxy::NoProxy); + setupProxyCheck(directProxy, url); + QNetworkProxy defaultProxy; + setupProxyCheck(defaultProxy, url); _timeout2.setSingleShot(true); _timeout2.setInterval(timeout2); _timeout1.setSingleShot(true); _timeout1.setInterval(timeout1); - start(); // in own thread to prevent hanging at proxy request + _timeout1.start(); } //! If Qt Network is available you may check the proxies found /*! @copydoc proxy(const std::string&, int) */ @@ -145,7 +158,8 @@ namespace proxy { case QNetworkProxy::HttpProxy: return QString("http://%1:%2").arg(p.hostName()).arg(p.port()); case QNetworkProxy::HttpCachingProxy: - return QString("http-cache://%1:%2").arg(p.hostName()).arg(p.port()); + return QString("http-cache://%1:%2").arg(p.hostName()) + .arg(p.port()); case QNetworkProxy::FtpCachingProxy: return QString("ftp-cache://%1:%2").arg(p.hostName()).arg(p.port()); } @@ -156,23 +170,6 @@ namespace proxy { void proxyFound(const QUrl&, const QNetworkProxy&); //! Signals a timeout, and no valid proxy for the URL requested earlier. void proxyError(QNetworkReply::NetworkError); - protected: - void run() { - qDebug()<<"Search proxy for URL, direct and default" - <<"url="<<_url.data(); - for (Requests::iterator it(_requests.begin()); - it!=_requests.end(); ++it) - delete it->second.first; - _requests.clear(); - _direct = true; // first try direct access - QNetworkProxy directProxy(QNetworkProxy::NoProxy); - setupProxyCheck(directProxy, _url); - QNetworkProxy defaultProxy; - setupProxyCheck(defaultProxy, _url); - _timeout1.start(); - exec(); - } - private: void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) { qDebug()<<"Testing proxy for url:"<type==DEFAULT?QNetworkProxy::DefaultProxy - :(it->type==HTTP?QNetworkProxy::HttpProxy - :(it->type==SOCKS?QNetworkProxy::Socks5Proxy - :QNetworkProxy::NoProxy))), - QString::fromStdString(it->host), it->port); - setupProxyCheck(prxy, url); - } - QNetworkProxy directProxy(QNetworkProxy::NoProxy); - setupProxyCheck(directProxy, url); - QNetworkProxy defaultProxy; - setupProxyCheck(defaultProxy, url); - _timeout2.start(); + _url = url; + start(); // autoproxy detection in own thread } else { qDebug()<<"No proxy at all, giving up - offline?"; proxyError(QNetworkReply::TimeoutError); @@ -260,6 +245,26 @@ namespace proxy { for (QList::const_iterator it(l.begin()); it!=l.end(); ++it) qDebug()<<" SSL-Error -> "<errorString(); } + void threadFinished() { + for (List::const_iterator it(_proxies.begin()); + it!=_proxies.end(); ++it) { + QNetworkProxy prxy((it->type==DEFAULT?QNetworkProxy::DefaultProxy + :(it->type==HTTP?QNetworkProxy::HttpProxy + :(it->type==SOCKS?QNetworkProxy::Socks5Proxy + :QNetworkProxy::NoProxy))), + QString::fromStdString(it->host), it->port); + setupProxyCheck(prxy, _url); + } + QNetworkProxy directProxy(QNetworkProxy::NoProxy); + setupProxyCheck(directProxy, _url); + QNetworkProxy defaultProxy; + setupProxyCheck(defaultProxy, _url); + _timeout2.start(); + } + protected: + void run() { + _proxies = proxies(_url); + } private: typedef std::map > @@ -268,6 +273,7 @@ namespace proxy { bool _direct; QTimer _timeout1; QTimer _timeout2; + List _proxies; std::string _url; #endif };