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