From: Adam Dickmeiss Date: Wed, 3 Aug 2011 09:40:33 +0000 (+0200) Subject: ZOOM: addinfo includes HTTP content when SRU decode fails X-Git-Tag: v4.2.7~1 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=4aaca71aaade2a94eab1806a11967d672e7c90dd;p=yaz-moved-to-github.git ZOOM: addinfo includes HTTP content when SRU decode fails When ZOOM C sees an SRU responst that it cannot decode it returns "meta" diagnostic ZOOM_ERROR_DECODE/10003 . The additional info now contains the HTTP content. --- diff --git a/src/zoom-c.c b/src/zoom-c.c index d2f33da..3422afb 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -1563,7 +1563,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) } else { - ret = ZOOM_handle_sru(c, hres, &cret); + ret = ZOOM_handle_sru(c, hres, &cret, &addinfo); if (ret == 0) { if (c->no_redirects) /* end of redirect. change hosts again */ @@ -1576,7 +1576,11 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) if (hres->code != 200) ZOOM_set_HTTP_error(c, hres->code, 0, 0); else + { + yaz_log(YLOG_LOG, "set error... addinfo=%s", addinfo ? + addinfo : "NULL"); ZOOM_set_error(c, ZOOM_ERROR_DECODE, addinfo); + } ZOOM_connection_close(c); } if (cret == zoom_complete) diff --git a/src/zoom-p.h b/src/zoom-p.h index 3c7b7ea..fd2a04c 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -271,7 +271,7 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c); zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c); int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, - zoom_ret *cret); + zoom_ret *cret, char **addinfo); void ZOOM_set_HTTP_error(ZOOM_connection c, int error, const char *addinfo, const char *addinfo2); diff --git a/src/zoom-sru.c b/src/zoom-sru.c index 105970f..f9baf44 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -391,16 +391,15 @@ static void handle_srw_scan_response(ZOOM_connection c, #endif int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, - zoom_ret *cret) + zoom_ret *cret, char **addinfo) { #if YAZ_HAVE_XML2 int ret = 0; - const char *addinfo = 0; /* not redirect (normal response) */ if (!yaz_srw_check_content_type(hres)) { - addinfo = "content-type"; + *addinfo = "content-type"; ret = -1; } else if (c->sru_mode == zoom_sru_solr) @@ -445,7 +444,19 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, soap_package->u.fault->fault_string); } else + { + size_t max_chars = 1000; + size_t sz = hres->content_len; + if (sz > max_chars - 1) + sz = max_chars; + *addinfo = odr_malloc(c->odr_in, sz + 4); + memcpy(*addinfo, hres->content_buf, sz); + if (sz == max_chars) + strcpy(*addinfo + sz, "..."); + else + strcpy(*addinfo + sz, ""); ret = -1; + } } return ret; #else