|
|
|
@ -12,6 +12,7 @@ |
|
|
|
|
#include <QtNetwork/QNetworkProxy> |
|
|
|
|
#include <QtNetwork/QNetworkAccessManager> |
|
|
|
|
#include <QtNetwork/QNetworkReply> |
|
|
|
|
#include <QtNetwork/QAuthenticator> |
|
|
|
|
#include <QtNetwork/QSslError> |
|
|
|
|
#include <QtNetwork/QHostInfo> |
|
|
|
|
#include <QtCore/QTimer> |
|
|
|
@ -31,6 +32,8 @@ |
|
|
|
|
|
|
|
|
|
//! auto proxy configuration
|
|
|
|
|
namespace proxy { |
|
|
|
|
|
|
|
|
|
std::string version(); |
|
|
|
|
|
|
|
|
|
//! exceptions
|
|
|
|
|
namespace exc { |
|
|
|
@ -95,7 +98,11 @@ namespace proxy { |
|
|
|
|
#endif |
|
|
|
|
public: |
|
|
|
|
//! Keep your instance as long as possible, because of caching.
|
|
|
|
|
Interface() { |
|
|
|
|
Interface() |
|
|
|
|
#ifdef QT_NETWORK_LIB |
|
|
|
|
: _timeout1Paused(false), _timeout2Paused(false) |
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
#ifdef QT_NETWORK_LIB |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
if (!connect(&_timeout1, SIGNAL(timeout()), SLOT(timeout()))) |
|
|
|
@ -121,6 +128,35 @@ namespace proxy { |
|
|
|
|
clean(it->second.first); |
|
|
|
|
_requests.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//! Pause timeouts and restart them later.
|
|
|
|
|
/*! Use while waiting for user input at proxy authentication.
|
|
|
|
|
@see restart() */ |
|
|
|
|
void pause() { |
|
|
|
|
if (_timeout1.isActive()) { |
|
|
|
|
_timeout1.stop(); |
|
|
|
|
_timeout1Paused = true; |
|
|
|
|
} |
|
|
|
|
if (_timeout2.isActive()) { |
|
|
|
|
_timeout2.stop(); |
|
|
|
|
_timeout2Paused = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//! Restart paused timeouts.
|
|
|
|
|
/*! Use while waiting for user input at proxy authentication.
|
|
|
|
|
@see pause() */ |
|
|
|
|
void restart() { |
|
|
|
|
if (_timeout1Paused) { |
|
|
|
|
_timeout1.start(); |
|
|
|
|
_timeout1Paused = false; |
|
|
|
|
} |
|
|
|
|
if (_timeout2Paused) { |
|
|
|
|
_timeout2.start(); |
|
|
|
|
_timeout2Paused = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//! Network Ping: Check access to a given address using default proxy.
|
|
|
|
|
void ping(const std::string& url, int timeout2=30000) { |
|
|
|
|
if (_requests.size() || _timeout1.isActive() || _timeout2.isActive()) |
|
|
|
@ -214,6 +250,8 @@ namespace proxy { |
|
|
|
|
void proxyError(QNetworkReply::NetworkError); |
|
|
|
|
//! Signals an error during proxy detection.
|
|
|
|
|
void temporaryError(QNetworkReply::NetworkError, QString, QString); |
|
|
|
|
void authenticationRequired(QNetworkReply*, QAuthenticator*); |
|
|
|
|
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*); |
|
|
|
|
private: |
|
|
|
|
void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
@ -223,17 +261,26 @@ namespace proxy { |
|
|
|
|
if (!connect(manager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
|
SLOT(replyFinished(QNetworkReply*)))) |
|
|
|
|
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>&))); |
|
|
|
|
if (!connect(manager, |
|
|
|
|
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), |
|
|
|
|
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
if (!connect(manager, |
|
|
|
|
SIGNAL(proxyAuthenticationRequired |
|
|
|
|
(const QNetworkProxy&, QAuthenticator*)), |
|
|
|
|
SIGNAL(proxyAuthenticationRequired |
|
|
|
|
(const QNetworkProxy&, QAuthenticator*)))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
if (!connect(manager, |
|
|
|
|
SIGNAL(proxyAuthenticationRequired |
|
|
|
|
(const QNetworkProxy&, QAuthenticator*)), |
|
|
|
|
SLOT(proxyAuthenticationRequiredLog |
|
|
|
|
(const QNetworkProxy&, QAuthenticator*)))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
if (!connect(manager, |
|
|
|
|
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), |
|
|
|
|
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)))) |
|
|
|
|
qFatal("connect failed"); |
|
|
|
|
_requests.insert |
|
|
|
|
(std::make_pair(manager->head |
|
|
|
|
(QNetworkRequest |
|
|
|
@ -248,14 +295,20 @@ namespace proxy { |
|
|
|
|
SIGNAL(authenticationRequired(QNetworkReply*, |
|
|
|
|
QAuthenticator*)), |
|
|
|
|
this, |
|
|
|
|
SLOT(authenticationRequired(QNetworkReply*, |
|
|
|
|
QAuthenticator*))); |
|
|
|
|
SIGNAL(authenticationRequired(QNetworkReply*, |
|
|
|
|
QAuthenticator*))); |
|
|
|
|
disconnect(manager, |
|
|
|
|
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, |
|
|
|
|
QAuthenticator*)), |
|
|
|
|
this, |
|
|
|
|
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, |
|
|
|
|
QAuthenticator*))); |
|
|
|
|
disconnect(manager, |
|
|
|
|
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, |
|
|
|
|
QAuthenticator*)), |
|
|
|
|
this, |
|
|
|
|
SLOT(proxyAuthenticationRequired(const QNetworkProxy&, |
|
|
|
|
QAuthenticator*))); |
|
|
|
|
SLOT(proxyAuthenticationRequiredLog(const QNetworkProxy&, |
|
|
|
|
QAuthenticator*))); |
|
|
|
|
disconnect(manager, |
|
|
|
|
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), |
|
|
|
|
this, |
|
|
|
@ -263,6 +316,13 @@ namespace proxy { |
|
|
|
|
//delete manager;
|
|
|
|
|
} |
|
|
|
|
private Q_SLOTS: |
|
|
|
|
void proxyAuthenticationRequiredLog(const QNetworkProxy&, |
|
|
|
|
QAuthenticator* auth) { |
|
|
|
|
qDebug()<<"proxyAuthenticationRequired for "<<auth->realm(); |
|
|
|
|
} |
|
|
|
|
void bullshit() { |
|
|
|
|
qDebug()<<"SCHEISSE"; |
|
|
|
|
} |
|
|
|
|
void timeout() { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
reset(); |
|
|
|
@ -297,14 +357,6 @@ namespace proxy { |
|
|
|
|
<<"url="<<url<<"proxy="<<toString(prxy); |
|
|
|
|
proxyFound(url, prxy); |
|
|
|
|
} |
|
|
|
|
void authenticationRequired(QNetworkReply*, QAuthenticator*) { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
qDebug()<<"## "<<__PRETTY_FUNCTION__; |
|
|
|
|
} |
|
|
|
|
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*) { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
qDebug()<<"## "<<__PRETTY_FUNCTION__; |
|
|
|
|
} |
|
|
|
|
void sslErrors(QNetworkReply*, const QList<QSslError>& l) { |
|
|
|
|
PROXYFACE_LOG; |
|
|
|
|
qDebug()<<"## "<<__PRETTY_FUNCTION__; |
|
|
|
@ -344,6 +396,8 @@ namespace proxy { |
|
|
|
|
bool _direct; |
|
|
|
|
QTimer _timeout1; |
|
|
|
|
QTimer _timeout2; |
|
|
|
|
bool _timeout1Paused; |
|
|
|
|
bool _timeout2Paused; |
|
|
|
|
List _proxies; |
|
|
|
|
std::string _url; |
|
|
|
|
#endif |
|
|
|
|