GFS: scan handler gets extra_args from request
[yaz-moved-to-github.git] / src / zoom-c.c
index 2445215..7ac0304 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -303,6 +303,7 @@ ZOOM_API(ZOOM_connection)
 
     c->sru_version = 0;
     c->no_redirects = 0;
+    c->saveAPDU_wrbuf = 0;
     return c;
 }
 
@@ -628,6 +629,7 @@ ZOOM_API(void)
     xfree(c->group);
     xfree(c->password);
     xfree(c->sru_version);
+    wrbuf_destroy(c->saveAPDU_wrbuf);
     xfree(c);
 }
 
@@ -1549,15 +1551,26 @@ static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri,
         z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,
                                      c->user, c->password);
     }
-    if (!z_GDU(c->odr_out, &gdu, 0, 0))
+    return ZOOM_send_GDU(c, gdu);
+}
+
+zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
+{
+    ZOOM_Event event;
+
+    int r = z_GDU(c->odr_out, &gdu, 0, 0);
+    if (!r)
         return zoom_complete;
     if (c->odr_print)
         z_GDU(c->odr_print, &gdu, 0, 0);
     if (c->odr_save)
         z_GDU(c->odr_save, &gdu, 0, 0);
     c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
-
     odr_reset(c->odr_out);
+
+    event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU);
+    ZOOM_connection_put_event(c, event);
+
     return ZOOM_send_buf(c);
 }
 
@@ -1783,20 +1796,56 @@ zoom_ret ZOOM_send_buf(ZOOM_connection c)
 ZOOM_API(const char *)
     ZOOM_connection_option_get(ZOOM_connection c, const char *key)
 {
-    return ZOOM_options_get(c->options, key);
+    if (!strcmp(key, "APDU"))
+    {
+        return c->saveAPDU_wrbuf ? wrbuf_cstr(c->saveAPDU_wrbuf) : "";
+    }
+    else
+        return ZOOM_options_get(c->options, key);
 }
 
 ZOOM_API(const char *)
     ZOOM_connection_option_getl(ZOOM_connection c, const char *key, int *lenp)
 {
-    return ZOOM_options_getl(c->options, key, lenp);
+    if (!strcmp(key, "APDU"))
+    {
+        if (c->saveAPDU_wrbuf)
+        {
+            *lenp = wrbuf_len(c->saveAPDU_wrbuf);
+            return wrbuf_cstr(c->saveAPDU_wrbuf);
+        }
+        else
+        {
+            *lenp = 0;
+            return "";
+        }
+    }
+    else
+        return ZOOM_options_getl(c->options, key, lenp);
 }
 
 ZOOM_API(void)
     ZOOM_connection_option_set(ZOOM_connection c, const char *key,
                                const char *val)
 {
-    ZOOM_options_set(c->options, key, val);
+    if (!strcmp(key, "saveAPDU"))
+    {
+        if (val && strcmp(val, "0"))
+        {
+            if (!c->saveAPDU_wrbuf)
+                c->saveAPDU_wrbuf = wrbuf_alloc();
+            else
+                wrbuf_rewind(c->saveAPDU_wrbuf);
+        }
+        else
+        {
+            wrbuf_destroy(c->saveAPDU_wrbuf);
+            c->saveAPDU_wrbuf = 0;
+        }
+        ZOOM_connection_save_apdu_wrbuf(c, c->saveAPDU_wrbuf);
+    }
+    else
+        ZOOM_options_set(c->options, key, val);
 }
 
 ZOOM_API(void)