Mercurial > trustbridge
view ui/sslconnection.h @ 914:dcb6ed6ad594
Disable curl by default for Windows
This needs to be reevaluated once we have a working curl
in mxe
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 20 Aug 2014 16:52:44 +0200 |
parents | eaed02defe6a |
children | 879a634d0a40 |
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=2) * and comes with ABSOLUTELY NO WARRANTY! * See LICENSE.txt for details. */ #ifndef SSLCONNECTION_H #define SSLCONNECTION_H /** * @file sslconnection.h * @brief Qt wrapper around polarssl ssl api */ #include <QDebug> #include <QUrl> #include <QString> #include <QByteArray> class SSLConnection { public: enum ErrorCode { NoError, NoConnection, SSLHandshakeFailed, InvalidCertificate, InvalidPinnedCertificate, InvalidResponse, ConnectionLost, Timeout, ErrUnknown }; /** * @brief Construct a pinned SSL Connection * * @param[in] url the Url to connect to * @param[in] certificate optional certificate to validate https connection */ SSLConnection(const QString& url, const QByteArray& certificate = QByteArray()) : mUrl(url), mPinnedCert(certificate), mInitialized(false), mConnected(false), mNeedsReset(false), mServerFD(-1), mErrorState(NoError) {}; virtual ~SSLConnection() {}; bool initialized() { return mInitialized; } bool connected() { return mConnected; } ErrorCode getLastError() { return mErrorState; } /** @brief: Establish the connection * * @returns 0 on success otherwise an error or -1 is returned */ virtual int connect() = 0; /** @brief get the last modified header of a resource. * * Connection should be established beforehand. * Modifies the error state. * * @param[in] resource The resource to check * * @returns the last modified date or a null datetime in case of errors */ virtual QDateTime getLastModifiedHeader(const QString &resource) = 0; /** @brief Download resource * * Download a resource with the established connection. * Modifies the error state. * * @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. */ virtual bool downloadFile(const QString &resource, const QString &filename, size_t maxSize) = 0; protected: QUrl mUrl; QByteArray mPinnedCert; bool mInitialized; bool mConnected; /* A connection was established */ bool mNeedsReset; /* The connection needs to be reset before the next write */ int mServerFD; SSLConnection::ErrorCode mErrorState; }; #endif