gloox  1.0.28
carbons.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 "carbons.h"
15 
16 #include "forward.h"
17 #include "util.h"
18 
19 namespace gloox
20 {
21  /* chat state type values */
22  static const char* typeValues [] = {
23  "received",
24  "sent",
25  "enable",
26  "disable",
27  "private"
28  };
29 
31  : StanzaExtension( ExtCarbons ), m_forward( 0 ), m_type( type )
32  {
33  }
34 
35  Carbons::Carbons( const Tag* tag )
36  : StanzaExtension( ExtCarbons ), m_forward( 0 ), m_type( Invalid )
37  {
38  if( !tag )
39  return;
40 
41  const std::string& name = tag->name();
42  m_type = static_cast<Type>( util::lookup( name, typeValues ) );
43 
44  switch( m_type )
45  {
46  case Sent:
47  case Received:
48  {
49  Tag* f = tag->findChild( "forwarded", XMLNS, XMLNS_STANZA_FORWARDING );
50  if( f )
51  m_forward = new Forward( f );
52  break;
53  }
54  default:
55  break;
56  }
57  }
58 
60  {
61  delete m_forward;
62  }
63 
64  const std::string& Carbons::filterString() const
65  {
66  static const std::string filter = "/message/*[@xmlns='" + XMLNS_MESSAGE_CARBONS + "']";
67  return filter;
68  }
69 
71  {
72  if( !m_forward || m_type == Invalid )
73  return 0;
74 
75  return m_forward->embeddedStanza();
76  }
77 
79  {
80  if( !m_forward || m_type == Invalid )
81  return 0;
82 
83  return m_forward->embeddedTag();
84  }
85 
86  Tag* Carbons::tag() const
87  {
88  if( m_type == Invalid )
89  return 0;
90 
91  Tag* t = new Tag( util::lookup( m_type, typeValues ), XMLNS, XMLNS_MESSAGE_CARBONS );
92  if( m_forward && ( m_type == Received || m_type == Sent ) )
93  t->addChild( m_forward->tag() );
94 
95  return t;
96  }
97 
99  {
100  return 0; // TODO
101  }
102 
103 }
virtual Stanza * embeddedStanza() const
Definition: carbons.cpp:70
Carbons(Type type)
Definition: carbons.cpp:30
virtual StanzaExtension * clone() const
Definition: carbons.cpp:98
virtual Tag * embeddedTag() const
Definition: carbons.cpp:78
virtual ~Carbons()
Definition: carbons.cpp:59
virtual const std::string & filterString() const
Definition: carbons.cpp:64
virtual Tag * tag() const
Definition: carbons.cpp:86
This is an implementation of Stanza Forwarding (XEP-0297) as a StanzaExtension.
Definition: forward.h:41
virtual Tag * embeddedTag() const
Definition: forward.h:78
virtual Stanza * embeddedStanza() const
Definition: forward.h:75
virtual Tag * tag() const
Definition: forward.cpp:62
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
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
const std::string & name() const
Definition: tag.h:394
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string XMLNS_MESSAGE_CARBONS
Definition: gloox.cpp:111
const std::string XMLNS_STANZA_FORWARDING
Definition: gloox.cpp:110
const std::string XMLNS
Definition: gloox.cpp:122