gloox  1.0.20
jinglesessionmanager.cpp
1 /*
2  Copyright (c) 2013-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 "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:67
void addFeature(const std::string &feature)
Definition: disco.h:422
const StanzaExtension * findExtension(int type) const
Definition: stanza.cpp:57
virtual const StringList features() const
Definition: jingleplugin.h:127
std::list< std::string > StringList
Definition: gloox.h:1251
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)
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)
const std::string & sid() const
This is an implementation of a Jingle Session (XEP-0166).
Definition: jinglesession.h:80
The namespace for the gloox library.
Definition: adhoc.cpp:27
Session * createSession(const JID &callee, SessionHandler *handler)
void registerPlugin(Plugin *plugin)
An abstraction of a JID.
Definition: jid.h:30
A Jingle session handler.
This is an abstraction of Jingle&#39;s (XEP-0166) <jingle> element as a StanzaExtension.
const JID & from() const
Definition: stanza.h:51
virtual bool handleIq(const IQ &iq)
virtual Disco * disco() const
Definition: clientbase.h:233
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