1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
7 * \brief HTTP cookie utility
13 #include <yaz/cookie.h>
24 struct yaz_cookies_s {
28 yaz_cookies_t yaz_cookies_create(void)
30 yaz_cookies_t yc = xmalloc(sizeof(*yc));
35 void yaz_cookies_destroy(yaz_cookies_t yc)
39 struct cookie *c = yc->list;
42 struct cookie *c1 = c->next;
54 void yaz_cookies_response(yaz_cookies_t yc, Z_HTTP_Response *res)
56 struct Z_HTTP_Header *h;
57 for (h = res->headers; h; h = h->next)
59 if (!strcmp(h->name, "Set-Cookie"))
65 cp = strchr(h->value, '=');
69 for (c = yc->list; c; c = c->next)
70 if (!strncmp(h->value, c->name, len) && c->name[len] == '\0')
74 c = xmalloc(sizeof(*c));
75 c->name = xstrndup(h->value, len);
83 cp1 = strchr(cp, ';');
85 cp1 = cp + strlen(cp);
87 c->value = xstrndup(cp, cp1 - cp);
92 void yaz_cookies_request(yaz_cookies_t yc, ODR odr, Z_HTTP_Request *req)
97 for (c = yc->list; c; c = c->next)
99 if (c->name && c->value)
100 sz += strlen(c->name) + strlen(c->value) + 3;
104 char *buf = odr_malloc(odr, sz + 1);
107 for (c = yc->list; c; c = c->next)
111 strcat(buf, c->name);
113 strcat(buf, c->value);
115 z_HTTP_header_add(odr, &req->headers, "Cookie", buf);
122 * c-file-style: "Stroustrup"
123 * indent-tabs-mode: nil
125 * vim: shiftwidth=4 tabstop=8 expandtab