Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

bob.cpp

00001 /*
00002   Copyright (c) 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 
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 }

Generated on Tue May 4 16:35:11 2010 for gloox by  doxygen 1.4.1