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"
|
|
|
|
|
2015-10-15 10:54:01 +03:00
|
|
|
#include "configfile.h"
|
|
|
|
|
2015-07-16 22:49:12 +03:00
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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-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;
|
|
|
|
}
|
2015-07-16 22:49:12 +03:00
|
|
|
}
|