QXmpp  Version: 1.15.1
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 
17 struct 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 
36 inline 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 
92 namespace QXmpp {
93 
111  Ox,
118 
119 // Keep in sync with namespaces and names in Global/Message.cpp!
120 
121 #if QXMPP_DEPRECATED_SINCE(1, 5)
122  OTR = Otr,
133  OX = Ox,
138 #endif
139 };
140 
148 enum SceMode : uint8_t {
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 
208 template<typename T = Success>
209 using Result = std::variant<T, QXmppError>;
210 
215 template<typename T>
216 bool hasValue(const Result<T> &r) { return std::holds_alternative<T>(r); }
217 
223 template<typename T>
224 bool hasError(const Result<T> &r) { return std::holds_alternative<QXmppError>(r); }
225 
231 template<typename T>
232 const T &getValue(const Result<T> &r) { return std::get<T>(r); }
233 
239 template<typename T>
240 T &getValue(Result<T> &r) { return std::get<T>(r); }
241 
247 template<typename T>
248 T 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
Definition: QXmppGlobal.h:183
const T & getValue(const Result< T > &r)
Definition: QXmppGlobal.h:232
Definition: QXmppError.h:17
Definition: QXmppGlobal.h:137
Definition: QXmppGlobal.h:199
XEP-0384: OMEMO Encryption
Definition: QXmppGlobal.h:113
Definition: QXmppGlobal.h:129
XEP-0027: Current Jabber OpenPGP Usage
Definition: QXmppGlobal.h:109
Cipher
Definition: QXmppGlobal.h:172
XEP-0373: OpenPGP for XMPP
Definition: QXmppGlobal.h:111
bool hasError(const Result< T > &r)
Definition: QXmppGlobal.h:224
Definition: QXmppGlobal.h:133
Only processes &#39;public&#39; elements (e.g. needed for routing).
Definition: QXmppGlobal.h:150
SceMode
Definition: QXmppGlobal.h:148
Definition: QXmppGlobal.h:125
No encryption.
Definition: QXmppGlobal.h:103
XEP-0384: OMEMO Encryption since version 0.8
Definition: QXmppGlobal.h:117
constexpr bool operator &(SceMode mode1, SceMode mode2)
Definition: QXmppGlobal.h:162
bool hasValue(const Result< T > &r)
Definition: QXmppGlobal.h:216
Definition: QXmppGlobal.h:190
Only processes sensitive elements that should be encrypted.
Definition: QXmppGlobal.h:151
Unknown encryption.
Definition: QXmppGlobal.h:105
Processes all known elements.
Definition: QXmppGlobal.h:149
XEP-0384: OMEMO Encryption since version 0.4
Definition: QXmppGlobal.h:115
EncryptionMethod
Definition: QXmppGlobal.h:101
XEP-0364: Current Off-the-Record Messaging Usage
Definition: QXmppGlobal.h:107
std::variant< T, QXmppError > Result
Definition: QXmppGlobal.h:209