diff --git a/conf/conference.conf.xml b/conf/conference.conf.xml
new file mode 100644
index 0000000000..c1a1056ac9
--- /dev/null
+++ b/conf/conference.conf.xml
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/console.conf.xml b/conf/console.conf.xml
new file mode 100644
index 0000000000..9ea7b65c5e
--- /dev/null
+++ b/conf/console.conf.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/conf/default_context.xml b/conf/default_context.xml
new file mode 100644
index 0000000000..2e0c19305e
--- /dev/null
+++ b/conf/default_context.xml
@@ -0,0 +1,105 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/dialplan_directory.conf.xml b/conf/dialplan_directory.conf.xml
new file mode 100644
index 0000000000..e4edcd6b15
--- /dev/null
+++ b/conf/dialplan_directory.conf.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/conf/dingaling.conf.xml b/conf/dingaling.conf.xml
new file mode 100644
index 0000000000..487358f62f
--- /dev/null
+++ b/conf/dingaling.conf.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/directory.xml b/conf/directory.xml
new file mode 100644
index 0000000000..815cd6b049
--- /dev/null
+++ b/conf/directory.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+ Peter Saint-Andre
+
+ Saint-Andre
+ Peter
+
+
+ stpeter
+ http://www.jabber.org/people/stpeter.php
+ 1966-08-06
+
+ Jabber Software Foundation
+ Jabber Software Foundation
+
+ Executive Director
+ Patron Saint
+ 303-308-3282
+
+
+
+
+ Suite 600
+ 1899 Wynkoop Street
+ Denver
+ CO
+ 80202
+ USA
+
+ 303-555-1212
+
+
+
+
+
+
+ Denver
+ CO
+ 80209
+ USA
+
+ stpeter@jabber.org
+ stpeter@jabber.org
+
+ More information about me is located on my
+ personal website: http://www.saint-andre.com/
+
+
+
+
+
diff --git a/conf/enum.conf.xml b/conf/enum.conf.xml
new file mode 100644
index 0000000000..e0881c269d
--- /dev/null
+++ b/conf/enum.conf.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/event_multicast.conf.xml b/conf/event_multicast.conf.xml
new file mode 100644
index 0000000000..9f2091df35
--- /dev/null
+++ b/conf/event_multicast.conf.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/conf/event_socket.conf.xml b/conf/event_socket.conf.xml
new file mode 100644
index 0000000000..ea9a0b9ba7
--- /dev/null
+++ b/conf/event_socket.conf.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/conf/freeswitch.xml b/conf/freeswitch.xml
index bd97be82da..825d9652a5 100644
--- a/conf/freeswitch.xml
+++ b/conf/freeswitch.xml
@@ -1,800 +1,66 @@
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
- Peter Saint-Andre
-
- Saint-Andre
- Peter
-
-
- stpeter
- http://www.jabber.org/people/stpeter.php
- 1966-08-06
-
- Jabber Software Foundation
- Jabber Software Foundation
-
- Executive Director
- Patron Saint
- 303-308-3282
-
-
-
-
- Suite 600
- 1899 Wynkoop Street
- Denver
- CO
- 80202
- USA
-
- 303-555-1212
-
-
-
-
-
-
- Denver
- CO
- 80209
- USA
-
- stpeter@jabber.org
- stpeter@jabber.org
-
- More information about me is located on my
- personal website: http://www.saint-andre.com/
-
-
-
-
-
+
+
-
diff --git a/conf/iax.conf.xml b/conf/iax.conf.xml
new file mode 100644
index 0000000000..df4109d2a1
--- /dev/null
+++ b/conf/iax.conf.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/ivr.conf.xml b/conf/ivr.conf.xml
new file mode 100644
index 0000000000..d1859836bc
--- /dev/null
+++ b/conf/ivr.conf.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
diff --git a/conf/lang_en.xml b/conf/lang_en.xml
new file mode 100644
index 0000000000..e27f84da71
--- /dev/null
+++ b/conf/lang_en.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/lang_fr.xml b/conf/lang_fr.xml
new file mode 100644
index 0000000000..3b2edac441
--- /dev/null
+++ b/conf/lang_fr.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/modules.conf.xml b/conf/modules.conf.xml
new file mode 100644
index 0000000000..0ef7e7de1f
--- /dev/null
+++ b/conf/modules.conf.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/portaudio.conf.xml b/conf/portaudio.conf.xml
new file mode 100644
index 0000000000..34b46961b5
--- /dev/null
+++ b/conf/portaudio.conf.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/rss.conf.xml b/conf/rss.conf.xml
new file mode 100644
index 0000000000..f8c4f6d2b4
--- /dev/null
+++ b/conf/rss.conf.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/conf/sofia.conf.xml b/conf/sofia.conf.xml
new file mode 100644
index 0000000000..2933754efa
--- /dev/null
+++ b/conf/sofia.conf.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/spidermonkey.conf.xml b/conf/spidermonkey.conf.xml
new file mode 100644
index 0000000000..4d42ccc021
--- /dev/null
+++ b/conf/spidermonkey.conf.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/conf/switch.conf.xml b/conf/switch.conf.xml
new file mode 100644
index 0000000000..818f91542e
--- /dev/null
+++ b/conf/switch.conf.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/syslog.conf.xml b/conf/syslog.conf.xml
new file mode 100644
index 0000000000..c929e16aaa
--- /dev/null
+++ b/conf/syslog.conf.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/wanpipe.conf.xml b/conf/wanpipe.conf.xml
new file mode 100644
index 0000000000..d7dd17e308
--- /dev/null
+++ b/conf/wanpipe.conf.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/woomera.conf.xml b/conf/woomera.conf.xml
new file mode 100644
index 0000000000..7b8d14fd17
--- /dev/null
+++ b/conf/woomera.conf.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/xml_curl.conf.xml b/conf/xml_curl.conf.xml
new file mode 100644
index 0000000000..398226ddb7
--- /dev/null
+++ b/conf/xml_curl.conf.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
diff --git a/conf/xml_rpc.conf.xml b/conf/xml_rpc.conf.xml
new file mode 100644
index 0000000000..714a909907
--- /dev/null
+++ b/conf/xml_rpc.conf.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/xmpp_event.conf.xml b/conf/xmpp_event.conf.xml
new file mode 100644
index 0000000000..630ea3357e
--- /dev/null
+++ b/conf/xmpp_event.conf.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/conf/zeroconf.conf.xml b/conf/zeroconf.conf.xml
new file mode 100644
index 0000000000..84c1a46171
--- /dev/null
+++ b/conf/zeroconf.conf.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/src/switch_xml.c b/src/switch_xml.c
index f2da227986..ff79effb2c 100644
--- a/src/switch_xml.c
+++ b/src/switch_xml.c
@@ -781,13 +781,204 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
return &root->xml;
}
+static switch_size_t read_line(int fd, char *buf, switch_size_t len) {
+ char c, *p;
+ int cur;
+ switch_size_t total = 0;
+
+ p = buf;
+ while (total + sizeof(c) < len && (cur = read(fd, &c, sizeof(c))) > 0) {
+ total += cur;
+ *p++ = c;
+ if (c == '\n') {
+ break;
+ }
+ }
+
+ *p++ = '\0';
+ return total;
+}
+
+static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_t *newlen)
+{
+ char *var, *val;
+ char *rp = buf;
+ char *wp = ebuf;
+ char *ep = ebuf + elen - 1;
+
+ if (!(var = strstr(rp, "$${"))) {
+ *newlen = strlen(buf);
+ return buf;
+ }
+
+ while(*rp && wp < ep) {
+
+ if (*rp == '$' && *(rp+1) == '$' && *(rp+2) == '{') {
+ char *e = strchr(rp, '}');
+
+ if (e) {
+ rp += 3;
+ var = rp;
+ *e++ = '\0';
+ rp = e;
+ if ((val = switch_core_get_variable(var))) {
+ char *p;
+ for(p = val; p && *p && wp <= ep; p++) {
+ *wp++ = *p;
+ }
+ }
+ }
+
+ }
+
+ *wp++ = *rp++;
+ }
+ *wp++ = '\0';
+ *newlen = strlen(ebuf);
+
+ return ebuf;
+
+}
+
+static int preprocess(const char *file, int new_fd, int rlevel)
+{
+ int old_fd, close_fd = -1;
+ char *new_file = NULL;
+ switch_size_t cur = 0, ml = 0;
+ char *q, *cmd, buf[2048], ebuf[8192];
+
+ if ((old_fd = open(file, O_RDONLY, 0)) < 0) {
+ return old_fd;
+ }
+
+ if (rlevel > 100) {
+ return -1;
+ }
+
+ if (new_fd < 0) {
+ if (!(new_file = switch_mprintf("%s/freeswitch.registry", SWITCH_GLOBAL_dirs.log_dir))) {
+ goto done;
+ }
+
+ if ((new_fd = open(new_file, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0) {
+ goto done;
+ }
+ close_fd = new_fd;
+ }
+
+ while((cur = read_line(old_fd, buf, sizeof(buf))) > 0) {
+ char *arg, *e;
+ char *bp = expand_vars(buf, ebuf, sizeof(ebuf), &cur);
+
+ /* we ignore or for the sake of validators */
+ if (strstr(buf, "") || strstr(buf, "")) {
+ continue;
+ }
+
+ if (ml) {
+ if ((e = strstr(buf, "-->"))) {
+ ml = 0;
+ bp = e + 3;
+ cur = strlen(bp);
+ } else {
+ continue;
+ }
+ }
+
+ if ((cmd = strstr(bp, ""))) {
+ *e = '\0';
+ e += 3;
+ write(new_fd, e, strlen(e));
+ } else {
+ ml++;
+ }
+
+ cmd += 5;
+ if ((e = strchr(cmd, '\r')) || (e = strchr(cmd, '\n'))) {
+ *e = '\0';
+ }
+
+ if ((arg = strchr(cmd, ' '))) {
+ *arg++ = '\0';
+ if ((q = strchr(arg, '"'))) {
+ char *qq = q+1;
+
+ if ((qq = strchr(qq, '"'))) {
+ *qq = '\0';
+ arg = q+1;
+ }
+ }
+
+ if (!strcasecmp(cmd, "set")) {
+ char *name = arg;
+ char *val = strchr(name, '=');
+
+ if (val) {
+ char *ve = val++;
+ while(*val && *val == ' ') {
+ val++;
+ }
+ *ve-- = '\0';
+ while(*ve && *ve == ' ') {
+ *ve-- = '\0';
+ }
+ }
+
+ if (name && val) {
+ switch_core_set_variable(name, val);
+ }
+
+ } else if (!strcasecmp(cmd, "include")) {
+ char *fme = NULL, *ifile = arg;
+
+ if (!switch_is_file_path(ifile)) {
+ fme = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, arg);
+ ifile = fme;
+ }
+ if (preprocess(ifile, new_fd, rlevel + 1) < 0) {
+ fprintf(stderr, "Error including %s (%s)\n", ifile, strerror(errno));
+ }
+ switch_safe_free(fme);
+ } /* else NO OP */
+ }
+
+ continue;
+ }
+
+ write(new_fd, bp, cur);
+ }
+
+ close(old_fd);
+
+ if (close_fd > -1) {
+ close(close_fd);
+ new_fd = open(new_file, O_RDONLY, 0);
+ }
+
+ done:
+
+ switch_safe_free(new_file);
+
+ if (new_fd < 0) {
+ return old_fd;
+ }
+
+ return new_fd;
+}
+
// a wrapper for switch_xml_parse_fd that accepts a file name
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
{
- int fd = open(file, O_RDONLY, 0);
- switch_xml_t xml = switch_xml_parse_fd(fd);
+ int fd = -1;
+ switch_xml_t xml = NULL;
+
+ if ((fd = preprocess(file, -1, 0)) > -1) {
+ xml = switch_xml_parse_fd(fd);
+ close(fd);
+ }
- if (fd >= 0) close(fd);
return xml;
}