38 #include <arpa/inet.h> 39 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) 41 #include <sys/resource.h> 43 #include <sys/types.h> 51 #define ESCAPE_META '\\' 52 #ifdef SWITCH_HAVE_GUMBO 56 #if defined(HAVE_OPENSSL) 57 #include <openssl/evp.h> 58 #include <openssl/hmac.h> 59 #include <openssl/sha.h> 88 return calloc(nmemb, size);
94 return inet_pton(af, src, dst);
105 snprintf(buf + strlen(buf), len - strlen(buf),
":%d", port);
116 new_frame->
buflen = (uint32_t)size;
117 new_frame->
data = malloc(size);
147 for (np = fb->
head; np; np = np->
next) {
150 if (np == fb->
head) {
152 }
else if (np->
prev) {
308 if (!qlen) qlen = 500;
331 new_frame = malloc(
sizeof(*new_frame));
341 new_frame->
data = ((
unsigned char *)new_frame->
packet) + 12;
352 new_frame->
img = NULL;
397 const char *next_str = 0;
402 while ((next_str = va_arg(ap,
const char *))) {
403 if (!strcasecmp(str, next_str)) {
417 char *e, *r = NULL, *ptr = NULL, *
next = NULL;
425 next = strchr(ptr,
';');
427 if (!strncasecmp(ptr, param, len) && *e ==
'=') {
435 e = ptr + strlen(ptr);
438 mlen = (e - ptr) + 1;
478 #define IN6_AND_MASK(result, ip, mask) \ 479 ((uint32_t *) (result))[0] =((const uint32_t *) (ip))[0] & ((const uint32_t *)(mask))[0]; \ 480 ((uint32_t *) (result))[1] =((const uint32_t *) (ip))[1] & ((const uint32_t *)(mask))[1]; \ 481 ((uint32_t *) (result))[2] =((const uint32_t *) (ip))[2] & ((const uint32_t *)(mask))[2]; \ 482 ((uint32_t *) (result))[3] =((const uint32_t *) (ip))[3] & ((const uint32_t *)(mask))[3]; 484 if (!IN6_IS_ADDR_UNSPECIFIED(&_mask.
v6)) {
485 struct in6_addr a, b;
488 return !memcmp(&a,&b,
sizeof(
struct in6_addr));
490 if (!IN6_IS_ADDR_UNSPECIFIED(&_net.
v6)) {
491 return !memcmp(&_net,&_ip,
sizeof(
struct in6_addr));
504 if (node->
family == AF_INET)
continue;
516 *token = node->
token;
553 if (node->
family == AF_INET6)
continue;
564 *token = node->
token;
586 if (strncasecmp(ip_str,
"::ffff:", 7)) {
590 return strdup(ip_str + 7);
599 if (port->
port != 0) {
603 if (port->
ports[0] != 0) {
607 written += snprintf(buf + written,
sizeof(buf) - written, (i != 0 ?
", %u" :
"%u"), port->
ports[i]);
636 cidr_str, ports ? ports :
"", ok ?
"allow" :
"deny",
switch_str_nil(token), list->
name);
654 if (strchr(cidr_str,
':')) {
668 cidr_str, ports ? ports :
"", ok ?
"allow" :
"deny",
switch_str_nil(token), list->
name);
677 char *cidr_str_dup = NULL;
680 if (strchr(cidr_str,
',')) {
681 char *argv[32] = { 0 };
683 cidr_str_dup = strdup(cidr_str);
687 for (i = 0; i < argc; i++) {
690 status = this_status;
717 node->
ip.
v4 = ntohl(ip.
v4);
725 mask.
v4 = mask.
v4 - ((mask.
v4 >> 1) & 0x55555555);
726 mask.
v4 = (mask.
v4 & 0x33333333) + ((mask.
v4 >> 2) & 0x33333333);
727 node->
bits = (((mask.
v4 + (mask.
v4 >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
753 bit_str = strchr(host,
'/');
760 bits = atoi(bit_str);
761 ipv6 = strchr(
string,
':');
766 if (bits < 0 || bits > 128) {
770 bits = atoi(bit_str);
773 for (n = bits, i = 0; i < 16; i++) {
775 maskv->
v6.s6_addr[i] = 0xFF & ~(0xFF >> k);
779 if (bits < 0 || bits > 32) {
783 bits = atoi(bit_str);
785 ipv->
v4 = htonl(ipv->
v4);
787 maskv->
v4 = 0xFFFFFFFF & ~(0xFFFFFFFF >>
bits);
798 const char *e = NULL;
801 while (s && *s && *s ==
' ') {
805 if (s && *s == open) {
807 for (e = s + 1; e && *e; e++) {
808 if (*e == open && open != close) {
810 }
else if (*e == close) {
819 return (e && *e == close) ? (
char *) e : NULL;
829 while (total + 2 < len && (cur = read(fd, &c, 1)) == 1) {
832 if (c ==
'\r' || c ==
'\n') {
842 #define DLINE_BLOCK_SIZE 1024 843 #define DLINE_MAX_SIZE 1048576 859 while ((cur = read(fd, &c, 1)) == 1) {
861 if (total + 2 >= ilen) {
868 data = realloc(data, ilen);
877 if (c ==
'\r' || c ==
'\n') {
908 while (fread(&c, 1, 1, fd) == 1) {
910 if (total + 2 >= ilen) {
917 data = realloc(data, ilen);
926 if (c ==
'\r' || c ==
'\n') {
947 for (p = s; x < len; p++) {
951 if (x + 6 > len - 1) {
963 if (x + 6 > len - 1) {
975 if (x + 5 > len - 1) {
986 if (x + 4 > len - 1) {
996 if (x + 4 > len - 1) {
1006 if (x + 1 > len - 1) {
1023 static const char switch_b64_table[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1024 #define B64BUFFLEN 1024 1027 int y = 0, bytes = 0;
1029 unsigned int b = 0, l = 0;
1031 for (x = 0; x < ilen; x++) {
1032 b = (b << 8) + in[x];
1037 if (bytes >= (
int)olen - 1) {
1052 while (l < 6 && bytes < (
int)olen - 1) {
1053 out[bytes++] =
'=', l += 2;
1068 int b = 0, c, l = 0, i;
1073 for (i = 0; i < 256; i++) {
1077 for (i = 0; i < 64; i++) {
1081 for (ip = in; ip && *
ip; ip++) {
1091 op[ol++] = (char) ((b >> (l -= 8)) % 256);
1092 if (ol >= olen - 1) {
1108 int len = (int) strlen(buf);
1109 if (fd && write(fd, buf, len) != len) {
1119 const char *headers,
1120 const char *body,
const char *file,
const char *convert_cmd,
const char *convert_ext)
1122 char *bound =
"XXXX_boundary_XXXX";
1123 const char *mime_type =
"audio/inline";
1125 int fd = -1, ifd = -1;
1126 int x = 0, y = 0, bytes = 0, ilen = 0;
1127 unsigned int b = 0, l = 0;
1130 char *dupfile = NULL, *ext = NULL;
1131 char *newfile = NULL;
1133 const char *err = NULL;
1138 err =
"No to address specified";
1142 if (!
zstr(file) && !
zstr(convert_cmd) && !
zstr(convert_ext)) {
1143 if (strrchr(file,
'.')) {
1144 dupfile = strdup(file);
1145 if ((ext = strrchr(dupfile,
'.'))) {
1152 char cmd[1024] =
"";
1153 switch_snprintf(cmd,
sizeof(cmd),
"%s %s %s", convert_cmd, file, newfile);
1155 if (strcmp(file, newfile)) {
1167 if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) > -1) {
1169 if ((ifd = open(file, O_RDONLY |
O_BINARY)) < 0) {
1171 err =
"Cannot open tmp file\n";
1184 err =
"write error.";
1189 if (headers && !
write_buf(fd, headers)) {
1191 err =
"write error.";
1197 err =
"write error.";
1209 err =
"write error.";
1217 err =
"write error.";
1222 if (file && bound) {
1224 const char *new_type;
1227 if ((ext = strrchr(stipped_file,
'.'))) {
1230 mime_type = new_type;
1235 "\n\n--%s\nContent-Type: %s; name=\"%s\"\n" 1236 "Content-ID: <ATTACHED@freeswitch.org>\n" 1237 "Content-Transfer-Encoding: base64\n" 1238 "Content-Description: Sound attachment.\n" 1239 "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
1242 err =
"write error.";
1247 for (x = 0; x < ilen; x++) {
1248 b = (b << 8) + in[x];
1254 out[bytes++] =
'\n';
1258 if (write(fd, &out, bytes) != bytes) {
1272 out[bytes++] =
'=', l += 2;
1274 if (write(fd, &out, bytes) != bytes) {
1285 err =
"write error.";
1297 from =
"freeswitch";
1312 err =
"execute error";
1332 if (!
zstr_buf(filename) && unlink(filename) != 0) {
1347 if (
zstr(err)) err =
"Unknown Error";
1360 return (strncmp(ip,
"10.", 3) &&
1361 strncmp(ip,
"192.168.", 8) &&
1362 strncmp(ip,
"127.", 4) &&
1363 strncmp(ip,
"255.", 4) &&
1364 strncmp(ip,
"0.", 2) &&
1365 strncmp(ip,
"1.", 2) &&
1366 strncmp(ip,
"2.", 2) &&
1367 strncmp(ip,
"172.16.", 7) &&
1368 strncmp(ip,
"172.17.", 7) &&
1369 strncmp(ip,
"172.18.", 7) &&
1370 strncmp(ip,
"172.19.", 7) &&
1371 strncmp(ip,
"172.20.", 7) &&
1372 strncmp(ip,
"172.21.", 7) &&
1373 strncmp(ip,
"172.22.", 7) &&
1374 strncmp(ip,
"172.23.", 7) &&
1375 strncmp(ip,
"172.24.", 7) &&
1376 strncmp(ip,
"172.25.", 7) &&
1377 strncmp(ip,
"172.26.", 7) &&
1378 strncmp(ip,
"172.27.", 7) &&
1379 strncmp(ip,
"172.28.", 7) &&
1380 strncmp(ip,
"172.29.", 7) &&
1381 strncmp(ip,
"172.30.", 7) &&
1382 strncmp(ip,
"172.31.", 7) &&
1383 strncmp(ip,
"192.0.2.", 8) &&
1384 strncmp(ip,
"169.254.", 8)
1390 const char *p = pat;
1398 *(rbuf + strlen(rbuf)) =
'^';
1402 strncat(rbuf,
"[2-9]", len - strlen(rbuf));
1403 }
else if (*p ==
'X') {
1404 strncat(rbuf,
"[0-9]", len - strlen(rbuf));
1405 }
else if (*p ==
'Z') {
1406 strncat(rbuf,
"[1-9]", len - strlen(rbuf));
1407 }
else if (*p ==
'.') {
1408 strncat(rbuf,
".*", len - strlen(rbuf));
1409 }
else if (strlen(rbuf) < len - 1) {
1410 *(rbuf + strlen(rbuf)) = *p;
1414 *(rbuf + strlen(rbuf)) =
'$';
1430 for (; p && *p; p++) {
1441 const char *sp =
str;
1449 while ((*sp == 13 ) || (*sp == 10 ) || (*sp == 9 ) || (*sp == 32) || (*sp == 11) ) {
1460 if ((len = strlen(s)) > 0) {
1463 while ((p >= s) && ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11))) {
1473 const char *sp =
str;
1481 while ((*sp == 13 ) || (*sp == 10 ) || (*sp == 9 ) || (*sp == 32) || (*sp == 11) ) {
1492 if ((len = strlen(s)) > 0) {
1495 while ((p >= s) && ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11))) {
1513 while (*sp ==
' ') {
1528 if ((len = strlen(s)) > 0) {
1531 while (p && *p && (p >= s) && *p ==
' ') {
1541 char *p =
in, *q = out;
1545 for (; p && *p; p++) {
1546 if ((*p > 47 && *p < 58)) {
1553 }
else if (*p !=
',') {
1564 char *p =
in, *q = out;
1568 for (; p && *p; p++) {
1569 if ((*p > 47 && *p < 58) || *p ==
'.' || *p ==
'-' || *p ==
'+') {
1587 if ((args = strchr(str,
'('))) {
1598 }
else if (br > 1 && *e ==
')') {
1600 }
else if (br == 1 && *e ==
')') {
1614 const char *original_str =
str;
1616 if (str == NULL || *str ==
'\0' || from > to) {
1620 for (; *str !=
'\0'; str++) {
1621 if (!isdigit(*str)) {
1626 number = atoi(original_str);
1628 if (number < from || number > to) {
1640 if (*str ==
'-' || *str ==
'+') {
1644 for (p = str; p && *p; p++) {
1645 if (!(*p ==
'.' || (*p > 47 && *p < 58))) {
1659 if (*str ==
'-' || *str ==
'+') {
1663 for (p = str; p && *p; p++) {
1664 if ((*p ==
'.' || (*p > 47 && *p < 58))) {
1683 const char *pptr, *sptr, *start;
1688 for (start = str; *start; start++) {
1713 #ifdef HAVE_GETIFADDRS 1714 #include <ifaddrs.h> 1717 struct ifaddrs *ifaddrs, *i = NULL;
1719 if (!me || getifaddrs(&ifaddrs) < 0) {
1723 for (i = ifaddrs; i; i = i->ifa_next) {
1724 struct sockaddr_in *s = (
struct sockaddr_in *) i->ifa_addr;
1725 struct sockaddr_in *m = (
struct sockaddr_in *) i->ifa_netmask;
1727 if (s && m && s->sin_family == AF_INET && s->sin_addr.s_addr == me->sin_addr.s_addr) {
1728 *mask = m->sin_addr.s_addr;
1729 freeifaddrs(ifaddrs);
1734 freeifaddrs(ifaddrs);
1738 #elif defined(__linux__) 1740 #include <sys/ioctl.h> 1745 static struct ifreq ifreqs[20] = { {{{0}}} };
1746 struct ifconf ifconf;
1751 memset(&ifconf, 0,
sizeof(ifconf));
1752 ifconf.ifc_buf = (
char *) (ifreqs);
1753 ifconf.ifc_len =
sizeof(ifreqs);
1756 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
1760 if (ioctl(sock, SIOCGIFCONF, (
char *) &ifconf) < 0) {
1764 nifaces = ifconf.ifc_len /
sizeof(
struct ifreq);
1766 for (i = 0; i < nifaces; i++) {
1767 struct sockaddr_in *sin = NULL;
1770 ioctl(sock, SIOCGIFADDR, &ifreqs[i]);
1771 sin = (
struct sockaddr_in *) &ifreqs[i].ifr_addr;
1774 if (ip.s_addr == me->sin_addr.s_addr) {
1775 ioctl(sock, SIOCGIFNETMASK, &ifreqs[i]);
1776 sin = (
struct sockaddr_in *) &ifreqs[i].ifr_addr;
1778 *mask = sin->sin_addr.s_addr;
1792 #elif defined(WIN32) 1796 SOCKET sock = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
1797 INTERFACE_INFO interfaces[20];
1798 unsigned long bytes;
1799 int interface_count, x;
1804 if (sock == SOCKET_ERROR) {
1808 if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, 0, 0, &interfaces,
sizeof(interfaces), &bytes, 0, 0) == SOCKET_ERROR) {
1813 interface_count = bytes /
sizeof(INTERFACE_INFO);
1815 for (x = 0; x < interface_count; ++x) {
1816 struct sockaddr_in *addr = (
struct sockaddr_in *) &(interfaces[x].iiAddress);
1818 if (addr->sin_addr.s_addr == me->sin_addr.s_addr) {
1819 struct sockaddr_in *netmask = (
struct sockaddr_in *) &(interfaces[x].iiNetmask);
1820 *mask = netmask->sin_addr.s_addr;
1844 struct addrinfo *ai;
1846 if (getaddrinfo(host, 0, 0, &ai)) {
1850 get_addr(buf, buflen, ai->ai_addr,
sizeof(
struct sockaddr_storage));
1867 SOCKADDR_STORAGE l_address;
1869 struct addrinfo *address_info;
1876 int tmp_socket = -1, on = 1;
1882 if (force_local_ip_v4) {
1889 if (force_local_ip_v6) {
1909 base =
"82.45.148.209";
1913 base =
"2001:503:BA3E::2:30";
1921 tmp_socket = socket(family, SOCK_DGRAM, 0);
1923 getaddrinfo(base, NULL, NULL, &address_info);
1925 if (!address_info || WSAIoctl(tmp_socket,
1926 SIO_ROUTING_INTERFACE_QUERY,
1927 address_info->ai_addr, (DWORD) address_info->ai_addrlen, &l_address,
sizeof(l_address), (LPDWORD) & l_address_len, NULL,
1930 closesocket(tmp_socket);
1932 freeaddrinfo(address_info);
1937 closesocket(tmp_socket);
1938 freeaddrinfo(address_info);
1940 if (!getnameinfo((
const struct sockaddr *) &l_address, l_address_len, buf, len, NULL, 0, NI_NUMERICHOST)) {
1943 get_netmask((
struct sockaddr_in *) &l_address, mask);
1951 struct sockaddr_in iface_out;
1952 struct sockaddr_in remote;
1953 memset(&remote, 0,
sizeof(
struct sockaddr_in));
1955 remote.sin_family = AF_INET;
1956 remote.sin_addr.s_addr = inet_addr(base);
1957 remote.sin_port = htons(4242);
1959 memset(&iface_out, 0,
sizeof(iface_out));
1960 if ( (tmp_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1 ) {
1964 if (setsockopt(tmp_socket, SOL_SOCKET, SO_BROADCAST, &on,
sizeof(on)) == -1) {
1968 if (connect(tmp_socket, (
struct sockaddr *) &remote,
sizeof(
struct sockaddr_in)) == -1) {
1972 ilen =
sizeof(iface_out);
1973 if (getsockname(tmp_socket, (
struct sockaddr *) &iface_out, &ilen) == -1) {
1977 if (iface_out.sin_addr.s_addr == 0) {
1983 get_netmask((
struct sockaddr_in *) &iface_out, mask);
1991 struct sockaddr_in6 iface_out;
1992 struct sockaddr_in6 remote;
1993 memset(&remote, 0,
sizeof(
struct sockaddr_in6));
1995 remote.sin6_family = AF_INET6;
1997 remote.sin6_port = htons(4242);
1999 memset(&iface_out, 0,
sizeof(iface_out));
2000 if ( (tmp_socket = socket(AF_INET6, SOCK_DGRAM, 0)) == -1 ) {
2004 if (connect(tmp_socket, (
struct sockaddr *) &remote,
sizeof(remote)) == -1) {
2008 ilen =
sizeof(iface_out);
2009 if (getsockname(tmp_socket, (
struct sockaddr *) &iface_out, &ilen) == -1) {
2013 inet_ntop(AF_INET6, (
const void *) &iface_out.sin6_addr, buf, len - 1);
2020 if (tmp_socket > 0) {
2028 #ifdef HAVE_GETIFADDRS 2029 # include <ifaddrs.h> 2030 # include <net/if.h> 2036 #ifdef HAVE_GETIFADDRS 2038 struct ifaddrs *addrs, *addr;
2041 for(addr = addrs; addr; addr = addr->ifa_next)
2043 if (!(addr->ifa_flags & IFF_UP))
continue;
2044 if (!addr->ifa_addr)
continue;
2045 if (!addr->ifa_netmask)
continue;
2046 if (family != AF_UNSPEC && addr->ifa_addr->sa_family != family)
continue;
2047 if (strcmp(addr->ifa_name, ifname))
continue;
2049 switch(addr->ifa_addr->sa_family) {
2051 inet_ntop(AF_INET, &( ((
struct sockaddr_in*)(addr->ifa_addr))->sin_addr ), buf, len - 1);
2054 inet_ntop(AF_INET6, &( ((
struct sockaddr_in6*)(addr->ifa_addr))->sin6_addr ), buf, len - 1);
2060 if (mask && addr->ifa_netmask->sa_family == AF_INET) {
2061 *mask = ((
struct sockaddr_in*)(addr->ifa_addr))->sin_addr.s_addr;
2069 #elif defined(__linux__) 2073 #elif defined(WIN32) 2086 int proceed = 0, ovector[30], time_only = 0;
2088 char replace[1024] =
"";
2090 char *pattern =
"^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
2091 char *pattern2 =
"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})";
2092 char *pattern3 =
"^(\\d*):{0,1}(\\d*):{0,1}(\\d*)$";
2097 if ((time_only =
switch_regex_perform(in, pattern3, &re, ovector,
sizeof(ovector) /
sizeof(ovector[0])))) {
2104 if (!(proceed =
switch_regex_perform(in, pattern, &re, ovector,
sizeof(ovector) /
sizeof(ovector[0])))) {
2106 proceed =
switch_regex_perform(in, pattern2, &re, ovector,
sizeof(ovector) /
sizeof(ovector[0]));
2110 if (proceed || time_only) {
2112 if (time_only > 1) {
2117 if (time_only > 2) {
2119 tm.
tm_min = atoi(replace);
2122 if (time_only > 3) {
2124 tm.
tm_sec = atoi(replace);
2129 tm.
tm_year = atoi(replace) - 1900;
2134 tm.
tm_mon = atoi(replace) - 1;
2149 tm.
tm_min = atoi(replace);
2154 tm.
tm_sec = atoi(replace);
2212 #include <sys/types.h> 2219 static const char *switch_inet_ntop4(
const unsigned char *src,
char *dst,
size_t size);
2221 static const char *switch_inet_ntop6(
const unsigned char *src,
char *dst,
size_t size);
2237 return switch_inet_ntop4(src, dst, size);
2240 return switch_inet_ntop6(src, dst, size);
2259 static const char *switch_inet_ntop4(
const unsigned char *src,
char *dst,
size_t size)
2261 static const char fmt[] =
"%u.%u.%u.%u";
2262 char tmp[
sizeof "255.255.255.255"];
2264 if (
switch_snprintf(tmp,
sizeof tmp, fmt, src[0], src[1], src[2], src[3]) >= (
int) size) {
2268 return strcpy(dst, tmp);
2271 #if HAVE_SIN6 || defined(NTDDI_VERSION) 2278 static const char *switch_inet_ntop6(
unsigned char const *src,
char *dst,
size_t size)
2287 char tmp[
sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
2293 unsigned int words[8];
2301 for (i = 0; i < 16; i += 2)
2302 words[i / 2] = (src[i] << 8) | (src[i + 1]);
2305 for (i = 0; i < 8; i++) {
2306 if (words[i] == 0) {
2308 cur.base = i,
cur.len = 1;
2312 if (
cur.base != -1) {
2313 if (best.base == -1 ||
cur.len > best.len)
2319 if (
cur.base != -1) {
2320 if (best.base == -1 ||
cur.len > best.len)
2323 if (best.base != -1 && best.len < 2)
2330 for (i = 0; i < 8; i++) {
2332 if (best.base != -1 && i >= best.base && i < (best.base + best.len)) {
2341 if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
2342 if (!switch_inet_ntop4(src + 12, tp,
sizeof tmp - (tp - tmp)))
2347 tp += sprintf(tp,
"%x", words[i]);
2350 if (best.base != -1 && (best.base + best.len) == 8)
2357 if ((
size_t) (tp - tmp) >= size) {
2361 return strcpy(dst, tmp);
2369 struct sockaddr_in *s = (
struct sockaddr_in *) &sa->sa;
2371 return ntohs((
unsigned short) s->sin_addr.s_addr);
2376 struct sockaddr_in *s1;
2377 struct sockaddr_in *s2;
2379 struct sockaddr_in6 *s16;
2380 struct sockaddr_in6 *s26;
2382 struct sockaddr *ss1;
2383 struct sockaddr *ss2;
2388 s1 = (
struct sockaddr_in *) &sa1->sa;
2389 s2 = (
struct sockaddr_in *) &sa2->sa;
2391 s16 = (
struct sockaddr_in6 *) &sa1->sa;
2392 s26 = (
struct sockaddr_in6 *) &sa2->sa;
2394 ss1 = (
struct sockaddr *) &sa1->sa;
2395 ss2 = (
struct sockaddr *) &sa2->sa;
2397 if (ss1->sa_family != ss2->sa_family)
2400 switch (ss1->sa_family) {
2403 return (s1->sin_addr.s_addr == s2->sin_addr.s_addr);
2405 return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port);
2412 if (s16->sin6_port != s26->sin6_port)
return 0;
2415 for (i = 0; i < 4; i++) {
2416 if (*((int32_t *) s16->sin6_addr.s6_addr + i) != *((int32_t *) s26->sin6_addr.s6_addr + i))
return 0;
2429 struct sockaddr_in *s1;
2430 struct sockaddr_in *s2;
2432 struct sockaddr_in6 *s16;
2433 struct sockaddr_in6 *s26;
2435 struct sockaddr *ss1;
2441 s1 = (
struct sockaddr_in *) &sa1->sa;
2442 s2 = (
struct sockaddr_in *) &sa2->sa;
2444 s16 = (
struct sockaddr_in6 *) &sa1->sa;
2445 s26 = (
struct sockaddr_in6 *) &sa2->sa;
2447 ss1 = (
struct sockaddr *) &sa1->sa;
2450 sa1->port = sa2->port;
2451 sa1->family = sa2->family;
2453 sa1->sa.sin.sin_family = sa2->family;
2455 switch (ss1->sa_family) {
2457 s1->sin_addr.s_addr = s2->sin_addr.s_addr;
2458 s1->sin_port = s2->sin_port;
2465 s16->sin6_port = s26->sin6_port;
2467 for (i = 0; i < 4; i++) {
2468 *((int32_t *) s16->sin6_addr.s6_addr + i) = *((int32_t *) s26->sin6_addr.s6_addr + i);
2484 #if defined(NTDDI_VERSION) 2485 switch_inet_ntop6((
unsigned char*)&(sa->sin6_addr), buf, len);
2487 inet_ntop(AF_INET6, &(sa->sin6_addr), buf, len);
2500 getnameinfo(sa, salen, buf, (socklen_t) len, NULL, 0, NI_NUMERICHOST);
2507 unsigned short port = 0;
2509 switch (sa->sa_family) {
2511 port = ntohs(((
struct sockaddr_in *) sa)->sin_port);
2514 port = ntohs(((
struct sockaddr_in6 *) sa)->sin6_port);
2523 char host[NI_MAXHOST], serv[NI_MAXSERV];
2524 struct sockaddr_in6 si6;
2525 const struct sockaddr *addr;
2529 memcpy(&si6, &sa->sa, sa->salen);
2530 si6.sin6_scope_id = 0;
2532 addr = (
const struct sockaddr *) &si6;
2534 addr = (
const struct sockaddr *) (intptr_t) & sa->sa;
2537 if (getnameinfo(addr, sa->salen, host,
sizeof(host), serv,
sizeof(serv),
2542 colon = strchr(host,
':');
2545 user ? user :
"", user ?
"@" :
"", colon ?
"[" :
"", host, colon ?
"]" :
"", serv[0] ?
":" :
"", serv[0] ? serv :
"");
2550 if (event > -1 && event < (int32_t)
sizeof(
RFC2833_CHARS)) {
2559 unsigned char counter = 0;
2575 int count = 1, i = 0;
2637 unescaped = escaped;
2647 for (p = in; *p; p++) {
2682 size_t len = strlen(in) * 2 + 1;
2695 int inside_quotes = 0;
2698 for (ptr = str; *ptr ==
' '; ++ptr) {
2701 for (start = dest = ptr; *ptr; ++ptr) {
2707 if (e ==
'\'' || e ==
'"' || (delim && e == delim) || e ==
ESCAPE_META || (e =
unescape_char(*(ptr + 1))) != *(ptr + 1)) {
2715 if (*ptr ==
'\'' && (inside_quotes || strchr(ptr+1,
'\''))) {
2716 if ((inside_quotes = (1 - inside_quotes))) {
2721 if (*ptr !=
' ' || inside_quotes) {
2736 unsigned int count = 0;
2738 size_t dlen = strlen(delim);
2740 array[count++] =
buf;
2742 while (count < arraylen && array[count - 1]) {
2743 if ((d = strstr(array[count - 1], delim))) {
2757 enum tokenizer_state {
2762 unsigned int count = 0;
2764 int inside_quotes = 0;
2767 while (*ptr && count < arraylen) {
2770 array[count++] = ptr;
2778 }
else if (*ptr ==
'\'' && (inside_quotes || strchr(ptr+1,
'\''))) {
2779 inside_quotes = (1 - inside_quotes);
2780 }
else if (*ptr == delim && !inside_quotes) {
2790 for (i = 0; i <
count; ++i) {
2800 enum tokenizer_state {
2807 unsigned int count = 0;
2809 int inside_quotes = 0;
2812 while (*ptr && count < arraylen) {
2815 array[count++] = ptr;
2816 state = SKIP_INITIAL_SPACE;
2819 case SKIP_INITIAL_SPACE:
2830 }
else if (*ptr ==
'\'') {
2831 inside_quotes = (1 - inside_quotes);
2832 }
else if (*ptr ==
' ' && !inside_quotes) {
2834 state = SKIP_ENDING_SPACE;
2839 case SKIP_ENDING_SPACE:
2850 for (i = 0; i <
count; ++i) {
2859 if (!buf || !array || !arraylen) {
2864 if (*buf ==
'^' && *(buf+1) ==
'^') {
2874 memset(array, 0, arraylen *
sizeof(*array));
2882 enum tokenizer_state {
2885 }
state = START, dstate = START;
2887 unsigned int count = 0;
2888 const char *ptr =
buf;
2890 while (*ptr && count < arraylen) {
2901 if (*ptr == delim) {
2902 larray[count - 1] = (
unsigned int)(ptr - array[count - 1]);
2911 if (dstate == START) larray[count - 1] = strlen(array[count - 1]);
2925 enum tokenizer_state {
2930 }
state = START, dstate = START;
2932 unsigned int count = 0;
2933 const char *ptr =
buf;
2935 while (*ptr && count < arraylen) {
2938 array[count++] = ptr;
2940 state = SKIP_INITIAL_SPACE;
2943 case SKIP_INITIAL_SPACE:
2953 larray[count - 1] = (
unsigned int)(ptr - array[count - 1]);
2955 state = SKIP_ENDING_SPACE;
2960 case SKIP_ENDING_SPACE:
2970 if (dstate == START) larray[count - 1] = strlen(array[count - 1]);
2984 if (!buf || !array || !arraylen) {
2989 if (*buf ==
'^' && *(buf+1) ==
'^') {
2990 const char *p = buf + 2;
2999 memset(array, 0, arraylen *
sizeof(*array));
3007 const char *p, *ret =
in;
3008 const char delims[] =
"/\\";
3012 for (i = delims; *i; i++) {
3014 while ((p = strchr(p, *i)) != 0) {
3028 for (i = 0; (i < search_len) && (i < string_len); i++) {
3029 if (
string[i] != search[i]) {
3034 if (i == search_len) {
3043 size_t string_len = strlen(
string);
3044 size_t search_len = strlen(search);
3045 size_t replace_len = strlen(replace);
3047 size_t dest_len = 0;
3050 dest = (
char *) malloc(
sizeof(
char));
3053 for (i = 0; i < string_len; i++) {
3055 for (n = 0; n < replace_len; n++) {
3056 dest[dest_len] = replace[n];
3058 tmp = (
char *) realloc(dest,
sizeof(
char) * (dest_len + 1));
3062 i += search_len - 1;
3064 dest[dest_len] =
string[i];
3066 tmp = (
char *) realloc(dest,
sizeof(
char) * (dest_len + 1));
3083 size_t string_len = strlen(
string);
3086 size_t dest_len = 0;
3090 dest_len = strlen(
string) + 1;
3092 for (i = 0; i < string_len; i++) {
3093 switch (
string[i]) {
3108 dest = (
char *) malloc(
sizeof(
char) * dest_len);
3118 for (i = 0; i < string_len; i++) {
3119 switch (
string[i]) {
3135 dest[n++] =
string[i];
3155 struct pollfd pfds[2] = { { 0 } };
3166 pfds[0].events |= POLLIN;
3170 pfds[0].events |= POLLOUT;
3174 pfds[0].events |= POLLERR;
3178 pfds[0].events |= POLLHUP;
3182 pfds[0].events |= POLLRDNORM;
3186 pfds[0].events |= POLLRDBAND;
3190 pfds[0].events |= POLLPRI;
3193 s = poll(pfds, 1, ms);
3204 if ((pfds[0].revents & POLLIN)) {
3207 if ((pfds[0].revents & POLLOUT)) {
3210 if ((pfds[0].revents & POLLERR)) {
3213 if ((pfds[0].revents & POLLHUP)) {
3216 if ((pfds[0].revents & POLLRDNORM)) {
3219 if ((pfds[0].revents & POLLRDBAND)) {
3222 if ((pfds[0].revents & POLLPRI)) {
3225 if ((pfds[0].revents & POLLNVAL)) {
3236 struct pollfd *pfds;
3237 int s = 0, r = 0, i;
3239 pfds = calloc(len,
sizeof(
struct pollfd));
3242 for (i = 0; i < len; i++) {
3247 pfds[i].fd = waitlist[i].
sock;
3250 pfds[i].events |= POLLIN;
3254 pfds[i].events |= POLLOUT;
3258 pfds[i].events |= POLLERR;
3262 pfds[i].events |= POLLHUP;
3266 pfds[i].events |= POLLRDNORM;
3270 pfds[i].events |= POLLRDBAND;
3274 pfds[i].events |= POLLPRI;
3278 s = poll(pfds, len, ms);
3289 for (i = 0; i < len; i++) {
3290 if ((pfds[i].revents & POLLIN)) {
3294 if ((pfds[i].revents & POLLOUT)) {
3298 if ((pfds[i].revents & POLLERR)) {
3302 if ((pfds[i].revents & POLLHUP)) {
3306 if ((pfds[i].revents & POLLRDNORM)) {
3310 if ((pfds[i].revents & POLLRDBAND)) {
3314 if ((pfds[i].revents & POLLPRI)) {
3318 if ((pfds[i].revents & POLLNVAL)) {
3345 rfds = malloc(
sizeof(fd_set));
3346 wfds = malloc(
sizeof(fd_set));
3347 efds = malloc(
sizeof(fd_set));
3355 assert(sock <= FD_SETSIZE);
3361 #pragma warning( push ) 3362 #pragma warning( disable : 4127 ) 3364 #pragma warning( pop ) 3373 #pragma warning( push ) 3374 #pragma warning( disable : 4127 ) 3376 #pragma warning( pop ) 3385 #pragma warning( push ) 3386 #pragma warning( disable : 4127 ) 3388 #pragma warning( pop ) 3394 tv.tv_sec = ms / 1000;
3395 tv.tv_usec = (ms % 1000) * 1000;
3397 s = select(sock + 1, (flags & SWITCH_POLL_READ) ? rfds : NULL, (flags & SWITCH_POLL_WRITE) ? wfds : NULL, (flags & SWITCH_POLL_ERROR) ? efds : NULL, &tv);
3408 if ((flags & SWITCH_POLL_READ) && FD_ISSET(sock, rfds)) {
3412 if ((flags & SWITCH_POLL_WRITE) && FD_ISSET(sock, wfds)) {
3416 if ((flags & SWITCH_POLL_ERROR) && FD_ISSET(sock, efds)) {
3440 rfds = malloc(
sizeof(fd_set));
3441 wfds = malloc(
sizeof(fd_set));
3442 efds = malloc(
sizeof(fd_set));
3448 for (i = 0; i < len; i++) {
3453 if (waitlist[i].sock > max_fd) {
3454 max_fd = waitlist[i].
sock;
3459 assert(waitlist[i].sock <= FD_SETSIZE);
3461 flags |= waitlist[i].
events;
3466 #pragma warning( push ) 3467 #pragma warning( disable : 4127 ) 3468 FD_SET(waitlist[i].sock, rfds);
3469 #pragma warning( pop ) 3471 FD_SET(waitlist[i].sock, rfds);
3478 #pragma warning( push ) 3479 #pragma warning( disable : 4127 ) 3480 FD_SET(waitlist[i].sock, wfds);
3481 #pragma warning( pop ) 3483 FD_SET(waitlist[i].sock, wfds);
3490 #pragma warning( push ) 3491 #pragma warning( disable : 4127 ) 3492 FD_SET(waitlist[i].sock, efds);
3493 #pragma warning( pop ) 3495 FD_SET(waitlist[i].sock, efds);
3500 tv.tv_sec = ms / 1000;
3501 tv.tv_usec = (ms % 1000) * 1000;
3514 for (i = 0; i < len; i++) {
3515 if ((waitlist[i].events & SWITCH_POLL_READ) && FD_ISSET(waitlist[i].sock, rfds)) {
3520 if ((waitlist[i].events & SWITCH_POLL_WRITE) && FD_ISSET(waitlist[i].sock, wfds)) {
3525 if ((waitlist[i].events & SWITCH_POLL_ERROR) && FD_ISSET(waitlist[i].sock, efds)) {
3567 const char hex[] =
"0123456789ABCDEF";
3572 if (!url)
return NULL;
3573 if (!pool)
return NULL;
3577 for (p = url; *p; p++) {
3583 if (!double_encode && *p ==
'%' && e-p > 1) {
3584 if (strchr(hex, *(p+1)) && strchr(hex, *(p+2))) {
3608 const char hex[] =
"0123456789ABCDEF";
3620 for (p = url; *p; p++) {
3627 if (!double_encode && *p ==
'%' && e-p > 1) {
3628 if (strchr(hex, *(p+1)) && strchr(hex, *(p+2))) {
3634 if ((x + 3) > len) {
3638 buf[x++] = hex[(*p >> 4) & 0x0f];
3639 buf[x++] = hex[*p & 0x0f];
3659 if (
zstr(s) || !strchr(s,
'%')) {
3663 for (o = s; *s; s++, o++) {
3664 if (*s ==
'%' && strlen(s) > 2 && sscanf(s + 1,
"%2x", &tmp) == 1) {
3677 char *dup = strdup(exp);
3685 if ((smin=strchr(dup,
':'))) {
3687 if ((ssec=strchr(smin,
':'))) {
3693 *hour = atol(shour);
3710 char *dup = strdup(exp);
3712 char *smonth = NULL;
3718 if ((smonth=strchr(dup,
'-'))) {
3720 if ((sday=strchr(smonth,
'-'))) {
3723 *year = atol(syear);
3726 *month = atol(smonth);
3741 char *dup = strdup(exp);
3753 if ((p = strchr(cur,
','))) {
3759 if ((sEnd = strchr(cur,
'~'))) {
3766 if (tsStart == 0 || tsEnd == 0) {
3771 if (tsStart <= *ts && tsEnd > *ts) {
3778 if ((p = strchr(p,
','))) {
3790 #define SWITCH_CTYPE_NUM_CHARS 256 3794 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3795 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3796 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3797 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3798 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3799 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3800 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3801 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
3802 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
3803 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
3804 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
3805 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
3806 0x60,
'A',
'B',
'C',
'D',
'E',
'F',
'G',
3807 'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
3808 'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
3809 'X',
'Y',
'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
3810 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
3811 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
3812 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
3813 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
3814 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
3815 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
3816 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
3817 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
3818 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
3819 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
3820 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
3821 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
3822 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
3823 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
3824 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
3825 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
3832 if ((
unsigned int) c > 255)
3836 return ((_switch_toupper_tab_ + 1)[c]);
3841 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3842 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3843 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3844 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3845 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3846 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3847 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3848 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
3849 0x40,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
3850 'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
3851 'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
3852 'x',
'y',
'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
3853 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
3854 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
3855 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
3856 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
3857 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
3858 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
3859 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
3860 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
3861 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
3862 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
3863 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
3864 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
3865 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
3866 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
3867 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
3868 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
3869 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
3870 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
3871 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
3872 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
3879 if ((
unsigned int) c > 255)
3883 return ((_switch_tolower_tab_ + 1)[c]);
3980 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_U |
_L |
_N)));
3985 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_U |
_L)));
3990 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_C));
3995 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_N));
4000 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (_P |
_U |
_L |
_N)));
4005 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_L));
4010 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (_P |
_U |
_L |
_N |
_B)));
4015 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & _P));
4020 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_S));
4025 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] &
_U));
4030 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(
unsigned char) c] & (
_N |
_X)));
4054 if (!strncasecmp(DOW[x], exp, 3)) {
4083 }
else if (**s ==
',') {
4086 }
else if (**s >=
'1' && **s <=
'7') {
4087 dow_t r = **s -
'0';
4103 const char *p = exp;
4118 if (range_start <= cur ? (val >= range_start && val <= cur) : (val >= range_start || val <= cur)) {
4122 }
else if (val == cur) {
4138 int a = strtol(exp, (
char **)&exp, 10);
4143 int b = strtol(++exp, (
char **)&exp, 10);
4144 if (a <= b ? (val >= a && val <=b ) : (val >= a || val <= b))
4154 char *dup = strdup(exp);
4163 int range_start, range_end;
4168 if ((p = strchr(cur,
','))) {
4174 if ((minm=strchr(cur,
':'))) {
4176 if ((maxh=strchr(minm,
'-'))) {
4177 if ((maxm=strchr(maxh,
':'))) {
4181 if ((mins=strchr(minm,
':'))) {
4186 if ((maxs=strchr(maxm,
':'))) {
4192 range_start = (atol(minh) * 60 * 60) + (atol(minm) * 60) + atol(mins);
4193 range_end = (atol(maxh) * 60 * 60) + (atol(maxm) * 60) + atol(maxs);
4194 if (range_start <= range_end ? (val >= range_start && val <= range_end) : (val >= range_start || val <= range_end)) {
4204 if ((p = strchr(p,
','))) {
4218 char *p = NULL, *h = NULL, *u = NULL;
4223 if (!strncasecmp(in,
"sip:", 4)) in += 4;
4224 else if (!strncasecmp(in,
"sips:", 5)) in += 5;
4227 if ((h = in, p = strchr(h,
'@'))) *p =
'\0', u =
in, h = p+1;
4230 for (p = h; *p; p++)
4231 if (*p ==
':' || *p ==
';' || *p ==
' ') {
4235 if (user) *user = u;
4236 if (domain) *domain = h;
4260 const char *p = num;
4281 if (len == 11 && p[0] ==
'1') {
4282 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]);
4283 }
else if (len == 10) {
4284 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]);
4295 int tmp = atoi(nptr);
4296 if (tmp < 0)
return 0;
4297 else return (
unsigned int) tmp;
4302 long tmp = atol(nptr);
4303 if (tmp < 0)
return 0;
4304 else return (
unsigned long) tmp;
4310 #ifdef HAVE_STRERROR_R 4311 #ifdef STRERROR_R_CHAR_P 4313 return strerror_r(errnum, buf, buflen);
4319 if (strerror_r(errnum, buf, buflen)) {
4324 #elif defined(WIN32) 4326 if (strerror_s(buf, buflen, errnum)) {
4347 dup = q = strdup(request->
qs);
4356 if ((next = strchr(next,
'&'))) {
4360 for (p = q; p && *p; p++) {
4361 if (*p ==
'+') *p =
' ';
4367 if ((val = strchr(name,
'='))) {
4382 int last, i, len, uri_len = 0;
4386 if (argc ==
sizeof(argv)) {
4391 for(i = 1; i < argc; i++) {
4392 if (*argv[i] ==
'\0' || !strcmp(argv[i],
".")) {
4394 }
else if (!strcmp(argv[i],
"..")) {
4396 if (last > 1) last--;
4398 argv[last++] = argv[i];
4402 for(i = 1; i < last; i++) {
4403 len = strlen(argv[i]);
4404 sprintf(uri + uri_len,
"/%s", argv[i]);
4405 uri_len += (len + 1);
4418 char *headers[64] = { 0 };
4420 char *argv[2] = { 0 };
4423 if (datalen < 16)
return status;
4426 if (*p++ ==
' ')
break;
4429 if (i == 0)
return status;
4431 if ((body = strstr(buffer,
"\r\n\r\n"))) {
4434 }
else if (( body = strstr(buffer,
"\n\n"))) {
4441 request->
_buffer = strdup(buffer);
4448 p = strchr(request->
method,
' ');
4454 if (*p !=
'/')
goto err;
4457 p = strchr(request->
uri,
' ');
4464 p = strchr(request->
uri,
'?');
4475 if (!strncmp(http,
"HTTP/1.1", 8)) {
4477 }
else if (strncmp(http,
"HTTP/1.0", 8)) {
4488 p = strchr(http,
'\n');
4498 if (header_count < 1)
goto err;
4500 for (i = 0; i < header_count; i++) {
4501 char *header, *
value;
4506 if (argc != 2)
goto err;
4511 if (*value ==
' ') value++;
4513 len = strlen(value);
4515 if (len && *(value + len - 1) ==
'\r') *(value + len - 1) =
'\0';
4519 if (!strncasecmp(header,
"User-Agent", 10)) {
4521 }
else if (!strncasecmp(header,
"Host", 4)) {
4523 p = strchr(value,
':');
4530 }
else if (!strncasecmp(header,
"Content-Type", 12)) {
4532 }
else if (!strncasecmp(header,
"Content-Length", 14)) {
4534 }
else if (!strncasecmp(header,
"Referer", 7)) {
4565 printf(
"method: %s\n", request->
method);
4567 if (request->
uri) printf(
"uri: %s\n", request->
uri);
4568 if (request->
qs) printf(
"qs: %s\n", request->
qs);
4569 if (request->
host) printf(
"host: %s\n", request->
host);
4570 if (request->
port) printf(
"port: %d\n", request->
port);
4571 if (request->
from) printf(
"from: %s\n", request->
from);
4574 if (request->
user) printf(
"user: %s\n", request->
user);
4582 printf(
"headers:\n-------------------------\n");
4585 printf(
"%s: %s\n", header->
name, header->
value);
4586 header = header->
next;
4594 FILETIME ct, et, kt, ut;
4595 GetProcessTimes(GetCurrentProcess(), &ct, &et, &kt, &ut);
4596 t->
userms = ((int64_t)ut.dwLowDateTime | ((int64_t)ut.dwHighDateTime << 32)) / 10000;
4597 t->
kernelms = ((int64_t)kt.dwLowDateTime | ((int64_t)kt.dwHighDateTime << 32)) / 10000;
4598 #elif defined(HAVE_GETRUSAGE) 4600 getrusage(RUSAGE_SELF, &r);
4601 t->
userms = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000;
4602 t->
kernelms = r.ru_stime.tv_sec * 1000 + r.ru_stime.tv_usec / 1000;
4610 #ifdef SWITCH_HAVE_GUMBO 4613 if (node->type == GUMBO_NODE_TEXT) {
4616 }
else if (node->type == GUMBO_NODE_ELEMENT && node->v.element.tag != GUMBO_TAG_SCRIPT && node->v.element.tag != GUMBO_TAG_STYLE) {
4617 GumboVector *children = &node->v.element.children;
4620 if (node->v.element.tag != GUMBO_TAG_UNKNOWN && node->v.element.tag <= GUMBO_TAG_LAST) {
4621 GumboAttribute* attr = NULL;
4622 const char *aval = NULL;
4624 if (node->v.element.tag == GUMBO_TAG_SPAN) {
4625 if ((attr = gumbo_get_attribute(&node->v.element.attributes,
"class"))) {
4630 if (aval && !strcasecmp(aval,
"Apple-converted-space")) {
4631 const char *txt = ((GumboNode*)children->data[0])->v.text.text;
4634 for (x = 0; txt[x]; x++) {
4635 if (txt[x] ==
' ') {
4640 for (x = 0; x < len*2; x++) {
4644 for (i = 0; i < children->length; ++i) {
4645 process((GumboNode*) children->data[i], stream);
4649 if (node->v.element.tag == GUMBO_TAG_P || node->v.element.tag == GUMBO_TAG_BR) {
4660 char *p, *html = NULL, *text = NULL;
4661 int x = 0, got_ct = 0;
4662 #ifdef SWITCH_HAVE_GUMBO 4663 GumboOutput *output;
4669 for(p = (
char *)str; p && *p; p++) {
4671 if (!strncasecmp(p,
"Content-Type:", 13)) {
4675 if (!got_ct)
continue;
4682 }
else if (x && (*p !=
'\r')) {
4689 #ifdef SWITCH_HAVE_GUMBO 4690 if ((output = gumbo_parse_with_options(&kGumboDefaultOptions, html, strlen(html)))) {
4691 process(output->root, &stream);
4692 gumbo_destroy_output(&kGumboDefaultOptions, output);
4695 text = (
char *)stream.
data;
4707 pid_t pid = getpid();
4709 int pid = _getpid();
4712 return (
unsigned long)pid;
4717 #if defined(HAVE_OPENSSL) 4729 md = EVP_get_digestbyname(digest_name);
4736 size = EVP_MD_size(md);
4737 if (!size || !(*digest = malloc(size))) {
4742 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 4743 mdctx = EVP_MD_CTX_new();
4745 mdctx = EVP_MD_CTX_create();
4754 EVP_MD_CTX_init(mdctx);
4755 EVP_DigestInit_ex(mdctx, md, NULL);
4756 EVP_DigestUpdate(mdctx, input, inputLen);
4757 EVP_DigestFinal_ex(mdctx, *digest, outputlen);
4759 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 4760 EVP_MD_CTX_free(mdctx);
4762 EVP_MD_CTX_destroy(mdctx);
4773 unsigned char *digest = NULL;
4778 status =
switch_digest(digest_name, &digest, input, inputLen, outputlen);
4781 if ((*digest_str = malloc(*outputlen * 2 + 1))) {
4782 for (x = i = 0; x < *outputlen; x++) {
4783 b = (digest[x] >> 4) & 15;
4784 (*digest_str)[i++] = b + (b > 9 ?
'a' - 10 :
'0');
4786 (*digest_str)[i++] = b + (b > 9 ?
'a' - 10 :
'0');
4789 (*digest_str)[i] =
'\0';
4805 char *s = strdup(_s);
4812 const char *status = NULL;
4818 #if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 33) 4819 struct mallinfo2 mi;
4838 stream->
write_function(stream,
"Total non-mmapped bytes (arena): %u\n", mi.arena);
4839 stream->
write_function(stream,
"# of free chunks (ordblks): %u\n", mi.ordblks);
4840 stream->
write_function(stream,
"# of free fastbin blocks (smblks): %u\n", mi.smblks);
4841 stream->
write_function(stream,
"# of mapped regions (hblks): %u\n", mi.hblks);
4842 stream->
write_function(stream,
"Bytes in mapped regions (hblkhd): %u\n", mi.hblkhd);
4843 stream->
write_function(stream,
"Max. total allocated space (usmblks): %u\n", mi.usmblks);
4844 stream->
write_function(stream,
"Free bytes held in fastbins (fsmblks): %u\n", mi.fsmblks);
4845 stream->
write_function(stream,
"Total allocated space (uordblks): %u\n", mi.uordblks);
4846 stream->
write_function(stream,
"Total free space (fordblks): %u\n", mi.fordblks);
4847 stream->
write_function(stream,
"Topmost releasable block (keepcost): %u\n", mi.keepcost);
4856 SIZE_T BytesToAllocate;
4859 DWORD NumberOfHeaps;
4861 HANDLE hDefaultProcessHeap;
4862 size_t CommittedSizeTotal = 0;
4863 size_t UnCommittedSizeTotal = 0;
4864 size_t SizeTotal = 0;
4865 size_t OverheadTotal = 0;
4867 NumberOfHeaps = GetProcessHeaps(0, NULL);
4868 Result = SIZETMult(NumberOfHeaps,
sizeof(*aHeaps), &BytesToAllocate);
4869 if (Result != S_OK) {
4873 hDefaultProcessHeap = GetProcessHeap();
4874 if (hDefaultProcessHeap == NULL) {
4878 aHeaps = (PHANDLE)HeapAlloc(hDefaultProcessHeap, 0, BytesToAllocate);
4879 if (aHeaps == NULL) {
4883 HeapsLength = NumberOfHeaps;
4884 NumberOfHeaps = GetProcessHeaps(HeapsLength, aHeaps);
4886 if (NumberOfHeaps == 0) {
4888 }
else if (NumberOfHeaps > HeapsLength) {
4897 stream->
write_function(stream,
"Process has %d heaps.\n", HeapsLength);
4898 for (HeapsIndex = 0; HeapsIndex < HeapsLength; ++HeapsIndex) {
4899 PROCESS_HEAP_ENTRY Entry;
4900 HANDLE hHeap = aHeaps[HeapsIndex];
4902 stream->
write_function(stream,
"Heap %d at address: %#p.\n", HeapsIndex, aHeaps[HeapsIndex]);
4905 if (HeapLock(hHeap) ==
FALSE) {
4909 Entry.lpData = NULL;
4910 while (HeapWalk(hHeap, &Entry) !=
FALSE) {
4911 if ((Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
4912 }
else if ((Entry.wFlags & PROCESS_HEAP_REGION) != 0) {
4913 CommittedSizeTotal += Entry.Region.dwCommittedSize;
4914 UnCommittedSizeTotal += Entry.Region.dwUnCommittedSize;
4917 SizeTotal += Entry.cbData;
4918 OverheadTotal += Entry.cbOverhead;
4922 if (HeapUnlock(hHeap) ==
FALSE) {
4933 HeapFree(hDefaultProcessHeap, 0, aHeaps);
4935 switch_goto_status(
"Memory usage statistics is not implemented on the current platform.", done);
4942 #define SHA256_LENGTH 32 4947 cJSON *payload = NULL;
4949 unsigned int len = 0;
4951 const char *alg = NULL;
4952 const char *typ = NULL;
4953 char *header = strdup(token);
4957 dot = strchr(header,
'.');
4962 if (len == 0)
goto end;
4963 json = cJSON_Parse(out);
4966 if (!json)
goto end;
4968 if (!alg || strcmp(alg,
"HS256"))
goto end;
4970 if (!typ || strcmp(typ,
"JWT"))
goto end;
4974 dot = strrchr(token,
'.');
4976 HMAC(EVP_sha256(), secret, strlen(secret), (
unsigned char *)token, dot - token, signature, &len);
4982 ok = !memcmp(out, signature, len);
4987 char *p = strchr(token,
'.');
4993 payload = cJSON_Parse(out);
5002 if (json) cJSON_Delete(json);
5015 unsigned int len = 0;
5017 unsigned char *bsignature;
5018 char *result = NULL;
5020 if (!secret || !payload)
return NULL;
5022 json = cJSON_CreateObject();
5024 cJSON_AddStringToObject(json,
"alg",
"HS256");
5025 cJSON_AddStringToObject(json,
"typ",
"JWT");
5026 header = cJSON_Print(json);
5028 if (!header)
return NULL;
5030 need = ((strlen(header) + 3 - 1) / 3) * 4 + 1;
5036 need = ((size + 3 - 1) / 3) * 4 + 1;
5040 to_sign =
switch_mprintf(
"%s.%s", (
char *)bheader, (
char *)bpayload);
5043 HMAC(EVP_sha256(), secret, strlen(secret), (
unsigned char *)to_sign, strlen(to_sign), signature, &len);
5048 need = ((len + 3 - 1) / 3) * 4 + 1;
5051 result =
switch_mprintf(
"%s.%s.%s", bheader, bpayload, bsignature);
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)
switch_status_t switch_digest_string(const char *digest_name, char **digest_str, const void *input, switch_size_t inputLen, unsigned int *outputlen)
unsigned int switch_queue_size(switch_queue_t *queue)
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.
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)
char * switch_core_url_encode_opt(switch_memory_pool_t *pool, const char *url, switch_bool_t double_encode)
const char *const const double number
#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.
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_status_t switch_frame_buffer_create(switch_frame_buffer_t **fbP, switch_size_t qlen)
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]
int switch_frame_buffer_size(switch_frame_buffer_t *fb)
switch_bool_t is_port_in_node(int port, switch_network_node_t *node)
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)
char * switch_core_session_url_encode(switch_core_session_t *session, const char *url)
int old_switch_toupper(int c)
switch_priority_t
Priority Indication.
unsigned int switch_atoui(const char *nptr)
switch_bool_t switch_network_list_validate_ip6_port_token(switch_network_list_t *list, ip_t ip, int port, const char **token)
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)
#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)
static unsigned int separate_string_blank_delim_cheap(const char *buf, const char **array, unsigned int larray[], unsigned int arraylen)
switch_status_t switch_find_local_ip(char *buf, int len, int *mask, int family)
void * switch_calloc(size_t nmemb, size_t size)
const char *const const char *const const cJSON *const value
#define SWITCH_RTP_MAX_BUF_LEN
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
int switch_ispunct(int c)
unsigned int switch_separate_string_cheap(const char *buf, char delim, const char **array, unsigned int larray[], unsigned int arraylen)
static void * switch_must_malloc(size_t _b)
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)
const char * switch_memory_usage_stream(switch_stream_handle_t *stream)
char * switch_separate_paren_args(char *str)
const char * switch_dow_int2str(int val)
int switch_strcasecmp_any(const char *str,...)
switch_status_t switch_network_list_add_cidr_port_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token, switch_network_port_range_p port)
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
#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
#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)
const char * content_type
#define SWITCH_URL_UNSAFE
int switch_split_user_domain(char *in, char **user, char **domain)
Split a user string as user and domain.
switch_bool_t _destroy_headers
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.
unsigned long switch_getpid(void)
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)
static char * switch_safe_strdup(const char *it)
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_core_session_url_encode_opt(switch_core_session_t *session, const char *url, switch_bool_t double_encode)
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)
int ports[MAX_NETWORK_PORTS]
switch_status_t switch_frame_buffer_destroy(switch_frame_buffer_t **fbP)
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.
cJSON * switch_jwt_verify(const char *secret, const char *token)
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
int switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2, switch_bool_t ip_only)
#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)
char * switch_network_port_range_to_string(switch_network_port_range_p port)
struct switch_frame_node_s * next
char * switch_must_strdup(const char *_s)
#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.
const char * cJSON_GetObjectCstr(const cJSON *object, const char *string)
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
#define SWITCH_STANDARD_STREAM(s)
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)
char * switch_core_url_encode(switch_memory_pool_t *pool, const char *url)
#define MAX_NETWORK_PORTS
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_status_t switch_frame_buffer_push(switch_frame_buffer_t *fb, void *ptr)
switch_directories SWITCH_GLOBAL_dirs
switch_status_t switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
switch_bool_t switch_network_list_validate_ip_port_token(switch_network_list_t *list, uint32_t ip, int port, const char **token)
struct fspr_sockaddr_t switch_sockaddr_t
switch_status_t switch_frame_buffer_pop(switch_frame_buffer_t *fb, void **ptr)
#define switch_str_nil(s)
Make a null string a blank string instead.
struct fspr_thread_mutex_t switch_mutex_t
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)
switch_stream_handle_write_function_t write_function
unsigned char switch_char_to_rfc2833(char key)
Return the RFC2833 event based on an key character.
switch_memory_pool_t * pool
switch_size_t content_length
switch_status_t
Common return values.
char * switch_pool_strip_whitespace(switch_memory_pool_t *pool, const char *str)
#define switch_goto_status(_status, _label)
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)
switch_status_t switch_frame_buffer_trypop(switch_frame_buffer_t *fb, void **ptr)
char * switch_html_strip(const char *str)
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)
switch_status_t switch_digest(const char *digest_name, unsigned char **digest, const void *input, switch_size_t inputLen, unsigned int *outputlen)
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)
switch_bool_t switch_is_uint_in_range(const char *str, unsigned int from, unsigned int to)
Check if a 32 bit unsigned number is in a range.
int switch_isalnum(int c)
char * switch_strerror_r(int errnum, char *buf, switch_size_t buflen)
switch_network_port_range_t port_range
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
char * switch_jwt_sign(const char *secret, const uint8_t *payload, switch_size_t size)
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
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
#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)
struct fspr_pool_t switch_memory_pool_t
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
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
switch_status_t switch_frame_buffer_trypush(switch_frame_buffer_t *fb, void *ptr)
const short * _switch_tolower_tab_
const char * switch_stristr(const char *instr, const char *str)
switch_size_t switch_b64_decode(const char *in, char *out, switch_size_t olen)
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)
switch_size_t bytes_header
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.
switch_size_t bytes_buffered
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, switch_network_port_range_p port)
#define SWITCH_UUID_FORMATTED_LENGTH
switch_bool_t switch_dow_cmp(const char *exp, int val)
switch_event_header_t * headers
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)
static unsigned int separate_string_char_delim_cheap(const char *buf, char delim, const char **array, unsigned int larray[], unsigned int arraylen)
char * switch_format_number(const char *num)
switch_status_t switch_network_list_add_host_port_mask(switch_network_list_t *list, const char *host, const char *mask_str, switch_bool_t ok, switch_network_port_range_p port)
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)