add support for XInclude in the main configuration file
[pazpar2-moved-to-github.git] / src / pazpar2_config.c
index 4266275..a4503b7 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2013 Index Data
+   Copyright (C) Index Data
 
 Pazpar2 is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
+#include <libxml/xinclude.h>
 
 #include <yaz/yaz-util.h>
 #include <yaz/nmem.h>
@@ -1232,7 +1233,10 @@ static int parse_config(struct conf_config *config, xmlNode *root)
 
 struct conf_config *config_create(const char *fname, int verbose)
 {
-    xmlDoc *doc = xmlParseFile(fname);
+    xmlDoc *doc = xmlReadFile(fname,
+                              NULL,
+                              XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
+                              + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
     xmlNode *n;
     const char *p;
     int r;
@@ -1248,6 +1252,14 @@ struct conf_config *config_create(const char *fname, int verbose)
         return 0;
     }
 
+    // Perform XInclude.
+    r = xmlXIncludeProcess(doc);
+    if (r == -1)
+    {
+        yaz_log(YLOG_FATAL, "XInclude processing failed");
+        return 0;
+    }
+
     config->nmem = nmem;
     config->servers = 0;
     config->no_threads = 0;