iq.cpp
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_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
00038 IQ::IQ( IqType type, const JID& to, const std::string& id )
00039 : Stanza( to ), m_subtype( type )
00040 {
00041 m_id = id;
00042 }
00043
00044 IQ::~IQ()
00045 {
00046 }
00047
00048 Tag* IQ::tag() const
00049 {
00050 if( m_subtype == Invalid )
00051 return 0;
00052
00053 Tag* t = new Tag( "iq" );
00054 if( m_to )
00055 t->addAttribute( "to", m_to.full() );
00056 if( m_from )
00057 t->addAttribute( "from", m_from.full() );
00058 if( !m_id.empty() )
00059 t->addAttribute( "id", m_id );
00060 t->addAttribute( TYPE, typeString( m_subtype ) );
00061
00062 StanzaExtensionList::const_iterator it = m_extensionList.begin();
00063 for( ; it != m_extensionList.end(); ++it )
00064 t->addChild( (*it)->tag() );
00065
00066 return t;
00067 }
00068
00069 }