gloox  0.9.9.12
stanza.h
1 /*
2  Copyright (c) 2005-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef STANZA_H__
15 #define STANZA_H__
16 
17 #include "gloox.h"
18 #include "tag.h"
19 #include "jid.h"
20 
21 namespace gloox
22 {
23 
25 
29  typedef std::list<StanzaExtension*> StanzaExtensionList;
30 
39  class GLOOX_API Stanza : public Tag
40  {
41  public:
50  Stanza( const Tag *tag );
51 
60  Stanza( const std::string& name, const std::string& cdata = "",
61  const std::string& xmllang = "default", bool incoming = false );
62 
66  virtual ~Stanza();
67 
72  virtual StanzaSubType subtype() const { return m_subtype; }
73 
78  virtual const JID& from() const { return m_from; }
79 
84  virtual const JID& to() const { return m_to; }
85 
90  virtual const std::string& id() const { return m_id; }
91 
96  virtual const std::string& xmlns() const { return m_xmlns; }
97 
102  virtual Presence presence() const { return m_presence; }
103 
111  virtual int priority() const { return m_priority; }
112 
122  virtual const std::string status( const std::string& lang = "default" ) const
123  { return findLang( m_status, lang ); }
124 
134  virtual const std::string body( const std::string& lang = "default" ) const
135  { return findLang( m_body, lang ); }
136 
146  virtual const std::string subject( const std::string& lang = "default" ) const
147  { return findLang( m_subject, lang ); }
148 
158  virtual const std::string errorText( const std::string& lang = "default" ) const
159  { return findLang( m_errorText, lang ); }
160 
165  virtual StanzaError error() const { return m_stanzaError; }
166 
172  Tag* errorAppCondition() { return m_stanzaErrorAppCondition; }
173 
178  virtual const std::string& thread() const { return m_thread; }
179 
185  void setThread( const std::string& thread ) { m_thread = thread; }
186 
191  const std::string& xmlLang() const { return m_xmllang; }
192 
200  void finalize() { init(); }
201 
209  void addExtension( StanzaExtension *se );
210 
215  const StanzaExtensionList& extensions() const { return m_extensionList; }
216 
228  static Stanza* createIqStanza( const JID& to, const std::string& id,
229  StanzaSubType subtype = StanzaIqGet,
230  const std::string& xmlns = "", Tag* tag = 0 );
231 
242  static Stanza* createPresenceStanza( const JID& to, const std::string& msg = "",
243  Presence status = PresenceAvailable,
244  const std::string& xmllang = "" );
245 
256  static Stanza* createMessageStanza( const JID& to, const std::string& body,
258  const std::string& subject = "", const std::string& thread = "",
259  const std::string& xmllang = "" );
260 
269  static Stanza* createSubscriptionStanza( const JID& to, const std::string& msg = "",
271  const std::string& xmllang = "" );
272 
273  protected:
274  void init();
275 
276  StanzaExtensionList m_extensionList;
277  StanzaSubType m_subtype;
278  Presence m_presence;
279  StanzaError m_stanzaError;
280  StanzaErrorType m_stanzaErrorType;
281  Tag *m_stanzaErrorAppCondition;
282  StringMap m_errorText;
283  StringMap m_body;
284  StringMap m_subject;
285  StringMap m_status;
286  JID m_from;
287  JID m_to;
288  std::string m_xmlns;
289  std::string m_id;
290  std::string m_thread;
291  std::string m_xmllang;
292  int m_priority;
293 
294  static const std::string findLang( const StringMap& map, const std::string& lang );
295  static void setLang( StringMap& map, const Tag *tag );
296  };
297 
298 }
299 
300 #endif // STANZA_H__