From ed886db22397360898fa5ef764543237e99b1774 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 3 Jul 2007 11:21:48 +0000 Subject: [PATCH] Added new setting pz:apdulog which controls whether APDUs should be logged for some target(s). Fixed bug #1252: Using record&offset=.. may hang for a long time. The problem was that a target did return a record initially but it failed for later present requests . So it was disconnected at the time the record&offset= was used. --- doc/pazpar2_conf.xml | 14 ++++++++++++-- src/client.c | 30 +++++++++++++++++++++++++----- src/connection.c | 15 ++++++++++++++- src/http_command.c | 6 +++--- src/settings.c | 3 ++- src/settings.h | 3 ++- 6 files changed, 58 insertions(+), 13 deletions(-) diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index dab43f6..8fb5b36 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -8,7 +8,7 @@ %idcommon; ]> - + Pazpar2 @@ -541,7 +541,7 @@ - + @@ -725,6 +725,16 @@ + + + pz:apdulog + + + If the 'pz:apdulog' setting is defined and has other value than 0, + then Z39.50 APDUs are written to the log. + + + diff --git a/src/client.c b/src/client.c index 9a8bf1d..6d98253 100644 --- a/src/client.c +++ b/src/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.12 2007-06-19 12:25:29 adam Exp $ +/* $Id: client.c,v 1.13 2007-07-03 11:21:48 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -108,6 +108,18 @@ static struct client *client_freelist = 0; static int send_apdu(struct client *c, Z_APDU *a) { + struct session_database *sdb = client_get_database(c); + const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG); + if (apdulog && *apdulog && *apdulog != '0') + { + ODR p = odr_createmem(ODR_PRINT); + yaz_log(YLOG_LOG, "send APDU %s", client_get_url(c)); + + odr_setprint(p, yaz_log_file()); + z_APDU(p, &a, 0, 0); + odr_setprint(p, stderr); + odr_destroy(p); + } return connection_send_apdu(client_get_connection(c), a); } @@ -235,7 +247,16 @@ int client_show_raw_begin(struct client *cl, int position, cl->show_raw->esn = xstrdup(esn); else cl->show_raw->esn = 0; - client_continue(cl); + + + if (cl->state == Client_Failed || cl->state == Client_Disconnected) + { + client_show_raw_error(cl, "not connected"); + } + else + { + client_continue(cl); + } return 0; } @@ -271,8 +292,8 @@ void client_send_raw_present(struct client *cl) assert(cl->show_raw); - yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d", - toget, start); + yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d", + client_get_url(cl), toget, start); a->u.presentRequest->resultSetStartPoint = &start; a->u.presentRequest->numberOfRecordsRequested = &toget; @@ -747,7 +768,6 @@ void client_continue(struct client *cl) if (cl->state == Client_Connected) { client_init_request(cl); } - if (cl->state == Client_Idle) { struct session *se = client_get_session(cl); diff --git a/src/connection.c b/src/connection.c index 7c7fba3..a75066e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1,4 +1,4 @@ -/* $Id: connection.c,v 1.5 2007-06-26 13:03:46 adam Exp $ +/* $Id: connection.c,v 1.6 2007-07-03 11:21:48 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -209,6 +209,8 @@ static void connection_handler(IOCHAN i, int event) if (client_is_our_response(cl)) { Z_APDU *a; + struct session_database *sdb = client_get_database(cl); + const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG); odr_reset(global_parameters.odr_in); odr_setbuf(global_parameters.odr_in, co->ibuf, len, 0); @@ -217,6 +219,17 @@ static void connection_handler(IOCHAN i, int event) client_fatal(cl); return; } + + if (apdulog && *apdulog && *apdulog != '0') + { + ODR p = odr_createmem(ODR_PRINT); + yaz_log(YLOG_LOG, "recv APDU %s", client_get_url(cl)); + + odr_setprint(p, yaz_log_file()); + z_APDU(p, &a, 0, 0); + odr_setprint(p, stderr); + odr_destroy(p); + } switch (a->which) { case Z_APDU_initResponse: diff --git a/src/http_command.c b/src/http_command.c index 31e416a..b024f86 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.55 2007-06-28 09:36:10 adam Exp $ +/* $Id: http_command.c,v 1.56 2007-07-03 11:21:48 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ /* - * $Id: http_command.c,v 1.55 2007-06-28 09:36:10 adam Exp $ + * $Id: http_command.c,v 1.56 2007-07-03 11:21:48 adam Exp $ */ #include @@ -500,7 +500,7 @@ static void show_raw_record_error(void *data, const char *addinfo) http_remove_observer(obs); - error(rs, PAZPAR2_NOT_IMPLEMENTED, addinfo); + error(rs, PAZPAR2_RECORD_FAIL, addinfo); } static void show_raw_record_ok(void *data, const char *buf, size_t sz) diff --git a/src/settings.c b/src/settings.c index 61613ea..b70a4cc 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,4 +1,4 @@ -/* $Id: settings.c,v 1.24 2007-06-28 09:36:10 adam Exp $ +/* $Id: settings.c,v 1.25 2007-07-03 11:21:48 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -60,6 +60,7 @@ static char *hard_settings[] = { "pz:queryencoding", "pz:ip", "pz:zproxy", + "pz:apdulog", 0 }; diff --git a/src/settings.h b/src/settings.h index 17b2f17..767d487 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,4 +1,4 @@ -/* $Id: settings.h,v 1.18 2007-06-06 11:49:48 marc Exp $ +/* $Id: settings.h,v 1.19 2007-07-03 11:21:48 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -36,6 +36,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define PZ_QUERYENCODING 11 #define PZ_IP 12 #define PZ_ZPROXY 13 +#define PZ_APDULOG 14 struct setting -- 1.7.10.4