Fix ZOOM: crash extended services diagnostics YAZ-846
[yaz-moved-to-github.git] / src / zoom-c.c
index b7bb1fe..b6cc643 100644 (file)
@@ -49,7 +49,6 @@ static void initlog(void)
     }
 }
 
-void ZOOM_connection_remove_tasks(ZOOM_connection c);
 static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri);
 
 void ZOOM_set_dset_error(ZOOM_connection c, int error,
@@ -84,7 +83,6 @@ void ZOOM_set_dset_error(ZOOM_connection c, int error,
                 c, c->host_port ? c->host_port : "<>", dset, error,
                 addinfo ? addinfo : "",
                 addinfo2 ? addinfo2 : "");
-        ZOOM_connection_remove_tasks(c);
     }
 }
 
@@ -189,6 +187,8 @@ void ZOOM_connection_remove_task(ZOOM_connection c)
     if (task)
     {
         c->tasks = task->next;
+        yaz_log(YLOG_LOG, "remove task p=%d type=%d next=%p",
+                task, (int) task->which, c->tasks);
         switch (task->which)
         {
         case ZOOM_TASK_SEARCH:
@@ -266,6 +266,7 @@ ZOOM_API(ZOOM_connection)
     c->host_port = 0;
     c->proxy = 0;
     c->tproxy = 0;
+    c->proxy_mode = 0;
 
     c->charset = c->lang = 0;
 
@@ -1078,8 +1079,11 @@ static zoom_ret do_connect_host(ZOOM_connection c, const char *logical_url)
 
     if (c->cs)
         cs_close(c->cs);
-    c->cs = cs_create_host_proxy(logical_url, CS_FLAGS_DNS_NO_BLOCK, &add,
-                                 c->tproxy ? c->tproxy : c->proxy);
+    c->cs = cs_create_host2(logical_url, CS_FLAGS_DNS_NO_BLOCK, &add,
+                            c->tproxy ? c->tproxy : c->proxy,
+                            &c->proxy_mode);
+    if (!c->proxy)
+        c->proxy_mode = 0;
 
     if (c->cs && c->cs->protocol == PROTO_HTTP)
     {
@@ -1501,7 +1505,6 @@ ZOOM_API(int)
     return 1;
 }
 
-#if YAZ_HAVE_XML2
 
 static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri)
 {
@@ -1521,6 +1524,7 @@ static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri)
     return ZOOM_send_GDU(c, gdu);
 }
 
+
 zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
 {
     ZOOM_Event event;
@@ -1541,15 +1545,13 @@ zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
     return ZOOM_send_buf(c);
 }
 
-#if YAZ_HAVE_XML2
 void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
                          const char *addinfo, const char *addinfo2)
 {
     ZOOM_set_dset_error(c, error, "HTTP", addinfo, addinfo2);
 }
-#endif
-
 
+#if YAZ_HAVE_XML2
 static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
 {
     zoom_ret cret = zoom_complete;
@@ -1677,22 +1679,26 @@ static int do_read(ZOOM_connection c)
 
         if (!z_GDU(c->odr_in, &gdu, 0, 0))
         {
-            int x;
-            int err = odr_geterrorx(c->odr_in, &x);
-            char msg[100];
-            const char *element = odr_getelement(c->odr_in);
-            yaz_snprintf(msg, sizeof(msg),
-                    "ODR code %d:%d element=%s offset=%d",
-                    err, x, element ? element : "<unknown>",
-                    odr_offset(c->odr_in));
-            ZOOM_set_error(c, ZOOM_ERROR_DECODE, msg);
-            if (c->log_api)
+            /* even on failures we try to re-connect (HTTP) */
+            if (!ZOOM_test_reconnect(c))
             {
-                FILE *ber_file = yaz_log_file();
-                if (ber_file)
-                    odr_dumpBER(ber_file, c->buf_in, r);
+                int x;
+                int err = odr_geterrorx(c->odr_in, &x);
+                char msg[100];
+                const char *element = odr_getelement(c->odr_in);
+                yaz_snprintf(msg, sizeof(msg),
+                             "ODR code %d:%d element=%s offset=%d",
+                             err, x, element ? element : "<unknown>",
+                             odr_offset(c->odr_in));
+                ZOOM_set_error(c, ZOOM_ERROR_DECODE, msg);
+                if (c->log_api)
+                {
+                    FILE *ber_file = yaz_log_file();
+                    if (ber_file)
+                        odr_dumpBER(ber_file, c->buf_in, r);
+                }
+                ZOOM_connection_close(c);
             }
-            ZOOM_connection_close(c);
         }
         else
         {