aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ aheinecke@10: #ifndef DOWNLOADER_H aheinecke@10: #define DOWNLOADER_H aheinecke@10: /** aheinecke@10: * @file downloader.h aheinecke@10: * @brief High level API to download necessary data. aheinecke@10: * aheinecke@10: */ aheinecke@10: aheinecke@10: #include aheinecke@45: #include aheinecke@10: #include aheinecke@10: #include aheinecke@15: aheinecke@45: #include "sslconnection.h" aheinecke@10: andre@1255: /** @brief High level API to download necessary data. andre@1255: * andre@1255: * The downloader class is the UI interface to the Update server. andre@1255: * It controls the SSL Connection and checks if updates are available andre@1255: * and downloads them on demand. Each Downloader object is intended andre@1255: * to be run only once and controlled mainly by the constructor of andre@1255: * the object. andre@1255: */ aheinecke@10: class Downloader: public QThread aheinecke@10: { aheinecke@10: Q_OBJECT aheinecke@10: aheinecke@10: public: aheinecke@10: /** aheinecke@15: * @brief Construct a downloader with a specific certificate aheinecke@10: * aheinecke@15: * The downloader will check the last-modified date of the aheinecke@15: * certificate list / sw on the server at the specified url aheinecke@15: * and download those accordingly. If newestSW or newestList is aheinecke@15: * are valid datetimes only files modified after the respective date aheinecke@15: * are downloaded. aheinecke@15: * aheinecke@15: * Downloaded files are placed in QStandardPaths::DataLocation aheinecke@10: * aheinecke@10: * @param[in] parent the parent object. aheinecke@10: * @param[in] url the Url to download data from aheinecke@15: * @param[in] certificate optional certificate to validate https connection aheinecke@15: * @param[in] newestSW datetime after which software should be downloaded aheinecke@15: * @param[in] newestList datetime after which the list should be downloaded aheinecke@45: * @param[in] resourceSW the path where the software is to be found aheinecke@45: * @param[in] resourceList the path where the list is to be found emanuel@1053: * @param[in] downloadSW TODO aheinecke@10: */ aheinecke@10: Downloader(QObject* parent, const QString& url, aheinecke@15: const QByteArray& certificate = QByteArray(), aheinecke@15: const QDateTime& newestSW = QDateTime(), aheinecke@45: const QDateTime& newestList = QDateTime(), aheinecke@45: const QString& resourceSW = QString(), rrenkert@460: const QString& resourceList = QString(), rrenkert@460: bool downloadSW = true); aheinecke@10: andre@27: ~Downloader(); aheinecke@10: aheinecke@10: /** aheinecke@15: * @brief get the directory where the downloader saves data aheinecke@10: * aheinecke@15: * If the directory does not exist this function ensures that it aheinecke@15: * is created. aheinecke@15: * aheinecke@15: * @returns The directory in which downloaded files are placed. aheinecke@15: **/ aheinecke@15: QString getDataDirectory(); aheinecke@15: andre@27: /** andre@27: * @brief get the current error state andre@27: * andre@27: * @returns The current error state. andre@27: **/ aheinecke@45: SSLConnection::ErrorCode getErrorState(); aheinecke@10: andre@990: andre@990: /** andre@990: * @brief forward the setCiphersuites call to the sslconnection andre@990: * andre@990: * see sslconnection.h for details. andre@990: */ andre@990: void setCiphersuites(int suites[]); andre@990: aheinecke@10: protected: aheinecke@10: void run(); aheinecke@10: aheinecke@10: private: aheinecke@15: QDateTime mLastModSW; aheinecke@15: QDateTime mLastModList; aheinecke@15: aheinecke@45: QString mResourceSW; aheinecke@45: QString mResourceList; andre@27: rrenkert@460: bool mDownloadSW; rrenkert@460: andre@908: SSLConnection *mSSLConnection; andre@32: aheinecke@10: Q_SIGNALS: aheinecke@10: /** aheinecke@15: * @brief software update is available aheinecke@15: */ aheinecke@15: void newSoftwareAvailable(const QString &fileName, aheinecke@15: const QDateTime &lastMod); aheinecke@15: aheinecke@15: /** aheinecke@15: * @brief new certificate list available aheinecke@15: */ aheinecke@15: void newListAvailable(const QString &fileName, const QDateTime &lastMod); aheinecke@15: aheinecke@15: /** aheinecke@10: * @brief Some progress has been made. aheinecke@10: * aheinecke@10: * @param[out] message: A message to show. Can be empty. aheinecke@10: * @param[out] current: Value of current progress. aheinecke@10: * @param[out] total: Total value of possible progress aheinecke@10: */ aheinecke@10: void progress(const QString &message, int current, int total); aheinecke@10: aheinecke@10: /** aheinecke@10: * @brief An error happened aheinecke@10: * aheinecke@10: * @param[out] message: A message to show. Can be empty. emanuel@1053: * @param[out] error: ErrorCode of this error. aheinecke@10: */ aheinecke@45: void error(const QString &message, SSLConnection::ErrorCode error); rrenkert@485: rrenkert@485: /** rrenkert@485: * @brief Found the last modified date for software. rrenkert@485: * rrenkert@485: * @param[out] date The last modified date. rrenkert@485: */ rrenkert@485: void lastModifiedDate(const QDateTime &date); aheinecke@10: }; aheinecke@10: #endif