Checksums: Prepare 'supported checksums' capability #3735

It currently always returns the empty list and thus has no effect.
This commit is contained in:
Christian Kamm 2015-10-01 15:00:33 +02:00
parent 24c41ed0da
commit 3812fd0866
5 changed files with 33 additions and 14 deletions

View file

@ -38,4 +38,9 @@ int Capabilities::publicLinkExpireDateDays() const
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt();
}
QStringList Capabilities::supportedChecksumTypes() const
{
return QStringList();
}
}

View file

@ -34,6 +34,7 @@ public:
bool publicLinkEnforcePassword() const;
bool publicLinkEnforceExpireDate() const;
int publicLinkExpireDateDays() const;
QStringList supportedChecksumTypes() const;
private:
QVariantMap _capabilities;

View file

@ -213,6 +213,18 @@ void PropagateUploadFileQNAM::start()
// in any case, the validator will emit signal startUpload to let the flow
// continue in slotStartUpload here.
TransmissionChecksumValidator *validator = new TransmissionChecksumValidator(filePath, this);
// If the config file does not specify a checksum type but the
// server supports it choose a type based on that.
if (validator->checksumType().isEmpty()) {
QStringList checksumTypes = _propagator->account()->capabilities().supportedChecksumTypes();
if (!checksumTypes.isEmpty()) {
// TODO: We might want to prefer some types over others instead
// of choosing the first.
validator->setChecksumType(checksumTypes.first());
}
}
connect(validator, SIGNAL(validated(QByteArray)), this, SLOT(slotStartUpload(QByteArray)));
validator->uploadValidation();
}

View file

@ -17,32 +17,29 @@
#include "syncfileitem.h"
#include "propagatorjobs.h"
#include "configfile.h"
#include "account.h"
#include <qtconcurrentrun.h>
namespace OCC {
TransmissionChecksumValidator::TransmissionChecksumValidator(const QString& filePath, QObject *parent)
:QObject(parent),
: QObject(parent),
_filePath(filePath)
{
// If the config file specifies a checksum type, use that.
ConfigFile cfg;
_checksumType = cfg.transmissionChecksum();
}
void TransmissionChecksumValidator::setChecksumType( const QByteArray& type )
void TransmissionChecksumValidator::setChecksumType(const QString& type)
{
_checksumType = type;
}
QString TransmissionChecksumValidator::checksumType() const
{
QString checksumType = _checksumType;
if( checksumType.isEmpty() ) {
ConfigFile cfg;
checksumType = cfg.transmissionChecksum();
}
return checksumType;
return _checksumType;
}
void TransmissionChecksumValidator::uploadValidation()

View file

@ -15,6 +15,7 @@
#pragma once
#include "owncloudlib.h"
#include "accountfwd.h"
#include <QObject>
#include <QByteArray>
@ -53,9 +54,12 @@ public:
*/
void downloadValidation( const QByteArray& checksumHeader );
// This is only used in test cases (by now). This class reads the required
// test case from the config file.
void setChecksumType(const QByteArray &type );
/**
* By default the checksum type is read from the config file, but can be overridden
* with this method.
*/
void setChecksumType(const QString& type);
QString checksumType() const;
signals:
@ -67,7 +71,7 @@ private slots:
void slotDownloadChecksumCalculated();
private:
QByteArray _checksumType;
QString _checksumType;
QByteArray _expectedHash;
QByteArray _checksumHeader;