iq.cpp
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "iq.h"
#include "util.h"
namespace gloox
{
static const char * iqTypeStringValues[] =
{
"get", "set", "result", "error"
};
static inline const char* typeString( IQ::IqType type )
{
return iqTypeStringValues[type];
}
IQ::IQ( Tag* tag )
: Stanza( tag ), m_subtype( Invalid )
{
if( !tag || tag->name() != "iq" )
return;
m_subtype = static_cast<IQ::IqType>( util::lookup( tag->findAttribute( TYPE ), iqTypeStringValues ) );
}
IQ::IQ( IqType type, const JID& to, const std::string& id )
: Stanza( to ), m_subtype( type )
{
m_id = id;
}
IQ::~IQ()
{
}
Tag* IQ::tag() const
{
if( m_subtype == Invalid )
return 0;
Tag* t = new Tag( "iq" );
if( m_to )
t->addAttribute( "to", m_to.full() );
if( m_from )
t->addAttribute( "from", m_from.full() );
if( !m_id.empty() )
t->addAttribute( "id", m_id );
t->addAttribute( TYPE, typeString( m_subtype ) );
StanzaExtensionList::const_iterator it = m_extensionList.begin();
for( ; it != m_extensionList.end(); ++it )
t->addChild( (*it)->tag() );
return t;
}
}
gloox::IQ::~IQ
virtual ~IQ()
Definition iq.cpp:44
gloox::IQ::IQ
IQ(IqType type, const JID &to, const std::string &id=EmptyString)
Definition iq.cpp:38
gloox::IQ::IqType
IqType
Definition iq.h:44
gloox::IQ::Invalid
@ Invalid
Definition iq.h:51
gloox::IQ::tag
virtual Tag * tag() const
Definition iq.cpp:48
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::Stanza
This is the base class for XMPP stanza abstractions.
Definition stanza.h:34
gloox::Stanza::id
const std::string & id() const
Definition stanza.h:63
gloox::Stanza::Stanza
Stanza(Tag *tag)
Definition stanza.cpp:31
gloox::Stanza::to
const JID & to() const
Definition stanza.h:57
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
gloox::Tag::addChild
void addChild(Tag *child)
Definition tag.cpp:424
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::TYPE
const std::string TYPE
Definition gloox.cpp:123