Merge cookies on SRU redirects.
authorGiannis Kosmas <kosmas@lib.uoc.gr>
Wed, 16 Jun 2010 15:47:08 +0000 (18:47 +0300)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 23 Jun 2010 08:10:39 +0000 (10:10 +0200)
client/client.c
src/zoom-c.c

index 144c0f4..d1dfe50 100644 (file)
@@ -1280,6 +1280,8 @@ static int send_SRW_redirect(const char *uri, Z_HTTP_Response *cookie_hres)
     const char *username = 0;
     const char *password = 0;
     struct Z_HTTP_Header *h;
     const char *username = 0;
     const char *password = 0;
     struct Z_HTTP_Header *h;
+    char *combined_cookies;
+    int combined_cookies_len = 0;
     Z_GDU *gdu = get_HTTP_Request_url(out, uri);
 
     gdu->u.HTTP_Request->method = odr_strdup(out, "GET");
     Z_GDU *gdu = get_HTTP_Request_url(out, uri);
 
     gdu->u.HTTP_Request->method = odr_strdup(out, "GET");
@@ -1288,9 +1290,24 @@ static int send_SRW_redirect(const char *uri, Z_HTTP_Response *cookie_hres)
     
     for (h = cookie_hres->headers; h; h = h->next)
     {
     
     for (h = cookie_hres->headers; h; h = h->next)
     {
-        if (!strcmp(h->name, "Set-Cookie"))
-            z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
-                              "Cookie", h->value);
+        if (!strcmp(h->name, "Set-Cookie")) {
+            char *cp;
+
+            if (!(cp = strchr(h->value, ';')))
+                cp = h->value + strlen(h->value);
+            if (cp - h->value >= 1) {
+                combined_cookies = xrealloc(combined_cookies, combined_cookies_len + cp - h->value + 3);
+                memcpy(combined_cookies+combined_cookies_len, h->value, cp - h->value);
+                combined_cookies[combined_cookies_len + cp - h->value] = '\0';
+                strcat(combined_cookies,"; ");
+                combined_cookies_len = strlen(combined_cookies);
+            }
+        }
+    }
+    if (combined_cookies_len)
+    {
+        z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers, "Cookie", combined_cookies);
+        xfree(combined_cookies);
     }
 
     if (auth)
     }
 
     if (auth)
index d79e4e2..56d631f 100644 (file)
@@ -4241,17 +4241,38 @@ static zoom_ret send_SRW_redirect(ZOOM_connection c, const char *uri,
 {
     struct Z_HTTP_Header *h;
     Z_GDU *gdu = get_HTTP_Request_url(c->odr_out, uri);
 {
     struct Z_HTTP_Header *h;
     Z_GDU *gdu = get_HTTP_Request_url(c->odr_out, uri);
+    char *combined_cookies;
+    int combined_cookies_len = 0;
 
     gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET");
     z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "Accept",
                       "text/xml");
 
     gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET");
     z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "Accept",
                       "text/xml");
-    
+
     for (h = cookie_hres->headers; h; h = h->next)
     {
         if (!strcmp(h->name, "Set-Cookie"))
     for (h = cookie_hres->headers; h; h = h->next)
     {
         if (!strcmp(h->name, "Set-Cookie"))
-            z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
-                              "Cookie", h->value);
+        {
+            char *cp;
+
+            if (!(cp = strchr(h->value, ';')))
+                cp = h->value + strlen(h->value);
+            if (cp - h->value >= 1) {
+                combined_cookies = xrealloc(combined_cookies, combined_cookies_len + cp - h->value + 3);
+                memcpy(combined_cookies+combined_cookies_len, h->value, cp - h->value);
+                combined_cookies[combined_cookies_len + cp - h->value] = '\0';
+                strcat(combined_cookies,"; ");
+                combined_cookies_len = strlen(combined_cookies);
+            }
+        }
     }
     }
+
+    if (combined_cookies_len)
+    {
+        z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
+                          "Cookie", combined_cookies);
+        xfree(combined_cookies);
+    }
+
     if (c->user && c->password)
     {
         z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,
     if (c->user && c->password)
     {
         z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,