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-11-23 13:53:06 +03:00
|
|
|
class SyncJournalDb;
|
|
|
|
|
2015-10-14 16:03:40 +03:00
|
|
|
/// Creates a checksum header from type and value.
|
|
|
|
QByteArray makeChecksumHeader(const QByteArray& checksumType, const QByteArray& checksum);
|
|
|
|
|
|
|
|
/// Parses a checksum header
|
|
|
|
bool parseChecksumHeader(const QByteArray& header, QByteArray* type, QByteArray* checksum);
|
|
|
|
|
2015-10-15 10:39:49 +03:00
|
|
|
/// Checks OWNCLOUD_DISABLE_CHECKSUM_UPLOAD
|
|
|
|
bool uploadChecksumEnabled();
|
|
|
|
|
|
|
|
/// Checks OWNCLOUD_DISABLE_CHECKSUM_DOWNLOAD
|
|
|
|
bool downloadChecksumEnabled();
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
2015-10-14 16:03:40 +03:00
|
|
|
* Computes the checksum of a file.
|
|
|
|
* \ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2015-10-14 16:03:40 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT ComputeChecksum : public QObject
|
2015-05-15 16:34:17 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-10-14 16:03:40 +03:00
|
|
|
explicit ComputeChecksum(QObject* parent = 0);
|
|
|
|
|
|
|
|
/**
|
2015-10-15 10:54:01 +03:00
|
|
|
* Sets the checksum type to be used. The default is empty.
|
2015-10-14 16:03:40 +03:00
|
|
|
*/
|
|
|
|
void setChecksumType(const QByteArray& type);
|
|
|
|
|
|
|
|
QByteArray checksumType() const;
|
2015-05-15 16:34:17 +03:00
|
|
|
|
2015-05-21 15:32:08 +03:00
|
|
|
/**
|
2015-10-14 16:03:40 +03:00
|
|
|
* Computes the checksum for the given file path.
|
2015-05-21 15:32:08 +03:00
|
|
|
*
|
2015-10-14 16:03:40 +03:00
|
|
|
* done() is emitted when the calculation finishes.
|
2015-05-21 15:32:08 +03:00
|
|
|
*/
|
2015-10-14 16:03:40 +03:00
|
|
|
void start(const QString& filePath);
|
|
|
|
|
2015-11-23 13:53:06 +03:00
|
|
|
/**
|
|
|
|
* Computes the checksum synchronously.
|
|
|
|
*/
|
|
|
|
static QByteArray computeNow(const QString& filePath, const QByteArray& checksumType);
|
|
|
|
|
2015-10-14 16:03:40 +03:00
|
|
|
signals:
|
|
|
|
void done(const QByteArray& checksumType, const QByteArray& checksum);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void slotCalculationDone();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray _checksumType;
|
|
|
|
|
|
|
|
// watcher for the checksum calculation thread
|
|
|
|
QFutureWatcher<QByteArray> _watcher;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a file's checksum matches the expected value.
|
|
|
|
* @ingroup libsync
|
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT ValidateChecksumHeader : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ValidateChecksumHeader(QObject *parent = 0);
|
2015-05-21 15:32:08 +03:00
|
|
|
|
|
|
|
/**
|
2015-10-14 16:03:40 +03:00
|
|
|
* Check a file's actual checksum against the provided checksumHeader
|
2015-05-21 15:32:08 +03:00
|
|
|
*
|
|
|
|
* 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-10-14 16:03:40 +03:00
|
|
|
void start(const QString& filePath, const QByteArray& checksumHeader);
|
2015-05-15 16:34:17 +03:00
|
|
|
|
|
|
|
signals:
|
2015-10-28 13:00:03 +03:00
|
|
|
void validated(const QByteArray& checksumType, const QByteArray& checksum);
|
2015-05-15 16:34:17 +03:00
|
|
|
void validationFailed( const QString& errMsg );
|
|
|
|
|
|
|
|
private slots:
|
2015-10-14 16:03:40 +03:00
|
|
|
void slotChecksumCalculated(const QByteArray& checksumType, const QByteArray& checksum);
|
2015-05-15 16:34:17 +03:00
|
|
|
|
|
|
|
private:
|
2015-10-14 16:03:40 +03:00
|
|
|
QByteArray _expectedChecksumType;
|
|
|
|
QByteArray _expectedChecksum;
|
2015-05-15 16:34:17 +03:00
|
|
|
};
|
|
|
|
|
2015-11-23 13:53:06 +03:00
|
|
|
/**
|
|
|
|
* Hooks checksum computations into csync.
|
|
|
|
* @ingroup libsync
|
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT CSyncChecksumHook : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit CSyncChecksumHook(SyncJournalDb* journal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the checksum for \a path is the same as the one provided.
|
|
|
|
*
|
|
|
|
* Called from csync, where a instance of CSyncChecksumHook
|
|
|
|
* has to be set as userdata.
|
|
|
|
*/
|
|
|
|
static bool hook(const char* path, uint32_t checksumTypeId, const char* checksum,
|
|
|
|
void* this_obj);
|
|
|
|
|
|
|
|
bool check(const QString& path, int checksumTypeId, const QByteArray& checksum);
|
|
|
|
|
|
|
|
private:
|
|
|
|
SyncJournalDb* _journal;
|
|
|
|
};
|
|
|
|
|
2015-05-15 16:34:17 +03:00
|
|
|
}
|