X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-c.c;h=dc529637ba0b3342a5e97132d12f27de65d88fb5;hp=d6821d60b59aee78e02e5d020dc96c5f46827ba3;hb=8fba4cf2cac1cc543aa4c1063c78b449ebac44a7;hpb=aaddb3668a93e2048e2237463a375ec3f48b68bb diff --git a/src/zoom-c.c b/src/zoom-c.c index d6821d6..dc52963 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -265,7 +265,6 @@ ZOOM_API(ZOOM_connection) c->options = ZOOM_options_create_with_parent(options); c->host_port = 0; - c->path = 0; c->proxy = 0; c->charset = c->lang = 0; @@ -507,8 +506,15 @@ ZOOM_API(void) ZOOM_options_get_int(c->options, "preferredMessageSize", 1024*1024); c->async = ZOOM_options_get_bool(c->options, "async", 0); + + if (c->sru_mode == zoom_sru_error) + { + ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, val); + ZOOM_connection_remove_tasks(c); + return; + } + yaz_log(c->log_details, "%p ZOOM_connection_connect async=%d", c, c->async); - ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); if (!c->async) @@ -583,7 +589,6 @@ ZOOM_API(void) ZOOM_connection_remove_tasks(c); ZOOM_connection_remove_events(c); xfree(c->host_port); - xfree(c->path); xfree(c->proxy); xfree(c->charset); xfree(c->lang); @@ -1045,20 +1050,6 @@ static zoom_ret do_connect_host(ZOOM_connection c, const char *logical_url) { #if YAZ_HAVE_XML2 c->proto = PROTO_HTTP; - xfree(c->path); - if (c->proxy) - { - c->path = xstrdup(logical_url); - } - else - { - const char *db = 0; - - cs_get_host_args(logical_url, &db); - - c->path = xmalloc(strlen(db) * 3 + 2); - yaz_encode_sru_dbpath_buf(c->path, db); - } #else ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW"); ZOOM_connection_close(c); @@ -1476,39 +1467,14 @@ ZOOM_API(int) } #if YAZ_HAVE_XML2 -static Z_GDU *get_HTTP_Request_url(ODR odr, const char *url) -{ - Z_GDU *p = z_get_HTTP_Request(odr); - const char *host = url; - const char *cp0 = strstr(host, "://"); - const char *cp1 = 0; - if (cp0) - cp0 = cp0+3; - else - cp0 = host; - - cp1 = strchr(cp0, '/'); - if (!cp1) - cp1 = cp0 + strlen(cp0); - - if (cp0 && cp1) - { - char *h = (char*) odr_malloc(odr, cp1 - cp0 + 1); - memcpy (h, cp0, cp1 - cp0); - h[cp1-cp0] = '\0'; - z_HTTP_header_add(odr, &p->u.HTTP_Request->headers, "Host", h); - } - p->u.HTTP_Request->path = odr_strdup(odr, *cp1 ? cp1 : "/"); - return p; -} static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri, Z_HTTP_Response *cookie_hres) { struct Z_HTTP_Header *h; - Z_GDU *gdu = get_HTTP_Request_url(c->odr_out, uri); char *combined_cookies = 0; int combined_cookies_len = 0; + Z_GDU *gdu = z_get_HTTP_Request_uri(c->odr_out, uri, 0, c->proxy ? 1 : 0); gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET"); z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "Accept", @@ -1567,14 +1533,14 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) { zoom_ret cret = zoom_complete; int ret = -1; - const char *addinfo = 0; + char *addinfo = 0; const char *connection_head = z_HTTP_header_lookup(hres->headers, "Connection"); const char *location; ZOOM_connection_set_mask(c, 0); yaz_log(c->log_details, "%p handle_http", c); - + if ((hres->code == 301 || hres->code == 302) && c->sru_mode == zoom_sru_get && (location = z_HTTP_header_lookup(hres->headers, "Location"))) { @@ -1592,13 +1558,12 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) do_connect_host(c, location); send_HTTP_redirect(c, location, hres); /* we're OK for now. Operation is not really complete */ - ret = 0; - cret = zoom_pending; + return; } } 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 */ @@ -1611,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) @@ -1643,6 +1612,8 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) c->reconnect_ok = 0; } } + else + c->reconnect_ok = 1; /* if the server closes anyway */ } } #endif @@ -1713,7 +1684,6 @@ static int do_read(ZOOM_connection c) #endif } } - c->reconnect_ok = 0; } return 1; }