gloox  0.9.9.12
oob.cpp
1 /*
2  Copyright (c) 2006-2008 by Jakob Schroeter <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( 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  Tag* OOB::tag() const
54  {
55  if( !m_valid )
56  return 0;
57 
58  Tag *t = 0;
59 
60  if( m_iqext )
61  {
62  t = new Tag( "query" );
63  t->addAttribute( "xmlns", XMLNS_IQ_OOB );
64  }
65  else
66  {
67  t = new Tag( "x" );
68  t->addAttribute( "xmlns", XMLNS_X_OOB );
69  }
70 
71  new Tag( t, "url", m_url );
72  if( !m_desc.empty() )
73  new Tag( t, "desc", m_desc );
74 
75  return t;
76  }
77 
78 }