From 94d43c475d0d24c4e7d0c53a318dd1e0067188c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 9 Mar 2010 12:30:03 +0000 Subject: [PATCH] no more crash on windows --- proxyface/autoproxy.hxx | 48 ++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/proxyface/autoproxy.hxx b/proxyface/autoproxy.hxx index 78a4839..79f58c0 100644 --- a/proxyface/autoproxy.hxx +++ b/proxyface/autoproxy.hxx @@ -17,6 +17,9 @@ #include #include #include +#ifndef PROXYFACE_LOG +#define PROXYFACE_LOG qDebug()<<__PRETTY_FUNCTION__ +#endif #endif #include @@ -87,6 +90,7 @@ namespace proxy { //! Keep your instance as long as possible, because of caching. Interface() { #ifdef QT_NETWORK_LIB + PROXYFACE_LOG; if (!connect(&_timeout1, SIGNAL(timeout()), SLOT(timeout()))) qFatal("connect failed"); if (!connect(&_timeout2, SIGNAL(timeout()), SLOT(timeout()))) @@ -112,12 +116,13 @@ namespace proxy { @param timeout [ms] time to give up search */ void proxy(const std::string& url, int timeout1=5000, int timeout2=30000) { + PROXYFACE_LOG; qDebug()<<"Search proxy for URL, direct and default" <<"url="<second.first; + clean(it->second.first); _requests.clear(); _direct = true; // first try direct access QNetworkProxy directProxy(QNetworkProxy::NoProxy); @@ -133,11 +138,13 @@ 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=5000, int timeout2=30000) { + PROXYFACE_LOG; 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=5000, int timeout2=30000) { + PROXYFACE_LOG; proxy(url.toStdString(), timeout1, timeout2); } static QString toString(const QNetworkProxy& p) { @@ -174,6 +181,7 @@ namespace proxy { void temporaryError(QNetworkReply::NetworkError, QString, QString); private: void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) { + PROXYFACE_LOG; qDebug()<<"Testing proxy for url:"<setProxy(prxy); @@ -197,15 +205,38 @@ namespace proxy { (QUrl(QString::fromStdString(url)))), std::make_pair(manager, prxy))); } + void clean(QNetworkAccessManager* manager) { + if (!disconnect(manager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(replyFinished(QNetworkReply*)))) + qFatal("disconnect failed"); + disconnect(manager, + SIGNAL(authenticationRequired(QNetworkReply*, + QAuthenticator*)), + this, + SLOT(authenticationRequired(QNetworkReply*, + QAuthenticator*))); + disconnect(manager, + SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, + QAuthenticator*)), + this, + SLOT(proxyAuthenticationRequired(const QNetworkProxy&, + QAuthenticator*))); + disconnect(manager, + SIGNAL(sslErrors(QNetworkReply*, const QList&)), + this, + SLOT(sslErrors(QNetworkReply*, const QList&))); + delete manager; + } 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(); - delete it->second.first; + clean(it->second.first); } _requests.clear(); qDebug()<<"Proxy detection timed out"<<"url="<error()<errorString(); if (reply->error()!=QNetworkReply::NoError) { @@ -239,24 +266,28 @@ namespace proxy { QUrl url(reply->url()); for (Requests::iterator it(_requests.begin()); it!=_requests.end(); ++it) - delete it->second.first; + clean(it->second.first); _requests.clear(); qDebug()<<"SUCCESS - Valid proxy found for url:" <<"url="<& l) { + PROXYFACE_LOG; qDebug()<<"## "<<__PRETTY_FUNCTION__; for (QList::const_iterator it(l.begin()); it!=l.end(); ++it) qDebug()<<" SSL-Error -> "<errorString(); } void threadFinished() { + PROXYFACE_LOG; for (List::const_iterator it(_proxies.begin()); it!=_proxies.end(); ++it) { QNetworkProxy prxy((it->type==DEFAULT?QNetworkProxy::DefaultProxy @@ -274,6 +305,7 @@ namespace proxy { } protected: void run() { + PROXYFACE_LOG; _proxies = proxies(_url); } private: