65 #include <apr_file_io.h>
74 int (*gl_errfunc) (
const char *, int);
78 #define GLOB_APPEND 0x0001
79 #define GLOB_DOOFFS 0x0002
80 #define GLOB_ERR 0x0004
81 #define GLOB_MARK 0x0008
82 #define GLOB_NOCHECK 0x0010
83 #define GLOB_NOSORT 0x0020
86 #define GLOB_NOSPACE (-1)
87 #define GLOB_ABORTED (-2)
88 #define GLOB_NOMATCH (-3)
89 #define GLOB_NOSYS (-4)
91 #define GLOB_ALTDIRFUNC 0x0040
92 #define GLOB_MAGCHAR 0x0100
93 #define GLOB_NOMAGIC 0x0200
94 #define GLOB_QUOTE 0x0400
95 #define GLOB_LIMIT 0x1000
97 int glob(
const char *,
int,
int (*)(
const char *,
int), glob_t *);
98 void globfree(glob_t *);
102 #define SWITCH_XML_WS "\t\r\n "
103 #define SWITCH_XML_ERRL 128
111 char *val = strchr(key,
'=');
115 while (*val && *val ==
' ') {
119 while (*ve && *ve ==
' ') {
129 char *tmp = (
char *) exec_result.
data;
130 tmp = &tmp[strlen(tmp)-1];
131 while (tmp >= (
char *) exec_result.
data && ( tmp[0] ==
' ' || tmp[0] ==
'\n') ) {
144 static int preprocess(
const char *cwd,
const char *file, FILE *write_fd,
int rlevel);
216 for (x = 0; x < strlen(str); x++) {
217 buf[x] = (char) tolower((
int) str[x]);
220 if (!SECTIONS[x].
name) {
223 if (strstr(buf, SECTIONS[x].name)) {
224 sections |= SECTIONS[x].
section;
238 for (ptr = BINDINGS; ptr; ptr = ptr->
next) {
239 if (ptr == *binding) {
243 BINDINGS = (*binding)->
next;
261 for (ptr = BINDINGS; ptr; ptr = ptr->
next) {
268 BINDINGS = ptr->
next;
283 binding->sections = sections;
289 binding->user_data = user_data;
294 return binding->sections;
299 return binding->user_data;
306 assert(
function != NULL);
317 for (ptr = BINDINGS; ptr && ptr->
next; ptr = ptr->
next);
326 *ret_binding = binding;
338 if (!(childname && attrname && value)) {
344 if (aname && value && !strcasecmp(aname, value)) {
355 const char *names[256] = { 0 };
356 const char *vals[256] = { 0 };
359 const char *attrname, *value = NULL;
361 va_start(ap, childname);
364 if ((attrname = va_arg(ap,
const char *))) {
365 value = va_arg(ap,
const char *);
367 if (attrname && value) {
378 if (!(childname && i)) {
383 for (x = 0; x < i; x++) {
384 if (names[x] && vals[x]) {
388 if (*vals[x] ==
'!') {
389 const char *sval = vals[x] + 1;
390 if (sval && strcasecmp(aname, sval)) {
394 if (!strcasecmp(aname, vals[x])) {
411 xml = (xml) ? xml->
child : NULL;
412 while (xml && strcmp(name, xml->name))
420 for (; xml && idx; idx--)
430 return ret ? ret :
"";
439 if (!xml || !xml->attr)
441 while (xml->attr[i] && attr && strcmp(attr, xml->attr[i]))
444 return xml->
attr[i + 1];
453 for (i = 0; root->
attr[i] && xml->name && strcmp(xml->name, root->
attr[i][0]); i++);
456 while (root->
attr[i][j] && attr && strcmp(attr, root->
attr[i][j]))
458 return (root->
attr[i][j]) ? root->
attr[i][j + 1] : NULL;
464 char *
name = va_arg(ap,
char *);
468 idx = va_arg(ap,
int);
501 if (!root || !root->
pi) {
504 while (root->
pi[i] && strcmp(target, root->
pi[i][0]))
506 return (
const char **) ((root->
pi[i]) ? root->
pi[i] + 1 : SWITCH_XML_NIL);
516 if (!root || !root->
s) {
520 for (t = root->
s; t && t < s; t++)
540 char *e, *r = s, *m = s;
541 unsigned long b, c, d, l;
547 memmove(s, (s + 1), strlen(s));
552 while (*s && *s !=
'&' && (*s !=
'%' || t !=
'%') && !isspace((
unsigned char) (*s)))
557 else if (t !=
'c' && !strncmp(s,
"&#", 2)) {
564 if (!isxdigit((
int)*code)) {
568 c = strtoul(code, &e, base);
569 if (!c || *e !=
';') {
576 else if (c > 0x7FFFFFFF) {
580 for (b = 0, d = c; d; d /= 2)
584 *(s++) = (
char) ((0xFF << (7 - b)) | (c >> (6 * b)));
586 *(s++) = (
char) (0x80 | ((c >> (6 * --b)) & 0x3F));
589 memmove(s, strchr(s,
';') + 1, strlen(strchr(s,
';')));
590 }
else if ((*s ==
'&' && (t ==
'&' || t ==
' ' || t ==
'*')) || (*s ==
'%' && t ==
'%')) {
591 for (b = 0; ent[b] && strncmp(s + 1, ent[b], strlen(ent[b])); b += 2);
594 if ((c = (
unsigned long) strlen(ent[b])) - 1 > (e = strchr(s,
';')) - s) {
595 l = (d = (
unsigned long) (s - r)) + c + (
unsigned long) strlen(e);
604 e = strchr((s = r + d),
';');
607 memmove(s + c, e + 1, strlen(e));
608 strncpy(s, ent[b], c);
611 }
else if ((t ==
' ' || t ==
'*') && isspace((
int) (*s)))
618 for (s = r; *s; s++) {
619 if ((l = (
unsigned long) strspn(s,
" ")))
620 memmove(s, s + l, strlen(s + l) + 1);
621 while (*s && *s !=
' ')
624 if (--s >= r && *s ==
' ')
635 if (!root || !root->
cur) {
657 if (!root || !root->
cur) {
663 if (!xml || !xml->
name || !len)
677 xml->
txt = strcpy(tmp, xml->
txt);
679 strcpy(xml->
txt + l, s);
692 return switch_xml_err(root, s,
"unexpected closing tag </%s>", name);
705 while (*s && *s !=
'&')
709 if (!strncmp(s + 1, name, strlen(name)))
711 for (i = 0; ent[i] && strncmp(ent[i], s + 1, strlen(ent[i])); i += 2);
734 if (!strcmp(target,
"xml")) {
735 if ((s = strstr(s,
"standalone")) && !strncmp(s + strspn(s + 10,
SWITCH_XML_WS "='\"") + 10,
"yes", 3))
740 if (!root->
pi || !root->
pi[0]) {
745 while (root->
pi[i] && strcmp(target, root->
pi[i][0]))
754 root->
pi[i][0] = target;
755 root->
pi[i][1] = (
char *) (root->
pi[i + 1] = NULL);
759 while (root->
pi[i][j])
764 root->
pi[i][j + 2] = stmp;
765 strcpy(root->
pi[i][j + 2] + j - 1, (root->
xml.
name) ?
">" :
"<");
766 root->
pi[i][j + 1] = NULL;
773 char q, *c, *t, *n = NULL, *v, **ent, **pe;
779 for (s[len] =
'\0'; s;) {
780 while (*s && *s !=
'<' && *s !=
'%')
785 else if (!strncmp(s,
"<!ENTITY", 8)) {
791 if ((q = *(v++)) !=
'"' && q !=
'\'') {
796 for (i = 0, ent = (*c ==
'%') ? pe : root->
ent; ent[i]; i++);
805 if ((s = strchr(v, q)))
816 }
else if (!strncmp(s,
"<!ATTLIST", 9)) {
826 for (i = 0; root->
attr[i] && strcmp(n, root->
attr[i][0]); i++);
843 c = (strncmp(s,
"CDATA", 5)) ? (
char *)
"*" : (
char *)
" ";
844 if (!strncmp(s,
"NOTATION", 8))
846 s = (*s ==
'(') ? strchr(s,
')') : s + strcspn(s,
SWITCH_XML_WS);
853 if (!strncmp(s,
"#FIXED", 6))
860 }
else if ((*s ==
'"' || *s ==
'\'') &&
861 (s = strchr(v = s + 1, *s)))
868 if (!root->
attr[i]) {
872 root->
attr[i][0] = t;
873 root->
attr[i][1] = (
char *) (root->
attr[i + 1] = NULL);
876 for (j = 1; root->
attr[i][j]; j += 3);
879 root->
attr[i] = sstmp;
880 root->
attr[i][j + 3] = NULL;
881 root->
attr[i][j + 2] = c;
883 root->
attr[i][j] = n;
885 }
else if (!strncmp(s,
"<!--", 4))
886 s = strstr(s + 4,
"-->");
887 else if (!strncmp(s,
"<?", 2)) {
888 if ((s = strstr(c = s + 2,
"?>")))
890 }
else if (*s ==
'<')
907 int b, be = (**s ==
'\xFE') ? 1 : (**s ==
'\xFF') ? 0 : -1;
913 for (sl = 2; sl < *len - 1; sl += 2) {
914 c = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
915 : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
916 if (c >= 0xD800 && c <= 0xDFFF && (sl += 2) < *len - 1) {
917 d = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
918 : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
919 c = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000;
922 while (l + 6 > max) {
930 for (b = 0, d = c; d; d /= 2)
933 u[l++] = (char) ((0xFF << (7 - b)) | (c >> (6 * b)));
935 u[l++] = (char) (0x80 | ((c >> (6 * --b)) & 0x3F));
947 if (!attr || attr == SWITCH_XML_NIL)
952 for (i = 0; m[i]; i++) {
956 free(attr[(i * 2) + 1]);
964 switch_xml_root_t root;
985 char q, e, *d, **attr, **a = NULL;
992 root->
e = (root->
s = s) + len;
997 while (*s && *s !=
'<')
1003 attr = (
char **) SWITCH_XML_NIL;
1006 if (isalpha((
int) (*s)) || *s ==
'_' || *s ==
':' || (int8_t) * s <
'\0') {
1008 return switch_xml_err(root, d,
"markup outside of root element");
1011 while (isspace((
int) (*s)))
1014 if (*s && *s !=
'/' && *s !=
'>')
1015 for (i = 0; (a = root->
attr[i]) && strcmp(a[0], d); i++);
1017 for (l = 0; *s && *s !=
'/' && *s !=
'>'; l += 2) {
1022 strcpy(attr[l + 3] + (l / 2),
" ");
1024 attr[l + 1] = (
char *)
"";
1028 if (*s ==
'=' || isspace((
int) (*s))) {
1031 if (q ==
'"' || q ==
'\'') {
1033 while (*s && *s != q)
1042 for (j = 1; a && a[j] && strcmp(a[j], attr[l]); j += 3);
1044 if (attr[l + 1] < d || attr[l + 1] > s)
1048 while (isspace((
int) (*s)))
1054 if ((*s && *s !=
'>') || (!*s && e !=
'>')) {
1061 }
else if ((q = *s) ==
'>' || (!*s && e ==
'>')) {
1070 }
else if (*s ==
'/') {
1072 if (!(q = *s) && e !=
'>')
1077 if (isspace((
int) (*s = q)))
1079 }
else if (!strncmp(s,
"!--", 3)) {
1080 if (!(s = strstr(s + 3,
"--")) || (*(s += 2) !=
'>' && *s) || (!*s && e !=
'>'))
1082 }
else if (!strncmp(s,
"![CDATA[", 8)) {
1083 if ((s = strstr(s,
"]]>")))
1087 }
else if (!strncmp(s,
"!DOCTYPE", 8)) {
1088 for (l = 0; *s && ((!l && *s !=
'>') || (l && (*s !=
']' || *(s + strspn(s + 1,
SWITCH_XML_WS) + 1) !=
'>'))); l = (*s ==
'[') ? 1 : l)
1089 s += strcspn(s + 1,
"[]>") + 1;
1090 if (!*s && e !=
'>')
1092 d = (l) ? strchr(d,
'[') + 1 : d;
1095 }
else if (*s ==
'?') {
1098 }
while (s && *(++s) && *s !=
'>');
1099 if (!s || (!*s && e !=
'>'))
1110 if (*s && *s !=
'<') {
1111 while (*s && *s !=
'<')
1134 switch_xml_root_t root;
1159 switch_xml_root_t root;
1174 if (!(0<(l = read(fd, m, st.st_size)))
1189 char *
ep = ebuf + elen - 1;
1191 if (!(var = strstr(rp,
"$${"))) {
1192 *newlen = strlen(buf);
1196 while (*rp && wp < ep) {
1198 if (*rp ==
'$' && *(rp + 1) ==
'$' && *(rp + 2) ==
'{') {
1208 for (p = val; p && *p && wp <=
ep; p++) {
1215 *err =
"unterminated ${var}";
1227 *newlen = strlen(ebuf);
1232 static FILE *
preprocess_exec(
const char *cwd,
const char *command, FILE *write_fd,
int rlevel)
1238 if (!command || !strlen(command))
goto end;
1240 if ((fp = _popen(command,
"r"))) {
1241 while (fgets(buffer,
sizeof(buffer), fp) != NULL) {
1242 if (fwrite(buffer, 1, strlen(buffer), write_fd) <= 0) {
1253 switch_snprintf(buffer,
sizeof(buffer),
"<!-- exec can not execute [%s] -->", command);
1254 fwrite( buffer, 1, strlen(buffer), write_fd);
1257 int fds[2], pid = 0;
1269 char buf[1024] =
"";
1272 while ((bytes = read(fds[0], buf,
sizeof(buf))) > 0) {
1273 if (fwrite(buf, 1, bytes, write_fd) <= 0) {
1278 waitpid(pid, NULL, 0);
1282 dup2(fds[1], STDOUT_FILENO);
1295 static FILE *
preprocess_glob(
const char *cwd,
const char *pattern, FILE *write_fd,
int rlevel)
1297 char *full_path = NULL;
1298 char *dir_path = NULL, *e = NULL;
1305 pattern = full_path;
1308 glob_return = glob(pattern, GLOB_ERR, NULL, &glob_data);
1309 if (glob_return == GLOB_NOSPACE || glob_return == GLOB_ABORTED) {
1312 }
else if (glob_return == GLOB_NOMATCH) {
1317 for (n = 0; n < glob_data.gl_pathc; ++n) {
1323 if (
preprocess(dir_path, glob_data.gl_pathv[n], write_fd, rlevel) < 0) {
1330 globfree(&glob_data);
1339 static int preprocess(
const char *cwd,
const char *file, FILE *write_fd,
int rlevel)
1341 FILE *read_fd = NULL;
1343 char *q, *cmd, *
buf = NULL, *ebuf = NULL;
1352 if (!(read_fd = fopen(file,
"r"))) {
1353 const char *reason = strerror(errno);
1358 setvbuf(read_fd, (
char *) NULL, _IOFBF, 65536);
1362 const char *err = NULL;
1375 while (!(bp =
expand_vars(buf, ebuf, eblen, &cur, &err))) {
1388 if (strstr(buf,
"<include>") || strstr(buf,
"</include>") || strstr(buf,
"<?")) {
1393 if ((e = strstr(buf,
"-->"))) {
1403 if (*(tcmd - 1) !=
'<') {
1406 if ((e = strstr(tcmd,
"/>"))) {
1409 if (fwrite(e, 1, (
unsigned) strlen(e), write_fd) != (
int) strlen(e)) {
1429 if ((e = strchr(tcmd,
'"'))) {
1447 if ((e = strchr(targ,
'"'))) {
1451 if (!strcasecmp(tcmd,
"set")) {
1452 char *name = (
char *) targ;
1453 char *val = strchr(name,
'=');
1457 while (*val && *val ==
' ') {
1461 while (*ve && *ve ==
' ') {
1470 }
else if (!strcasecmp(tcmd,
"exec-set")) {
1472 }
else if (!strcasecmp(tcmd,
"include")) {
1474 }
else if (!strcasecmp(tcmd,
"exec")) {
1481 if ((cmd = strstr(bp,
"<!--#"))) {
1482 if (fwrite(bp, 1, (
unsigned) (cmd - bp), write_fd) != (
unsigned) (cmd - bp)) {
1485 if ((e = strstr(cmd,
"-->"))) {
1488 if (fwrite(e, 1, (
unsigned) strlen(e), write_fd) != (
int) strlen(e)) {
1496 if ((e = strchr(cmd,
'\r')) || (e = strchr(cmd,
'\n'))) {
1500 if ((arg = strchr(cmd,
' '))) {
1502 if ((q = strchr(arg,
'"'))) {
1505 if ((qq = strchr(qq,
'"'))) {
1511 if (!strcasecmp(cmd,
"set")) {
1513 char *val = strchr(name,
'=');
1517 while (*val && *val ==
' ') {
1521 while (*ve && *ve ==
' ') {
1530 }
else if (!strcasecmp(cmd,
"exec-set")) {
1532 }
else if (!strcasecmp(cmd,
"include")) {
1534 }
else if (!strcasecmp(cmd,
"exec")) {
1542 if (fwrite(bp, 1, (
unsigned) cur, write_fd) != (
int) cur) {
1562 switch_xml_root_t root;
1564 if ((fd = open(file, O_RDONLY, 0)) > -1) {
1566 if (!st.st_size)
goto error;
1569 if (!(0<(l = read(fd, m, st.st_size))))
goto error;
1586 FILE *write_fd = NULL;
1588 char *new_file = NULL;
1589 char *new_file_tmp = NULL;
1590 const char *abs, *absw;
1592 abs = strrchr(file,
'/');
1593 absw = strrchr(file,
'\\');
1595 abs > absw ? abs++ : (abs = ++absw);
1610 if ((write_fd = fopen(new_file_tmp,
"w+")) == NULL) {
1614 setvbuf(write_fd, (
char *) NULL, _IOFBF, 65536);
1621 if ( rename(new_file_tmp,new_file) ) {
1624 if ((fd = open(new_file, O_RDONLY, 0)) > -1) {
1656 const
char *tag_name,
1657 const
char *key_name,
1658 const
char *key_value,
1670 for (binding = BINDINGS; binding; binding = binding->
next) {
1675 if ((xml = binding->
function(section, tag_name, key_name, key_value, params, binding->
user_data))) {
1676 const char *err = NULL;
1686 if (aname && !strcasecmp(aname,
"not found")) {
1758 const
char *domain_name,
1807 const char *type =
"!pointer";
1811 if (!strcasecmp(val,
"any")) {
1825 if (!strcasecmp(key,
"id")) {
1842 switch_xml_t group = NULL, groups = NULL, users = NULL;
1887 if (var && ivar && !strcasecmp(var, ivar)) {
1908 do_merge(user, group,
"params",
"param");
1909 do_merge(user, group,
"variables",
"variable");
1910 do_merge(user, group,
"profile-variables",
"variable");
1911 do_merge(user, domain,
"params",
"param");
1912 do_merge(user, domain,
"variables",
"variable");
1913 do_merge(user, domain,
"profile-variables",
"variable");
1915 if (!
zstr(domain_name)) {
1925 char mega_key[1024];
1928 char *expires_val = NULL;
1932 if (key && user_name && domain_name) {
1933 switch_snprintf(mega_key,
sizeof(mega_key),
"%s%s%s", key, user_name, domain_name);
1972 char mega_key[1024];
1976 switch_snprintf(mega_key,
sizeof(mega_key),
"%s%s%s", key, user_name, domain_name);
1980 char *expires_lookup = NULL;
1987 time_expires = atol(expires_lookup);
1989 if (time_expires < time_now) {
2007 char mega_key[1024];
2009 char *expires_lookup;
2011 switch_snprintf(mega_key,
sizeof(mega_key),
"%s%s%s", key, user_name, domain_name);
2024 if (sprintf(expires_val,
"%ld", (
long)expires)) {
2040 char *keys[10] = {0};
2043 if (strchr(key,
':')) {
2047 keys[0] = (
char *)key;
2051 for(i = 0; i < nkeys; i++) {
2056 const char *cacheable = NULL;
2062 if (!
zstr(cacheable)) {
2067 int cache_ms = atol(cacheable);
2069 user_name, domain_name, cache_ms);
2071 expires = time_now + (cache_ms * 1000);
2090 const
char *user_name,
2091 const
char *domain_name,
2098 switch_xml_t group = NULL, groups = NULL, users = NULL;
2222 MAIN_XML_ROOT = new_main;
2224 MAIN_XML_ROOT->
refs++;
2227 if (old_root->
refs) {
2231 if (!old_root->
refs) {
2282 char path_buf[1024];
2286 if (MAIN_XML_ROOT) {
2296 switch_copy_string(not_so_threadsafe_error_buffer, *err,
sizeof(not_so_threadsafe_error_buffer));
2308 *err =
"Cannot Open log directory or XML Root!";
2336 XML_MEMORY_POOL =
pool;
2348 assert(pool != NULL);
2366 if (MAIN_XML_ROOT) {
2368 MAIN_XML_ROOT = NULL;
2389 assert(MAIN_XML_ROOT != NULL);
2403 const char *e = NULL;
2405 int expecting_x_utf_8_char = 0;
2406 int unicode_char = 0x000000;
2416 while (*dlen + 10 > *max) {
2424 (*dst)[(*dlen)++] = *s;
2430 *dlen += sprintf(*dst + *dlen,
"&");
2433 if (*(s + 1) ==
'!') {
2434 (*dst)[(*dlen)++] = *s;
2438 *dlen += sprintf(*dst + *dlen,
"<");
2441 *dlen += sprintf(*dst + *dlen,
">");
2444 *dlen += sprintf(*dst + *dlen, (a) ?
""" :
"\"");
2447 *dlen += sprintf(*dst + *dlen, (a) ?
"
" :
"\n");
2450 *dlen += sprintf(*dst + *dlen, (a) ?
"	" :
"\t");
2453 *dlen += sprintf(*dst + *dlen,
"
");
2456 if (USE_UTF_8_ENCODING && expecting_x_utf_8_char == 0 && ((*s >> 8) & 0x01)) {
2458 for (;num<4;num++) {
2459 if (! ((*s >> (7-num)) & 0x01)) {
2465 unicode_char = *s & 0x1f;
2468 unicode_char = *s & 0x0f;
2471 unicode_char = *s & 0x07;
2478 expecting_x_utf_8_char = num - 1;
2480 }
else if (USE_UTF_8_ENCODING && expecting_x_utf_8_char > 0) {
2481 if (((*s >> 6) & 0x03) == 0x2) {
2483 unicode_char = unicode_char << 6;
2484 unicode_char = unicode_char | (*s & 0x3f);
2487 expecting_x_utf_8_char = 0;
2490 expecting_x_utf_8_char--;
2491 if (expecting_x_utf_8_char == 0) {
2492 *dlen += sprintf(*dst + *dlen,
"&#x%X;", unicode_char);
2495 (*dst)[(*dlen)++] = *s;
2503 #define XML_INDENT " "
2524 if (!isroot && xml->
parent) {
2531 while (*len + strlen(xml->
name) + 5 + (strlen(
XML_INDENT) * (*count)) + 1 > *max) {
2535 if (*len && *(*s + (*len) - 1) ==
'>') {
2536 *len += sprintf(*s + *len,
"\n");
2538 for (lcount = 0; lcount < *count; lcount++) {
2539 *len += sprintf(*s + *len,
"%s",
XML_INDENT);
2542 *len += sprintf(*s + *len,
"<%s", xml->
name);
2543 for (i = 0; xml->
attr[i]; i += 2) {
2546 while (*len + strlen(xml->
attr[i]) + 7 + (strlen(
XML_INDENT) * (*count)) > *max) {
2550 *len += sprintf(*s + *len,
" %s=\"", xml->
attr[i]);
2552 *len += sprintf(*s + *len,
"\"");
2555 for (i = 0; attr[i] && strcmp(attr[i][0], xml->
name); i++);
2556 for (j = 1; attr[i] && attr[i][j]; j += 3) {
2557 if (!attr[i][j + 1] ||
switch_xml_attr(xml, attr[i][j]) != attr[i][j + 1])
2559 while (*len + strlen(attr[i][j]) + 8 + (strlen(
XML_INDENT) * (*count)) > *max) {
2563 *len += sprintf(*s + *len,
" %s=\"", attr[i][j]);
2565 *len += sprintf(*s + *len,
"\"");
2568 *len += sprintf(*s + *len, (xml->
child || xml->
txt) ?
">" :
"/>\n");
2578 while (*len + strlen(xml->
name) + 5 + (strlen(
XML_INDENT) * (*count)) > *max) {
2583 if (*(*s + (*len) - 1) ==
'\n') {
2584 for (lcount = 0; lcount < *count; lcount++) {
2585 *len += sprintf(*s + *len,
"%s",
XML_INDENT);
2588 *len += sprintf(*s + (*len),
"</%s>\n", xml->
name);
2591 while (txt[off] && off < xml->off)
2594 if (!isroot && xml->
ordered) {
2647 switch_xml_root_t root = (switch_xml_root_t)
xml;
2658 len += sprintf(s + len,
"<?xml version=\"1.0\"?>\n");
2661 if (!xml || !xml->name) {
2665 while (root->xml.parent) {
2669 for (i = 0; !p && root->pi[i]; i++) {
2670 for (k = 2; root->pi[i][k - 1]; k++);
2671 for (j = 1; (n = root->pi[i][j]); j++) {
2672 if (root->pi[i][k][j - 1] ==
'>') {
2675 while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max) {
2678 len += sprintf(s + len,
"<?%s%s%s?>", t, *n ?
" " :
"", n);
2684 for (i = 0; !p && root->pi[i]; i++) {
2685 for (k = 2; root->pi[i][k - 1]; k++);
2686 for (j = 1; (n = root->pi[i][j]); j++) {
2687 if (root->pi[i][k][j - 1] ==
'<') {
2690 while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max) {
2693 len += sprintf(s + len,
"\n<?%s%s%s?>", t, *n ?
" " :
"", n);
2703 switch_xml_root_t root;
2729 if (xml->free_path) {
2730 if (unlink(xml->free_path) != 0) {
2740 #if (_MSC_VER >= 1400) // VC8+
2741 __analysis_assume(
sizeof(root->
ent) > 44);
2743 for (i = 10; root->
ent[i]; i += 2)
2744 if ((s = root->
ent[i + 1]) < root->
s || s > root->
e)
2748 for (i = 0; (a = root->
attr[i]); i++) {
2749 for (j = 1; a[j++]; j += 2)
2750 if (a[j] && (a[j] < root->
s || a[j] > root->
e))
2757 for (i = 0; root->
pi[i]; i++) {
2758 for (j = 1; root->
pi[i][j]; j++);
2759 free(root->
pi[i][j + 1]);
2788 while (xml && xml->parent)
2796 static const char *ent[] = {
"lt;",
"<",
"gt;",
">",
"quot;",
""",
2797 "apos;",
"'",
"amp;",
"&", NULL
2802 root->
xml.
name = (
char *) name;
2804 strcpy(root->
err, root->
xml.
txt = (
char *)
"");
2806 root->
attr = root->
pi = (
char ***) (root->
xml.
attr = SWITCH_XML_NIL);
2815 xml->next = xml->sibling = xml->ordered = NULL;
2819 if ((head = dest->
child)) {
2820 if (head->
off <= off) {
2829 for (cur = head, prev = NULL; cur && strcmp(cur->
name, xml->name); prev =
cur, cur = cur->
sibling);
2830 if (cur && cur->off <= off) {
2831 while (cur->next && cur->next->off <= off)
2839 for (cur = head, prev = NULL; cur && cur->
off <= off; prev =
cur, cur = cur->sibling);
2861 child->
name = (
char *) name;
2865 child->
txt = (
char *)
"";
2878 xml->txt = (
char *) txt;
2890 while (xml->attr[l] && strcmp(xml->attr[l], name))
2892 if (!xml->attr[l]) {
2895 if (xml->attr == SWITCH_XML_NIL) {
2902 xml->attr[l] = (
char *) name;
2903 xml->attr[l + 2] = NULL;
2904 xml->attr[l + 3] = (
char *)
switch_must_realloc(xml->attr[l + 1], (c = (
int) strlen(xml->attr[l + 1])) + 2);
2905 strcpy(xml->attr[l + 3] + c,
" ");
2909 free((
char *) name);
2911 for (c = l; xml->attr[c]; c += 2);
2913 free(xml->attr[l + 1]);
2920 xml->attr[l + 1] = (
char *) value;
2924 memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) *
sizeof(
char *));
2926 memmove(xml->attr[c + 1] + (l / 2), xml->attr[c + 1] + (l / 2) + 1, (c / 2) - (l / 2));
2949 xml->next->sibling = xml->sibling;
2961 if (strcmp(cur->
name, xml->name)) {
2970 while (cur->
next && cur->
next != xml)
2998 int loffset = -1000;
2999 int eoffset = -1000;
3002 int time_match = -1;
3010 loffset = atoi(tzoff);
3018 }
else if (!
zstr(tzname)) {
3024 if (eoffset == -1000) {
3028 if (loffset == -1000) {
3033 if (time_match && tzoff) {
3034 time_match = loffset == eoffset;
3036 "XML DateTime Check: TZOFFSET[%d] == %d (%s)\n", eoffset, loffset, time_match ?
"PASS" :
"FAIL");
3040 if (time_match && dst > -1) {
3041 time_match = (tm2.
tm_isdst > 0 && dst > 0);
3043 "XML DateTime Check: DST[%s] == %s (%s)\n",
3044 tm2.
tm_isdst > 0 ?
"true" :
"false", dst > 0 ?
"true" :
"false", time_match ?
"PASS" :
"FAIL");
3048 if (time_match && xdt) {
3051 switch_strftime(tmpdate, &retsize,
sizeof(tmpdate),
"%Y-%m-%d %H:%M:%S", &tm);
3054 "XML DateTime Check: date time[%s] =~ %s (%s)\n", tmpdate, xdt, time_match ?
"PASS" :
"FAIL");
3057 if (time_match && xyear) {
3061 "XML DateTime Check: year[%d] =~ %s (%s)\n", test, xyear, time_match ?
"PASS" :
"FAIL");
3064 if (time_match && xyday) {
3068 "XML DateTime Check: day of year[%d] =~ %s (%s)\n", test, xyday, time_match ?
"PASS" :
"FAIL");
3071 if (time_match && xmon) {
3072 int test = tm.
tm_mon + 1;
3075 "XML DateTime Check: month[%d] =~ %s (%s)\n", test, xmon, time_match ?
"PASS" :
"FAIL");
3078 if (time_match && xmday) {
3082 "XML DateTime Check: day of month[%d] =~ %s (%s)\n", test, xmday, time_match ?
"PASS" :
"FAIL");
3085 if (time_match && xweek) {
3086 int test = (int) (tm.
tm_yday / 7 + 1);
3089 "XML DateTime Check: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ?
"PASS" :
"FAIL");
3091 if (time_match && xweek) {
3092 int test = (int) (tm.
tm_yday / 7 + 1);
3095 "XML DateTime Check: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ?
"PASS" :
"FAIL");
3098 if (time_match && xmweek) {
3100 int firstdow = (int) (7 - (tm.
tm_mday - (tm.
tm_wday + 1)) % 7) % 7;
3102 int test = (int) ceil((tm.
tm_mday + firstdow) / 7.0);
3105 "XML DateTime: week of month[%d] =~ %s (%s)\n", test, xmweek, time_match ?
"PASS" :
"FAIL");
3108 if (time_match && xwday) {
3112 "XML DateTime Check: day of week[%s] =~ %s (%s)\n",
switch_dow_int2str(test), xwday, time_match ?
"PASS" :
"FAIL");
3114 if (time_match && xhour) {
3118 "XML DateTime Check: hour[%d] =~ %s (%s)\n", test, xhour, time_match ?
"PASS" :
"FAIL");
3121 if (time_match && xminute) {
3125 "XML DateTime Check: minute[%d] =~ %s (%s)\n", test, xminute, time_match ?
"PASS" :
"FAIL");
3128 if (time_match && xminday) {
3132 "XML DateTime Check: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ?
"PASS" :
"FAIL");
3135 if (time_match && xtod) {
3141 "XML DateTime Check: time of day[%s] =~ %s (%s)\n", tmpdate, xtod, time_match ?
"PASS" :
"FAIL");
3171 *macros = *language;
3245 #define LBRACKET '['
3247 #define QUESTION '?'
3249 #define RBRACKET ']'
3254 #define UNDERSCORE '_'
3260 #define M_QUOTE (char)0x80
3261 #define M_PROTECT (char)0x40
3262 #define M_MASK (char)0xff
3263 #define M_ASCII (char)0x7f
3265 #define CHAR(c) ((char)((c)&M_ASCII))
3266 #define META(c) ((char)((c)|M_QUOTE))
3267 #define M_ALL META('*')
3268 #define M_END META(']')
3269 #define M_NOT META('!')
3270 #define M_ONE META('?')
3271 #define M_RNG META('-')
3272 #define M_SET META('[')
3273 #define ismeta(c) (((c)&M_QUOTE) != 0)
3276 #define MAXPATHLEN 256
3279 static int compare(
const void *,
const void *);
3280 static int glob0(
const char *, glob_t *,
size_t *);
3281 static int glob1(
char *, glob_t *,
size_t *);
3282 static int glob2(
char *,
char *,
char *,
char *, glob_t *,
size_t *);
3283 static int glob3(
char *,
char *,
char *,
char *,
char *, glob_t *,
size_t *);
3284 static int globextend(
const char *, glob_t *,
size_t *);
3285 static int match(
char *,
char *,
char *);
3287 #pragma warning(push)
3288 #pragma warning(disable:4310)
3290 int glob(
const char *pattern,
int flags,
int (*errfunc) (
const char *,
int), glob_t *pglob)
3292 const unsigned char *patnext;
3295 char *bufnext, *bufend, patbuf[MAXPATHLEN];
3297 patnext = (
unsigned char *) pattern;
3298 if (!(flags & GLOB_APPEND)) {
3299 pglob->gl_pathc = 0;
3300 pglob->gl_pathv = NULL;
3301 if (!(flags & GLOB_DOOFFS))
3304 if (flags & GLOB_LIMIT) {
3305 limit = pglob->gl_matchc;
3310 pglob->gl_flags = flags & ~GLOB_MAGCHAR;
3311 pglob->gl_errfunc = errfunc;
3312 pglob->gl_matchc = 0;
3315 bufend = bufnext + MAXPATHLEN - 1;
3316 while (bufnext < bufend && (c = *patnext++) != EOS)
3320 return glob0(patbuf, pglob, &limit);
3329 static int glob0(
const char *pattern, glob_t *pglob,
size_t *limit)
3331 const char *qpatnext;
3334 char *bufnext, patbuf[MAXPATHLEN];
3337 oldpathc = pglob->gl_pathc;
3341 while ((c = *qpatnext++) != EOS) {
3344 *bufnext++ = WIN_SEP;
3350 if (*qpatnext == EOS || strchr((
char *) qpatnext + 1, RBRACKET) == NULL) {
3351 *bufnext++ = LBRACKET;
3361 *bufnext++ = CHAR(c);
3362 if (*qpatnext == RANGE && (c = qpatnext[1]) != RBRACKET) {
3364 *bufnext++ = CHAR(c);
3367 }
while ((c = *qpatnext++) != RBRACKET);
3368 pglob->gl_flags |= GLOB_MAGCHAR;
3372 pglob->gl_flags |= GLOB_MAGCHAR;
3376 pglob->gl_flags |= GLOB_MAGCHAR;
3380 if (bufnext == patbuf || bufnext[-1] != M_ALL)
3384 *bufnext++ = CHAR(c);
3390 if ((err = glob1(patbuf, pglob, limit)) != 0)
3399 if (pglob->gl_pathc == oldpathc) {
3400 if (((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR))))
3401 return (globextend(pattern, pglob, limit));
3403 return (GLOB_NOMATCH);
3405 if (!(pglob->gl_flags & GLOB_NOSORT))
3406 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc,
sizeof(
char *), compare);
3410 static int compare(
const void *p,
const void *q)
3412 return (strcmp(*(
char **) p, *(
char **) q));
3415 static int glob1(
char *pattern, glob_t *pglob,
size_t *limit)
3417 char pathbuf[MAXPATHLEN];
3420 if (*pattern == EOS)
3422 return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, pattern, pglob, limit));
3430 static int glob2(
char *pathbuf,
char *pathend,
char *pathend_last,
char *pattern, glob_t *pglob,
size_t *limit)
3440 for (anymeta = 0;;) {
3441 if (*pattern == EOS) {
3443 if (stat(pathbuf, &sb))
3446 if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP && pathend[-1] != WIN_SEP) && (_S_IFDIR & sb.st_mode)) {
3447 if (pathend + 1 > pathend_last)
3448 return (GLOB_ABORTED);
3449 *pathend++ = WIN_SEP;
3453 return (globextend(pathbuf, pglob, limit));
3459 while (*p != EOS && *p != SEP && *p != WIN_SEP) {
3462 if (q + 1 > pathend_last)
3463 return (GLOB_ABORTED);
3470 while (*pattern == SEP || *pattern == WIN_SEP) {
3471 if (pathend + 1 > pathend_last)
3472 return (GLOB_ABORTED);
3473 *pathend++ = *pattern++;
3476 return (glob3(pathbuf, pathend, pathend_last, pattern, p, pglob, limit));
3481 static int glob3(
char *pathbuf,
char *pathend,
char *pathend_last,
char *pattern,
char *restpattern, glob_t *pglob,
size_t *limit)
3487 apr_pool_create(&pool, NULL);
3489 if (pathend > pathend_last)
3490 return (GLOB_ABORTED);
3494 if (apr_dir_open(&dirp, pathbuf, pool) != APR_SUCCESS) {
3496 apr_pool_destroy(pool);
3497 if (pglob->gl_errfunc) {
3498 if (pglob->gl_errfunc(pathbuf, errno) || pglob->gl_flags & GLOB_ERR)
3499 return (GLOB_ABORTED);
3512 if (apr_dir_read(&dp, APR_FINFO_NAME, dirp) != APR_SUCCESS)
3514 if (!(dp.valid & APR_FINFO_NAME) || !(dp.name) || !strlen(dp.name))
3518 if (dp.name[0] == DOT && *pattern != DOT)
3521 sc = (
unsigned char *) dp.name;
3523 while (dc < pathend_last && (*dc++ = *sc++) != EOS);
3525 if (!match(pathend, pattern, restpattern)) {
3529 err = glob2(pathbuf, --dc, pathend_last, restpattern, pglob, limit);
3535 apr_dir_close(dirp);
3536 apr_pool_destroy(pool);
3555 static int globextend(
const char *path, glob_t *pglob,
size_t *limit)
3560 size_t newsize, len;
3563 if (*limit && pglob->gl_pathc > *limit) {
3565 return (GLOB_NOSPACE);
3568 newsize =
sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
3571 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
3573 pathv += pglob->gl_offs;
3574 for (i = pglob->gl_offs; i-- > 0;)
3577 pglob->gl_pathv = pathv;
3579 for (p = path; *p++;)
3581 len = (size_t) (p - path);
3583 memcpy(copy, path, len);
3584 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
3585 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
3586 return (copy == NULL ? GLOB_NOSPACE : 0);
3593 static int match(
char *name,
char *pat,
char *patend)
3595 int ok, negate_range;
3599 while (pat < patend) {
3601 switch (c & M_MASK) {
3606 if (match(name, pat, patend))
3608 while (*name++ != EOS);
3616 if ((k = *name++) == EOS)
3618 if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
3620 while (((c = *pat++) & M_MASK) != M_END)
3621 if ((*pat & M_MASK) == M_RNG) {
3622 memset(s1, 0,
sizeof(s1));
3626 if (strcoll(&s1[0], &s1[2]) <= 0 && strcoll(&s1[2], &s1[4]) <= 0)
3631 if (ok == negate_range)
3640 return (*name == EOS);
3644 void globfree(glob_t *pglob)
3649 if (pglob->gl_pathv != NULL) {
3650 pp = pglob->gl_pathv + pglob->gl_offs;
3651 for (i = pglob->gl_pathc; i--; ++pp)
3654 free(pglob->gl_pathv);
3655 pglob->gl_pathv = NULL;
3659 #pragma warning(pop)
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)
#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_find_child_multi(switch_xml_t node, const char *childname,...)
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)
#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)
int switch_stream_system_fork(const char *cmd, switch_stream_handle_t *stream)
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)
switch_xml_t(* switch_xml_open_root_function_t)(uint8_t reload, const char **err, void *user_data)
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
#define switch_xml_add_child_d(xml, name, off)
wrapper for switch_xml_add_child() that strdup()s name
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.
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_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)
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
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
switch_xml_t __switch_xml_open_root(uint8_t reload, const char **err, void *user_data)
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)
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)
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
static void preprocess_exec_set(char *keyval)
switch_byte_t switch_byte_t * buf
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)
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
void switch_xml_set_binding_sections(switch_xml_binding_t *binding, switch_xml_section_t sections)
static switch_bool_t USE_UTF_8_ENCODING
#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)
struct apr_thread_rwlock_t switch_thread_rwlock_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.
static void switch_xml_open_tag(switch_xml_root_t root, char *name, char **attr)
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_xml_tohtml(switch_xml_t xml, switch_bool_t prn_header)
#define SWITCH_STANDARD_STREAM(s)
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_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
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)
static char * switch_must_strdup(const char *_s)
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)
struct apr_thread_mutex_t switch_mutex_t
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_status_t
Common return values.
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)
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)
struct apr_thread_t switch_thread_t
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 int switch_xml_ent_ok(char *name, char *s, char **ent)
struct apr_pool_t switch_memory_pool_t
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
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)
#define switch_xml_set_attr_d(xml, name, value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
void switch_event_destroy(switch_event_t **event)
Destroy an event.
void switch_xml_free(switch_xml_t xml)
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)
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)
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)
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,...)
char * switch_xml_toxml_nolock(switch_xml_t xml, switch_bool_t prn_header)
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_xml_t switch_xml_close_tag(switch_xml_root_t root, char *name, char *s)
static switch_memory_pool_t * XML_MEMORY_POOL
char * switch_core_get_variable_dup(_In_z_ const char *varname)
char * switch_xml_toxml(switch_xml_t xml, switch_bool_t prn_header)
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.
char * switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset, switch_bool_t prn_header)
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.