gloox 1.0
|
00001 /* 00002 Copyright (c) 2006-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 #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( const 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 const std::string& OOB::filterString() const 00054 { 00055 static const std::string filter = 00056 "/presence/x[@xmlns='" + XMLNS_X_OOB + "']" 00057 "|/message/x[@xmlns='" + XMLNS_X_OOB + "']" 00058 "|/iq/query[@xmlns='" + XMLNS_IQ_OOB + "']"; 00059 return filter; 00060 } 00061 00062 Tag* OOB::tag() const 00063 { 00064 if( !m_valid ) 00065 return 0; 00066 00067 Tag* t = 0; 00068 00069 if( m_iqext ) 00070 t = new Tag( "query", XMLNS, XMLNS_IQ_OOB ); 00071 else 00072 t = new Tag( "x", XMLNS, XMLNS_X_OOB ); 00073 00074 new Tag( t, "url", m_url ); 00075 if( !m_desc.empty() ) 00076 new Tag( t, "desc", m_desc ); 00077 00078 return t; 00079 } 00080 00081 }