X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzgdu.c;h=37f98205480f26b9f8b97f38086984b0b555b292;hp=88c92a50b4c139ea3a30c0378e42dafc1918ac4e;hb=d58b3c28b5efc7106f6ed65cd52c8ad56de7b6b9;hpb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505 diff --git a/src/zgdu.c b/src/zgdu.c index 88c92a5..37f9820 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.15 2006-06-02 13:08:27 adam 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) { @@ -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));