diff ui/sslconnection_curl.cpp @ 1058:fe2c6666b462

(issue46) Add debug option to trustbridge client application
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 09 Sep 2014 17:58:55 +0200
parents 7dff5c0c569c
children 508c96e72f62
line wrap: on
line diff
--- 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 <polarssl/ssl.h>
 #include <QSaveFile>
 
-#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();

http://wald.intevation.org/projects/trustbridge/