gloox  1.0.10
jinglecontent.cpp
1 /*
2  Copyright (c) 2008-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 "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 (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 (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( !factory || !tag || tag->name() != "content" )
58  return;
59 
60  m_name = tag->findAttribute( "name" );
61  m_creator = (Creator)util::lookup( tag->findAttribute( "creator" ), creatorValues );
62  m_senders = (Senders)util::lookup( tag->findAttribute( "senders" ), sendersValues );
63  m_disposition = tag->findAttribute( "disposition" );
64 
65  factory->addPlugins( *this, tag );
66  }
67 
69  {
70  }
71 
72  const std::string& Content::filterString() const
73  {
74  static const std::string filter = "jingle/content";
75  return filter;
76  }
77 
78  Tag* Content::tag() const
79  {
80  if( m_creator == InvalidCreator || m_name.empty() )
81  return 0;
82 
83  Tag* t = new Tag( "content" );
84  t->addAttribute( "creator", util::lookup( m_creator, creatorValues ) );
85  t->addAttribute( "disposition", m_disposition );
86  t->addAttribute( "name", m_name );
87  t->addAttribute( "senders", util::lookup( m_senders, sendersValues ) );
88 
89  PluginList::const_iterator it = m_plugins.begin();
90  for( ; it != m_plugins.end(); ++it )
91  t->addChild( (*it)->tag() );
92 
93  return t;
94  }
95 
97  {
98  return 0;
99  }
100 
101  }
102 
103 }