Mercurial > trustbridge
diff ui/downloader.cpp @ 908:d1c951b3012d
Curl based implementation of sslconnection
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 13 Aug 2014 19:35:08 +0200 |
parents | 4b702f6cf9b6 |
children | eaed02defe6a |
line wrap: on
line diff
--- a/ui/downloader.cpp Thu Aug 14 08:19:30 2014 +0200 +++ b/ui/downloader.cpp Wed Aug 13 19:35:08 2014 +0200 @@ -28,6 +28,8 @@ #define MAX_SW_SIZE 15728640 #define MAX_LIST_SIZE 1048576 +#include "sslconnection_curl.h" +#include "sslconnection_bare.h" Downloader::Downloader(QObject* parent, const QString& url, const QByteArray& certificate, @@ -41,13 +43,18 @@ mLastModList(newestList), mResourceSW(resourceSW), mResourceList(resourceList), - mDownloadSW(downloadSW), - mSSLConnection(url, certificate) + mDownloadSW(downloadSW) { +#ifdef USE_CURL + mSSLConnection = new SSLConnectionCurl(url, certificate); +#else + mSSLConnection = new SSLConnectionBare(url, certificate); +#endif } Downloader::~Downloader() { + delete mSSLConnection; } QString Downloader::getDataDirectory() @@ -112,13 +119,13 @@ QString headRequest = QString::fromLatin1("HEAD %1 HTTP/1.0\r\n\r\n").arg(resource); - ret = mSSLConnection.write(headRequest.toUtf8()); + ret = mSSLConnection->write(headRequest.toUtf8()); if (ret != 0) { emit error (tr("Connection lost"), SSLConnection::ConnectionLost); return QDateTime(); } - response = mSSLConnection.read(1024); + response = mSSLConnection->read(1024); qDebug() << "Response from server was: " << response; @@ -152,7 +159,7 @@ QSaveFile outputFile(fileName); - ret = mSSLConnection.write(getRequest.toUtf8()); + ret = mSSLConnection->write(getRequest.toUtf8()); // Open / Create the file to write to. if (!outputFile.open(QIODevice::WriteOnly)) { @@ -170,7 +177,7 @@ do { /* Read the response in 8KiB chunks */ int responseSize = 0; - QByteArray response = mSSLConnection.read(8192); + QByteArray response = mSSLConnection->read(8192); if (response.isNull()) { qDebug() << "Error reading response"; emit error(tr("Connection lost"), SSLConnection::ConnectionLost); @@ -198,16 +205,16 @@ QDateTime remoteModList; QDateTime remoteModSW; - if (!mSSLConnection.initialized()) { + if (!mSSLConnection->initialized()) { emit error(tr("Failed to initialize SSL Module."), SSLConnection::ErrUnknown); return; } - ret = mSSLConnection.connect(); + ret = mSSLConnection->connect(); if (ret != 0) { emit error(tr("Failed to connect."), - mSSLConnection.getLastError()); + mSSLConnection->getLastError()); return; }