diff ui/downloader.h @ 45:c6125d73faf4

Move SSLConnection into it's own class
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 14 Mar 2014 16:40:53 +0000
parents d8e93fa1fc93
children 09cd242d8443
line wrap: on
line diff
--- a/ui/downloader.h	Fri Mar 14 16:06:40 2014 +0000
+++ b/ui/downloader.h	Fri Mar 14 16:40:53 2014 +0000
@@ -7,15 +7,11 @@
  */
 
 #include <QThread>
+#include <QDateTime>
 #include <QString>
 #include <QByteArray>
-#include <QDateTime>
-#include <QUrl>
 
-#include <polarssl/x509_crt.h>
-#include <polarssl/entropy.h>
-#include <polarssl/ctr_drbg.h>
-#include <polarssl/ssl.h>
+#include "sslconnection.h"
 
 class Downloader: public QThread
 {
@@ -38,26 +34,18 @@
      * @param[in] certificate optional certificate to validate https connection
      * @param[in] newestSW datetime after which software should be downloaded
      * @param[in] newestList datetime after which the list should be downloaded
+     * @param[in] resourceSW the path where the software is to be found
+     * @param[in] resourceList the path where the list is to be found
      */
     Downloader(QObject* parent, const QString& url,
                const QByteArray& certificate = QByteArray(),
                const QDateTime& newestSW = QDateTime(),
-               const QDateTime& newestList = QDateTime());
+               const QDateTime& newestList = QDateTime(),
+               const QString& resourceSW = QString(),
+               const QString& resourceList = QString());
 
     ~Downloader();
 
-    enum ErrorCode {
-        NoError,
-        NoConnection,
-        SSLHandshakeFailed,
-        InvalidCertificate,
-        InvalidPinnedCertificate,
-        InvalidResponse,
-        ConnectionLost,
-        Timeout,
-        ErrUnknown
-    };
-
     /**
      * @brief get the directory where the downloader saves data
      *
@@ -73,50 +61,19 @@
      *
      * @returns The current error state.
      **/
-    ErrorCode getErrorState();
+    SSLConnection::ErrorCode getErrorState();
 
 protected:
     void run();
 
 private:
-    QUrl mUrl;
-    QByteArray mPinnedCert;
-    x509_crt mX509PinnedCert;
-    entropy_context mEntropy;
-    ctr_drbg_context mCtr_drbg;
-    ssl_context mSSL;
-
     QDateTime mLastModSW;
     QDateTime mLastModList;
 
-    /* Convienience to avoid having to parse all
-     * PolarSSL errors */
-    ErrorCode mErrorState;
-
-    bool mInitialized;
-    bool mConnectionEstablished;
-
-    int mServerFD;
-
+    QString mResourceSW;
+    QString mResourceList;
 
-    /* @brief: Initialize polarssl structures
-     *
-     * This wraps polarssl initialization functions
-     * that can return an error.
-     * Sets the error state accordingly.
-     *
-     * @returns: 0 on success a polarssl error otherwise.
-     */
-    int init();
-
-    /** @brief: Establish the ssl connection
-     *
-     * Modifies the error state. Before calling this the mServerFD should
-     * be set to a valid socket.
-     *
-     * @returns 0 on success otherwise a polarssl error or -1 is returned
-     */
-    int establishSSLConnection();
+    SSLConnection mSSLConnection;
 
     /** @brief get the last modified header of a resource.
      *
@@ -170,6 +127,6 @@
      * @param[out] message: A message to show. Can be empty.
      * @param[out] errorCode: ErrorCode of this error.
      */
-    void error(const QString &message, Downloader::ErrorCode error);
+    void error(const QString &message, SSLConnection::ErrorCode error);
 };
 #endif

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