gloox  1.0.16
delayeddelivery.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 "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 )
23  {
24  if( !m_stamp.empty() )
25  m_valid = true;
26  }
27 
28 
31  {
32  if( !tag || !tag->hasAttribute( "stamp" ) )
33  return;
34 
35  if( !( tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_DELAY ) ) )
36  if( !( tag->name() == "delay" && tag->hasAttribute( XMLNS, XMLNS_DELAY ) ) )
37  return;
38 
39  m_reason = tag->cdata();
40  m_stamp = tag->findAttribute( "stamp" );
41  m_from = tag->findAttribute( "from" );
42  m_valid = true;
43  }
44 
46  {
47  }
48 
49  const std::string& DelayedDelivery::filterString() const
50  {
51  static const std::string filter =
52  "/presence/delay[@xmlns='" + XMLNS_DELAY + "']"
53  "|/message/delay[@xmlns='" + XMLNS_DELAY + "']"
54  "|/presence/x[@xmlns='" + XMLNS_X_DELAY + "']"
55  "|/message/x[@xmlns='" + XMLNS_X_DELAY + "']";
56  return filter;
57  }
58 
60  {
61  if( !m_valid )
62  return 0;
63 
64  Tag* t = new Tag( "delay" );
66  if( m_from )
67  t->addAttribute( "from", m_from.full() );
68  if( !m_stamp.empty() )
69  t->addAttribute( "stamp", m_stamp );
70  if( !m_reason.empty() )
71  t->setCData( m_reason );
72  return t;
73  }
74 
75 }
const std::string XMLNS
Definition: gloox.cpp:121
DelayedDelivery(const JID &from, const std::string stamp, const std::string &reason="")
virtual const std::string & filterString() const
bool setCData(const std::string &cdata)
Definition: tag.cpp:446
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...
const std::string & findAttribute(const std::string &name) const
Definition: tag.cpp:588
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
Definition: tag.cpp:601
virtual Tag * tag() const
const std::string cdata() const
Definition: tag.cpp:496
An abstraction of a JID.
Definition: jid.h:30
const std::string XMLNS_X_DELAY
Definition: gloox.cpp:53
bool addAttribute(Attribute *attr)
Definition: tag.cpp:353
const std::string & name() const
Definition: tag.h:394
const std::string & full() const
Definition: jid.h:61
This is an abstraction of an XML element.
Definition: tag.h:46
const std::string XMLNS_DELAY
Definition: gloox.cpp:37