QXmpp Version: 1.5.6
Loading...
Searching...
No Matches
QXmppOmemoManager.h
1// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPOMEMOMANAGER_H
6#define QXMPPOMEMOMANAGER_H
7
8#include "QXmppClientExtension.h"
9#include "QXmppE2eeExtension.h"
10#include "QXmppMessageHandler.h"
11#include "QXmppPubSubEventHandler.h"
12#include "QXmppTrustSecurityPolicy.h"
13#include "qxmppomemo_export.h"
14
15class QXmppOmemoDevicePrivate;
16class QXmppOmemoManagerPrivate;
17class QXmppOmemoOwnDevicePrivate;
19
20class QXMPPOMEMO_EXPORT QXmppOmemoOwnDevice
21{
22public:
27
30
31 QString label() const;
32 void setLabel(const QString &label);
33
34 QByteArray keyId() const;
35 void setKeyId(const QByteArray &keyId);
36
37private:
38 QSharedDataPointer<QXmppOmemoOwnDevicePrivate> d;
39};
40
41class QXMPPOMEMO_EXPORT QXmppOmemoDevice
42{
43public:
48
51
52 QString jid() const;
53 void setJid(const QString &jid);
54
55 QString label() const;
56 void setLabel(const QString &label);
57
58 QByteArray keyId() const;
59 void setKeyId(const QByteArray &keyId);
60
61 QXmpp::TrustLevel trustLevel() const;
62 void setTrustLevel(QXmpp::TrustLevel trustLevel);
63
64private:
65 QSharedDataPointer<QXmppOmemoDevicePrivate> d;
66};
67
69{
70 Q_OBJECT
71
72public:
73 using Result = std::variant<QXmpp::Success, QXmppError>;
74
75 struct DevicesResult
76 {
77 QString jid;
78 Result result;
79 };
80
81 explicit QXmppOmemoManager(QXmppOmemoStorage *omemoStorage);
82 ~QXmppOmemoManager() override;
83
84 QXmppTask<bool> load();
85 QXmppTask<bool> setUp();
86
87 QXmppTask<QByteArray> ownKey();
88 QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> keys(QXmpp::TrustLevels trustLevels = {});
89 QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> keys(const QList<QString> &jids, QXmpp::TrustLevels trustLevels = {});
90
91 QXmppTask<bool> changeDeviceLabel(const QString &deviceLabel = {});
92
93 int maximumDevicesPerJid() const;
94 void setMaximumDevicesPerJid(int maximum);
95
96 int maximumDevicesPerStanza() const;
97 void setMaximumDevicesPerStanza(int maximum);
98
99 QXmppTask<QVector<DevicesResult>> requestDeviceLists(const QList<QString> &jids);
100 QXmppTask<QVector<DevicesResult>> subscribeToDeviceLists(const QList<QString> &jids);
101 QXmppTask<QVector<DevicesResult>> unsubscribeFromDeviceLists();
102
103 QXmppOmemoOwnDevice ownDevice();
105 QXmppTask<QVector<QXmppOmemoDevice>> devices(const QList<QString> &jids);
106 QXmppTask<Result> removeContactDevices(const QString &jid);
107
108 void setAcceptedSessionBuildingTrustLevels(QXmpp::TrustLevels trustLevels);
109 QXmpp::TrustLevels acceptedSessionBuildingTrustLevels();
110
111 void setNewDeviceAutoSessionBuildingEnabled(bool isNewDeviceAutoSessionBuildingEnabled);
112 bool isNewDeviceAutoSessionBuildingEnabled();
113
114 QXmppTask<void> buildMissingSessions(const QList<QString> &jids);
115
116 QXmppTask<bool> resetOwnDevice();
117 QXmppTask<bool> resetAll();
118
119 QXmppTask<void> setSecurityPolicy(QXmpp::TrustSecurityPolicy securityPolicy);
121
122 QXmppTask<void> setTrustLevel(const QMultiHash<QString, QByteArray> &keyIds, QXmpp::TrustLevel trustLevel);
123 QXmppTask<QXmpp::TrustLevel> trustLevel(const QString &keyOwnerJid, const QByteArray &keyId);
124
126 QXmppTask<MessageEncryptResult> encryptMessage(QXmppMessage &&message, const std::optional<QXmppSendStanzaParams> &params) override;
127 QXmppTask<MessageDecryptResult> decryptMessage(QXmppMessage &&message) override;
128
129 QXmppTask<IqEncryptResult> encryptIq(QXmppIq &&iq, const std::optional<QXmppSendStanzaParams> &params) override;
130 QXmppTask<IqDecryptResult> decryptIq(const QDomElement &element) override;
131
132 bool isEncrypted(const QDomElement &) override;
133 bool isEncrypted(const QXmppMessage &) override;
134
135 QStringList discoveryFeatures() const override;
136 bool handleStanza(const QDomElement &stanza) override;
137 bool handleMessage(const QXmppMessage &message) override;
139
140 Q_SIGNAL void trustLevelsChanged(const QMultiHash<QString, QByteArray> &modifiedKeys);
141
142 Q_SIGNAL void deviceAdded(const QString &jid, uint32_t deviceId);
143 Q_SIGNAL void deviceChanged(const QString &jid, uint32_t deviceId);
144 Q_SIGNAL void deviceRemoved(const QString &jid, uint32_t deviceId);
145 Q_SIGNAL void devicesRemoved(const QString &jid);
146 Q_SIGNAL void allDevicesRemoved();
147
148protected:
150 void setClient(QXmppClient *client) override;
151 bool handlePubSubEvent(const QDomElement &element, const QString &pubSubService, const QString &nodeName) override;
153
154private:
155 std::unique_ptr<QXmppOmemoManagerPrivate> d;
156
157 friend class QXmppOmemoManagerPrivate;
158 friend class tst_QXmppOmemoManager;
159};
160
161#endif // QXMPPOMEMOMANAGER_H
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:33
The QXmppClient class is the main class for using QXmpp.
Definition QXmppClient.h:84
Definition QXmppE2eeExtension.h:23
The QXmppIq class is the base class for all IQs.
Definition QXmppIq.h:23
Definition QXmppMessageHandler.h:16
The QXmppMessage class represents an XMPP message.
Definition QXmppMessage.h:35
The QXmppOmemoDevice class represents a XEP-0384: OMEMO Encryption device.
Definition QXmppOmemoManager.h:42
QXmppOmemoDevice(QXmppOmemoDevice &&) noexcept
Move-constructor.
QXmppOmemoDevice(const QXmppOmemoDevice &other)
Copy-constructor.
Definition QXmppOmemoManager.h:69
Q_SIGNAL void deviceRemoved(const QString &jid, uint32_t deviceId)
std::variant< QXmpp::Success, QXmppError > Result
Definition QXmppOmemoManager.h:73
Q_SIGNAL void allDevicesRemoved()
Q_SIGNAL void devicesRemoved(const QString &jid)
Q_SIGNAL void deviceAdded(const QString &jid, uint32_t deviceId)
Q_SIGNAL void trustLevelsChanged(const QMultiHash< QString, QByteArray > &modifiedKeys)
Q_SIGNAL void deviceChanged(const QString &jid, uint32_t deviceId)
The QXmppOmemoOwnDevice class represents the XEP-0384: OMEMO Encryption device of this client instanc...
Definition QXmppOmemoManager.h:21
QXmppOmemoOwnDevice(const QXmppOmemoOwnDevice &other)
Copy-constructor.
QXmppOmemoOwnDevice(QXmppOmemoOwnDevice &&) noexcept
Move-constructor.
The QXmppOmemoStorage class stores data used by XEP-0384: OMEMO Encryption.
Definition QXmppOmemoStorage.h:17
Definition QXmppPubSubEventHandler.h:15
Definition QXmppTask.h:62
TrustLevel
Definition QXmppTrustLevel.h:19
TrustSecurityPolicy
Definition QXmppTrustSecurityPolicy.h:18