QXmpp Version: 1.10.0
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 "QXmppElement.h"
22#include "QXmppNonza.h"
23
24#include <QXmlStreamWriter>
25
27class QXmppExtendedAddressPrivate;
28
38class QXMPP_EXPORT QXmppExtendedAddress
39{
40public:
45
48
49 QString description() const;
50 void setDescription(const QString &description);
51
52 QString jid() const;
53 void setJid(const QString &jid);
54
55 QString type() const;
56 void setType(const QString &type);
57
58 bool isDelivered() const;
59 void setDelivered(bool);
60
61 bool isValid() const;
62
64 void parse(const QDomElement &element);
65 void toXml(QXmlStreamWriter *writer) const;
67
68private:
69 QSharedDataPointer<QXmppExtendedAddressPrivate> d;
70};
71
72class QXmppStanzaPrivate;
73class QXmppStanzaErrorPrivate;
74
81
87class QXMPP_EXPORT QXmppStanza : public QXmppNonza
88{
89public:
93 class QXMPP_EXPORT Error
94 {
95 public:
100 enum Type {
101 NoType = -1,
106 Wait
107 };
108
111 NoCondition = -1,
123#if QXMPP_DEPRECATED_SINCE(1, 3)
126 PaymentRequired Q_DECL_ENUMERATOR_DEPRECATED_X("The <payment-required/> error was removed in RFC6120"),
127#endif
128 RecipientUnavailable = 12,
138 PolicyViolation
139 };
140
141 Error();
142 Error(const Error &);
144 Error(Type type, Condition cond, const QString &text = QString());
145 Error(const QString &type, const QString &cond, const QString &text = QString());
147 Error(QSharedDataPointer<QXmppStanzaErrorPrivate> d);
150
153
154 int code() const;
155 void setCode(int code);
156
157 QString text() const;
158 void setText(const QString &text);
159
160 Condition condition() const;
161 void setCondition(Condition cond);
162
163 Type type() const;
164 void setType(Type type);
165
166 QString by() const;
167 void setBy(const QString &by);
168
169 QString redirectionUri() const;
170 void setRedirectionUri(const QString &redirectionUri);
171
172 // XEP-0363: HTTP File Upload
173 bool fileTooLarge() const;
174 void setFileTooLarge(bool);
175
176 qint64 maxFileSize() const;
177 void setMaxFileSize(qint64);
178
179 QDateTime retryDate() const;
180 void setRetryDate(const QDateTime &);
181
183 void parse(const QDomElement &element);
184 void toXml(QXmlStreamWriter *writer) const;
186
187 private:
188 friend class QXmppStanza;
189
190 QSharedDataPointer<QXmppStanzaErrorPrivate> d;
191 };
192
193 QXmppStanza(const QString &from = QString(), const QString &to = QString());
196 ~QXmppStanza() override;
197
200
201 QString to() const;
202 void setTo(const QString &);
203
204 QString from() const;
205 void setFrom(const QString &);
206
207 QString id() const;
208 void setId(const QString &);
209
210 QString lang() const;
211 void setLang(const QString &);
212
214 std::optional<Error> errorOptional() const;
215 void setError(const QXmppStanza::Error &error);
216 void setError(const std::optional<Error> &error);
217
218 QXmppElementList extensions() const;
219 void setExtensions(const QXmppElementList &elements);
220
221 QList<QXmppExtendedAddress> extendedAddresses() const;
222 void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
223
224 std::optional<QXmppE2eeMetadata> e2eeMetadata() const;
225 void setE2eeMetadata(const std::optional<QXmppE2eeMetadata> &e2eeMetadata);
226
228 void parse(const QDomElement &element) override;
229
230protected:
231 void extensionsToXml(QXmlStreamWriter *writer, QXmpp::SceMode = QXmpp::SceAll) const;
232 void generateAndSetNextId();
234
235private:
236 QSharedDataPointer<QXmppStanzaPrivate> d;
237 static uint s_uniqeIdNo;
238 friend class TestClient;
239};
240
241Q_DECLARE_METATYPE(QXmppStanza::Error::Type);
242Q_DECLARE_METATYPE(QXmppStanza::Error::Condition);
243
244#endif // QXMPPSTANZA_H
The QXmppE2eeMetadata class contains data used for end-to-end encryption purposes.
Definition: QXmppE2eeMetadata.h:16
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:39
QXmppExtendedAddress(const QXmppExtendedAddress &)
Default copy-constructur.
QXmppExtendedAddress(QXmppExtendedAddress &&)
Default move-constructur.
QXmppExtendedAddress & operator=(const QXmppExtendedAddress &)
Default assignment operator.
QXmppExtendedAddress & operator=(QXmppExtendedAddress &&)
Default assignment operator.
Definition: QXmppNonza.h:14
virtual void parse(const QDomElement &)=0
The Error class represents a stanza error.
Definition: QXmppStanza.h:94
Error & operator=(Error &&)
Move operator.
~Error()
Default destructor.
Error(Error &&)
Move constructor.
Type
Definition: QXmppStanza.h:100
@ Auth
The request needs to be resent after authentication.
Definition: QXmppStanza.h:105
@ Modify
The request needs to be changed and resent.
Definition: QXmppStanza.h:104
@ Cancel
The error is not temporary.
Definition: QXmppStanza.h:102
@ Continue
The error was only a warning.
Definition: QXmppStanza.h:103
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:110
@ ItemNotFound
The requested item could not be found.
Definition: QXmppStanza.h:118
@ ResourceConstraint
The recipient lacks system resources to perform the request.
Definition: QXmppStanza.h:133
@ UndefinedCondition
An undefined condition was hit.
Definition: QXmppStanza.h:136
@ Forbidden
The requesting entity does not posses the necessary privileges to perform the request.
Definition: QXmppStanza.h:115
@ FeatureNotImplemented
The feature is not implemented.
Definition: QXmppStanza.h:114
@ RegistrationRequired
The requesting entity needs to register first.
Definition: QXmppStanza.h:130
@ NotAcceptable
The request does not meet the defined critera.
Definition: QXmppStanza.h:120
@ Redirect
The requested resource is available elsewhere. This is used in combination with a redirection URI.
Definition: QXmppStanza.h:129
@ BadRequest
The request does not contain a valid schema.
Definition: QXmppStanza.h:112
@ NotAuthorized
The request should be resent after authentication.
Definition: QXmppStanza.h:122
@ Conflict
The request conflicts with another.
Definition: QXmppStanza.h:113
@ UnexpectedRequest
The request was unexpected.
Definition: QXmppStanza.h:137
@ InternalServerError
The server has expierienced an internal error and can not process the request.
Definition: QXmppStanza.h:117
@ Gone
The user or server can not be contacted at the address. This is used in combination with a redirectio...
Definition: QXmppStanza.h:116
@ SubscriptionRequired
The requester needs to subscribe first.
Definition: QXmppStanza.h:135
@ RemoteServerTimeout
The connection to the server could not be established or timed out.
Definition: QXmppStanza.h:132
@ RemoteServerNotFound
The remote server could not be found.
Definition: QXmppStanza.h:131
@ JidMalformed
The given JID is not valid.
Definition: QXmppStanza.h:119
@ ServiceUnavailable
The service is currently not available.
Definition: QXmppStanza.h:134
@ NotAllowed
No entity is allowed to perform the request.
Definition: QXmppStanza.h:121
@ Q_DECL_ENUMERATOR_DEPRECATED_X
Definition: QXmppStanza.h:126
Error & operator=(const Error &)
Copy operator.
Error(const Error &)
Copy constructor.
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:88
QXmppStanza::Error error() const
Definition: QXmppStanza.cpp:905
QString lang() const
Definition: QXmppStanza.cpp:885
void setLang(const QString &)
Definition: QXmppStanza.cpp:895
~QXmppStanza() override
Destroys a QXmppStanza.
QXmppStanza(QXmppStanza &&)
Move constructor.
void setFrom(const QString &)
Definition: QXmppStanza.cpp:859
QXmppElementList extensions() const
Definition: QXmppStanza.cpp:954
void setError(const QXmppStanza::Error &error)
Definition: QXmppStanza.cpp:928
void setE2eeMetadata(const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
Definition: QXmppStanza.cpp:1005
QString to() const
Definition: QXmppStanza.cpp:831
QXmppStanza & operator=(const QXmppStanza &other)
Assigns other to this stanza.
void setTo(const QString &)
Definition: QXmppStanza.cpp:841
QString from() const
Definition: QXmppStanza.cpp:849
QString id() const
Definition: QXmppStanza.cpp:867
void setExtendedAddresses(const QList< QXmppExtendedAddress > &extendedAddresses)
Definition: QXmppStanza.cpp:982
std::optional< QXmppE2eeMetadata > e2eeMetadata() const
Definition: QXmppStanza.cpp:992
std::optional< Error > errorOptional() const
Definition: QXmppStanza.cpp:915
void setExtensions(const QXmppElementList &elements)
Definition: QXmppStanza.cpp:964
QXmppStanza & operator=(QXmppStanza &&)
Move-assignment operator.
QList< QXmppExtendedAddress > extendedAddresses() const
Definition: QXmppStanza.cpp:973
QXmppStanza(const QString &from=QString(), const QString &to=QString())
Definition: QXmppStanza.cpp:810
void setId(const QString &)
Definition: QXmppStanza.cpp:877
QXmppStanza(const QXmppStanza &other)
Constructs a copy of other.
SceMode
Definition: QXmppGlobal.h:136
@ SceAll
Processes all known elements.
Definition: QXmppGlobal.h:137