Added support for file access in GFS to facilitate static
[yaz-moved-to-github.git] / src / statserv.c
index 95643f4..c3d2e8b 100644 (file)
@@ -5,7 +5,7 @@
  * NT threaded server code by
  *   Chas Woodfield, Fretwell Downing Informatics.
  *
- * $Id: statserv.c,v 1.32 2005-08-22 20:34:21 adam Exp $
+ * $Id: statserv.c,v 1.34 2006-03-15 13:32:05 adam Exp $
  */
 
 /**
@@ -219,6 +219,8 @@ static struct gfs_server * gfs_server_new()
     n->cql_transform = 0;
     n->server_node_ptr = 0;
     n->directory = 0;
+    n->docpath = 0;
+    n->stylesheet = 0;
     return n;
 }
 
@@ -262,6 +264,10 @@ 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;
     if (control_block.xml_config[0])
     {
         struct gfs_server *gfs;
@@ -289,6 +295,8 @@ 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->last_control = &gfs->cb;
@@ -300,8 +308,6 @@ int control_association(association *assoc, const char *host, int force_open)
         }
         statserv_setcontrol(0);
         assoc->last_control = 0;
-        assoc->cql_transform = 0;
-        assoc->server_node_ptr = 0;
         yaz_log(YLOG_DEBUG, "server select: no match");
         return 0;
     }
@@ -309,8 +315,6 @@ int control_association(association *assoc, const char *host, int force_open)
     {
         statserv_setcontrol(&control_block);
         assoc->last_control = &control_block;
-        assoc->cql_transform = 0;
-        assoc->server_node_ptr = 0;
         yaz_log(YLOG_DEBUG, "server select: config=%s", control_block.configname);
         return 1;
     }
@@ -409,6 +413,28 @@ static void xml_config_read()
                     (*gfsp)->directory = 
                         nmem_dup_xml_content(gfs_nmem, ptr->children);
                 }
+                else if (!strcmp((const char *) ptr->name, "docpath"))
+                {
+                    (*gfsp)->docpath = 
+                        nmem_dup_xml_content(gfs_nmem, ptr->children);
+                }
+                else if (!strcmp((const char *) ptr->name, "stylesheet"))
+                {
+                    char *s = nmem_dup_xml_content(gfs_nmem, ptr->children);
+                    (*gfsp)->stylesheet = 
+                        nmem_malloc(gfs_nmem, strlen(s) + 2);
+                    sprintf((*gfsp)->stylesheet, "/%s", s);
+                }
+                else if (!strcmp((const char *) ptr->name, "explain"))
+                {
+                    ; /* being processed separately */
+                }
+                else
+                {
+                    yaz_log(YLOG_FATAL, "Unknown element '%s' in config %s",
+                            ptr->name, control_block.xml_config);
+                    exit(1);
+                }
             }
             gfsp = &(*gfsp)->next;
         }
@@ -1299,7 +1325,7 @@ int check_options(int argc, char **argv)
     yaz_log_init_level(control_block.loglevel);
 
     get_logbits(1); 
-    while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:",
+    while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:",
                           argv, argc, &arg)) != -2)
     {
         switch (ret)
@@ -1338,6 +1364,13 @@ int check_options(int argc, char **argv)
             option_copy(control_block.logfile, arg);
             yaz_log_init(control_block.loglevel, me, control_block.logfile);
             break;
+        case 'm':
+            if (!arg) {
+                fprintf(stderr, "%s: Specify time format for log file.\n", me);
+                return(1);
+            }
+            yaz_log_time_format(arg);
+            break;
         case 'v':
             control_block.loglevel =
                 yaz_log_mask_str_x(arg,control_block.loglevel);
@@ -1406,7 +1439,7 @@ int check_options(int argc, char **argv)
             fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
                     " -l <logfile> -u <user> -c <config> -t <minutes>"
                     " -k <kilobytes> -d <daemon> -p <pidfile> -C certfile"
-                        " -ziDST1 -w <directory> <listener-addr>... ]\n", me);
+                        " -ziDST1 -m <time-format> -w <directory> <listener-addr>... ]\n", me);
             return 1;
         }
     }