SIP Witch 1.9.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:
124  usernode();
125  };
126 
130  class __EXPORT pointer
131  {
132  private:
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;
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:
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)
314 
315  static inline unsigned short getPort(void)
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:
335  const char *id;
336  };
337 
339  stringbuf<1024> buffer;
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
const char * value
Definition: service.h:96
Some convenience methods for manipulating SIP uri's.
Definition: uri.h:55
static volatile char * sip_publish
Definition: service.h:191
stringbuf< 1024 > buffer
Definition: service.h:339
static voip::context_t udp_context
Definition: service.h:235
static volatile char * sip_contact
Definition: service.h:190
Pointer to a provisioned user xml subtree.
Definition: service.h:119
service::keynode * keys
Definition: service.h:122
static voip::context_t tls_context
Definition: service.h:236
static volatile dialmode_t dialmode
Definition: service.h:252
static const char * getInterface(void)
Definition: service.h:312
Event message and supporting methods for plugins.
Definition: events.h:66
bool is_active(void) const
Definition: service.h:220
Used to splice new chains onto an existing xml tree.
Definition: service.h:105
static unsigned sip_prefix
Definition: service.h:204
keynode * getRoot(void)
Definition: service.h:304
Linked list of named xml node locations.
Definition: service.h:331
static void bind(unsigned short port)
Definition: service.h:238
static LinkedObject * getModules(void)
Definition: service.h:270
#define CONFIG_KEY_SIZE
Definition: service.h:65
static voip::context_t tcp_context
Definition: service.h:234
static const char * sip_iface
Definition: service.h:189
keynode root
Definition: service.h:338
Keyword and value pair definition lists.
Definition: service.h:94
Definitions for memory mapped objects that may be shared between processes.
void setContact(const char *text)
Definition: service.h:309
static LinkedObject * runlevels[4]
Definition: service.h:186
Basic server call detail record.
bool operator!() const
Definition: service.h:144
static const char * sip_realm
Definition: service.h:197
static void * alloc(service *cfgp, size_t size)
Definition: service.h:211
GNU SIP Witch library namespace.
static condlock_t locking
Definition: service.h:344
static keynode * getEnviron(void)
Definition: service.h:301
static service * cfg
Definition: service.h:343
void reset(const char *tag)
Definition: service.h:110
const char * contact
Definition: service.h:341
Callback methods for objects managed under the service thread.
Definition: service.h:175
static LinkedObject * getGenerics(void)
Definition: service.h:273
static void setPublic(void)
Definition: service.h:241
static bool is_configured(void)
Definition: service.h:217
static unsigned short getPort(void)
Definition: service.h:315
const char * key
Definition: service.h:95
static const char * sip_tlskey
Definition: service.h:202
static const char * sip_domain
Definition: service.h:196
static const char * sip_tlsdh
Definition: service.h:201
static const char * sip_tlsca
Definition: service.h:200
char * name[96]
Definition: cgiserver.cpp:88
char * value[96]
Definition: cgiserver.cpp:90
service::keynode * node
Definition: service.h:334
void * context_t
Definition: voip.h:53
A pointer to a subtree in the xml configuration tree.
Definition: service.h:130
static char * dup(service *cfgp, const char *s)
Definition: service.h:214
static voip::context_t out_context
Definition: service.h:233
dialmode_t
Dialing mode supported.
Definition: service.h:89
static const char * sip_tlsdev
Definition: service.h:199
static const char * sip_tlscert
Definition: service.h:203
System configuration instance and service functions.
Definition: service.h:78
Manage control interface.
keynode * operator*() const
Definition: service.h:149
static unsigned short sip_port
Definition: service.h:188
const service * operator->() const
Definition: service.h:165
The current singleton instance of the active xml configuration tree.
Definition: service.h:159
Interface class for call detail records.
Definition: cdr.h:56
Common interfaces and clases for plugins.
Definition: modules.h:55
static unsigned sip_range
Definition: service.h:205
static const char * sip_tlspwd
Definition: service.h:198
treemap< char * > keynode
Definition of a xml node.
Definition: service.h:84
keynode * operator->() const
Definition: service.h:152
static unsigned count
Definition: service.h:187