gloox  1.0.1
stanzaextensionfactory.cpp
1 /*
2  Copyright (c) 2006-2012 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #include "stanzaextensionfactory.h"
15 
16 #include "gloox.h"
17 #include "mutexguard.h"
18 #include "util.h"
19 #include "stanza.h"
20 #include "stanzaextension.h"
21 #include "tag.h"
22 
23 namespace gloox
24 {
25 
27  {
28  }
29 
31  {
32  m_extensionsMutex.lock();
33  util::clearList( m_extensions );
34  m_extensionsMutex.unlock();
35  }
36 
38  {
39  if( !ext )
40  return;
41 
42  util::MutexGuard m( m_extensionsMutex );
43  SEList::iterator it = m_extensions.begin();
44  SEList::iterator it2;
45  while( it != m_extensions.end() )
46  {
47  it2 = it++;
48  if( ext->extensionType() == (*it2)->extensionType() )
49  {
50  delete (*it2);
51  m_extensions.erase( it2 );
52  }
53  }
54  m_extensions.push_back( ext );
55  }
56 
58  {
59  util::MutexGuard m( m_extensionsMutex );
60  SEList::iterator it = m_extensions.begin();
61  for( ; it != m_extensions.end(); ++it )
62  {
63  if( (*it)->extensionType() == ext )
64  {
65  delete (*it);
66  m_extensions.erase( it );
67  return true;
68  }
69  }
70  return false;
71  }
72 
74  {
75  ConstTagList::const_iterator it;
76 
77  util::MutexGuard m( m_extensionsMutex );
78  SEList::const_iterator ite = m_extensions.begin();
79  for( ; ite != m_extensions.end(); ++ite )
80  {
81  const ConstTagList& match = tag->findTagList( (*ite)->filterString() );
82  it = match.begin();
83  for( ; it != match.end(); ++it )
84  {
85  StanzaExtension* se = (*ite)->newInstance( (*it) );
86  if( se )
87  stanza.addExtension( se );
88  }
89  }
90  }
91 
92 }