18 #include <sipwitch-config.h>
20 #include <ucommon/secure.h>
23 #include <systemd/sd-daemon.h>
33 #define SECOND_TIMEOUT (1000l)
34 #define MINUTE_TIMEOUT (SECOND_TIMEOUT * 60l)
35 #define HOUR_TIMEOUT (MINUTE_TIMEOUT * 60l)
36 #define DAY_TIMEOUT (HOUR_TIMEOUT * 24l)
40 #define PAGING_SIZE (2048l * sizeof(void *))
42 #define ALLOWS_INVITE 0x0001
43 #define ALLOWS_MESSAGE 0x0002
44 #define ALLOWS_DEFAULT 0x0003
53 static void reload(
void);
55 static const char *
get(
const char *id);
57 static bool set(
const char *
id,
const char *hash);
59 static void release(
const char *hash);
61 static void load(
void);
70 void update(Socket::address& addr,
int changed);
72 bool expire(Socket::address& addr);
73 bool refresh(Socket::address& addr, time_t expires,
const char *target_contact);
75 unsigned addTarget(Socket::address& via, time_t expires,
const char *contact,
const char *policy,
struct sockaddr *peer,
voip::context_t context);
76 unsigned setTarget(Socket::address& via, time_t expires,
const char *contact,
const char *policy,
struct sockaddr *peer,
voip::context_t context);
77 void addContact(
const char *
id);
78 void addPublished(
const char *
id);
79 void addRoute(
const char *pat,
unsigned pri,
const char *prefix,
const char *suffix);
93 void operator=(
mapped *ptr);
95 inline operator bool()
const
96 {
return entry != NULL;}
99 {
return entry == NULL;}
111 typedef enum {READY, BUSY, AWAY, DND, OFFLINE, UNKNOWN} status_t;
120 struct sockaddr_internet address;
121 struct sockaddr_storage peering;
131 static void *
operator new(
size_t size);
132 static void operator delete(
void *ptr);
151 static void *
operator new(
size_t size);
152 static void operator delete(
void *ptr);
159 void snapshot(FILE *fp);
161 static void clear(
mapped *rr);
162 static void expire(
mapped *rr);
163 static mapped *find(
const char *
id);
179 {
return (
const char *)reg.realm;}
182 {
return (
const char *)reg.digest;}
185 {
return reg.expires;}
196 static const char *getDomain(
void);
199 static unsigned getEntries(
void);
200 static unsigned getIndex(mapped *rr);
201 static bool isExtension(
const char *
id);
202 static bool isUserid(
const char *
id);
203 static mapped *address(
const struct sockaddr *addr);
204 static mapped *contact(
const char *
uri);
205 static mapped *contact(
const struct sockaddr *addr,
const char *uid);
206 static mapped *getExtension(
const char *
id);
207 static mapped *allocate(
const char *
id);
208 static mapped *access(
const char *
id);
210 static mapped *dialing(
const char *
id);
211 static bool exists(
const char *
id);
212 static pattern *getRouting(
unsigned trs,
const char *
id);
213 static void detach(mapped *m);
214 static bool remove(
const char *id);
215 static unsigned cleanup(time_t period);
231 static void create(timeout_t interval);
232 static void cancel(
void);
263 enum {OPEN, CLOSED,
RING, BUSY, REORDER, REFER, REINVITE} state;
274 struct sockaddr_storage peering;
281 {
return (
this == parent->source);}
284 {
return (
this == parent->target);}
292 static void *
operator new(
size_t size);
293 static void operator delete(
void *obj);
304 typedef enum {INITIAL,
TRYING, RINGING, RINGBACK, REORDER, HOLDING, ANSWERED, JOINED, TRANSFER, REDIRECT, BUSY, TERMINATE, FAILED, FINAL}
state_t;
321 void arm(timeout_t timeout);
322 void reply_source(
int error);
332 timeout_t getTimeout(
void);
333 void closingLocked(
session *s);
334 void terminateLocked(
void);
335 void disconnectLocked(
void);
337 void cancelLocked(
void);
340 void set(
state_t state,
char id,
const char *text);
361 static void *
operator new(
size_t size);
362 static void operator delete(
void *obj);
371 void snapshot(FILE *fp);
407 subnet(cidr::policy **acl,
const char *rule,
const char *
name);
409 struct sockaddr_storage iface;
415 {
return (
struct sockaddr *)&iface;}
417 inline operator bool()
430 {
return active ==
false;}
435 static const char *getScheme(
void);
436 static void getInterface(
struct sockaddr *iface,
const struct sockaddr *dest);
439 static void destroy(session *s);
440 static void destroy(call *cr);
441 static void disjoin(call *cr);
442 static void detach(session *s);
443 static void clear(session *s);
444 static void close(session *s);
446 static char *sipAddress(
struct sockaddr_internet *addr,
char *buf,
const char *user = NULL,
size_t size =
MAX_URI_SIZE);
447 static char *sipPublish(
struct sockaddr_internet *addr,
char *buf,
const char *user = NULL,
size_t size =
MAX_URI_SIZE);
448 static char *sipContact(
struct sockaddr_internet *addr,
char *buf,
const char *user = NULL,
const char *display = NULL,
size_t size =
MAX_URI_SIZE);
449 static Socket::address *getAddress(
const char *
uri, Socket::address *addr = NULL);
451 static void enableDumping(
void);
452 static void clearDumping(
void);
453 static void disableDumping(
void);
456 static void setDialog(session *session,
voip::did_t did);
457 static int getDialog(session *session);
461 static int inviteRemote(
stack::session *session,
const char *
uri,
const char *digest = NULL);
480 typedef linked_value<profile_t, LinkedObject>
profile;
487 bool create(
const char *
id, keynode *node);
488 keynode *find(
const char *
id);
502 static bool check(
void);
503 static profile_t *getProfile(
const char *
id);
504 static keynode *getRouting(
const char *
id);
505 static void getProvision(
const char *
id,
usernode& user);
506 static void getDialing(
const char *
id,
usernode& user);
507 static keynode *getConfig(
void);
508 static void listPolicy(FILE *fp);
509 static stack::subnet *getPolicy(
const struct sockaddr *addr);
511 static bool isLocal(
const struct sockaddr *addr);
513 static void release(keynode *node);
514 static void release(
usernode& user);
515 static void reload(
void);
516 static Socket::address *getContact(
const char *
id);
517 static void plugins(
const char *argv0,
const char *names);
518 static void run(
void);
519 static void stop(
void);
520 static void *allocate(
size_t size,
LinkedObject **list,
volatile unsigned *
count = NULL);
521 static unsigned allocate(
void);
523 static bool announce(
MappedRegistry *rr,
const char *msgtype,
const char *event,
const char *expires,
const char *body);
528 static bool authenticate(
voip::reg_t id,
const char *realm);
529 static const char *referLocal(
MappedRegistry *rr,
const char *target,
char *buffer,
size_t size);
530 static const char *referRemote(
MappedRegistry *rr,
const char *target,
char *buffer,
size_t size);
531 static bool checkId(
const char *
id);
532 static void printlog(
const char *fmt, ...) __PRINTF(1, 2);
556 void snapshot(FILE *fp);
558 static int deliver(
message *msg);
559 static int remote(
const char *to,
message *msg,
const char *digest = NULL);
564 static void automatic(
void);
565 static void update(
const char *userid);
566 static int deliver(
const char *to,
const char *reply,
const char *from, caddr_t body,
size_t size,
const char *msgtype,
const char *digest = NULL);
567 static int system(
const char *to,
const char *
message);
581 struct sockaddr_storage peering;
619 static void wait(
unsigned count);
622 void send_reply(
int error);
623 void expiration(
void);
626 bool getsource(
void);
627 bool unauthenticated(
void);
628 bool authenticate(
void);
630 bool authorize(
void);
631 void registration(
void);
635 void reregister(
const char *contact, time_t interval);
636 void deregister(
void);
637 void challenge(
void);
641 const char *getIdent(
void);
644 static void shutdown(
void);
655 static void startup(
void);
659 static void shutdown(
void);
675 struct sockaddr_storage local, top;
683 inline struct sockaddr *
get(void)
684 {
return (
struct sockaddr *)&local;}
686 void set(
const char *source,
char *target,
size_t len =
MAX_SDP_BUFFER);
687 char *
get(
char *buffer,
size_t len);
688 size_t put(
char *buffer);
691 void check_connect(
char *buffer,
size_t len);
692 void check_media(
char *buffer,
size_t len);
695 void reconnect(
void);
708 struct sockaddr_storage local, remote, peering;
715 void release(time_t expire = 0l);
716 void reconnect(
struct sockaddr *address);
730 static void enableIPV6(
void);
733 static void release(
LinkedObject **nat,
unsigned expires = 0);
749 static bool isProxied(
const char *source,
const char *target,
struct sockaddr_storage *peering);
759 history(shell::loglevel_t lid,
const char *msg);
761 void set(shell::loglevel_t lid,
const char *msg);
763 static void add(shell::loglevel_t lid,
const char *msg);
764 static void set(
unsigned size);
765 static void out(
void);
788 static void setup(
void);
789 static void start(
void);
790 static void stop(
void);
798 static void setup(
void);
799 static void start(
void);
800 static void stop(
void);
804 #ifdef HAVE_SYS_INOTIFY_H
818 static void start(
void);
819 static void stop(
void);
827 static void start(
void);
828 static void stop(
void);
linked_value< profile_t, LinkedObject > profile
Structure for SIP Message (REQUEST and RESPONSE).
static const char * sipusers
Some convenience methods for manipulating SIP uri's.
voip::proxyauth_t proxy_auth
static unsigned getRoutes(void)
static timeout_t ringTimeout(void)
registry::mapped * reginfo
const char *volatile trusted
Pointer to a provisioned user xml subtree.
User profiles are used to map features and toll restriction level together under a common identifier...
mapped * operator->() const
const char *volatile proxy
Structure for event description.
const char *volatile published
Representation of a mapped active user record.
service::keynode * routed
enum _state_t state_t
Enumeration for transaction state.
static unsigned inviteExpires(void)
static unsigned getRange(void)
service::usernode authorized
Server control interfaces and functions.
MappedRegistry * accepted
const char *volatile restricted
Top level include directory for GNU Telephony SIP Witch Server.
static background * thread
struct sockaddr * getInterface(void)
static const char * getRealm(void)
Representation of an active call record.
Callback methods for objects managed under the service thread.
Definition of the From header.
static timeout_t resetTimeout(void)
bool isSource(void) const
static const char * sipadmin
static shell::logmode_t logmode
destination_t destination
bool isTarget(void) const
static time_t getExpires(void)
Socket::address via_address
static const char * getDigest(void)
Definition of the Via header.
eXosip_event_type
Structure for event type description.
const char *volatile localnames
static timeout_t cfnaTimeout(void)
System configuration instance and service functions.
mapped * operator*() const
static unsigned getPrefix(void)
Interface class for call detail records.
Structure for referencing SIP urls.
voip::proxyauth_t www_auth
Definition of the WWW-Authenticate header.
struct sockaddr * address
treemap< char * > keynode
Definition of a xml node.