gloox  1.0.28
stanza.h
1 /*
2  Copyright (c) 2005-2023 by Jakob Schröter <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 #include "stanzaextension.h"
21 
22 namespace gloox
23 {
24 
25  class Error;
26 
33  class GLOOX_API Stanza
34  {
35  public:
39  virtual ~Stanza();
40 
45  void setFrom( const JID& from ) { m_from = from; }
46 
51  const JID& from() const { return m_from; }
52 
57  const JID& to() const { return m_to; }
58 
63  const std::string& id() const { return m_id; }
64 
69  const Error* error() const;
70 
76  const std::string& xmlLang() const { return m_xmllang; }
77 
85  void addExtension( const StanzaExtension* se );
86 
92  const StanzaExtension* findExtension( int type ) const;
93 
103  template< class T >
104  inline const T* findExtension( int type ) const
105  {
106  return static_cast<const T*>( findExtension( type ) );
107  }
108 
113  const StanzaExtensionList& extensions() const { return m_extensionList; }
114 
118  void removeExtensions();
119 
126  void setEmbeddedStanza() { m_hasEmbeddedStanza = true; }
127 
135  bool hasEmbeddedStanza() const { return m_hasEmbeddedStanza; }
136 
145  Stanza* embeddedStanza() const;
146 
156  Tag* embeddedTag() const;
157 
164  virtual Tag* tag() const = 0;
165 
166  protected:
172  Stanza( Tag* tag );
173 
179  Stanza( const JID& to );
180 
181  StanzaExtensionList m_extensionList;
182  std::string m_id;
183  std::string m_xmllang;
184  JID m_from;
185  JID m_to;
186 
187  static const std::string& findLang( const StringMap* map,
188  const std::string& defaultData,
189  const std::string& lang );
190 
191  static void setLang( StringMap** map,
192  std::string& defaultLang,
193  const Tag* tag );
194 
195  static void setLang( StringMap** map,
196  std::string& defaultLang,
197  const std::string& data,
198  const std::string& xmllang );
199 
200  static void getLangs( const StringMap* map,
201  const std::string& defaultData,
202  const std::string& name, Tag* tag );
203 
204  private:
205  Stanza( const Stanza& );
206 
207  bool m_hasEmbeddedStanza;
208 
209  };
210 
211 }
212 
213 #endif // STANZA_H__
A stanza error abstraction implemented as a StanzaExtension.
Definition: error.h:35
An abstraction of a JID.
Definition: jid.h:31
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is the base class for XMPP stanza abstractions.
Definition: stanza.h:34
void setFrom(const JID &from)
Definition: stanza.h:45
virtual Tag * tag() const =0
const T * findExtension(int type) const
Definition: stanza.h:104
const JID & to() const
Definition: stanza.h:57
const std::string & xmlLang() const
Definition: stanza.h:76
bool hasEmbeddedStanza() const
Definition: stanza.h:135
const StanzaExtensionList & extensions() const
Definition: stanza.h:113
const std::string & id() const
Definition: stanza.h:63
const JID & from() const
Definition: stanza.h:51
void setEmbeddedStanza()
Definition: stanza.h:126
This is an abstraction of an XML element.
Definition: tag.h:47
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< const StanzaExtension * > StanzaExtensionList
Definition: gloox.h:1268
std::map< std::string, std::string > StringMap
Definition: gloox.h:1261