temporary change for debugging, see #9
This commit is contained in:
@@ -96,7 +96,9 @@ namespace proxy {
|
|||||||
#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.
|
||||||
Interface()
|
Interface()
|
||||||
#ifdef QT_NETWORK_LIB
|
#ifdef QT_NETWORK_LIB
|
||||||
@@ -115,7 +117,9 @@ namespace proxy {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Interface() {}
|
virtual ~Interface() {}
|
||||||
|
|
||||||
//! Get list of proxies for a given URL.
|
//! Get list of proxies for a given URL.
|
||||||
virtual List proxies(const std::string& url) = 0;
|
virtual List proxies(const std::string& url) = 0;
|
||||||
#ifdef QT_NETWORK_LIB
|
#ifdef QT_NETWORK_LIB
|
||||||
@@ -171,12 +175,15 @@ namespace proxy {
|
|||||||
setupProxyCheck(defaultProxy, url);
|
setupProxyCheck(defaultProxy, url);
|
||||||
_timeout2.start();
|
_timeout2.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ping(const QUrl& url, int timeout2=30000) {
|
void ping(const QUrl& url, int timeout2=30000) {
|
||||||
ping(url.toString().toStdString(), timeout2);
|
ping(url.toString().toStdString(), timeout2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ping(const QString& url, int timeout2=30000) {
|
void ping(const QString& url, int timeout2=30000) {
|
||||||
ping(url.toStdString(), timeout2);
|
ping(url.toStdString(), timeout2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! If Qt Network is available you may check the proxies found
|
//! If Qt Network is available you may check the proxies found
|
||||||
/*! First checks for direct access to the target. If this is not
|
/*! First checks for direct access to the target. If this is not
|
||||||
possible, starts scan for proxies.
|
possible, starts scan for proxies.
|
||||||
@@ -204,20 +211,24 @@ namespace proxy {
|
|||||||
_timeout2.setInterval(timeout2);
|
_timeout2.setInterval(timeout2);
|
||||||
_timeout1.setSingleShot(true);
|
_timeout1.setSingleShot(true);
|
||||||
_timeout1.setInterval(timeout1);
|
_timeout1.setInterval(timeout1);
|
||||||
_timeout1.start();
|
timeout();
|
||||||
|
// @todo add again after test _timeout1.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! If Qt Network is available you may check the proxies found
|
//! If Qt Network is available you may check the proxies found
|
||||||
/*! @copydoc proxy(const std::string&, int) */
|
/*! @copydoc proxy(const std::string&, int) */
|
||||||
void proxy(const QUrl& url, int timeout1=5000, int timeout2=30000) {
|
void proxy(const QUrl& url, int timeout1=5000, int timeout2=30000) {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
proxy(url.toString().toStdString(), timeout1, timeout2);
|
proxy(url.toString().toStdString(), timeout1, timeout2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! If Qt Network is available you may check the proxies found
|
//! If Qt Network is available you may check the proxies found
|
||||||
/*! @copydoc proxy(const std::string&, int) */
|
/*! @copydoc proxy(const std::string&, int) */
|
||||||
void proxy(const QString& url, int timeout1=5000, int timeout2=30000) {
|
void proxy(const QString& url, int timeout1=5000, int timeout2=30000) {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
proxy(url.toStdString(), timeout1, timeout2);
|
proxy(url.toStdString(), timeout1, timeout2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString toString(const QNetworkProxy& p) {
|
static QString toString(const QNetworkProxy& p) {
|
||||||
switch (p.type()) {
|
switch (p.type()) {
|
||||||
case QNetworkProxy::NoProxy:
|
case QNetworkProxy::NoProxy:
|
||||||
@@ -243,7 +254,9 @@ namespace proxy {
|
|||||||
}
|
}
|
||||||
return QString("**ERROR** illegal proxy type");
|
return QString("**ERROR** illegal proxy type");
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
||||||
//! Signals a valid proxy for the URL requested earlier.
|
//! Signals a valid proxy for the URL requested earlier.
|
||||||
void proxyFound(const QUrl&, const QNetworkProxy&);
|
void proxyFound(const QUrl&, const QNetworkProxy&);
|
||||||
//! Signals a timeout, and no valid proxy for the URL requested earlier.
|
//! Signals a timeout, and no valid proxy for the URL requested earlier.
|
||||||
@@ -252,7 +265,9 @@ namespace proxy {
|
|||||||
void temporaryError(QNetworkReply::NetworkError, QString, QString);
|
void temporaryError(QNetworkReply::NetworkError, QString, QString);
|
||||||
void authenticationRequired(QNetworkReply*, QAuthenticator*);
|
void authenticationRequired(QNetworkReply*, QAuthenticator*);
|
||||||
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*);
|
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) {
|
void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
qDebug()<<"Testing proxy for url:"<<toString(prxy)<<"url="<<url.data();
|
qDebug()<<"Testing proxy for url:"<<toString(prxy)<<"url="<<url.data();
|
||||||
@@ -262,8 +277,10 @@ namespace proxy {
|
|||||||
SLOT(replyFinished(QNetworkReply*))))
|
SLOT(replyFinished(QNetworkReply*))))
|
||||||
qFatal("connect failed");
|
qFatal("connect failed");
|
||||||
if (!connect(manager,
|
if (!connect(manager,
|
||||||
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
|
SIGNAL(authenticationRequired(QNetworkReply*,
|
||||||
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*))))
|
QAuthenticator*)),
|
||||||
|
SIGNAL(authenticationRequired(QNetworkReply*,
|
||||||
|
QAuthenticator*))))
|
||||||
qFatal("connect failed");
|
qFatal("connect failed");
|
||||||
if (!connect(manager,
|
if (!connect(manager,
|
||||||
SIGNAL(proxyAuthenticationRequired
|
SIGNAL(proxyAuthenticationRequired
|
||||||
@@ -315,14 +332,18 @@ namespace proxy {
|
|||||||
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)));
|
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)));
|
||||||
//delete manager;
|
//delete manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
|
||||||
void proxyAuthenticationRequiredLog(const QNetworkProxy&,
|
void proxyAuthenticationRequiredLog(const QNetworkProxy&,
|
||||||
QAuthenticator* auth) {
|
QAuthenticator* auth) {
|
||||||
qDebug()<<"proxyAuthenticationRequired for "<<auth->realm();
|
qDebug()<<"proxyAuthenticationRequired for "<<auth->realm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bullshit() {
|
void bullshit() {
|
||||||
qDebug()<<"SCHEISSE";
|
qDebug()<<"SCHEISSE";
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeout() {
|
void timeout() {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
reset();
|
reset();
|
||||||
@@ -341,6 +362,7 @@ namespace proxy {
|
|||||||
proxyError(QNetworkReply::TimeoutError);
|
proxyError(QNetworkReply::TimeoutError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void replyFinished(QNetworkReply* reply) {
|
void replyFinished(QNetworkReply* reply) {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
qDebug()<<"Proxydetection got reply with status:"
|
qDebug()<<"Proxydetection got reply with status:"
|
||||||
@@ -357,12 +379,14 @@ namespace proxy {
|
|||||||
<<"url="<<url<<"proxy="<<toString(prxy);
|
<<"url="<<url<<"proxy="<<toString(prxy);
|
||||||
proxyFound(url, prxy);
|
proxyFound(url, prxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sslErrors(QNetworkReply*, const QList<QSslError>& l) {
|
void sslErrors(QNetworkReply*, const QList<QSslError>& l) {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
qDebug()<<"## "<<__PRETTY_FUNCTION__;
|
qDebug()<<"## "<<__PRETTY_FUNCTION__;
|
||||||
for (QList<QSslError>::const_iterator it(l.begin()); it!=l.end(); ++it)
|
for (QList<QSslError>::const_iterator it(l.begin()); it!=l.end(); ++it)
|
||||||
qDebug()<<" SSL-Error -> "<<it->errorString();
|
qDebug()<<" SSL-Error -> "<<it->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void threadFinished() {
|
void threadFinished() {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
for (List::const_iterator it(_proxies.begin());
|
for (List::const_iterator it(_proxies.begin());
|
||||||
@@ -374,13 +398,15 @@ namespace proxy {
|
|||||||
QString::fromStdString(it->host), it->port);
|
QString::fromStdString(it->host), it->port);
|
||||||
setupProxyCheck(prxy, _url);
|
setupProxyCheck(prxy, _url);
|
||||||
}
|
}
|
||||||
QNetworkProxy directProxy(QNetworkProxy::NoProxy);
|
/// @todo add again after test QNetworkProxy directProxy(QNetworkProxy::NoProxy);
|
||||||
setupProxyCheck(directProxy, _url);
|
/// @todo add again after test setupProxyCheck(directProxy, _url);
|
||||||
QNetworkProxy defaultProxy;
|
/// @todo add again after test QNetworkProxy defaultProxy;
|
||||||
setupProxyCheck(defaultProxy, _url);
|
/// @todo add again after test setupProxyCheck(defaultProxy, _url);
|
||||||
_timeout2.start();
|
_timeout2.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
PROXYFACE_LOG;
|
PROXYFACE_LOG;
|
||||||
_proxies = proxies(_url);
|
_proxies = proxies(_url);
|
||||||
@@ -388,7 +414,9 @@ namespace proxy {
|
|||||||
threadFinished();
|
threadFinished();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef std::map
|
typedef std::map
|
||||||
<QNetworkReply*, std::pair<QNetworkAccessManager*, QNetworkProxy> >
|
<QNetworkReply*, std::pair<QNetworkAccessManager*, QNetworkProxy> >
|
||||||
Requests;
|
Requests;
|
||||||
|
|||||||
Reference in New Issue
Block a user