summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-11-26 14:20:00 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-11-26 14:20:00 -0500
commit20a451e11a5c10d4751beebcf09e0c86568ac5d2 (patch)
tree428c81f5418b09ac4d8f8bbfa61e16723e519f67 /src
parent27e785f13b18b42885b15cb38a2cd48d7e8fbdd5 (diff)
More fun with cookies
Diffstat (limited to 'src')
-rw-r--r--src/c/urweb.c29
-rw-r--r--src/demo.sml2
-rw-r--r--src/monoize.sml34
-rw-r--r--src/settings.sml1
4 files changed, 58 insertions, 8 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);
}
diff --git a/src/demo.sml b/src/demo.sml
index 4e2caa99..c5480a93 100644
--- a/src/demo.sml
+++ b/src/demo.sml
@@ -430,7 +430,7 @@ fun make {prefix, dirname, guided} =
TextIO.closeOut outf;
- Compiler.compile (OS.Path.base fname)
+ Compiler.compiler (OS.Path.base fname)
end;
TextIO.output (demosOut, "\n</body></html>\n");
diff --git a/src/monoize.sml b/src/monoize.sml
index 5ac9d46b..25b7d9c3 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -1338,19 +1338,43 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
val s = (L'.TFfi ("Basis", "string"), loc)
val un = (L'.TRecord [], loc)
val t = monoType env t
- val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
+ val rt = (L'.TRecord [("Value", t),
+ ("Expires", (L'.TOption (L'.TFfi ("Basis", "time"),
+ loc), loc)),
+ ("Secure", (L'.TFfi ("Basis", "bool"), loc))], loc)
+
+ fun fd x = (L'.EField ((L'.ERel 1, loc), x), loc)
+ val (e, fm) = urlifyExp env fm (fd "Value", t)
in
- ((L'.EAbs ("c", s, (L'.TFun (t, (L'.TFun (un, un), loc)), loc),
- (L'.EAbs ("v", t, (L'.TFun (un, un), loc),
+ ((L'.EAbs ("c", s, (L'.TFun (rt, (L'.TFun (un, un), loc)), loc),
+ (L'.EAbs ("r", rt, (L'.TFun (un, un), loc),
(L'.EAbs ("_", un, un,
(L'.EFfiApp ("Basis", "set_cookie", [(L'.EPrim (Prim.String
(Settings.getUrlPrefix ())),
loc),
(L'.ERel 2, loc),
- e]), loc)),
+ e,
+ fd "Expires",
+ fd "Secure"])
+ , loc)), loc)), loc)), loc),
+ fm)
+ end
+
+ | L.ECApp ((L.EFfi ("Basis", "clearCookie"), _), t) =>
+ let
+ val s = (L'.TFfi ("Basis", "string"), loc)
+ val un = (L'.TRecord [], loc)
+ in
+ ((L'.EAbs ("c", s, (L'.TFun (un, un), loc),
+ (L'.EAbs ("_", un, un,
+ (L'.EFfiApp ("Basis", "clear_cookie",
+ [(L'.EPrim (Prim.String
+ (Settings.getUrlPrefix ())),
+ loc),
+ (L'.ERel 1, loc)]),
loc)), loc)), loc),
fm)
- end
+ end
| L.ECApp ((L.EFfi ("Basis", "channel"), _), t) =>
((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "channel"), loc),
diff --git a/src/settings.sml b/src/settings.sml
index 300bbf2c..009e2b0a 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -80,6 +80,7 @@ fun mayClientToServer x = S.member (!clientToServer, x)
val effectfulBase = basis ["dml",
"nextval",
"set_cookie",
+ "clear_cookie",
"new_client_source",
"get_client_source",
"set_client_source",