From: Adam Dickmeiss Date: Wed, 21 Nov 2012 14:49:55 +0000 (+0100) Subject: ZOOM: special options to control APDU logging X-Git-Tag: v4.2.47~5 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=411c62d6ff8ded6e1ef68eebea9d9bbaaac360fd;p=yaz-moved-to-github.git ZOOM: special options to control APDU logging Using ZOOM_connection_option_set(c, "saveAPDU", "1") will enable logging of APDUs until "saveAPDU" option is set again. If logging is already enabled the effect is that current APDU buffer is cleared. Using ZOOM_connection_option_set(c, "saveAPDU", "0") disables logging (default behavior on new connection). The APDUs sent/received can be obtained by using Using ZOOM_connection_option_get(c, "APDU") or ZOOM_connection_option_getl(c, "APDU", &l). --- diff --git a/src/zoom-c.c b/src/zoom-c.c index 2b6b80f..ddf4ee9 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -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); } @@ -1794,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) diff --git a/src/zoom-p.h b/src/zoom-p.h index 9113242..4a2e155 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -113,6 +113,7 @@ struct ZOOM_connection_p { int log_details; int log_api; + WRBUF saveAPDU_wrbuf; }; #if ZOOM_RESULT_LISTS diff --git a/zoom/zoomtst1.c b/zoom/zoomtst1.c index 8369f63..791910f 100644 --- a/zoom/zoomtst1.c +++ b/zoom/zoomtst1.c @@ -29,11 +29,14 @@ int main(int argc, char **argv) exit (2); } + ZOOM_connection_option_set(z, "saveAPDU", "1"); r = ZOOM_connection_search_pqf (z, argv[2]); if ((error = ZOOM_connection_error(z, &errmsg, &addinfo))) fprintf (stderr, "Error: %s (%d) %s\n", errmsg, error, addinfo); else printf ("Result count: %ld\n", (long) ZOOM_resultset_size(r)); + puts("APDUlog"); + puts(ZOOM_connection_option_get(z, "APDU")); ZOOM_resultset_destroy (r); ZOOM_connection_destroy (z); exit (0);