iq.cpp

00001 /*
00002   Copyright (c) 2007-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 #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 }

Generated by  doxygen 1.6.2