gloox  1.0.16
jinglesessionmanager.cpp
1 /*
2  Copyright (c) 2013-2015 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 "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, iq.from(), j, m_handler );
91  m_sessions.push_back( s );
92  m_handler->handleIncomingSession( s );
93  s->handleIq( iq );
94  }
95  else
96  {
97  (*it)->handleIq( iq );
98  }
99  return true;
100  }
101 
102  }
103 
104 }
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:64
void addFeature(const std::string &feature)
Definition: disco.h:422
std::list< std::string > StringList
Definition: gloox.h:1244
void clearList(std::list< T * > &L)
Definition: util.h:152
An abstraction of an IQ stanza.
Definition: iq.h:33
void registerIqHandler(IqHandler *ih, int exttype)
const std::string & sid() const
void discardSession(Session *session)
void registerStanzaExtension(StanzaExtension *ext)
void addPlugins(Plugin &plugin, const Tag *tag)
virtual void handleIncomingSession(Session *session)=0
SessionManager(ClientBase *parent, SessionHandler *sh)
This is an implementation of a Jingle Session (XEP-0166).
Definition: jinglesession.h:80
The namespace for the gloox library.
Definition: adhoc.cpp:27
virtual Disco * disco() const
Definition: clientbase.h:233
Session * createSession(const JID &callee, SessionHandler *handler)
void registerPlugin(Plugin *plugin)
An abstraction of a JID.
Definition: jid.h:30
A Jingle session handler.
virtual const StringList features() const
Definition: jingleplugin.h:124
This is an abstraction of Jingle's (XEP-0166) element as a StanzaExtension.
virtual bool handleIq(const IQ &iq)
virtual bool handleIq(const IQ &iq)
const std::string XMLNS_JINGLE
Definition: gloox.cpp:101
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:76
const StanzaExtension * findExtension(int type) const
Definition: stanza.cpp:57
const JID & from() const
Definition: stanza.h:51