Mercurial > trustbridge
diff ui/downloader.h @ 27:62cd56cea09b
Start on polarssl Downloader.
This breaks the windows build for now
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 12 Mar 2014 16:15:52 +0100 |
parents | 95e1b6edf2fc |
children | d8e93fa1fc93 |
line wrap: on
line diff
--- a/ui/downloader.h Tue Mar 11 19:00:35 2014 +0100 +++ b/ui/downloader.h Wed Mar 12 16:15:52 2014 +0100 @@ -10,12 +10,12 @@ #include <QString> #include <QByteArray> #include <QDateTime> +#include <QUrl> -#ifdef Q_OS_WIN -#include <windows.h> -#include <winhttp.h> -#endif - +#include <polarssl/x509_crt.h> +#include <polarssl/entropy.h> +#include <polarssl/ctr_drbg.h> +#include <polarssl/ssl.h> class Downloader: public QThread { @@ -44,10 +44,13 @@ const QDateTime& newestSW = QDateTime(), const QDateTime& newestList = QDateTime()); + ~Downloader(); enum ErrorCode { + NoError, NoConnection, InvalidCertificate, + InvalidPinnedCertificate, ConnectionLost, Timeout, ErrUnknown @@ -63,56 +66,52 @@ **/ QString getDataDirectory(); + /** + * @brief get the current error state + * + * @returns The current error state. + **/ + ErrorCode getErrorState(); protected: void run(); private: - QString mUrl; - QByteArray mCert; + QUrl mUrl; + QByteArray mPinnedCert; + x509_crt mX509PinnedCert; + entropy_context mEntropy; + ctr_drbg_context mCtr_drbg; + ssl_context mSSL; QDateTime mLastModSW; QDateTime mLastModList; -#ifdef Q_OS_WIN - /** @brief Download a file from the Internet - * - * @param[in] HSession the session to work in. - * @param[in] HConnect the connection to use. - * @param[in] resource the resource to download. - * @param[in] filename where the file should be saved. - * @param[in] maxSize maximum amount of bytes to download - * - * @returns True if the download was successful. - */ - bool downloadFile(HINTERNET hSession, HINTERNET hConnect, - LPCWSTR resource, const QString &filename, DWORD maxSize); + /* Convienience to avoid having to parse all + * PolarSSL errors */ + ErrorCode mErrorState; - /** @brief get the last modified header of a resource. + bool mInitialized; + + int mServerFD; + + + /* @brief: Initialize polarssl structures * - * On error call getLastError to get extended error information. - * This function still does not do any networking but only initializes - * it. + * This wraps polarssl initialization functions + * that can return an error. + * Sets the error state accordingly. * - * @param[in] HSession the session to work in. - * @param[in] HConnect the connection to use. - * @param[in] resource the resource to check the last-modified date on - * - * @returns the last modified date or a null datetime in case of errors + * @returns: 0 on success a polarssl error otherwise. */ - QDateTime getLastModifiedHeader(HINTERNET hSession, - HINTERNET hConnect, LPCWSTR resource); + int init(); - /** @brief verify that the certificate of the request matches + /** @brief: Establish the connection * - * Validates the certificate against the member variable certificate - * - * @param[in] hRequest: The request from which to get the certificate - * - * @returns True if the certificate exactly matches the one in hRequest + * @returns 0 on success otherwise a polarssl error or -1 is returned */ - - bool verifyCertificate(HINTERNET hRequest); + int establishSSLConnection(); +#ifdef Q_OS_WIN #endif Q_SIGNALS: @@ -142,6 +141,6 @@ * @param[out] message: A message to show. Can be empty. * @param[out] errorCode: ErrorCode of this error. */ - void error(const QString &message, ErrorCode error); + void error(const QString &message, Downloader::ErrorCode error); }; #endif