X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fzgdu.c;h=6fc72f84816c1546f5f277743eeeeee85e015629;hb=caa5ae948706a481006e6d8d2abea24dec56b672;hp=88c92a50b4c139ea3a30c0378e42dafc1918ac4e;hpb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505;p=yaz-moved-to-github.git diff --git a/src/zgdu.c b/src/zgdu.c index 88c92a5..6fc72f8 100644 --- a/src/zgdu.c +++ b/src/zgdu.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: zgdu.c,v 1.13 2005-06-25 15:46:06 adam Exp $ + * $Id: zgdu.c,v 1.16 2006-09-14 07:40:00 marc Exp $ */ /** @@ -152,6 +152,22 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, return 1; } +void z_HTTP_header_add_content_type(ODR o, Z_HTTP_Header **hp, + const char *content_type, + const char *charset) +{ + const char *l = "Content-Type"; + if (charset) + { + char *ctype = odr_malloc(o, strlen(content_type)+strlen(charset) + 15); + sprintf(ctype, "%s; charset=%s", content_type, charset); + z_HTTP_header_add(o, hp, l, ctype); + } + else + z_HTTP_header_add(o, hp, l, content_type); + +} + void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, const char *v) { @@ -163,7 +179,7 @@ void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, (*hp)->next = 0; } -const char *z_HTTP_header_lookup(Z_HTTP_Header *hp, const char *n) +const char *z_HTTP_header_lookup(const Z_HTTP_Header *hp, const char *n) { for (; hp; hp = hp->next) if (!yaz_matchstr(hp->name, n)) @@ -191,6 +207,41 @@ Z_GDU *z_get_HTTP_Request(ODR o) return p; } + +Z_GDU *z_get_HTTP_Request_host_path(ODR odr, + const char *host, + const char *path) +{ + Z_GDU *p = z_get_HTTP_Request(odr); + + p->u.HTTP_Request->path = odr_strdup(odr, path); + + if (host) + { + 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); + } + } + return p; +} + + Z_GDU *z_get_HTTP_Response(ODR o, int code) { Z_GDU *p = (Z_GDU *) odr_malloc(o, sizeof(*p));