gloox  1.0.16
shim.cpp
1 /*
2  Copyright (c) 2007-2015 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 }
const TagList & children() const
Definition: tag.cpp:509
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
Definition: tag.cpp:521
virtual const std::string & filterString() const
Definition: shim.cpp:45
virtual ~SHIM()
Definition: shim.cpp:41
std::list< Tag * > TagList
Definition: tag.h:26
bool setCData(const std::string &cdata)
Definition: tag.cpp:446
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string & xmlns() const
Definition: tag.cpp:542
std::map< std::string, std::string > HeaderList
Definition: shim.h:41
bool addAttribute(Attribute *attr)
Definition: tag.cpp:353
const std::string & name() const
Definition: tag.h:394
virtual Tag * tag() const
Definition: shim.cpp:53
SHIM(const HeaderList &hl)
Definition: shim.cpp:19
This is an abstraction of an XML element.
Definition: tag.h:46
const std::string XMLNS_SHIM
Definition: gloox.cpp:107