comparison 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
comparison
equal deleted inserted replaced
1057:126e5ce4d1d1 1058:fe2c6666b462
5 * and comes with ABSOLUTELY NO WARRANTY! 5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 8
9 #include "sslconnection_curl.h" 9 #include "sslconnection_curl.h"
10 #include "logging.h"
10 11
11 #include <polarssl/ssl.h> 12 #include <polarssl/ssl.h>
12 #include <QSaveFile> 13 #include <QSaveFile>
13
14 #undef CONNECTION_DEBUG
15 14
16 SSLConnectionCurl::SSLConnectionCurl(const QString& url, 15 SSLConnectionCurl::SSLConnectionCurl(const QString& url,
17 const QByteArray& certificate): 16 const QByteArray& certificate):
18 SSLConnection (url, certificate), 17 SSLConnection (url, certificate),
19 mCurl (NULL) 18 mCurl (NULL)
81 mCertFile.fileName().toUtf8().constData()) != CURLE_OK) { 80 mCertFile.fileName().toUtf8().constData()) != CURLE_OK) {
82 qDebug() << "Failed set peer certificate."; 81 qDebug() << "Failed set peer certificate.";
83 return; 82 return;
84 } 83 }
85 mInitialized = true; 84 mInitialized = true;
86 85 if (g_debug) {
87 #ifdef CONNECTION_DEBUG 86 curl_easy_setopt(mCurl, CURLOPT_VERBOSE, 1L);
88 curl_easy_setopt(mCurl, CURLOPT_VERBOSE, 1L); 87 }
89 #endif
90 } 88 }
91 89
92 SSLConnectionCurl::~SSLConnectionCurl() { 90 SSLConnectionCurl::~SSLConnectionCurl() {
93 if (mCurl) { 91 if (mCurl) {
94 curl_easy_cleanup (mCurl); 92 curl_easy_cleanup (mCurl);
149 } 147 }
150 ssl_curl_written += written; 148 ssl_curl_written += written;
151 return written; 149 return written;
152 } 150 }
153 151
152 size_t debug_write(void *ptr, size_t size, size_t nmemb,
153 void *unused)
154 {
155 Q_UNUSED(unused);
156
157 qDebug() << QString::fromUtf8((const char *)ptr, size * nmemb);
158 return size *nmemb;
159 }
160
154 bool SSLConnectionCurl::downloadFile(const QString &resource, 161 bool SSLConnectionCurl::downloadFile(const QString &resource,
155 const QString &fileName, 162 const QString &fileName,
156 size_t maxSize) 163 size_t maxSize)
157 { 164 {
158 ssl_curl_written = 0; 165 ssl_curl_written = 0;
211 218
212 QDateTime SSLConnectionCurl::getLastModifiedHeader(const QString &resource) { 219 QDateTime SSLConnectionCurl::getLastModifiedHeader(const QString &resource) {
213 QUrl urlCopy = mUrl; 220 QUrl urlCopy = mUrl;
214 urlCopy.setPath(resource); 221 urlCopy.setPath(resource);
215 222
223 if (curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, debug_write) != CURLE_OK) {
224 qDebug() << "Failed to set write function";
225 return QDateTime();
226 }
227
216 if (curl_easy_setopt(mCurl, CURLOPT_URL, urlCopy.toEncoded().constData()) != CURLE_OK) { 228 if (curl_easy_setopt(mCurl, CURLOPT_URL, urlCopy.toEncoded().constData()) != CURLE_OK) {
217 qDebug() << "Failed to set URL"; 229 qDebug() << "Failed to set URL";
218 return QDateTime(); 230 return QDateTime();
219 } 231 }
220 232

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