QXmpp  Version:0.9.1
QXmppStanza.h
1 /*
2  * Copyright (C) 2008-2014 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 
85 
89 
90 class QXMPP_EXPORT QXmppStanza
91 {
92 public:
93  class QXMPP_EXPORT Error
94  {
95  public:
96  enum Type
97  {
98  Cancel,
99  Continue,
100  Modify,
101  Auth,
102  Wait
103  };
104 
105  enum Condition
106  {
107  BadRequest,
108  Conflict,
109  FeatureNotImplemented,
110  Forbidden,
111  Gone,
112  InternalServerError,
113  ItemNotFound,
114  JidMalformed,
115  NotAcceptable,
116  NotAllowed,
117  NotAuthorized,
118  PaymentRequired,
119  RecipientUnavailable,
120  Redirect,
121  RegistrationRequired,
122  RemoteServerNotFound,
123  RemoteServerTimeout,
124  ResourceConstraint,
125  ServiceUnavailable,
126  SubscriptionRequired,
127  UndefinedCondition,
128  UnexpectedRequest
129  };
130 
131  Error();
132  Error(Type type, Condition cond, const QString& text = QString());
133  Error(const QString& type, const QString& cond, const QString& text = QString());
134 
135  int code() const;
136  void setCode(int code);
137 
138  QString text() const;
139  void setText(const QString& text);
140 
141  Condition condition() const;
142  void setCondition(Condition cond);
143 
144  void setType(Type type);
145  Type type() const;
146 
148  void parse(const QDomElement &element);
149  void toXml(QXmlStreamWriter *writer) const;
151 
152  private:
153  QString getConditionStr() const;
154  void setConditionFromStr(const QString& cond);
155 
156  QString getTypeStr() const;
157  void setTypeFromStr(const QString& type);
158 
159  int m_code;
160  Type m_type;
161  Condition m_condition;
162  QString m_text;
163  };
164 
165  QXmppStanza(const QString& from = QString(), const QString& to = QString());
166  QXmppStanza(const QXmppStanza &other);
167  virtual ~QXmppStanza();
168 
169  QXmppStanza& operator=(const QXmppStanza &other);
170 
171  QString to() const;
172  void setTo(const QString&);
173 
174  QString from() const;
175  void setFrom(const QString&);
176 
177  QString id() const;
178  void setId(const QString&);
179 
180  QString lang() const;
181  void setLang(const QString&);
182 
183  QXmppStanza::Error error() const;
184  void setError(const QXmppStanza::Error& error);
185 
186  QXmppElementList extensions() const;
187  void setExtensions(const QXmppElementList &elements);
188 
189  QList<QXmppExtendedAddress> extendedAddresses() const;
190  void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
191 
193  virtual void parse(const QDomElement &element);
194  virtual void toXml(QXmlStreamWriter *writer) const = 0;
195 
196 protected:
197  void extensionsToXml(QXmlStreamWriter *writer) const;
198  void generateAndSetNextId();
200 
201 private:
202  QSharedDataPointer<QXmppStanzaPrivate> d;
203  static uint s_uniqeIdNo;
204 };
205 
206 #endif // QXMPPSTANZA_H
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:90
Represents an extended address as defined by XEP-0033: Extended Stanza Addressing.
Definition: QXmppStanza.h:50