X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=d1dfe502b62748282e28f3f328c262319e0bcfb2;hb=b371ad40aaba0a2000cc31fee8cd536f3d5caeab;hp=45eb69dcffe9456530c0c016a6c94cc3a840a686;hpb=f5f832b061784c7a1a996f377ddb27e58fd8311e;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 45eb69d..d1dfe50 100644 --- a/client/client.c +++ b/client/client.c @@ -666,11 +666,10 @@ static int cmd_base(const char *arg) return set_base(arg); } -int session_connect(const char *arg) +static int session_connect_base(const char *arg, const char **basep) { void *add; char type_and_host[101]; - const char *basep = 0; if (conn) { cs_close(conn); @@ -682,7 +681,7 @@ int session_connect(const char *arg) session_mem = NULL; session_initResponse = 0; } - cs_get_host_args(arg, &basep); + cs_get_host_args(arg, basep); strncpy(type_and_host, arg, sizeof(type_and_host)-1); type_and_host[sizeof(type_and_host)-1] = '\0'; @@ -718,11 +717,6 @@ int session_connect(const char *arg) } printf("OK.\n"); cs_print_session_info(conn); - if (basep && *basep) - set_base(basep); - else if (protocol == PROTO_Z3950) - set_base("Default"); - if (protocol == PROTO_Z3950) { send_initRequest(type_and_host); @@ -731,6 +725,19 @@ int session_connect(const char *arg) return 0; } +static int session_connect(const char *arg) +{ + int r; + const char *basep = 0; + + r = session_connect_base(arg, &basep); + if (basep && *basep) + set_base(basep); + else if (protocol == PROTO_Z3950) + set_base("Default"); + return r; +} + int cmd_open(const char *arg) { int r; @@ -1273,6 +1280,8 @@ static int send_SRW_redirect(const char *uri, Z_HTTP_Response *cookie_hres) const char *username = 0; const char *password = 0; struct Z_HTTP_Header *h; + char *combined_cookies; + int combined_cookies_len = 0; Z_GDU *gdu = get_HTTP_Request_url(out, uri); gdu->u.HTTP_Request->method = odr_strdup(out, "GET"); @@ -1281,9 +1290,24 @@ static int send_SRW_redirect(const char *uri, Z_HTTP_Response *cookie_hres) for (h = cookie_hres->headers; h; h = h->next) { - if (!strcmp(h->name, "Set-Cookie")) - z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers, - "Cookie", h->value); + if (!strcmp(h->name, "Set-Cookie")) { + char *cp; + + if (!(cp = strchr(h->value, ';'))) + cp = h->value + strlen(h->value); + if (cp - h->value >= 1) { + combined_cookies = xrealloc(combined_cookies, combined_cookies_len + cp - h->value + 3); + memcpy(combined_cookies+combined_cookies_len, h->value, cp - h->value); + combined_cookies[combined_cookies_len + cp - h->value] = '\0'; + strcat(combined_cookies,"; "); + combined_cookies_len = strlen(combined_cookies); + } + } + } + if (combined_cookies_len) + { + z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers, "Cookie", combined_cookies); + xfree(combined_cookies); } if (auth) @@ -2843,6 +2867,7 @@ static int parse_show_args(const char *arg_c, char *setstring, Odr_int *start, Odr_int *number) { char *end_ptr; + Odr_int start_position; if (setnumber >= 0) sprintf(setstring, "%d", setnumber); @@ -2854,8 +2879,11 @@ static int parse_show_args(const char *arg_c, char *setstring, *number = last_hit_count; *start = 1; } - *start = odr_strtol(arg_c, &end_ptr, 10); - if (end_ptr == arg_c || *end_ptr == '\0') + start_position = odr_strtol(arg_c, &end_ptr, 10); + if (end_ptr == arg_c) + return 1; + *start = start_position; + if (*end_ptr == '\0') return 1; while (isspace(*(unsigned char *)end_ptr)) end_ptr++; @@ -4422,7 +4450,8 @@ static void wait_and_handle_response(int one_response_only) && !yaz_matchstr(sru_method, "get") && (location = z_HTTP_header_lookup(hres->headers, "Location"))) { - session_connect(location); + const char *base_tmp; + session_connect_base(location, &base_tmp); no_redirects++; if (conn) {