QXmpp: QXmppStanza.h Source File

QXmpp Version: 1.14.4

Loading...
Searching...
No Matches
QXmppStanza.h
1// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
2// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
3// SPDX-FileCopyrightText: 2015 Georg Rudoy <0xd34df00d@gmail.com>
4// SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
5// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de>
6//
7// SPDX-License-Identifier: LGPL-2.1-or-later
8
9#ifndef QXMPPSTANZA_H
10#define QXMPPSTANZA_H
11
12#include <optional>
13
14#include <QByteArray>
15#include <QSharedData>
16
17// forward declarations of QXmlStream* classes will not work on Mac, we need to
18// include the whole header.
19// See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
20// for an explanation.
21#include "QXmppConstants_p.h"
22#include "QXmppElement.h"
23#include "QXmppNonza.h"
24
25#include <QXmlStreamWriter>
26
27class QXmppE2eeMetadata;
28class QXmppExtendedAddressPrivate;
29
30namespace QXmpp {
31
37 enum class JingleErrorCondition {
38 OutOfOrder,
39 TieBreak,
40 UnknownSession,
41 UnsupportedInfo,
42};
43
44} // namespace QXmpp
45
55 class QXMPP_EXPORT QXmppExtendedAddress
56{
57public:
58 QXmppExtendedAddress();
59 QXmppExtendedAddress(const QXmppExtendedAddress &);
60 QXmppExtendedAddress(QXmppExtendedAddress &&);
61 ~QXmppExtendedAddress();
62
63 QXmppExtendedAddress &operator=(const QXmppExtendedAddress &);
64 QXmppExtendedAddress &operator=(QXmppExtendedAddress &&);
65
66 QString description() const;
67 void setDescription(const QString &description);
68
69 QString jid() const;
70 void setJid(const QString &jid);
71
72 QString type() const;
73 void setType(const QString &type);
74
75 bool isDelivered() const;
76 void setDelivered(bool);
77
78 bool isValid() const;
79
81 static constexpr std::tuple XmlTag = { u"address", QXmpp::Private::ns_extended_addressing };
82 void parse(const QDomElement &element);
83 void toXml(QXmlStreamWriter *writer) const;
85
86private:
87 QSharedDataPointer<QXmppExtendedAddressPrivate> d;
88};
89
90class QXmppStanzaPrivate;
91class QXmppStanzaErrorPrivate;
92
99
105 class QXMPP_EXPORT QXmppStanza : public QXmppNonza
106{
107public:
111 class QXMPP_EXPORT Error
112 {
113 public:
118 enum Type {
119 NoType = -1,
120 Cancel,
121 Continue,
122 Modify,
123 Auth,
124 Wait
125 };
126
128 enum Condition {
129 NoCondition = -1,
130 BadRequest,
131 Conflict,
132 FeatureNotImplemented,
133 Forbidden,
134 Gone,
135 InternalServerError,
136 ItemNotFound,
137 JidMalformed,
138 NotAcceptable,
139 NotAllowed,
140 NotAuthorized,
141#if QXMPP_DEPRECATED_SINCE(1, 3)
144 PaymentRequired Q_DECL_ENUMERATOR_DEPRECATED_X("The <payment-required/> error was removed in RFC6120"),
145#endif
146 RecipientUnavailable = 12,
147 Redirect,
148 RegistrationRequired,
149 RemoteServerNotFound,
150 RemoteServerTimeout,
151 ResourceConstraint,
152 ServiceUnavailable,
153 SubscriptionRequired,
154 UndefinedCondition,
155 UnexpectedRequest,
156 PolicyViolation
157 };
158
159 Error();
160 Error(const Error &);
161 Error(Error &&);
162 Error(Type type, Condition cond, const QString &text = QString());
163 Error(const QString &type, const QString &cond, const QString &text = QString());
165 Error(QSharedDataPointer<QXmppStanzaErrorPrivate> d);
167 ~Error();
168
169 Error &operator=(const Error &);
170 Error &operator=(Error &&);
171
172 int code() const;
173 void setCode(int code);
174
175 QString text() const;
176 void setText(const QString &text);
177
178 Condition condition() const;
179 void setCondition(Condition cond);
180
181 Type type() const;
182 void setType(Type type);
183
184 QString by() const;
185 void setBy(const QString &by);
186
187 QString redirectionUri() const;
188 void setRedirectionUri(const QString &redirectionUri);
189
190 // XEP-0166: Jingle
191 std::optional<QXmpp::JingleErrorCondition> jingleErrorCondition() const;
192 void setJingleErrorCondition(std::optional<QXmpp::JingleErrorCondition>);
193
194 // XEP-0363: HTTP File Upload
195 bool fileTooLarge() const;
196 void setFileTooLarge(bool);
197
198 qint64 maxFileSize() const;
199 void setMaxFileSize(qint64);
200
201 QDateTime retryDate() const;
202 void setRetryDate(const QDateTime &);
203
205 void parse(const QDomElement &element);
206 void toXml(QXmlStreamWriter *writer) const;
208
209 private:
210 friend class QXmppStanza;
211
212 QSharedDataPointer<QXmppStanzaErrorPrivate> d;
213 };
214
215 QXmppStanza(const QString &from = QString(), const QString &to = QString());
216 QXmppStanza(const QXmppStanza &other);
217 QXmppStanza(QXmppStanza &&);
218 ~QXmppStanza() override;
219
220 QXmppStanza &operator=(const QXmppStanza &other);
221 QXmppStanza &operator=(QXmppStanza &&);
222
223 QString to() const;
224 void setTo(const QString &);
225
226 QString from() const;
227 void setFrom(const QString &);
228
229 QString id() const;
230 void setId(const QString &);
231
232 QString lang() const;
233 void setLang(const QString &);
234
235 QXmppStanza::Error error() const;
236 std::optional<Error> errorOptional() const;
237 void setError(const QXmppStanza::Error &error);
238 void setError(const std::optional<Error> &error);
239
240 QXmppElementList extensions() const;
241 void setExtensions(const QXmppElementList &elements);
242
243 QList<QXmppExtendedAddress> extendedAddresses() const;
244 void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
245
246 std::optional<QXmppE2eeMetadata> e2eeMetadata() const;
247 void setE2eeMetadata(const std::optional<QXmppE2eeMetadata> &e2eeMetadata);
248
250 void parse(const QDomElement &element) override;
251
252protected:
253 void extensionsToXml(QXmlStreamWriter *writer, QXmpp::SceMode = QXmpp::SceAll) const;
254 void generateAndSetNextId();
256
257private:
258 QSharedDataPointer<QXmppStanzaPrivate> d;
259 friend class TestClient;
260};
261
262Q_DECLARE_METATYPE(QXmppStanza::Error::Type);
263Q_DECLARE_METATYPE(QXmppStanza::Error::Condition);
264
265#endif // QXMPPSTANZA_H
QXmppE2eeMetadata
The QXmppE2eeMetadata class contains data used for end-to-end encryption purposes.
Definition QXmppE2eeMetadata.h:16
QXmppExtendedAddress::setJid
void setJid(const QString &jid)
Definition QXmppStanza.cpp:94
QXmppExtendedAddress::setDelivered
void setDelivered(bool)
Definition QXmppStanza.cpp:126
QXmppExtendedAddress::QXmppExtendedAddress
QXmppExtendedAddress(const QXmppExtendedAddress &)
Default copy-constructur.
QXmppExtendedAddress::description
QString description() const
Definition QXmppStanza.cpp:70
QXmppExtendedAddress::isDelivered
bool isDelivered() const
Definition QXmppStanza.cpp:118
QXmppExtendedAddress::isValid
bool isValid() const
Definition QXmppStanza.cpp:135
QXmppExtendedAddress::setDescription
void setDescription(const QString &description)
Definition QXmppStanza.cpp:78
QXmppExtendedAddress::type
QString type() const
Definition QXmppStanza.cpp:102
QXmppExtendedAddress::QXmppExtendedAddress
QXmppExtendedAddress()
Definition QXmppStanza.cpp:51
QXmppExtendedAddress::jid
QString jid() const
Definition QXmppStanza.cpp:86
QXmppExtendedAddress::QXmppExtendedAddress
QXmppExtendedAddress(QXmppExtendedAddress &&)
Default move-constructur.
QXmppExtendedAddress::operator=
QXmppExtendedAddress & operator=(const QXmppExtendedAddress &)
Default assignment operator.
QXmppExtendedAddress::setType
void setType(const QString &type)
Definition QXmppStanza.cpp:110
QXmppExtendedAddress::operator=
QXmppExtendedAddress & operator=(QXmppExtendedAddress &&)
Default assignment operator.
QXmppNonza::parse
virtual void parse(const QDomElement &)=0
QXmppNonza::toXml
virtual void toXml(QXmlStreamWriter *writer) const =0
QXmppStanza::Error
The Error class represents a stanza error.
Definition QXmppStanza.h:112
QXmppStanza::Error::text
QString text() const
Definition QXmppStanza.cpp:233
QXmppStanza::Error::operator=
Error & operator=(Error &&)
Move operator.
QXmppStanza::Error::code
int code() const
Definition QXmppStanza.cpp:249
QXmppStanza::Error::Error
Error()
Definition QXmppStanza.cpp:183
QXmppStanza::Error::jingleErrorCondition
std::optional< QXmpp::JingleErrorCondition > jingleErrorCondition() const
Definition QXmppStanza.cpp:357
QXmppStanza::Error::setJingleErrorCondition
void setJingleErrorCondition(std::optional< QXmpp::JingleErrorCondition >)
Definition QXmppStanza.cpp:367
QXmppStanza::Error::setType
void setType(Type type)
Definition QXmppStanza.cpp:321
QXmppStanza::Error::setMaxFileSize
void setMaxFileSize(qint64)
Definition QXmppStanza.cpp:412
QXmppStanza::Error::fileTooLarge
bool fileTooLarge() const
Definition QXmppStanza.cpp:378
QXmppStanza::Error::type
Type type() const
Definition QXmppStanza.cpp:287
QXmppStanza::Error::setRetryDate
void setRetryDate(const QDateTime &)
Definition QXmppStanza.cpp:431
QXmppStanza::Error::redirectionUri
QString redirectionUri() const
Definition QXmppStanza.cpp:334
QXmppStanza::Error::setCondition
void setCondition(Condition cond)
Definition QXmppStanza.cpp:279
QXmppStanza::Error::~Error
~Error()
Default destructor.
QXmppStanza::Error::Error
Error(Error &&)
Move constructor.
QXmppStanza::Error::setFileTooLarge
void setFileTooLarge(bool)
Definition QXmppStanza.cpp:390
QXmppStanza::Error::Type
Type
Definition QXmppStanza.h:118
QXmppStanza::Error::Auth
@ Auth
The request needs to be resent after authentication.
Definition QXmppStanza.h:123
QXmppStanza::Error::Modify
@ Modify
The request needs to be changed and resent.
Definition QXmppStanza.h:122
QXmppStanza::Error::Cancel
@ Cancel
The error is not temporary.
Definition QXmppStanza.h:120
QXmppStanza::Error::Wait
@ Wait
The error is temporary, you should wait and resend.
Definition QXmppStanza.h:124
QXmppStanza::Error::Continue
@ Continue
The error was only a warning.
Definition QXmppStanza.h:121
QXmppStanza::Error::setText
void setText(const QString &text)
Definition QXmppStanza.cpp:241
QXmppStanza::Error::condition
Condition condition() const
Definition QXmppStanza.cpp:268
QXmppStanza::Error::by
QString by() const
Definition QXmppStanza.cpp:300
QXmppStanza::Error::Condition
Condition
A detailed condition of the error.
Definition QXmppStanza.h:128
QXmppStanza::Error::ItemNotFound
@ ItemNotFound
The requested item could not be found.
Definition QXmppStanza.h:136
QXmppStanza::Error::ResourceConstraint
@ ResourceConstraint
The recipient lacks system resources to perform the request.
Definition QXmppStanza.h:151
QXmppStanza::Error::UndefinedCondition
@ UndefinedCondition
An undefined condition was hit.
Definition QXmppStanza.h:154
QXmppStanza::Error::Forbidden
@ Forbidden
The requesting entity does not posses the necessary privileges to perform the request.
Definition QXmppStanza.h:133
QXmppStanza::Error::FeatureNotImplemented
@ FeatureNotImplemented
The feature is not implemented.
Definition QXmppStanza.h:132
QXmppStanza::Error::RegistrationRequired
@ RegistrationRequired
The requesting entity needs to register first.
Definition QXmppStanza.h:148
QXmppStanza::Error::NotAcceptable
@ NotAcceptable
The request does not meet the defined critera.
Definition QXmppStanza.h:138
QXmppStanza::Error::RecipientUnavailable
@ RecipientUnavailable
The recipient is unavailable.
Definition QXmppStanza.h:146
QXmppStanza::Error::Redirect
@ Redirect
The requested resource is available elsewhere. This is used in combination with a redirection URI.
Definition QXmppStanza.h:147
QXmppStanza::Error::PolicyViolation
@ PolicyViolation
The entity has violated a local server policy.
Definition QXmppStanza.h:156
QXmppStanza::Error::BadRequest
@ BadRequest
The request does not contain a valid schema.
Definition QXmppStanza.h:130
QXmppStanza::Error::NotAuthorized
@ NotAuthorized
The request should be resent after authentication.
Definition QXmppStanza.h:140
QXmppStanza::Error::Conflict
@ Conflict
The request conflicts with another.
Definition QXmppStanza.h:131
QXmppStanza::Error::UnexpectedRequest
@ UnexpectedRequest
The request was unexpected.
Definition QXmppStanza.h:155
QXmppStanza::Error::InternalServerError
@ InternalServerError
The server has expierienced an internal error and can not process the request.
Definition QXmppStanza.h:135
QXmppStanza::Error::Gone
@ Gone
The user or server can not be contacted at the address. This is used in combination with a redirectio...
Definition QXmppStanza.h:134
QXmppStanza::Error::SubscriptionRequired
@ SubscriptionRequired
The requester needs to subscribe first.
Definition QXmppStanza.h:153
QXmppStanza::Error::RemoteServerTimeout
@ RemoteServerTimeout
The connection to the server could not be established or timed out.
Definition QXmppStanza.h:150
QXmppStanza::Error::RemoteServerNotFound
@ RemoteServerNotFound
The remote server could not be found.
Definition QXmppStanza.h:149
QXmppStanza::Error::JidMalformed
@ JidMalformed
The given JID is not valid.
Definition QXmppStanza.h:137
QXmppStanza::Error::ServiceUnavailable
@ ServiceUnavailable
The service is currently not available.
Definition QXmppStanza.h:152
QXmppStanza::Error::NotAllowed
@ NotAllowed
No entity is allowed to perform the request.
Definition QXmppStanza.h:139
QXmppStanza::Error::Q_DECL_ENUMERATOR_DEPRECATED_X
@ Q_DECL_ENUMERATOR_DEPRECATED_X
Definition QXmppStanza.h:144
QXmppStanza::Error::retryDate
QDateTime retryDate() const
Definition QXmppStanza.cpp:423
QXmppStanza::Error::operator=
Error & operator=(const Error &)
Copy operator.
QXmppStanza::Error::setBy
void setBy(const QString &by)
Definition QXmppStanza.cpp:313
QXmppStanza::Error::Error
Error(const Error &)
Copy constructor.
QXmppStanza::Error::maxFileSize
qint64 maxFileSize() const
Definition QXmppStanza.cpp:400
QXmppStanza::Error::setCode
void setCode(int code)
Definition QXmppStanza.cpp:257
QXmppStanza::Error::setRedirectionUri
void setRedirectionUri(const QString &redirectionUri)
Definition QXmppStanza.cpp:347
QXmppStanza::error
QXmppStanza::Error error() const
Definition QXmppStanza.cpp:788
QXmppStanza::lang
QString lang() const
Definition QXmppStanza.cpp:768
QXmppStanza::setLang
void setLang(const QString &)
Definition QXmppStanza.cpp:778
QXmppStanza::~QXmppStanza
~QXmppStanza() override
Destroys a QXmppStanza.
QXmppStanza::QXmppStanza
QXmppStanza(QXmppStanza &&)
Move constructor.
QXmppStanza::setFrom
void setFrom(const QString &)
Definition QXmppStanza.cpp:742
QXmppStanza::extensions
QXmppElementList extensions() const
Definition QXmppStanza.cpp:837
QXmppStanza::setError
void setError(const QXmppStanza::Error &error)
Definition QXmppStanza.cpp:811
QXmppStanza::setE2eeMetadata
void setE2eeMetadata(const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
Definition QXmppStanza.cpp:888
QXmppStanza::to
QString to() const
Definition QXmppStanza.cpp:714
QXmppStanza::operator=
QXmppStanza & operator=(const QXmppStanza &other)
Assigns other to this stanza.
QXmppStanza::setTo
void setTo(const QString &)
Definition QXmppStanza.cpp:724
QXmppStanza::from
QString from() const
Definition QXmppStanza.cpp:732
QXmppStanza::id
QString id() const
Definition QXmppStanza.cpp:750
QXmppStanza::setExtendedAddresses
void setExtendedAddresses(const QList< QXmppExtendedAddress > &extendedAddresses)
Definition QXmppStanza.cpp:865
QXmppStanza::e2eeMetadata
std::optional< QXmppE2eeMetadata > e2eeMetadata() const
Definition QXmppStanza.cpp:875
QXmppStanza::errorOptional
std::optional< Error > errorOptional() const
Definition QXmppStanza.cpp:798
QXmppStanza::setExtensions
void setExtensions(const QXmppElementList &elements)
Definition QXmppStanza.cpp:847
QXmppStanza::operator=
QXmppStanza & operator=(QXmppStanza &&)
Move-assignment operator.
QXmppStanza::extendedAddresses
QList< QXmppExtendedAddress > extendedAddresses() const
Definition QXmppStanza.cpp:856
QXmppStanza::QXmppStanza
QXmppStanza(const QString &from=QString(), const QString &to=QString())
Definition QXmppStanza.cpp:693
QXmppStanza::setId
void setId(const QString &)
Definition QXmppStanza.cpp:760
QXmppStanza::QXmppStanza
QXmppStanza(const QXmppStanza &other)
Constructs a copy of other.
QXmpp
Definition Algorithms.h:14
QXmpp::JingleErrorCondition
JingleErrorCondition
Definition QXmppStanza.h:37
QXmpp::SceMode
SceMode
Definition QXmppGlobal.h:148
QXmpp::SceAll
@ SceAll
Processes all known elements.
Definition QXmppGlobal.h:149