libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
filesourceinfo.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#pragma once
6
7#include <Quotient/converters.h>
8
9#include <array>
10
11namespace Quotient {
12/**
13 * JSON Web Key object as specified in
14 * https://spec.matrix.org/unstable/client-server-api/#extensions-to-mroommessage-msgtypes
15 * The only currently relevant member is `k`, the rest needs to be set to the defaults specified in the spec.
16 */
17struct JWK
18{
19 Q_GADGET
20 Q_PROPERTY(QString kty MEMBER kty CONSTANT)
25
26public:
28 QStringList keyOps;
29 QString alg;
30 QString k;
31 bool ext;
32};
33
42
43public:
44 QUrl url;
45 JWK key;
46 QString iv;
48 QString v;
49
50 bool isValid() const { return url.isValid(); }
51};
52
56
57template <>
59 static void dumpTo(QJsonObject& jo, const EncryptedFileMetadata& pod);
60 static void fillFrom(const QJsonObject& jo, EncryptedFileMetadata& pod);
61};
62
63template <>
65 static void dumpTo(QJsonObject& jo, const JWK& pod);
66 static void fillFrom(const QJsonObject& jo, JWK& pod);
67};
68
70
72
74
75QUOTIENT_API void setUrlInSourceInfo(FileSourceInfo& fsi, const QUrl& newUrl);
76
77// The way FileSourceInfo is stored in JSON requires an extra parameter so
78// the original template is not applicable
79template <>
80void fillJson(QJsonObject&, const FileSourceInfo&) = delete;
81
82//! \brief Export FileSourceInfo to a JSON object
83//!
84//! Depending on what is stored inside FileSourceInfo, this function will insert
85//! - a key-to-string pair where key is taken from jsonKeys[0] and the string
86//! is the URL, if FileSourceInfo stores a QUrl;
87//! - a key-to-object mapping where key is taken from jsonKeys[1] and the object
88//! is the result of converting EncryptedFileMetadata to JSON,
89//! if FileSourceInfo stores EncryptedFileMetadata
90QUOTIENT_API void fillJson(QJsonObject& jo, const FileSourceInfoKeys& jsonKeys,
91 const FileSourceInfo& fsi);
92
95
96namespace FileMetadataMap {
97 QUOTIENT_API void add(const QString& roomId,
98 const QString& eventId,
99 const EncryptedFileMetadata& fileMetadata);
100 QUOTIENT_API void remove(const QString& roomId,
101 const QString& eventId);
102
103 //! \brief Obtain file source information across connections, thread-safely
104 //! \return the previously saved EncryptedFileMetadata object, or an invalid
105 //! (default-constructed) object in case of unsuccessful lookup
106 QUOTIENT_API EncryptedFileMetadata lookup(const QString& roomId,
107 const QString& eventId);
108}
109
110} // namespace Quotient
QUOTIENT_API void remove(const QString &roomId, const QString &eventId)
QUOTIENT_API void add(const QString &roomId, const QString &eventId, const EncryptedFileMetadata &fileMetadata)
QUOTIENT_API void fillJson(QJsonObject &jo, const FileSourceInfoKeys &jsonKeys, const FileSourceInfo &fsi)
Export FileSourceInfo to a JSON object.
void fillJson(QJsonObject &, const FileSourceInfo &)=delete
QUOTIENT_API void setUrlInSourceInfo(FileSourceInfo &fsi, const QUrl &newUrl)
#define QUOTIENT_API