QXmpp: QXmppGlobal.h Source File

QXmpp Version: 1.14.2

Loading...
Searching...
No Matches
QXmppGlobal.h
1// SPDX-FileCopyrightText: 2010 Manjeet Dahiya <manjeetdahiya@gmail.com>
2// SPDX-FileCopyrightText: 2017 Niels Ole Salscheider <niels_ole@salscheider-online.de>
3// SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
4// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de>
5//
6// SPDX-License-Identifier: LGPL-2.1-or-later
7
8#ifndef QXMPPGLOBAL_H
9#define QXMPPGLOBAL_H
10
11#include "qxmpp_export.h"
12
13#include <variant>
14
15#include <QString>
16
17struct QXmppError;
18
19#define QXMPP_AUTOTEST_EXPORT
20#define QXMPP_PRIVATE_EXPORT QXMPP_EXPORT
21
31#define QXMPP_VERSION QT_VERSION_CHECK(QXMPP_VERSION_MAJOR, QXMPP_VERSION_MINOR, QXMPP_VERSION_PATCH)
32
36inline QLatin1String QXmppVersion()
37{
38 return QLatin1String(
39 QT_STRINGIFY(QXMPP_VERSION_MAJOR) "." QT_STRINGIFY(QXMPP_VERSION_MINOR) "." QT_STRINGIFY(QXMPP_VERSION_PATCH));
40}
41
42// This sets which deprecated functions should still be usable
43// It works exactly like QT_DISABLE_DEPRECATED_BEFORE
44#ifndef QXMPP_DISABLE_DEPRECATED_BEFORE
45#define QXMPP_DISABLE_DEPRECATED_BEFORE 0x0
46#endif
47
48// This works exactly like QT_DEPRECATED_SINCE, but checks QXMPP_DISABLE_DEPRECATED_BEFORE instead.
49#define QXMPP_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QXMPP_DISABLE_DEPRECATED_BEFORE)
50
51// workaround for Qt < 5.12
52#ifndef Q_DECL_ENUMERATOR_DEPRECATED_X
53#define Q_DECL_ENUMERATOR_DEPRECATED_X(msg)
54#endif
55
56#ifndef QT_WARNING_DISABLE_DEPRECATED
57#define QT_WARNING_DISABLE_DEPRECATED
58#endif
59
60// Adds constructor and operator declarations to a ".h" file corresponding to the rule of six.
61// A default constructor has to be declared manually.
62#define QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(name) \
63 name(const name &); \
64 name(name &&) noexcept; \
65 ~name(); \
66 name &operator=(const name &); \
67 name &operator=(name &&) noexcept;
68
69// Adds constructor and operator definitions to a ".cpp" file corresponding to the rule of six.
70// A default constructor has to be defined manually.
71#define QXMPP_PRIVATE_DEFINE_RULE_OF_SIX(name) \
72 name::name(const name &) = default; \
73 name::name(name &&) noexcept = default; \
74 name::~name() = default; \
75 name &name::operator=(const name &) = default; \
76 name &name::operator=(name &&) noexcept = default;
77// Same as QXMPP_PRIVATE_DEFINE_RULE_OF_SIX but for an inner class.
78#define QXMPP_PRIVATE_DEFINE_RULE_OF_SIX_INNER(outer, name) \
79 outer::name::name(const outer::name &) = default; \
80 outer::name::name(outer::name &&) noexcept = default; \
81 outer::name::~name() = default; \
82 outer::name &outer::name::operator=(const outer::name &) = default; \
83 outer::name &outer::name::operator=(outer::name &&) noexcept = default;
84
92namespace QXmpp {
93
101 enum EncryptionMethod {
103 NoEncryption,
105 UnknownEncryption,
107 Otr,
109 LegacyOpenPgp,
111 Ox,
113 Omemo0,
115 Omemo1,
117 Omemo2,
118
119// Keep in sync with namespaces and names in Global/Message.cpp!
120
121#if QXMPP_DEPRECATED_SINCE(1, 5)
125 OTR = Otr,
129 LegacyOpenPGP = LegacyOpenPgp,
133 OX = Ox,
137 OMEMO = Omemo0,
138#endif
139};
140
148 enum SceMode : uint8_t {
149 SceAll,
150 ScePublic,
151 SceSensitive,
152};
153
162 inline constexpr bool operator&(SceMode mode1, SceMode mode2)
163{
164 return mode1 == SceAll || mode1 == mode2;
165}
166
172 enum Cipher {
173 Aes128GcmNoPad,
174 Aes256GcmNoPad,
175 Aes256CbcPkcs7,
176};
177
183 struct Success { };
184
190 struct Cancelled { };
191
199 struct TimeoutError { };
200
208template<typename T = Success>
209 using Result = std::variant<T, QXmppError>;
210
215template<typename T>
216 bool hasValue(const Result<T> &r) { return std::holds_alternative<T>(r); }
217
223template<typename T>
224 bool hasError(const Result<T> &r) { return std::holds_alternative<QXmppError>(r); }
225
231template<typename T>
232 const T &getValue(const Result<T> &r) { return std::get<T>(r); }
233
239template<typename T>
240T &getValue(Result<T> &r) { return std::get<T>(r); }
241
247template<typename T>
248T getValue(Result<T> &&r) { return std::get<T>(std::move(r)); }
249
250// getError() is defined in QXmppError.h
251
252} // namespace QXmpp
253
254#endif // QXMPPGLOBAL_H
QXmpp
Definition Algorithms.h:14
QXmpp::Cipher
Cipher
Definition QXmppGlobal.h:172
QXmpp::Result
std::variant< T, QXmppError > Result
Definition QXmppGlobal.h:209
QXmpp::getValue
const T & getValue(const Result< T > &r)
Definition QXmppGlobal.h:232
QXmpp::hasValue
bool hasValue(const Result< T > &r)
Definition QXmppGlobal.h:216
QXmpp::operator&
constexpr bool operator&(SceMode mode1, SceMode mode2)
Definition QXmppGlobal.h:162
QXmpp::SceMode
SceMode
Definition QXmppGlobal.h:148
QXmpp::SceSensitive
@ SceSensitive
Only processes sensitive elements that should be encrypted.
Definition QXmppGlobal.h:151
QXmpp::SceAll
@ SceAll
Processes all known elements.
Definition QXmppGlobal.h:149
QXmpp::ScePublic
@ ScePublic
Only processes 'public' elements (e.g. needed for routing).
Definition QXmppGlobal.h:150
QXmpp::hasError
bool hasError(const Result< T > &r)
Definition QXmppGlobal.h:224
QXmpp::EncryptionMethod
EncryptionMethod
Definition QXmppGlobal.h:101
QXmpp::LegacyOpenPgp
@ LegacyOpenPgp
XEP-0027: Current Jabber OpenPGP Usage
Definition QXmppGlobal.h:109
QXmpp::OMEMO
@ OMEMO
Definition QXmppGlobal.h:137
QXmpp::Omemo0
@ Omemo0
XEP-0384: OMEMO Encryption
Definition QXmppGlobal.h:113
QXmpp::Ox
@ Ox
XEP-0373: OpenPGP for XMPP
Definition QXmppGlobal.h:111
QXmpp::Omemo2
@ Omemo2
XEP-0384: OMEMO Encryption since version 0.8
Definition QXmppGlobal.h:117
QXmpp::OTR
@ OTR
Definition QXmppGlobal.h:125
QXmpp::Otr
@ Otr
XEP-0364: Current Off-the-Record Messaging Usage
Definition QXmppGlobal.h:107
QXmpp::NoEncryption
@ NoEncryption
No encryption.
Definition QXmppGlobal.h:103
QXmpp::OX
@ OX
Definition QXmppGlobal.h:133
QXmpp::LegacyOpenPGP
@ LegacyOpenPGP
Definition QXmppGlobal.h:129
QXmpp::Omemo1
@ Omemo1
XEP-0384: OMEMO Encryption since version 0.4
Definition QXmppGlobal.h:115
QXmpp::UnknownEncryption
@ UnknownEncryption
Unknown encryption.
Definition QXmppGlobal.h:105
QXmpp::Cancelled
Definition QXmppGlobal.h:190
QXmpp::Success
Definition QXmppGlobal.h:183
QXmpp::TimeoutError
Definition QXmppGlobal.h:199
QXmppError
Definition QXmppError.h:17