X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fhttp.c;h=c05dc02109bfb3e682135f8593f742e62ae1a4d4;hp=0fb1434c37d3d0f0a24fd389e5038dd5165b3adb;hb=f9ee3b9ec26306b6397c37434e8066f084d33b3a;hpb=d6717ba6822aea328e4a456edcf0318261cdc175 diff --git a/src/http.c b/src/http.c index 0fb1434..c05dc02 100644 --- a/src/http.c +++ b/src/http.c @@ -10,7 +10,6 @@ #include #endif -#include #include #include #include @@ -143,13 +142,13 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, /* chunk length .. */ int chunk_len = 0; for (; i < o->size-2; i++) - if (isdigit(o->buf[i])) + if (yaz_isdigit(o->buf[i])) chunk_len = chunk_len * 16 + (o->buf[i] - '0'); - else if (isupper(o->buf[i])) + else if (yaz_isupper(o->buf[i])) chunk_len = chunk_len * 16 + (o->buf[i] - ('A'-10)); - else if (islower(o->buf[i])) + else if (yaz_islower(o->buf[i])) chunk_len = chunk_len * 16 + (o->buf[i] - ('a'-10)); else @@ -318,6 +317,48 @@ Z_GDU *z_get_HTTP_Request_host_path(ODR odr, return p; } +Z_GDU *z_get_HTTP_Request_uri(ODR odr, const char *uri, const char *args, + int use_full_uri) +{ + Z_GDU *p = z_get_HTTP_Request(odr); + const char *cp0 = strstr(uri, "://"); + const char *cp1 = 0; + if (cp0) + cp0 = cp0+3; + else + cp0 = uri; + + 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); + } + + if (!args) + { + if (*cp1) + args = cp1 + 1; + else + args = ""; + } + p->u.HTTP_Request->path = odr_malloc(odr, cp1 - uri + strlen(args) + 2); + if (use_full_uri) + { + memcpy(p->u.HTTP_Request->path, uri, cp1 - uri); + strcpy(p->u.HTTP_Request->path + (cp1 - uri), "/"); + } + else + strcpy(p->u.HTTP_Request->path, "/"); + strcat(p->u.HTTP_Request->path, args); + return p; +} Z_GDU *z_get_HTTP_Response(ODR o, int code) {