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