QXmpp  Version:1.2.0
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 
48 
49 class QXMPP_EXPORT QXmppExtendedAddress
50 {
51 public:
55 
56  QXmppExtendedAddress &operator=(const QXmppExtendedAddress &);
57 
58  QString description() const;
59  void setDescription(const QString &description);
60 
61  QString jid() const;
62  void setJid(const QString &jid);
63 
64  QString type() const;
65  void setType(const QString &type);
66 
67  bool isDelivered() const;
68  void setDelivered(bool);
69 
70  bool isValid() const;
71 
73  void parse(const QDomElement &element);
74  void toXml(QXmlStreamWriter *writer) const;
76 
77 private:
78  QSharedDataPointer<QXmppExtendedAddressPrivate> d;
79 };
80 
81 class QXmppStanzaPrivate;
82 class QXmppStanzaErrorPrivate;
83 
90 
96 class QXMPP_EXPORT QXmppStanza
97 {
98 public:
102  class QXMPP_EXPORT Error
103  {
104  public:
109  enum Type {
114  Wait
115  };
116 
118  enum Condition {
140  UnexpectedRequest
141  };
142 
143  Error();
144  Error(const Error &);
145  Error(Type type, Condition cond, const QString &text = QString());
146  Error(const QString &type, const QString &cond, const QString &text = QString());
147  ~Error();
148 
149  Error &operator=(const Error &);
150 
151  int code() const;
152  void setCode(int code);
153 
154  QString text() const;
155  void setText(const QString &text);
156 
157  Condition condition() const;
158  void setCondition(Condition cond);
159 
160  void setType(Type type);
161  Type type() const;
162 
163  // XEP-0363: HTTP File Upload
164  bool fileTooLarge() const;
165  void setFileTooLarge(bool);
166 
167  qint64 maxFileSize() const;
168  void setMaxFileSize(qint64);
169 
170  QDateTime retryDate() const;
171  void setRetryDate(const QDateTime &);
172 
174  void parse(const QDomElement &element);
175  void toXml(QXmlStreamWriter *writer) const;
177 
178  private:
179  QString getConditionStr() const;
180  void setConditionFromStr(const QString &cond);
181 
182  QString getTypeStr() const;
183  void setTypeFromStr(const QString &type);
184 
185  QSharedDataPointer<QXmppStanzaErrorPrivate> d;
186  };
187 
188  QXmppStanza(const QString &from = QString(), const QString &to = QString());
189  QXmppStanza(const QXmppStanza &other);
190  virtual ~QXmppStanza();
191 
192  QXmppStanza &operator=(const QXmppStanza &other);
193 
194  QString to() const;
195  void setTo(const QString &);
196 
197  QString from() const;
198  void setFrom(const QString &);
199 
200  QString id() const;
201  void setId(const QString &);
202 
203  QString lang() const;
204  void setLang(const QString &);
205 
206  QXmppStanza::Error error() const;
207  void setError(const QXmppStanza::Error &error);
208 
209  QXmppElementList extensions() const;
210  void setExtensions(const QXmppElementList &elements);
211 
212  QList<QXmppExtendedAddress> extendedAddresses() const;
213  void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
214 
215  virtual bool isXmppStanza() const;
216 
218  virtual void parse(const QDomElement &element);
219  virtual void toXml(QXmlStreamWriter *writer) const = 0;
220 
221 protected:
222  void extensionsToXml(QXmlStreamWriter *writer) const;
223  void generateAndSetNextId();
225 
226 private:
227  QSharedDataPointer<QXmppStanzaPrivate> d;
228  static uint s_uniqeIdNo;
229 };
230 
231 #endif // QXMPPSTANZA_H
QXmppStanza::Error::NotAcceptable
The request does not meet the defined critera.
Definition: QXmppStanza.h:127
QXmppStanza::Error::NotAuthorized
The request should be resent after authentication.
Definition: QXmppStanza.h:129
QXmppStanza::Error::JidMalformed
The given JID is not valid.
Definition: QXmppStanza.h:126
QXmppStanza::Error::RegistrationRequired
The requesting entity needs to register first.
Definition: QXmppStanza.h:133
QXmppExtendedAddress
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:49
QXmppStanza::Error::RemoteServerTimeout
The connection to the server could not be established or timed out.
Definition: QXmppStanza.h:135
QXmppStanza::Error
The Error class represents a stanza error.
Definition: QXmppStanza.h:102
QXmppStanza::Error::Forbidden
The requesting entity does not posses the necessary privileges to perform the request.
Definition: QXmppStanza.h:122
QXmppStanza::Error::Conflict
The request conflicts with another.
Definition: QXmppStanza.h:120
QXmppStanza::Error::PaymentRequired
Payment is required to perform the request.
Definition: QXmppStanza.h:130
QXmppStanza::Error::Auth
The request needs to be resent after authentication.
Definition: QXmppStanza.h:113
QXmppStanza::Error::Modify
The request needs to be changed and resent.
Definition: QXmppStanza.h:112
QXmppStanza::Error::RecipientUnavailable
The recipient is unavailable.
Definition: QXmppStanza.h:131
QXmppStanza::Error::UndefinedCondition
An undefined condition was hit.
Definition: QXmppStanza.h:139
QXmppStanza
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:96
QXmppStanza::Error::RemoteServerNotFound
The remote server could not be found.
Definition: QXmppStanza.h:134
QXmppStanza::Error::ItemNotFound
The requested item could not be found.
Definition: QXmppStanza.h:125
QXmppStanza::Error::NotAllowed
No entity is allowed to perform the request.
Definition: QXmppStanza.h:128
QXmppStanza::Error::FeatureNotImplemented
The feature is not implemented.
Definition: QXmppStanza.h:121
QXmppStanza::Error::InternalServerError
The server has expierienced an internal error and can not process the request.
Definition: QXmppStanza.h:124
QXmppStanza::Error::SubscriptionRequired
The requester needs to subscribe first.
Definition: QXmppStanza.h:138
QXmppStanza::Error::Condition
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:118
QXmppStanza::Error::Gone
The user or server can not be contacted at the address.
Definition: QXmppStanza.h:123
QXmppStanza::Error::ServiceUnavailable
The service is currently not available.
Definition: QXmppStanza.h:137
QXmppStanza::Error::Continue
The error was only a warning.
Definition: QXmppStanza.h:111
QXmppStanza::Error::Redirect
The requested resource is available elsewhere.
Definition: QXmppStanza.h:132
QXmppStanza::Error::Cancel
The error is not temporary.
Definition: QXmppStanza.h:110
QXmppStanza::Error::BadRequest
The request does not contain a valid schema.
Definition: QXmppStanza.h:119
QXmppStanza::Error::Type
Type
Definition: QXmppStanza.h:109
QXmppStanza::Error::ResourceConstraint
The recipient lacks system resources to perform the request.
Definition: QXmppStanza.h:136