Changed the SRU update structures and codecs to reflect the SRU pre 1.0
[yaz-moved-to-github.git] / ztest / ztest.c
index a6b71d2..77a600d 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: ztest.c,v 1.75 2005-06-25 15:46:09 adam Exp $
+ * $Id: ztest.c,v 1.83 2006-12-06 21:35:59 adam Exp $
  */
 
 /*
@@ -12,6 +12,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 #include <yaz/yaz-util.h>
 #include <yaz/backend.h>
@@ -45,8 +48,27 @@ int ztest_search(void *handle, bend_search_rr *rr)
         exit(0);
     }
 #endif
-    /* Throw Database unavailable if other than Default */
-    if (yaz_matchstr (rr->basenames[0], "Default"))
+    /* Throw Database unavailable if other than Default or Slow */
+    if (!yaz_matchstr (rr->basenames[0], "Default"))
+        ;  /* Default is OK in our test */
+    else if(!yaz_matchstr (rr->basenames[0], "Slow"))
+    {
+#if HAVE_UNISTD_H
+        /* wait up to 3 seconds and check if connection is still alive */
+        int i;
+        for (i = 0; i<3; i++)
+        {
+            if (!bend_assoc_is_alive(rr->association))
+            {
+                yaz_log(YLOG_LOG, "search aborted");
+                break;
+            }
+            sleep(1);
+        }
+#endif
+        ;
+    }
+    else
     {
         rr->errcode = 109;
         rr->errstring = rr->basenames[0];
@@ -137,9 +159,9 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
                             if (!ill_ItemRequest (rr->decode, &item_req, 0, 0))
                             {
                                 yaz_log (log_level,
-                                    "Couldn't decode ItemRequest %s near %d",
+                                    "Couldn't decode ItemRequest %s near %ld",
                                        odr_errmsg(odr_geterror(rr->decode)),
-                                       odr_offset(rr->decode));
+                                       (long) odr_offset(rr->decode));
                             }
                             else
                                 yaz_log(log_level, "Decode ItemRequest OK");
@@ -160,9 +182,9 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
                             if (!ill_APDU (rr->decode, &ill_apdu, 0, 0))
                             {
                                 yaz_log (log_level,
-                                    "Couldn't decode ILL APDU %s near %d",
+                                    "Couldn't decode ILL APDU %s near %ld",
                                        odr_errmsg(odr_geterror(rr->decode)),
-                                       odr_offset(rr->decode));
+                                       (long) odr_offset(rr->decode));
                                 yaz_log(log_level, "PDU dump:");
                                 odr_dumpBER(yaz_log_file(),
                                      (char *) r->u.single_ASN1_type->buf,
@@ -398,16 +420,6 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
             }
         }
     }
-    else if (rr->esr->taskSpecificParameters->which == Z_External_update0)
-    {
-        yaz_log(log_level, "Received DB Update (version 0)");
-    }
-    else
-    {
-        yaz_log (YLOG_WARN, "Unknown Extended Service(%d)",
-                 rr->esr->taskSpecificParameters->which);
-        
-    }
     return 0;
 }
 
@@ -536,7 +548,17 @@ int ztest_scan(void *handle, bend_scan_rr *q)
     int term_position_req = q->term_position;
     int num_entries_req = q->num_entries;
 
-    if (yaz_matchstr (q->basenames[0], "Default"))
+    /* Throw Database unavailable if other than Default or Slow */
+    if (!yaz_matchstr (q->basenames[0], "Default"))
+        ;  /* Default is OK in our test */
+    else if(!yaz_matchstr (q->basenames[0], "Slow"))
+    {
+#if HAVE_UNISTD_H
+        sleep(3);
+#endif
+        ;
+    }
+    else
     {
         q->errcode = 109;
         q->errstring = q->basenames[0];
@@ -637,7 +659,7 @@ int ztest_scan(void *handle, bend_scan_rr *q)
     return 0;
 }
 
-static int ztest_explain(void *handle, bend_explain_rr *rr)
+int ztest_explain(void *handle, bend_explain_rr *rr)
 {
     if (rr->database && !strcmp(rr->database, "Default"))
     {
@@ -651,6 +673,12 @@ static int ztest_explain(void *handle, bend_explain_rr *rr)
     return 0;
 }
 
+int ztest_update(void *handle, bend_update_rr *rr)
+{
+    rr->operation_status = "success";
+    return 0;
+}
+
 bend_initresult *bend_init(bend_initrequest *q)
 {
     bend_initresult *r = (bend_initresult *)
@@ -678,6 +706,7 @@ bend_initresult *bend_init(bend_initrequest *q)
     q->bend_explain = ztest_explain;
 #endif
     q->bend_srw_scan = ztest_scan;
+    q->bend_srw_update = ztest_update;
 
     return r;
 }