QXmpp Version: 1.15.1
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
118
119// Keep in sync with namespaces and names in Global/Message.cpp!
120
121#if QXMPP_DEPRECATED_SINCE(1, 5)
138#endif
139};
140
153
162inline constexpr bool operator&(SceMode mode1, SceMode mode2)
163{
164 return mode1 == SceAll || mode1 == mode2;
165}
166
172enum Cipher {
173 Aes128GcmNoPad,
174 Aes256GcmNoPad,
175 Aes256CbcPkcs7,
176};
177
183struct Success { };
184
190struct Cancelled { };
191
199struct TimeoutError { };
200
208template<typename T = Success>
209using Result = std::variant<T, QXmppError>;
210
215template<typename T>
216bool hasValue(const Result<T> &r) { return std::holds_alternative<T>(r); }
217
223template<typename T>
224bool hasError(const Result<T> &r) { return std::holds_alternative<QXmppError>(r); }
225
231template<typename T>
232const 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
Definition Algorithms.h:14
std::variant< T, QXmppError > Result
Definition QXmppGlobal.h:209
Cipher
Definition QXmppGlobal.h:172
const T & getValue(const Result< T > &r)
Definition QXmppGlobal.h:232
bool hasValue(const Result< T > &r)
Definition QXmppGlobal.h:216
constexpr bool operator&(SceMode mode1, SceMode mode2)
Definition QXmppGlobal.h:162
SceMode
Definition QXmppGlobal.h:148
@ SceSensitive
Only processes sensitive elements that should be encrypted.
Definition QXmppGlobal.h:151
@ SceAll
Processes all known elements.
Definition QXmppGlobal.h:149
@ ScePublic
Only processes 'public' elements (e.g. needed for routing).
Definition QXmppGlobal.h:150
bool hasError(const Result< T > &r)
Definition QXmppGlobal.h:224
EncryptionMethod
Definition QXmppGlobal.h:101
@ LegacyOpenPgp
XEP-0027: Current Jabber OpenPGP Usage
Definition QXmppGlobal.h:109
@ OMEMO
Definition QXmppGlobal.h:137
@ Omemo0
XEP-0384: OMEMO Encryption
Definition QXmppGlobal.h:113
@ Ox
XEP-0373: OpenPGP for XMPP
Definition QXmppGlobal.h:111
@ Omemo2
XEP-0384: OMEMO Encryption since version 0.8
Definition QXmppGlobal.h:117
@ OTR
Definition QXmppGlobal.h:125
@ Otr
XEP-0364: Current Off-the-Record Messaging Usage
Definition QXmppGlobal.h:107
@ NoEncryption
No encryption.
Definition QXmppGlobal.h:103
@ OX
Definition QXmppGlobal.h:133
@ LegacyOpenPGP
Definition QXmppGlobal.h:129
@ Omemo1
XEP-0384: OMEMO Encryption since version 0.4
Definition QXmppGlobal.h:115
@ UnknownEncryption
Unknown encryption.
Definition QXmppGlobal.h:105
Definition QXmppError.h:17
Definition QXmppGlobal.h:190
Definition QXmppGlobal.h:183
Definition QXmppGlobal.h:199