-
Notifications
You must be signed in to change notification settings - Fork 667
/
capabilities.cpp
187 lines (156 loc) · 5.55 KB
/
capabilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* 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
* 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.
*/
#include "capabilities.h"
#include <QVariantMap>
#include <QDebug>
namespace OCC {
Capabilities::Capabilities(const QVariantMap &capabilities)
: _capabilities(capabilities)
{
}
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
{
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;
}
}
bool Capabilities::sharePublicLinkAllowUpload() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["upload"].toBool();
}
bool Capabilities::sharePublicLinkSupportsUploadOnly() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["supports_upload_only"].toBool();
}
bool Capabilities::sharePublicLinkEnforcePassword() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool();
}
bool Capabilities::sharePublicLinkDefaultExpire() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["enabled"].toBool();
}
int Capabilities::sharePublicLinkDefaultExpireDateDays() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt();
}
bool Capabilities::sharePublicLinkEnforceExpireDate() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["enforced"].toBool();
}
bool Capabilities::sharePublicLinkMultiple() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["multiple"].toBool();
}
bool Capabilities::shareResharing() const
{
return _capabilities["files_sharing"].toMap()["resharing"].toBool();
}
bool Capabilities::notificationsAvailable() const
{
// 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");
}
bool Capabilities::isValid() const
{
return !_capabilities.isEmpty();
}
QList<QByteArray> Capabilities::supportedChecksumTypes() const
{
QList<QByteArray> list;
foreach (const auto &t, _capabilities["checksums"].toMap()["supportedTypes"].toList()) {
list.push_back(t.toByteArray());
}
return list;
}
QByteArray Capabilities::preferredUploadChecksumType() const
{
return _capabilities["checksums"].toMap()["preferredUploadType"].toByteArray();
}
QByteArray Capabilities::uploadChecksumType() const
{
QByteArray preferred = preferredUploadChecksumType();
if (!preferred.isEmpty())
return preferred;
QList<QByteArray> supported = supportedChecksumTypes();
if (!supported.isEmpty())
return supported.first();
return QByteArray();
}
bool Capabilities::chunkingNg() const
{
static const auto chunkng = qgetenv("OWNCLOUD_CHUNKING_NG");
if (chunkng == "0")
return false;
if (chunkng == "1")
return true;
return _capabilities["dav"].toMap()["chunking"].toByteArray() >= "1.0";
}
bool Capabilities::chunkingParallelUploadDisabled() const
{
return _capabilities["dav"].toMap()["chunkingParallelUploadDisabled"].toBool();
}
bool Capabilities::privateLinkPropertyAvailable() const
{
return _capabilities["files"].toMap()["privateLinks"].toBool();
}
bool Capabilities::privateLinkDetailsParamAvailable() const
{
return _capabilities["files"].toMap()["privateLinksDetailsParam"].toBool();
}
QList<int> Capabilities::httpErrorCodesThatResetFailingChunkedUploads() const
{
QList<int> list;
foreach (const auto &t, _capabilities["dav"].toMap()["httpErrorCodesThatResetFailingChunkedUploads"].toList()) {
list.push_back(t.toInt());
}
return list;
}
QString Capabilities::invalidFilenameRegex() const
{
return _capabilities[QStringLiteral("dav")].toMap()[QStringLiteral("invalidFilenameRegex")].toString();
}
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[QStringLiteral("uploadConflictFiles")].toBool();
}
bool Capabilities::versioningEnabled() const
{
return _capabilities["files"].toMap()["versioning"].toBool();
}
QString Capabilities::zsyncSupportedVersion() const
{
return _capabilities[QStringLiteral("dav")].toMap()[QStringLiteral("zsync")].toString();
}
QStringList Capabilities::blacklistedFiles() const
{
return _capabilities["files"].toMap()["blacklisted_files"].toStringList();
}
}