Happy new year
[pazpar2-moved-to-github.git] / src / pazpar2_config.c
index 8862123..290a39a 100644 (file)
@@ -53,7 +53,9 @@ struct conf_config
     struct conf_server *servers;
 
     int no_threads;
+    int max_sockets;
     WRBUF confdir;
+    char *path;
     iochan_man_t iochan_man;
 };
 
@@ -168,7 +170,8 @@ static struct conf_metadata* conf_service_add_metadata(
     enum conf_metadata_mergekey mt,
     const char *facetrule,
     const char *limitmap,
-    const char *limitcluster
+    const char *limitcluster,
+    const char *icurule
     )
 {
     struct conf_metadata * md = 0;
@@ -200,6 +203,7 @@ static struct conf_metadata* conf_service_add_metadata(
     md->facetrule = nmem_strdup_null(nmem, facetrule);
     md->limitmap = nmem_strdup_null(nmem, limitmap);
     md->limitcluster = nmem_strdup_null(nmem, limitcluster);
+    md->icurule = nmem_strdup_null(nmem, icurule);
     return md;
 }
 
@@ -255,13 +259,20 @@ int conf_service_sortkey_field_id(struct conf_service *service,
 
 static void conf_dir_path(struct conf_config *config, WRBUF w, const char *src)
 {
-    if (config->confdir && wrbuf_len(config->confdir) > 0 &&
-        !yaz_is_abspath(src))
+    char full_path[1024];
+    if (yaz_filepath_resolve(src, config->path,
+                             wrbuf_len(config->confdir) > 0 ?
+                             wrbuf_cstr(config->confdir) : ".",
+                             full_path))
     {
-        wrbuf_printf(w, "%s/%s", wrbuf_cstr(config->confdir), src);
+        wrbuf_puts(w, full_path);
     }
     else
+    {
+        yaz_log(YLOG_WARN, "File not found: fname=%s path=%s base=%s", src,
+                config->path, wrbuf_cstr(config->confdir));
         wrbuf_puts(w, src);
+    }
 }
 
 void service_destroy(struct conf_service *service)
@@ -306,6 +317,7 @@ static int parse_metadata(struct conf_service *service, xmlNode *n,
     xmlChar *xml_limitmap = 0;
     xmlChar *xml_limitcluster = 0;
     xmlChar *xml_icu_chain = 0;
+    xmlChar *xml_icurule = 0;
 
     struct _xmlAttr *attr;
 
@@ -349,6 +361,9 @@ static int parse_metadata(struct conf_service *service, xmlNode *n,
         else if (!xmlStrcmp(attr->name, BAD_CAST "limitcluster") &&
                  attr->children && attr->children->type == XML_TEXT_NODE)
             xml_limitcluster = attr->children->content;
+        else if (!xmlStrcmp(attr->name, BAD_CAST "icurule") &&
+                 attr->children && attr->children->type == XML_TEXT_NODE)
+            xml_icurule = attr->children->content;
         else
         {
             yaz_log(YLOG_FATAL, "Unknown metadata attribute '%s'", attr->name);
@@ -506,7 +521,9 @@ static int parse_metadata(struct conf_service *service, xmlNode *n,
                               mergekey_type,
                               (const char *) xml_icu_chain,
                               (const char *) xml_limitmap,
-                              (const char *) xml_limitcluster);
+                              (const char *) xml_limitcluster,
+                              (const char *) xml_icurule
+        );
     (*md_node)++;
     return 0;
 }
@@ -638,9 +655,14 @@ static struct conf_service *service_create_static(struct conf_server *server,
                  || !strcmp((const char *) n->name, "facet"))
 
         {
-            yaz_log(YLOG_FATAL, "No longer supported: <%s>", n->name);
-            yaz_log(YLOG_LOG, "Use <icu_chain id=\"%s\">.. instead", n->name);
-            return 0;
+            if (!service->charsets)
+                service->charsets = pp2_charset_fact_create();
+            if (pp2_charset_fact_define(service->charsets, n,
+                                        (const char *) n->name))
+            {
+                yaz_log(YLOG_FATAL, "ICU chain definition error");
+                return 0;
+            }
         }
         else if (!strcmp((const char *) n->name, (const char *) "metadata"))
         {
@@ -935,9 +957,14 @@ static struct conf_server *server_create(struct conf_config *config,
                  || !strcmp((const char *) n->name, "mergekey")
                  || !strcmp((const char *) n->name, "facet"))
         {
-            yaz_log(YLOG_FATAL, "No longer supported: <%s>", n->name);
-            yaz_log(YLOG_LOG, "Use <icu_chain id=\"%s\">.. instead", n->name);
-            return 0;
+            if (!server->charsets)
+                server->charsets = pp2_charset_fact_create();
+            if (pp2_charset_fact_define(server->charsets, n,
+                                        (const char *) n->name))
+            {
+                yaz_log(YLOG_FATAL, "ICU chain definition error");
+                return 0;
+            }
         }
         else if (!strcmp((const char *) n->name, "service"))
         {
@@ -1055,6 +1082,9 @@ static void info_service_metadata(struct conf_service *service, WRBUF w)
                 case Metadata_type_position:
                     wrbuf_puts(w, "position");
                     break;
+                case Metadata_type_retrieval:
+                    wrbuf_puts(w, "retrieval");
+                    break;
                 default:
                     wrbuf_puts(w, "yes");
                     break;
@@ -1075,8 +1105,7 @@ static void info_service_metadata(struct conf_service *service, WRBUF w)
             case Metadata_type_float:
                 wrbuf_puts(w, " type=\"float\"");
                 break;
-            case Metadata_type_relevance:
-            case Metadata_type_position:
+            default:
                 break;
             }
             switch (md->merge)
@@ -1117,15 +1146,14 @@ static void info_service_metadata(struct conf_service *service, WRBUF w)
 
 static void info_service_databases(struct conf_service *service, WRBUF w)
 {
-    struct database *db;
-    struct setting *s;
-    int i;
 
     if (service->databases)
     {
+        struct database *db;
         wrbuf_puts(w, "   <databases>\n");
-        for(db = service->databases; db; db = db->next)
+        for (db = service->databases; db; db = db->next)
         {
+            int i;
             wrbuf_puts(w, "    <database");
             if (db->id)
             {
@@ -1136,18 +1164,16 @@ static void info_service_databases(struct conf_service *service, WRBUF w)
             wrbuf_puts(w, ">\n");
             for (i = 0; i < db->num_settings; i++)
             {
-                s = db->settings[i];
-                while (s != NULL)
+                struct setting *s = db->settings[i];
+                for (; s; s = s->next)
                 {
-                    wrbuf_puts(w, "     <setting");
-                    wrbuf_puts(w, " name=\"");
+                    wrbuf_puts(w, "     <setting name=\"");
                     wrbuf_xmlputs(w, s->name);
                     wrbuf_puts(w, "\"");
                     wrbuf_puts(w, " value=\"");
                     wrbuf_xmlputs(w, s->value);
                     wrbuf_puts(w, "\"");
                     wrbuf_puts(w, " />\n");
-                    s = s->next;
                 }
             }
             wrbuf_puts(w, "    </database>\n");
@@ -1160,7 +1186,6 @@ void info_services(struct conf_server *server, WRBUF w)
 {
     struct conf_service *s = server->service;
     int i;
-    struct setting *S;
 
     wrbuf_puts(w, " <services>\n");
     for (; s; s = s->next)
@@ -1175,34 +1200,30 @@ void info_services(struct conf_server *server, WRBUF w)
         wrbuf_puts(w, ">\n");
         if (s->settings)
         {
-            for (i=0; i<s->settings->num_settings; i++)
+            for (i = 0; i < s->settings->num_settings; i++)
             {
-                S = s->settings->settings[i];
-                while (S != NULL) {
-                    wrbuf_puts(w, "   <setting");
-                    wrbuf_puts(w, " name=\"");
+                struct setting *S = s->settings->settings[i];
+                for (; S; S = S->next)
+                {
+                    wrbuf_puts(w, "   <setting name=\"");
                     wrbuf_xmlputs(w,  S->name);
                     wrbuf_puts(w, "\"");
                     wrbuf_puts(w, " value=\"");
                     wrbuf_xmlputs(w, S->value);
                     wrbuf_puts(w, "\"");
-                    if (S->target) {
+                    if (S->target)
+                    {
                         wrbuf_puts(w, " target=\"");
                         wrbuf_xmlputs(w, S->target);
                         wrbuf_puts(w, "\"");
                     }
-
                     wrbuf_puts(w, " />\n");
-
-                    S = S->next;
                 }
             }
         }
         info_service_metadata(s, w);
         info_service_databases(s, w);
-        wrbuf_puts(w, "  </service>");
-
-        wrbuf_puts(w, "\n");
+        wrbuf_puts(w, "  </service>\n");
     }
     wrbuf_puts(w, " </services>\n");
 }
@@ -1232,6 +1253,24 @@ static int parse_config(struct conf_config *config, xmlNode *root)
                 xmlFree(number);
             }
         }
+        else if (!strcmp((const char *) n->name, "sockets"))
+        {
+            xmlChar *number = xmlGetProp(n, (xmlChar *) "max");
+            if (number)
+            {
+                config->max_sockets = atoi((const char *) number);
+                xmlFree(number);
+            }
+        }
+        else if (!strcmp((const char *) n->name, "file"))
+        {
+            xmlChar *path = xmlGetProp(n, (xmlChar *) "path");
+            if (path)
+            {
+                config->path = nmem_strdup(config->nmem, (const char *) path);
+                xmlFree(path);
+            }
+        }
         else if (!strcmp((const char *) n->name, "targetprofiles"))
         {
             yaz_log(YLOG_FATAL, "targetprofiles unsupported here. Must be part of service");
@@ -1247,7 +1286,7 @@ static int parse_config(struct conf_config *config, xmlNode *root)
     return 0;
 }
 
-struct conf_config *config_create(const char *fname, int verbose)
+struct conf_config *config_create(const char *fname)
 {
     xmlDoc *doc = xmlReadFile(fname,
                               NULL,
@@ -1278,7 +1317,9 @@ struct conf_config *config_create(const char *fname, int verbose)
 
     config->nmem = nmem;
     config->servers = 0;
+    config->path = nmem_strdup(nmem, ".");
     config->no_threads = 0;
+    config->max_sockets = 0;
     config->iochan_man = 0;
 
     config->confdir = wrbuf_alloc();
@@ -1299,16 +1340,15 @@ struct conf_config *config_create(const char *fname, int verbose)
     r = yaz_xml_include_simple(n, wrbuf_cstr(config->confdir));
     if (r == 0) /* OK */
     {
-        if (verbose)
-        {
-            yaz_log(YLOG_LOG, "Configuration %s after include processing",
-                    fname);
+#ifndef WIN32
+        yaz_log(YLOG_LOG, "Configuration %s after include processing",
+                fname);
 #if LIBXML_VERSION >= 20600
-            xmlDocFormatDump(yaz_log_file(), doc, 0);
+        xmlDocFormatDump(yaz_log_file(), doc, 0);
 #else
-            xmlDocDump(yaz_log_file(), doc);
+        xmlDocDump(yaz_log_file(), doc);
+#endif
 #endif
-        }
         r = parse_config(config, n);
     }
     xmlFreeDoc(doc);
@@ -1382,7 +1422,7 @@ int config_start_listeners(struct conf_config *conf,
 {
     struct conf_server *ser;
 
-    conf->iochan_man = iochan_man_create(conf->no_threads);
+    conf->iochan_man = iochan_man_create(conf->no_threads, conf->max_sockets);
     for (ser = conf->servers; ser; ser = ser->next)
     {
         WRBUF w;