00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "iq.h"
00014 #include "util.h"
00015
00016 namespace gloox
00017 {
00018
00019 static const char * iqTypeStringValues[] =
00020 {
00021 "get", "set", "result", "error"
00022 };
00023
00024 static inline const char* typeString( IQ::IqType type )
00025 {
00026 return iqTypeStringValues[type];
00027 }
00028
00029 IQ::IQ( Tag* tag )
00030 : Stanza( tag ), m_query( 0 ), m_subtype( Invalid )
00031 {
00032 if( !tag || tag->name() != "iq" )
00033 return;
00034
00035 m_subtype = (IQ::IqType)util::lookup( tag->findAttribute( TYPE ), iqTypeStringValues );
00036
00037 m_query = tag->findChildWithAttrib( XMLNS );
00038
00039 if( m_query )
00040 m_query = m_query->clone();
00041
00042
00043 if( m_query )
00044 m_xmlns = m_query->findAttribute( XMLNS );
00045 }
00046
00047 IQ::IQ( IqType type, const JID& to, const std::string& id )
00048 : Stanza( to ), m_query( 0 ), m_subtype( type )
00049 {
00050 m_id = id;
00051 }
00052
00053 IQ::IQ( IqType type, const JID& to, const std::string& id, const std::string& xmlns,
00054 const std::string& childtag )
00055 : Stanza( to ), m_query( 0 ), m_subtype( type )
00056 {
00057 m_id = id;
00058
00059 if( !xmlns.empty() )
00060 {
00061 m_xmlns = xmlns;
00062 m_query = new Tag( childtag.empty() ? "query" : childtag, XMLNS, xmlns );
00063 }
00064 }
00065
00066 IQ::~IQ()
00067 {
00068 delete m_query;
00069 }
00070
00071 Tag* IQ::tag() const
00072 {
00073 if( m_subtype == Invalid )
00074 return 0;
00075
00076 Tag* t = new Tag( "iq" );
00077 t->setXmlns( XMLNS_CLIENT );
00078 if( m_to )
00079 t->addAttribute( "to", m_to.full() );
00080 if( m_from )
00081 t->addAttribute( "from", m_from.full() );
00082 if( !m_id.empty() )
00083 t->addAttribute( "id", m_id );
00084 t->addAttribute( TYPE, typeString( m_subtype ) );
00085
00086 if( m_query )
00087 t->addChild( m_query->clone() );
00088
00089 StanzaExtensionList::const_iterator it = m_extensionList.begin();
00090 for( ; it != m_extensionList.end(); ++it )
00091 t->addChild( (*it)->tag() );
00092
00093 return t;
00094 }
00095
00096 }