stanzaextensionfactory.cpp
/*
Copyright (c) 2006-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 "stanzaextensionfactory.h"
#include "gloox.h"
#include "mutexguard.h"
#include "util.h"
#include "stanza.h"
#include "stanzaextension.h"
#include "tag.h"
namespace gloox
{
StanzaExtensionFactory::StanzaExtensionFactory()
{
}
StanzaExtensionFactory::~StanzaExtensionFactory()
{
m_extensionsMutex.lock();
util::clearList( m_extensions );
m_extensionsMutex.unlock();
}
void StanzaExtensionFactory::registerExtension( StanzaExtension* ext )
{
if( !ext )
return;
util::MutexGuard m( m_extensionsMutex );
SEList::iterator it = m_extensions.begin();
SEList::iterator it2;
while( it != m_extensions.end() )
{
it2 = it++;
if( ext->extensionType() == (*it2)->extensionType() )
{
delete (*it2);
m_extensions.erase( it2 );
}
}
m_extensions.push_back( ext );
}
bool StanzaExtensionFactory::removeExtension( int ext )
{
util::MutexGuard m( m_extensionsMutex );
SEList::iterator it = m_extensions.begin();
for( ; it != m_extensions.end(); ++it )
{
if( (*it)->extensionType() == ext )
{
delete (*it);
m_extensions.erase( it );
return true;
}
}
return false;
}
void StanzaExtensionFactory::addExtensions( Stanza& stanza, Tag* tag )
{
ConstTagList::const_iterator it;
util::MutexGuard m( m_extensionsMutex );
SEList::const_iterator ite = m_extensions.begin();
for( ; ite != m_extensions.end(); ++ite )
{
const ConstTagList& match = tag->findTagList( (*ite)->filterString() );
it = match.begin();
for( ; it != match.end(); ++it )
{
StanzaExtension* se = (*ite)->newInstance( (*it) );
if( se )
{
stanza.addExtension( se );
if( se->embeddedStanza() )
stanza.setEmbeddedStanza();
}
}
}
}
}
gloox::StanzaExtensionFactory::StanzaExtensionFactory
StanzaExtensionFactory()
Definition stanzaextensionfactory.cpp:26
gloox::StanzaExtensionFactory::~StanzaExtensionFactory
~StanzaExtensionFactory()
Definition stanzaextensionfactory.cpp:30
gloox::StanzaExtensionFactory::registerExtension
void registerExtension(StanzaExtension *ext)
Definition stanzaextensionfactory.cpp:37
gloox::StanzaExtensionFactory::addExtensions
void addExtensions(Stanza &stanza, Tag *tag)
Definition stanzaextensionfactory.cpp:73
gloox::StanzaExtensionFactory::removeExtension
bool removeExtension(int ext)
Definition stanzaextensionfactory.cpp:57
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition stanzaextension.h:204
gloox::StanzaExtension::newInstance
virtual StanzaExtension * newInstance(const Tag *tag) const =0
gloox::StanzaExtension::embeddedStanza
virtual Stanza * embeddedStanza() const
Definition stanzaextension.h:224
gloox::StanzaExtension::extensionType
int extensionType() const
Definition stanzaextension.h:271
gloox::Stanza
This is the base class for XMPP stanza abstractions.
Definition stanza.h:34
gloox::Stanza::addExtension
void addExtension(const StanzaExtension *se)
Definition stanza.cpp:52
gloox::Stanza::setEmbeddedStanza
void setEmbeddedStanza()
Definition stanza.h:126
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::findTagList
ConstTagList findTagList(const std::string &expression) const
Definition tag.cpp:811
gloox::util::MutexGuard
A simple implementation of a mutex guard.
Definition mutexguard.h:32
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::ConstTagList
std::list< const Tag * > ConstTagList
Definition tag.h:36