gloox  1.0.27
forward.cpp
1 /*
2  Copyright (c) 2013-2023 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  {
73  Tag* tmp = m_stanza->tag();
74  if( tmp->name() == "message" )
75  tmp->setXmlns( XMLNS_CLIENT );
76 
77  f->addChild( tmp );
78  }
79 
80  return f;
81  }
82 
84  {
85  if( !m_tag || !m_delay )
86  return 0;
87 
88  return new Forward( new Message( m_tag ), static_cast<DelayedDelivery*>( m_delay->clone() ) );
89  }
90 
91 }
This is an implementation of XEP-0203 (Delayed Delivery).
virtual StanzaExtension * clone() const
virtual Tag * tag() const
virtual ~Forward()
Definition: forward.cpp:47
StanzaExtension * clone() const
Definition: forward.cpp:83
const std::string & filterString() const
Definition: forward.cpp:54
Forward(Stanza *stanza, DelayedDelivery *delay)
Definition: forward.cpp:24
virtual Tag * tag() const
Definition: forward.cpp:62
An abstraction of a message stanza.
Definition: message.h:34
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is the base class for XMPP stanza abstractions.
Definition: stanza.h:34
virtual Tag * tag() const =0
This is an abstraction of an XML element.
Definition: tag.h:47
Tag * findChild(const std::string &name) const
Definition: tag.cpp:624
void addChild(Tag *child)
Definition: tag.cpp:424
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
Definition: tag.cpp:602
const std::string & name() const
Definition: tag.h:394
Tag * clone() const
Definition: tag.cpp:670
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
Definition: tag.cpp:522
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string XMLNS_DELAY
Definition: gloox.cpp:37
const std::string XMLNS_STANZA_FORWARDING
Definition: gloox.cpp:110
const std::string XMLNS_CLIENT
Definition: gloox.cpp:19
const std::string XMLNS
Definition: gloox.cpp:122