diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a32ee4ea..1bde998d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,6 @@ if (API_GENERATION_ENABLED) ${ABS_GTAD_PATH} --config ../gtad/gtad.yaml --out ${CSAPI_DIR} ${FULL_CSAPI_SRC_DIR} old_sync.yaml- room_initial_sync.yaml- # deprecated - key_backup.yaml- # immature and buggy in terms of API definition sync.yaml- # we have a better handcrafted implementation ${GTAD_ARGS} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/Quotient diff --git a/Quotient/csapi/administrative_contact.h b/Quotient/csapi/administrative_contact.h index b5d494345..6bbe81c06 100644 --- a/Quotient/csapi/administrative_contact.h +++ b/Quotient/csapi/administrative_contact.h @@ -8,6 +8,7 @@ #include #include #include + #include namespace Quotient { diff --git a/Quotient/csapi/content-repo.h b/Quotient/csapi/content-repo.h index e2035f7ff..063041311 100644 --- a/Quotient/csapi/content-repo.h +++ b/Quotient/csapi/content-repo.h @@ -4,11 +4,11 @@ #pragma once +#include + #include #include -#include - namespace Quotient { /*! \brief Upload some content to the content repository. diff --git a/Quotient/csapi/cross_signing.h b/Quotient/csapi/cross_signing.h index 0363cb763..b6bbbaaa5 100644 --- a/Quotient/csapi/cross_signing.h +++ b/Quotient/csapi/cross_signing.h @@ -6,6 +6,7 @@ #include #include + #include namespace Quotient { diff --git a/Quotient/csapi/definitions/key_backup_data.h b/Quotient/csapi/definitions/key_backup_data.h new file mode 100644 index 000000000..f7c2f050b --- /dev/null +++ b/Quotient/csapi/definitions/key_backup_data.h @@ -0,0 +1,49 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include + +namespace Quotient { +/// The key data +struct KeyBackupData { + /// The index of the first message in the session that the key can decrypt. + int firstMessageIndex; + + /// The number of times this key has been forwarded via key-sharing between + /// devices. + int forwardedCount; + + /// Whether the device backing up the key verified the device that the key + /// is from. + bool isVerified; + + /// Algorithm-dependent data. See the documentation for the backup + /// algorithms in [Server-side key + /// backups](/client-server-api/#server-side-key-backups) for more + /// information on the expected format of the data. + QJsonObject sessionData; +}; + +template <> +struct JsonObjectConverter { + static void dumpTo(QJsonObject& jo, const KeyBackupData& pod) + { + addParam<>(jo, QStringLiteral("first_message_index"), + pod.firstMessageIndex); + addParam<>(jo, QStringLiteral("forwarded_count"), pod.forwardedCount); + addParam<>(jo, QStringLiteral("is_verified"), pod.isVerified); + addParam<>(jo, QStringLiteral("session_data"), pod.sessionData); + } + static void fillFrom(const QJsonObject& jo, KeyBackupData& pod) + { + fillFromJson(jo.value("first_message_index"_ls), pod.firstMessageIndex); + fillFromJson(jo.value("forwarded_count"_ls), pod.forwardedCount); + fillFromJson(jo.value("is_verified"_ls), pod.isVerified); + fillFromJson(jo.value("session_data"_ls), pod.sessionData); + } +}; + +} // namespace Quotient diff --git a/Quotient/csapi/definitions/push_rule.h b/Quotient/csapi/definitions/push_rule.h index cd11c626d..755c60294 100644 --- a/Quotient/csapi/definitions/push_rule.h +++ b/Quotient/csapi/definitions/push_rule.h @@ -4,9 +4,10 @@ #pragma once -#include #include +#include + namespace Quotient { struct PushRule { diff --git a/Quotient/csapi/definitions/push_ruleset.h b/Quotient/csapi/definitions/push_ruleset.h index 00f684113..1b9c5cf35 100644 --- a/Quotient/csapi/definitions/push_ruleset.h +++ b/Quotient/csapi/definitions/push_ruleset.h @@ -4,9 +4,10 @@ #pragma once -#include #include +#include + namespace Quotient { struct PushRuleset { diff --git a/Quotient/csapi/definitions/room_event_filter.h b/Quotient/csapi/definitions/room_event_filter.h index 6e38e3ee5..f79406d12 100644 --- a/Quotient/csapi/definitions/room_event_filter.h +++ b/Quotient/csapi/definitions/room_event_filter.h @@ -4,9 +4,10 @@ #pragma once -#include #include +#include + namespace Quotient { struct RoomEventFilter : EventFilter { diff --git a/Quotient/csapi/definitions/room_key_backup.h b/Quotient/csapi/definitions/room_key_backup.h new file mode 100644 index 000000000..6b2bf11e5 --- /dev/null +++ b/Quotient/csapi/definitions/room_key_backup.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include + +#include + +namespace Quotient { +/// The backed up keys for a room. +struct RoomKeyBackup { + /// A map of session IDs to key data. + QHash sessions; +}; + +template <> +struct JsonObjectConverter { + static void dumpTo(QJsonObject& jo, const RoomKeyBackup& pod) + { + addParam<>(jo, QStringLiteral("sessions"), pod.sessions); + } + static void fillFrom(const QJsonObject& jo, RoomKeyBackup& pod) + { + fillFromJson(jo.value("sessions"_ls), pod.sessions); + } +}; + +} // namespace Quotient diff --git a/Quotient/csapi/definitions/sync_filter.h b/Quotient/csapi/definitions/sync_filter.h index ae7260e72..09d6c2af2 100644 --- a/Quotient/csapi/definitions/sync_filter.h +++ b/Quotient/csapi/definitions/sync_filter.h @@ -4,10 +4,11 @@ #pragma once -#include #include #include +#include + namespace Quotient { /// Filters to be applied to room data. struct RoomFilter { diff --git a/Quotient/csapi/definitions/wellknown/full.h b/Quotient/csapi/definitions/wellknown/full.h index f43469f5b..73b9f70bd 100644 --- a/Quotient/csapi/definitions/wellknown/full.h +++ b/Quotient/csapi/definitions/wellknown/full.h @@ -4,10 +4,11 @@ #pragma once -#include #include #include +#include + namespace Quotient { /// Used by clients to determine the homeserver, identity server, and other /// optional components they should be interacting with. diff --git a/Quotient/csapi/device_management.h b/Quotient/csapi/device_management.h index 62e0b2856..fed0a2d0e 100644 --- a/Quotient/csapi/device_management.h +++ b/Quotient/csapi/device_management.h @@ -6,6 +6,7 @@ #include #include + #include namespace Quotient { diff --git a/Quotient/csapi/filter.h b/Quotient/csapi/filter.h index 22bb29872..1d405899b 100644 --- a/Quotient/csapi/filter.h +++ b/Quotient/csapi/filter.h @@ -5,6 +5,7 @@ #pragma once #include + #include namespace Quotient { diff --git a/Quotient/csapi/joining.h b/Quotient/csapi/joining.h index 2c70774e9..d3e15e3b1 100644 --- a/Quotient/csapi/joining.h +++ b/Quotient/csapi/joining.h @@ -5,6 +5,7 @@ #pragma once #include + #include namespace Quotient { diff --git a/Quotient/csapi/key_backup.cpp b/Quotient/csapi/key_backup.cpp new file mode 100644 index 000000000..68857c3a6 --- /dev/null +++ b/Quotient/csapi/key_backup.cpp @@ -0,0 +1,295 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "key_backup.h" + +using namespace Quotient; + +PostRoomKeysVersionJob::PostRoomKeysVersionJob(const QString& algorithm, + const QJsonObject& authData) + : BaseJob(HttpVerb::Post, QStringLiteral("PostRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version")) +{ + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("algorithm"), algorithm); + addParam<>(_dataJson, QStringLiteral("auth_data"), authData); + setRequestData({ _dataJson }); + addExpectedKey("version"); +} + +QUrl GetRoomKeysVersionCurrentJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/version")); +} + +GetRoomKeysVersionCurrentJob::GetRoomKeysVersionCurrentJob() + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysVersionCurrentJob"), + makePath("/_matrix/client/v3", "/room_keys/version")) +{ + addExpectedKey("algorithm"); + addExpectedKey("auth_data"); + addExpectedKey("count"); + addExpectedKey("etag"); + addExpectedKey("version"); +} + +QUrl GetRoomKeysVersionJob::makeRequestUrl(QUrl baseUrl, const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/version/", version)); +} + +GetRoomKeysVersionJob::GetRoomKeysVersionJob(const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version/", version)) +{ + addExpectedKey("algorithm"); + addExpectedKey("auth_data"); + addExpectedKey("count"); + addExpectedKey("etag"); + addExpectedKey("version"); +} + +PutRoomKeysVersionJob::PutRoomKeysVersionJob(const QString& version, + const QString& algorithm, + const QJsonObject& authData) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version/", version)) +{ + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("algorithm"), algorithm); + addParam<>(_dataJson, QStringLiteral("auth_data"), authData); + setRequestData({ _dataJson }); +} + +QUrl DeleteRoomKeysVersionJob::makeRequestUrl(QUrl baseUrl, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/version/", version)); +} + +DeleteRoomKeysVersionJob::DeleteRoomKeysVersionJob(const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version/", version)) +{} + +auto queryToPutRoomKeyBySessionId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +PutRoomKeyBySessionIdJob::PutRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version, + const KeyBackupData& data) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeyBySessionIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", + sessionId), + queryToPutRoomKeyBySessionId(version)) +{ + setRequestData({ toJson(data) }); + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToGetRoomKeyBySessionId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl GetRoomKeyBySessionIdJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId, + const QString& sessionId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId, "/", + sessionId), + queryToGetRoomKeyBySessionId(version)); +} + +GetRoomKeyBySessionIdJob::GetRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeyBySessionIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", + sessionId), + queryToGetRoomKeyBySessionId(version)) +{} + +auto queryToDeleteRoomKeyBySessionId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl DeleteRoomKeyBySessionIdJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId, + const QString& sessionId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId, "/", + sessionId), + queryToDeleteRoomKeyBySessionId(version)); +} + +DeleteRoomKeyBySessionIdJob::DeleteRoomKeyBySessionIdJob( + const QString& roomId, const QString& sessionId, const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeyBySessionIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", + sessionId), + queryToDeleteRoomKeyBySessionId(version)) +{ + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToPutRoomKeysByRoomId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +PutRoomKeysByRoomIdJob::PutRoomKeysByRoomIdJob(const QString& roomId, + const QString& version, + const RoomKeyBackup& backupData) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeysByRoomIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId), + queryToPutRoomKeysByRoomId(version)) +{ + setRequestData({ toJson(backupData) }); + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToGetRoomKeysByRoomId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl GetRoomKeysByRoomIdJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId), + queryToGetRoomKeysByRoomId(version)); +} + +GetRoomKeysByRoomIdJob::GetRoomKeysByRoomIdJob(const QString& roomId, + const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysByRoomIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId), + queryToGetRoomKeysByRoomId(version)) +{} + +auto queryToDeleteRoomKeysByRoomId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl DeleteRoomKeysByRoomIdJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId), + queryToDeleteRoomKeysByRoomId(version)); +} + +DeleteRoomKeysByRoomIdJob::DeleteRoomKeysByRoomIdJob(const QString& roomId, + const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeysByRoomIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId), + queryToDeleteRoomKeysByRoomId(version)) +{ + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToPutRoomKeys(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +PutRoomKeysJob::PutRoomKeysJob(const QString& version, + const QHash& rooms) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeysJob"), + makePath("/_matrix/client/v3", "/room_keys/keys"), + queryToPutRoomKeys(version)) +{ + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("rooms"), rooms); + setRequestData({ _dataJson }); + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToGetRoomKeys(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl GetRoomKeysJob::makeRequestUrl(QUrl baseUrl, const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys"), + queryToGetRoomKeys(version)); +} + +GetRoomKeysJob::GetRoomKeysJob(const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysJob"), + makePath("/_matrix/client/v3", "/room_keys/keys"), + queryToGetRoomKeys(version)) +{ + addExpectedKey("rooms"); +} + +auto queryToDeleteRoomKeys(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl DeleteRoomKeysJob::makeRequestUrl(QUrl baseUrl, const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys"), + queryToDeleteRoomKeys(version)); +} + +DeleteRoomKeysJob::DeleteRoomKeysJob(const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeysJob"), + makePath("/_matrix/client/v3", "/room_keys/keys"), + queryToDeleteRoomKeys(version)) +{ + addExpectedKey("etag"); + addExpectedKey("count"); +} diff --git a/Quotient/csapi/key_backup.h b/Quotient/csapi/key_backup.h new file mode 100644 index 000000000..c7fb6124c --- /dev/null +++ b/Quotient/csapi/key_backup.h @@ -0,0 +1,486 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include +#include + +#include + +namespace Quotient { + +/*! \brief Create a new backup. + * + * Creates a new backup. + */ +class QUOTIENT_API PostRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Create a new backup. + * + * \param algorithm + * The algorithm used for storing backups. + * + * \param authData + * Algorithm-dependent data. See the documentation for the backup + * algorithms in [Server-side key + * backups](/client-server-api/#server-side-key-backups) for more + * information on the expected format of the data. + */ + explicit PostRoomKeysVersionJob(const QString& algorithm, + const QJsonObject& authData); + + // Result properties + + /// The backup version. This is an opaque string. + QString version() const { return loadFromJson("version"_ls); } +}; + +/*! \brief Get information about the latest backup version. + * + * Get information about the latest backup version. + */ +class QUOTIENT_API GetRoomKeysVersionCurrentJob : public BaseJob { +public: + /// Get information about the latest backup version. + explicit GetRoomKeysVersionCurrentJob(); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysVersionCurrentJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + // Result properties + + /// The algorithm used for storing backups. + QString algorithm() const { return loadFromJson("algorithm"_ls); } + + /// Algorithm-dependent data. See the documentation for the backup + /// algorithms in [Server-side key + /// backups](/client-server-api/#server-side-key-backups) for more + /// information on the expected format of the data. + QJsonObject authData() const + { + return loadFromJson("auth_data"_ls); + } + + /// The number of keys stored in the backup. + int count() const { return loadFromJson("count"_ls); } + + /// An opaque string representing stored keys in the backup. + /// Clients can compare it with the `etag` value they received + /// in the request of their last key storage request. If not + /// equal, another client has modified the backup. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The backup version. + QString version() const { return loadFromJson("version"_ls); } +}; + +/*! \brief Get information about an existing backup. + * + * Get information about an existing backup. + */ +class QUOTIENT_API GetRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Get information about an existing backup. + * + * \param version + * The backup version to get, as returned in the `version` parameter + * of the response in + * [`POST + * /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion) + * or this endpoint. + */ + explicit GetRoomKeysVersionJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysVersionJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); + + // Result properties + + /// The algorithm used for storing backups. + QString algorithm() const { return loadFromJson("algorithm"_ls); } + + /// Algorithm-dependent data. See the documentation for the backup + /// algorithms in [Server-side key + /// backups](/client-server-api/#server-side-key-backups) for more + /// information on the expected format of the data. + QJsonObject authData() const + { + return loadFromJson("auth_data"_ls); + } + + /// The number of keys stored in the backup. + int count() const { return loadFromJson("count"_ls); } + + /// An opaque string representing stored keys in the backup. + /// Clients can compare it with the `etag` value they received + /// in the request of their last key storage request. If not + /// equal, another client has modified the backup. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The backup version. + QString version() const { return loadFromJson("version"_ls); } +}; + +/*! \brief Update information about an existing backup. + * + * Update information about an existing backup. Only `auth_data` can be + * modified. + */ +class QUOTIENT_API PutRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Update information about an existing backup. + * + * \param version + * The backup version to update, as returned in the `version` + * parameter in the response of + * [`POST + * /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion) + * or [`GET + * /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion). + * + * \param algorithm + * The algorithm used for storing backups. Must be the same as + * the algorithm currently used by the backup. + * + * \param authData + * Algorithm-dependent data. See the documentation for the backup + * algorithms in [Server-side key + * backups](/client-server-api/#server-side-key-backups) for more + * information on the expected format of the data. + */ + explicit PutRoomKeysVersionJob(const QString& version, + const QString& algorithm, + const QJsonObject& authData); +}; + +/*! \brief Delete an existing key backup. + * + * Delete an existing key backup. Both the information about the backup, + * as well as all key data related to the backup will be deleted. + */ +class QUOTIENT_API DeleteRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Delete an existing key backup. + * + * \param version + * The backup version to delete, as returned in the `version` + * parameter in the response of + * [`POST + * /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion) + * or [`GET + * /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion). + */ + explicit DeleteRoomKeysVersionJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeysVersionJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); +}; + +/*! \brief Store a key in the backup. + * + * Store a key in the backup. + */ +class QUOTIENT_API PutRoomKeyBySessionIdJob : public BaseJob { +public: + /*! \brief Store a key in the backup. + * + * \param roomId + * The ID of the room that the key is for. + * + * \param sessionId + * The ID of the megolm session that the key is for. + * + * \param version + * The backup in which to store the key. Must be the current backup. + * + * \param data + * The key data. + */ + explicit PutRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version, + const KeyBackupData& data); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Retrieve a key from the backup. + * + * Retrieve a key from the backup. + */ +class QUOTIENT_API GetRoomKeyBySessionIdJob : public BaseJob { +public: + /*! \brief Retrieve a key from the backup. + * + * \param roomId + * The ID of the room that the requested key is for. + * + * \param sessionId + * The ID of the megolm session whose key is requested. + * + * \param version + * The backup from which to retrieve the key. + */ + explicit GetRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeyBySessionIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& sessionId, const QString& version); + + // Result properties + + /// The key data + KeyBackupData data() const { return fromJson(jsonData()); } +}; + +/*! \brief Delete a key from the backup. + * + * Delete a key from the backup. + */ +class QUOTIENT_API DeleteRoomKeyBySessionIdJob : public BaseJob { +public: + /*! \brief Delete a key from the backup. + * + * \param roomId + * The ID of the room that the specified key is for. + * + * \param sessionId + * The ID of the megolm session whose key is to be deleted. + * + * \param version + * The backup from which to delete the key + */ + explicit DeleteRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeyBySessionIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& sessionId, const QString& version); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Store several keys in the backup for a given room. + * + * Store several keys in the backup for a given room. + */ +class QUOTIENT_API PutRoomKeysByRoomIdJob : public BaseJob { +public: + /*! \brief Store several keys in the backup for a given room. + * + * \param roomId + * The ID of the room that the keys are for. + * + * \param version + * The backup in which to store the keys. Must be the current backup. + * + * \param backupData + * The backup data + */ + explicit PutRoomKeysByRoomIdJob(const QString& roomId, + const QString& version, + const RoomKeyBackup& backupData); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Retrieve the keys from the backup for a given room. + * + * Retrieve the keys from the backup for a given room. + */ +class QUOTIENT_API GetRoomKeysByRoomIdJob : public BaseJob { +public: + /*! \brief Retrieve the keys from the backup for a given room. + * + * \param roomId + * The ID of the room that the requested key is for. + * + * \param version + * The backup from which to retrieve the key. + */ + explicit GetRoomKeysByRoomIdJob(const QString& roomId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysByRoomIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& version); + + // Result properties + + /// The key data. If no keys are found, then an object with an empty + /// `sessions` property will be returned (`{"sessions": {}}`). + RoomKeyBackup data() const { return fromJson(jsonData()); } +}; + +/*! \brief Delete the keys from the backup for a given room. + * + * Delete the keys from the backup for a given room. + */ +class QUOTIENT_API DeleteRoomKeysByRoomIdJob : public BaseJob { +public: + /*! \brief Delete the keys from the backup for a given room. + * + * \param roomId + * The ID of the room that the specified key is for. + * + * \param version + * The backup from which to delete the key. + */ + explicit DeleteRoomKeysByRoomIdJob(const QString& roomId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeysByRoomIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& version); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Store several keys in the backup. + * + * Store several keys in the backup. + */ +class QUOTIENT_API PutRoomKeysJob : public BaseJob { +public: + /*! \brief Store several keys in the backup. + * + * \param version + * The backup in which to store the keys. Must be the current backup. + * + * \param rooms + * A map of room IDs to room key backup data. + */ + explicit PutRoomKeysJob(const QString& version, + const QHash& rooms); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Retrieve the keys from the backup. + * + * Retrieve the keys from the backup. + */ +class QUOTIENT_API GetRoomKeysJob : public BaseJob { +public: + /*! \brief Retrieve the keys from the backup. + * + * \param version + * The backup from which to retrieve the keys. + */ + explicit GetRoomKeysJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); + + // Result properties + + /// A map of room IDs to room key backup data. + QHash rooms() const + { + return loadFromJson>("rooms"_ls); + } +}; + +/*! \brief Delete the keys from the backup. + * + * Delete the keys from the backup. + */ +class QUOTIENT_API DeleteRoomKeysJob : public BaseJob { +public: + /*! \brief Delete the keys from the backup. + * + * \param version + * The backup from which to delete the key + */ + explicit DeleteRoomKeysJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeysJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +} // namespace Quotient diff --git a/Quotient/csapi/keys.h b/Quotient/csapi/keys.h index be152e6b1..63b769cf8 100644 --- a/Quotient/csapi/keys.h +++ b/Quotient/csapi/keys.h @@ -6,7 +6,9 @@ #include #include + #include + #include namespace Quotient { diff --git a/Quotient/csapi/list_public_rooms.h b/Quotient/csapi/list_public_rooms.h index d76c233f5..97a949c1e 100644 --- a/Quotient/csapi/list_public_rooms.h +++ b/Quotient/csapi/list_public_rooms.h @@ -5,6 +5,7 @@ #pragma once #include + #include namespace Quotient { diff --git a/Quotient/csapi/login.h b/Quotient/csapi/login.h index 2e737efef..23c561635 100644 --- a/Quotient/csapi/login.h +++ b/Quotient/csapi/login.h @@ -6,6 +6,7 @@ #include #include + #include namespace Quotient { diff --git a/Quotient/csapi/login_token.h b/Quotient/csapi/login_token.h index 990500eb9..415c899fb 100644 --- a/Quotient/csapi/login_token.h +++ b/Quotient/csapi/login_token.h @@ -5,6 +5,7 @@ #pragma once #include + #include namespace Quotient { diff --git a/Quotient/csapi/openid.h b/Quotient/csapi/openid.h index 5125f4408..1338f1572 100644 --- a/Quotient/csapi/openid.h +++ b/Quotient/csapi/openid.h @@ -5,6 +5,7 @@ #pragma once #include + #include namespace Quotient { diff --git a/Quotient/csapi/pushrules.h b/Quotient/csapi/pushrules.h index ff71a348e..ccb596540 100644 --- a/Quotient/csapi/pushrules.h +++ b/Quotient/csapi/pushrules.h @@ -7,6 +7,7 @@ #include #include #include + #include namespace Quotient { diff --git a/Quotient/csapi/registration.h b/Quotient/csapi/registration.h index c1b63d7e2..caf97a688 100644 --- a/Quotient/csapi/registration.h +++ b/Quotient/csapi/registration.h @@ -8,6 +8,7 @@ #include #include #include + #include namespace Quotient { diff --git a/Quotient/csapi/search.h b/Quotient/csapi/search.h index 85e41f443..e364be44c 100644 --- a/Quotient/csapi/search.h +++ b/Quotient/csapi/search.h @@ -5,6 +5,7 @@ #pragma once #include + #include #include #include diff --git a/Quotient/csapi/third_party_lookup.h b/Quotient/csapi/third_party_lookup.h index c29cf4cf2..d15b2e969 100644 --- a/Quotient/csapi/third_party_lookup.h +++ b/Quotient/csapi/third_party_lookup.h @@ -4,10 +4,11 @@ #pragma once +#include + #include #include #include -#include namespace Quotient { diff --git a/Quotient/csapi/wellknown.h b/Quotient/csapi/wellknown.h index d6143243b..2f3d10688 100644 --- a/Quotient/csapi/wellknown.h +++ b/Quotient/csapi/wellknown.h @@ -5,6 +5,7 @@ #pragma once #include + #include namespace Quotient { diff --git a/gtad/gtad.yaml b/gtad/gtad.yaml index f21443d44..a6d648515 100644 --- a/gtad/gtad.yaml +++ b/gtad/gtad.yaml @@ -31,6 +31,9 @@ analyzer: login>/address: "" login/version: "" # Structure inside `types`: # - swaggerType: