jinglesessionmanager.cpp
/*
Copyright (c) 2013-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "jinglesessionmanager.h"
#include "clientbase.h"
#include "jinglesession.h"
#include "jinglesessionhandler.h"
#include "disco.h"
#include "util.h"
namespace gloox
{
namespace Jingle
{
SessionManager::SessionManager( ClientBase* parent, SessionHandler* sh )
: m_parent( parent ), m_handler( sh )
{
if( m_parent )
{
m_parent->registerStanzaExtension( new Session::Jingle() );
m_parent->registerIqHandler( this, ExtJingle );
m_parent->disco()->addFeature( XMLNS_JINGLE );
}
}
SessionManager::~SessionManager()
{
util::clearList( m_sessions );
}
void SessionManager::registerPlugin( Plugin* plugin )
{
if( !plugin )
return;
m_factory.registerPlugin( plugin );
if( m_parent )
{
StringList features = plugin->features();
StringList::const_iterator it = features.begin();
for( ; it != features.end(); ++it )
m_parent->disco()->addFeature( (*it) );
}
}
Session* SessionManager::createSession( const JID& callee, SessionHandler* handler )
{
if( !( handler || m_handler ) || !callee )
return 0;
Session* sess = new Session( m_parent, callee, handler ? handler : m_handler );
m_sessions.push_back( sess );
return sess;
}
void SessionManager::discardSession( Session* session )
{
if( !session )
return;
m_sessions.remove( session );
delete session;
}
bool SessionManager::handleIq( const IQ& iq )
{
const Session::Jingle* j = iq.findExtension<Session::Jingle>( ExtJingle );
if( !j )
return false;
m_factory.addPlugins( const_cast<Session::Jingle&>( *j ), j->embeddedTag() );
SessionList::iterator it = m_sessions.begin();
for( ; it != m_sessions.end() && (*it)->sid() != j->sid(); ++it ) ;
if( it == m_sessions.end() )
{
Session* s = new Session( m_parent, iq.from(), j, m_handler );
m_sessions.push_back( s );
m_handler->handleIncomingSession( s );
s->handleIq( iq );
}
else
{
(*it)->handleIq( iq );
}
return true;
}
}
}
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::Jingle::Plugin
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.).
Definition jingleplugin.h:68
gloox::Jingle::Plugin::features
virtual const StringList features() const
Definition jingleplugin.h:127
gloox::Jingle::SessionHandler
A Jingle session handler.
Definition jinglesessionhandler.h:33
gloox::Jingle::SessionManager::~SessionManager
virtual ~SessionManager()
Definition jinglesessionmanager.cpp:39
gloox::Jingle::SessionManager::handleIq
virtual bool handleIq(const IQ &iq)
Definition jinglesessionmanager.cpp:78
gloox::Jingle::SessionManager::SessionManager
SessionManager(ClientBase *parent, SessionHandler *sh)
Definition jinglesessionmanager.cpp:28
gloox::Jingle::SessionManager::registerPlugin
void registerPlugin(Plugin *plugin)
Definition jinglesessionmanager.cpp:44
gloox::Jingle::SessionManager::createSession
Session * createSession(const JID &callee, SessionHandler *handler)
Definition jinglesessionmanager.cpp:59
gloox::Jingle::SessionManager::discardSession
void discardSession(Session *session)
Definition jinglesessionmanager.cpp:69
gloox::Jingle::Session::Jingle
This is an abstraction of Jingle's (XEP-0166) <jingle> element as a StanzaExtension.
Definition jinglesession.h:199
gloox::Jingle::Session::Jingle::embeddedTag
Tag * embeddedTag() const
Definition jinglesession.h:255
gloox::Jingle::Session::Jingle::sid
const std::string & sid() const
Definition jinglesession.h:219
gloox::Jingle::Session
This is an implementation of a Jingle Session (XEP-0166).
Definition jinglesession.h:81
gloox::Jingle::Session::handleIq
virtual bool handleIq(const IQ &iq)
Definition jinglesession.cpp:419
gloox::Stanza::from
const JID & from() const
Definition stanza.h:51
gloox::Stanza::findExtension
const StanzaExtension * findExtension(int type) const
Definition stanza.cpp:57
gloox::Jingle
The namespace containing Jingle-related (XEP-0166 et. al.) classes.
Definition jinglecontent.cpp:22
gloox::util::clearList
void clearList(std::list< T * > &L)
Definition util.h:152
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::XMLNS_JINGLE
const std::string XMLNS_JINGLE
Definition gloox.cpp:101
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::ExtJingle
@ ExtJingle
Definition stanzaextension.h:77