gloox  1.0.28
jinglecontent.cpp
1 /*
2  Copyright (c) 2008-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 "jinglecontent.h"
15 #include "jinglepluginfactory.h"
16 #include "util.h"
17 
18 namespace gloox
19 {
20 
21  namespace Jingle
22  {
23 
24  static const char* creatorValues [] = {
25  "initiator",
26  "responder"
27  };
28 
29  static inline Content::Creator creatorType( const std::string& type )
30  {
31  return static_cast<Content::Creator>( util::lookup( type, creatorValues ) );
32  }
33 
34  static const char* sendersValues [] = {
35  "initiator",
36  "responder",
37  "both",
38  "none"
39  };
40 
41  static inline Content::Senders sendersType( const std::string& type )
42  {
43  return static_cast<Content::Senders>( util::lookup( type, sendersValues ) );
44  }
45 
46  Content::Content( const std::string& name, const PluginList& plugins, Creator creator,
47  Senders senders, const std::string& disposition )
48  : Plugin( PluginContent ), m_creator( creator ), m_disposition( disposition ),
49  m_name( name ), m_senders( senders )
50  {
51  m_plugins = plugins;
52  }
53 
54  Content::Content( const Tag* tag, PluginFactory* factory )
56  {
57  if( !tag || tag->name() != "content" )
58  return;
59 
60  m_name = tag->findAttribute( "name" );
61  m_creator = static_cast<Creator>( util::lookup( tag->findAttribute( "creator" ), creatorValues ) );
62  m_senders = static_cast<Senders>( util::lookup( tag->findAttribute( "senders" ), sendersValues ) );
63  m_disposition = tag->findAttribute( "disposition" );
64 
65  if( factory )
66  factory->addPlugins( *this, tag );
67  }
68 
70  {
71  }
72 
73  const std::string& Content::filterString() const
74  {
75  static const std::string filter = "jingle/content";
76  return filter;
77  }
78 
79  Tag* Content::tag() const
80  {
81  if( m_creator == InvalidCreator || m_name.empty() )
82  return 0;
83 
84  Tag* t = new Tag( "content" );
85  t->addAttribute( "creator", util::lookup( m_creator, creatorValues ) );
86  t->addAttribute( "disposition", m_disposition );
87  t->addAttribute( "name", m_name );
88  t->addAttribute( "senders", util::lookup( m_senders, sendersValues ) );
89 
90  PluginList::const_iterator it = m_plugins.begin();
91  for( ; it != m_plugins.end(); ++it )
92  t->addChild( (*it)->tag() );
93 
94  return t;
95  }
96 
98  {
99  return 0;
100  }
101 
102  }
103 
104 }
virtual Plugin * clone() const
virtual const std::string & filterString() const
Content(const std::string &name, const PluginList &plugins, Creator creator=CInitiator, Senders senders=SBoth, const std::string &disposition="session")
virtual Tag * tag() const
A factory for which creates Plugin instances based on Tags. This is part of Jingle (XEP-0166).
void addPlugins(Plugin &plugin, const Tag *tag)
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:68
const PluginList & plugins() const
Definition: jingleplugin.h:120
This is an abstraction of an XML element.
Definition: tag.h:47
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
void addChild(Tag *child)
Definition: tag.cpp:424
const std::string & findAttribute(const std::string &name) const
Definition: tag.cpp:589
const std::string & name() const
Definition: tag.h:394
std::list< const Plugin * > PluginList
Definition: jingleplugin.h:52
The namespace for the gloox library.
Definition: adhoc.cpp:28