2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
5 * Subject to the GPL, version 2.
15 #include <sys/ioctl.h>
16 #include <sys/types.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
23 #define FILE_SETTINGS ".transsip/settings"
24 #define FILE_CONTACTS ".transsip/contacts"
25 #define FILE_PRIVKEY ".transsip/priv.key"
26 #define FILE_PUBKEY ".transsip/pub.key"
27 #define FILE_USERNAME ".transsip/username"
29 #define FILE_ETCDIR "/etc/transsip"
31 #define FILE_BUSY "busytone.s16"
32 #define FILE_RING "ring.s16"
33 #define FILE_DIAL "dialtone.s16"
44 __extension__
uint16_t ring
:1,
51 char address
[ADDRSIZ
];
53 } __attribute__((packed
));
55 extern int open_or_die(const char *file
, int flags
);
56 extern int open_or_die_m(const char *file
, int flags
, mode_t mode
);
57 extern ssize_t
read_or_die(int fd
, void *buf
, size_t count
);
58 extern ssize_t
write_or_die(int fd
, const void *buf
, size_t count
);
59 extern size_t strlcpy(char *dest
, const char *src
, size_t size
);
60 extern int slprintf(char *dst
, size_t size
, const char *fmt
, ...);
61 extern char **strntoargv(char *str
, size_t len
, int *argc
);
70 #define __magenta "35"
73 #define __on_black "40"
75 #define __on_green "42"
76 #define __on_yellow "43"
77 #define __on_blue "44"
78 #define __on_magenta "45"
79 #define __on_cyan "46"
80 #define __on_white "47"
82 #define colorize_start(fore) "\033[" __##fore "m"
83 #define colorize_start_full(fore, back) "\033[" __##fore ";" __on_##back "m"
84 #define colorize_end() "\033[" __reset "m"
86 #define colorize_str(fore, text) \
87 colorize_start(fore) text colorize_end()
88 #define colorize_full_str(fore, back, text) \
89 colorize_start_full(fore, back) text colorize_end()
91 static inline void register_signal(int signal
, void (*handler
)(int))
94 struct sigaction saction
;
95 sigfillset(&block_mask
);
96 saction
.sa_handler
= handler
;
97 saction
.sa_mask
= block_mask
;
98 saction
.sa_flags
= SA_RESTART
;
99 sigaction(signal
, &saction
, NULL
);
102 static inline int set_timeout(struct timeval
*timeval
, unsigned int msec
)
108 timeval
->tv_usec
= 0;
111 timeval
->tv_usec
= msec
* 1000;
115 timeval
->tv_sec
= (long) (msec
/ 1000);
116 timeval
->tv_usec
= (long) ((msec
- (timeval
->tv_sec
* 1000)) * 1000);
121 #endif /* XUTILS_H */