37 #include <arpa/inet.h>
38 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
40 #include <sys/resource.h>
44 #define ESCAPE_META '\\'
68 return inet_pton(af, src, dst);
79 snprintf(buf + strlen(buf), len - strlen(buf),
":%d", port);
90 new_frame->
buflen = (uint32_t)size;
91 new_frame->
data = malloc(size);
121 for (np = fb->
head; np; np = np->
next) {
126 if (np == fb->
head) {
128 }
else if (np->
prev) {
210 fb->head->prev = node;
213 node->
next = fb->head;
279 new_frame = malloc(
sizeof(*new_frame));
287 memcpy(new_frame->
packet, orig->packet, orig->packetlen);
288 new_frame->
data = ((
unsigned char *)new_frame->
packet) + 12;
293 memcpy(new_frame->
data, orig->data, orig->datalen);
297 new_frame->
codec = NULL;
298 new_frame->
pmap = NULL;
299 new_frame->
img = NULL;
342 const char *next_str = 0;
347 while ((next_str = va_arg(ap,
const char *))) {
348 if (!strcasecmp(str, next_str)) {
362 char *e, *r = NULL, *ptr = NULL, *next = NULL;
370 next = strchr(ptr,
';');
372 if (!strncasecmp(ptr, param, len) && *e ==
'=') {
380 e = ptr + strlen(ptr);
383 mlen = (e - ptr) + 1;
423 #define IN6_AND_MASK(result, ip, mask) \
424 ((uint32_t *) (result))[0] =((const uint32_t *) (ip))[0] & ((const uint32_t *)(mask))[0]; \
425 ((uint32_t *) (result))[1] =((const uint32_t *) (ip))[1] & ((const uint32_t *)(mask))[1]; \
426 ((uint32_t *) (result))[2] =((const uint32_t *) (ip))[2] & ((const uint32_t *)(mask))[2]; \
427 ((uint32_t *) (result))[3] =((const uint32_t *) (ip))[3] & ((const uint32_t *)(mask))[3];
429 if (!IN6_IS_ADDR_UNSPECIFIED(&_mask.v6)) {
430 struct in6_addr a, b;
433 return !memcmp(&a,&b,
sizeof(
struct in6_addr));
435 if (!IN6_IS_ADDR_UNSPECIFIED(&_net.v6)) {
436 return !memcmp(&_net,&_ip,
sizeof(
struct in6_addr));
447 for (node = list->node_head; node; node = node->
next) {
448 if (node->
family == AF_INET)
continue;
460 *token = node->
token;
474 for (node = list->node_head; node; node = node->
next) {
475 if (node->
family == AF_INET6)
continue;
486 *token = node->
token;
498 if (strncasecmp(ip_str,
"::ffff:", 7)) {
502 return strdup(ip_str + 7);
519 cidr_str, ok ?
"allow" :
"deny",
switch_str_nil(token), list->name);
532 if (strchr(cidr_str,
':')) {
542 node->
next = list->node_head;
543 list->node_head = node;
546 cidr_str, ok ?
"allow" :
"deny",
switch_str_nil(token), list->name);
554 char *cidr_str_dup = NULL;
557 if (strchr(cidr_str,
',')) {
558 char *argv[32] = { 0 };
560 cidr_str_dup = strdup(cidr_str);
564 for (i = 0; i < argc; i++) {
567 status = this_status;
589 node->
ip.
v4 = ntohl(ip.
v4);
594 mask.
v4 = mask.
v4 - ((mask.
v4 >> 1) & 0x55555555);
595 mask.
v4 = (mask.
v4 & 0x33333333) + ((mask.
v4 >> 2) & 0x33333333);
596 node->
bits = (((mask.
v4 + (mask.
v4 >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
600 node->
next = list->node_head;
601 list->node_head = node;
617 bit_str = strchr(host,
'/');
624 bits = atoi(bit_str);
625 ipv6 = strchr(
string,
':');
628 if (bits < 0 || bits > 128) {
631 bits = atoi(bit_str);
633 for (n=bits,i=0 ;i < 16; i++){
635 maskv->
v6.s6_addr[i] = 0xFF;
638 maskv->
v6.s6_addr[i] = 0xFF & ~(0xFF >> n);
641 maskv->
v6.s6_addr[i] = 0x00;
645 if (bits < 0 || bits > 32) {
649 bits = atoi(bit_str);
651 ipv->
v4 = htonl(ipv->
v4);
653 maskv->
v4 = 0xFFFFFFFF & ~(0xFFFFFFFF >> bits);
663 const char *e = NULL;
666 while (s && *s && *s ==
' ') {
670 if (s && *s == open) {
672 for (e = s + 1; e && *e; e++) {
673 if (*e == open && open != close) {
675 }
else if (*e == close) {
684 return (e && *e == close) ? (
char *) e : NULL;
694 while (total + 2 < len && (cur = read(fd, &c, 1)) == 1) {
697 if (c ==
'\r' || c ==
'\n') {
707 #define DLINE_BLOCK_SIZE 1024
708 #define DLINE_MAX_SIZE 1048576
724 while ((cur = read(fd, &c, 1)) == 1) {
726 if (total + 2 >= ilen) {
733 data = realloc(data, ilen);
742 if (c ==
'\r' || c ==
'\n') {
773 while (fread(&c, 1, 1, fd) == 1) {
775 if (total + 2 >= ilen) {
782 data = realloc(data, ilen);
791 if (c ==
'\r' || c ==
'\n') {
812 for (p = s; x < len; p++) {
816 if (x + 6 > len - 1) {
828 if (x + 6 > len - 1) {
840 if (x + 5 > len - 1) {
851 if (x + 4 > len - 1) {
861 if (x + 4 > len - 1) {
871 if (x + 1 > len - 1) {
888 static const char switch_b64_table[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
889 #define B64BUFFLEN 1024
892 int y = 0, bytes = 0;
894 unsigned int b = 0, l = 0;
896 for (x = 0; x < ilen; x++) {
897 b = (b << 8) + in[x];
902 if (bytes >= (
int)olen - 1) {
917 while (l < 6 && bytes < (
int)olen - 1) {
918 out[bytes++] =
'=', l += 2;
933 int b = 0, c, l = 0, i;
937 for (i = 0; i < 256; i++) {
941 for (i = 0; i < 64; i++) {
945 for (ip = in; ip && *ip; ip++) {
955 op[ol++] = (char) ((b >> (l -= 8)) % 256);
956 if (ol >= olen - 2) {
972 int len = (int) strlen(buf);
973 if (fd && write(fd, buf, len) != len) {
984 const
char *body, const
char *file, const
char *convert_cmd, const
char *convert_ext)
986 char *bound =
"XXXX_boundary_XXXX";
987 const char *mime_type =
"audio/inline";
989 int fd = -1, ifd = -1;
990 int x = 0, y = 0, bytes = 0, ilen = 0;
991 unsigned int b = 0, l = 0;
994 char *dupfile = NULL, *ext = NULL;
995 char *newfile = NULL;
997 const char *err = NULL;
1000 err =
"No to address specified";
1004 if (!
zstr(file) && !
zstr(convert_cmd) && !
zstr(convert_ext)) {
1005 if ((ext = strrchr(file,
'.'))) {
1006 dupfile = strdup(file);
1007 if ((ext = strrchr(dupfile,
'.'))) {
1014 char cmd[1024] =
"";
1015 switch_snprintf(cmd,
sizeof(cmd),
"%s %s %s", convert_cmd, file, newfile);
1017 if (strcmp(file, newfile)) {
1029 if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) > -1) {
1031 if ((ifd = open(file, O_RDONLY |
O_BINARY)) < 0) {
1033 err =
"Cannot open tmp file\n";
1046 err =
"write error.";
1051 if (headers && !
write_buf(fd, headers)) {
1053 err =
"write error.";
1059 err =
"write error.";
1071 err =
"write error.";
1079 err =
"write error.";
1084 if (file && bound) {
1086 const char *new_type;
1089 if ((ext = strrchr(stipped_file,
'.'))) {
1092 mime_type = new_type;
1097 "\n\n--%s\nContent-Type: %s; name=\"%s\"\n"
1098 "Content-ID: <ATTACHED@freeswitch.org>\n"
1099 "Content-Transfer-Encoding: base64\n"
1100 "Content-Description: Sound attachment.\n"
1101 "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
1104 err =
"write error.";
1109 for (x = 0; x < ilen; x++) {
1110 b = (b << 8) + in[x];
1116 out[bytes++] =
'\n';
1120 if (write(fd, &out, bytes) != bytes) {
1134 out[bytes++] =
'=', l += 2;
1136 if (write(fd, &out, bytes) != bytes) {
1147 err =
"write error.";
1159 from =
"freeswitch";
1174 err =
"execute error";
1194 if (unlink(filename) != 0) {
1209 if (
zstr(err)) err =
"Unknown Error";
1222 return (strncmp(ip,
"10.", 3) &&
1223 strncmp(ip,
"192.168.", 8) &&
1224 strncmp(ip,
"127.", 4) &&
1225 strncmp(ip,
"255.", 4) &&
1226 strncmp(ip,
"0.", 2) &&
1227 strncmp(ip,
"1.", 2) &&
1228 strncmp(ip,
"2.", 2) &&
1229 strncmp(ip,
"172.16.", 7) &&
1230 strncmp(ip,
"172.17.", 7) &&
1231 strncmp(ip,
"172.18.", 7) &&
1232 strncmp(ip,
"172.19.", 7) &&
1233 strncmp(ip,
"172.20.", 7) &&
1234 strncmp(ip,
"172.21.", 7) &&
1235 strncmp(ip,
"172.22.", 7) &&
1236 strncmp(ip,
"172.23.", 7) &&
1237 strncmp(ip,
"172.24.", 7) &&
1238 strncmp(ip,
"172.25.", 7) &&
1239 strncmp(ip,
"172.26.", 7) &&
1240 strncmp(ip,
"172.27.", 7) &&
1241 strncmp(ip,
"172.28.", 7) &&
1242 strncmp(ip,
"172.29.", 7) &&
1243 strncmp(ip,
"172.30.", 7) &&
1244 strncmp(ip,
"172.31.", 7) &&
1245 strncmp(ip,
"192.0.2.", 8) &&
1246 strncmp(ip,
"169.254.", 8)
1252 const char *p = pat;
1260 *(rbuf + strlen(rbuf)) =
'^';
1264 strncat(rbuf,
"[2-9]", len - strlen(rbuf));
1265 }
else if (*p ==
'X') {
1266 strncat(rbuf,
"[0-9]", len - strlen(rbuf));
1267 }
else if (*p ==
'Z') {
1268 strncat(rbuf,
"[1-9]", len - strlen(rbuf));
1269 }
else if (*p ==
'.') {
1270 strncat(rbuf,
".*", len - strlen(rbuf));
1271 }
else if (strlen(rbuf) < len - 1) {
1272 *(rbuf + strlen(rbuf)) = *p;
1276 *(rbuf + strlen(rbuf)) =
'$';
1292 for (; p && *p; p++) {
1303 const char *sp = str;
1311 while ((*sp == 13 ) || (*sp == 10 ) || (*sp == 9 ) || (*sp == 32) || (*sp == 11) ) {
1322 if ((len = strlen(s)) > 0) {
1325 while ((p >= s) && ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11))) {
1343 while (*sp ==
' ') {
1358 if ((len = strlen(s)) > 0) {
1361 while (p && *p && (p >= s) && *p ==
' ') {
1371 char *p =
in, *q = out;
1375 for (; p && *p; p++) {
1376 if ((*p > 47 && *p < 58)) {
1378 }
else if (*p !=
',') {
1394 char *p =
in, *q = out;
1398 for (; p && *p; p++) {
1399 if ((*p > 47 && *p < 58) || *p ==
'.' || *p ==
'-' || *p ==
'+') {
1417 if ((args = strchr(str,
'('))) {
1428 }
else if (br > 1 && *e ==
')') {
1430 }
else if (br == 1 && *e ==
')') {
1446 if (*str ==
'-' || *str ==
'+') {
1450 for (p = str; p && *p; p++) {
1451 if (!(*p ==
'.' || (*p > 47 && *p < 58))) {
1465 if (*str ==
'-' || *str ==
'+') {
1469 for (p = str; p && *p; p++) {
1470 if ((*p ==
'.' || (*p > 47 && *p < 58))) {
1489 const char *pptr, *sptr, *start;
1494 for (start = str; *start; start++) {
1519 #ifdef HAVE_GETIFADDRS
1520 #include <ifaddrs.h>
1521 static int get_netmask(
struct sockaddr_in *me,
int *mask)
1523 struct ifaddrs *ifaddrs, *i = NULL;
1525 if (!me || getifaddrs(&ifaddrs) < 0) {
1529 for (i = ifaddrs; i; i = i->ifa_next) {
1530 struct sockaddr_in *s = (
struct sockaddr_in *) i->ifa_addr;
1531 struct sockaddr_in *m = (
struct sockaddr_in *) i->ifa_netmask;
1533 if (s && m && s->sin_family == AF_INET && s->sin_addr.s_addr == me->sin_addr.s_addr) {
1534 *mask = m->sin_addr.s_addr;
1535 freeifaddrs(ifaddrs);
1540 freeifaddrs(ifaddrs);
1544 #elif defined(__linux__)
1546 #include <sys/ioctl.h>
1548 static int get_netmask(
struct sockaddr_in *me,
int *mask)
1551 static struct ifreq ifreqs[20] = { {{{0}}} };
1552 struct ifconf ifconf;
1557 memset(&ifconf, 0,
sizeof(ifconf));
1558 ifconf.ifc_buf = (
char *) (ifreqs);
1559 ifconf.ifc_len =
sizeof(ifreqs);
1562 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
1566 if (ioctl(sock, SIOCGIFCONF, (
char *) &ifconf) < 0) {
1570 nifaces = ifconf.ifc_len /
sizeof(
struct ifreq);
1572 for (i = 0; i < nifaces; i++) {
1573 struct sockaddr_in *sin = NULL;
1576 ioctl(sock, SIOCGIFADDR, &ifreqs[i]);
1577 sin = (
struct sockaddr_in *) &ifreqs[i].ifr_addr;
1580 if (ip.s_addr == me->sin_addr.s_addr) {
1581 ioctl(sock, SIOCGIFNETMASK, &ifreqs[i]);
1582 sin = (
struct sockaddr_in *) &ifreqs[i].ifr_addr;
1584 *mask = sin->sin_addr.s_addr;
1598 #elif defined(WIN32)
1600 static int get_netmask(
struct sockaddr_in *me,
int *mask)
1602 SOCKET sock = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
1603 INTERFACE_INFO interfaces[20];
1604 unsigned long bytes;
1605 int interface_count, x;
1610 if (sock == SOCKET_ERROR) {
1614 if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, 0, 0, &interfaces,
sizeof(interfaces), &bytes, 0, 0) == SOCKET_ERROR) {
1619 interface_count = bytes /
sizeof(INTERFACE_INFO);
1621 for (x = 0; x < interface_count; ++x) {
1622 struct sockaddr_in *addr = (
struct sockaddr_in *) &(interfaces[x].iiAddress);
1624 if (addr->sin_addr.s_addr == me->sin_addr.s_addr) {
1625 struct sockaddr_in *netmask = (
struct sockaddr_in *) &(interfaces[x].iiNetmask);
1626 *mask = netmask->sin_addr.s_addr;
1650 struct addrinfo *ai;
1653 if ((err = getaddrinfo(host, 0, 0, &ai))) {
1657 get_addr(buf, buflen, ai->ai_addr,
sizeof(*ai->ai_addr));
1674 SOCKADDR_STORAGE l_address;
1676 struct addrinfo *address_info;
1683 int tmp_socket = -1, on = 1;
1689 if (force_local_ip_v4) {
1696 if (force_local_ip_v6) {
1716 base =
"82.45.148.209";
1720 base =
"2001:503:BA3E::2:30";
1728 tmp_socket = socket(family, SOCK_DGRAM, 0);
1730 getaddrinfo(base, NULL, NULL, &address_info);
1732 if (!address_info || WSAIoctl(tmp_socket,
1733 SIO_ROUTING_INTERFACE_QUERY,
1734 address_info->ai_addr, (DWORD) address_info->ai_addrlen, &l_address,
sizeof(l_address), (LPDWORD) & l_address_len, NULL,
1737 closesocket(tmp_socket);
1739 freeaddrinfo(address_info);
1744 closesocket(tmp_socket);
1745 freeaddrinfo(address_info);
1747 if (!getnameinfo((
const struct sockaddr *) &l_address, l_address_len, buf, len, NULL, 0, NI_NUMERICHOST)) {
1750 get_netmask((
struct sockaddr_in *) &l_address, mask);
1758 struct sockaddr_in iface_out;
1759 struct sockaddr_in remote;
1760 memset(&remote, 0,
sizeof(
struct sockaddr_in));
1762 remote.sin_family = AF_INET;
1763 remote.sin_addr.s_addr = inet_addr(base);
1764 remote.sin_port = htons(4242);
1766 memset(&iface_out, 0,
sizeof(iface_out));
1767 if ( (tmp_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1 ) {
1771 if (setsockopt(tmp_socket, SOL_SOCKET, SO_BROADCAST, &on,
sizeof(on)) == -1) {
1775 if (connect(tmp_socket, (
struct sockaddr *) &remote,
sizeof(
struct sockaddr_in)) == -1) {
1779 ilen =
sizeof(iface_out);
1780 if (getsockname(tmp_socket, (
struct sockaddr *) &iface_out, &ilen) == -1) {
1784 if (iface_out.sin_addr.s_addr == 0) {
1790 get_netmask((
struct sockaddr_in *) &iface_out, mask);
1798 struct sockaddr_in6 iface_out;
1799 struct sockaddr_in6 remote;
1800 memset(&remote, 0,
sizeof(
struct sockaddr_in6));
1802 remote.sin6_family = AF_INET6;
1804 remote.sin6_port = htons(4242);
1806 memset(&iface_out, 0,
sizeof(iface_out));
1807 if ( (tmp_socket = socket(AF_INET6, SOCK_DGRAM, 0)) == -1 ) {
1811 if (connect(tmp_socket, (
struct sockaddr *) &remote,
sizeof(remote)) == -1) {
1815 ilen =
sizeof(iface_out);
1816 if (getsockname(tmp_socket, (
struct sockaddr *) &iface_out, &ilen) == -1) {
1820 inet_ntop(AF_INET6, (
const void *) &iface_out.sin6_addr, buf, len - 1);
1827 if (tmp_socket > 0) {
1835 #ifdef HAVE_GETIFADDRS
1836 # include <ifaddrs.h>
1837 # include <net/if.h>
1843 #ifdef HAVE_GETIFADDRS
1845 struct ifaddrs *addrs, *addr;
1848 for(addr = addrs; addr; addr = addr->ifa_next)
1850 if (!(addr->ifa_flags & IFF_UP))
continue;
1851 if (!addr->ifa_addr)
continue;
1852 if (!addr->ifa_netmask)
continue;
1853 if (family != AF_UNSPEC && addr->ifa_addr->sa_family != family)
continue;
1854 if (strcmp(addr->ifa_name, ifname))
continue;
1856 switch(addr->ifa_addr->sa_family) {
1858 inet_ntop(AF_INET, &( ((
struct sockaddr_in*)(addr->ifa_addr))->sin_addr ), buf, len - 1);
1861 inet_ntop(AF_INET6, &( ((
struct sockaddr_in6*)(addr->ifa_addr))->sin6_addr ), buf, len - 1);
1867 if (mask && addr->ifa_netmask->sa_family == AF_INET) {
1868 *mask = ((
struct sockaddr_in*)(addr->ifa_addr))->sin_addr.s_addr;
1876 #elif defined(__linux__)
1880 #elif defined(WIN32)
1893 int proceed = 0, ovector[30];
1895 char replace[1024] =
"";
1897 char *pattern =
"^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
1898 char *pattern2 =
"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})";
1903 if (!(proceed =
switch_regex_perform(in, pattern, &re, ovector,
sizeof(ovector) /
sizeof(ovector[0])))) {
1905 proceed =
switch_regex_perform(in, pattern2, &re, ovector,
sizeof(ovector) /
sizeof(ovector[0]));
1912 tm.
tm_year = atoi(replace) - 1900;
1917 tm.
tm_mon = atoi(replace) - 1;
1932 tm.
tm_min = atoi(replace);
1937 tm.
tm_sec = atoi(replace);
1995 #include <sys/types.h>
2002 static const char *switch_inet_ntop4(
const unsigned char *src,
char *dst,
size_t size);
2004 static const char *switch_inet_ntop6(
const unsigned char *src,
char *dst,
size_t size);
2020 return switch_inet_ntop4(src, dst, size);
2023 return switch_inet_ntop6(src, dst, size);
2042 static const char *switch_inet_ntop4(
const unsigned char *src,
char *dst,
size_t size)
2044 static const char fmt[] =
"%u.%u.%u.%u";
2045 char tmp[
sizeof "255.255.255.255"];
2047 if (
switch_snprintf(tmp,
sizeof tmp, fmt, src[0], src[1], src[2], src[3]) >= (
int) size) {
2051 return strcpy(dst, tmp);
2054 #if HAVE_SIN6 || defined(NTDDI_VERSION)
2061 static const char *switch_inet_ntop6(
unsigned char const *src,
char *dst,
size_t size)
2070 char tmp[
sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
2076 unsigned int words[8];
2084 for (i = 0; i < 16; i += 2)
2085 words[i / 2] = (src[i] << 8) | (src[i + 1]);
2088 for (i = 0; i < 8; i++) {
2089 if (words[i] == 0) {
2091 cur.base = i,
cur.len = 1;
2095 if (
cur.base != -1) {
2096 if (best.base == -1 ||
cur.len > best.len)
2102 if (
cur.base != -1) {
2103 if (best.base == -1 ||
cur.len > best.len)
2106 if (best.base != -1 && best.len < 2)
2113 for (i = 0; i < 8; i++) {
2115 if (best.base != -1 && i >= best.base && i < (best.base + best.len)) {
2124 if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
2125 if (!switch_inet_ntop4(src + 12, tp,
sizeof tmp - (tp - tmp)))
2130 tp += sprintf(tp,
"%x", words[i]);
2133 if (best.base != -1 && (best.base + best.len) == 8)
2140 if ((
size_t) (tp - tmp) >= size) {
2144 return strcpy(dst, tmp);
2152 struct sockaddr_in *s = (
struct sockaddr_in *) &sa->sa;
2154 return ntohs((
unsigned short) s->sin_addr.s_addr);
2159 struct sockaddr_in *s1;
2160 struct sockaddr_in *s2;
2162 struct sockaddr_in6 *s16;
2163 struct sockaddr_in6 *s26;
2165 struct sockaddr *ss1;
2166 struct sockaddr *ss2;
2171 s1 = (
struct sockaddr_in *) &sa1->sa;
2172 s2 = (
struct sockaddr_in *) &sa2->sa;
2174 s16 = (
struct sockaddr_in6 *) &sa1->sa;
2175 s26 = (
struct sockaddr_in6 *) &sa2->sa;
2177 ss1 = (
struct sockaddr *) &sa1->sa;
2178 ss2 = (
struct sockaddr *) &sa2->sa;
2180 if (ss1->sa_family != ss2->sa_family)
2183 switch (ss1->sa_family) {
2185 return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port);
2187 if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) {
2190 if (s16->sin6_port != s26->sin6_port)
2193 for (i = 0; i < 4; i++) {
2194 if (*((int32_t *) s16->sin6_addr.s6_addr + i) != *((int32_t *) s26->sin6_addr.s6_addr + i))
2208 struct sockaddr_in *s1;
2209 struct sockaddr_in *s2;
2211 struct sockaddr_in6 *s16;
2212 struct sockaddr_in6 *s26;
2214 struct sockaddr *ss1;
2220 s1 = (
struct sockaddr_in *) &sa1->sa;
2221 s2 = (
struct sockaddr_in *) &sa2->sa;
2223 s16 = (
struct sockaddr_in6 *) &sa1->sa;
2224 s26 = (
struct sockaddr_in6 *) &sa2->sa;
2226 ss1 = (
struct sockaddr *) &sa1->sa;
2229 sa1->port = sa2->port;
2230 sa1->family = sa2->family;
2232 sa1->sa.sin.sin_family = sa2->family;
2234 switch (ss1->sa_family) {
2236 s1->sin_addr.s_addr = s2->sin_addr.s_addr;
2237 s1->sin_port = s2->sin_port;
2241 if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) {
2244 s16->sin6_port = s26->sin6_port;
2246 for (i = 0; i < 4; i++) {
2247 *((int32_t *) s16->sin6_addr.s6_addr + i) = *((int32_t *) s26->sin6_addr.s6_addr + i);
2263 #if defined(NTDDI_VERSION)
2264 switch_inet_ntop6((
unsigned char*)&(sa->sin6_addr), buf, len);
2266 inet_ntop(AF_INET6, &(sa->sin6_addr), buf, len);
2279 getnameinfo(sa, salen, buf, (socklen_t) len, NULL, 0, NI_NUMERICHOST);
2286 unsigned short port = 0;
2288 switch (sa->sa_family) {
2290 port = ntohs(((
struct sockaddr_in *) sa)->sin_port);
2293 port = ntohs(((
struct sockaddr_in6 *) sa)->sin6_port);
2302 char host[NI_MAXHOST], serv[NI_MAXSERV];
2303 struct sockaddr_in6 si6;
2304 const struct sockaddr *addr;
2308 memcpy(&si6, &sa->sa, sa->salen);
2309 si6.sin6_scope_id = 0;
2311 addr = (
const struct sockaddr *) &si6;
2313 addr = (
const struct sockaddr *) (intptr_t) & sa->sa;
2316 if (getnameinfo(addr, sa->salen, host,
sizeof(host), serv,
sizeof(serv),
2321 colon = strchr(host,
':');
2324 user ? user :
"", user ?
"@" :
"", colon ?
"[" :
"", host, colon ?
"]" :
"", serv[0] ?
":" :
"", serv[0] ? serv :
"");
2329 if (event > -1 && event < (int32_t)
sizeof(RFC2833_CHARS)) {
2330 return RFC2833_CHARS[event];
2338 unsigned char counter = 0;
2341 for (c = RFC2833_CHARS; *c; c++) {
2354 int count = 1, i = 0;
2416 unescaped = escaped;
2426 for (p = in; *p; p++) {
2461 size_t len = strlen(in) * 2 + 1;
2474 int inside_quotes = 0;
2477 for (ptr = str; *ptr ==
' '; ++ptr) {
2480 for (start = dest = ptr; *ptr; ++ptr) {
2486 if (e ==
'\'' || e ==
'"' || (delim && e == delim) || e ==
ESCAPE_META || (e =
unescape_char(*(ptr + 1))) != *(ptr + 1)) {
2494 if (*ptr ==
'\'' && (inside_quotes || ((ptr+1) && strchr(ptr+1,
'\'')))) {
2495 if ((inside_quotes = (1 - inside_quotes))) {
2500 if (*ptr !=
' ' || inside_quotes) {
2515 unsigned int count = 0;
2517 size_t dlen = strlen(delim);
2519 array[count++] =
buf;
2521 while (count < arraylen && array[count - 1]) {
2522 if ((d = strstr(array[count - 1], delim))) {
2536 enum tokenizer_state {
2541 unsigned int count = 0;
2543 int inside_quotes = 0;
2546 while (*ptr && count < arraylen) {
2549 array[count++] = ptr;
2557 }
else if (*ptr ==
'\'' && (inside_quotes || ((ptr+1) && strchr(ptr+1,
'\'')))) {
2558 inside_quotes = (1 - inside_quotes);
2559 }
else if (*ptr == delim && !inside_quotes) {
2569 for (i = 0; i < count; ++i) {
2579 enum tokenizer_state {
2586 unsigned int count = 0;
2588 int inside_quotes = 0;
2591 while (*ptr && count < arraylen) {
2594 array[count++] = ptr;
2595 state = SKIP_INITIAL_SPACE;
2598 case SKIP_INITIAL_SPACE:
2609 }
else if (*ptr ==
'\'') {
2610 inside_quotes = (1 - inside_quotes);
2611 }
else if (*ptr ==
' ' && !inside_quotes) {
2613 state = SKIP_ENDING_SPACE;
2618 case SKIP_ENDING_SPACE:
2629 for (i = 0; i < count; ++i) {
2638 if (!buf || !array || !arraylen) {
2643 if (*buf ==
'^' && *(buf+1) ==
'^') {
2646 if (p && *p && *(p+1)) {
2653 memset(array, 0, arraylen *
sizeof(*array));
2660 const char *p, *ret =
in;
2661 const char delims[] =
"/\\";
2665 for (i = delims; *i; i++) {
2667 while ((p = strchr(p, *i)) != 0) {
2681 for (i = 0; (i < search_len) && (i < string_len); i++) {
2682 if (
string[i] != search[i]) {
2687 if (i == search_len) {
2696 size_t string_len = strlen(
string);
2697 size_t search_len = strlen(search);
2698 size_t replace_len = strlen(replace);
2700 size_t dest_len = 0;
2703 dest = (
char *) malloc(
sizeof(
char));
2706 for (i = 0; i < string_len; i++) {
2708 for (n = 0; n < replace_len; n++) {
2709 dest[dest_len] = replace[n];
2711 tmp = (
char *) realloc(dest,
sizeof(
char) * (dest_len + 1));
2715 i += search_len - 1;
2717 dest[dest_len] =
string[i];
2719 tmp = (
char *) realloc(dest,
sizeof(
char) * (dest_len + 1));
2736 size_t string_len = strlen(
string);
2739 size_t dest_len = 0;
2743 dest_len = strlen(
string) + 1;
2745 for (i = 0; i < string_len; i++) {
2746 switch (
string[i]) {
2761 dest = (
char *) malloc(
sizeof(
char) * dest_len);
2771 for (i = 0; i < string_len; i++) {
2772 switch (
string[i]) {
2788 dest[n++] =
string[i];
2808 struct pollfd pfds[2] = { { 0 } };
2819 pfds[0].events |= POLLIN;
2823 pfds[0].events |= POLLOUT;
2827 pfds[0].events |= POLLERR;
2831 pfds[0].events |= POLLHUP;
2835 pfds[0].events |= POLLRDNORM;
2839 pfds[0].events |= POLLRDBAND;
2843 pfds[0].events |= POLLPRI;
2846 s = poll(pfds, 1, ms);
2857 if ((pfds[0].revents & POLLIN)) {
2860 if ((pfds[0].revents & POLLOUT)) {
2863 if ((pfds[0].revents & POLLERR)) {
2866 if ((pfds[0].revents & POLLHUP)) {
2869 if ((pfds[0].revents & POLLRDNORM)) {
2872 if ((pfds[0].revents & POLLRDBAND)) {
2875 if ((pfds[0].revents & POLLPRI)) {
2878 if ((pfds[0].revents & POLLNVAL)) {
2889 struct pollfd *pfds;
2890 int s = 0, r = 0, i;
2892 pfds = calloc(len,
sizeof(
struct pollfd));
2894 for (i = 0; i < len; i++) {
2899 pfds[i].fd = waitlist[i].sock;
2901 if ((waitlist[i].events & SWITCH_POLL_READ)) {
2902 pfds[i].events |= POLLIN;
2905 if ((waitlist[i].events & SWITCH_POLL_WRITE)) {
2906 pfds[i].events |= POLLOUT;
2909 if ((waitlist[i].events & SWITCH_POLL_ERROR)) {
2910 pfds[i].events |= POLLERR;
2913 if ((waitlist[i].events & SWITCH_POLL_HUP)) {
2914 pfds[i].events |= POLLHUP;
2917 if ((waitlist[i].events & SWITCH_POLL_RDNORM)) {
2918 pfds[i].events |= POLLRDNORM;
2921 if ((waitlist[i].events & SWITCH_POLL_RDBAND)) {
2922 pfds[i].events |= POLLRDBAND;
2925 if ((waitlist[i].events & SWITCH_POLL_PRI)) {
2926 pfds[i].events |= POLLPRI;
2930 s = poll(pfds, len, ms);
2941 for (i = 0; i < len; i++) {
2942 if ((pfds[i].revents & POLLIN)) {
2946 if ((pfds[i].revents & POLLOUT)) {
2950 if ((pfds[i].revents & POLLERR)) {
2954 if ((pfds[i].revents & POLLHUP)) {
2958 if ((pfds[i].revents & POLLRDNORM)) {
2962 if ((pfds[i].revents & POLLRDBAND)) {
2966 if ((pfds[i].revents & POLLPRI)) {
2970 if ((pfds[i].revents & POLLNVAL)) {
2997 rfds = malloc(
sizeof(fd_set));
2998 wfds = malloc(
sizeof(fd_set));
2999 efds = malloc(
sizeof(fd_set));
3007 assert(sock <= FD_SETSIZE);
3010 if ((flags & SWITCH_POLL_READ)) {
3013 #pragma warning( push )
3014 #pragma warning( disable : 4127 )
3016 #pragma warning( pop )
3022 if ((flags & SWITCH_POLL_WRITE)) {
3025 #pragma warning( push )
3026 #pragma warning( disable : 4127 )
3028 #pragma warning( pop )
3034 if ((flags & SWITCH_POLL_ERROR)) {
3037 #pragma warning( push )
3038 #pragma warning( disable : 4127 )
3040 #pragma warning( pop )
3046 tv.tv_sec = ms / 1000;
3047 tv.tv_usec = (ms % 1000) * ms;
3049 s = select(sock + 1, (flags & SWITCH_POLL_READ) ? rfds : NULL, (flags & SWITCH_POLL_WRITE) ? wfds : NULL, (flags & SWITCH_POLL_ERROR) ? efds : NULL, &tv);
3060 if ((flags & SWITCH_POLL_READ) && FD_ISSET(sock, rfds)) {
3064 if ((flags & SWITCH_POLL_WRITE) && FD_ISSET(sock, wfds)) {
3068 if ((flags & SWITCH_POLL_ERROR) && FD_ISSET(sock, efds)) {
3092 rfds = malloc(
sizeof(fd_set));
3093 wfds = malloc(
sizeof(fd_set));
3094 efds = malloc(
sizeof(fd_set));
3100 for (i = 0; i < len; i++) {
3105 if (waitlist[i].sock > max_fd) {
3106 max_fd = waitlist[i].sock;
3111 assert(waitlist[i].sock <= FD_SETSIZE);
3113 flags |= waitlist[i].events;
3115 if ((waitlist[i].events & SWITCH_POLL_READ)) {
3118 #pragma warning( push )
3119 #pragma warning( disable : 4127 )
3120 FD_SET(waitlist[i].sock, rfds);
3121 #pragma warning( pop )
3123 FD_SET(waitlist[i].sock, rfds);
3127 if ((waitlist[i].events & SWITCH_POLL_WRITE)) {
3130 #pragma warning( push )
3131 #pragma warning( disable : 4127 )
3132 FD_SET(waitlist[i].sock, wfds);
3133 #pragma warning( pop )
3135 FD_SET(waitlist[i].sock, wfds);
3139 if ((waitlist[i].events & SWITCH_POLL_ERROR)) {
3142 #pragma warning( push )
3143 #pragma warning( disable : 4127 )
3144 FD_SET(waitlist[i].sock, efds);
3145 #pragma warning( pop )
3147 FD_SET(waitlist[i].sock, efds);
3152 tv.tv_sec = ms / 1000;
3153 tv.tv_usec = (ms % 1000) * ms;
3155 s = select(max_fd + 1, (flags & SWITCH_POLL_READ) ? rfds : NULL, (flags & SWITCH_POLL_WRITE) ? wfds : NULL, (flags & SWITCH_POLL_ERROR) ? efds : NULL, &tv);
3166 for (i = 0; i < len; i++) {
3167 if ((waitlist[i].events & SWITCH_POLL_READ) && FD_ISSET(waitlist[i].sock, rfds)) {
3172 if ((waitlist[i].events & SWITCH_POLL_WRITE) && FD_ISSET(waitlist[i].sock, wfds)) {
3177 if ((waitlist[i].events & SWITCH_POLL_ERROR) && FD_ISSET(waitlist[i].sock, efds)) {
3206 const char hex[] =
"0123456789ABCDEF";
3218 for (p = url; *p; p++) {
3225 if (!double_encode && *p ==
'%' && e-p > 1) {
3226 if (strchr(hex, *(p+1)) && strchr(hex, *(p+2))) {
3232 if ((x + 3) > len) {
3236 buf[x++] = hex[(*p >> 4) & 0x0f];
3237 buf[x++] = hex[*p & 0x0f];
3261 for (o = s; *s; s++, o++) {
3262 if (*s ==
'%' && strlen(s) > 2 && sscanf(s + 1,
"%2x", &tmp) == 1) {
3275 char *dup = strdup(exp);
3283 if ((smin=strchr(dup,
':'))) {
3285 if ((ssec=strchr(smin,
':'))) {
3290 if (hour && shour) {
3291 *hour = atol(shour);
3308 char *dup = strdup(exp);
3310 char *smonth = NULL;
3316 if ((smonth=strchr(dup,
'-'))) {
3318 if ((sday=strchr(smonth,
'-'))) {
3320 if (year && syear) {
3321 *year = atol(syear);
3323 if (month && smonth) {
3324 *month = atol(smonth);
3339 char *dup = strdup(exp);
3348 if ((p = strchr(cur,
','))) {
3354 if ((sEnd=strchr(cur,
'~'))) {
3355 char *sDate = sStart;
3358 if ((sTime=strchr(sStart,
' '))) {
3361 int year = 1970, month = 1, day = 1;
3362 int hour = 0, min = 0, sec = 0;
3365 memset(&tmTmp, 0,
sizeof(tmTmp));
3368 tmTmp.tm_year = year-1900;
3369 tmTmp.tm_mon = month-1;
3370 tmTmp.tm_mday = day;
3372 tmTmp.tm_hour = hour;
3376 tsStart = mktime(&tmTmp);
3379 if ((sTime=strchr(sEnd,
' '))) {
3382 int year = 1970, month = 1, day = 1;
3383 int hour = 0, min = 0, sec = 0;
3386 memset(&tmTmp, 0,
sizeof(tmTmp));
3389 tmTmp.tm_year = year-1900;
3390 tmTmp.tm_mon = month-1;
3391 tmTmp.tm_mday = day;
3393 tmTmp.tm_hour = hour;
3397 tsEnd = mktime(&tmTmp);
3399 if (tsStart <= *ts/1000000 && tsEnd > *ts/1000000) {
3409 if ((p = strchr(p,
','))) {
3422 #define SWITCH_CTYPE_NUM_CHARS 256
3426 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3427 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3428 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3429 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3430 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3431 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3432 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3433 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
3434 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
3435 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
3436 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
3437 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
3438 0x60,
'A',
'B',
'C',
'D',
'E',
'F',
'G',
3439 'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
3440 'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
3441 'X',
'Y',
'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
3442 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
3443 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
3444 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
3445 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
3446 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
3447 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
3448 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
3449 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
3450 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
3451 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
3452 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
3453 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
3454 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
3455 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
3456 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
3457 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
3464 if ((
unsigned int) c > 255)
3468 return ((_switch_toupper_tab_ + 1)[c]);
3473 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3474 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3475 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3476 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3477 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3478 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3479 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3480 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
3481 0x40,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
3482 'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
3483 'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
3484 'x',
'y',
'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
3485 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
3486 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
3487 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
3488 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
3489 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
3490 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
3491 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
3492 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
3493 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
3494 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
3495 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
3496 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
3497 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
3498 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
3499 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
3500 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
3501 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
3502 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
3503 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
3504 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
3511 if ((
unsigned int) c > 255)
3515 return ((_switch_tolower_tab_ + 1)[c]);
3612 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_U |
_L |
_N)));
3617 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_U |
_L)));
3622 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_C));
3627 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_N));
3632 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_P |
_U |
_L |
_N)));
3637 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_L));
3642 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_P |
_U |
_L |
_N |
_B)));
3647 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_P));
3652 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_S));
3657 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_U));
3662 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_N |
_X)));
3686 if (!strncasecmp(DOW[x], exp, 3)) {
3715 }
else if (**s ==
',') {
3718 }
else if (**s >=
'1' && **s <=
'7') {
3719 dow_t r = **s -
'0';
3735 const char *p = exp;
3750 if (range_start <= cur ? (val >= range_start && val <= cur) : (val >= range_start || val <= cur)) {
3754 }
else if (val == cur) {
3770 int a = strtol(exp, (
char **)&exp, 10);
3775 int b = strtol(++exp, (
char **)&exp, 10);
3776 if (a <= b ? (val >= a && val <=b ) : (val >= a || val <= b))
3786 char *dup = strdup(exp);
3795 int range_start, range_end;
3800 if ((p = strchr(cur,
','))) {
3806 if ((minm=strchr(cur,
':'))) {
3808 if ((maxh=strchr(minm,
'-'))) {
3809 if ((maxm=strchr(maxh,
':'))) {
3813 if ((mins=strchr(minm,
':'))) {
3818 if ((maxs=strchr(maxm,
':'))) {
3824 range_start = (atol(minh) * 60 * 60) + (atol(minm) * 60) + atol(mins);
3825 range_end = (atol(maxh) * 60 * 60) + (atol(maxm) * 60) + atol(maxs);
3826 if (range_start <= range_end ? (val >= range_start && val <= range_end) : (val >= range_start || val <= range_end)) {
3836 if ((p = strchr(p,
','))) {
3850 char *p = NULL, *h = NULL, *u = NULL;
3855 if (!strncasecmp(in,
"sip:", 4)) in += 4;
3856 else if (!strncasecmp(in,
"sips:", 5)) in += 5;
3859 if ((h = in, p = strchr(h,
'@'))) *p =
'\0', u =
in, h = p+1;
3862 for (p = h; *p; p++)
3863 if (*p ==
':' || *p ==
';' || *p ==
' ') {
3867 if (user) *user = u;
3868 if (domain) *domain = h;
3892 const char *p = num;
3913 if (len == 11 && p[0] ==
'1') {
3914 r =
switch_mprintf(
"%c (%c%c%c) %c%c%c-%c%c%c%c", p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10]);
3915 }
else if (len == 10) {
3916 r =
switch_mprintf(
"1 (%c%c%c) %c%c%c-%c%c%c%c", p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9]);
3927 int tmp = atoi(nptr);
3928 if (tmp < 0)
return 0;
3929 else return (
unsigned int) tmp;
3934 long tmp = atol(nptr);
3935 if (tmp < 0)
return 0;
3936 else return (
unsigned long) tmp;
3942 #ifdef HAVE_STRERROR_R
3943 #ifdef STRERROR_R_CHAR_P
3945 return strerror_r(errnum, buf, buflen);
3951 if (strerror_r(errnum, buf, buflen)) {
3956 #elif defined(WIN32)
3958 if (strerror_s(buf, buflen, errnum)) {
3978 q = strdup(request->qs);
3987 if ((next = strchr(next,
'&'))) {
3991 for (p = q; p && *p; p++) {
3992 if (*p ==
'+') *p =
' ';
3998 if ((val = strchr(name,
'='))) {
4015 int last, i, len, uri_len = 0;
4019 if (argc ==
sizeof(argv)) {
4024 for(i = 1; i < argc; i++) {
4025 if (*argv[i] ==
'\0' || !strcmp(argv[i],
".")) {
4027 }
else if (!strcmp(argv[i],
"..")) {
4029 if (last > 1) last--;
4031 argv[last++] = argv[i];
4035 for(i = 1; i < last; i++) {
4036 len = strlen(argv[i]);
4037 sprintf(uri + uri_len,
"/%s", argv[i]);
4038 uri_len += (len + 1);
4051 char *headers[64] = { 0 };
4053 char *argv[2] = { 0 };
4056 if (datalen < 16)
return status;
4059 if (*p++ ==
' ')
break;
4062 if (i == 0)
return status;
4064 if ((body = strstr(buffer,
"\r\n\r\n"))) {
4067 }
else if (( body = strstr(buffer,
"\n\n"))) {
4074 request->_buffer = strdup(buffer);
4075 request->method = request->_buffer;
4076 request->bytes_buffered = datalen;
4078 request->bytes_header = body - buffer;
4079 request->bytes_read = body - buffer;
4082 p = strchr(request->method,
' ');
4088 if (*p !=
'/')
goto err;
4091 p = strchr(request->uri,
' ');
4098 p = strchr(request->uri,
'?');
4109 if (!strncmp(http,
"HTTP/1.1", 8)) {
4111 }
else if (strncmp(http,
"HTTP/1.0", 8)) {
4115 if (!request->headers) {
4122 p = strchr(http,
'\n');
4132 if (header_count < 1)
goto err;
4134 for (i = 0; i < header_count; i++) {
4135 char *header, *value;
4140 if (argc != 2)
goto err;
4145 if (*value ==
' ') value++;
4147 len = strlen(value);
4149 if (len && *(value + len - 1) ==
'\r') *(value + len - 1) =
'\0';
4153 if (!strncasecmp(header,
"User-Agent", 10)) {
4154 request->user_agent = value;
4155 }
else if (!strncasecmp(header,
"Host", 4)) {
4156 request->host = value;
4157 p = strchr(value,
':');
4164 }
else if (!strncasecmp(header,
"Content-Type", 12)) {
4165 request->content_type = value;
4166 }
else if (!strncasecmp(header,
"Content-Length", 14)) {
4167 request->content_length = atoi(value);
4168 }
else if (!strncasecmp(header,
"Referer", 7)) {
4169 request->referer = value;
4188 if (request->_buffer) free(request->_buffer);
4189 if (request->_destroy_headers && request->headers) {
4199 printf(
"method: %s\n", request->method);
4201 if (request->uri) printf(
"uri: %s\n", request->uri);
4202 if (request->qs) printf(
"qs: %s\n", request->qs);
4203 if (request->host) printf(
"host: %s\n", request->host);
4204 if (request->port) printf(
"port: %d\n", request->port);
4205 if (request->from) printf(
"from: %s\n", request->from);
4206 if (request->user_agent) printf(
"user_agent: %s\n", request->user_agent);
4207 if (request->referer) printf(
"referer: %s\n", request->referer);
4208 if (request->user) printf(
"user: %s\n", request->user);
4209 if (request->keepalive) printf(
"uri: %d\n", request->keepalive);
4210 if (request->content_type) printf(
"uri: %s\n", request->content_type);
4211 if (request->content_length) printf(
"uri: %" SWITCH_SIZE_T_FMT "\n", request->content_length);
4216 printf(
"headers:\n-------------------------\n");
4219 printf(
"%s: %s\n", header->
name, header->
value);
4220 header = header->
next;
4228 FILETIME ct, et, kt, ut;
4229 GetProcessTimes(GetCurrentProcess(), &ct, &et, &kt, &ut);
4230 t->userms = ((int64_t)ut.dwLowDateTime | ((int64_t)ut.dwHighDateTime << 32)) / 10000;
4231 t->kernelms = ((int64_t)kt.dwLowDateTime | ((int64_t)kt.dwHighDateTime << 32)) / 10000;
4232 #elif defined(HAVE_GETRUSAGE)
4234 getrusage(RUSAGE_SELF, &r);
4235 t->userms = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000;
4236 t->kernelms = r.ru_stime.tv_sec * 1000 + r.ru_stime.tv_usec / 1000;
int switch_isupper(int c)
char * switch_escape_char(switch_memory_pool_t *pool, char *in, const char *delim, char esc)
Escape a string by prefixing a list of characters with an escape character.
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
int switch_build_uri(char *uri, switch_size_t size, const char *scheme, const char *user, const switch_sockaddr_t *sa, int flags)
build a URI string from components
#define switch_regex_safe_free(re)
char * switch_escape_string_pool(const char *in, switch_memory_pool_t *pool)
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
char * switch_strip_whitespace(const char *str)
switch_status_t switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input)
struct switch_network_node * node_head
char * switch_url_encode_opt(const char *url, char *buf, size_t len, switch_bool_t double_encode)
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
int switch_regex_copy_substring(const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int size)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
#define switch_test_subnet(_ip, _net, _mask)
switch_time_t switch_str_time(const char *in)
Converts a string representation of a date into a switch_time_t.
switch_status_t switch_frame_buffer_create(switch_frame_buffer_t **fbP)
char * switch_amp_encode(char *s, char *buf, switch_size_t len)
#define SWITCH_CHANNEL_LOG
int old_switch_tolower(int c)
switch_status_t switch_frame_free(switch_frame_t **frame)
#define IN6_AND_MASK(result, ip, mask)
switch_bool_t switch_is_lan_addr(const char *ip)
void switch_img_free(switch_image_t **img)
Close an image descriptor.
switch_size_t switch_b64_decode(char *in, char *out, switch_size_t olen)
int switch_isspace(int c)
static switch_frame_t * find_free_frame(switch_frame_buffer_t *fb, switch_frame_t *orig)
char * switch_string_replace(const char *string, const char *search, const char *replace)
unsigned long switch_atoul(const char *nptr)
static int get_netmask(struct sockaddr_in *me, int *mask)
static int switch_errno_is_break(int errcode)
char * switch_find_end_paren(const char *s, char open, char close)
switch_bool_t switch_network_list_validate_ip_token(switch_network_list_t *list, uint32_t ip, const char **token)
switch_bool_t switch_ast2regex(const char *pat, char *rbuf, size_t len)
void switch_split_date(const char *exp, int *year, int *month, int *day)
char * switch_strip_spaces(char *str, switch_bool_t dup)
int switch_wait_sock(switch_os_socket_t sock, uint32_t ms, switch_poll_t flags)
void switch_http_dump_request(switch_http_request_t *request)
static const char switch_b64_table[65]
switch_status_t switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
static unsigned int separate_string_char_delim(char *buf, char delim, char **array, unsigned int arraylen)
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
int switch_iscntrl(int c)
int old_switch_toupper(int c)
switch_priority_t
Priority Indication.
unsigned int switch_atoui(const char *nptr)
struct switch_network_node * next
int switch_islower(int c)
int switch_isalpha(int c)
switch_status_t switch_frame_dup(switch_frame_t *orig, switch_frame_t **clone)
switch_status_t switch_network_list_perform_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
void switch_http_free_request(switch_http_request_t *request)
switch_status_t switch_find_local_ip(char *buf, int len, int *mask, int family)
#define SWITCH_RTP_MAX_BUF_LEN
int switch_ispunct(int c)
char * switch_url_encode(const char *url, char *buf, size_t len)
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
int switch_isdigit(int c)
char * switch_separate_paren_args(char *str)
const char * switch_dow_int2str(int val)
int switch_strcasecmp_any(const char *str,...)
#define SWITCH_CTYPE_NUM_CHARS
switch_status_t switch_http_parse_header(char *buffer, uint32_t datalen, switch_http_request_t *request)
switch_size_t switch_fd_read_dline(int fd, char **buf, switch_size_t *len)
struct real_pcre switch_regex_t
char * switch_print_host(switch_sockaddr_t *addr, char *buf, switch_size_t len)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
int switch_tod_cmp(const char *exp, int val)
struct switch_runtime runtime
int switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
#define SWITCH_SOCK_INVALID
switch_size_t switch_fd_read_line(int fd, char *buf, switch_size_t len)
switch_bool_t switch_testv6_subnet(ip_t _ip, ip_t _net, ip_t _mask)
int switch_isgraph(int c)
#define SWITCH_URL_UNSAFE
int switch_split_user_domain(char *in, char **user, char **domain)
Split a user string as user and domain.
static dow_t _dow_read_token(const char **s)
switch_bool_t switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file, const char *convert_cmd, const char *convert_ext)
char * switch_util_quote_shell_arg_pool(const char *string, switch_memory_pool_t *pool)
Quote shell argument, allocating from pool if provided.
void switch_split_time(const char *exp, int *hour, int *min, int *sec)
void switch_getcputime(switch_cputime *t)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
int get_addr_int(switch_sockaddr_t *sa)
int switch_system(const char *cmd, switch_bool_t wait)
int switch_number_cmp(const char *exp, int val)
switch_bool_t switch_is_leading_number(const char *str)
#define SWITCH_MUTEX_NESTED
void switch_http_parse_qs(switch_http_request_t *request, char *qs)
char * switch_escape_string(const char *in, char *out, switch_size_t outlen)
char * get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen)
#define SWITCH_PATH_SEPARATOR
switch_status_t switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen)
switch_byte_t switch_byte_t * buf
switch_size_t switch_fp_read_dline(FILE *fd, char **buf, switch_size_t *len)
switch_status_t switch_frame_buffer_dup(switch_frame_buffer_t *fb, switch_frame_t *orig, switch_frame_t **clone)
int switch_isxdigit(int c)
switch_status_t switch_frame_buffer_destroy(switch_frame_buffer_t **fbP)
struct apr_sockaddr_t switch_sockaddr_t
const int _switch_C_ctype_[1+SWITCH_CTYPE_NUM_CHARS]
switch_frame_node_t * head
char * switch_find_parameter(const char *str, const char *param, switch_memory_pool_t *pool)
switch_frame_flag_t flags
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
switch_status_t switch_network_list_add_host_mask(switch_network_list_t *list, const char *host, const char *mask_str, switch_bool_t ok)
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
const short * _switch_toupper_tab_
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
const char * switch_cut_path(const char *in)
Create a pointer to the file name in a given file path eliminating the directory name.
#define switch_zmalloc(ptr, len)
void switch_img_copy(switch_image_t *img, switch_image_t **new_img)
Copy image to a new image.
unsigned short get_port(struct sockaddr *sa)
get the port number of an ip address
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_status_t switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len)
static uint32_t switch_toupper(uint32_t eax)
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
#define SWITCH_BLANK_STRING
switch_status_t switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool)
struct switch_frame_node_s * next
#define switch_arraylen(_a)
An abstraction of a data frame.
int switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask, uint32_t *bitp)
char * switch_util_quote_shell_arg(const char *string)
Quote shell argument.
switch_status_t switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input)
switch_byte_t switch_byte_t uint32_t buflen
int switch_regex_perform(const char *field, const char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
char * get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen)
find the char representation of an ip adress
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
const short _switch_C_tolower_[1+SWITCH_CTYPE_NUM_CHARS]
static char * cleanup_separated_string(char *str, char delim)
static char RFC2833_CHARS[]
int switch_dow_str2int(const char *exp)
switch_directories SWITCH_GLOBAL_dirs
#define switch_str_nil(s)
Make a null string a blank string instead.
const short _switch_C_toupper_[1+SWITCH_CTYPE_NUM_CHARS]
struct switch_frame_node_s * prev
switch_bool_t switch_is_number(const char *str)
void switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
unsigned char switch_char_to_rfc2833(char key)
Return the RFC2833 event based on an key character.
switch_memory_pool_t * pool
struct apr_thread_mutex_t switch_mutex_t
switch_status_t
Common return values.
int switch_socket_waitfor(switch_pollfd_t *poll, int ms)
Wait for a socket.
switch_status_t switch_network_list_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token)
unsigned int switch_separate_string_string(char *buf, char *delim, char **array, unsigned int arraylen)
char * switch_url_decode(char *s)
char switch_rfc2833_to_char(int event)
Return the RFC2833 character based on an event id.
int switch_fulldate_cmp(const char *exp, switch_time_t *ts)
static int write_buf(int fd, const char *buf)
switch_status_t switch_frame_alloc(switch_frame_t **frame, switch_size_t size)
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
unsigned int switch_separate_string(char *buf, char delim, char **array, unsigned int arraylen)
char * switch_network_ipv4_mapped_ipv6_addr(const char *ip_str)
void switch_uuid_get(switch_uuid_t *uuid)
switch_status_t switch_resolve_host(const char *host, char *buf, size_t buflen)
char * switch_strip_commas(char *in, char *out, switch_size_t len)
int switch_isalnum(int c)
char * switch_strerror_r(int errnum, char *buf, switch_size_t buflen)
const char * switch_core_mime_ext2type(const char *ext)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
int switch_inet_pton(int af, const char *src, void *dst)
switch_bool_t default_type
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
char * switch_uuid_str(char *buf, switch_size_t len)
static const char * DOW[]
switch_bool_t switch_network_list_validate_ip6_token(switch_network_list_t *list, ip_t ip, const char **token)
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
void switch_event_destroy(switch_event_t **event)
Destroy an event.
switch_status_t clean_uri(char *uri)
struct switch_frame_node_s switch_frame_node_t
const short * _switch_tolower_tab_
const char * switch_stristr(const char *instr, const char *str)
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
const int * _switch_ctype_
static char unescape_char(char escaped)
switch_status_t switch_find_interface_ip(char *buf, int len, int *mask, const char *ifname, int family)
int switch_cp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
int switch_isprint(int c)
switch_status_t switch_frame_buffer_free(switch_frame_buffer_t *fb, switch_frame_t **frameP)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
int switch_wait_socklist(switch_waitlist_t *waitlist, uint32_t len, uint32_t ms)
#define SWITCH_SIZE_T_FMT
#define SWITCH_UUID_FORMATTED_LENGTH
switch_bool_t switch_dow_cmp(const char *exp, int val)
char * switch_strip_nonnumerics(char *in, char *out, switch_size_t len)
static unsigned int separate_string_blank_delim(char *buf, char **array, unsigned int arraylen)
char * switch_core_get_variable_dup(_In_z_ const char *varname)
char * switch_format_number(const char *num)
switch_memory_pool_t * pool
const char * switch_priority_name(switch_priority_t priority)
Return a printable name of a switch_priority_t.
char * switch_replace_char(char *str, char from, char to, switch_bool_t dup)