gloox
1.0
|
00001 /* 00002 Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net> 00003 This file is part of the gloox library. http://camaya.net/gloox 00004 00005 This software is distributed under a license. The full license 00006 agreement can be found in the file LICENSE in this distribution. 00007 This software may not be copied, modified, sold or distributed 00008 other than expressed in the named license agreement. 00009 00010 This software is distributed without any warranty. 00011 */ 00012 00013 #include "shim.h" 00014 #include "tag.h" 00015 00016 namespace gloox 00017 { 00018 00019 SHIM::SHIM( const HeaderList& hl ) 00020 : StanzaExtension( ExtSHIM ), m_headers( hl ) 00021 { 00022 } 00023 00024 SHIM::SHIM( const Tag* tag ) 00025 : StanzaExtension( ExtSHIM ) 00026 { 00027 if( !tag || tag->name() != "headers" || tag->xmlns() != XMLNS_SHIM ) 00028 return; 00029 00030 const TagList& l = tag->children(); 00031 TagList::const_iterator it = l.begin(); 00032 for( ; it != l.end(); ++it ) 00033 { 00034 if( (*it)->name() != "header" || !(*it)->hasAttribute( "name" ) ) 00035 return; 00036 00037 m_headers.insert( std::make_pair( (*it)->findAttribute( "name" ), (*it)->cdata() ) ); 00038 } 00039 } 00040 00041 SHIM::~SHIM() 00042 { 00043 } 00044 00045 const std::string& SHIM::filterString() const 00046 { 00047 static const std::string filter = "/presence/headers[@xmlns='" + XMLNS_SHIM + "']" 00048 "|/message/headers[@xmlns='" + XMLNS_SHIM + "']" 00049 "|/iq/*/headers[@xmlns='" + XMLNS_SHIM + "']"; 00050 return filter; 00051 } 00052 00053 Tag* SHIM::tag() const 00054 { 00055 if( !m_headers.size() ) 00056 return 0; 00057 00058 Tag* t = new Tag( "headers" ); 00059 t->setXmlns( XMLNS_SHIM ); 00060 00061 HeaderList::const_iterator it = m_headers.begin(); 00062 for( ; it != m_headers.end(); ++it ) 00063 { 00064 Tag* h = new Tag( t, "header" ); 00065 h->addAttribute( "name", (*it).first ); 00066 h->setCData( (*it).second ); 00067 } 00068 return t; 00069 } 00070 00071 }