2015-07-16 22:49:12 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-07-16 22:49:12 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "capabilities.h"
|
|
|
|
|
|
|
|
#include <QVariantMap>
|
2017-09-11 12:31:25 +03:00
|
|
|
#include <QLoggingCategory>
|
2018-01-29 16:06:12 +03:00
|
|
|
|
2017-09-11 12:31:25 +03:00
|
|
|
#include <QDebug>
|
2015-07-16 22:49:12 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2017-12-28 22:33:10 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcServerCapabilities, "nextcloud.sync.server.capabilities", QtInfoMsg)
|
2017-09-11 12:31:25 +03:00
|
|
|
|
2015-07-16 22:49:12 +03:00
|
|
|
|
2015-07-29 13:05:00 +03:00
|
|
|
Capabilities::Capabilities(const QVariantMap &capabilities)
|
2015-07-16 22:49:12 +03:00
|
|
|
: _capabilities(capabilities)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:07:45 +03:00
|
|
|
bool Capabilities::shareAPI() const
|
|
|
|
{
|
|
|
|
if (_capabilities["files_sharing"].toMap().contains("api_enabled")) {
|
|
|
|
return _capabilities["files_sharing"].toMap()["api_enabled"].toBool();
|
|
|
|
} else {
|
|
|
|
// This was later added so if it is not present just assume the API is enabled.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Capabilities::sharePublicLink() const
|
|
|
|
{
|
2015-11-30 18:55:06 +03:00
|
|
|
if (_capabilities["files_sharing"].toMap().contains("public")) {
|
|
|
|
return shareAPI() && _capabilities["files_sharing"].toMap()["public"].toMap()["enabled"].toBool();
|
|
|
|
} else {
|
|
|
|
// This was later added so if it is not present just assume that link sharing is enabled.
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-06 10:07:45 +03:00
|
|
|
}
|
|
|
|
|
2015-08-20 14:39:44 +03:00
|
|
|
bool Capabilities::sharePublicLinkAllowUpload() const
|
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["upload"].toBool();
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:38:22 +03:00
|
|
|
bool Capabilities::sharePublicLinkSupportsUploadOnly() const
|
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["supports_upload_only"].toBool();
|
|
|
|
}
|
|
|
|
|
2020-10-06 13:45:19 +03:00
|
|
|
bool Capabilities::sharePublicLinkAskOptionalPassword() const
|
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["password"].toMap()["askForOptionalPassword"].toBool();
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:07:45 +03:00
|
|
|
bool Capabilities::sharePublicLinkEnforcePassword() const
|
2015-07-16 22:49:12 +03:00
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool();
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:07:45 +03:00
|
|
|
bool Capabilities::sharePublicLinkEnforceExpireDate() const
|
2015-07-16 22:49:12 +03:00
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["enforced"].toBool();
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:07:45 +03:00
|
|
|
int Capabilities::sharePublicLinkExpireDateDays() const
|
2015-07-16 22:49:12 +03:00
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt();
|
|
|
|
}
|
|
|
|
|
2017-04-21 15:08:00 +03:00
|
|
|
bool Capabilities::sharePublicLinkMultiple() const
|
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["public"].toMap()["multiple"].toBool();
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:07:45 +03:00
|
|
|
bool Capabilities::shareResharing() const
|
|
|
|
{
|
|
|
|
return _capabilities["files_sharing"].toMap()["resharing"].toBool();
|
|
|
|
}
|
|
|
|
|
2020-06-17 14:31:30 +03:00
|
|
|
bool Capabilities::clientSideEncryptionAvailable() const
|
2017-09-03 14:33:50 +03:00
|
|
|
{
|
2017-12-29 22:45:48 +03:00
|
|
|
auto it = _capabilities.constFind(QStringLiteral("end-to-end-encryption"));
|
2020-07-15 16:26:45 +03:00
|
|
|
if (it == _capabilities.constEnd()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto properties = (*it).toMap();
|
|
|
|
const auto enabled = properties.value(QStringLiteral("enabled"), false).toBool();
|
|
|
|
if (!enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto version = properties.value(QStringLiteral("api-version"), "1.0").toByteArray();
|
|
|
|
qCInfo(lcServerCapabilities) << "E2EE API version:" << version;
|
|
|
|
const auto splittedVersion = version.split('.');
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
const auto major = !splittedVersion.isEmpty() ? splittedVersion.at(0).toInt(&ok) : 0;
|
|
|
|
if (!ok) {
|
|
|
|
qCWarning(lcServerCapabilities) << "Didn't understand version scheme (major), E2EE disabled";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = false;
|
|
|
|
const auto minor = splittedVersion.size() > 1 ? splittedVersion.at(1).toInt(&ok) : 0;
|
|
|
|
if (!ok) {
|
|
|
|
qCWarning(lcServerCapabilities) << "Didn't understand version scheme (minor), E2EE disabled";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return major == 1 && minor >= 1;
|
2017-09-03 14:33:50 +03:00
|
|
|
}
|
|
|
|
|
2016-03-09 19:19:36 +03:00
|
|
|
bool Capabilities::notificationsAvailable() const
|
|
|
|
{
|
2016-07-04 19:30:13 +03:00
|
|
|
// We require the OCS style API in 9.x, can't deal with the REST one only found in 8.2
|
|
|
|
return _capabilities.contains("notifications") && _capabilities["notifications"].toMap().contains("ocs-endpoints");
|
2016-03-09 19:19:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Capabilities::isValid() const
|
|
|
|
{
|
|
|
|
return !_capabilities.isEmpty();
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:09:29 +03:00
|
|
|
bool Capabilities::hasActivities() const
|
|
|
|
{
|
2018-11-19 16:13:51 +03:00
|
|
|
return _capabilities.contains("activity");
|
|
|
|
}
|
|
|
|
|
2015-10-15 10:54:01 +03:00
|
|
|
QList<QByteArray> Capabilities::supportedChecksumTypes() const
|
|
|
|
{
|
2016-04-12 11:12:35 +03:00
|
|
|
QList<QByteArray> list;
|
|
|
|
foreach (const auto &t, _capabilities["checksums"].toMap()["supportedTypes"].toList()) {
|
|
|
|
list.push_back(t.toByteArray());
|
2015-10-15 10:54:01 +03:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-04-12 11:12:35 +03:00
|
|
|
QByteArray Capabilities::preferredUploadChecksumType() const
|
2015-10-15 10:54:01 +03:00
|
|
|
{
|
2016-04-12 11:12:35 +03:00
|
|
|
return _capabilities["checksums"].toMap()["preferredUploadType"].toByteArray();
|
2015-10-15 10:54:01 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 14:10:53 +03:00
|
|
|
QByteArray Capabilities::uploadChecksumType() const
|
|
|
|
{
|
|
|
|
QByteArray preferred = preferredUploadChecksumType();
|
|
|
|
if (!preferred.isEmpty())
|
|
|
|
return preferred;
|
|
|
|
QList<QByteArray> supported = supportedChecksumTypes();
|
|
|
|
if (!supported.isEmpty())
|
|
|
|
return supported.first();
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
2016-10-21 17:42:27 +03:00
|
|
|
bool Capabilities::chunkingNg() const
|
|
|
|
{
|
2016-11-16 11:30:29 +03:00
|
|
|
static const auto chunkng = qgetenv("OWNCLOUD_CHUNKING_NG");
|
|
|
|
if (chunkng == "0")
|
|
|
|
return false;
|
|
|
|
if (chunkng == "1")
|
|
|
|
return true;
|
2016-10-21 17:42:27 +03:00
|
|
|
return _capabilities["dav"].toMap()["chunking"].toByteArray() >= "1.0";
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:08:45 +03:00
|
|
|
bool Capabilities::chunkingParallelUploadDisabled() const
|
|
|
|
{
|
|
|
|
return _capabilities["dav"].toMap()["chunkingParallelUploadDisabled"].toBool();
|
|
|
|
}
|
2016-10-21 17:42:27 +03:00
|
|
|
|
2017-09-15 15:24:34 +03:00
|
|
|
bool Capabilities::privateLinkPropertyAvailable() const
|
|
|
|
{
|
|
|
|
return _capabilities["files"].toMap()["privateLinks"].toBool();
|
|
|
|
}
|
|
|
|
|
2017-01-13 16:44:45 +03:00
|
|
|
QList<int> Capabilities::httpErrorCodesThatResetFailingChunkedUploads() const
|
|
|
|
{
|
|
|
|
QList<int> list;
|
|
|
|
foreach (const auto &t, _capabilities["dav"].toMap()["httpErrorCodesThatResetFailingChunkedUploads"].toList()) {
|
|
|
|
list.push_back(t.toInt());
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2017-10-13 15:56:40 +03:00
|
|
|
|
|
|
|
QString Capabilities::invalidFilenameRegex() const
|
|
|
|
{
|
|
|
|
return _capabilities["dav"].toMap()["invalidFilenameRegex"].toString();
|
|
|
|
}
|
2017-12-02 13:40:43 +03:00
|
|
|
|
|
|
|
bool Capabilities::uploadConflictFiles() const
|
|
|
|
{
|
|
|
|
static auto envIsSet = !qEnvironmentVariableIsEmpty("OWNCLOUD_UPLOAD_CONFLICT_FILES");
|
|
|
|
static int envValue = qEnvironmentVariableIntValue("OWNCLOUD_UPLOAD_CONFLICT_FILES");
|
|
|
|
if (envIsSet)
|
|
|
|
return envValue != 0;
|
|
|
|
|
|
|
|
return _capabilities["uploadConflictFiles"].toBool();
|
|
|
|
}
|
2020-01-18 17:07:51 +03:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// Direct Editing
|
|
|
|
void Capabilities::addDirectEditor(DirectEditor* directEditor)
|
|
|
|
{
|
|
|
|
if(directEditor)
|
|
|
|
_directEditors.append(directEditor);
|
|
|
|
}
|
|
|
|
|
|
|
|
DirectEditor* Capabilities::getDirectEditorForMimetype(const QMimeType &mimeType)
|
|
|
|
{
|
|
|
|
foreach(DirectEditor* editor, _directEditors) {
|
|
|
|
if(editor->hasMimetype(mimeType))
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DirectEditor* Capabilities::getDirectEditorForOptionalMimetype(const QMimeType &mimeType)
|
|
|
|
{
|
|
|
|
foreach(DirectEditor* editor, _directEditors) {
|
|
|
|
if(editor->hasOptionalMimetype(mimeType))
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DirectEditor::DirectEditor(const QString &id, const QString &name, QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, _id(id)
|
|
|
|
, _name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DirectEditor::id() const
|
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DirectEditor::name() const
|
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirectEditor::addMimetype(const QByteArray &mimeType)
|
|
|
|
{
|
|
|
|
_mimeTypes.append(mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirectEditor::addOptionalMimetype(const QByteArray &mimeType)
|
|
|
|
{
|
|
|
|
_optionalMimeTypes.append(mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QByteArray> DirectEditor::mimeTypes() const
|
|
|
|
{
|
|
|
|
return _mimeTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QByteArray> DirectEditor::optionalMimeTypes() const
|
|
|
|
{
|
|
|
|
return _optionalMimeTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DirectEditor::hasMimetype(const QMimeType &mimeType)
|
|
|
|
{
|
|
|
|
return _mimeTypes.contains(mimeType.name().toLatin1());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DirectEditor::hasOptionalMimetype(const QMimeType &mimeType)
|
|
|
|
{
|
|
|
|
return _optionalMimeTypes.contains(mimeType.name().toLatin1());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------------------*/
|
|
|
|
|
2015-07-16 22:49:12 +03:00
|
|
|
}
|