From ef0a61b93862f0bbb99b88f2d4460ad75509c814 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 15 Nov 2011 15:29:19 +0100 Subject: [PATCH] Command bytarget addinfo from diagnostics The new element is only present if there is an error (non-zero code). Question is whether we should also include the text representation of the error code itself (Bib-1 presumably). --- src/client.c | 15 +++++++++++++-- src/client.h | 5 +++-- src/connection.c | 4 ++-- src/http_command.c | 8 ++++++++ src/session.c | 3 ++- src/session.h | 1 + 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/client.c b/src/client.c index 5100f80..8890060 100644 --- a/src/client.c +++ b/src/client.c @@ -108,6 +108,7 @@ struct client { struct session *session; char *pquery; // Current search char *cqlquery; // used for SRU targets only + char *addinfo; // diagnostic info for most resent error Odr_int hits; int record_offset; int maxrecs; @@ -862,6 +863,7 @@ struct client *client_create(const char *id) cl->startrecs = 0; cl->pquery = 0; cl->cqlquery = 0; + cl->addinfo = 0; cl->database = 0; cl->connection = 0; cl->session = 0; @@ -913,6 +915,8 @@ int client_destroy(struct client *c) c->pquery = 0; xfree(c->cqlquery); c->cqlquery = 0; + xfree(c->addinfo); + c->addinfo = 0; xfree(c->id); assert(!c->connection); facet_limits_destroy(c->facet_limits); @@ -1304,13 +1308,20 @@ int client_get_num_records(struct client *cl) return cl->record_offset; } -void client_set_diagnostic(struct client *cl, int diagnostic) +void client_set_diagnostic(struct client *cl, int diagnostic, + const char *addinfo) { cl->diagnostic = diagnostic; + xfree(cl->addinfo); + cl->addinfo = 0; + if (addinfo) + cl->addinfo = xstrdup(addinfo); } -int client_get_diagnostic(struct client *cl) +int client_get_diagnostic(struct client *cl, const char **addinfo) { + if (addinfo) + *addinfo = cl->addinfo; return cl->diagnostic; } diff --git a/src/client.h b/src/client.h index 275b294..8697ba0 100644 --- a/src/client.h +++ b/src/client.h @@ -88,8 +88,9 @@ int client_parse_query(struct client *cl, const char *query, const char *maxrecs); Odr_int client_get_hits(struct client *cl); int client_get_num_records(struct client *cl); -int client_get_diagnostic(struct client *cl); -void client_set_diagnostic(struct client *cl, int diagnostic); +int client_get_diagnostic(struct client *cl, const char **addinfo); +void client_set_diagnostic(struct client *cl, int diagnostic, + const char *addinfo); void client_set_database(struct client *cl, struct session_database *db); const char *client_get_id(struct client *cl); int client_get_maxrecs(struct client *cl); diff --git a/src/connection.c b/src/connection.c index 1c7d467..9eac1a9 100644 --- a/src/connection.c +++ b/src/connection.c @@ -224,7 +224,7 @@ static void non_block_events(struct connection *co) { yaz_log(YLOG_LOG, "Error %s from %s", error, client_get_id(cl)); - client_set_diagnostic(cl, err); + client_set_diagnostic(cl, err, addinfo); client_set_state(cl, Client_Error); } else @@ -287,7 +287,7 @@ void connection_continue(struct connection *co) { yaz_log(YLOG_LOG, "Error %s from %s", error, client_get_id(co->client)); - client_set_diagnostic(co->client, err); + client_set_diagnostic(co->client, err, addinfo); client_set_state_nb(co->client, Client_Error); } } diff --git a/src/http_command.c b/src/http_command.c index ffe6b6d..f736b38 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -666,6 +666,14 @@ static void bytarget_response(struct http_channel *c) { wrbuf_printf(c->wrbuf, "" ODR_INT_PRINTF "\n", ht[i].hits); wrbuf_printf(c->wrbuf, "%d\n", ht[i].diagnostic); + if (ht[i].diagnostic) + { + wrbuf_puts(c->wrbuf, ""); + if (ht[i].addinfo) + wrbuf_xmlputs(c->wrbuf, ht[i].addinfo); + wrbuf_puts(c->wrbuf, "\n"); + } + wrbuf_printf(c->wrbuf, "%d\n", ht[i].records); wrbuf_puts(c->wrbuf, ""); diff --git a/src/session.c b/src/session.c index cdd588c..9706e0e 100644 --- a/src/session.c +++ b/src/session.c @@ -961,7 +961,8 @@ static struct hitsbytarget *hitsbytarget_nb(struct session *se, res[*count].name = *name ? name : "Unknown"; res[*count].hits = client_get_hits(cl); res[*count].records = client_get_num_records(cl); - res[*count].diagnostic = client_get_diagnostic(cl); + res[*count].diagnostic = + client_get_diagnostic(cl, &res[*count].addinfo); res[*count].state = client_get_state_str(cl); res[*count].connected = client_get_connection(cl) ? 1 : 0; session_settings_dump(se, client_get_database(cl), w); diff --git a/src/session.h b/src/session.h index a819922..9d74fdb 100644 --- a/src/session.h +++ b/src/session.h @@ -139,6 +139,7 @@ struct hitsbytarget { const char *name; Odr_int hits; int diagnostic; + const char *addinfo; int records; const char *state; int connected; -- 1.7.10.4