Test using dynamic rank
[pazpar2-moved-to-github.git] / src / pazpar2_config.c
index 27241a6..698fb15 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2012 Index Data
+   Copyright (C) 2006-2013 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
@@ -64,6 +64,25 @@ struct service_xslt
     struct service_xslt *next;
 };
 
+static char *xml_context(const xmlNode *ptr, char *res, size_t len)
+{
+    size_t off = len - 1;
+    res[off] = '\0';
+    while (ptr && ptr->type == XML_ELEMENT_NODE)
+    {
+        size_t l = strlen((const char *) ptr->name);
+        if (off <= l + 1)
+            break;
+
+        off = off - l;
+        memcpy(res + off, ptr->name, l);
+        res[--off] = '/';
+
+        ptr = ptr->parent;
+    }
+    return res + off;
+}
+
 struct conf_service *service_init(struct conf_server *server,
                                          int num_metadata, int num_sortkeys,
                                          const char *service_id)
@@ -385,6 +404,8 @@ static int parse_metadata(struct conf_service *service, xmlNode *n,
             merge = Metadata_merge_range;
         else if (!strcmp((const char *) xml_merge, "all"))
             merge = Metadata_merge_all;
+        else if (!strcmp((const char *) xml_merge, "first"))
+            merge = Metadata_merge_first;
         else
         {
             yaz_log(YLOG_FATAL,
@@ -595,15 +616,6 @@ static struct conf_service *service_create_static(struct conf_server *server,
             if (service_xslt_config(service, n))
                 return 0;
         }
-        else if (!strcmp((const char *) n->name, (const char *) "set"))
-        {
-            xmlChar *name= xmlGetProp(n, (xmlChar *) "name");
-            xmlChar *value = xmlGetProp(n, (xmlChar *) "value");
-            if (service->dictionary && name && value) {
-                yaz_log(YLOG_DEBUG, "service set: %s=%s (Not implemented)", (char *) name, (char *) value);
-                //service_aply_setting(service, name, value);
-            }
-        }
         else if (!strcmp((const char *) n->name, "rank"))
         {
             char *rank_cluster = (char *) xmlGetProp(n, (xmlChar *) "cluster");
@@ -681,7 +693,9 @@ static struct conf_service *service_create_static(struct conf_server *server,
         }
         else
         {
-            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+            char tmp[80];
+            yaz_log(YLOG_FATAL, "Bad element: %s . Context: %s", n->name,
+                    xml_context(n, tmp, sizeof tmp));
             return 0;
         }
     }
@@ -780,7 +794,7 @@ static struct conf_server *server_create(struct conf_config *config,
     struct conf_server *server = nmem_malloc(nmem, sizeof(struct conf_server));
     xmlChar *server_id = xmlGetProp(node, (xmlChar *) "id");
 
-    server->host = 0;
+    server->host = "@";
     server->port = 0;
     server->proxy_host = 0;
     server->proxy_port = 0;
@@ -809,10 +823,12 @@ static struct conf_server *server_create(struct conf_config *config,
         {
             xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
             xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
+
             if (port)
-                server->port = atoi((const char *) port);
+                server->port = nmem_strdup(nmem, (const char *) port);
             if (host)
                 server->host = nmem_strdup(nmem, (const char *) host);
+
             xmlFree(port);
             xmlFree(host);
         }
@@ -916,6 +932,11 @@ static struct conf_server *server_create(struct conf_config *config,
             return 0;
         }
     }
+    if (!server->port)
+    {
+        yaz_log(YLOG_FATAL, "No listening port given");
+        return 0;
+    }
     if (server->service)
     {
         struct conf_service *s;
@@ -1137,28 +1158,27 @@ int config_start_listeners(struct conf_config *conf,
     conf->iochan_man = iochan_man_create(conf->no_threads);
     for (ser = conf->servers; ser; ser = ser->next)
     {
-        WRBUF w = wrbuf_alloc();
+        WRBUF w;
         int r;
 
         ser->iochan_man = conf->iochan_man;
         if (listener_override)
         {
-            wrbuf_puts(w, listener_override);
-            listener_override = 0; /* only first server is overriden */
-        }
-        else
-        {
-            if (ser->host)
-                wrbuf_puts(w, ser->host);
-            if (ser->port)
+            const char *cp = strrchr(listener_override, ':');
+            if (cp)
             {
-                if (wrbuf_len(w))
-                    wrbuf_puts(w, ":");
-                wrbuf_printf(w, "%d", ser->port);
+                ser->host = nmem_strdupn(conf->nmem, listener_override,
+                                         cp - listener_override);
+                ser->port = nmem_strdup(conf->nmem, cp + 1);
             }
+            else
+            {
+                ser->host = "@";
+                ser->port = nmem_strdup(conf->nmem, listener_override);
+            }
+            listener_override = 0; /* only first server is overriden */
         }
-        r = http_init(wrbuf_cstr(w), ser, record_fname);
-        wrbuf_destroy(w);
+        r = http_init(ser, record_fname);
         if (r)
             return -1;