gloox  1.0.10
forward.cpp
1 /*
2  Copyright (c) 2013 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 "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 }