Towards 2.1.40.
[yaz-moved-to-github.git] / src / zgdu.c
index 0dfdbaf..6fc72f8 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: zgdu.c,v 1.14 2006-03-01 23:24:25 adam Exp $
+ * $Id: zgdu.c,v 1.16 2006-09-14 07:40:00 marc Exp $
  */
 
 /**
@@ -179,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))
@@ -207,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));