QXmpp  Version:1.3.2
QXmppStanza.h
1 /*
2  * Copyright (C) 2008-2020 The QXmpp developers
3  *
4  * Authors:
5  * Manjeet Dahiya
6  * Jeremy LainĂ©
7  * Georg Rudoy
8  *
9  * Source:
10  * https://github.com/qxmpp-project/qxmpp
11  *
12  * This file is a part of QXmpp library.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  */
25 
26 #ifndef QXMPPSTANZA_H
27 #define QXMPPSTANZA_H
28 
29 #include <QByteArray>
30 #include <QSharedData>
31 #include <QString>
32 
33 // forward declarations of QXmlStream* classes will not work on Mac, we need to
34 // include the whole header.
35 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
36 // for an explanation.
37 #include "QXmppElement.h"
38 
39 #include <QXmlStreamWriter>
40 
41 class QXmppExtendedAddressPrivate;
42 
52 class QXMPP_EXPORT QXmppExtendedAddress
53 {
54 public:
58 
59  QXmppExtendedAddress &operator=(const QXmppExtendedAddress &);
60 
61  QString description() const;
62  void setDescription(const QString &description);
63 
64  QString jid() const;
65  void setJid(const QString &jid);
66 
67  QString type() const;
68  void setType(const QString &type);
69 
70  bool isDelivered() const;
71  void setDelivered(bool);
72 
73  bool isValid() const;
74 
76  void parse(const QDomElement &element);
77  void toXml(QXmlStreamWriter *writer) const;
79 
80 private:
81  QSharedDataPointer<QXmppExtendedAddressPrivate> d;
82 };
83 
84 class QXmppStanzaPrivate;
85 class QXmppStanzaErrorPrivate;
86 
93 
99 class QXMPP_EXPORT QXmppStanza
100 {
101 public:
105  class QXMPP_EXPORT Error
106  {
107  public:
112  enum Type {
117  Wait
118  };
119 
121  enum Condition {
133 #if QXMPP_DEPRECATED_SINCE(1, 3)
134  PaymentRequired Q_DECL_ENUMERATOR_DEPRECATED_X("The <payment-required/> error was removed in RFC6120"),
137 #endif
138  RecipientUnavailable = 12,
148  PolicyViolation
149  };
150 
151  Error();
152  Error(const Error &);
153  Error(Type type, Condition cond, const QString &text = QString());
154  Error(const QString &type, const QString &cond, const QString &text = QString());
156 
157  Error &operator=(const Error &);
158 
159  int code() const;
160  void setCode(int code);
161 
162  QString text() const;
163  void setText(const QString &text);
164 
165  Condition condition() const;
166  void setCondition(Condition cond);
167 
168  void setType(Type type);
169  Type type() const;
170 
171  QString by() const;
172  void setBy(const QString &by);
173 
174  QString redirectionUri() const;
175  void setRedirectionUri(const QString &redirectionUri);
176 
177  // XEP-0363: HTTP File Upload
178  bool fileTooLarge() const;
179  void setFileTooLarge(bool);
180 
181  qint64 maxFileSize() const;
182  void setMaxFileSize(qint64);
183 
184  QDateTime retryDate() const;
185  void setRetryDate(const QDateTime &);
186 
188  void parse(const QDomElement &element);
189  void toXml(QXmlStreamWriter *writer) const;
191 
192  private:
193  QString getConditionStr() const;
194  void setConditionFromStr(const QString &cond);
195 
196  QString getTypeStr() const;
197  void setTypeFromStr(const QString &type);
198 
199  QSharedDataPointer<QXmppStanzaErrorPrivate> d;
200  };
201 
202  QXmppStanza(const QString &from = QString(), const QString &to = QString());
203  QXmppStanza(const QXmppStanza &other);
204  virtual ~QXmppStanza();
205 
206  QXmppStanza &operator=(const QXmppStanza &other);
207 
208  QString to() const;
209  void setTo(const QString &);
210 
211  QString from() const;
212  void setFrom(const QString &);
213 
214  QString id() const;
215  void setId(const QString &);
216 
217  QString lang() const;
218  void setLang(const QString &);
219 
220  QXmppStanza::Error error() const;
221  void setError(const QXmppStanza::Error &error);
222 
223  QXmppElementList extensions() const;
224  void setExtensions(const QXmppElementList &elements);
225 
226  QList<QXmppExtendedAddress> extendedAddresses() const;
227  void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
228 
229  virtual bool isXmppStanza() const;
230 
232  virtual void parse(const QDomElement &element);
233  virtual void toXml(QXmlStreamWriter *writer) const = 0;
234 
235 protected:
236  void extensionsToXml(QXmlStreamWriter *writer) const;
237  void generateAndSetNextId();
239 
240 private:
241  QSharedDataPointer<QXmppStanzaPrivate> d;
242  static uint s_uniqeIdNo;
243 };
244 
245 Q_DECLARE_METATYPE(QXmppStanza::Error::Type);
246 Q_DECLARE_METATYPE(QXmppStanza::Error::Condition);
247 
248 #endif // QXMPPSTANZA_H
QXmppStanza::Error::NotAcceptable
@ NotAcceptable
The request does not meet the defined critera.
Definition: QXmppStanza.h:130
QXmppStanza::Error::NotAuthorized
@ NotAuthorized
The request should be resent after authentication.
Definition: QXmppStanza.h:132
QXmppStanza::Error::operator=
Error & operator=(const Error &)
Copy operator.
QXmppStanza::Error::JidMalformed
@ JidMalformed
The given JID is not valid.
Definition: QXmppStanza.h:129
QXmppStanza::Error::RegistrationRequired
@ RegistrationRequired
The requesting entity needs to register first.
Definition: QXmppStanza.h:140
QXmppExtendedAddress
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:53
QXmppStanza::Error::RemoteServerTimeout
@ RemoteServerTimeout
The connection to the server could not be established or timed out.
Definition: QXmppStanza.h:142
QXmppStanza::Error
The Error class represents a stanza error.
Definition: QXmppStanza.h:106
QXmppStanza::Error::Forbidden
@ Forbidden
The requesting entity does not posses the necessary privileges to perform the request.
Definition: QXmppStanza.h:125
QXmppStanza::Error::UnexpectedRequest
@ UnexpectedRequest
The request was unexpected.
Definition: QXmppStanza.h:147
QXmppStanza::Error::Error
Error(const Error &)
Copy constructor.
QXmppStanza::Error::Conflict
@ Conflict
The request conflicts with another.
Definition: QXmppStanza.h:123
QXmppStanza::Error::Auth
@ Auth
The request needs to be resent after authentication.
Definition: QXmppStanza.h:116
QXmppStanza::Error::Modify
@ Modify
The request needs to be changed and resent.
Definition: QXmppStanza.h:115
QXmppStanza::Error::UndefinedCondition
@ UndefinedCondition
An undefined condition was hit.
Definition: QXmppStanza.h:146
QXmppStanza
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:100
QXmppStanza::Error::RemoteServerNotFound
@ RemoteServerNotFound
The remote server could not be found.
Definition: QXmppStanza.h:141
QXmppStanza::Error::~Error
~Error()
Default destructor.
QXmppStanza::Error::ItemNotFound
@ ItemNotFound
The requested item could not be found.
Definition: QXmppStanza.h:128
QXmppStanza::Error::NotAllowed
@ NotAllowed
No entity is allowed to perform the request.
Definition: QXmppStanza.h:131
QXmppStanza::Error::FeatureNotImplemented
@ FeatureNotImplemented
The feature is not implemented.
Definition: QXmppStanza.h:124
QXmppStanza::Error::InternalServerError
@ InternalServerError
The server has expierienced an internal error and can not process the request.
Definition: QXmppStanza.h:127
QXmppStanza::Error::SubscriptionRequired
@ SubscriptionRequired
The requester needs to subscribe first.
Definition: QXmppStanza.h:145
QXmppStanza::Error::Condition
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:121
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:126
QXmppStanza::Error::ServiceUnavailable
@ ServiceUnavailable
The service is currently not available.
Definition: QXmppStanza.h:144
QXmppExtendedAddress::QXmppExtendedAddress
QXmppExtendedAddress(const QXmppExtendedAddress &)
QXmppStanza::Error::Continue
@ Continue
The error was only a warning.
Definition: QXmppStanza.h:114
QXmppStanza::Error::Redirect
@ Redirect
The requested resource is available elsewhere. This is used in combination with a redirection URI.
Definition: QXmppStanza.h:139
QXmppStanza::Error::Cancel
@ Cancel
The error is not temporary.
Definition: QXmppStanza.h:113
QXmppStanza::Error::BadRequest
@ BadRequest
The request does not contain a valid schema.
Definition: QXmppStanza.h:122
QXmppStanza::Error::Type
Type
Definition: QXmppStanza.h:112
QXmppStanza::Error::ResourceConstraint
@ ResourceConstraint
The recipient lacks system resources to perform the request.
Definition: QXmppStanza.h:143