Embedded XSLT stylesheets for service
[pazpar2-moved-to-github.git] / src / pazpar2_config.c
index 0f5ab1a..dd1c570 100644 (file)
@@ -41,6 +41,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "ppmutex.h"
 #include "incref.h"
 #include "pazpar2_config.h"
+#include "service_xslt.h"
 #include "settings.h"
 #include "eventl.h"
 #include "http.h"
@@ -56,6 +57,13 @@ struct conf_config
     database_hosts_t database_hosts;
 };
 
+struct service_xslt
+{
+    char *id;
+    xsltStylesheetPtr xsp;
+    struct service_xslt *next;
+};
+    
 static void conf_metadata_assign(NMEM nmem, 
                                  struct conf_metadata * metadata,
                                  const char *name,
@@ -115,6 +123,7 @@ static struct conf_service *service_init(struct conf_server *server,
     service->nmem = nmem;
     service->next = 0;
     service->databases = 0;
+    service->xslt_list = 0;
     service->server = server;
     service->session_timeout = 60; /* default session timeout */
     service->z3950_session_timeout = 180;
@@ -230,6 +239,7 @@ void service_destroy(struct conf_service *service)
     {
         if (!pazpar2_decref(&service->ref_count, service->mutex))
         {
+            service_xslt_destroy(service);
             pp2_charset_fact_destroy(service->charsets);
             yaz_mutex_destroy(&service->mutex);
             nmem_destroy(service->nmem);
@@ -542,6 +552,11 @@ static struct conf_service *service_create_static(struct conf_server *server,
             if (parse_metadata(service, n, &md_node, &sk_node))
                 return 0;
         }
+        else if (!strcmp((const char *) n->name, (const char *) "xslt"))
+        {
+            if (service_xslt_config(service, n))
+                return 0;
+        }
         else
         {
             yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
@@ -625,7 +640,6 @@ struct conf_service *service_create(struct conf_server *server,
     if (service)
     {
         inherit_server_settings(service);
-        resolve_databases(service);
         assert(service->mutex == 0);
         pazpar2_mutex_create(&service->mutex, "conf");
     }
@@ -650,7 +664,7 @@ static struct conf_server *server_create(struct conf_config *config,
     server->charsets = 0;
     server->http_server = 0;
     server->iochan_man = 0;
-    server->database_hosts = 0;
+    server->database_hosts = config->database_hosts;
     server->settings_fname = 0;
 
     if (server_id)
@@ -888,7 +902,7 @@ struct conf_config *config_create(const char *fname, int verbose)
     config->servers = 0;
     config->no_threads = 0;
     config->iochan_man = 0;
-    config->database_hosts = 0;
+    config->database_hosts = database_hosts_create();
 
     config->confdir = wrbuf_alloc();
     if ((p = strrchr(fname, 
@@ -955,9 +969,8 @@ void config_destroy(struct conf_config *config)
             struct conf_server *s_next = server->next;
             server_destroy(server);
             server = s_next;
+            database_hosts_destroy(&config->database_hosts);
         }
-        database_hosts_destroy(&config->database_hosts);
-
         wrbuf_destroy(config->confdir);
         nmem_destroy(config->nmem);
     }
@@ -974,22 +987,18 @@ void config_process_events(struct conf_config *conf)
 {
     struct conf_server *ser;
     
-    conf->database_hosts = database_hosts_create();
     for (ser = conf->servers; ser; ser = ser->next)
     {
         struct conf_service *s = ser->service;
 
-        ser->database_hosts = conf->database_hosts;
-
         for (;s ; s = s->next)
         {
-            resolve_databases(s);
             assert(s->mutex == 0);
             pazpar2_mutex_create(&s->mutex, "service");
         }
         http_mutex_init(ser);
     }
-    iochan_man_events(conf->iochan_man);    
+    iochan_man_events(conf->iochan_man);
 }
 
 int config_start_listeners(struct conf_config *conf,