Make more room for YAZ version string
[pazpar2-moved-to-github.git] / src / config.c
index 46c3f64..de47152 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: config.c,v 1.5 2007-01-08 18:32:35 quinn Exp $ */
+/* $Id: config.c,v 1.10 2007-01-12 15:08:44 quinn Exp $ */
 
 #include <string.h>
 
@@ -30,16 +30,27 @@ static struct conf_service *parse_service(xmlNode *node)
 {
     xmlNode *n;
     struct conf_service *r = nmem_malloc(nmem, sizeof(struct conf_service));
-    int num_metadata = 0;
     int md_node = 0;
 
+    r->num_sortkeys = r->num_metadata = 0;
     // Allocate array of conf metadata structs, if necessary
     for (n = node->children; n; n = n->next)
         if (n->type == XML_ELEMENT_NODE && !strcmp(n->name, "metadata"))
-            num_metadata++;
-    if (num_metadata)
-        r->metadata = nmem_malloc(nmem, sizeof(struct conf_metadata) * num_metadata);
-    r->num_metadata = num_metadata;
+        {
+            xmlChar *sortkey = xmlGetProp(n, "sortkey");
+            r->num_metadata++;
+            if (sortkey && strcmp(sortkey, "no"))
+                r->num_sortkeys++;
+            xmlFree(sortkey);
+        }
+    if (r->num_metadata)
+        r->metadata = nmem_malloc(nmem, sizeof(struct conf_metadata) * r->num_metadata);
+    else
+        r->metadata = 0;
+    if (r->num_sortkeys)
+        r->sortkeys = nmem_malloc(nmem, sizeof(struct conf_sortkey) * r->num_sortkeys);
+    else
+        r->sortkeys = 0;
 
     for (n = node->children; n; n = n->next)
     {
@@ -54,6 +65,7 @@ static struct conf_service *parse_service(xmlNode *node)
             xmlChar *merge = xmlGetProp(n, "merge");
             xmlChar *type = xmlGetProp(n, "type");
             xmlChar *termlist = xmlGetProp(n, "termlist");
+            xmlChar *rank = xmlGetProp(n, "rank");
 
             if (!name)
             {
@@ -87,6 +99,11 @@ static struct conf_service *parse_service(xmlNode *node)
             else
                 md->termlist = 0;
 
+            if (rank)
+                md->rank = atoi(rank);
+            else
+                md->rank = 0;
+
             if (type)
             {
                 if (!strcmp(type, "generic"))
@@ -101,7 +118,8 @@ static struct conf_service *parse_service(xmlNode *node)
                     return 0;
                 }
             }
-            md->type = Metadata_type_generic;
+            else
+                md->type = Metadata_type_generic;
 
             if (sortkey)
             {
@@ -148,6 +166,7 @@ static struct conf_service *parse_service(xmlNode *node)
             xmlFree(sortkey);
             xmlFree(merge);
             xmlFree(termlist);
+            xmlFree(rank);
             md_node++;
         }
         else
@@ -320,7 +339,7 @@ static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node)
             xmlChar *charset = xmlGetProp(n, "charset");
             xmlChar *format = xmlGetProp(n, "format");
             xmlChar *stylesheet = xmlGetProp(n, "stylesheet");
-            bzero(m, sizeof(*m));
+            memset(m, 0, sizeof(*m));
             if (type)
             {
                 if (!strcmp(type, "xslt"))
@@ -413,7 +432,7 @@ int read_config(const char *fname)
         yaz_log(YLOG_FATAL, "Failed to read %s", fname);
         exit(1);
     }
-    if ((p = rindex(fname, '/')))
+    if ((p = strrchr(fname, '/')))
     {
         int len = p - fname;
         strncpy(confdir, fname, len);