diff --git a/buildconf/default.ini b/buildconf/default.ini
index 1a73b3f2..655cda3f 100644
--- a/buildconf/default.ini
+++ b/buildconf/default.ini
@@ -1,5 +1,5 @@
[uwsgi]
-xml = true
+xml = auto
ini = true
yaml = true
json = auto
diff --git a/mega.xml b/mega.xml
index d0eebc9c..72276212 100644
--- a/mega.xml
+++ b/mega.xml
@@ -19,4 +19,8 @@
trac.web.main:dispatch_request
+
+ :3031
+
+
diff --git a/uwsgiconfig.py b/uwsgiconfig.py
index 8846c4ea..64da3275 100644
--- a/uwsgiconfig.py
+++ b/uwsgiconfig.py
@@ -753,7 +753,19 @@ class uConf(object):
self.gcc_list.append('sendfile')
if self.get('xml'):
- if self.get('xml_implementation') == 'libxml2':
+ if self.get('xml') == 'auto':
+ xmlconf = spcall('xml2-config --libs')
+ if xmlconf:
+ self.libs.append(xmlconf)
+ xmlconf = spcall("xml2-config --cflags")
+ self.cflags.append(xmlconf)
+ self.cflags.append("-DUWSGI_XML -DUWSGI_XML_LIBXML2")
+ self.gcc_list.append('xmlconf')
+ elif self.has_include('expat.h'):
+ self.cflags.append("-DUWSGI_XML -DUWSGI_XML_EXPAT")
+ self.libs.append('-lexpat')
+ self.gcc_list.append('xmlconf')
+ elif self.get('xml_implementation') == 'libxml2':
xmlconf = spcall('xml2-config --libs')
if xmlconf is None:
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
diff --git a/xmlconf.c b/xmlconf.c
index 83bbdf83..0c22c234 100644
--- a/xmlconf.c
+++ b/xmlconf.c
@@ -120,6 +120,106 @@ void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, char *magic
#include
+int uwsgi_xml_found_stanza = 0;
+char *uwsgi_xml_found_opt_key = NULL;
+
+static void startElement(void *xml_id, const XML_Char *name, const XML_Char **attrs) {
+
+
+ if (!uwsgi_xml_found_stanza) {
+ if (xml_id) {
+ if (!attrs[0]) return;
+ if (!attrs[1]) return;
+ if (strcmp("id", attrs[0])) return;
+ if (strcmp((char *)xml_id, attrs[1])) return;
+ }
+ if (!strcmp("uwsgi", name)) uwsgi_xml_found_stanza = 1;
+ }
+ else {
+ uwsgi_xml_found_opt_key = (char *) name;
+ }
+}
+
+
+static void textElement(void *xml_id, const char *s, int len) {
+
+ if (!uwsgi_xml_found_stanza) return ;
+ if (uwsgi_xml_found_opt_key) {
+ add_exported_option(strdup(uwsgi_xml_found_opt_key), uwsgi_concat2n((char *)s, len, (char *)"", 0), 0);
+ uwsgi_xml_found_opt_key = NULL;
+ }
+}
+
+static void endElement(void *xml_id, const XML_Char *name) {
+
+ if (!uwsgi_xml_found_stanza) return ;
+
+ if (!strcmp(name, "uwsgi")) {
+ uwsgi_xml_found_stanza = 0;
+ return;
+ }
+
+ if (!uwsgi_xml_found_opt_key) return;
+
+ add_exported_option(strdup(uwsgi_xml_found_opt_key), strdup("1"), 0);
+ uwsgi_xml_found_opt_key = NULL;
+}
+
+void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, char *magic_table[]) {
+
+ char *colon;
+
+ char *xml_content;
+ int xml_size = 0;
+ int done = 0;
+
+ if (uwsgi_check_scheme(filename)) {
+ colon = uwsgi_get_last_char(filename, '/');
+ colon = uwsgi_get_last_char(colon, ':');
+ }
+ else {
+ colon = uwsgi_get_last_char(filename, ':');
+ }
+ if (colon) {
+ colon[0] = 0;
+ colon++;
+ if (*colon == 0) {
+ uwsgi_log("invalid xml id\n");
+ exit(1);
+ }
+ uwsgi_log( "[uWSGI] using xml uwsgi id: %s\n", colon);
+ }
+
+ xml_content = uwsgi_open_and_read(filename, &xml_size, 0, magic_table);
+
+ uwsgi_log( "[uWSGI] parsing config file %s\n", filename);
+
+ XML_Parser parser = XML_ParserCreate(NULL);
+ XML_SetUserData(parser, NULL);
+ if (colon) {
+ XML_SetUserData(parser, colon);
+ }
+
+ XML_SetElementHandler(parser, startElement, endElement);
+ XML_SetCharacterDataHandler(parser, textElement);
+
+ do {
+ if (!XML_Parse(parser, xml_content, xml_size, done)) {
+ if (XML_GetErrorCode(parser) != XML_ERROR_JUNK_AFTER_DOC_ELEMENT) {
+ uwsgi_log("unable to parse xml file: %s (line %d)\n", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
+ exit(1);
+ }
+ else {
+ break;
+ }
+ }
+
+ } while(!done);
+
+
+ // we can safely free, as we have a copy of datas
+ XML_ParserFree(parser);
+}
#endif