ZOOM: addinfo includes HTTP content when SRU decode fails
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 3 Aug 2011 09:40:33 +0000 (11:40 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 3 Aug 2011 09:40:33 +0000 (11:40 +0200)
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.

src/zoom-c.c
src/zoom-p.h
src/zoom-sru.c

index d2f33da..3422afb 100644 (file)
@@ -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)
index 3c7b7ea..fd2a04c 100644 (file)
@@ -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);
index 105970f..f9baf44 100644 (file)
@@ -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