gloox 1.0
softwareversion.cpp
00001 /*
00002   Copyright (c) 2008-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 "softwareversion.h"
00016 #include "tag.h"
00017 
00018 namespace gloox
00019 {
00020 
00021   SoftwareVersion::SoftwareVersion( const std::string& name,
00022                                            const std::string& version,
00023                                            const std::string& os )
00024     : StanzaExtension( ExtVersion ), m_name( name ), m_version( version ), m_os( os )
00025   {
00026   }
00027 
00028   SoftwareVersion::SoftwareVersion( const Tag* tag )
00029     : StanzaExtension( ExtVersion )
00030   {
00031     if( !tag )
00032       return;
00033 
00034     Tag* t = tag->findChild( "name" );
00035     if( t )
00036       m_name = t->cdata();
00037 
00038     t = tag->findChild( "version" );
00039     if( t )
00040       m_version = t->cdata();
00041 
00042     t = tag->findChild( "os" );
00043     if( t )
00044       m_os = t->cdata();
00045   }
00046 
00047   SoftwareVersion::~SoftwareVersion()
00048   {
00049   }
00050 
00051   const std::string& SoftwareVersion::filterString() const
00052   {
00053     static const std::string filter = "/iq/query[@xmlns='" + XMLNS_VERSION + "']";
00054     return filter;
00055   }
00056 
00057   Tag* SoftwareVersion::tag() const
00058   {
00059     Tag* t = new Tag( "query" );
00060     t->setXmlns( XMLNS_VERSION );
00061 
00062     if( !m_name.empty() )
00063       new Tag( t, "name", m_name );
00064 
00065     if( !m_version.empty() )
00066       new Tag( t, "version", m_version );
00067 
00068     if( !m_os.empty() )
00069       new Tag( t, "os", m_os );
00070 
00071     return t;
00072   }
00073 
00074 }