gloox  1.0.22
jinglecontent.cpp
1 /*
2  Copyright (c) 2008-2017 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 }
gloox::Jingle::Content::Senders
Senders
Definition: jinglecontent.h:57
gloox::Jingle::Plugin::plugins
const PluginList & plugins() const
Definition: jingleplugin.h:120
gloox::Jingle::Content::InvalidCreator
@ InvalidCreator
Definition: jinglecontent.h:51
gloox::Jingle::Content::Content
Content(const std::string &name, const PluginList &plugins, Creator creator=CInitiator, Senders senders=SBoth, const std::string &disposition="session")
Definition: jinglecontent.cpp:46
gloox::Jingle::Plugin
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:67
gloox::Jingle::PluginList
std::list< const Plugin * > PluginList
Definition: jingleplugin.h:52
gloox::Tag::findAttribute
const std::string & findAttribute(const std::string &name) const
Definition: tag.cpp:589
gloox::Jingle::Content::filterString
virtual const std::string & filterString() const
Definition: jinglecontent.cpp:73
gloox::Tag::addChild
void addChild(Tag *child)
Definition: tag.cpp:424
gloox::Jingle::Content::tag
virtual Tag * tag() const
Definition: jinglecontent.cpp:79
gloox::Jingle::PluginFactory::addPlugins
void addPlugins(Plugin &plugin, const Tag *tag)
Definition: jinglepluginfactory.cpp:42
gloox::Jingle::Content::clone
virtual Plugin * clone() const
Definition: jinglecontent.cpp:97
gloox
The namespace for the gloox library.
Definition: adhoc.cpp:27
gloox::Jingle::Content::~Content
virtual ~Content()
Definition: jinglecontent.cpp:69
gloox::Tag
This is an abstraction of an XML element.
Definition: tag.h:46
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
gloox::Jingle::Content::Creator
Creator
Definition: jinglecontent.h:47
gloox::Tag::name
const std::string & name() const
Definition: tag.h:394
gloox::Jingle::PluginFactory
A factory for which creates Plugin instances based on Tags. This is part of Jingle (XEP-0166).
Definition: jinglepluginfactory.h:36
gloox::Jingle::PluginContent
@ PluginContent
Definition: jingleplugin.h:40