X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fhttp.c;h=0f17df533b598e5f505330ec4795afbb1d04e0ef;hp=642c3ada69ca69187269b920a142146611028785;hb=d606d0d7c6015414a1d5ba065d09b507679be5a3;hpb=4aec24bebc09735c5157ce9c9904e7b0ad310fdd diff --git a/src/http.c b/src/http.c index 642c3ad..0f17df5 100644 --- a/src/http.c +++ b/src/http.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** @@ -16,6 +16,7 @@ #include #include #include +#include static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, char **content_buf, int *content_len) @@ -547,23 +548,23 @@ int yaz_decode_http_request(ODR o, Z_HTTP_Request **hr_p) static void dump_http_package(ODR o, const char *buf, size_t len) { - int i; + int i, limit = 8192; for (i = 0; ; i++) { if (i == len) { - odr_printf(o, "%.*s\n", i, buf); + o->op->stream_write(o, o->op->print, ODR_VISIBLESTRING, buf, i); break; } - else if (i > 8192) + else if (i >= limit) { - odr_printf(o, "%.*s\n", i, buf); - odr_printf(o, "(truncated\n", (long) len); + o->op->stream_write(o, o->op->print, ODR_VISIBLESTRING, buf, i); + odr_printf(o, "(truncated from %ld to %d\n", (long) len, i); break; } else if (buf[i] == 0) { - odr_printf(o, "%.*s\n", i, buf); + o->op->stream_write(o, o->op->print, ODR_VISIBLESTRING, buf, i); odr_printf(o, "(binary data)\n", (long) len); break; } @@ -645,6 +646,32 @@ int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr) return 1; } +const char *yaz_check_location(ODR odr, const char *uri, const char *location, + int *host_change) +{ + if (*location == '/') + { /* relative location */ + char *args = 0; + char *nlocation = (char *) odr_malloc(odr, strlen(location) + + strlen(uri) + 3); + strcpy(nlocation, uri); + cs_get_host_args(nlocation, (const char **) &args); + if (!args || !*args) + args = nlocation + strlen(nlocation); + else + args--; + strcpy(args, location); + *host_change = 0; + return nlocation; + } + else + { + /* we don't check if host is the same as before - yet */ + *host_change = 1; + return location; + } +} + /* * Local variables: * c-basic-offset: 4