QXmpp  Version:0.9.3
QXmppStanza.h
00001 /*
00002  * Copyright (C) 2008-2014 The QXmpp developers
00003  *
00004  * Authors:
00005  *  Manjeet Dahiya
00006  *  Jeremy Lainé
00007  *  Georg Rudoy
00008  *
00009  * Source:
00010  *  https://github.com/qxmpp-project/qxmpp
00011  *
00012  * This file is a part of QXmpp library.
00013  *
00014  * This library is free software; you can redistribute it and/or
00015  * modify it under the terms of the GNU Lesser General Public
00016  * License as published by the Free Software Foundation; either
00017  * version 2.1 of the License, or (at your option) any later version.
00018  *
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  */
00025 
00026 
00027 #ifndef QXMPPSTANZA_H
00028 #define QXMPPSTANZA_H
00029 
00030 #include <QByteArray>
00031 #include <QString>
00032 #include <QSharedData>
00033 
00034 // forward declarations of QXmlStream* classes will not work on Mac, we need to
00035 // include the whole header.
00036 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
00037 // for an explanation.
00038 #include <QXmlStreamWriter>
00039 
00040 #include "QXmppElement.h"
00041 
00042 class QXmppExtendedAddressPrivate;
00043 
00049 
00050 class QXMPP_EXPORT QXmppExtendedAddress
00051 {
00052 public:
00053     QXmppExtendedAddress();
00054     QXmppExtendedAddress(const QXmppExtendedAddress&);
00055     ~QXmppExtendedAddress();
00056 
00057     QXmppExtendedAddress& operator=(const QXmppExtendedAddress&);
00058 
00059     QString description() const;
00060     void setDescription(const QString &description);
00061 
00062     QString jid() const;
00063     void setJid(const QString &jid);
00064 
00065     QString type() const;
00066     void setType(const QString &type);
00067 
00068     bool isDelivered() const;
00069     void setDelivered(bool);
00070 
00071     bool isValid() const;
00072 
00074     void parse(const QDomElement &element);
00075     void toXml(QXmlStreamWriter *writer) const;
00077 
00078 private:
00079     QSharedDataPointer<QXmppExtendedAddressPrivate> d;
00080 };
00081 
00082 class QXmppStanzaPrivate;
00083 
00085 
00089 
00090 class QXMPP_EXPORT QXmppStanza
00091 {
00092 public:
00093     class QXMPP_EXPORT Error
00094     {
00095     public:
00096         enum Type
00097         {
00098             Cancel,
00099             Continue,
00100             Modify,
00101             Auth,
00102             Wait
00103         };
00104 
00105         enum Condition
00106         {
00107             BadRequest,
00108             Conflict,
00109             FeatureNotImplemented,
00110             Forbidden,
00111             Gone,
00112             InternalServerError,
00113             ItemNotFound,
00114             JidMalformed,
00115             NotAcceptable,
00116             NotAllowed,
00117             NotAuthorized,
00118             PaymentRequired,
00119             RecipientUnavailable,
00120             Redirect,
00121             RegistrationRequired,
00122             RemoteServerNotFound,
00123             RemoteServerTimeout,
00124             ResourceConstraint,
00125             ServiceUnavailable,
00126             SubscriptionRequired,
00127             UndefinedCondition,
00128             UnexpectedRequest
00129         };
00130 
00131         Error();
00132         Error(Type type, Condition cond, const QString& text = QString());
00133         Error(const QString& type, const QString& cond, const QString& text = QString());
00134 
00135         int code() const;
00136         void setCode(int code);
00137 
00138         QString text() const;
00139         void setText(const QString& text);
00140 
00141         Condition condition() const;
00142         void setCondition(Condition cond);
00143 
00144         void setType(Type type);
00145         Type type() const;
00146 
00148         void parse(const QDomElement &element);
00149         void toXml(QXmlStreamWriter *writer) const;
00151 
00152     private:
00153         QString getConditionStr() const;
00154         void setConditionFromStr(const QString& cond);
00155 
00156         QString getTypeStr() const;
00157         void setTypeFromStr(const QString& type);
00158 
00159         int m_code;
00160         Type m_type;
00161         Condition m_condition;
00162         QString m_text;
00163     };
00164 
00165     QXmppStanza(const QString& from = QString(), const QString& to = QString());
00166     QXmppStanza(const QXmppStanza &other);
00167     virtual ~QXmppStanza();
00168 
00169     QXmppStanza& operator=(const QXmppStanza &other);
00170 
00171     QString to() const;
00172     void setTo(const QString&);
00173 
00174     QString from() const;
00175     void setFrom(const QString&);
00176 
00177     QString id() const;
00178     void setId(const QString&);
00179 
00180     QString lang() const;
00181     void setLang(const QString&);
00182 
00183     QXmppStanza::Error error() const;
00184     void setError(const QXmppStanza::Error& error);
00185 
00186     QXmppElementList extensions() const;
00187     void setExtensions(const QXmppElementList &elements);
00188 
00189     QList<QXmppExtendedAddress> extendedAddresses() const;
00190     void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses);
00191 
00193     virtual void parse(const QDomElement &element);
00194     virtual void toXml(QXmlStreamWriter *writer) const = 0;
00195 
00196 protected:
00197     void extensionsToXml(QXmlStreamWriter *writer) const;
00198     void generateAndSetNextId();
00200 
00201 private:
00202     QSharedDataPointer<QXmppStanzaPrivate> d;
00203     static uint s_uniqeIdNo;
00204 };
00205 
00206 #endif // QXMPPSTANZA_H
 All Classes Functions Enumerations Enumerator Properties