annotate ui/sslconnection_curl.cpp @ 993:561cc777e0b6

Add failure indicator if translation load failed.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 01 Sep 2014 12:53:22 +0200
parents 6a3d284b9c16
children daa9448b64f5
rev   line source
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 *
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details.
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 */
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include "sslconnection_curl.h"
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
10 #include <QSaveFile>
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #define CONNECTION_DEBUG
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 SSLConnectionCurl::SSLConnectionCurl(const QString& url,
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 const QByteArray& certificate):
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 SSLConnection (url, certificate),
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 mCurl (NULL)
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 curl_global_init(CURL_GLOBAL_DEFAULT);
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 mCurl = curl_easy_init();
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 if (!mCurl) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 qDebug() << "Failed to initialize curl";
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 return;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 if (curl_easy_setopt(mCurl, CURLOPT_SSL_VERIFYPEER, 1L) != CURLE_OK) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 /* Should be default anyway */
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 qDebug() << "Setting verifypeer failed";
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 return;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
33 if (curl_easy_setopt(mCurl, CURLOPT_ERRORBUFFER, mErrBuf) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
34 qDebug() << "Setting errorbuf failed";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
35 return;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
36 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
37
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 mCertFile.open();
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 if (mCertFile.write(mPinnedCert) != mPinnedCert.size()) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 qDebug() << "Failed to write temporary certificate";
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 return;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 mCertFile.close();
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 if (curl_easy_setopt(mCurl, CURLOPT_CAINFO,
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 mCertFile.fileName().toUtf8().constData()) != CURLE_OK) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 qDebug() << "Failed to write temporary certificate";
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 return;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 }
991
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
50
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 mInitialized = true;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 #ifdef CONNECTION_DEBUG
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 curl_easy_setopt(mCurl, CURLOPT_VERBOSE, 1L);
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 #endif
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 SSLConnectionCurl::~SSLConnectionCurl() {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 if (mCurl) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 curl_easy_cleanup (mCurl);
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 if (mInitialized) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 mCertFile.close();
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 curl_global_cleanup();
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 int SSLConnectionCurl::connect() {
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
69 CURLcode retval;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
70
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
71 if (curl_easy_setopt(mCurl, CURLOPT_URL, mUrl.toEncoded().constData()) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
72 qDebug() << "Failed to set URL";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
73 return -1;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
74 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
75
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76 if (curl_easy_setopt(mCurl, CURLOPT_CONNECT_ONLY, 1L) != CURLE_OK) {
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 qDebug() << "Failed to set connect only option";
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 return -1;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 }
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
80 retval = curl_easy_perform(mCurl);
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
81 if (retval != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
82 qDebug() << "Failed to connect: " << mErrBuf << " retval: " << retval;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
83 if (retval == CURLE_PEER_FAILED_VERIFICATION) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
84 mErrorState = InvalidCertificate;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
85 return -1;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
86 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
87
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 mErrorState = NoConnection;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 return -1;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 mConnected = true;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 return 0;
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94
991
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
95 /* Globally do this as we can't pass "this" (the ptr) to the c function */
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
96 size_t ssl_curl_max_write, ssl_curl_written;
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
98 size_t write_data(void *ptr, size_t size, size_t nmemb,
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
99 QSaveFile *fp)
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
100 {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
101 qDebug() << "Writing size: " << size << " * " << nmemb;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
102 if (ssl_curl_max_write < ssl_curl_written) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
103 qDebug() << "Aborting write. Too much data.";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
104 return 0;
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 }
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
106 size_t written = fp->write((const char *)ptr, size * nmemb);
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
107 if (written != size * nmemb) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
108 qDebug() << "Failed to write data. Written: " << written
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
109 << " requested: " << size * nmemb;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
110 return 0;
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 }
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
112 ssl_curl_written += written;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
113 return written;
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 }
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
116 bool SSLConnectionCurl::downloadFile(const QString &resource,
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
117 const QString &fileName,
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
118 size_t maxSize)
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 {
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
120 ssl_curl_written = 0;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
121 ssl_curl_max_write = maxSize;
991
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
122 QSaveFile outputFile(fileName);
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
123 // Open / Create the file to write to.
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
124 if (!outputFile.open(QIODevice::WriteOnly)) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
125 qDebug() << "Failed to open file";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
126 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
127 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
128 QUrl urlCopy = mUrl;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
129 urlCopy.setPath(resource);
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
131 if (curl_easy_setopt(mCurl, CURLOPT_URL, urlCopy.toEncoded().constData()) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
132 qDebug() << "Failed to set URL";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
133 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
134 }
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
136 if (curl_easy_setopt(mCurl, CURLOPT_CONNECT_ONLY, 0L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
137 qDebug() << "Failed to set connect";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
138 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
139 }
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
141 if (curl_easy_setopt(mCurl, CURLOPT_HEADER, 0L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
142 qDebug() << "Failed to set header";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
143 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
144 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
145
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
146 if (curl_easy_setopt(mCurl, CURLOPT_NOBODY, 0L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
147 qDebug() << "Failed to set no body";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
148 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
149 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
150
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
151 if (curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, write_data) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
152 qDebug() << "Failed to set write function";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
153 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
154 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
155
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
156 if (curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, &outputFile) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
157 qDebug() << "Failed to set write function";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
158 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
159 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
160
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
161 if (curl_easy_perform (mCurl) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
162 qDebug() << "Failed to perform download.";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
163 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
164 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
165
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
166 if (!outputFile.commit()) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
167 qDebug() << "Failed to commit data to filesystem.";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
168 return false;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
169 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
170
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
171 return true;
908
d1c951b3012d Curl based implementation of sslconnection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 }
910
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
173
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
174 QDateTime SSLConnectionCurl::getLastModifiedHeader(const QString &resource) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
175 QUrl urlCopy = mUrl;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
176 urlCopy.setPath(resource);
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
177
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
178 if (curl_easy_setopt(mCurl, CURLOPT_URL, urlCopy.toEncoded().constData()) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
179 qDebug() << "Failed to set URL";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
180 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
181 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
182
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
183 if (curl_easy_setopt(mCurl, CURLOPT_CONNECT_ONLY, 0L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
184 qDebug() << "Failed to set connect";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
185 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
186 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
187
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
188 if (curl_easy_setopt(mCurl, CURLOPT_HEADER, 1L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
189 qDebug() << "Failed to set header";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
190 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
191 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
192
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
193 if (curl_easy_setopt(mCurl, CURLOPT_NOBODY, 1L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
194 qDebug() << "Failed to set no body";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
195 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
196 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
197
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
198 if (curl_easy_setopt(mCurl, CURLOPT_FILETIME, 1L) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
199 qDebug() << "Failed to set filetime";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
200 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
201 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
202
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
203 if (curl_easy_perform (mCurl) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
204 qDebug() << "Failed to perform last modified check.";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
205 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
206 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
207 long filetime = 0;
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
208
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
209 if (curl_easy_getinfo (mCurl, CURLINFO_FILETIME, &filetime) != CURLE_OK) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
210 qDebug() << "Failed to get filetime";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
211 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
212 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
213
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
214 if (filetime == -1) {
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
215 qDebug() << "Invalid Time";
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
216 return QDateTime();
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
217 }
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
218 return QDateTime::fromTime_t(filetime);
eaed02defe6a More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 908
diff changeset
219 }
956
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
220
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
221 void SSLConnectionCurl::setProxy(const QUrl& proxyUrl) {
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
222 if (curl_easy_setopt(mCurl, CURLOPT_PROXY, proxyUrl.toEncoded().constData()) != CURLE_OK) {
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
223 qDebug() << "Failed to set proxy";
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
224 return;
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
225 }
879a634d0a40 (issue41) Add proxy support
Andre Heinecke <andre.heinecke@intevation.de>
parents: 942
diff changeset
226 }
991
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
227
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
228 void SSLConnectionCurl::setCiphersuites(int ciphers[]) {
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
229 qDebug() << "Set ciphersuites not supported.";
6a3d284b9c16 Delegate certificate loading to base class. Minor cleanups.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 956
diff changeset
230 }

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