More example code to handle Extended Services Update.
[yaz-moved-to-github.git] / zoom / zoom-c.c
index c87a035..b36d9b2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoom-c.c,v 1.17 2002-01-03 10:23:46 adam Exp $
+ * $Id: zoom-c.c,v 1.20 2002-01-09 12:44:31 adam Exp $
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
@@ -69,9 +69,21 @@ static ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c)
 
 static void clear_error (ZOOM_connection c)
 {
-    c->error = ZOOM_ERROR_NONE;
-    xfree (c->addinfo);
-    c->addinfo = 0;
+
+    switch (c->error)
+    {
+    case ZOOM_ERROR_CONNECT:
+    case ZOOM_ERROR_MEMORY:
+    case ZOOM_ERROR_DECODE:
+    case ZOOM_ERROR_CONNECTION_LOST:
+    case ZOOM_ERROR_INIT:
+    case ZOOM_ERROR_INTERNAL:
+        break;
+    default:
+        c->error = ZOOM_ERROR_NONE;
+        xfree (c->addinfo);
+        c->addinfo = 0;
+    }
 }
 
 ZOOM_task ZOOM_connection_add_task (ZOOM_connection c, int which)
@@ -245,7 +257,9 @@ void ZOOM_connection_connect(ZOOM_connection c,
     ZOOM_options_set(c->options, "host", c->host_port);
 
     c->async = ZOOM_options_get_bool (c->options, "async", 0);
-    
+    c->error = ZOOM_ERROR_NONE;
+
     task = ZOOM_connection_add_task (c, ZOOM_TASK_CONNECT);
 
     if (!c->async)
@@ -923,8 +937,23 @@ void *ZOOM_record_get (ZOOM_record rec, const char *type, size_t *len)
     {
        if (npr->which == Z_NamePlusRecord_databaseRecord)
        {
-            *len = -1;
-           return (Z_External *) npr->u.databaseRecord;
+           Z_External *r = (Z_External *) npr->u.databaseRecord;
+           
+           if (r->which == Z_External_sutrs)
+           {
+               *len = r->u.sutrs->len;
+               return r->u.sutrs->buf;
+           }
+           else if (r->which == Z_External_octet)
+           {
+               *len = r->u.octet_aligned->len;
+               return r->u.octet_aligned->buf;
+           }
+           else /* grs-1, explain, ... */
+           {
+               *len = -1;
+                return (Z_External *) npr->u.databaseRecord;
+           }
        }
        return 0;
     }
@@ -1092,6 +1121,15 @@ static int scan_response (ZOOM_connection c, Z_ScanResponse *res)
         response_diag(c, res->entries->nonsurrogateDiagnostics[0]);
     scan->scan_response = res;
     nmem_transfer (scan->odr->mem, nmem);
+    if (res->stepSize)
+        ZOOM_options_set_int (scan->options, "stepSize", *res->stepSize);
+    if (res->positionOfTerm)
+        ZOOM_options_set_int (scan->options, "position", *res->positionOfTerm);
+    if (res->scanStatus)
+        ZOOM_options_set_int (scan->options, "scanStatus", *res->scanStatus);
+    if (res->numberOfEntriesReturned)
+        ZOOM_options_set_int (scan->options, "number",
+                              *res->numberOfEntriesReturned);
     nmem_destroy (nmem);
     return 1;
 }
@@ -1350,6 +1388,17 @@ const char *ZOOM_scanset_term (ZOOM_scanset scan, size_t pos,
     return term;
 }
 
+const char *ZOOM_scanset_option_get (ZOOM_scanset scan, const char *key)
+{
+    return ZOOM_options_get (scan->options, key);
+}
+
+void ZOOM_scanset_option_set (ZOOM_scanset scan, const char *key,
+                              const char *val)
+{
+    ZOOM_options_set (scan->options, key, val);
+}
+
 static int ZOOM_connection_exec_task (ZOOM_connection c)
 {
     ZOOM_task task = c->tasks;