From 0b0eb588d2989d5bc7d77600e4e9b375d1eade12 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 5 Dec 2011 11:28:08 +0100 Subject: [PATCH] Add ZOOM_connection_save_apdu_wrbuf This function may be used to save APDUs for a connection to a WRBUF. --- include/yaz/zoom.h | 9 +++++++++ src/odr.c | 1 + src/zoom-c.c | 26 ++++++++++++++++++++++++++ src/zoom-p.h | 2 ++ src/zoom-sru.c | 2 ++ src/zoom-z3950.c | 2 ++ 6 files changed, 42 insertions(+) diff --git a/include/yaz/zoom.h b/include/yaz/zoom.h index 63ebc14..c9c9e09 100644 --- a/include/yaz/zoom.h +++ b/include/yaz/zoom.h @@ -562,6 +562,15 @@ ZOOM_connection_peek_event(ZOOM_connection c); ZOOM_API(const char *) ZOOM_get_event_str(int event); +#ifdef WRBUF_H + +/** \brief log APDUs to WRBUF + \param c connection + \param w WRBUF where APDUs are logged +*/ +ZOOM_API(void) ZOOM_connection_save_apdu_wrbuf(ZOOM_connection c, WRBUF w); +#endif + ZOOM_END_CDECL /* diff --git a/src/odr.c b/src/odr.c index 7013ad7..3ad263d 100644 --- a/src/odr.c +++ b/src/odr.c @@ -175,6 +175,7 @@ void odr_setprint(ODR o, FILE *file) odr_set_stream(o, file, odr_FILE_write, odr_FILE_close); } + void odr_set_stream(ODR o, void *handle, void (*stream_write)(ODR o, void *handle, int type, diff --git a/src/zoom-c.c b/src/zoom-c.c index 3615ed9..92154a7 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -236,6 +236,12 @@ void ZOOM_connection_remove_tasks(ZOOM_connection c) ZOOM_connection_remove_task(c); } +static void odr_wrbuf_write(ODR o, void *handle, int type, + const char *buf, int len) +{ + WRBUF w = (WRBUF) handle; + wrbuf_write(w, buf, len); +} ZOOM_API(ZOOM_connection) ZOOM_connection_create(ZOOM_options options) @@ -286,6 +292,7 @@ ZOOM_API(ZOOM_connection) c->odr_in = odr_createmem(ODR_DECODE); c->odr_out = odr_createmem(ODR_ENCODE); c->odr_print = 0; + c->odr_save = 0; c->async = 0; c->support_named_resultsets = 0; @@ -299,6 +306,19 @@ ZOOM_API(ZOOM_connection) return c; } +ZOOM_API(void) ZOOM_connection_save_apdu_wrbuf(ZOOM_connection c, WRBUF w) +{ + if (c->odr_save) + { + odr_destroy(c->odr_save); + c->odr_save = 0; + } + if (w) + { + c->odr_save = odr_createmem(ODR_PRINT); + odr_set_stream(c->odr_save, w, odr_wrbuf_write, 0); + } +} /* set database names. Take local databases (if set); otherwise take databases given in ZURL (if set); otherwise use Default */ @@ -592,6 +612,8 @@ ZOOM_API(void) xfree(c->diagset); odr_destroy(c->odr_in); odr_destroy(c->odr_out); + if (c->odr_save) + odr_destroy(c->odr_save); if (c->odr_print) { odr_setprint(c->odr_print, 0); /* prevent destroy from fclose'ing */ @@ -1528,6 +1550,8 @@ static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri, 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); @@ -1686,6 +1710,8 @@ static int do_read(ZOOM_connection c) { if (c->odr_print) z_GDU(c->odr_print, &gdu, 0, 0); + if (c->odr_save) + z_GDU(c->odr_save, &gdu, 0, 0); if (gdu->which == Z_GDU_Z3950) ZOOM_handle_Z3950_apdu(c, gdu->u.z3950); else if (gdu->which == Z_GDU_HTTP_Response) diff --git a/src/zoom-p.h b/src/zoom-p.h index e8c58b5..b150422 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -73,6 +73,8 @@ struct ZOOM_connection_p { ODR odr_in; ODR odr_out; ODR odr_print; + ODR odr_save; + char *buf_in; int len_in; char *buf_out; diff --git a/src/zoom-sru.c b/src/zoom-sru.c index da588f0..d47cf26 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -61,6 +61,8 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr) 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); event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU); diff --git a/src/zoom-z3950.c b/src/zoom-z3950.c index 400de9f..c11933a 100644 --- a/src/zoom-z3950.c +++ b/src/zoom-z3950.c @@ -539,6 +539,8 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) } if (c->odr_print) z_APDU(c->odr_print, &a, 0, 0); + if (c->odr_save) + z_APDU(c->odr_save, &a, 0, 0); yaz_log(c->log_details, "%p encoding_APDU encoding OK", c); return 0; } -- 1.7.10.4