gloox  1.0.9
jinglesessionmanager.cpp
1 /*
2  Copyright (c) 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 "jinglesessionmanager.h"
15 
16 #include "clientbase.h"
17 #include "jinglesession.h"
18 #include "jinglesessionhandler.h"
19 #include "disco.h"
20 #include "util.h"
21 
22 namespace gloox
23 {
24 
25  namespace Jingle
26  {
27 
29  : m_parent( parent ), m_handler( sh )
30  {
31  if( m_parent )
32  {
33  m_parent->registerStanzaExtension( new Session::Jingle() );
34  m_parent->registerIqHandler( this, ExtJingle );
35  m_parent->disco()->addFeature( XMLNS_JINGLE );
36  }
37  }
38 
40  {
41  util::clearList( m_sessions );
42  }
43 
45  {
46  if( !plugin )
47  return;
48 
49  m_factory.registerPlugin( plugin );
50  if( m_parent )
51  {
52  StringList features = plugin->features();
53  StringList::const_iterator it = features.begin();
54  for( ; it != features.end(); ++it )
55  m_parent->disco()->addFeature( (*it) );
56  }
57  }
58 
60  {
61  if( !( handler || m_handler ) || !callee )
62  return 0;
63 
64  Session* sess = new Session( m_parent, callee, handler ? handler : m_handler );
65  m_sessions.push_back( sess );
66  return sess;
67  }
68 
70  {
71  if( !session )
72  return;
73 
74  m_sessions.remove( session );
75  delete session;
76  }
77 
78  bool SessionManager::handleIq( const IQ& iq )
79  {
81  if( !j )
82  return false;
83 
84  m_factory.addPlugins( const_cast<Session::Jingle&>( *j ), j->embeddedTag() );
85 
86  SessionList::iterator it = m_sessions.begin();
87  for( ; it != m_sessions.end() && (*it)->sid() != j->sid(); ++it ) ;
88  if( it == m_sessions.end() )
89  {
90  Session* s = new Session( m_parent, j, m_handler );
91  m_handler->handleIncomingSession( s );
92  s->handleIq( iq );
93  }
94  else
95  {
96  (*it)->handleIq( iq );
97  }
98  return true;
99  }
100 
101  }
102 
103 }