diff options
author | 2009-11-26 14:20:00 -0500 | |
---|---|---|
committer | 2009-11-26 14:20:00 -0500 | |
commit | 20a451e11a5c10d4751beebcf09e0c86568ac5d2 (patch) | |
tree | 428c81f5418b09ac4d8f8bbfa61e16723e519f67 /src/c/urweb.c | |
parent | 27e785f13b18b42885b15cb38a2cd48d7e8fbdd5 (diff) |
More fun with cookies
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r-- | src/c/urweb.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 344ef2ad..cbe065c3 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -672,7 +672,7 @@ static input *check_input_space(uw_context ctx, size_t len) { } int uw_set_input(uw_context ctx, const char *name, char *value) { - printf("Input name %s\n", name); + //printf("Input name %s\n", name); if (!strcasecmp(name, ".b")) { int n = uw_input_num(value); @@ -2680,18 +2680,41 @@ uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) { return NULL; } -uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v) { +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) { uw_write_header(ctx, "Set-Cookie: "); uw_write_header(ctx, c); uw_write_header(ctx, "="); uw_write_header(ctx, v); uw_write_header(ctx, "; path="); uw_write_header(ctx, prefix); + if (expires) { + char formatted[30]; + struct tm tm; + + gmtime_r(expires, &tm); + + strftime(formatted, sizeof formatted, "%a, %d-%b-%Y %T GMT", &tm); + + uw_write_header(ctx, "; expires="); + uw_write_header(ctx, formatted); + } + if (secure) + uw_write_header(ctx, "; secure"); uw_write_header(ctx, "\r\n"); return uw_unit_v; } +uw_unit uw_Basis_clear_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c) { + uw_write_header(ctx, "Set-Cookie: "); + uw_write_header(ctx, c); + uw_write_header(ctx, "=; path="); + uw_write_header(ctx, prefix); + uw_write_header(ctx, "; expires=Mon, 01-01-1970 00:00:00 GMT\r\n"); + + return uw_unit_v; +} + static delta *allocate_delta(uw_context ctx, unsigned client) { unsigned i; delta *d; @@ -3077,6 +3100,8 @@ uw_Basis_string uw_Basis_mstrcat(uw_context ctx, ...) { return r; } +const uw_Basis_time minTime = 0; + uw_Basis_time uw_Basis_now(uw_context ctx) { return time(NULL); } |