diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index 89814544ca..a40a2c17c6 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -117,6 +117,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd); ///\return a formated xml node or NULL SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file); +SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file); + ///\brief Wrapper for switch_xml_parse_str() that accepts a file stream. Reads the entire ///\ stream into memory and then parses it. For xml files, use switch_xml_parse_file() ///\ or switch_xml_parse_fd() diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index f4ffc0710e..3ec37baa5d 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -316,7 +316,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session, if (!switch_strlen_zero(alt_path)) { switch_xml_t conf = NULL, tag = NULL; - if (!(alt_root = switch_xml_parse_file(alt_path))) { + if (!(alt_root = switch_xml_parse_file_simple(alt_path))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path); goto done; } diff --git a/src/switch_xml.c b/src/switch_xml.c index 61a0c4cde4..584528c4af 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1032,7 +1032,26 @@ static int preprocess(const char *file, int write_fd, int rlevel) return write_fd; } -// a wrapper for switch_xml_parse_fd that accepts a file name +SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file) +{ + int fd = -1; + struct stat st; + switch_size_t l; + void *m; + switch_xml_root_t root; + + if ((fd = open(file, O_RDONLY, 0)) > -1) { + fstat(fd, &st); + l = read(fd, m = malloc(st.st_size), st.st_size); + root = (switch_xml_root_t) switch_xml_parse_str(m, l); + root->dynamic = 1; + close(fd); + return &root->xml; + } + + return NULL; +} + SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) { int fd = -1, write_fd = -1; @@ -1045,7 +1064,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) } else { abs = file; } - + if (!(new_file = switch_mprintf("%s%s%s.fsxml", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, abs))) { return NULL; }