gloox  1.0.28
stanzaextensionfactory.cpp
1 /*
2  Copyright (c) 2006-2023 by Jakob Schröter <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  {
88  stanza.addExtension( se );
89  if( se->embeddedStanza() )
90  stanza.setEmbeddedStanza();
91  }
92  }
93  }
94  }
95 
96 }
void registerExtension(StanzaExtension *ext)
void addExtensions(Stanza &stanza, Tag *tag)
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
virtual Stanza * embeddedStanza() const
virtual StanzaExtension * newInstance(const Tag *tag) const =0
This is the base class for XMPP stanza abstractions.
Definition: stanza.h:34
void addExtension(const StanzaExtension *se)
Definition: stanza.cpp:52
void setEmbeddedStanza()
Definition: stanza.h:126
This is an abstraction of an XML element.
Definition: tag.h:47
ConstTagList findTagList(const std::string &expression) const
Definition: tag.cpp:811
A simple implementation of a mutex guard.
Definition: mutexguard.h:32
void clearList(std::list< T * > &L)
Definition: util.h:152
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< const Tag * > ConstTagList
Definition: tag.h:36