oob.cpp

00001 /*
00002   Copyright (c) 2006-2008 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 #include "oob.h"
00015 #include "tag.h"
00016 
00017 namespace gloox
00018 {
00019 
00020   OOB::OOB( const std::string& url, const std::string& description, bool iqext )
00021     : StanzaExtension( ExtOOB ), m_url( url ), m_desc( description ), m_iqext( iqext ),
00022       m_valid( true )
00023   {
00024     if( m_url.empty() )
00025       m_valid = false;
00026   }
00027 
00028   OOB::OOB( Tag *tag )
00029     : StanzaExtension( ExtOOB ), m_iqext( false ), m_valid( false )
00030   {
00031     if( tag && ( ( tag->name() == "x" && tag->hasAttribute( "xmlns", XMLNS_X_OOB ) ) ||
00032         ( tag && tag->name() == "query" && tag->hasAttribute( "xmlns", XMLNS_IQ_OOB ) ) ) )
00033     {
00034       if( tag->name() == "query" )
00035         m_iqext = true;
00036     }
00037     else
00038       return;
00039 
00040     if( tag->hasChild( "url" ) )
00041     {
00042       m_valid = true;
00043       m_url = tag->findChild( "url" )->cdata();
00044     }
00045     if( tag->hasChild( "desc" ) )
00046       m_desc = tag->findChild( "desc" )->cdata();
00047   }
00048 
00049   OOB::~OOB()
00050   {
00051   }
00052 
00053   Tag* OOB::tag() const
00054   {
00055     if( !m_valid )
00056       return 0;
00057 
00058     Tag *t = 0;
00059 
00060     if( m_iqext )
00061     {
00062       t = new Tag( "query" );
00063       t->addAttribute( "xmlns", XMLNS_IQ_OOB );
00064     }
00065     else
00066     {
00067       t = new Tag( "x" );
00068       t->addAttribute( "xmlns", XMLNS_X_OOB );
00069     }
00070 
00071     new Tag( t, "url", m_url );
00072     if( !m_desc.empty() )
00073       new Tag( t, "desc", m_desc );
00074 
00075     return t;
00076   }
00077 
00078 }

Generated on Fri Oct 10 15:26:11 2008 for gloox by  doxygen 1.5.6