Skip to content

Commit

Permalink
Checksums: Prepare 'supported checksums' capability #3735
Browse files Browse the repository at this point in the history
It currently always returns the empty list and thus has no effect.
  • Loading branch information
ckamm committed Oct 1, 2015
1 parent 24c41ed commit 3812fd0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
1 change: 1 addition & 0 deletions src/libsync/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OWNCLOUDSYNC_EXPORT Capabilities {
bool publicLinkEnforcePassword() const;
bool publicLinkEnforceExpireDate() const;
int publicLinkExpireDateDays() const;
QStringList supportedChecksumTypes() const;

private:
QVariantMap _capabilities;
Expand Down
12 changes: 12 additions & 0 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
17 changes: 7 additions & 10 deletions src/libsync/transmissionchecksumvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 8 additions & 4 deletions src/libsync/transmissionchecksumvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "owncloudlib.h"
#include "accountfwd.h"

#include <QObject>
#include <QByteArray>
Expand Down Expand Up @@ -53,9 +54,12 @@ class OWNCLOUDSYNC_EXPORT TransmissionChecksumValidator : public QObject
*/
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:
Expand All @@ -67,7 +71,7 @@ private slots:
void slotDownloadChecksumCalculated();

private:
QByteArray _checksumType;
QString _checksumType;
QByteArray _expectedHash;
QByteArray _checksumHeader;

Expand Down

0 comments on commit 3812fd0

Please sign in to comment.