New element <message> in bytarget response
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Dec 2012 11:59:05 +0000 (12:59 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Dec 2012 11:59:05 +0000 (12:59 +0100)
Holds diagnostic message of code (say 'Unsupported Use Attribute' for
Bib-1 114).

src/client.c
src/client.h
src/connection.c
src/http_command.c
src/session.c
src/session.h
test/test_settings_7.res

index c12b84f..a194a7e 100644 (file)
@@ -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;
index 8745abe..7a38ab4 100644 (file)
@@ -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);
index b456f0d..f48d735 100644 (file)
@@ -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);
             }
         }
index 8887e91..9fc50a8 100644 (file)
@@ -726,6 +726,9 @@ static void bytarget_response(struct http_channel *c, struct http_session *s, co
         wrbuf_printf(c->wrbuf, "<diagnostic>%d</diagnostic>\n", ht[i].diagnostic);
         if (ht[i].diagnostic)
         {
+            wrbuf_puts(c->wrbuf, "<message>");
+            wrbuf_xmlputs(c->wrbuf, ht[i].message);
+            wrbuf_puts(c->wrbuf, "</message>\n");
             wrbuf_puts(c->wrbuf, "<addinfo>");
             if (ht[i].addinfo)
                 wrbuf_xmlputs(c->wrbuf, ht[i].addinfo);
index 1927a1c..d43d407 100644 (file)
@@ -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);
index 6a4bf31..e1f5340 100644 (file)
@@ -140,6 +140,7 @@ struct hitsbytarget {
     Odr_int hits;
     Odr_int approximation;
     int diagnostic;
+    const char *message;
     const char *addinfo;
     int records;
     int filtered;
index c0035ee..6ef303f 100644 (file)
@@ -4,6 +4,7 @@
 <name>Target name</name>
 <hits>0</hits>
 <diagnostic>114</diagnostic>
+<message>Unsupported Use attribute</message>
 <addinfo>host_wildcard</addinfo>
 <records>0</records>
 <state>Client_Error</state>