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