more information in cae of network error

master
Marc Wäckerlin 10 years ago
parent 0838a24b51
commit c9ec2b6122
  1. 99
      src/networkaccessmanager.hxx

@ -8,6 +8,7 @@
#define __NETWORKACCESS_MANAGER_HXX__ #define __NETWORKACCESS_MANAGER_HXX__
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkConfiguration> #include <QNetworkConfiguration>
#include <QNetworkProxy> #include <QNetworkProxy>
@ -15,7 +16,7 @@ class NetworkAccessManager: public QNetworkAccessManager {
Q_OBJECT; Q_OBJECT;
public: public:
NetworkAccessManager(QObject* parent = 0): QNetworkAccessManager(parent) { NetworkAccessManager(QObject* parent = 0): QNetworkAccessManager(parent) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
connect(this, connect(this,
SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
SLOT(authenticationRequiredLog(QNetworkReply*, QAuthenticator*))); SLOT(authenticationRequiredLog(QNetworkReply*, QAuthenticator*)));
@ -40,122 +41,122 @@ class NetworkAccessManager: public QNetworkAccessManager {
SLOT(sslErrorsLog(QNetworkReply*, const QList<QSslError>&))); SLOT(sslErrorsLog(QNetworkReply*, const QList<QSslError>&)));
} }
virtual ~NetworkAccessManager() { virtual ~NetworkAccessManager() {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
} }
QNetworkConfiguration activeConfiguration() const { QNetworkConfiguration activeConfiguration() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::activeConfiguration(); return QNetworkAccessManager::activeConfiguration();
} }
QAbstractNetworkCache* cache() const { QAbstractNetworkCache* cache() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::cache(); return QNetworkAccessManager::cache();
} }
void clearAccessCache() { void clearAccessCache() {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::clearAccessCache(); return QNetworkAccessManager::clearAccessCache();
} }
QNetworkConfiguration configuration() const { QNetworkConfiguration configuration() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::configuration(); return QNetworkAccessManager::configuration();
} }
void connectToHost(const QString& hostName, quint16 port = 80) { void connectToHost(const QString& hostName, quint16 port = 80) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
QNetworkAccessManager::connectToHost(hostName, port); QNetworkAccessManager::connectToHost(hostName, port);
} }
void connectToHostEncrypted(const QString& hostName, quint16 port = 443, void connectToHostEncrypted(const QString& hostName, quint16 port = 443,
const QSslConfiguration& sslConfiguration const QSslConfiguration& sslConfiguration
= QSslConfiguration::defaultConfiguration()) { = QSslConfiguration::defaultConfiguration()) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
QNetworkAccessManager::connectToHostEncrypted(hostName, port, QNetworkAccessManager::connectToHostEncrypted(hostName, port,
sslConfiguration); sslConfiguration);
} }
QNetworkCookieJar* cookieJar() const { QNetworkCookieJar* cookieJar() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::cookieJar(); return QNetworkAccessManager::cookieJar();
} }
QNetworkReply* deleteResource(const QNetworkRequest & request) { QNetworkReply* deleteResource(const QNetworkRequest & request) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::deleteResource(request); return QNetworkAccessManager::deleteResource(request);
} }
QNetworkReply* get(const QNetworkRequest& request) { QNetworkReply* get(const QNetworkRequest& request) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::get(request); return QNetworkAccessManager::get(request);
} }
QNetworkReply* head(const QNetworkRequest& request) { QNetworkReply* head(const QNetworkRequest& request) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::head(request); return QNetworkAccessManager::head(request);
} }
NetworkAccessibility networkAccessible() const { NetworkAccessibility networkAccessible() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::networkAccessible(); return QNetworkAccessManager::networkAccessible();
} }
QNetworkReply* post(const QNetworkRequest & request, QIODevice * data) { QNetworkReply* post(const QNetworkRequest & request, QIODevice * data) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::post(request, data); return QNetworkAccessManager::post(request, data);
} }
QNetworkReply* post(const QNetworkRequest& request, QNetworkReply* post(const QNetworkRequest& request,
const QByteArray& data) { const QByteArray& data) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::post(request, data); return QNetworkAccessManager::post(request, data);
} }
QNetworkReply* post(const QNetworkRequest& request, QNetworkReply* post(const QNetworkRequest& request,
QHttpMultiPart* multiPart) { QHttpMultiPart* multiPart) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::post(request, multiPart); return QNetworkAccessManager::post(request, multiPart);
} }
QNetworkProxy proxy() const { QNetworkProxy proxy() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::proxy(); return QNetworkAccessManager::proxy();
} }
QNetworkProxyFactory* proxyFactory() const { QNetworkProxyFactory* proxyFactory() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::proxyFactory(); return QNetworkAccessManager::proxyFactory();
} }
QNetworkReply* put(const QNetworkRequest& request, QIODevice* data) { QNetworkReply* put(const QNetworkRequest& request, QIODevice* data) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::put(request, data); return QNetworkAccessManager::put(request, data);
} }
QNetworkReply* put(const QNetworkRequest& request, QNetworkReply* put(const QNetworkRequest& request,
QHttpMultiPart* multiPart) { QHttpMultiPart* multiPart) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::put(request, multiPart); return QNetworkAccessManager::put(request, multiPart);
} }
QNetworkReply* put(const QNetworkRequest& request, const QByteArray& data) { QNetworkReply* put(const QNetworkRequest& request, const QByteArray& data) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::put(request, data); return QNetworkAccessManager::put(request, data);
} }
QNetworkReply* sendCustomRequest(const QNetworkRequest& request, QNetworkReply* sendCustomRequest(const QNetworkRequest& request,
const QByteArray& verb, const QByteArray& verb,
QIODevice* data = 0) { QIODevice* data = 0) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::sendCustomRequest(request, verb, data); return QNetworkAccessManager::sendCustomRequest(request, verb, data);
} }
void setCache(QAbstractNetworkCache* cache) { void setCache(QAbstractNetworkCache* cache) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::setCache(cache); return QNetworkAccessManager::setCache(cache);
} }
void setConfiguration(const QNetworkConfiguration& config) { void setConfiguration(const QNetworkConfiguration& config) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::setConfiguration(config); return QNetworkAccessManager::setConfiguration(config);
} }
void setCookieJar(QNetworkCookieJar* cookieJar) { void setCookieJar(QNetworkCookieJar* cookieJar) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::setCookieJar(cookieJar); return QNetworkAccessManager::setCookieJar(cookieJar);
} }
void setNetworkAccessible(NetworkAccessibility accessible) { void setNetworkAccessible(NetworkAccessibility accessible) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::setNetworkAccessible(accessible); return QNetworkAccessManager::setNetworkAccessible(accessible);
} }
void setProxy(const QNetworkProxy& proxy) { void setProxy(const QNetworkProxy& proxy) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::setProxy(proxy); return QNetworkAccessManager::setProxy(proxy);
} }
void setProxyFactory(QNetworkProxyFactory* factory) { void setProxyFactory(QNetworkProxyFactory* factory) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::setProxyFactory(factory); return QNetworkAccessManager::setProxyFactory(factory);
} }
QStringList supportedSchemes() const { QStringList supportedSchemes() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::supportedSchemes(); return QNetworkAccessManager::supportedSchemes();
} }
Q_SIGNALS: Q_SIGNALS:
@ -170,7 +171,7 @@ class NetworkAccessManager: public QNetworkAccessManager {
virtual QNetworkReply* createRequest(Operation op, virtual QNetworkReply* createRequest(Operation op,
const QNetworkRequest& req, const QNetworkRequest& req,
QIODevice* outgoingData = 0) { QIODevice* outgoingData = 0) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
switch (op) { switch (op) {
case QNetworkAccessManager::HeadOperation: break; case QNetworkAccessManager::HeadOperation: break;
case QNetworkAccessManager::GetOperation: break; case QNetworkAccessManager::GetOperation: break;
@ -180,32 +181,54 @@ class NetworkAccessManager: public QNetworkAccessManager {
case QNetworkAccessManager::CustomOperation: break; case QNetworkAccessManager::CustomOperation: break;
case QNetworkAccessManager::UnknownOperation: break; case QNetworkAccessManager::UnknownOperation: break;
} }
return QNetworkAccessManager::createRequest(op, req, outgoingData); QNetworkReply* reply
(QNetworkAccessManager::createRequest(op, req, outgoingData));
connect(reply, SIGNAL(encrypted()), SLOT(encryptedLog()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
SLOT(errorLog(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(finished()), SLOT(finishedLog()));
connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)),
SLOT(sslErrorsLog(const QList<QSslError>&)));
return reply;
} }
protected Q_SLOTS: protected Q_SLOTS:
QStringList supportedSchemesImplementation() const { QStringList supportedSchemesImplementation() const {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
return QNetworkAccessManager::supportedSchemesImplementation(); return QNetworkAccessManager::supportedSchemesImplementation();
} }
private Q_SLOTS: private Q_SLOTS:
void errorLog(QNetworkReply::NetworkError) {
log("**** Network Error: "
+ dynamic_cast<QNetworkReply*>(sender())->errorString());
}
void authenticationRequiredLog(QNetworkReply*, QAuthenticator*) { void authenticationRequiredLog(QNetworkReply*, QAuthenticator*) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
}
void encryptedLog() {
//log(__PRETTY_FUNCTION__);
} }
void encryptedLog(QNetworkReply*) { void encryptedLog(QNetworkReply*) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
}
void finishedLog() {
//log(__PRETTY_FUNCTION__);
} }
void finishedLog(QNetworkReply*) { void finishedLog(QNetworkReply*) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
} }
void networkAccessibleChangedLog void networkAccessibleChangedLog
(QNetworkAccessManager::NetworkAccessibility) { (QNetworkAccessManager::NetworkAccessibility) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
} }
void proxyAuthenticationRequiredLog(const QNetworkProxy&, QAuthenticator*) { void proxyAuthenticationRequiredLog(const QNetworkProxy&, QAuthenticator*) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
}
void sslErrorsLog(const QList<QSslError>& errors) {
Q_FOREACH(const QSslError& error, errors)
log("**** SSL-Error: "+error.errorString());
} }
void sslErrorsLog(QNetworkReply*, const QList<QSslError>&) { void sslErrorsLog(QNetworkReply*, const QList<QSslError>&) {
// log(__PRETTY_FUNCTION__); //log(__PRETTY_FUNCTION__);
} }
}; };

Loading…
Cancel
Save