gloox  1.0.28
iq.cpp
1 /*
2  Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 #include "iq.h"
14 #include "util.h"
15 
16 namespace gloox
17 {
18 
19  static const char * iqTypeStringValues[] =
20  {
21  "get", "set", "result", "error"
22  };
23 
24  static inline const char* typeString( IQ::IqType type )
25  {
26  return iqTypeStringValues[type];
27  }
28 
29  IQ::IQ( Tag* tag )
30  : Stanza( tag ), m_subtype( Invalid )
31  {
32  if( !tag || tag->name() != "iq" )
33  return;
34 
35  m_subtype = static_cast<IQ::IqType>( util::lookup( tag->findAttribute( TYPE ), iqTypeStringValues ) );
36  }
37 
38  IQ::IQ( IqType type, const JID& to, const std::string& id )
39  : Stanza( to ), m_subtype( type )
40  {
41  m_id = id;
42  }
43 
45  {
46  }
47 
48  Tag* IQ::tag() const
49  {
50  if( m_subtype == Invalid )
51  return 0;
52 
53  Tag* t = new Tag( "iq" );
54  if( m_to )
55  t->addAttribute( "to", m_to.full() );
56  if( m_from )
57  t->addAttribute( "from", m_from.full() );
58  if( !m_id.empty() )
59  t->addAttribute( "id", m_id );
60  t->addAttribute( TYPE, typeString( m_subtype ) );
61 
62  StanzaExtensionList::const_iterator it = m_extensionList.begin();
63  for( ; it != m_extensionList.end(); ++it )
64  t->addChild( (*it)->tag() );
65 
66  return t;
67  }
68 
69 }
virtual ~IQ()
Definition: iq.cpp:44
IQ(IqType type, const JID &to, const std::string &id=EmptyString)
Definition: iq.cpp:38
IqType
Definition: iq.h:44
@ Invalid
Definition: iq.h:51
virtual Tag * tag() const
Definition: iq.cpp:48
An abstraction of a JID.
Definition: jid.h:31
const std::string & full() const
Definition: jid.h:61
This is the base class for XMPP stanza abstractions.
Definition: stanza.h:34
const std::string & id() const
Definition: stanza.h:63
This is an abstraction of an XML element.
Definition: tag.h:47
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
void addChild(Tag *child)
Definition: tag.cpp:424
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string TYPE
Definition: gloox.cpp:123