QXmpp  Version: 1.15.1
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 
27 class QXmppE2eeMetadata;
28 class QXmppExtendedAddressPrivate;
29 
30 namespace QXmpp {
31 
38  OutOfOrder,
39  TieBreak,
40  UnknownSession,
41  UnsupportedInfo,
42 };
43 
44 } // namespace QXmpp
45 
55 class QXMPP_EXPORT QXmppExtendedAddress
56 {
57 public:
62 
63  QXmppExtendedAddress &operator=(const 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 
86 private:
87  QSharedDataPointer<QXmppExtendedAddressPrivate> d;
88 };
89 
90 class QXmppStanzaPrivate;
91 class QXmppStanzaErrorPrivate;
92 
99 
105 class QXMPP_EXPORT QXmppStanza : public QXmppNonza
106 {
107 public:
111  class QXMPP_EXPORT Error
112  {
113  public:
118  enum Type {
119  NoType = -1,
124  Wait
125  };
126 
128  enum Condition {
129  NoCondition = -1,
141 #if QXMPP_DEPRECATED_SINCE(1, 3)
142  PaymentRequired Q_DECL_ENUMERATOR_DEPRECATED_X("The <payment-required/> error was removed in RFC6120"),
145 #endif
146  RecipientUnavailable = 12,
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);
218  ~QXmppStanza() override;
219 
220  QXmppStanza &operator=(const QXmppStanza &other);
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 
252 protected:
253  void extensionsToXml(QXmlStreamWriter *writer, QXmpp::SceMode = QXmpp::SceAll) const;
254  void generateAndSetNextId();
256 
257 private:
258  QSharedDataPointer<QXmppStanzaPrivate> d;
259  friend class TestClient;
260 };
261 
262 Q_DECLARE_METATYPE(QXmppStanza::Error::Type);
263 Q_DECLARE_METATYPE(QXmppStanza::Error::Condition);
264 
265 #endif // QXMPPSTANZA_H
The request does not contain a valid schema.
Definition: QXmppStanza.h:130
The error is not temporary.
Definition: QXmppStanza.h:120
The connection to the server could not be established or timed out.
Definition: QXmppStanza.h:150
The given JID is not valid.
Definition: QXmppStanza.h:137
void setId(const QString &)
Definition: QXmppStanza.cpp:760
QString lang() const
Definition: QXmppStanza.cpp:768
QList< QXmppExtendedAddress > extendedAddresses() const
Definition: QXmppStanza.cpp:856
The requesting entity needs to register first.
Definition: QXmppStanza.h:148
void setTo(const QString &)
Definition: QXmppStanza.cpp:724
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:105
The request should be resent after authentication.
Definition: QXmppStanza.h:140
std::optional< Error > errorOptional() const
Definition: QXmppStanza.cpp:798
QXmppStanza(const QString &from=QString(), const QString &to=QString())
Definition: QXmppStanza.cpp:693
The request conflicts with another.
Definition: QXmppStanza.h:131
JingleErrorCondition
Definition: QXmppStanza.h:37
~QXmppStanza() override
Destroys a QXmppStanza.
virtual void parse(const QDomElement &)=0
QXmppStanza::Error error() const
Definition: QXmppStanza.cpp:788
The requesting entity does not posses the necessary privileges to perform the request.
Definition: QXmppStanza.h:133
An undefined condition was hit.
Definition: QXmppStanza.h:154
The request was unexpected.
Definition: QXmppStanza.h:155
The request needs to be resent after authentication.
Definition: QXmppStanza.h:123
void setExtensions(const QXmppElementList &elements)
Definition: QXmppStanza.cpp:847
The request needs to be changed and resent.
Definition: QXmppStanza.h:122
QString from() const
Definition: QXmppStanza.cpp:732
The remote server could not be found.
Definition: QXmppStanza.h:149
QString id() const
Definition: QXmppStanza.cpp:750
QXmppElementList extensions() const
Definition: QXmppStanza.cpp:837
QString to() const
Definition: QXmppStanza.cpp:714
SceMode
Definition: QXmppGlobal.h:148
The user or server can not be contacted at the address. This is used in combination with a redirectio...
Definition: QXmppStanza.h:134
The service is currently not available.
Definition: QXmppStanza.h:152
The feature is not implemented.
Definition: QXmppStanza.h:132
std::optional< QXmppE2eeMetadata > e2eeMetadata() const
Definition: QXmppStanza.cpp:875
void setError(const QXmppStanza::Error &error)
Definition: QXmppStanza.cpp:811
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:128
The requested item could not be found.
Definition: QXmppStanza.h:136
No entity is allowed to perform the request.
Definition: QXmppStanza.h:139
Processes all known elements.
Definition: QXmppGlobal.h:149
void setFrom(const QString &)
Definition: QXmppStanza.cpp:742
Definition: QXmppNonza.h:13
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:55
The requester needs to subscribe first.
Definition: QXmppStanza.h:153
The server has expierienced an internal error and can not process the request.
Definition: QXmppStanza.h:135
The QXmppE2eeMetadata class contains data used for end-to-end encryption purposes.
Definition: QXmppE2eeMetadata.h:15
void setE2eeMetadata(const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
Definition: QXmppStanza.cpp:888
Type
Definition: QXmppStanza.h:118
The requested resource is available elsewhere. This is used in combination with a redirection URI...
Definition: QXmppStanza.h:147
The Error class represents a stanza error.
Definition: QXmppStanza.h:111
The request does not meet the defined critera.
Definition: QXmppStanza.h:138
The recipient lacks system resources to perform the request.
Definition: QXmppStanza.h:151
void setLang(const QString &)
Definition: QXmppStanza.cpp:778
QXmppStanza & operator=(const QXmppStanza &other)
Assigns other to this stanza.
The error was only a warning.
Definition: QXmppStanza.h:121
void setExtendedAddresses(const QList< QXmppExtendedAddress > &extendedAddresses)
Definition: QXmppStanza.cpp:865