diff src/c/urweb.c @ 463:bb27c7efcd90

Reading cookies works
author Adam Chlipala <adamc@hcoop.net>
date Thu, 06 Nov 2008 12:08:41 -0500
parents 21bb5bbba2e9
children 91914c15a85b
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Nov 06 11:29:16 2008 -0500
+++ b/src/c/urweb.c	Thu Nov 06 12:08:41 2008 -0500
@@ -1143,7 +1143,23 @@
         return NULL;
     }
   }
+}
 
+uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
+  int len = strlen(c);
+  char *s = ctx->headers, *p;
+
+  while (p = strchr(s, ':')) {
+    if (!strncasecmp(s, "Cookie: ", 8) && !strncmp(p + 2, c, len)
+        && p + 2 + len < ctx->headers_end && p[2 + len] == '=') {
+      return p + 3 + len;
+    } else {
+      if ((s = strchr(p, 0)) && s < ctx->headers_end)
+        s += 2;
+      else
+        return NULL;
+    }
+  }
 }
 
 uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string c, uw_Basis_string v) {