# HG changeset patch # User Andre Heinecke # Date 1410278335 -7200 # Node ID fe2c6666b462363f7994beff70e8d1e35ba479ab # Parent 126e5ce4d1d1eff6e1bafc6ca016bff0fdb44b9e (issue46) Add debug option to trustbridge client application diff -r 126e5ce4d1d1 -r fe2c6666b462 common/logging.h --- a/common/logging.h Tue Sep 09 17:16:07 2014 +0200 +++ b/common/logging.h Tue Sep 09 17:58:55 2014 +0200 @@ -26,6 +26,8 @@ /** @def The name used for logging */ #define LOG_NAME "TrustBridge" +extern bool g_debug; + #ifdef WIN32 #include diff -r 126e5ce4d1d1 -r fe2c6666b462 ui/main.cpp --- a/ui/main.cpp Tue Sep 09 17:16:07 2014 +0200 +++ b/ui/main.cpp Tue Sep 09 17:58:55 2014 +0200 @@ -52,6 +52,21 @@ Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) #endif +bool g_debug = false; +QtMessageHandler g_default_msg_handler = NULL; + +void noDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + if (type == QtDebugMsg) { + return; + } + + if (g_default_msg_handler) { + (*g_default_msg_handler)(type, context, msg); + } +} + + int main(int argc, char **argv) { #ifdef WIN32 @@ -77,12 +92,19 @@ QApplication::setApplicationName(QString::fromLatin1(APPNAME)); QApplication::setApplicationVersion(QString::fromLatin1(VERSION)); QSettings::setDefaultFormat(QSettings::IniFormat); + QStringList arguments = QApplication::arguments(); + + if (arguments.contains("--debug")) { + g_debug = true; + } else { + g_debug = false; + g_default_msg_handler = qInstallMessageHandler(noDebugOutput); + } qDebug() << "Application style is: " << app.style()->metaObject()->className(); qDebug() << "Available styles: " << QStyleFactory::keys().join(", "); qDebug() << "Font is: " << app.font(); - QStringList arguments = QApplication::arguments(); bool trayMode = arguments.contains("--tray"); if (arguments.contains("--version")) { diff -r 126e5ce4d1d1 -r fe2c6666b462 ui/sslconnection_curl.cpp --- a/ui/sslconnection_curl.cpp Tue Sep 09 17:16:07 2014 +0200 +++ b/ui/sslconnection_curl.cpp Tue Sep 09 17:58:55 2014 +0200 @@ -7,12 +7,11 @@ */ #include "sslconnection_curl.h" +#include "logging.h" #include #include -#undef CONNECTION_DEBUG - SSLConnectionCurl::SSLConnectionCurl(const QString& url, const QByteArray& certificate): SSLConnection (url, certificate), @@ -83,10 +82,9 @@ return; } mInitialized = true; - -#ifdef CONNECTION_DEBUG - curl_easy_setopt(mCurl, CURLOPT_VERBOSE, 1L); -#endif + if (g_debug) { + curl_easy_setopt(mCurl, CURLOPT_VERBOSE, 1L); + } } SSLConnectionCurl::~SSLConnectionCurl() { @@ -151,6 +149,15 @@ return written; } +size_t debug_write(void *ptr, size_t size, size_t nmemb, + void *unused) +{ + Q_UNUSED(unused); + + qDebug() << QString::fromUtf8((const char *)ptr, size * nmemb); + return size *nmemb; +} + bool SSLConnectionCurl::downloadFile(const QString &resource, const QString &fileName, size_t maxSize) @@ -213,6 +220,11 @@ QUrl urlCopy = mUrl; urlCopy.setPath(resource); + if (curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, debug_write) != CURLE_OK) { + qDebug() << "Failed to set write function"; + return QDateTime(); + } + if (curl_easy_setopt(mCurl, CURLOPT_URL, urlCopy.toEncoded().constData()) != CURLE_OK) { qDebug() << "Failed to set URL"; return QDateTime(); diff -r 126e5ce4d1d1 -r fe2c6666b462 ui/tests/downloadertest.cpp --- a/ui/tests/downloadertest.cpp Tue Sep 09 17:16:07 2014 +0200 +++ b/ui/tests/downloadertest.cpp Tue Sep 09 17:58:55 2014 +0200 @@ -309,5 +309,7 @@ } } +bool g_debug = true; + QTEST_GUILESS_MAIN (DownloaderTest);