QXmpp  Version:1.1.0
QXmppStanza.h
1 /*
2  * Copyright (C) 2008-2019 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 
27 #ifndef QXMPPSTANZA_H
28 #define QXMPPSTANZA_H
29 
30 #include <QByteArray>
31 #include <QString>
32 #include <QSharedData>
33 
34 // forward declarations of QXmlStream* classes will not work on Mac, we need to
35 // include the whole header.
36 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
37 // for an explanation.
38 #include <QXmlStreamWriter>
39 
40 #include "QXmppElement.h"
41 
42 class QXmppExtendedAddressPrivate;
43 
49 
50 class QXMPP_EXPORT QXmppExtendedAddress
51 {
52 public:
56 
57  QXmppExtendedAddress& operator=(const QXmppExtendedAddress&);
58 
59  QString description() const;
60  void setDescription(const QString &description);
61 
62  QString jid() const;
63  void setJid(const QString &jid);
64 
65  QString type() const;
66  void setType(const QString &type);
67 
68  bool isDelivered() const;
69  void setDelivered(bool);
70 
71  bool isValid() const;
72 
74  void parse(const QDomElement &element);
75  void toXml(QXmlStreamWriter *writer) const;
77 
78 private:
79  QSharedDataPointer<QXmppExtendedAddressPrivate> d;
80 };
81 
82 class QXmppStanzaPrivate;
83 class QXmppStanzaErrorPrivate;
84 
86 
90 
91 class QXMPP_EXPORT QXmppStanza
92 {
93 public:
94  class QXMPP_EXPORT Error
95  {
96  public:
97  enum Type
98  {
99  Cancel,
100  Continue,
101  Modify,
102  Auth,
103  Wait
104  };
105 
106  enum Condition
107  {
108  BadRequest,
109  Conflict,
110  FeatureNotImplemented,
111  Forbidden,
112  Gone,
113  InternalServerError,
114  ItemNotFound,
115  JidMalformed,
116  NotAcceptable,
117  NotAllowed,
118  NotAuthorized,
119  PaymentRequired,
120  RecipientUnavailable,
121  Redirect,
122  RegistrationRequired,
123  RemoteServerNotFound,
124  RemoteServerTimeout,
125  ResourceConstraint,
126  ServiceUnavailable,
127  SubscriptionRequired,
128  UndefinedCondition,
129  UnexpectedRequest
130  };
131 
132  Error();
133  Error(const Error &);
134  Error(Type type, Condition cond, const QString& text = QString());
135  Error(const QString& type, const QString& cond, const QString& text = QString());
136  ~Error();
137 
138  Error &operator=(const Error &);
139 
140  int code() const;
141  void setCode(int code);
142 
143  QString text() const;
144  void setText(const QString& text);
145 
146  Condition condition() const;
147  void setCondition(Condition cond);
148 
149  void setType(Type type);
150  Type type() const;
151 
152  // XEP-0363: HTTP File Upload
153  bool fileTooLarge() const;
154  void setFileTooLarge(bool);
155 
156  qint64 maxFileSize() const;
157  void setMaxFileSize(qint64);
158 
159  QDateTime retryDate() const;
160  void setRetryDate(const QDateTime&);
161 
163  void parse(const QDomElement &element);
164  void toXml(QXmlStreamWriter *writer) const;
166 
167  private:
168  QString getConditionStr() const;
169  void setConditionFromStr(const QString& cond);
170 
171  QString getTypeStr() const;
172  void setTypeFromStr(const QString& type);
173 
174  QSharedDataPointer<QXmppStanzaErrorPrivate> d;
175  };
176 
177  QXmppStanza(const QString& from = QString(), const QString& to = QString());
178  QXmppStanza(const QXmppStanza &other);
179  virtual ~QXmppStanza();
180 
181  QXmppStanza& operator=(const QXmppStanza &other);
182 
183  QString to() const;
184  void setTo(const QString&);
185 
186  QString from() const;
187  void setFrom(const QString&);
188 
189  QString id() const;
190  void setId(const QString&);
191 
192  QString lang() const;
193  void setLang(const QString&);
194 
195  QXmppStanza::Error error() const;
196  void setError(const QXmppStanza::Error& error);
197 
198  QXmppElementList extensions() const;
199  void setExtensions(const QXmppElementList &elements);
200 
201  QList<QXmppExtendedAddress> extendedAddresses() const;
202  void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
203 
204  virtual bool isXmppStanza() const;
205 
207  virtual void parse(const QDomElement &element);
208  virtual void toXml(QXmlStreamWriter *writer) const = 0;
209 
210 protected:
211  void extensionsToXml(QXmlStreamWriter *writer) const;
212  void generateAndSetNextId();
214 
215 private:
216  QSharedDataPointer<QXmppStanzaPrivate> d;
217  static uint s_uniqeIdNo;
218 };
219 
220 #endif // QXMPPSTANZA_H
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:91
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:50