gloox  1.0.16
forward.cpp
1 /*
2  Copyright (c) 2013-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 "forward.h"
15 
16 #include "delayeddelivery.h"
17 #include "message.h"
18 #include "stanza.h"
19 #include "util.h"
20 
21 namespace gloox
22 {
23 
26  m_stanza( stanza ), m_tag( 0 ), m_delay( delay )
27  {
28  }
29 
30  Forward::Forward( const Tag* tag )
32  m_stanza( 0 ), m_tag( 0 ), m_delay( 0 )
33  {
34  if( !tag || !( tag->name() == "forwarded" && tag->hasAttribute( XMLNS, XMLNS_STANZA_FORWARDING ) ) )
35  return;
36 
37  m_delay = new DelayedDelivery( tag->findChild( "delay", XMLNS, XMLNS_DELAY ) );
38 
39  Tag* m = tag->findChild( "message" );
40  if( !m )
41  return;
42 
43  m_tag = m->clone();
44  m_stanza = new Message( m );
45  }
46 
48  {
49  delete m_delay;
50  delete m_stanza;
51  delete m_tag;
52  }
53 
54  const std::string& Forward::filterString() const
55  {
56  static const std::string filter = "/message/forwarded[@xmlns='" + XMLNS_STANZA_FORWARDING + "']"
57  "|/iq/forwarded[@xmlns='" + XMLNS_STANZA_FORWARDING + "']"
58  "|/presence/forwarded[@xmlns='" + XMLNS_STANZA_FORWARDING + "']";
59  return filter;
60  }
61 
62  Tag* Forward::tag() const
63  {
64  if( !m_stanza )
65  return 0;
66 
67  Tag* f = new Tag( "forwarded" );
69  if( m_delay )
70  f->addChild( m_delay->tag() );
71  if( m_stanza )
72  f->addChild( m_stanza->tag() );
73 
74  return f;
75  }
76 
78  {
79  if( !m_tag || !m_delay )
80  return 0;
81 
82  return new Forward( new Message( m_tag ), static_cast<DelayedDelivery*>( m_delay->clone() ) );
83  }
84 
85 }
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
Definition: tag.cpp:521
const std::string XMLNS
Definition: gloox.cpp:121
This is the base class for XMPP stanza abstractions.
Definition: stanza.h:33
This is an implementation of XEP-0203 (Delayed Delivery).
const std::string & filterString() const
Definition: forward.cpp:54
void addChild(Tag *child)
Definition: tag.cpp:423
Forward(Stanza *stanza, DelayedDelivery *delay)
Definition: forward.cpp:24
An abstraction of a message stanza.
Definition: message.h:33
virtual Tag * tag() const
Definition: forward.cpp:62
virtual ~Forward()
Definition: forward.cpp:47
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
virtual Tag * tag() const
virtual Tag * tag() const =0
StanzaExtension * clone() const
Definition: forward.cpp:77
Tag * clone() const
Definition: tag.cpp:669
const std::string & name() const
Definition: tag.h:394
const std::string XMLNS_STANZA_FORWARDING
Definition: gloox.cpp:110
virtual StanzaExtension * clone() const
Tag * findChild(const std::string &name) const
Definition: tag.cpp:623
This is an abstraction of an XML element.
Definition: tag.h:46
const std::string XMLNS_DELAY
Definition: gloox.cpp:37