QXmpp  Version: 1.5.3
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 
26 class QXmppE2eeMetadata;
27 class QXmppExtendedAddressPrivate;
28 
38 class QXMPP_EXPORT QXmppExtendedAddress
39 {
40 public:
45 
46  QXmppExtendedAddress &operator=(const QXmppExtendedAddress &);
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 
68 private:
69  QSharedDataPointer<QXmppExtendedAddressPrivate> d;
70 };
71 
72 class QXmppStanzaPrivate;
73 class QXmppStanzaErrorPrivate;
74 
81 
87 class QXMPP_EXPORT QXmppStanza : public QXmppNonza
88 {
89 public:
93  class QXMPP_EXPORT Error
94  {
95  public:
100  enum Type {
101  NoType = -1,
106  Wait
107  };
108 
110  enum Condition {
111  NoCondition = -1,
123 #if QXMPP_DEPRECATED_SINCE(1, 3)
124  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 &);
143  Error(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);
149  ~Error();
150 
151  Error &operator=(const Error &);
152  Error &operator=(Error &&);
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());
194  QXmppStanza(const QXmppStanza &other);
196  virtual ~QXmppStanza();
197 
198  QXmppStanza &operator=(const QXmppStanza &other);
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 
213  QXmppStanza::Error error() const;
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 
230 protected:
231  void extensionsToXml(QXmlStreamWriter *writer, QXmpp::SceMode = QXmpp::SceAll) const;
232  void generateAndSetNextId();
234 
235 private:
236  QSharedDataPointer<QXmppStanzaPrivate> d;
237  static uint s_uniqeIdNo;
238  friend class TestClient;
239 };
240 
241 Q_DECLARE_METATYPE(QXmppStanza::Error::Type);
242 Q_DECLARE_METATYPE(QXmppStanza::Error::Condition);
243 
244 #endif // QXMPPSTANZA_H
The request does not contain a valid schema.
Definition: QXmppStanza.h:112
The error is not temporary.
Definition: QXmppStanza.h:102
The connection to the server could not be established or timed out.
Definition: QXmppStanza.h:132
The given JID is not valid.
Definition: QXmppStanza.h:119
void setId(const QString &)
Definition: QXmppStanza.cpp:876
QString lang() const
Definition: QXmppStanza.cpp:884
QList< QXmppExtendedAddress > extendedAddresses() const
Definition: QXmppStanza.cpp:972
The requesting entity needs to register first.
Definition: QXmppStanza.h:130
void setTo(const QString &)
Definition: QXmppStanza.cpp:840
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:87
The request should be resent after authentication.
Definition: QXmppStanza.h:122
std::optional< Error > errorOptional() const
Definition: QXmppStanza.cpp:914
QXmppStanza(const QString &from=QString(), const QString &to=QString())
Definition: QXmppStanza.cpp:809
The request conflicts with another.
Definition: QXmppStanza.h:113
virtual void parse(const QDomElement &)=0
QXmppStanza::Error error() const
Definition: QXmppStanza.cpp:904
The requesting entity does not posses the necessary privileges to perform the request.
Definition: QXmppStanza.h:115
An undefined condition was hit.
Definition: QXmppStanza.h:136
The request was unexpected.
Definition: QXmppStanza.h:137
The request needs to be resent after authentication.
Definition: QXmppStanza.h:105
void setExtensions(const QXmppElementList &elements)
Definition: QXmppStanza.cpp:963
The request needs to be changed and resent.
Definition: QXmppStanza.h:104
QString from() const
Definition: QXmppStanza.cpp:848
The remote server could not be found.
Definition: QXmppStanza.h:131
QString id() const
Definition: QXmppStanza.cpp:866
QXmppElementList extensions() const
Definition: QXmppStanza.cpp:953
QString to() const
Definition: QXmppStanza.cpp:830
SceMode
Definition: QXmppGlobal.h:136
The user or server can not be contacted at the address. This is used in combination with a redirectio...
Definition: QXmppStanza.h:116
The service is currently not available.
Definition: QXmppStanza.h:134
The feature is not implemented.
Definition: QXmppStanza.h:114
std::optional< QXmppE2eeMetadata > e2eeMetadata() const
Definition: QXmppStanza.cpp:991
void setError(const QXmppStanza::Error &error)
Definition: QXmppStanza.cpp:927
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:110
The requested item could not be found.
Definition: QXmppStanza.h:118
No entity is allowed to perform the request.
Definition: QXmppStanza.h:121
Processes all known elements.
Definition: QXmppGlobal.h:137
void setFrom(const QString &)
Definition: QXmppStanza.cpp:858
Definition: QXmppNonza.h:13
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:38
The requester needs to subscribe first.
Definition: QXmppStanza.h:135
The server has expierienced an internal error and can not process the request.
Definition: QXmppStanza.h:117
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:1004
Type
Definition: QXmppStanza.h:100
The requested resource is available elsewhere. This is used in combination with a redirection URI...
Definition: QXmppStanza.h:129
The Error class represents a stanza error.
Definition: QXmppStanza.h:93
The request does not meet the defined critera.
Definition: QXmppStanza.h:120
virtual ~QXmppStanza()
Destroys a QXmppStanza.
The recipient lacks system resources to perform the request.
Definition: QXmppStanza.h:133
void setLang(const QString &)
Definition: QXmppStanza.cpp:894
QXmppStanza & operator=(const QXmppStanza &other)
Assigns other to this stanza.
The error was only a warning.
Definition: QXmppStanza.h:103
void setExtendedAddresses(const QList< QXmppExtendedAddress > &extendedAddresses)
Definition: QXmppStanza.cpp:981