SIP Witch 1.9.15: service.h Source File

SIP Witch 1.9.15
service.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
30 #ifndef _SIPWITCH_SERVICE_H_
31 #define _SIPWITCH_SERVICE_H_
32 
33 #ifndef _UCOMMON_LINKED_H_
34 #include <ucommon/linked.h>
35 #endif
36 
37 #ifndef _UCOMMON_THREAD_H_
38 #include <ucommon/thread.h>
39 #endif
40 
41 #ifndef _UCOMMON_STRING_H_
42 #include <ucommon/string.h>
43 #endif
44 
45 #ifndef _UCOMMON_FSYS_H_
46 #include <ucommon/fsys.h>
47 #endif
48 
49 #ifndef _SIPWITCH_NAMESPACE_H_
50 #include <sipwitch/namespace.h>
51 #endif
52 
53 #ifndef _SIPWITCH_MAPPED_H_
54 #include <sipwitch/mapped.h>
55 #endif
56 
57 #ifndef _SIPWITCH_CONTROL_H_
58 #include <sipwitch/control.h>
59 #endif
60 
61 #ifndef _SIPWITCH_CDR_H_
62 #include <sipwitch/cdr.h>
63 #endif
64 
65  #define CONFIG_KEY_SIZE 177
66 
67 namespace sipwitch {
68 
78  class __EXPORT service : public memalloc
79 {
80 public:
84   typedef treemap<char *> keynode;
85 
89   typedef enum {EXT_DIALING, USER_DIALING, ALL_DIALING} dialmode_t;
90 
94   typedef struct {
95   const char *key;
96   const char *value;
97  } define;
98 
105   class __EXPORT keyclone : public treemap<char *>
106  {
107  public:
108  void splice(keyclone *trunk);
109 
110   inline void reset(const char *tag)
111  {Id = (char *)tag;}
112  };
113 
119   class __EXPORT usernode
120  {
121  public:
122   service::keynode *keys;
123   service *heap;
124  usernode();
125  };
126 
130   class __EXPORT pointer
131  {
132  private:
133   keynode *node;
134 
135  public:
136  pointer();
137  pointer(const char *path);
138  pointer(pointer const&);
139  ~pointer();
140 
141   inline operator bool() const
142 {return node != NULL;}
143 
144   inline bool operator!() const
145 {return node == NULL;}
146 
147  void operator=(keynode *node);
148 
149   inline keynode *operator*() const
150 {return node;}
151 
152   inline keynode *operator->() const
153 {return node;}
154  };
155 
159   class __EXPORT instance
160  {
161  public:
162  instance();
163  ~instance();
164 
165   inline const service *operator->() const
166 {return service::cfg;}
167  };
168 
175   class __EXPORT callback : public OrderedObject
176  {
177  protected:
178   friend class service;
179   friend class modules;
180   friend class events;
181   friend class srv;
182 
183   unsigned runlevel;
184   bool active_flag;
185 
186   static LinkedObject *runlevels[4];
187   static unsigned count;
188   static unsigned short sip_port;
189   static const char *sip_iface;
190   static volatile char *sip_contact;
191   static volatile char *sip_publish;
192   static int sip_protocol;
193   static int sip_family;
194   static int sip_tlsmode;
195   static bool sip_public; // hotspot mode flag
196   static const char *sip_domain;
197   static const char *sip_realm;
198   static const char *sip_tlspwd;
199   static const char *sip_tlsdev;
200   static const char *sip_tlsca;
201   static const char *sip_tlsdh;
202   static const char *sip_tlskey;
203   static const char *sip_tlscert;
204   static unsigned sip_prefix;
205   static unsigned sip_range;
206   static char session_uuid[40];
207 
208  callback(int level = 0); // default is priority
209  virtual ~callback();
210 
211   inline static void *alloc(service *cfgp, size_t size)
212  {return cfgp->alloc(size);}
213 
214   inline static char *dup(service *cfgp, const char *s)
215  {return cfgp->dup(s);}
216 
217   inline static bool is_configured(void)
218  {return service::cfg != NULL;}
219 
220   inline bool is_active(void) const
221 {return active_flag;}
222 
223  virtual void cdrlog(cdr *call);
224  virtual void errlog(shell::loglevel_t level, const char *text);
225  virtual bool check(void);
226  virtual void snapshot(FILE *fp);
227  virtual void start(service *cfg);
228  virtual void stop(service *cfg);
229  virtual void reload(service *cfg);
230  virtual void publish(service *cfg);
231 
232  public:
233   static voip::context_t out_context;
234   static voip::context_t tcp_context;
235   static voip::context_t udp_context;
236   static voip::context_t tls_context;
237 
238   inline static void bind(unsigned short port)
239  {sip_port = port;}
240 
241   inline static void setPublic(void)
242  {sip_public = true;}
243 
244  static void bind(const char *addr);
245 
246  voip::context_t getContext(const char *uri);
247  };
248 
249  service(const char *name, size_t s = 0);
250  virtual ~service();
251 
252   static volatile dialmode_t dialmode;
253 
261  bool load(FILE *file, keynode *node = NULL);
262 
263  keynode *getPath(const char *path);
264  keynode *getNode(keynode *base, const char *id, const char *value);
265  keynode *addNode(keynode *base, define *defs);
266  keynode *addNode(keynode *base, const char *id, const char *value);
267  keynode *getNode(keynode *base, const char *grp, const char *attr, const char *value);
268  keynode *getList(const char *path);
269 
270   inline static LinkedObject *getModules(void)
271  {return service::callback::runlevels[3];}
272 
273   inline static LinkedObject *getGenerics(void)
274  {return service::callback::runlevels[2];}
275 
281  static void publish(const char *addr);
282 
283  static void published(struct sockaddr_storage *peer);
284  static const char *getValue(keynode *base, const char *id);
285  static void dump(FILE *fp, keynode *node, unsigned level);
286  static void snapshot(void);
287  static void dumpfile(void);
288  static bool period(long slice);
289  static void result(const char *value);
290  static void startup(void);
291  static void shutdown(void);
292  static long uptime(void);
293  static bool match(const char *digits, const char *pattern, bool partial);
294  static keynode *get(void);
295 
296  static keynode *getProtected(const char *path);
297  static keynode *getUser(const char *uid);
298  static keynode *path(const char *p);
299  static keynode *list(const char *p);
300 
301   inline static keynode *getEnviron(void)
302  {return getProtected("environ");}
303 
304   inline keynode *getRoot(void)
305  {return &root;}
306 
307  static string_t getContact(void);
308 
309   inline void setContact(const char *text)
310  {contact = dup(text);}
311 
312   static inline const char *getInterface(void)
313  {return service::callback::sip_iface;}
314 
315   static inline unsigned short getPort(void)
316  {return service::callback::sip_port;}
317 
318  virtual void dump(FILE *fp);
319  virtual void confirm(void);
320  void commit(void);
321 
322  static bool check(void);
323  static void release(keynode *node);
324 
325 protected:
326   friend class instance;
327 
331   class __LOCAL keymap : public LinkedObject
332  {
333  public:
334   service::keynode *node;
335   const char *id;
336  };
337 
338   keynode root;
339   stringbuf<1024> buffer;
340   LinkedObject *keys[CONFIG_KEY_SIZE];
341   const char *contact;
342 
343   static service *cfg;
344   static condlock_t locking;
345 
351  void addAttributes(keynode *node, char *attrib);
352 };
353 
354  #define RUNLEVELS (sizeof(callback::runlevels) / sizeof(LinkedObject *))
355  #define PRIORITY_RUNLEVEL 0
356  #define DEFAULT_RUNLEVEL 1
357  #define MODULE_RUNLEVEL (RUNLEVELS - 1)
358  #define GENERIC_RUNLEVEL (RUNLEVELS - 2)
359 
360 } // namespace sipwitch
361 
362 #endif
sipwitch::service::define::value
const char * value
Definition: service.h:96
sipwitch::uri
Some convenience methods for manipulating SIP uri's.
Definition: uri.h:55
sipwitch::service::callback::sip_publish
static volatile char * sip_publish
Definition: service.h:191
sipwitch::service::buffer
stringbuf< 1024 > buffer
Definition: service.h:339
sipwitch::service::callback::udp_context
static voip::context_t udp_context
Definition: service.h:235
sipwitch::service::callback::sip_contact
static volatile char * sip_contact
Definition: service.h:190
sipwitch::service::usernode
Pointer to a provisioned user xml subtree.
Definition: service.h:119
sipwitch::service::usernode::keys
service::keynode * keys
Definition: service.h:122
sipwitch::service::callback::tls_context
static voip::context_t tls_context
Definition: service.h:236
sipwitch::service::dialmode
static volatile dialmode_t dialmode
Definition: service.h:252
sipwitch::service::getInterface
static const char * getInterface(void)
Definition: service.h:312
sipwitch::events
Event message and supporting methods for plugins.
Definition: events.h:66
sipwitch::service::callback::is_active
bool is_active(void) const
Definition: service.h:220
sipwitch::service::keyclone
Used to splice new chains onto an existing xml tree.
Definition: service.h:105
sipwitch::service::keymap::id
const char * id
Definition: service.h:335
sipwitch::service::callback::sip_public
static bool sip_public
Definition: service.h:195
sipwitch::service::callback::sip_prefix
static unsigned sip_prefix
Definition: service.h:204
sipwitch::service::getRoot
keynode * getRoot(void)
Definition: service.h:304
sipwitch::service::keymap
Linked list of named xml node locations.
Definition: service.h:331
sipwitch::service::callback::bind
static void bind(unsigned short port)
Definition: service.h:238
sipwitch::service::getModules
static LinkedObject * getModules(void)
Definition: service.h:270
CONFIG_KEY_SIZE
#define CONFIG_KEY_SIZE
Definition: service.h:65
sipwitch::service::callback::tcp_context
static voip::context_t tcp_context
Definition: service.h:234
sipwitch::service::callback::sip_iface
static const char * sip_iface
Definition: service.h:189
sipwitch::service::root
keynode root
Definition: service.h:338
sipwitch::service::define
Keyword and value pair definition lists.
Definition: service.h:94
mapped.h
Definitions for memory mapped objects that may be shared between processes.
sipwitch::service::setContact
void setContact(const char *text)
Definition: service.h:309
sipwitch::service::callback::runlevels
static LinkedObject * runlevels[4]
Definition: service.h:186
cdr.h
Basic server call detail record.
sipwitch::service::pointer::operator!
bool operator!() const
Definition: service.h:144
sipwitch::service::callback::sip_realm
static const char * sip_realm
Definition: service.h:197
sipwitch::service::callback::alloc
static void * alloc(service *cfgp, size_t size)
Definition: service.h:211
namespace.h
GNU SIP Witch library namespace.
sipwitch::service::locking
static condlock_t locking
Definition: service.h:344
sipwitch::service::getEnviron
static keynode * getEnviron(void)
Definition: service.h:301
sipwitch::service::callback::sip_tlsmode
static int sip_tlsmode
Definition: service.h:194
sipwitch::service::cfg
static service * cfg
Definition: service.h:343
sipwitch::service::keyclone::reset
void reset(const char *tag)
Definition: service.h:110
sipwitch::service::contact
const char * contact
Definition: service.h:341
sipwitch::service::callback
Callback methods for objects managed under the service thread.
Definition: service.h:175
sipwitch::service::getGenerics
static LinkedObject * getGenerics(void)
Definition: service.h:273
sipwitch::service::callback::setPublic
static void setPublic(void)
Definition: service.h:241
sipwitch::service::callback::is_configured
static bool is_configured(void)
Definition: service.h:217
sipwitch::service::getPort
static unsigned short getPort(void)
Definition: service.h:315
sipwitch::service::define::key
const char * key
Definition: service.h:95
sipwitch::service::callback::sip_tlskey
static const char * sip_tlskey
Definition: service.h:202
sipwitch::service::callback::sip_domain
static const char * sip_domain
Definition: service.h:196
sipwitch::service::callback::sip_tlsdh
static const char * sip_tlsdh
Definition: service.h:201
sipwitch::service::callback::sip_tlsca
static const char * sip_tlsca
Definition: service.h:200
name
char * name[96]
Definition: cgiserver.cpp:88
value
char * value[96]
Definition: cgiserver.cpp:90
sipwitch::service::keymap::node
service::keynode * node
Definition: service.h:334
sipwitch::voip::context_t
void * context_t
Definition: voip.h:53
sipwitch::service::pointer
A pointer to a subtree in the xml configuration tree.
Definition: service.h:130
sipwitch::service::callback::dup
static char * dup(service *cfgp, const char *s)
Definition: service.h:214
sipwitch::service::callback::out_context
static voip::context_t out_context
Definition: service.h:233
sipwitch::service::dialmode_t
dialmode_t
Dialing mode supported.
Definition: service.h:89
sipwitch::service::callback::sip_tlsdev
static const char * sip_tlsdev
Definition: service.h:199
sipwitch::service::callback::sip_family
static int sip_family
Definition: service.h:193
sipwitch::service::callback::sip_tlscert
static const char * sip_tlscert
Definition: service.h:203
sipwitch::service::callback::sip_protocol
static int sip_protocol
Definition: service.h:192
sipwitch::service
System configuration instance and service functions.
Definition: service.h:78
control.h
Manage control interface.
sipwitch::service::pointer::operator*
keynode * operator*() const
Definition: service.h:149
sipwitch::service::callback::sip_port
static unsigned short sip_port
Definition: service.h:188
sipwitch::service::instance::operator->
const service * operator->() const
Definition: service.h:165
sipwitch::service::instance
The current singleton instance of the active xml configuration tree.
Definition: service.h:159
sipwitch::cdr
Interface class for call detail records.
Definition: cdr.h:56
sipwitch::modules
Common interfaces and clases for plugins.
Definition: modules.h:55
sipwitch::service::callback::sip_range
static unsigned sip_range
Definition: service.h:205
sipwitch::service::callback::sip_tlspwd
static const char * sip_tlspwd
Definition: service.h:198
sipwitch::srv
Definition: uri.h:69
sipwitch::service::keynode
treemap< char * > keynode
Definition of a xml node.
Definition: service.h:84
sipwitch::service::pointer::operator->
keynode * operator->() const
Definition: service.h:152
sipwitch::service::callback::count
static unsigned count
Definition: service.h:187

Generated on Dec 21, 2017 for sipwitch-1.9.15 (*.h and *.cpp), libosip2-5.0.0 (*.h) and libeXosip2-4.0.0 (*.h), by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /