glooxd  0.3-svn
configmanager.h
1 /*
2  Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the glooxd library. http://camaya.net/glooxd
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 #ifndef CONFIGMANAGER_H__
15 #define CONFIGMANAGER_H__
16 
17 #include "macros.h"
18 
19 #include <gloox/gloox.h>
20 #include <gloox/jid.h>
21 #include <gloox/mutex.h>
22 
23 #include <list>
24 
25 namespace gloox
26 {
27  class LogSink;
28 }
29 
30 namespace glooxd
31 {
32 
33  class ConfigHandler;
34  class ServerEventHandler;
35 
42  class GLOOXD_API ConfigManager
43  {
44  public:
49  ConfigManager( const gloox::LogSink& _logInstance );
50 
54  virtual ~ConfigManager();
55 
60  void registerConfigHandler( ConfigHandler* ch );
61 
66  void registerServerEventHandler( ServerEventHandler* seh );
67 
77  void bindDomain( const std::string& domain, const std::string& interface = gloox::EmptyString,
78  unsigned short port = 5222 );
79 
86  void unbindDomain( const std::string& domain, const std::string& interface = gloox::EmptyString,
87  unsigned short port = 5222 );
88 
94  bool addC2SInterface( const std::string& interface = gloox::EmptyString,
95  unsigned short port = 5222 );
96 
102  bool removeC2SInterface( const std::string& interface = gloox::EmptyString,
103  unsigned short port = 5222 );
104 
111  void rebind();
112 
118  void shutdown();
119 
126  virtual bool checkDomain( const std::string& domain, const std::string& ip,
127  int port );
128 
140  virtual void handleC2SListening( bool yes );
141 
153  virtual void handleS2SListening( bool yes );
154 
164  virtual void handleClientConnected( const gloox::JID jid, const std::string localIP, int localPort,
165  const std::string remoteIP, int remotePort );
166 
176  virtual void handleClientDisconnected( const gloox::JID jid, gloox::ConnectionError e,
177  gloox::StreamError se );
178 
179  private:
184  struct Interface
185  {
186 
187  public:
195  Interface( const std::string& iface = gloox::EmptyString, int p = 5222 )
196  : m_interface( iface ), m_port( p )
197  {}
198 
202  ~Interface() {}
203 
208  const std::string& interface() const { return m_interface; }
209 
214  int port() const { return m_port; }
215 
221  bool hasDomain( const std::string& domain );
222 
227  void removeDomain( const std::string& domain )
228  {
229  m_domains.remove( domain );
230  }
231 
236  void addDomain( const std::string& domain )
237  {
238  m_domains.push_back( domain );
239  }
240 
241  private:
242  std::string m_interface;
243  int m_port;
244 
245  gloox::StringList m_domains;
246 
247  };
248 
249  bool findInterface( const std::string& interface, unsigned short port );
250 
251  typedef std::list<ConfigHandler*> ConfigHandlerList;
252  typedef std::list<Interface*> InterfaceList;
253  typedef std::list<ServerEventHandler*> ServerEventHandlerList;
254 
255  ConfigHandlerList m_configHandlers;
256  InterfaceList m_c2sInterfaces;
257  ServerEventHandlerList m_eventHandlers;
258 
259  gloox::util::Mutex m_c2sInterfacesMutex;
260  gloox::util::Mutex m_configHandlersMutex;
261  gloox::util::Mutex m_eventHandlersMutex;
262 
263  const gloox::LogSink& m_logInstance;
264 
265  };
266 
267 }
268 
269 #endif // CONFIGMANAGER_H__