|
|
@ -12,6 +12,7 @@ |
|
|
|
#include <QtNetwork/QNetworkProxy> |
|
|
|
#include <QtNetwork/QNetworkProxy> |
|
|
|
#include <QtNetwork/QNetworkAccessManager> |
|
|
|
#include <QtNetwork/QNetworkAccessManager> |
|
|
|
#include <QtNetwork/QNetworkReply> |
|
|
|
#include <QtNetwork/QNetworkReply> |
|
|
|
|
|
|
|
#include <QtNetwork/QSslError> |
|
|
|
#include <QtCore/QTimer> |
|
|
|
#include <QtCore/QTimer> |
|
|
|
#include <QtCore/QDebug> |
|
|
|
#include <QtCore/QDebug> |
|
|
|
#include <map> |
|
|
|
#include <map> |
|
|
@ -79,7 +80,7 @@ namespace proxy { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef QT_NETWORK_LIB |
|
|
|
#ifdef QT_NETWORK_LIB |
|
|
|
Q_OBJECT; |
|
|
|
Q_OBJECT |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
public: |
|
|
|
public: |
|
|
|
//! Keep your instance as long as possible, because of caching.
|
|
|
|
//! Keep your instance as long as possible, because of caching.
|
|
|
@ -169,8 +170,19 @@ namespace proxy { |
|
|
|
QNetworkAccessManager* manager(new QNetworkAccessManager); |
|
|
|
QNetworkAccessManager* manager(new QNetworkAccessManager); |
|
|
|
manager->setProxy(prxy); |
|
|
|
manager->setProxy(prxy); |
|
|
|
if (!connect(manager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
if (!connect(manager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
this, SLOT(replyFinished(QNetworkReply*)))) |
|
|
|
SLOT(replyFinished(QNetworkReply*)))) |
|
|
|
qFatal("connect failed"); |
|
|
|
qFatal("connect failed"); |
|
|
|
|
|
|
|
connect(manager, |
|
|
|
|
|
|
|
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), |
|
|
|
|
|
|
|
SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*))); |
|
|
|
|
|
|
|
connect(manager, |
|
|
|
|
|
|
|
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, |
|
|
|
|
|
|
|
QAuthenticator*)), |
|
|
|
|
|
|
|
SLOT(proxyAuthenticationRequired(const QNetworkProxy&, |
|
|
|
|
|
|
|
QAuthenticator*))); |
|
|
|
|
|
|
|
connect(manager, |
|
|
|
|
|
|
|
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), |
|
|
|
|
|
|
|
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&))); |
|
|
|
_requests.insert |
|
|
|
_requests.insert |
|
|
|
(std::make_pair(manager->head |
|
|
|
(std::make_pair(manager->head |
|
|
|
(QNetworkRequest |
|
|
|
(QNetworkRequest |
|
|
@ -220,13 +232,25 @@ namespace proxy { |
|
|
|
_timeout2.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()); it!=_requests.end(); ++it) |
|
|
|
for (Requests::iterator it(_requests.begin()); |
|
|
|
|
|
|
|
it!=_requests.end(); ++it) |
|
|
|
delete it->second.first; |
|
|
|
delete it->second.first; |
|
|
|
_requests.clear(); |
|
|
|
_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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void authenticationRequired(QNetworkReply*, QAuthenticator*) { |
|
|
|
|
|
|
|
qDebug()<<"## "<<__PRETTY_FUNCTION__; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*) { |
|
|
|
|
|
|
|
qDebug()<<"## "<<__PRETTY_FUNCTION__; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void sslErrors(QNetworkReply*, const QList<QSslError>& l) { |
|
|
|
|
|
|
|
qDebug()<<"## "<<__PRETTY_FUNCTION__; |
|
|
|
|
|
|
|
for (QList<QSslError>::const_iterator it(l.begin()); it!=l.end(); ++it) |
|
|
|
|
|
|
|
qDebug()<<" SSL-Error -> "<<it->errorString(); |
|
|
|
|
|
|
|
} |
|
|
|
private: |
|
|
|
private: |
|
|
|
typedef std::map |
|
|
|
typedef std::map |
|
|
|
<QNetworkReply*, std::pair<QNetworkAccessManager*, QNetworkProxy> > |
|
|
|
<QNetworkReply*, std::pair<QNetworkAccessManager*, QNetworkProxy> > |
|
|
|