stanza.h

00001 /*
00002   Copyright (c) 2005-2008 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 #ifndef STANZA_H__
00015 #define STANZA_H__
00016 
00017 #include "gloox.h"
00018 #include "tag.h"
00019 #include "jid.h"
00020 
00021 namespace gloox
00022 {
00023 
00024   class StanzaExtension;
00025 
00029   typedef std::list<StanzaExtension*> StanzaExtensionList;
00030 
00039   class GLOOX_API Stanza : public Tag
00040   {
00041     public:
00050       Stanza( const Tag *tag );
00051 
00060       Stanza( const std::string& name, const std::string& cdata = "",
00061               const std::string& xmllang = "default", bool incoming = false );
00062 
00066       virtual ~Stanza();
00067 
00072       virtual StanzaSubType subtype() const { return m_subtype; }
00073 
00078       virtual const JID& from() const { return m_from; }
00079 
00084       virtual const JID& to() const { return m_to; }
00085 
00090       virtual const std::string& id() const { return m_id; }
00091 
00096       virtual const std::string& xmlns() const { return m_xmlns; }
00097 
00102       virtual Presence presence() const { return m_presence; }
00103 
00111       virtual int priority() const { return m_priority; }
00112 
00122       virtual const std::string status( const std::string& lang = "default" ) const
00123         { return findLang( m_status, lang ); }
00124 
00134       virtual const std::string body( const std::string& lang = "default" ) const
00135         { return findLang( m_body, lang ); }
00136 
00146       virtual const std::string subject( const std::string& lang = "default" ) const
00147         { return findLang( m_subject, lang ); }
00148 
00158       virtual const std::string errorText( const std::string& lang = "default" ) const
00159         { return findLang( m_errorText, lang ); }
00160 
00165       virtual StanzaError error() const { return m_stanzaError; }
00166 
00172       Tag* errorAppCondition() { return m_stanzaErrorAppCondition; }
00173 
00178       virtual const std::string& thread() const { return m_thread; }
00179 
00185       void setThread( const std::string& thread ) { m_thread = thread; }
00186 
00191       const std::string& xmlLang() const { return m_xmllang; }
00192 
00200       void finalize() { init(); }
00201 
00209       void addExtension( StanzaExtension *se );
00210 
00215       const StanzaExtensionList& extensions() const { return m_extensionList; }
00216 
00228       static Stanza* createIqStanza( const JID& to, const std::string& id,
00229                                      StanzaSubType subtype = StanzaIqGet,
00230                                      const std::string& xmlns = "", Tag* tag = 0 );
00231 
00242       static Stanza* createPresenceStanza( const JID& to, const std::string& msg = "",
00243                                            Presence status = PresenceAvailable,
00244                                            const std::string& xmllang = "" );
00245 
00256       static Stanza* createMessageStanza( const JID& to, const std::string& body,
00257                                           StanzaSubType subtype = StanzaMessageChat,
00258                                           const std::string& subject = "", const std::string& thread = "",
00259                                           const std::string& xmllang = "" );
00260 
00269       static Stanza* createSubscriptionStanza( const JID& to, const std::string& msg = "",
00270                                                StanzaSubType subtype = StanzaS10nSubscribe,
00271                                                const std::string& xmllang = "" );
00272 
00273     protected:
00274       void init();
00275 
00276       StanzaExtensionList m_extensionList;
00277       StanzaSubType m_subtype;
00278       Presence m_presence;
00279       StanzaError m_stanzaError;
00280       StanzaErrorType m_stanzaErrorType;
00281       Tag *m_stanzaErrorAppCondition;
00282       StringMap m_errorText;
00283       StringMap m_body;
00284       StringMap m_subject;
00285       StringMap m_status;
00286       JID m_from;
00287       JID m_to;
00288       std::string m_xmlns;
00289       std::string m_id;
00290       std::string m_thread;
00291       std::string m_xmllang;
00292       int m_priority;
00293 
00294       static const std::string findLang( const StringMap& map, const std::string& lang );
00295       static void setLang( StringMap& map, const Tag *tag );
00296   };
00297 
00298 }
00299 
00300 #endif // STANZA_H__

Generated on Sun Apr 27 11:08:13 2008 for gloox by  doxygen 1.5.5