gloox  1.0.1
shim.cpp
1 /*
2  Copyright (c) 2007-2012 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 #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 }