Dates
[yaz-moved-to-github.git] / server / seshigh.c
index b9f2e66..4d2ecf0 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.144 2003-02-20 15:15:04 adam Exp $
+ * $Id: seshigh.c,v 1.147 2003-02-23 20:39:31 adam Exp $
  */
 
 /*
@@ -39,6 +39,7 @@
 #include <unistd.h>
 #endif
 #include <assert.h>
+#include <ctype.h>
 
 #include <yaz/yconfig.h>
 #include <yaz/xmalloc.h>
@@ -505,7 +506,10 @@ static int srw_bend_fetch(association *assoc, int pos,
     rr.errcode = 0;
     rr.errstring = 0;
     rr.surrogate_flag = 0;
-    
+
+    if (!assoc->init->bend_fetch)
+        return 1;
+
     (*assoc->init->bend_fetch)(assoc->backend, &rr);
 
     if (rr.len >= 0)
@@ -524,15 +528,27 @@ static void srw_bend_search(association *assoc, request *req,
                             Z_SRW_searchRetrieveRequest *srw_req,
                             Z_SRW_searchRetrieveResponse *srw_res)
 {
-    char *base = "Default";
     int srw_error = 0;
     bend_search_rr rr;
     Z_External *ext;
     
     yaz_log(LOG_LOG, "Got SRW SearchRetrieveRequest");
     if (!assoc->init)
-        srw_bend_init(assoc);
-
+    {
+        if (!srw_bend_init(assoc))
+        {
+            srw_error = 3;  /* assume Authentication error */
+
+            srw_res->num_diagnostics = 1;
+            srw_res->diagnostics = (Z_SRW_diagnostic *)
+                odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
+            srw_res->diagnostics[0].code = 
+                odr_intdup(assoc->encode, srw_error);
+            srw_res->diagnostics[0].details = 0;
+            return;
+        }
+    }
+    
     rr.setname = "default";
     rr.replace_set = 1;
     rr.num_bases = 1;
@@ -541,7 +557,7 @@ static void srw_bend_search(association *assoc, request *req,
 
     rr.query = (Z_Query *) odr_malloc (assoc->decode, sizeof(*rr.query));
 
-    if (srw_req->query)
+    if (srw_req->query_type == Z_SRW_query_type_cql)
     {
         ext = (Z_External *) odr_malloc(assoc->decode, sizeof(*ext));
         ext->direct_reference = odr_getoidbystr(assoc->decode, 
@@ -549,21 +565,20 @@ static void srw_bend_search(association *assoc, request *req,
         ext->indirect_reference = 0;
         ext->descriptor = 0;
         ext->which = Z_External_CQL;
-        ext->u.cql = srw_req->query;
+        ext->u.cql = srw_req->query.cql;
 
         rr.query->which = Z_Query_type_104;
         rr.query->u.type_104 =  ext;
     }
-    else if (srw_req->pQuery)
+    else if (srw_req->query_type == Z_SRW_query_type_pqf)
     {
         Z_RPNQuery *RPNquery;
         YAZ_PQF_Parser pqf_parser;
 
         pqf_parser = yaz_pqf_create ();
 
-        yaz_log(LOG_LOG, "PQF: %s", srw_req->pQuery);
-
-        RPNquery = yaz_pqf_parse (pqf_parser, assoc->decode, srw_req->pQuery);
+        RPNquery = yaz_pqf_parse (pqf_parser, assoc->decode,
+                                  srw_req->query.pqf);
         if (!RPNquery)
         {
             const char *pqf_msg;
@@ -583,9 +598,12 @@ static void srw_bend_search(association *assoc, request *req,
     else
         srw_error = 11;
 
-    if (srw_req->sortKeys || srw_req->xSortKeys)
+    if (!srw_error && srw_req->sort_type != Z_SRW_sort_type_none)
         srw_error = 80;
 
+    if (!srw_error && !assoc->init->bend_search)
+        srw_error = 1;
+
     if (srw_error)
     {
         srw_res->num_diagnostics = 1;
@@ -596,7 +614,6 @@ static void srw_bend_search(association *assoc, request *req,
         srw_res->diagnostics[0].details = 0;
         return;
     }
-
     
     rr.stream = assoc->encode;
     rr.decode = assoc->decode;
@@ -644,7 +661,7 @@ static void srw_bend_search(association *assoc, request *req,
                     int errcode;
                     srw_res->records[j].recordData_buf = 0;
                     errcode = srw_bend_fetch(assoc, i+start, srw_req,
-                                              srw_res->records + j);
+                                             srw_res->records + j);
                     if (errcode)
                     {
                         srw_res->num_diagnostics = 1;
@@ -791,11 +808,11 @@ static void process_http_request(association *assoc, request *req)
                 soap_package->u.generic->no == 0)
             {
                 /* SRW package */
-                Z_SRW_searchRetrieve *sr = soap_package->u.generic->p;
+                Z_SRW_PDU *sr = soap_package->u.generic->p;
                 
                 if (sr->which == Z_SRW_searchRetrieve_request)
                 {
-                    Z_SRW_searchRetrieve *res =
+                    Z_SRW_PDU *res =
                         yaz_srw_get(assoc->encode,
                                     Z_SRW_searchRetrieve_response);
 
@@ -875,7 +892,7 @@ static void process_http_request(association *assoc, request *req)
         if (alive && isdigit(*alive))
             t = atoi(alive);
         else
-            t = 30;
+            t = 15;
         if (t < 0 || t > 3600)
             t = 3600;
         iochan_settimeout(assoc->client_chan,t);