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
00032
00033 SEList::iterator it = m_extensions.begin();
00034 SEList::iterator it2;
00035 while( it != m_extensions.end() )
00036 {
00037 it2 = it++;
00038 delete (*it2);
00039 m_extensions.erase( it2 );
00040 }
00041
00042 }
00043
00044 void StanzaExtensionFactory::registerExtension( StanzaExtension* ext )
00045 {
00046 if( !ext )
00047 return;
00048
00049 SEList::iterator it = m_extensions.begin();
00050 SEList::iterator it2;
00051 while( it != m_extensions.end() )
00052 {
00053 it2 = it++;
00054 if( ext->extensionType() == (*it2)->extensionType() )
00055 {
00056 delete (*it2);
00057 m_extensions.erase( it2 );
00058 }
00059 }
00060 m_extensions.push_back( ext );
00061 }
00062
00063 bool StanzaExtensionFactory::removeExtension( int ext )
00064 {
00065 SEList::iterator it = m_extensions.begin();
00066 for( ; it != m_extensions.end(); ++it )
00067 {
00068 if( (*it)->extensionType() == ext )
00069 {
00070 delete (*it);
00071 m_extensions.erase( it );
00072 return true;
00073 }
00074 }
00075 return false;
00076 }
00077
00078 void StanzaExtensionFactory::addExtensions( Stanza& stanza, Tag* tag )
00079 {
00080 ConstTagList match;
00081 ConstTagList::const_iterator it;
00082 SEList::const_iterator ite = m_extensions.begin();
00083 for( ; ite != m_extensions.end(); ++ite )
00084 {
00085 match = tag->findTagList( (*ite)->filterString() );
00086 it = match.begin();
00087 for( ; it != match.end(); ++it )
00088 {
00089 StanzaExtension* se = (*ite)->newInstance( (*it) );
00090 if( se )
00091 stanza.addExtension( se );
00092 }
00093 }
00094 }
00095
00096 }