14 #include "confighandler.h"
15 #include "configmanager.h"
16 #include "servereventhandler.h"
18 #include <gloox/logsink.h>
19 #include <gloox/mutexguard.h>
20 #include <gloox/util.h>
28 bool ConfigManager::Interface::hasDomain(
const std::string& domain )
30 gloox::StringList::const_iterator it = m_domains.begin();
31 for( ; it != m_domains.end() && (*it) != domain; ++it )
33 return it != m_domains.end();
38 : m_logInstance( logInstance )
44 gloox::util::clearList( m_c2sInterfaces );
52 m_configHandlersMutex.lock();
53 m_configHandlers.push_back( ch );
54 m_configHandlersMutex.unlock();
62 m_eventHandlersMutex.lock();
63 m_eventHandlers.push_back( seh );
64 m_eventHandlersMutex.unlock();
73 m_configHandlersMutex.lock();
75 m_configHandlersMutex.unlock();
77 gloox::util::MutexGuard mg( m_c2sInterfacesMutex );
78 InterfaceList::const_iterator it = m_c2sInterfaces.begin();
79 for( ; it != m_c2sInterfaces.end(); ++it )
81 if( (*it)->interface() ==
interface && (*it)->port() == port )
83 (*it)->addDomain( domain );
95 m_configHandlersMutex.lock();
97 m_configHandlersMutex.unlock();
99 gloox::util::MutexGuard mg( m_c2sInterfacesMutex );
100 InterfaceList::const_iterator it = m_c2sInterfaces.begin();
101 for( ; it != m_c2sInterfaces.end(); ++it )
103 if( (*it)->interface() ==
interface && (*it)->port() == port )
105 (*it)->removeDomain( domain );
112 unsigned short port )
114 if( findInterface( interface, port ) )
117 m_c2sInterfacesMutex.lock();
118 m_c2sInterfaces.push_back(
new Interface( interface, port ) );
119 m_c2sInterfacesMutex.unlock();
121 m_configHandlersMutex.lock();
123 m_configHandlersMutex.unlock();
128 unsigned short port )
130 gloox::util::MutexGuard mg( m_c2sInterfacesMutex );
131 InterfaceList::iterator it = m_c2sInterfaces.begin();
132 for( ; it != m_c2sInterfaces.end(); ++it )
134 if( (*it)->interface() ==
interface && (*it)->port() == port )
137 m_c2sInterfaces.erase( it );
146 bool ConfigManager::findInterface(
const std::string& interface,
147 unsigned short port )
149 gloox::util::MutexGuard mg( m_c2sInterfacesMutex );
150 InterfaceList::const_iterator it = m_c2sInterfaces.begin();
151 for( ; it != m_c2sInterfaces.end(); ++it )
153 if( (*it)->interface() ==
interface && (*it)->port() == port )
161 gloox::util::MutexGuard mg( m_configHandlersMutex );
162 InterfaceList::const_iterator it = m_c2sInterfaces.begin();
163 for( ; it != m_c2sInterfaces.end(); ++it )
165 const std::string&
interface = (*it)->interface();
166 int port = (*it)->port();
174 gloox::util::MutexGuard mg( m_configHandlersMutex );
182 printf(
"checking %s on %s:%d\n", domain.c_str(), ip.c_str(), port );
184 gloox::util::MutexGuard mg( m_c2sInterfacesMutex );
185 InterfaceList::const_iterator it = m_c2sInterfaces.begin();
186 for( ; it != m_c2sInterfaces.end(); ++it )
188 if( ( (*it)->interface() == gloox::EmptyString
189 || (*it)->interface() == ip )
190 && (*it)->port() == port
191 && (*it)->hasDomain( domain ) )
199 gloox::util::MutexGuard mg( m_eventHandlersMutex );
205 gloox::util::MutexGuard mg( m_eventHandlersMutex );
210 const std::string remoteIP,
int remotePort )
212 gloox::util::MutexGuard mg( m_eventHandlersMutex );
213 ServerEventHandlerList::const_iterator it = m_eventHandlers.begin();
214 for( ; it != m_eventHandlers.end(); ++it )
215 (*it)->handleClientConnected( jid, localIP, localPort, remoteIP, remotePort );
219 gloox::StreamError se )
221 gloox::util::MutexGuard mg( m_eventHandlersMutex );