comparison src/c/urweb.c @ 1052:7e3226c97678

Fix handling of clearCookie/getCookie in same page gen
author Adam Chlipala <adamc@hcoop.net>
date Fri, 27 Nov 2009 09:12:46 -0500
parents 731e6aa6655a
children 118a5a08a881
comparison
equal deleted inserted replaced
1051:731e6aa6655a 1052:7e3226c97678
2643 b.size = r - ctx->heap.front; 2643 b.size = r - ctx->heap.front;
2644 ctx->heap.front = r; 2644 ctx->heap.front = r;
2645 return b; 2645 return b;
2646 } 2646 }
2647 2647
2648 #define THE_PAST "expires=Mon, 01-01-1970 00:00:00 GMT"
2649
2648 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) { 2650 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
2649 int len = strlen(c); 2651 int len = strlen(c);
2650 char *p = ctx->outHeaders.start; 2652 char *p = ctx->outHeaders.start;
2651 2653
2652 while (p = strstr(p, "\nSet-Cookie: ")) { 2654 while (p = strstr(p, "\nSet-Cookie: ")) {
2656 2658
2657 if (p2) { 2659 if (p2) {
2658 size_t sz = strcspn(p2+1, ";\r\n"); 2660 size_t sz = strcspn(p2+1, ";\r\n");
2659 2661
2660 if (!strncasecmp(p, c, p2 - p)) { 2662 if (!strncasecmp(p, c, p2 - p)) {
2661 char *ret = uw_malloc(ctx, sz + 1); 2663 if (sz == 0 && strstr(p2+2, THE_PAST))
2662 memcpy(ret, p2+1, sz); 2664 return NULL;
2663 ret[sz] = 0; 2665 else {
2664 return ret; 2666 char *ret = uw_malloc(ctx, sz + 1);
2667 memcpy(ret, p2+1, sz);
2668 ret[sz] = 0;
2669 return ret;
2670 }
2665 } 2671 }
2666 } 2672 }
2667 } 2673 }
2668 2674
2669 if (p = uw_Basis_requestHeader(ctx, "Cookie")) { 2675 if (p = uw_Basis_requestHeader(ctx, "Cookie")) {
2717 uw_unit uw_Basis_clear_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c) { 2723 uw_unit uw_Basis_clear_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c) {
2718 uw_write_header(ctx, "Set-Cookie: "); 2724 uw_write_header(ctx, "Set-Cookie: ");
2719 uw_write_header(ctx, c); 2725 uw_write_header(ctx, c);
2720 uw_write_header(ctx, "=; path="); 2726 uw_write_header(ctx, "=; path=");
2721 uw_write_header(ctx, prefix); 2727 uw_write_header(ctx, prefix);
2722 uw_write_header(ctx, "; expires=Mon, 01-01-1970 00:00:00 GMT\r\n"); 2728 uw_write_header(ctx, "; " THE_PAST "\r\n");
2723 2729
2724 return uw_unit_v; 2730 return uw_unit_v;
2725 } 2731 }
2726 2732
2727 static delta *allocate_delta(uw_context ctx, unsigned client) { 2733 static delta *allocate_delta(uw_context ctx, unsigned client) {