comparison src/c/urweb.c @ 1055:118a5a08a881

Merge
author Adam Chlipala <adamc@hcoop.net>
date Thu, 03 Dec 2009 11:56:15 -0500
parents b06a2a65e670 7e3226c97678
children 03a81e26e5fe
comparison
equal deleted inserted replaced
1054:b06a2a65e670 1055:118a5a08a881
670 670
671 return r; 671 return r;
672 } 672 }
673 673
674 int uw_set_input(uw_context ctx, const char *name, char *value) { 674 int uw_set_input(uw_context ctx, const char *name, char *value) {
675 printf("Input name %s\n", name); 675 //printf("Input name %s\n", name);
676 676
677 if (!strcasecmp(name, ".b")) { 677 if (!strcasecmp(name, ".b")) {
678 int n = uw_input_num(value); 678 int n = uw_input_num(value);
679 input *inps; 679 input *inps;
680 680
2701 b.size = r - ctx->heap.front; 2701 b.size = r - ctx->heap.front;
2702 ctx->heap.front = r; 2702 ctx->heap.front = r;
2703 return b; 2703 return b;
2704 } 2704 }
2705 2705
2706 #define THE_PAST "expires=Mon, 01-01-1970 00:00:00 GMT"
2707
2706 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) { 2708 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
2707 int len = strlen(c); 2709 int len = strlen(c);
2708 char *p = ctx->outHeaders.start; 2710 char *p = ctx->outHeaders.start;
2709 2711
2710 while (p = strstr(p, "\nSet-Cookie: ")) { 2712 while (p = strstr(p, "\nSet-Cookie: ")) {
2714 2716
2715 if (p2) { 2717 if (p2) {
2716 size_t sz = strcspn(p2+1, ";\r\n"); 2718 size_t sz = strcspn(p2+1, ";\r\n");
2717 2719
2718 if (!strncasecmp(p, c, p2 - p)) { 2720 if (!strncasecmp(p, c, p2 - p)) {
2719 char *ret = uw_malloc(ctx, sz + 1); 2721 if (sz == 0 && strstr(p2+2, THE_PAST))
2720 memcpy(ret, p2+1, sz); 2722 return NULL;
2721 ret[sz] = 0; 2723 else {
2722 return ret; 2724 char *ret = uw_malloc(ctx, sz + 1);
2725 memcpy(ret, p2+1, sz);
2726 ret[sz] = 0;
2727 return ret;
2728 }
2723 } 2729 }
2724 } 2730 }
2725 } 2731 }
2726 2732
2727 if (p = uw_Basis_requestHeader(ctx, "Cookie")) { 2733 if (p = uw_Basis_requestHeader(ctx, "Cookie")) {
2734 char *p2;
2735
2728 while (1) { 2736 while (1) {
2729 if (!strncmp(p, c, len) && p[len] == '=') 2737 if (!strncmp(p, c, len) && p[len] == '=') {
2730 return p + 1 + len; 2738 if (p2 = strchr(p, ';')) {
2731 else if (p = strchr(p, ';')) 2739 size_t n = p2 - (p + len);
2740 char *r = uw_malloc(ctx, n);
2741 memcpy(r, p + 1 + len, n-1);
2742 r[n-1] = 0;
2743 return r;
2744 } else
2745 return p + 1 + len;
2746 } else if (p = strchr(p, ';'))
2732 p += 2; 2747 p += 2;
2733 else 2748 else
2734 return NULL; 2749 return NULL;
2735 } 2750 }
2736 } 2751 }
2737 2752
2738 return NULL; 2753 return NULL;
2739 } 2754 }
2740 2755
2741 uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v) { 2756 uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v, uw_Basis_time *expires, uw_Basis_bool secure) {
2742 uw_write_header(ctx, "Set-Cookie: "); 2757 uw_write_header(ctx, "Set-Cookie: ");
2743 uw_write_header(ctx, c); 2758 uw_write_header(ctx, c);
2744 uw_write_header(ctx, "="); 2759 uw_write_header(ctx, "=");
2745 uw_write_header(ctx, v); 2760 uw_write_header(ctx, v);
2746 uw_write_header(ctx, "; path="); 2761 uw_write_header(ctx, "; path=");
2747 uw_write_header(ctx, prefix); 2762 uw_write_header(ctx, prefix);
2763 if (expires) {
2764 char formatted[30];
2765 struct tm tm;
2766
2767 gmtime_r(expires, &tm);
2768
2769 strftime(formatted, sizeof formatted, "%a, %d-%b-%Y %T GMT", &tm);
2770
2771 uw_write_header(ctx, "; expires=");
2772 uw_write_header(ctx, formatted);
2773 }
2774 if (secure)
2775 uw_write_header(ctx, "; secure");
2748 uw_write_header(ctx, "\r\n"); 2776 uw_write_header(ctx, "\r\n");
2777
2778 return uw_unit_v;
2779 }
2780
2781 uw_unit uw_Basis_clear_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c) {
2782 uw_write_header(ctx, "Set-Cookie: ");
2783 uw_write_header(ctx, c);
2784 uw_write_header(ctx, "=; path=");
2785 uw_write_header(ctx, prefix);
2786 uw_write_header(ctx, "; " THE_PAST "\r\n");
2749 2787
2750 return uw_unit_v; 2788 return uw_unit_v;
2751 } 2789 }
2752 2790
2753 static delta *allocate_delta(uw_context ctx, unsigned client) { 2791 static delta *allocate_delta(uw_context ctx, unsigned client) {
3133 *s2 = 0; 3171 *s2 = 0;
3134 3172
3135 return r; 3173 return r;
3136 } 3174 }
3137 3175
3176 const uw_Basis_time minTime = 0;
3177
3138 uw_Basis_time uw_Basis_now(uw_context ctx) { 3178 uw_Basis_time uw_Basis_now(uw_context ctx) {
3139 return time(NULL); 3179 return time(NULL);
3140 } 3180 }