From ab0c408e57e6d12f3b9fbe71727616e45e80e8d9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 5 Dec 2012 12:59:05 +0100 Subject: [PATCH] New element in bytarget response Holds diagnostic message of code (say 'Unsupported Use Attribute' for Bib-1 114). --- src/client.c | 21 +++++++++++++++++---- src/client.h | 5 +++-- src/connection.c | 4 ++-- src/http_command.c | 3 +++ src/session.c | 3 ++- src/session.h | 1 + test/test_settings_7.res | 1 + 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/client.c b/src/client.c index c12b84f..a194a7e 100644 --- a/src/client.c +++ b/src/client.c @@ -119,6 +119,7 @@ struct client { int maxrecs; int startrecs; int diagnostic; + char *message; int preferred; struct suggestions *suggestions; enum client_state state; @@ -933,6 +934,7 @@ struct client *client_create(const char *id) cl->pquery = 0; cl->cqlquery = 0; cl->addinfo = 0; + cl->message = 0; cl->database = 0; cl->connection = 0; cl->session = 0; @@ -989,6 +991,8 @@ int client_destroy(struct client *c) c->cqlquery = 0; xfree(c->addinfo); c->addinfo = 0; + xfree(c->message); + c->message = 0; xfree(c->id); xfree(c->sort_strategy); xfree(c->sort_criteria); @@ -1055,7 +1059,9 @@ static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset) WRBUF w = wrbuf_alloc(); wrbuf_printf(w, "Malformed cclmap. name=%s", s->name); yaz_log(YLOG_WARN, "%s: %s", client_get_id(cl), wrbuf_cstr(w)); - client_set_diagnostic(cl, ZOOM_ERROR_CCL_CONFIG, wrbuf_cstr(w)); + client_set_diagnostic(cl, ZOOM_ERROR_CCL_CONFIG, + ZOOM_diag_str(ZOOM_ERROR_CCL_CONFIG), + wrbuf_cstr(w)); client_set_state_nb(cl, Client_Error); ccl_qual_rm(&res); wrbuf_destroy(w); @@ -1069,7 +1075,9 @@ static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset) wrbuf_printf(w, "Malformed cclmap. name=%s: value=%s (%s)", s->name, p, addinfo); yaz_log(YLOG_WARN, "%s: %s", client_get_id(cl), wrbuf_cstr(w)); - client_set_diagnostic(cl, ZOOM_ERROR_CCL_CONFIG, wrbuf_cstr(w)); + client_set_diagnostic(cl, ZOOM_ERROR_CCL_CONFIG, + ZOOM_diag_str(ZOOM_ERROR_CCL_CONFIG), + wrbuf_cstr(w)); client_set_state_nb(cl, Client_Error); ccl_qual_rm(&res); wrbuf_destroy(w); @@ -1494,17 +1502,22 @@ int client_get_num_records_filtered(struct client *cl) } void client_set_diagnostic(struct client *cl, int diagnostic, - const char *addinfo) + const char *message, const char *addinfo) { cl->diagnostic = diagnostic; + xfree(cl->message); + cl->message = xstrdup(message); xfree(cl->addinfo); cl->addinfo = 0; if (addinfo) cl->addinfo = xstrdup(addinfo); } -int client_get_diagnostic(struct client *cl, const char **addinfo) +int client_get_diagnostic(struct client *cl, const char **message, + const char **addinfo) { + if (message) + *message = cl->message; if (addinfo) *addinfo = cl->addinfo; return cl->diagnostic; diff --git a/src/client.h b/src/client.h index 8745abe..7a38ab4 100644 --- a/src/client.h +++ b/src/client.h @@ -96,9 +96,10 @@ Odr_int client_get_hits(struct client *cl); Odr_int client_get_approximation(struct client *cl); int client_get_num_records(struct client *cl); int client_get_num_records_filtered(struct client *cl); -int client_get_diagnostic(struct client *cl, const char **addinfo); +int client_get_diagnostic(struct client *cl, + const char **message, const char **addinfo); void client_set_diagnostic(struct client *cl, int diagnostic, - const char *addinfo); + const char *message, 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 b456f0d..f48d735 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, addinfo); + client_set_diagnostic(cl, err, error, addinfo); client_set_state(cl, Client_Error); } else @@ -288,7 +288,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, addinfo); + client_set_diagnostic(co->client, err, error, addinfo); client_set_state_nb(co->client, Client_Error); } } diff --git a/src/http_command.c b/src/http_command.c index 8887e91..9fc50a8 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -726,6 +726,9 @@ static void bytarget_response(struct http_channel *c, struct http_session *s, co wrbuf_printf(c->wrbuf, "%d\n", ht[i].diagnostic); if (ht[i].diagnostic) { + wrbuf_puts(c->wrbuf, ""); + wrbuf_xmlputs(c->wrbuf, ht[i].message); + wrbuf_puts(c->wrbuf, "\n"); wrbuf_puts(c->wrbuf, ""); if (ht[i].addinfo) wrbuf_xmlputs(c->wrbuf, ht[i].addinfo); diff --git a/src/session.c b/src/session.c index 1927a1c..d43d407 100644 --- a/src/session.c +++ b/src/session.c @@ -1014,7 +1014,8 @@ static struct hitsbytarget *hitsbytarget_nb(struct session *se, res[*count].records = client_get_num_records(cl); res[*count].filtered = client_get_num_records_filtered(cl); res[*count].diagnostic = - client_get_diagnostic(cl, &res[*count].addinfo); + client_get_diagnostic(cl, &res[*count].message, + &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 6a4bf31..e1f5340 100644 --- a/src/session.h +++ b/src/session.h @@ -140,6 +140,7 @@ struct hitsbytarget { Odr_int hits; Odr_int approximation; int diagnostic; + const char *message; const char *addinfo; int records; int filtered; diff --git a/test/test_settings_7.res b/test/test_settings_7.res index c0035ee..6ef303f 100644 --- a/test/test_settings_7.res +++ b/test/test_settings_7.res @@ -4,6 +4,7 @@ Target name 0 114 +Unsupported Use attribute host_wildcard 0 Client_Error -- 1.7.10.4