File indexing completed on 2024-06-23 04:03:37

0001 /*
0002  * Copyright (C) 2003  Justin Karneges
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * either version 2
0008    of the License, or (at your option) any later version.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0018  *
0019  */
0020 
0021 #ifndef XMPP_STANZA_H
0022 #define XMPP_STANZA_H
0023 
0024 #include "iris_export.h"
0025 #include <QPair>
0026 #include <QString>
0027 #include <QDomElement>
0028 
0029 class QDomDocument;
0030 
0031 namespace XMPP 
0032 {
0033     class Jid;
0034     class Stream;
0035 
0036     class IRIS_EXPORT Stanza
0037     {
0038     public:
0039         enum Kind { Message, Presence, IQ };
0040 
0041         Stanza();
0042         Stanza(const Stanza &from);
0043         Stanza & operator=(const Stanza &from);
0044         virtual ~Stanza();
0045 
0046         class Error
0047         {
0048         public:
0049             enum ErrorType { Cancel = 1, Continue, Modify, Auth, Wait };
0050             enum ErrorCond
0051             {
0052                 BadRequest = 1,
0053                 Conflict,
0054                 FeatureNotImplemented,
0055                 Forbidden,
0056                 Gone,
0057                 InternalServerError,
0058                 ItemNotFound,
0059                 JidMalformed,
0060                 NotAcceptable,
0061                 NotAllowed,
0062                 NotAuthorized,
0063                 PaymentRequired,
0064                 RecipientUnavailable,
0065                 Redirect,
0066                 RegistrationRequired,
0067                 RemoteServerNotFound,
0068                 RemoteServerTimeout,
0069                 ResourceConstraint,
0070                 ServiceUnavailable,
0071                 SubscriptionRequired,
0072                 UndefinedCondition,
0073                 UnexpectedRequest
0074             };
0075 
0076             Error(int type=Cancel, int condition=UndefinedCondition, const QString &text="", const QDomElement &appSpec=QDomElement());
0077 
0078             int type;
0079             int condition;
0080             QString text;
0081             QDomElement appSpec;
0082 
0083             int code() const;
0084             bool fromCode(int code);
0085 
0086             QPair<QString, QString> description() const;
0087 
0088             QDomElement toXml(QDomDocument &doc, const QString &baseNS) const;
0089             bool fromXml(const QDomElement &e, const QString &baseNS);
0090         private:
0091             class Private;
0092             int originalCode;
0093 
0094         };
0095 
0096         bool isNull() const;
0097 
0098         QDomElement element() const;
0099         QString toString() const;
0100 
0101         QDomDocument & doc() const;
0102         QString baseNS() const;
0103         QDomElement createElement(const QString &ns, const QString &tagName);
0104         QDomElement createTextElement(const QString &ns, const QString &tagName, const QString &text);
0105         void appendChild(const QDomElement &e);
0106 
0107         Kind kind() const;
0108         void setKind(Kind k);
0109 
0110         Jid to() const;
0111         Jid from() const;
0112         QString id() const;
0113         QString type() const;
0114         QString lang() const;
0115 
0116         void setTo(const Jid &j);
0117         void setFrom(const Jid &j);
0118         void setId(const QString &id);
0119         void setType(const QString &type);
0120         void setLang(const QString &lang);
0121 
0122         Error error() const;
0123         void setError(const Error &err);
0124         void clearError();
0125 
0126     private:
0127         friend class Stream;
0128         Stanza(Stream *s, Kind k, const Jid &to, const QString &type, const QString &id);
0129         Stanza(Stream *s, const QDomElement &e);
0130 
0131         class Private;
0132         Private *d;
0133     };
0134 }
0135 
0136 #endif