00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "bob.h"
00016 #include "base64.h"
00017 #include "tag.h"
00018
00019 #include <cstdlib>
00020
00021 namespace gloox
00022 {
00023
00024 BOB::BOB( const Tag* tag )
00025 : StanzaExtension( ExtBOB )
00026 {
00027 if( !tag || tag->name() != "data" || tag->xmlns() != XMLNS_BOB )
00028 return;
00029
00030 m_cid = tag->findAttribute( "cid" );
00031 m_maxage = strtol( tag->findAttribute( "max-age" ).c_str(), 0, 10 );
00032 m_type = tag->findAttribute( "type" );
00033 m_data = tag->cdata();
00034 }
00035
00036 BOB::BOB( const std::string& cid, const std::string& type,
00037 const std::string& data, int maxage )
00038 : StanzaExtension( ExtBOB ), m_cid( cid ), m_type( type ),
00039 m_data( Base64::encode64( data ) ), m_maxage( maxage )
00040 {
00041 }
00042
00043 const std::string BOB::data() const
00044 {
00045 return Base64::decode64( m_data );
00046 }
00047
00048 const std::string& BOB::filterString() const
00049 {
00050 static const std::string filter = "/iq/data[@xmlns='" + XMLNS_BOB + "']"
00051 "|/presence/data[@xmlns='" + XMLNS_BOB + "']"
00052 "|/message/data[@xmlns='" + XMLNS_BOB + "']";
00053 return filter;
00054 }
00055
00056 Tag* BOB::tag() const
00057 {
00058 if( m_cid.empty() || m_type.empty() )
00059 return 0;
00060
00061 Tag* t = new Tag( "data" );
00062 t->setXmlns( XMLNS_BOB );
00063 t->addAttribute( "cid", m_cid );
00064 t->addAttribute( "type", m_type );
00065 t->addAttribute( "max-age", m_maxage );
00066 t->setCData( m_data );
00067
00068 return t;
00069 }
00070
00071 }