Fixed args passing with blanks for Windows Service
[yaz-moved-to-github.git] / src / seshigh.c
index b2dcd41..8c0c3fa 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2008 Index Data
+ * Copyright (C) 1995-2009 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -398,6 +398,7 @@ void ir_session(IOCHAN h, int event)
             yaz_log(YLOG_WARN, "accept failed");
             destroy_association(assoc);
             iochan_destroy(h);
+            return;
         }
         iochan_clearflag(h, EVENT_OUTPUT);
         if (conn->io_pending) 
@@ -508,6 +509,7 @@ static void assoc_init_reset(association *assoc)
     assoc->init->bend_explain = NULL;
     assoc->init->bend_srw_scan = NULL;
     assoc->init->bend_srw_update = NULL;
+    assoc->init->named_result_sets = 0;
 
     assoc->init->charneg_request = NULL;
     assoc->init->charneg_response = NULL;
@@ -663,7 +665,6 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr)
         rr->output_format = match_syntax;
     if (match_schema)
         rr->schema = odr_strdup(rr->stream, match_schema);
-    return 0;
 #else
     (*assoc->init->bend_fetch)(assoc->backend, rr);
 #endif
@@ -1121,9 +1122,7 @@ static void srw_bend_search(association *assoc, request *req,
             querystr = srw_req->query.pqf;
             break;
         }
-        wrbuf_printf(wr, "SRWSearch ");
-        wrbuf_printf(wr, srw_req->database);
-        wrbuf_printf(wr, " ");
+        wrbuf_printf(wr, "SRWSearch %s ", srw_req->database);
         if (srw_res->num_diagnostics)
             wrbuf_printf(wr, "ERROR %s", srw_res->diagnostics[0].uri);
         else if (*http_code != 200)
@@ -1393,9 +1392,7 @@ static void srw_bend_scan(association *assoc, request *req,
             querystr = "";
         }
 
-        wrbuf_printf(wr, "SRWScan ");
-        wrbuf_printf(wr, srw_req->database);
-        wrbuf_printf(wr, " ");
+        wrbuf_printf(wr, "SRWScan %s ", srw_req->database);
 
         if (srw_res->num_diagnostics)
             wrbuf_printf(wr, "ERROR %s - ", srw_res->diagnostics[0].uri);
@@ -1660,7 +1657,7 @@ static int check_path(const char *path)
     return 1;
 }
 
-static char *read_file(const char *fname, ODR o, int *sz)
+static char *read_file(const char *fname, ODR o, size_t *sz)
 {
     char *buf;
     FILE *inf = fopen(fname, "rb");
@@ -1671,7 +1668,8 @@ static char *read_file(const char *fname, ODR o, int *sz)
     *sz = ftell(inf);
     rewind(inf);
     buf = (char *) odr_malloc(o, *sz);
-    fread(buf, 1, *sz, inf);
+    if (fread(buf, 1, *sz, inf) != *sz)
+        yaz_log(YLOG_WARN|YLOG_ERRNO, "short read %s", fname);
     fclose(inf);
     return buf;     
 }
@@ -1712,7 +1710,7 @@ static void process_http_request(association *assoc, request *req)
         }
         else
         {
-            int content_size = 0;
+            size_t content_size = 0;
             char *content_buf = read_file(hreq->path+1, o, &content_size);
             if (!content_buf)
             {
@@ -2166,7 +2164,6 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
     Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_initResponse);
     Z_InitResponse *resp = apdu->u.initResponse;
     bend_initresult *binitres;
-    char *version;
     char options[140];
     statserv_options_block *cb = 0;  /* by default no control for backend */
 
@@ -2201,6 +2198,10 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
             assoc->init->charneg_request = negotiation;
     }
 
+    /* by default named_result_sets is 0 .. Enable it if client asks for it. */
+    if (ODR_MASK_GET(req->options, Z_Options_namedResultSets))
+        assoc->init->named_result_sets = 1;
+
     assoc->backend = 0;
     if (cb)
     {
@@ -2267,7 +2268,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
         ODR_MASK_SET(resp->options, Z_Options_extendedServices);
         strcat(options, " extendedServices");
     }
-    if (ODR_MASK_GET(req->options, Z_Options_namedResultSets))
+    if (ODR_MASK_GET(req->options, Z_Options_namedResultSets)
+        && assoc->init->named_result_sets)
     {
         ODR_MASK_SET(resp->options, Z_Options_namedResultSets);
         strcat(options, " namedresults");
@@ -2353,14 +2355,6 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
                 assoc->init->implementation_name,
                 odr_prepend(assoc->encode, "GFS", resp->implementationName));
 
-    version = odr_strdup(assoc->encode, "$Revision: 1.128 $");
-    if (strlen(version) > 10)   /* check for unexpanded CVS strings */
-        version[strlen(version)-2] = '\0';
-    resp->implementationVersion = odr_prepend(assoc->encode,
-                assoc->init->implementation_version,
-                odr_prepend(assoc->encode, &version[11],
-                            resp->implementationVersion));
-
     if (binitres->errcode)
     {
         assoc->state = ASSOC_DEAD;
@@ -2836,7 +2830,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb,
         for (i = 0 ; i < req->num_databaseNames; i++){
             if (i)
                 wrbuf_printf(wr, "+");
-            wrbuf_printf(wr, req->databaseNames[i]);
+            wrbuf_puts(wr, req->databaseNames[i]);
         }
         wrbuf_printf(wr, " ");
         
@@ -3135,7 +3129,7 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
         {
             if (i)
                 wrbuf_printf(wr, "+");
-            wrbuf_printf(wr, req->databaseNames[i]);
+            wrbuf_puts(wr, req->databaseNames[i]);
         }
 
         wrbuf_printf(wr, " ");
@@ -3232,7 +3226,7 @@ static Z_APDU *process_sortRequest(association *assoc, request *reqb,
         {
             if (i)
                 wrbuf_printf(wr, "+");
-            wrbuf_printf(wr, req->inputResultSetNames[i]);
+            wrbuf_puts(wr, req->inputResultSetNames[i]);
         }
         wrbuf_printf(wr, ")->%s ",req->sortedResultSetName);
 
@@ -3535,6 +3529,7 @@ int bend_assoc_is_alive(bend_association assoc)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab