gloox  1.0.28
shim.cpp
1 /*
2  Copyright (c) 2007-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 #include "shim.h"
14 #include "tag.h"
15 
16 namespace gloox
17 {
18 
19  SHIM::SHIM( const HeaderList& hl )
20  : StanzaExtension( ExtSHIM ), m_headers( hl )
21  {
22  }
23 
24  SHIM::SHIM( const Tag* tag )
26  {
27  if( !tag || tag->name() != "headers" || tag->xmlns() != XMLNS_SHIM )
28  return;
29 
30  const TagList& l = tag->children();
31  TagList::const_iterator it = l.begin();
32  for( ; it != l.end(); ++it )
33  {
34  if( (*it)->name() != "header" || !(*it)->hasAttribute( "name" ) )
35  return;
36 
37  m_headers.insert( std::make_pair( (*it)->findAttribute( "name" ), (*it)->cdata() ) );
38  }
39  }
40 
42  {
43  }
44 
45  const std::string& SHIM::filterString() const
46  {
47  static const std::string filter = "/presence/headers[@xmlns='" + XMLNS_SHIM + "']"
48  "|/message/headers[@xmlns='" + XMLNS_SHIM + "']"
49  "|/iq/*/headers[@xmlns='" + XMLNS_SHIM + "']";
50  return filter;
51  }
52 
53  Tag* SHIM::tag() const
54  {
55  if( !m_headers.size() )
56  return 0;
57 
58  Tag* t = new Tag( "headers" );
59  t->setXmlns( XMLNS_SHIM );
60 
61  HeaderList::const_iterator it = m_headers.begin();
62  for( ; it != m_headers.end(); ++it )
63  {
64  Tag* h = new Tag( t, "header" );
65  h->addAttribute( "name", (*it).first );
66  h->setCData( (*it).second );
67  }
68  return t;
69  }
70 
71 }
std::map< std::string, std::string > HeaderList
Definition: shim.h:41
virtual const std::string & filterString() const
Definition: shim.cpp:45
virtual ~SHIM()
Definition: shim.cpp:41
SHIM(const HeaderList &hl)
Definition: shim.cpp:19
virtual Tag * tag() const
Definition: shim.cpp:53
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
bool setCData(const std::string &cdata)
Definition: tag.cpp:447
const std::string xmlns() const
Definition: tag.cpp:543
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
const std::string & name() const
Definition: tag.h:394
const TagList & children() const
Definition: tag.cpp:510
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
Definition: tag.cpp:522
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< Tag * > TagList
Definition: tag.h:26
const std::string XMLNS_SHIM
Definition: gloox.cpp:107