For Libxml2 and friends, YAZ defines YAZ_HAVE_{XML2,XSLT,EXSLT) in
[yaz-moved-to-github.git] / src / statserv.c
index c3d2e8b..ccd0007 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
  * NT threaded server code by
  *   Chas Woodfield, Fretwell Downing Informatics.
  *
- * $Id: statserv.c,v 1.34 2006-03-15 13:32:05 adam Exp $
+ * $Id: statserv.c,v 1.39 2006-07-06 10:17:54 adam Exp $
  */
 
 /**
@@ -14,6 +14,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #ifdef WIN32
@@ -35,7 +36,7 @@
 #include <pwd.h>
 #endif
 
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xinclude.h>
@@ -92,7 +93,7 @@ statserv_options_block control_block = {
     1,                          /* dynamic mode */
     0,                          /* threaded mode */
     0,                          /* one shot (single session) */
-    YLOG_DEFAULT_LEVEL,          /* log level */
+    0, /* __UNUSED_loglevel */
     "",                         /* no PDUs */
     "",                         /* diagnostic output to stderr */
     "tcp:@:9999",               /* default listener port */
@@ -143,11 +144,11 @@ static void get_logbits(int force)
 
 static int add_listener(char *where, int listen_id);
 
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
 static xmlDocPtr xml_config_doc = 0;
 #endif
 
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
 static xmlNodePtr xml_config_get_root()
 {
     xmlNodePtr ptr = 0;
@@ -167,7 +168,7 @@ static xmlNodePtr xml_config_get_root()
 }
 #endif
 
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
 static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr)
 {
     unsigned char *cp;
@@ -221,6 +222,9 @@ static struct gfs_server * gfs_server_new()
     n->directory = 0;
     n->docpath = 0;
     n->stylesheet = 0;
+#if YAZ_HAVE_XML2
+    n->retrieval = yaz_retrieval_create();
+#endif
     return n;
 }
 
@@ -264,10 +268,7 @@ int control_association(association *assoc, const char *host, int force_open)
             *cp = '\0';
         host = vhost;
     }
-    assoc->cql_transform = 0;
-    assoc->server_node_ptr = 0;
-    assoc->docpath = 0;
-    assoc->stylesheet = 0;
+    assoc->server = 0;
     if (control_block.xml_config[0])
     {
         struct gfs_server *gfs;
@@ -295,10 +296,7 @@ int control_association(association *assoc, const char *host, int force_open)
                     xfree(assoc->init);
                     assoc->init = 0;
                 }
-                assoc->docpath = gfs->docpath;
-                assoc->stylesheet = gfs->stylesheet;
-                assoc->cql_transform = gfs->cql_transform;
-                assoc->server_node_ptr = gfs->server_node_ptr;
+                assoc->server = gfs;
                 assoc->last_control = &gfs->cb;
                 statserv_setcontrol(&gfs->cb);
                 gfs_server_chdir(gfs);
@@ -324,7 +322,7 @@ static void xml_config_read()
 {
     struct gfs_server **gfsp = &gfs_server_list;
     struct gfs_listen **gfslp = &gfs_listen_list;
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
     xmlNodePtr ptr = xml_config_get_root();
 
     if (!ptr)
@@ -429,6 +427,16 @@ static void xml_config_read()
                 {
                     ; /* being processed separately */
                 }
+                else if (!strcmp((const char *) ptr->name, "retrievalinfo"))
+                {
+                    if (yaz_retrieval_configure((*gfsp)->retrieval, ptr))
+                    {       
+                        yaz_log(YLOG_FATAL, "%s in config %s",
+                                yaz_retrieval_get_error((*gfsp)->retrieval),
+                                control_block.xml_config);
+                        exit(1);
+                    }
+                }
                 else
                 {
                     yaz_log(YLOG_FATAL, "Unknown element '%s' in config %s",
@@ -459,7 +467,7 @@ static void xml_config_open()
 #endif
     
     gfs_nmem = nmem_create();
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
     if (control_block.xml_config[0] == '\0')
         return;
 
@@ -488,7 +496,7 @@ static void xml_config_open()
 
 static void xml_config_close()
 {
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
     if (xml_config_doc)
     {
         xmlFreeDoc(xml_config_doc);
@@ -911,7 +919,7 @@ static void listener(IOCHAN h, int event)
                     iochan_destroy(pp);
                 }
                 sprintf(nbuf, "%s(%d)", me, no_sessions);
-                yaz_log_init(control_block.loglevel, nbuf, 0);
+                yaz_log_init_prefix(nbuf);
                 /* ensure that bend_stop is not called when each child exits -
                    only for the main process ..  */
                 control_block.bend_stop = 0;
@@ -1320,9 +1328,16 @@ int check_options(int argc, char **argv)
     int ret = 0, r;
     char *arg;
 
-    /* set default log level */
-    control_block.loglevel = yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL);
-    yaz_log_init_level(control_block.loglevel);
+    if (getenv("YAZ_LOG") == 0) {
+        /*
+         * Set default log level.  We want to avoid doing this if the
+         * user has already explicitly specified a preferred default
+         * log-level, hence the inelegant peek at the YAZ_LOG
+         * environment variable that will subsequently be interpreted
+         * by the YAZ logging module itself.
+         */
+        yaz_log_init_level(yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL));
+    }
 
     get_logbits(1); 
     while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:",
@@ -1362,7 +1377,7 @@ int check_options(int argc, char **argv)
             break;
         case 'l':
             option_copy(control_block.logfile, arg);
-            yaz_log_init(control_block.loglevel, me, control_block.logfile);
+            yaz_log_init_file(control_block.logfile);
             break;
         case 'm':
             if (!arg) {
@@ -1371,12 +1386,12 @@ int check_options(int argc, char **argv)
             }
             yaz_log_time_format(arg);
             break;
-        case 'v':
-            control_block.loglevel =
-                yaz_log_mask_str_x(arg,control_block.loglevel);
-            yaz_log_init(control_block.loglevel, me, control_block.logfile);
+        case 'v': {
+            int default_level = yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL);
+            yaz_log_init_level(yaz_log_mask_str_x(arg, default_level));
             get_logbits(1); 
             break;
+        }
         case 'a':
             option_copy(control_block.apdufile, arg);
             break;
@@ -1425,7 +1440,7 @@ int check_options(int argc, char **argv)
             option_copy(control_block.pid_fname, arg);
             break;
         case 'f':
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
             option_copy(control_block.xml_config, arg);
 #else
             fprintf(stderr, "%s: Option -f unsupported since YAZ is compiled without Libxml2 support\n", me);