Remove support for deprecated ICU definitions
[pazpar2-moved-to-github.git] / src / pazpar2_config.c
index 92717e2..4332397 100644 (file)
@@ -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>
@@ -511,6 +512,18 @@ static int parse_metadata(struct conf_service *service, xmlNode *n,
     return 0;
 }
 
+
+static void count_metadata(xmlNode *n, int *num_metadata, int *num_sortkeys)
+{
+    xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
+    (*num_metadata)++;
+
+    if (sortkey && strcmp((const char *) sortkey, "no"))
+        (*num_sortkeys)++;
+    xmlFree(sortkey);
+}
+
+
 static struct conf_service *service_create_static(struct conf_server *server,
                                                   xmlNode *node,
                                                   const char *service_id)
@@ -529,11 +542,18 @@ static struct conf_service *service_create_static(struct conf_server *server,
         if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)
                                                    n->name, "metadata"))
         {
-            xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
-            num_metadata++;
-            if (sortkey && strcmp((const char *) sortkey, "no"))
-                num_sortkeys++;
-            xmlFree(sortkey);
+            if (n->children) // This is a <metadata> container, look at its contents.
+            {
+                xmlNode *m;
+                for (m = n->children; m; m = m->next)
+                {
+                    if (m->type == XML_ELEMENT_NODE &&
+                            !strcmp((const char *) m->name, "metadata"))
+                        count_metadata(m, &num_metadata, &num_sortkeys);
+                }
+            }
+            else // This is a metadata-element proper, count it right away.
+                count_metadata(n, &num_metadata, &num_sortkeys);
         }
 
     service = service_init(server, num_metadata, num_sortkeys, service_id);
@@ -619,19 +639,23 @@ static struct conf_service *service_create_static(struct conf_server *server,
                  || !strcmp((const char *) n->name, "facet"))
 
         {
-            if (!service->charsets)
-                service->charsets = pp2_charset_fact_create();
-            if (pp2_charset_fact_define(service->charsets,
-                                        n->children, (const char *) n->name))
-            {
-                yaz_log(YLOG_FATAL, "ICU chain definition error");
-                return 0;
-            }
+            yaz_log(YLOG_FATAL, "No longer supported: <%s>", n->name);
+            yaz_log(YLOG_LOG, "Use <icu_chain id=\"%s\">.. instead", n->name);
+            return 0;
         }
         else if (!strcmp((const char *) n->name, (const char *) "metadata"))
         {
-            if (parse_metadata(service, n, &md_node, &sk_node))
-                return 0;
+            if (n->children) // This is a <metadata> container, look at its content.
+            {
+                xmlNode *m;
+                for (m = n->children; m; m = m->next)
+                    if ((!strcmp((const char *) m->name, (const char *) "metadata")))
+                        if (parse_metadata(service, m, &md_node, &sk_node))
+                            return 0;
+            }
+            else // This is a metadata-element proper, count it right away.
+                if (parse_metadata(service, n, &md_node, &sk_node))
+                    return 0;
         }
         else if (!strcmp((const char *) n->name, (const char *) "xslt"))
         {
@@ -651,7 +675,7 @@ static struct conf_service *service_create_static(struct conf_server *server,
                     service->rank_cluster = 1;
                 else if (!strcmp(rank_cluster, "no"))
                     service->rank_cluster = 0;
-                else 
+                else
                 {
                     yaz_log(YLOG_FATAL, "service: rank@cluster boolean");
                     return 0;
@@ -682,7 +706,7 @@ static struct conf_service *service_create_static(struct conf_server *server,
                 if (!strcmp(rank_length, "linear"))
                     service->rank_length = 2;
                 else if (!strcmp(rank_length, "log"))
-                    service->rank_length = 1; 
+                    service->rank_length = 1;
                 else if (!strcmp(rank_length, "none"))
                     service->rank_length = 0;
                 else
@@ -913,14 +937,9 @@ static struct conf_server *server_create(struct conf_config *config,
                  || !strcmp((const char *) n->name, "mergekey")
                  || !strcmp((const char *) n->name, "facet"))
         {
-            if (!server->charsets)
-                server->charsets = pp2_charset_fact_create();
-            if (pp2_charset_fact_define(server->charsets,
-                                        n->children, (const char *) n->name))
-            {
-                yaz_log(YLOG_FATAL, "ICU chain definition error");
-                return 0;
-            }
+            yaz_log(YLOG_FATAL, "No longer supported: <%s>", n->name);
+            yaz_log(YLOG_LOG, "Use <icu_chain id=\"%s\">.. instead", n->name);
+            return 0;
         }
         else if (!strcmp((const char *) n->name, "service"))
         {
@@ -1232,7 +1251,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_NSCLEAN + XML_PARSE_NONET);
     xmlNode *n;
     const char *p;
     int r;
@@ -1248,6 +1270,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;