gloox  0.9.9.12
xdelayeddelivery.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 "xdelayeddelivery.h"
15 
16 #include "tag.h"
17 
18 namespace gloox
19 {
20 
21  XDelayedDelivery::XDelayedDelivery( const JID& from, const std::string stamp, const std::string& reason )
22  : StanzaExtension( ExtXDelay ), m_from( from ), m_stamp( stamp ), m_reason( reason ), m_valid( false )
23  {
24  if( !m_stamp.empty() )
25  m_valid = true;
26  }
27 
29  : StanzaExtension( ExtXDelay ), m_valid( false )
30  {
31  if( !tag || tag->name() != "x" || !tag->hasAttribute( "xmlns", XMLNS_X_DELAY )
32  || !tag->hasAttribute( "stamp" ) )
33  return;
34 
35  m_reason = tag->cdata();
36  m_stamp = tag->findAttribute( "stamp" );
37  m_from.setJID( tag->findAttribute( "from" ) );
38  m_valid = true;
39  }
40 
42  {
43  }
44 
46  {
47  if( !m_valid )
48  return 0;
49 
50  Tag *t = new Tag( "x" );
51  t->addAttribute( "xmlns", XMLNS_X_DELAY );
52  if( m_from )
53  t->addAttribute( "from", m_from.full() );
54  if( !m_stamp.empty() )
55  t->addAttribute( "stamp", m_stamp );
56  if( !m_reason.empty() )
57  t->setCData( m_reason );
58  return t;
59  }
60 
61 }