capabilities.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #ifndef CAPABILITIES_H
  15. #define CAPABILITIES_H
  16. #include "owncloudlib.h"
  17. #include <QVariantMap>
  18. #include <QStringList>
  19. #include <QMimeDatabase>
  20. #include <QColor>
  21. namespace OCC {
  22. class DirectEditor;
  23. enum PushNotificationType {
  24. None = 0,
  25. Files = 1,
  26. Activities = 2,
  27. Notifications = 4
  28. };
  29. Q_DECLARE_FLAGS(PushNotificationTypes, PushNotificationType)
  30. Q_DECLARE_OPERATORS_FOR_FLAGS(PushNotificationTypes)
  31. /**
  32. * @brief The Capabilities class represents the capabilities of an ownCloud
  33. * server
  34. * @ingroup libsync
  35. */
  36. class OWNCLOUDSYNC_EXPORT Capabilities
  37. {
  38. public:
  39. Capabilities(const QVariantMap &capabilities);
  40. [[nodiscard]] bool shareAPI() const;
  41. [[nodiscard]] bool shareEmailPasswordEnabled() const;
  42. [[nodiscard]] bool shareEmailPasswordEnforced() const;
  43. [[nodiscard]] bool sharePublicLink() const;
  44. [[nodiscard]] bool sharePublicLinkAllowUpload() const;
  45. [[nodiscard]] bool sharePublicLinkSupportsUploadOnly() const;
  46. [[nodiscard]] bool sharePublicLinkAskOptionalPassword() const;
  47. [[nodiscard]] bool sharePublicLinkEnforcePassword() const;
  48. [[nodiscard]] bool sharePublicLinkEnforceExpireDate() const;
  49. [[nodiscard]] int sharePublicLinkExpireDateDays() const;
  50. [[nodiscard]] bool shareInternalEnforceExpireDate() const;
  51. [[nodiscard]] int shareInternalExpireDateDays() const;
  52. [[nodiscard]] bool shareRemoteEnforceExpireDate() const;
  53. [[nodiscard]] int shareRemoteExpireDateDays() const;
  54. [[nodiscard]] bool sharePublicLinkMultiple() const;
  55. [[nodiscard]] bool shareResharing() const;
  56. [[nodiscard]] int shareDefaultPermissions() const;
  57. [[nodiscard]] bool chunkingNg() const;
  58. [[nodiscard]] bool bulkUpload() const;
  59. [[nodiscard]] bool filesLockAvailable() const;
  60. [[nodiscard]] bool userStatus() const;
  61. [[nodiscard]] bool userStatusSupportsEmoji() const;
  62. [[nodiscard]] QColor serverColor() const;
  63. [[nodiscard]] QColor serverTextColor() const;
  64. /// Returns which kind of push notfications are available
  65. [[nodiscard]] PushNotificationTypes availablePushNotifications() const;
  66. /// Websocket url for files push notifications if available
  67. [[nodiscard]] QUrl pushNotificationsWebSocketUrl() const;
  68. /// disable parallel upload in chunking
  69. [[nodiscard]] bool chunkingParallelUploadDisabled() const;
  70. /// Whether the "privatelink" DAV property is available
  71. [[nodiscard]] bool privateLinkPropertyAvailable() const;
  72. /// returns true if the capabilities report notifications
  73. [[nodiscard]] bool notificationsAvailable() const;
  74. /// returns true if the server supports client side encryption
  75. [[nodiscard]] bool clientSideEncryptionAvailable() const;
  76. [[nodiscard]] double clientSideEncryptionVersion() const;
  77. /// returns true if the capabilities are loaded already.
  78. [[nodiscard]] bool isValid() const;
  79. /// return true if the activity app is enabled
  80. [[nodiscard]] bool hasActivities() const;
  81. /**
  82. * Returns the checksum types the server understands.
  83. *
  84. * When the client uses one of these checksumming algorithms in
  85. * the OC-Checksum header of a file upload, the server will use
  86. * it to validate that data was transmitted correctly.
  87. *
  88. * Path: checksums/supportedTypes
  89. * Default: []
  90. * Possible entries: "Adler32", "MD5", "SHA1"
  91. */
  92. [[nodiscard]] QList<QByteArray> supportedChecksumTypes() const;
  93. /**
  94. * The checksum algorithm that the server recommends for file uploads.
  95. * This is just a preference, any algorithm listed in supportedTypes may be used.
  96. *
  97. * Path: checksums/preferredUploadType
  98. * Default: empty, meaning "no preference"
  99. * Possible values: empty or any of the supportedTypes
  100. */
  101. [[nodiscard]] QByteArray preferredUploadChecksumType() const;
  102. /**
  103. * Helper that returns the preferredUploadChecksumType() if set, or one
  104. * of the supportedChecksumTypes() if it isn't. May return an empty
  105. * QByteArray if no checksum types are supported.
  106. */
  107. [[nodiscard]] QByteArray uploadChecksumType() const;
  108. /**
  109. * List of HTTP error codes should be guaranteed to eventually reset
  110. * failing chunked uploads.
  111. *
  112. * The resetting works by tracking UploadInfo::errorCount.
  113. *
  114. * Note that other error codes than the ones listed here may reset the
  115. * upload as well.
  116. *
  117. * Motivation: See #5344. They should always be reset on 412 (possibly
  118. * checksum error), but broken servers may also require resets on
  119. * unusual error codes such as 503.
  120. *
  121. * Path: dav/httpErrorCodesThatResetFailingChunkedUploads
  122. * Default: []
  123. * Example: [503, 500]
  124. */
  125. [[nodiscard]] QList<int> httpErrorCodesThatResetFailingChunkedUploads() const;
  126. /**
  127. * Regex that, if contained in a filename, will result in it not being uploaded.
  128. *
  129. * For servers older than 8.1.0 it defaults to [\\:?*"<>|]
  130. * For servers >= that version, it defaults to the empty regex (the server
  131. * will indicate invalid characters through an upload error)
  132. *
  133. * Note that it just needs to be contained. The regex [ab] is contained in "car".
  134. */
  135. [[nodiscard]] QString invalidFilenameRegex() const;
  136. /**
  137. * return the list of filename that should not be uploaded
  138. */
  139. [[nodiscard]] QStringList blacklistedFiles() const;
  140. /**
  141. * Whether conflict files should remain local (default) or should be uploaded.
  142. */
  143. [[nodiscard]] bool uploadConflictFiles() const;
  144. [[nodiscard]] bool groupFoldersAvailable() const;
  145. // Direct Editing
  146. void addDirectEditor(DirectEditor* directEditor);
  147. DirectEditor* getDirectEditorForMimetype(const QMimeType &mimeType);
  148. DirectEditor* getDirectEditorForOptionalMimetype(const QMimeType &mimeType);
  149. private:
  150. [[nodiscard]] QMap<QString, QVariant> serverThemingMap() const;
  151. QVariantMap _capabilities;
  152. QList<DirectEditor*> _directEditors;
  153. };
  154. /*-------------------------------------------------------------------------------------*/
  155. class OWNCLOUDSYNC_EXPORT DirectEditor : public QObject
  156. {
  157. Q_OBJECT
  158. public:
  159. DirectEditor(const QString &id, const QString &name, QObject* parent = nullptr);
  160. void addMimetype(const QByteArray &mimeType);
  161. void addOptionalMimetype(const QByteArray &mimeType);
  162. bool hasMimetype(const QMimeType &mimeType);
  163. bool hasOptionalMimetype(const QMimeType &mimeType);
  164. [[nodiscard]] QString id() const;
  165. [[nodiscard]] QString name() const;
  166. [[nodiscard]] QList<QByteArray> mimeTypes() const;
  167. [[nodiscard]] QList<QByteArray> optionalMimeTypes() const;
  168. private:
  169. QString _id;
  170. QString _name;
  171. QList<QByteArray> _mimeTypes;
  172. QList<QByteArray> _optionalMimeTypes;
  173. };
  174. /*-------------------------------------------------------------------------------------*/
  175. }
  176. #endif //CAPABILITIES_H