gloox  1.0.16
oob.cpp
1 /*
2  Copyright (c) 2006-2015 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 
14 #include "oob.h"
15 #include "tag.h"
16 
17 namespace gloox
18 {
19 
20  OOB::OOB( const std::string& url, const std::string& description, bool iqext )
21  : StanzaExtension( ExtOOB ), m_url( url ), m_desc( description ), m_iqext( iqext ),
22  m_valid( true )
23  {
24  if( m_url.empty() )
25  m_valid = false;
26  }
27 
28  OOB::OOB( const Tag* tag )
29  : StanzaExtension( ExtOOB ), m_iqext( false ), m_valid( false )
30  {
31  if( tag && ( ( tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_OOB ) ) ||
32  ( tag && tag->name() == "query" && tag->hasAttribute( XMLNS, XMLNS_IQ_OOB ) ) ) )
33  {
34  if( tag->name() == "query" )
35  m_iqext = true;
36  }
37  else
38  return;
39 
40  if( tag->hasChild( "url" ) )
41  {
42  m_valid = true;
43  m_url = tag->findChild( "url" )->cdata();
44  }
45  if( tag->hasChild( "desc" ) )
46  m_desc = tag->findChild( "desc" )->cdata();
47  }
48 
50  {
51  }
52 
53  const std::string& OOB::filterString() const
54  {
55  static const std::string filter =
56  "/presence/x[@xmlns='" + XMLNS_X_OOB + "']"
57  "|/message/x[@xmlns='" + XMLNS_X_OOB + "']"
58  "|/iq/query[@xmlns='" + XMLNS_IQ_OOB + "']";
59  return filter;
60  }
61 
62  Tag* OOB::tag() const
63  {
64  if( !m_valid )
65  return 0;
66 
67  Tag* t = 0;
68 
69  if( m_iqext )
70  t = new Tag( "query", XMLNS, XMLNS_IQ_OOB );
71  else
72  t = new Tag( "x", XMLNS, XMLNS_X_OOB );
73 
74  new Tag( t, "url", m_url );
75  if( !m_desc.empty() )
76  new Tag( t, "desc", m_desc );
77 
78  return t;
79  }
80 
81 }
virtual ~OOB()
Definition: oob.cpp:49
const std::string XMLNS
Definition: gloox.cpp:121
const std::string XMLNS_IQ_OOB
Definition: gloox.cpp:48
virtual const std::string & filterString() const
Definition: oob.cpp:53
Tag * tag() const
Definition: oob.cpp:62
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an element in a specific namespace...
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
Definition: tag.cpp:601
const std::string cdata() const
Definition: tag.cpp:496
bool hasChild(const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const
Definition: tag.cpp:614
const std::string & name() const
Definition: tag.h:394
Tag * findChild(const std::string &name) const
Definition: tag.cpp:623
OOB(const std::string &url, const std::string &description, bool iqext)
Definition: oob.cpp:20
This is an abstraction of an XML element.
Definition: tag.h:46
const std::string XMLNS_X_OOB
Definition: gloox.cpp:51