2015-05-15 16:34:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-05-27 15:59:28 +03:00
|
|
|
#include "owncloudlib.h"
|
2015-10-01 16:00:33 +03:00
|
|
|
#include "accountfwd.h"
|
2015-05-27 15:59:28 +03:00
|
|
|
|
2015-05-15 16:34:17 +03:00
|
|
|
#include <QObject>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The TransmissionChecksumValidator class
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2015-05-27 15:59:28 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT TransmissionChecksumValidator : public QObject
|
2015-05-15 16:34:17 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TransmissionChecksumValidator(const QString& filePath, QObject *parent = 0);
|
|
|
|
|
2015-05-21 15:32:08 +03:00
|
|
|
/**
|
|
|
|
* method to prepare a checksum for transmission and save it to the _checksum
|
|
|
|
* member of the SyncFileItem *item.
|
|
|
|
* The kind of requested checksum is taken from config. No need to set from outside.
|
|
|
|
*
|
|
|
|
* In any case of processing (checksum set, no checksum required and also unusual error)
|
|
|
|
* the object will emit the signal validated(). The item->_checksum is than either
|
|
|
|
* set to a proper value or empty.
|
|
|
|
*/
|
2015-05-21 16:51:48 +03:00
|
|
|
void uploadValidation();
|
2015-05-21 15:32:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* method to verify the checksum coming with requests in a checksum header. The required
|
|
|
|
* checksum method is read from config.
|
|
|
|
*
|
|
|
|
* If no checksum is there, or if a correct checksum is there, the signal validated()
|
|
|
|
* will be emitted. In case of any kind of error, the signal validationFailed() will
|
|
|
|
* be emitted.
|
|
|
|
*/
|
2015-05-15 16:34:17 +03:00
|
|
|
void downloadValidation( const QByteArray& checksumHeader );
|
|
|
|
|
2015-10-01 16:00:33 +03:00
|
|
|
/**
|
|
|
|
* By default the checksum type is read from the config file, but can be overridden
|
|
|
|
* with this method.
|
|
|
|
*/
|
|
|
|
void setChecksumType(const QString& type);
|
|
|
|
|
2015-05-21 15:32:08 +03:00
|
|
|
QString checksumType() const;
|
2015-05-15 16:34:17 +03:00
|
|
|
|
|
|
|
signals:
|
2015-05-21 16:51:48 +03:00
|
|
|
void validated(const QByteArray& checksum);
|
2015-05-15 16:34:17 +03:00
|
|
|
void validationFailed( const QString& errMsg );
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void slotUploadChecksumCalculated();
|
|
|
|
void slotDownloadChecksumCalculated();
|
|
|
|
|
|
|
|
private:
|
2015-10-01 16:00:33 +03:00
|
|
|
QString _checksumType;
|
2015-05-15 16:34:17 +03:00
|
|
|
QByteArray _expectedHash;
|
2015-05-21 16:51:48 +03:00
|
|
|
QByteArray _checksumHeader;
|
|
|
|
|
2015-05-15 16:34:17 +03:00
|
|
|
QString _filePath;
|
|
|
|
|
|
|
|
// watcher for the checksum calculation thread
|
|
|
|
QFutureWatcher<QByteArray> _watcher;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|