00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "stanzaextensionfactory.h"
00015
00016 #include "gloox.h"
00017 #include "mutexguard.h"
00018 #include "util.h"
00019 #include "stanza.h"
00020 #include "stanzaextension.h"
00021 #include "tag.h"
00022
00023 namespace gloox
00024 {
00025
00026 StanzaExtensionFactory::StanzaExtensionFactory()
00027 {
00028 }
00029
00030 StanzaExtensionFactory::~StanzaExtensionFactory()
00031 {
00032 m_extensionsMutex.lock();
00033 util::clearList( m_extensions );
00034 m_extensionsMutex.unlock();
00035 }
00036
00037 void StanzaExtensionFactory::registerExtension( StanzaExtension* ext )
00038 {
00039 if( !ext )
00040 return;
00041
00042 util::MutexGuard m( m_extensionsMutex );
00043 SEList::iterator it = m_extensions.begin();
00044 SEList::iterator it2;
00045 while( it != m_extensions.end() )
00046 {
00047 it2 = it++;
00048 if( ext->extensionType() == (*it2)->extensionType() )
00049 {
00050 delete (*it2);
00051 m_extensions.erase( it2 );
00052 }
00053 }
00054 m_extensions.push_back( ext );
00055 }
00056
00057 bool StanzaExtensionFactory::removeExtension( int ext )
00058 {
00059 util::MutexGuard m( m_extensionsMutex );
00060 SEList::iterator it = m_extensions.begin();
00061 for( ; it != m_extensions.end(); ++it )
00062 {
00063 if( (*it)->extensionType() == ext )
00064 {
00065 delete (*it);
00066 m_extensions.erase( it );
00067 return true;
00068 }
00069 }
00070 return false;
00071 }
00072
00073 void StanzaExtensionFactory::addExtensions( Stanza& stanza, Tag* tag )
00074 {
00075 ConstTagList::const_iterator it;
00076
00077 util::MutexGuard m( m_extensionsMutex );
00078 SEList::const_iterator ite = m_extensions.begin();
00079 for( ; ite != m_extensions.end(); ++ite )
00080 {
00081 const ConstTagList& match = tag->findTagList( (*ite)->filterString() );
00082 it = match.begin();
00083 for( ; it != match.end(); ++it )
00084 {
00085 StanzaExtension* se = (*ite)->newInstance( (*it) );
00086 if( se )
00087 stanza.addExtension( se );
00088 }
00089 }
00090 }
00091
00092 }