QXmpp  Version:0.4.92
 All Classes Functions Enumerations Enumerator Properties Groups
QXmppStanza.h
1 /*
2  * Copyright (C) 2008-2011 The QXmpp developers
3  *
4  * Author:
5  * Manjeet Dahiya
6  *
7  * Source:
8  * http://code.google.com/p/qxmpp
9  *
10  * This file is a part of QXmpp library.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  */
23 
24 
25 #ifndef QXMPPSTANZA_H
26 #define QXMPPSTANZA_H
27 
28 #include <QByteArray>
29 #include <QString>
30 
31 // forward declarations of QXmlStream* classes will not work on Mac, we need to
32 // include the whole header.
33 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
34 // for an explanation.
35 #include <QXmlStreamWriter>
36 
37 #include "QXmppElement.h"
38 
40 
44 
45 class QXMPP_EXPORT QXmppStanza
46 {
47 public:
48  class QXMPP_EXPORT Error
49  {
50  public:
51  enum Type
52  {
53  Cancel,
54  Continue,
55  Modify,
56  Auth,
57  Wait
58  };
59 
60  enum Condition
61  {
62  BadRequest,
63  Conflict,
64  FeatureNotImplemented,
65  Forbidden,
66  Gone,
67  InternalServerError,
68  ItemNotFound,
69  JidMalformed,
70  NotAcceptable,
71  NotAllowed,
72  NotAuthorized,
73  PaymentRequired,
74  RecipientUnavailable,
75  Redirect,
76  RegistrationRequired,
77  RemoteServerNotFound,
78  RemoteServerTimeout,
79  ResourceConstraint,
80  ServiceUnavailable,
81  SubscriptionRequired,
82  UndefinedCondition,
83  UnexpectedRequest
84  };
85 
86  Error();
87  Error(Type type, Condition cond, const QString& text="");
88  Error(const QString& type, const QString& cond, const QString& text="");
89 
90  int code() const;
91  void setCode(int code);
92 
93  QString text() const;
94  void setText(const QString& text);
95 
96  Condition condition() const;
97  void setCondition(Condition cond);
98 
99  void setType(Type type);
100  Type type() const;
101 
103  void parse(const QDomElement &element);
104  void toXml(QXmlStreamWriter *writer) const;
106 
107  private:
108  QString getConditionStr() const;
109  void setConditionFromStr(const QString& cond);
110 
111  QString getTypeStr() const;
112  void setTypeFromStr(const QString& type);
113 
114  int m_code;
115  Type m_type;
116  Condition m_condition;
117  QString m_text;
118  };
119 
120  QXmppStanza(const QString& from = QString(), const QString& to = QString());
121  virtual ~QXmppStanza();
122 
123  QString to() const;
124  void setTo(const QString&);
125 
126  QString from() const;
127  void setFrom(const QString&);
128 
129  QString id() const;
130  void setId(const QString&);
131 
132  QString lang() const;
133  void setLang(const QString&);
134 
135  QXmppStanza::Error error() const;
136  void setError(const QXmppStanza::Error& error);
137 
138  QXmppElementList extensions() const;
139  void setExtensions(const QXmppElementList &elements);
140 
142  virtual void parse(const QDomElement &element);
143  virtual void toXml(QXmlStreamWriter *writer) const = 0;
144 
145 protected:
146  void generateAndSetNextId();
148 
149 private:
150  static uint s_uniqeIdNo;
151  QString m_to;
152  QString m_from;
153  QString m_id;
154  QString m_lang;
155  QXmppStanza::Error m_error;
156  QXmppElementList m_extensions;
157 };
158 
159 #endif // QXMPPSTANZA_H