62 #include <switch_private.h> 66 #include <fspr_file_io.h> 75 int (*gl_errfunc) (
const char *, int);
79 #define GLOB_APPEND 0x0001 80 #define GLOB_DOOFFS 0x0002 81 #define GLOB_ERR 0x0004 82 #define GLOB_MARK 0x0008 83 #define GLOB_NOCHECK 0x0010 84 #define GLOB_NOSORT 0x0020 87 #define GLOB_NOSPACE (-1) 88 #define GLOB_ABORTED (-2) 89 #define GLOB_NOMATCH (-3) 90 #define GLOB_NOSYS (-4) 92 #define GLOB_ALTDIRFUNC 0x0040 93 #define GLOB_MAGCHAR 0x0100 94 #define GLOB_NOMAGIC 0x0200 95 #define GLOB_QUOTE 0x0400 96 #define GLOB_LIMIT 0x1000 98 int glob(
const char *,
int,
int (*)(
const char *,
int), glob_t *);
99 void globfree(glob_t *);
103 #define SWITCH_XML_WS "\t\r\n " 104 #define SWITCH_XML_ERRL 128 109 char *val = strchr(keyval,
'=');
113 while (*val && *val ==
' ') {
117 while (*ve && *ve ==
' ') {
127 char *tmp = (
char *) exec_result.
data;
128 tmp = &tmp[strlen(tmp)-1];
129 while (tmp >= (
char *) exec_result.
data && ( tmp[0] ==
' ' || tmp[0] ==
'\n') ) {
145 char *val = strchr(keyval,
'=');
149 while (*val && *val ==
' ') {
153 while (*ve && *ve ==
' ') {
159 char *external_ip = NULL;
165 if (!
zstr(external_ip)) {
166 char *tmp = external_ip;
167 tmp = &tmp[strlen(tmp) - 1];
168 while (tmp >= external_ip && (tmp[0] ==
' ' || tmp[0] ==
'\n')) {
185 char *val = strchr(keyval,
'=');
191 char *data = getenv(val);
200 static int preprocess(
const char *cwd,
const char *file, FILE *write_fd,
int rlevel);
272 for (x = 0; x < strlen(str); x++) {
273 buf[x] = (char) tolower((
int) str[x]);
276 if (!SECTIONS[x].
name) {
279 if (strstr(buf, SECTIONS[x].name)) {
280 sections |= SECTIONS[x].
section;
294 for (ptr = BINDINGS; ptr; ptr = ptr->
next) {
295 if (ptr == *binding) {
299 BINDINGS = (*binding)->
next;
317 for (ptr = BINDINGS; ptr; ptr = ptr->
next) {
324 BINDINGS = ptr->
next;
362 assert(
function != NULL);
373 for (ptr = BINDINGS; ptr && ptr->
next; ptr = ptr->
next);
382 *ret_binding = binding;
394 if (!(childname && attrname && value)) {
400 if (aname && !strcasecmp(aname, value)) {
411 const char *names[256] = { 0 };
412 const char *vals[256] = { 0 };
415 const char *attrname, *
value = NULL;
417 va_start(ap, childname);
420 if ((attrname = va_arg(ap,
const char *))) {
421 value = va_arg(ap,
const char *);
423 if (attrname && value) {
434 if (!(childname && i)) {
439 for (x = 0; x < i; x++) {
440 if (names[x] && vals[x]) {
444 if (*vals[x] ==
'!') {
445 const char *sval = vals[x] + 1;
446 if (strcasecmp(aname, sval)) {
450 if (!strcasecmp(aname, vals[x])) {
467 xml = (xml) ? xml->
child : NULL;
476 for (; xml && idx; idx--)
486 return ret ? ret :
"";
495 if (!xml || !xml->
attr)
497 while (xml->
attr[i] && attr && strcmp(attr, xml->
attr[i]))
500 return xml->
attr[i + 1];
509 for (i = 0; root->
attr[i] && xml->
name && strcmp(xml->
name, root->
attr[i][0]); i++);
512 while (root->
attr[i][j] && attr && strcmp(attr, root->
attr[i][j]))
514 return (root->
attr[i][j]) ? root->
attr[i][j + 1] : NULL;
520 char *
name = va_arg(ap,
char *);
524 idx = va_arg(ap,
int);
561 if (!root || !root->
pi) {
565 while (root->
pi[i] && strcmp(target, root->
pi[i][0])) {
569 return (
const char **) ((root->
pi[i]) ? root->
pi[i] + 1 : SWITCH_XML_NIL);
579 if (!root || !root->
s) {
583 for (t = root->
s; t && t < s; t++)
603 char *e, *r = s, *m = s;
604 unsigned long b, c, d, l;
610 memmove(s, (s + 1), strlen(s));
615 while (*s && *s !=
'&' && (*s !=
'%' || t !=
'%') && !isspace((
unsigned char) (*s)))
620 else if (t !=
'c' && !strncmp(s,
"&#", 2)) {
627 if (!isxdigit((
int)*code)) {
631 c = strtoul(code, &e, base);
632 if (!c || *e !=
';') {
639 else if (c > 0x7FFFFFFF) {
643 for (b = 0, d = c; d; d /= 2)
647 *(s++) = (
char) ((0xFF << (7 -
b)) | (c >> (6 *
b)));
649 *(s++) = (
char) (0x80 | ((c >> (6 * --
b)) & 0x3F));
652 memmove(s, strchr(s,
';') + 1, strlen(strchr(s,
';')));
653 }
else if ((*s ==
'&' && (t ==
'&' || t ==
' ' || t ==
'*')) || (*s ==
'%' && t ==
'%')) {
654 for (b = 0; ent[
b] && strncmp(s + 1, ent[b], strlen(ent[b])); b += 2);
657 if ((c = (
unsigned long) strlen(ent[b])) - 1 > (e = strchr(s,
';')) - s) {
658 l = (d = (
unsigned long) (s - r)) + c + (
unsigned long) strlen(e);
667 e = strchr((s = r + d),
';');
670 memmove(s + c, e + 1, strlen(e));
671 strncpy(s, ent[b], c);
674 }
else if ((t ==
' ' || t ==
'*') && isspace((
int) (*s)))
681 for (s = r; *s; s++) {
682 if ((l = (
unsigned long) strspn(s,
" ")))
683 memmove(s, s + l, strlen(s + l) + 1);
684 while (*s && *s !=
' ')
687 if (--s >= r && *s ==
' ')
698 if (!root || !root->
cur) {
721 if (!root || !root->
cur) {
727 if (!xml || !xml->
name || !len)
741 xml->
txt = strcpy(tmp, xml->
txt);
743 strcpy(xml->
txt + l, s);
756 return switch_xml_err(root, s,
"unexpected closing tag </%s>", name);
770 while (*s && *s !=
'&')
774 if (!strncmp(s + 1, name, strlen(name)))
776 for (i = 0; ent[i] && strncmp(ent[i], s + 1, strlen(ent[i])); i += 2);
799 if (!strcmp(target,
"xml")) {
800 if ((s = strstr(s,
"standalone")) && !strncmp(s + strspn(s + 10,
SWITCH_XML_WS "='\"") + 10,
"yes", 3))
805 if (root->
pi == (
char ***)(SWITCH_XML_NIL) || !root->
pi || !root->
pi[0]) {
810 while (root->
pi[i] && strcmp(target, root->
pi[i][0]))
820 root->
pi[i][1] = (
char *) (root->
pi[i + 1] = NULL);
824 while (root->
pi[i][j])
829 root->
pi[i][j + 2] = stmp;
830 strcpy(root->
pi[i][j + 2] + j - 1, (root->
xml.
name) ?
">" :
"<");
831 root->
pi[i][j + 1] = NULL;
838 char q, *c, *t, *n = NULL, *v, **ent, **pe;
844 for (s[len] =
'\0'; s;) {
845 while (*s && *s !=
'<' && *s !=
'%')
850 else if (!strncmp(s,
"<!ENTITY", 8)) {
858 if ((q = *(v++)) !=
'"' && q !=
'\'') {
863 use_pe = (*c ==
'%');
864 for (i = 0, ent = (use_pe) ? pe : root->
ent; ent[i]; i++);
873 if ((s = strchr(v, q)))
884 }
else if (!strncmp(s,
"<!ATTLIST", 9)) {
894 for (i = 0; root->
attr[i] && n && strcmp(n, root->
attr[i][0]); i++);
911 c = (strncmp(s,
"CDATA", 5)) ? (
char *)
"*" : (
char *)
" ";
912 if (!strncmp(s,
"NOTATION", 8))
914 s = (*s ==
'(') ? strchr(s,
')') : s + strcspn(s,
SWITCH_XML_WS);
921 if (!strncmp(s,
"#FIXED", 6))
928 }
else if ((*s ==
'"' || *s ==
'\'') &&
929 (s = strchr(v = s + 1, *s)))
936 if (!root->
attr[i]) {
940 root->
attr[i][0] = t;
941 root->
attr[i][1] = (
char *) (root->
attr[i + 1] = NULL);
944 for (j = 1; root->
attr[i][j]; j += 3);
947 root->
attr[i] = sstmp;
948 root->
attr[i][j + 3] = NULL;
949 root->
attr[i][j + 2] = c;
951 root->
attr[i][j] = n;
953 }
else if (!strncmp(s,
"<!--", 4))
954 s = strstr(s + 4,
"-->");
955 else if (!strncmp(s,
"<?", 2)) {
956 if ((s = strstr(c = s + 2,
"?>")))
958 }
else if (*s ==
'<')
975 int b, be = (**s ==
'\xFE') ? 1 : (**s ==
'\xFF') ? 0 : -1;
984 for (sl = 2; sl < *len - 1; sl += 2) {
985 c = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
986 : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
987 if (c >= 0xD800 && c <= 0xDFFF && (sl += 2) < *len - 1) {
988 d = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
989 : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
990 c = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000;
993 while (l + 6 > max) {
1001 for (b = 0, d = c; d; d /= 2)
1004 u[l++] = (char) ((0xFF << (7 - b)) | (c >> (6 * b)));
1006 u[l++] = (char) (0x80 | ((c >> (6 * --b)) & 0x3F));
1018 if (!attr || attr == SWITCH_XML_NIL)
1023 for (i = c / 2 - 1; i >= 0 ; i--) {
1027 free(attr[(i * 2) + 1]);
1035 switch_xml_root_t root;
1056 char q, e, *d, **attr, **a = NULL;
1063 root->
e = (root->
s = s) + len;
1068 while (*s && *s !=
'<')
1074 attr = (
char **) SWITCH_XML_NIL;
1077 if (isalpha((
int) (*s)) || *s ==
'_' || *s ==
':' || (int8_t) * s <
'\0') {
1079 return switch_xml_err(root, d,
"markup outside of root element");
1082 while (isspace((
int) (*s)))
1085 if (*s && *s !=
'/' && *s !=
'>')
1086 for (i = 0; (a = root->
attr[i]) && strcmp(a[0], d); i++);
1088 for (l = 0; *s && *s !=
'/' && *s !=
'>'; l += 2) {
1093 strcpy(attr[l + 3] + (l / 2),
" ");
1095 attr[l + 1] = (
char *)
"";
1099 if (*s ==
'=' || isspace((
int) (*s))) {
1102 if (q ==
'"' || q ==
'\'') {
1104 while (*s && *s != q)
1113 for (j = 1; a && a[j] && strcmp(a[j], attr[l]); j += 3);
1115 if (attr[l + 1] < d || attr[l + 1] > s)
1119 while (isspace((
int) (*s)))
1125 if ((*s && *s !=
'>') || (!*s && e !=
'>')) {
1132 }
else if ((q = *s) ==
'>' || (!*s && e ==
'>')) {
1141 }
else if (*s ==
'/') {
1142 char *close_pos = d - 1;
1144 if (!(q = *s) && e !=
'>')
1149 if (isspace((
int) (*s = q)))
1151 }
else if (!strncmp(s,
"!--", 3)) {
1152 if (!(s = strstr(s + 3,
"--")) || (*(s += 2) !=
'>' && *s) || (!*s && e !=
'>'))
1154 }
else if (!strncmp(s,
"![CDATA[", 8)) {
1155 if ((s = strstr(s,
"]]>"))) {
1163 }
else if (!strncmp(s,
"!DOCTYPE", 8)) {
1164 for (l = 0; *s && ((!l && *s !=
'>') || (l && (*s !=
']' || *(s + strspn(s + 1,
SWITCH_XML_WS) + 1) !=
'>'))); l = (*s ==
'[') ? 1 : l)
1165 s += strcspn(s + 1,
"[]>") + 1;
1166 if (!*s && e !=
'>')
1168 d = (l) ? strchr(d,
'[') + 1 : d;
1171 }
else if (*s ==
'?') {
1174 }
while (s && *(++s) && *s !=
'>');
1175 if (!s || (!*s && e !=
'>'))
1186 if (*s && *s !=
'<') {
1187 while (*s && *s !=
'<')
1210 switch_xml_root_t root;
1243 switch_xml_root_t root;
1251 if (fstat(fd, &st) == -1 || !st.st_size) {
1257 if (!(0<(l = read(fd, m, st.st_size)))
1274 char *ep = ebuf + elen - 1;
1276 if (!strstr(rp,
"$${")) {
1277 *newlen = strlen(buf);
1281 while (*rp && wp < ep) {
1283 if (*rp ==
'$' && *(rp + 1) ==
'$' && *(rp + 2) ==
'{') {
1293 for (p = val; p && *p && wp <= ep; p++) {
1300 *err =
"unterminated ${var}";
1312 *newlen = strlen(ebuf);
1317 static FILE *
preprocess_exec(
const char *cwd,
const char *command, FILE *write_fd,
int rlevel)
1323 if (!command || !strlen(command))
goto end;
1325 if ((fp = _popen(command,
"r"))) {
1326 while (fgets(buffer,
sizeof(buffer), fp) != NULL) {
1327 if (fwrite(buffer, 1, strlen(buffer), write_fd) <= 0) {
1338 switch_snprintf(buffer,
sizeof(buffer),
"<!-- exec can not execute [%s] -->", command);
1339 fwrite( buffer, 1, strlen(buffer), write_fd);
1342 int fds[2], pid = 0;
1354 char buf[1024] =
"";
1357 while ((bytes = read(fds[0], buf,
sizeof(buf))) > 0) {
1358 if (fwrite(buf, 1, bytes, write_fd) <= 0) {
1363 waitpid(pid, NULL, 0);
1367 dup2(fds[1], STDOUT_FILENO);
1380 static FILE *
preprocess_glob(
const char *cwd,
const char *pattern, FILE *write_fd,
int rlevel)
1382 char *full_path = NULL;
1383 char *dir_path = NULL, *e = NULL;
1390 pattern = full_path;
1393 glob_return = glob(pattern, GLOB_ERR, NULL, &glob_data);
1394 if (glob_return == GLOB_NOSPACE || glob_return == GLOB_ABORTED) {
1397 }
else if (glob_return == GLOB_NOMATCH) {
1402 for (n = 0; n < glob_data.gl_pathc; ++n) {
1408 if (
preprocess(dir_path, glob_data.gl_pathv[n], write_fd, rlevel) < 0) {
1415 globfree(&glob_data);
1424 static int preprocess(
const char *cwd,
const char *file, FILE *write_fd,
int rlevel)
1426 FILE *read_fd = NULL;
1428 char *q, *cmd, *
buf = NULL, *ebuf = NULL;
1437 if (!(read_fd = fopen(file,
"r"))) {
1438 const char *reason = strerror(errno);
1443 setvbuf(read_fd, (
char *) NULL, _IOFBF, 65536);
1447 const char *err = NULL;
1460 while (!(bp =
expand_vars(buf, ebuf, eblen, &cur, &err))) {
1473 if (strstr(buf,
"<include>") || strstr(buf,
"</include>") || strstr(buf,
"<?")) {
1478 if ((e = strstr(buf,
"-->"))) {
1488 if (*(tcmd - 1) !=
'<') {
1491 if ((e = strstr(tcmd,
"/>"))) {
1494 if (fwrite(e, 1, (
unsigned) strlen(e), write_fd) != (
int) strlen(e)) {
1514 if ((e = strchr(tcmd,
'"'))) {
1532 if ((e = strchr(targ,
'"'))) {
1536 if (!strcasecmp(tcmd,
"set")) {
1537 char *
name = (
char *) targ;
1538 char *val = strchr(name,
'=');
1542 while (*val && *val ==
' ') {
1546 while (*ve && *ve ==
' ') {
1555 }
else if (!strcasecmp(tcmd,
"exec-set")) {
1557 }
else if (!strcasecmp(tcmd,
"stun-set")) {
1559 }
else if (!strcasecmp(tcmd,
"env-set")) {
1561 }
else if (!strcasecmp(tcmd,
"include")) {
1563 }
else if (!strcasecmp(tcmd,
"exec")) {
1570 if ((cmd = strstr(bp,
"<!--#"))) {
1571 if (fwrite(bp, 1, (
unsigned) (cmd - bp), write_fd) != (
unsigned) (cmd - bp)) {
1574 if ((e = strstr(cmd,
"-->"))) {
1577 if (fwrite(e, 1, (
unsigned) strlen(e), write_fd) != (
int) strlen(e)) {
1585 if ((e = strchr(cmd,
'\r')) || (e = strchr(cmd,
'\n'))) {
1589 if ((arg = strchr(cmd,
' '))) {
1591 if ((q = strchr(arg,
'"'))) {
1594 if ((qq = strchr(qq,
'"'))) {
1600 if (!strcasecmp(cmd,
"set")) {
1602 char *val = strchr(name,
'=');
1606 while (*val && *val ==
' ') {
1610 while (*ve && *ve ==
' ') {
1619 }
else if (!strcasecmp(cmd,
"exec-set")) {
1621 }
else if (!strcasecmp(cmd,
"stun-set")) {
1623 }
else if (!strcasecmp(cmd,
"include")) {
1625 }
else if (!strcasecmp(cmd,
"exec")) {
1633 if (fwrite(bp, 1, (
unsigned) cur, write_fd) != (
int) cur) {
1653 switch_xml_root_t root;
1655 if ((fd = open(file, O_RDONLY, 0)) > -1) {
1656 if (fstat(fd, &st) == -1 || !st.st_size) {
1663 if (!(0 < (l = read(fd, m, st.st_size)))) {
1691 FILE *write_fd = NULL;
1693 char *new_file = NULL;
1694 char *new_file_tmp = NULL;
1695 const char *abs, *absw;
1697 abs = strrchr(file,
'/');
1698 absw = strrchr(file,
'\\');
1700 abs > absw ? abs++ : (abs = ++absw);
1715 if ((write_fd = fopen(new_file_tmp,
"w+")) == NULL) {
1719 setvbuf(write_fd, (
char *) NULL, _IOFBF, 65536);
1726 if ( rename(new_file_tmp,new_file) ) {
1730 if ((fd = open(new_file, O_RDONLY, 0)) > -1) {
1758 const char *tag_name,
1759 const char *key_name,
1760 const char *key_value,
1772 for (binding = BINDINGS; binding; binding = binding->
next) {
1777 if ((xml = binding->
function(section, tag_name, key_name, key_value, params, binding->
user_data))) {
1778 const char *err = NULL;
1788 if (aname && !strcasecmp(aname,
"not found")) {
1860 const char *domain_name,
1909 const char *type =
"!pointer";
1913 if (!strcasecmp(val,
"any")) {
1927 if (!strcasecmp(key,
"id")) {
1944 switch_xml_t group = NULL, groups = NULL, users = NULL;
1995 if (var && ivar && !strcasecmp(var, ivar)) {
2016 do_merge(user, group,
"params",
"param");
2017 do_merge(user, group,
"variables",
"variable");
2018 do_merge(user, group,
"profile-variables",
"variable");
2019 do_merge(user, domain,
"params",
"param");
2020 do_merge(user, domain,
"variables",
"variable");
2021 do_merge(user, domain,
"profile-variables",
"variable");
2023 if (!
zstr(domain_name)) {
2033 char mega_key[1024];
2036 char *expires_val = NULL;
2040 if (key && user_name && !domain_name) {
2044 if (key && user_name && domain_name) {
2045 switch_snprintf(mega_key,
sizeof(mega_key),
"%s%s%s", key, user_name, domain_name);
2084 char mega_key[1024];
2088 switch_snprintf(mega_key,
sizeof(mega_key),
"%s%s%s", key, user_name, domain_name);
2092 char *expires_lookup = NULL;
2099 time_expires = atoll(expires_lookup);
2101 if (time_expires < time_now) {
2119 char mega_key[1024];
2121 char *expires_lookup;
2123 switch_snprintf(mega_key,
sizeof(mega_key),
"%s%s%s", key, user_name, domain_name);
2151 char *keys[10] = {0};
2154 if (strchr(key,
':')) {
2158 keys[0] = (
char *)key;
2162 for(i = 0; i < nkeys; i++) {
2167 const char *cacheable = NULL;
2173 if (!
zstr(cacheable)) {
2178 int cache_ms = atol(cacheable);
2180 user_name, domain_name, cache_ms);
2182 expires = time_now + (cache_ms * 1000);
2201 const char *user_name,
2202 const char *domain_name,
2209 switch_xml_t group = NULL, groups = NULL, users = NULL;
2337 MAIN_XML_ROOT = new_main;
2339 MAIN_XML_ROOT->
refs++;
2342 if (old_root->
refs) {
2346 if (!old_root->
refs) {
2362 XML_OPEN_ROOT_FUNCTION = func;
2363 XML_OPEN_ROOT_FUNCTION_USER_DATA = user_data;
2378 if (XML_OPEN_ROOT_FUNCTION) {
2397 char path_buf[1024];
2401 if (MAIN_XML_ROOT) {
2411 switch_copy_string(not_so_threadsafe_error_buffer, *err,
sizeof(not_so_threadsafe_error_buffer));
2423 *err =
"Cannot Open log directory or XML Root!";
2451 XML_MEMORY_POOL =
pool;
2463 assert(pool != NULL);
2481 if (MAIN_XML_ROOT) {
2483 MAIN_XML_ROOT = NULL;
2505 assert(MAIN_XML_ROOT != NULL);
2519 const char *e = NULL;
2521 int expecting_x_utf_8_char = 0;
2522 int unicode_char = 0x000000;
2532 while (*dlen + 10 > *max) {
2540 (*dst)[(*dlen)++] = *s;
2546 *dlen += sprintf(*dst + *dlen,
"&");
2549 if (*(s + 1) ==
'!') {
2550 (*dst)[(*dlen)++] = *s;
2554 *dlen += sprintf(*dst + *dlen,
"<");
2557 *dlen += sprintf(*dst + *dlen,
">");
2560 *dlen += sprintf(*dst + *dlen, (a) ?
""" :
"\"");
2563 *dlen += sprintf(*dst + *dlen, (a) ?
"
" :
"\n");
2566 *dlen += sprintf(*dst + *dlen, (a) ?
"	" :
"\t");
2569 *dlen += sprintf(*dst + *dlen,
"
");
2572 if (use_utf8_encoding && expecting_x_utf_8_char == 0 && ((*s >> 8) & 0x01)) {
2574 for (;num<4;num++) {
2575 if (! ((*s >> (7-num)) & 0x01)) {
2581 unicode_char = *s & 0x1f;
2584 unicode_char = *s & 0x0f;
2587 unicode_char = *s & 0x07;
2594 expecting_x_utf_8_char = num - 1;
2596 }
else if (use_utf8_encoding && expecting_x_utf_8_char > 0) {
2597 if (((*s >> 6) & 0x03) == 0x2) {
2599 unicode_char = unicode_char << 6;
2600 unicode_char = unicode_char | (*s & 0x3f);
2603 expecting_x_utf_8_char = 0;
2606 expecting_x_utf_8_char--;
2607 if (expecting_x_utf_8_char == 0) {
2608 *dlen += sprintf(*dst + *dlen,
"&#x%X;", unicode_char);
2611 (*dst)[(*dlen)++] = *s;
2619 #define XML_INDENT " " 2639 if (!isroot && xml->
parent) {
2646 while (*len + strlen(xml->
name) + 5 + (strlen(
XML_INDENT) * (*count)) + 1 > *max) {
2650 if (*len && *(*s + (*len) - 1) ==
'>') {
2651 *len += sprintf(*s + *len,
"\n");
2653 for (lcount = 0; lcount < *
count; lcount++) {
2654 *len += sprintf(*s + *len,
"%s",
XML_INDENT);
2657 *len += sprintf(*s + *len,
"<%s", xml->
name);
2658 for (i = 0; xml->
attr[i]; i += 2) {
2661 while (*len + strlen(xml->
attr[i]) + 7 + (strlen(
XML_INDENT) * (*count)) > *max) {
2665 *len += sprintf(*s + *len,
" %s=\"", xml->
attr[i]);
2667 *len += sprintf(*s + *len,
"\"");
2670 for (i = 0; attr[i] && strcmp(attr[i][0], xml->
name); i++);
2671 for (j = 1; attr[i] && attr[i][j]; j += 3) {
2672 if (!attr[i][j + 1] ||
switch_xml_attr(xml, attr[i][j]) != attr[i][j + 1])
2674 while (*len + strlen(attr[i][j]) + 8 + (strlen(
XML_INDENT) * (*count)) > *max) {
2678 *len += sprintf(*s + *len,
" %s=\"", attr[i][j]);
2680 *len += sprintf(*s + *len,
"\"");
2683 *len += sprintf(*s + *len, (xml->
child || xml->
txt) ?
">" :
"/>\n");
2693 while (*len + strlen(xml->
name) + 5 + (strlen(
XML_INDENT) * (*count)) > *max) {
2698 if (*(*s + (*len) - 1) ==
'\n') {
2699 for (lcount = 0; lcount < *
count; lcount++) {
2700 *len += sprintf(*s + *len,
"%s",
XML_INDENT);
2703 *len += sprintf(*s + (*len),
"</%s>\n", xml->
name);
2706 while (txt[off] && off < xml->off)
2709 if (!isroot && xml->
ordered) {
2761 switch_xml_root_t root = (switch_xml_root_t)
xml;
2772 len += sprintf(s + len,
"<?xml version=\"1.0\"?>\n");
2775 if (!xml || !xml->
name) {
2779 while (root->xml.parent) {
2783 for (i = 0; !p && root->pi[i]; i++) {
2784 for (k = 2; root->pi[i][k - 1]; k++);
2785 for (j = 1; (n = root->pi[i][j]); j++) {
2786 if (root->pi[i][k][j - 1] ==
'>') {
2789 while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max) {
2792 len += sprintf(s + len,
"<?%s%s%s?>", t, *n ?
" " :
"", n);
2798 for (i = 0; !p && root->pi[i]; i++) {
2799 for (k = 2; root->pi[i][k - 1]; k++);
2800 for (j = 1; (n = root->pi[i][j]); j++) {
2801 if (root->pi[i][k][j - 1] ==
'<') {
2804 while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max) {
2807 len += sprintf(s + len,
"\n<?%s%s%s?>", t, *n ?
" " :
"", n);
2817 switch_xml_root_t root;
2854 #if (_MSC_VER >= 1400) // VC8+ 2855 __analysis_assume(
sizeof(root->
ent) > 44);
2857 for (i = 10; root->
ent[i]; i += 2)
2858 if ((s = root->
ent[i + 1]) < root->
s || s > root->
e)
2862 for (i = 0; (a = root->
attr[i]); i++) {
2863 for (j = 1; a[j++]; j += 2)
2864 if (a[j] && (a[j] < root->
s || a[j] > root->
e))
2871 for (i = 0; root->
pi[i]; i++) {
2872 for (j = 1; root->
pi[i][j]; j++);
2873 free(root->
pi[i][j + 1]);
2902 while (xml && xml->
parent)
2910 static const char *ent[] = {
"lt;",
"<",
"gt;",
">",
"quot;",
""",
2911 "apos;",
"'",
"amp;",
"&", NULL
2916 root->
xml.
name = (
char *) name;
2918 strcpy(root->
err, root->
xml.
txt = (
char *)
"");
2920 root->
attr = root->
pi = (
char ***) (root->
xml.
attr = SWITCH_XML_NIL);
2933 if ((head = dest->
child)) {
2934 if (head->
off <= off) {
2943 for (cur = head, prev = NULL; cur && strcmp(cur->
name, xml->
name); prev =
cur, cur = cur->
sibling);
2944 if (cur && cur->off <= off) {
2945 while (cur->next && cur->next->off <= off)
2953 for (cur = head, prev = NULL; cur && cur->
off <= off; prev =
cur, cur = cur->sibling);
2975 child->
name = (
char *) name;
2979 child->
txt = (
char *)
"";
2988 if (!xml)
return NULL;
3000 xml->
txt = (
char *) txt;
3007 if (!xml)
return NULL;
3019 while (xml->
attr[l] && strcmp(xml->
attr[l], name))
3021 if (!xml->
attr[l]) {
3024 if (xml->
attr == SWITCH_XML_NIL) {
3031 xml->
attr[l] = (
char *) name;
3032 xml->
attr[l + 2] = NULL;
3034 strcpy(xml->
attr[l + 3] + c,
" ");
3039 for (c = l; xml->
attr[c]; c += 2);
3044 free(xml->
attr[l + 1]);
3053 xml->
attr[l + 1] = (
char *) value;
3059 memmove(xml->
attr + l, xml->
attr + l + 2, (c - l + 2) *
sizeof(
char*));
3061 memmove(xml->
attr[c + 1] + (l / 2), xml->
attr[c + 1] + (l / 2) + 1, (c / 2) - (l / 2));
3062 xml->
attr[c + 1][c / 2] =
'\0';
3079 if (!xml)
return NULL;
3087 if (!xml)
return NULL;
3119 if (strcmp(cur->
name, xml->
name)) {
3128 while (cur->
next && cur->
next != xml)
3156 int loffset = -1000;
3157 int eoffset = -1000;
3160 int time_match = -1;
3168 loffset = atoi(tzoff);
3176 }
else if (!
zstr(tzname)) {
3182 if (eoffset == -1000) {
3186 if (loffset == -1000) {
3191 if (time_match && tzoff) {
3192 time_match = loffset == eoffset;
3194 "XML DateTime Check: TZOFFSET[%d] == %d (%s)\n", eoffset, loffset, time_match ?
"PASS" :
"FAIL");
3198 if (time_match && dst > -1) {
3199 time_match = (tm2.
tm_isdst > 0 && dst > 0);
3201 "XML DateTime Check: DST[%s] == %s (%s)\n",
3202 tm2.
tm_isdst > 0 ?
"true" :
"false", dst > 0 ?
"true" :
"false", time_match ?
"PASS" :
"FAIL");
3206 if (time_match && xdt) {
3209 switch_strftime(tmpdate, &retsize,
sizeof(tmpdate),
"%Y-%m-%d %H:%M:%S", &tm);
3212 "XML DateTime Check: date time[%s] =~ %s (%s)\n", tmpdate, xdt, time_match ?
"PASS" :
"FAIL");
3215 if (time_match && xyear) {
3219 "XML DateTime Check: year[%d] =~ %s (%s)\n", test, xyear, time_match ?
"PASS" :
"FAIL");
3222 if (time_match && xyday) {
3226 "XML DateTime Check: day of year[%d] =~ %s (%s)\n", test, xyday, time_match ?
"PASS" :
"FAIL");
3229 if (time_match && xmon) {
3230 int test = tm.
tm_mon + 1;
3233 "XML DateTime Check: month[%d] =~ %s (%s)\n", test, xmon, time_match ?
"PASS" :
"FAIL");
3236 if (time_match && xmday) {
3240 "XML DateTime Check: day of month[%d] =~ %s (%s)\n", test, xmday, time_match ?
"PASS" :
"FAIL");
3243 if (time_match && xweek) {
3244 int test = (int) (tm.
tm_yday / 7 + 1);
3247 "XML DateTime Check: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ?
"PASS" :
"FAIL");
3250 if (time_match && xmweek) {
3252 int firstdow = (int) (7 - (tm.
tm_mday - (tm.
tm_wday + 1)) % 7) % 7;
3254 int test = (int) ceil((tm.
tm_mday + firstdow) / 7.0);
3257 "XML DateTime: week of month[%d] =~ %s (%s)\n", test, xmweek, time_match ?
"PASS" :
"FAIL");
3260 if (time_match && xwday) {
3264 "XML DateTime Check: day of week[%s] =~ %s (%s)\n",
switch_dow_int2str(test), xwday, time_match ?
"PASS" :
"FAIL");
3266 if (time_match && xhour) {
3270 "XML DateTime Check: hour[%d] =~ %s (%s)\n", test, xhour, time_match ?
"PASS" :
"FAIL");
3273 if (time_match && xminute) {
3277 "XML DateTime Check: minute[%d] =~ %s (%s)\n", test, xminute, time_match ?
"PASS" :
"FAIL");
3280 if (time_match && xminday) {
3284 "XML DateTime Check: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ?
"PASS" :
"FAIL");
3287 if (time_match && xtod) {
3293 "XML DateTime Check: time of day[%s] =~ %s (%s)\n", tmpdate, xtod, time_match ?
"PASS" :
"FAIL");
3323 *macros = *language;
3360 char *str_language_dup = strdup(str_language);
3363 if ((secondary = strchr(str_language_dup,
'-'))) {
3364 *secondary++ =
'\0';
3366 "language %s not found. trying %s by removing %s\n", str_language, str_language_dup, secondary);
3417 #define LBRACKET '[' 3419 #define QUESTION '?' 3421 #define RBRACKET ']' 3426 #define UNDERSCORE '_' 3432 #define M_QUOTE (char)0x80 3433 #define M_PROTECT (char)0x40 3434 #define M_MASK (char)0xff 3435 #define M_ASCII (char)0x7f 3437 #define CHAR(c) ((char)((c)&M_ASCII)) 3438 #define META(c) ((char)((c)|M_QUOTE)) 3439 #define M_ALL META('*') 3440 #define M_END META(']') 3441 #define M_NOT META('!') 3442 #define M_ONE META('?') 3443 #define M_RNG META('-') 3444 #define M_SET META('[') 3445 #define ismeta(c) (((c)&M_QUOTE) != 0) 3448 #define MAXPATHLEN 256 3451 static int compare(
const void *,
const void *);
3452 static int glob0(
const char *, glob_t *,
size_t *);
3453 static int glob1(
char *, glob_t *,
size_t *);
3454 static int glob2(
char *,
char *,
char *,
char *, glob_t *,
size_t *);
3455 static int glob3(
char *,
char *,
char *,
char *,
char *, glob_t *,
size_t *);
3456 static int globextend(
const char *, glob_t *,
size_t *);
3457 static int match(
char *,
char *,
char *);
3459 #pragma warning(push) 3460 #pragma warning(disable:4310) 3462 int glob(
const char *pattern,
int flags,
int (*errfunc) (
const char *,
int), glob_t *pglob)
3464 const unsigned char *patnext;
3467 char *bufnext, *bufend, patbuf[MAXPATHLEN];
3469 patnext = (
unsigned char *) pattern;
3470 if (!(flags & GLOB_APPEND)) {
3471 pglob->gl_pathc = 0;
3472 pglob->gl_pathv = NULL;
3473 if (!(flags & GLOB_DOOFFS))
3476 if (flags & GLOB_LIMIT) {
3477 limit = pglob->gl_matchc;
3482 pglob->gl_flags = flags & ~GLOB_MAGCHAR;
3483 pglob->gl_errfunc = errfunc;
3484 pglob->gl_matchc = 0;
3487 bufend = bufnext + MAXPATHLEN - 1;
3488 while (bufnext < bufend && (c = *patnext++) != EOS)
3492 return glob0(patbuf, pglob, &limit);
3501 static int glob0(
const char *pattern, glob_t *pglob,
size_t *limit)
3503 const char *qpatnext;
3506 char *bufnext, patbuf[MAXPATHLEN];
3509 oldpathc = pglob->gl_pathc;
3513 while ((c = *qpatnext++) != EOS) {
3516 *bufnext++ = WIN_SEP;
3522 if (*qpatnext == EOS || strchr((
char *) qpatnext + 1, RBRACKET) == NULL) {
3523 *bufnext++ = LBRACKET;
3533 *bufnext++ = CHAR(c);
3534 if (*qpatnext == RANGE && (c = qpatnext[1]) != RBRACKET) {
3536 *bufnext++ = CHAR(c);
3539 }
while ((c = *qpatnext++) != RBRACKET);
3540 pglob->gl_flags |= GLOB_MAGCHAR;
3544 pglob->gl_flags |= GLOB_MAGCHAR;
3548 pglob->gl_flags |= GLOB_MAGCHAR;
3552 if (bufnext == patbuf || bufnext[-1] != M_ALL)
3556 *bufnext++ = CHAR(c);
3562 if ((err = glob1(patbuf, pglob, limit)) != 0)
3571 if (pglob->gl_pathc == oldpathc) {
3572 if (((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR))))
3573 return (globextend(pattern, pglob, limit));
3575 return (GLOB_NOMATCH);
3577 if (!(pglob->gl_flags & GLOB_NOSORT))
3578 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc,
sizeof(
char *), compare);
3582 static int compare(
const void *p,
const void *q)
3584 return (strcmp(*(
char **) p, *(
char **) q));
3587 static int glob1(
char *pattern, glob_t *pglob,
size_t *limit)
3589 char pathbuf[MAXPATHLEN];
3592 if (*pattern == EOS)
3594 return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, pattern, pglob, limit));
3602 static int glob2(
char *pathbuf,
char *pathend,
char *pathend_last,
char *pattern, glob_t *pglob,
size_t *limit)
3612 for (anymeta = 0;;) {
3613 if (*pattern == EOS) {
3615 if (stat(pathbuf, &sb))
3618 if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP && pathend[-1] != WIN_SEP) && (_S_IFDIR & sb.st_mode)) {
3619 if (pathend + 1 > pathend_last)
3620 return (GLOB_ABORTED);
3621 *pathend++ = WIN_SEP;
3625 return (globextend(pathbuf, pglob, limit));
3631 while (*p != EOS && *p != SEP && *p != WIN_SEP) {
3634 if (q + 1 > pathend_last)
3635 return (GLOB_ABORTED);
3642 while (*pattern == SEP || *pattern == WIN_SEP) {
3643 if (pathend + 1 > pathend_last)
3644 return (GLOB_ABORTED);
3645 *pathend++ = *pattern++;
3648 return (glob3(pathbuf, pathend, pathend_last, pattern, p, pglob, limit));
3653 static int glob3(
char *pathbuf,
char *pathend,
char *pathend_last,
char *pattern,
char *restpattern, glob_t *pglob,
size_t *limit)
3659 fspr_pool_create(&pool, NULL);
3661 if (pathend > pathend_last)
3662 return (GLOB_ABORTED);
3666 if (fspr_dir_open(&dirp, pathbuf, pool) != APR_SUCCESS) {
3668 fspr_pool_destroy(pool);
3669 if (pglob->gl_errfunc) {
3670 if (pglob->gl_errfunc(pathbuf, errno) || pglob->gl_flags & GLOB_ERR)
3671 return (GLOB_ABORTED);
3684 if (fspr_dir_read(&dp, APR_FINFO_NAME, dirp) != APR_SUCCESS)
3686 if (!(dp.valid & APR_FINFO_NAME) || !(dp.name) || !strlen(dp.name))
3690 if (dp.name[0] == DOT && *pattern != DOT)
3693 sc = (
unsigned char *) dp.name;
3695 while (dc < pathend_last && (*dc++ = *sc++) != EOS);
3697 if (!match(pathend, pattern, restpattern)) {
3701 err = glob2(pathbuf, --dc, pathend_last, restpattern, pglob, limit);
3707 fspr_dir_close(dirp);
3708 fspr_pool_destroy(pool);
3727 static int globextend(
const char *
path, glob_t *pglob,
size_t *limit)
3732 size_t newsize, len;
3735 if (*limit && pglob->gl_pathc > *limit) {
3737 return (GLOB_NOSPACE);
3740 newsize =
sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
3743 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
3745 pathv += pglob->gl_offs;
3746 for (i = pglob->gl_offs; i-- > 0;)
3749 pglob->gl_pathv = pathv;
3751 for (p = path; *p++;)
3753 len = (size_t) (p - path);
3755 memcpy(copy, path, len);
3756 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
3757 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
3758 return (copy == NULL ? GLOB_NOSPACE : 0);
3765 static int match(
char *
name,
char *pat,
char *patend)
3767 int ok, negate_range;
3771 while (pat < patend) {
3773 switch (c & M_MASK) {
3778 if (match(name, pat, patend))
3780 while (*name++ != EOS);
3788 if ((k = *name++) == EOS)
3790 if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
3792 while (((c = *pat++) & M_MASK) != M_END)
3793 if ((*pat & M_MASK) == M_RNG) {
3794 memset(s1, 0,
sizeof(s1));
3798 if (strcoll(&s1[0], &s1[2]) <= 0 && strcoll(&s1[2], &s1[4]) <= 0)
3803 if (ok == negate_range)
3812 return (*name == EOS);
3816 void globfree(glob_t *pglob)
3821 if (pglob->gl_pathv != NULL) {
3822 pp = pglob->gl_pathv + pglob->gl_offs;
3823 for (i = pglob->gl_pathc; i--; ++pp)
3826 free(pglob->gl_pathv);
3827 pglob->gl_pathv = NULL;
3831 #pragma warning(pop)
switch_xml_t switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
static switch_xml_binding_t * BINDINGS
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
void switch_close_extra_files(int *keep, int keep_ttl)
switch_xml_t switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value)
Sets the given tag attribute or adds a new attribute if not found. A value \ of NULL will remove the ...
switch_xml_t switch_xml_insert(switch_xml_t xml, switch_xml_t dest, switch_size_t off)
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
switch_xml_t switch_xml_parse_file(const char *file)
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
switch_xml_t switch_xml_add_child_d(switch_xml_t xml, const char *name, switch_size_t off)
switch_xml_t switch_xml_find_child_multi(switch_xml_t node, const char *childname,...)
switch_xml_t switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
char * switch_find_end_paren(const char *s, char open, char close)
static switch_time_t time_now(int64_t offset)
switch_xml_t switch_xml_new(const char *name)
switch_xml_t(* switch_xml_search_function_t)(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
#define switch_core_hash_init(_hash)
void switch_xml_free_in_thread(switch_xml_t xml, int stacksize)
switch_xml_t switch_xml_get(switch_xml_t xml,...)
static short switch_xml_internal_dtd(switch_xml_root_t root, char *s, switch_size_t len)
switch_status_t switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language)
void switch_xml_set_binding_user_data(switch_xml_binding_t *binding, void *user_data)
#define switch_split(_data, _delim, _array)
switch_status_t switch_xml_locate_user_merged(const char *key, const char *user_name, const char *domain_name, const char *ip, switch_xml_t *user, switch_event_t *params)
static void switch_xml_free_attr(char **attr)
struct switch_xml * switch_xml_t
switch_xml_t switch_xml_root(void)
retrieve the core XML root node
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
switch_xml_section_t switch_xml_get_binding_sections(switch_xml_binding_t *binding)
switch_xml_t switch_xml_set_flag(switch_xml_t xml, switch_xml_flag_t flag)
sets a flag for the given tag and returns the tag
static void switch_xml_user_cache(const char *key, const char *user_name, const char *domain_name, switch_xml_t user, switch_time_t expires)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
Representation of an event.
switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt)
sets the character content for the given tag and returns the tag
const char ** switch_xml_pi(switch_xml_t xml, const char *target)
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
const char *const const char *const const cJSON *const value
switch_xml_t switch_xml_open_root(uint8_t reload, const char **err)
const char * switch_xml_error(switch_xml_t xml)
static switch_mutex_t * REFLOCK
static void * switch_must_malloc(size_t _b)
switch_bool_t switch_is_number(const char *str)
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
switch_status_t switch_xml_locate(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_bool_t clone)
A representation of an XML tree.
switch_xml_section_t sections
switch_status_t switch_xml_reload(const char **err)
static switch_status_t switch_xml_locate_user_cache(const char *key, const char *user_name, const char *domain_name, switch_xml_t *user)
switch_xml_t switch_xml_set_txt_d(switch_xml_t xml, const char *txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
static switch_hash_t * CACHE_HASH
switch_xml_t switch_xml_parse_file_simple(const char *file)
static switch_thread_t * thread
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
struct switch_xml_binding * next
switch_xml_t __switch_xml_open_root(uint8_t reload, const char **err, void *user_data)
char * switch_xml_toxml_buf_ex(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset, switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
int switch_stream_system(const char *cmd, switch_stream_handle_t *stream)
switch_xml_t switch_xml_idx(switch_xml_t xml, int idx)
switch_status_t switch_xml_unbind_search_function_ptr(switch_xml_search_function_t function)
static void switch_xml_open_tag(switch_xml_root_t root, char *name, char *open_pos, char **attr)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_xml_t switch_xml_dup(switch_xml_t xml)
int switch_system(const char *cmd, switch_bool_t wait)
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
switch_bool_t switch_dow_cmp(const char *exp, int val)
#define SWITCH_MUTEX_NESTED
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
static char not_so_threadsafe_error_buffer[256]
#define SWITCH_PATH_SEPARATOR
switch_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
static void preprocess_exec_set(char *keyval)
switch_byte_t switch_byte_t * buf
static switch_xml_t switch_xml_close_tag(switch_xml_root_t root, char *name, char *s, char *close_pos)
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
char * switch_xml_tohtml_ex(switch_xml_t xml, switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
int switch_xml_std_datetime_check(switch_xml_t xcond, int *offset, const char *tzname)
static void * XML_OPEN_ROOT_FUNCTION_USER_DATA
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
static void switch_xml_proc_inst(switch_xml_root_t root, char *s, switch_size_t len)
switch_status_t switch_xml_locate_language_ex(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language)
uint32_t switch_xml_section_t
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.
struct switch_xml_root * switch_xml_root_t
static void preprocess_env_set(char *keyval)
void switch_xml_set_binding_sections(switch_xml_binding_t *binding, switch_xml_section_t sections)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
static void switch_xml_char_content(switch_xml_root_t root, char *s, switch_size_t len, char t)
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
static switch_xml_open_root_function_t XML_OPEN_ROOT_FUNCTION
static void * switch_must_realloc(void *_b, size_t _z)
static void do_merge(switch_xml_t in, switch_xml_t src, const char *container, const char *tag_name)
switch_memory_pool_t * pool
void switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
Gets the key and value of the current hash element.
switch_size_t switch_fp_read_dline(FILE *fd, char **buf, switch_size_t *len)
static switch_xml_t MAIN_XML_ROOT
switch_filenames SWITCH_GLOBAL_filenames
switch_byte_t switch_byte_t uint32_t buflen
switch_status_t switch_xml_locate_user(const char *key, const char *user_name, const char *domain_name, const char *ip, switch_xml_t *root, switch_xml_t *domain, switch_xml_t *user, switch_xml_t *ingroup, switch_event_t *params)
static FILE * preprocess_glob(const char *cwd, const char *pattern, FILE *write_fd, int rlevel)
char * switch_must_strdup(const char *_s)
#define SWITCH_STANDARD_STREAM(s)
char * switch_core_get_variable(_In_z_ const char *varname)
Retrieve a global variable from the core.
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
static void *SWITCH_THREAD_FUNC destroy_thread(switch_thread_t *thread, void *obj)
switch_xml_t(* switch_xml_open_root_function_t)(uint8_t reload, const char **err, void *user_data)
switch_xml_search_function_t function
switch_status_t switch_xml_init(switch_memory_pool_t *pool, const char **err)
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
static struct xml_section_t SECTIONS[]
switch_status_t switch_time_exp_tz(switch_time_exp_t *result, switch_time_t input, switch_int32_t offs)
switch_status_t switch_xml_destroy(void)
uint32_t switch_xml_clear_user_cache(const char *key, const char *user_name, const char *domain_name)
switch_directories SWITCH_GLOBAL_dirs
static char * switch_xml_ampencode(const char *s, switch_size_t len, char **dst, switch_size_t *dlen, switch_size_t *max, short a, switch_bool_t use_utf8_encoding)
switch_status_t switch_xml_unbind_search_function(switch_xml_binding_t **binding)
switch_xml_t switch_xml_open_cfg(const char *file_path, switch_xml_t *node, switch_event_t *params)
switch_status_t switch_xml_locate_domain(const char *domain_name, switch_event_t *params, switch_xml_t *root, switch_xml_t *domain)
#define switch_str_nil(s)
Make a null string a blank string instead.
struct fspr_thread_mutex_t switch_mutex_t
const char * switch_dow_int2str(int val)
const char * switch_xml_attr_soft(switch_xml_t xml, const char *attr)
static switch_hash_t * CACHE_EXPIRES_HASH
switch_xml_t switch_xml_parse_str_dynamic(char *s, switch_bool_t dup)
switch_status_t
Common return values.
const char *const const char *const path
char * switch_xml_toxml_ex(switch_xml_t xml, switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
const cJSON *const target
int switch_tod_cmp(const char *exp, int val)
static char * switch_xml_str2utf8(char **s, switch_size_t *len)
static switch_xml_t switch_xml_vget(switch_xml_t xml, va_list ap)
static char * switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len, switch_size_t *max, switch_size_t start, char ***attr, uint32_t *count, int isroot, switch_bool_t use_utf8_encoding)
switch_status_t switch_stun_ip_lookup(char **external_ip, const char *sourceip, switch_memory_pool_t *external_pool)
Perform a stun ip lookup.
switch_xml_t switch_xml_parse_str(char *s, switch_size_t len)
switch_xml_t switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off)
switch_status_t switch_xml_set_root(switch_xml_t new_main)
set new core xml root
switch_status_t switch_xml_bind_search_function_ret(switch_xml_search_function_t function, switch_xml_section_t sections, void *user_data, switch_xml_binding_t **ret_binding)
switch_status_t switch_xml_locate_group(const char *group_name, const char *domain_name, switch_xml_t *root, switch_xml_t *domain, switch_xml_t *group, switch_event_t *params)
#define switch_core_hash_insert(_h, _k, _d)
static char * expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_t *newlen, const char **err)
switch_xml_t switch_xml_cut(switch_xml_t xml)
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
static switch_bool_t switch_is_file_path(const char *file)
#define SWITCH_XML_BUFSIZE
#define switch_event_get_header(_e, _h)
static switch_status_t find_user_in_tag(switch_xml_t tag, const char *ip, const char *user_name, const char *key, switch_event_t *params, switch_xml_t *user)
char err[SWITCH_XML_ERRL]
int switch_number_cmp(const char *exp, int val)
void switch_xml_merge_user(switch_xml_t user, switch_xml_t domain, switch_xml_t group)
static void preprocess_stun_set(char *keyval)
static int switch_xml_ent_ok(char *name, char *s, char **ent)
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
switch_xml_t switch_xml_parse_fp(FILE *fp)
switch_xml_t switch_xml_parse_fd(int fd)
A wrapper for switch_xml_parse_str() that accepts a file descriptor. First \ attempts to mem map the ...
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.
const char * switch_stristr(const char *instr, const char *str)
switch_status_t switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
static switch_mutex_t * CACHE_MUTEX
char * switch_xml_toxml_nolock_ex(switch_xml_t xml, switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
static switch_mutex_t * XML_LOCK
static int preprocess(const char *cwd, const char *file, FILE *write_fd, int rlevel)
while(unpack->bits_cur<=SWITCH_BITS_PER_BYTE)
struct fspr_pool_t switch_memory_pool_t
#define switch_core_hash_insert_alloc(_h, _k, _s)
void switch_event_destroy(switch_event_t **event)
Destroy an event.
void switch_xml_free(switch_xml_t xml)
static char * switch_xml_decode(char *s, char **ent, char t)
switch_status_t switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
struct fspr_thread_t switch_thread_t
switch_xml_t switch_xml_find_child(switch_xml_t node, const char *childname, const char *attrname, const char *value)
switch_status_t switch_xml_locate_user_in_domain(const char *user_name, switch_xml_t domain, switch_xml_t *user, switch_xml_t *ingroup)
struct fspr_thread_rwlock_t switch_thread_rwlock_t
static switch_xml_t switch_xml_err(switch_xml_root_t root, char *s, const char *err,...)
void * switch_xml_get_binding_user_data(switch_xml_binding_t *binding)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
switch_xml_t switch_xml_child(switch_xml_t xml, const char *name)
static switch_mutex_t * FILE_LOCK
int switch_fulldate_cmp(const char *exp, switch_time_t *ts)
switch_xml_section_t switch_xml_parse_section_string(const char *str)
static switch_memory_pool_t * XML_MEMORY_POOL
char * switch_core_get_variable_dup(_In_z_ const char *varname)
#define switch_xml_toxml(xml, prn_header)
Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ mus...
switch_status_t switch_xml_set_open_root_function(switch_xml_open_root_function_t func, void *user_data)
Set and alternate function for opening xml root.
static FILE * preprocess_exec(const char *cwd, const char *command, FILE *write_fd, int rlevel)
static switch_thread_rwlock_t * B_RWLOCK
switch_hash_index_t * switch_core_hash_first_iter(_In_ switch_hash_t *hash, switch_hash_index_t *hi)
Gets the first element of a hashtable.