summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2019-03-23 20:16:15 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2019-03-23 20:16:15 -0400
commit3f119f5c0a5f210ed442841dfed3ae98786004e9 (patch)
tree9cc52e33546dd2ff9101ec139f11eaf545eb31c1
parent18d42a0f0829132803a8c508e1d1cc797c6dbbde (diff)
Supporting 'char' arguments to handlers called from client code
-rw-r--r--include/urweb/urweb_cpp.h1
-rw-r--r--src/c/urweb.c17
-rw-r--r--src/settings.sml2
3 files changed, 20 insertions, 0 deletions
diff --git a/include/urweb/urweb_cpp.h b/include/urweb/urweb_cpp.h
index 18b5f583..dcf67fef 100644
--- a/include/urweb/urweb_cpp.h
+++ b/include/urweb/urweb_cpp.h
@@ -149,6 +149,7 @@ uw_Basis_unit uw_Basis_unurlifyUnit(struct uw_context * ctx, char **s);
uw_Basis_int uw_Basis_unurlifyInt(struct uw_context *, char **);
uw_Basis_float uw_Basis_unurlifyFloat(struct uw_context *, char **);
uw_Basis_string uw_Basis_unurlifyString(struct uw_context *, char **);
+uw_Basis_char uw_Basis_unurlifyChar(struct uw_context *, char **);
uw_Basis_string uw_Basis_unurlifyString_fromClient(struct uw_context *, char **);
uw_Basis_bool uw_Basis_unurlifyBool(struct uw_context *, char **);
uw_Basis_time uw_Basis_unurlifyTime(struct uw_context *, char **);
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 58f7884d..4d9e8630 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2267,6 +2267,23 @@ uw_Basis_string uw_Basis_unurlifyString(uw_context ctx, char **s) {
return r;
}
+uw_Basis_char uw_Basis_unurlifyChar(uw_context ctx, char **s) {
+ char *new_s = uw_unurlify_advance(*s);
+ char *r;
+ int len;
+
+ len = strlen(*s);
+ uw_check_heap(ctx, len + 1);
+
+ r = ctx->heap.front;
+ ctx->heap.front = uw_unurlifyString_to(0, ctx, ctx->heap.front, *s);
+ *s = new_s;
+ if (strlen(r) == 1)
+ return r[0];
+ else
+ uw_error(ctx, FATAL, "Unurlified character is multiple characters long");
+}
+
uw_Basis_unit uw_Basis_unurlifyUnit(uw_context ctx, char **s) {
(void)ctx;
*s = uw_unurlify_advance(*s);
diff --git a/src/settings.sml b/src/settings.sml
index abb26f72..edc03d4c 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -117,6 +117,7 @@ fun basis x = S.addList (S.empty, map (fn x : string => ("Basis", x)) x)
val clientToServerBase = basis ["int",
"float",
"string",
+ "char",
"time",
"file",
"unit",
@@ -277,6 +278,7 @@ val jsFuncsBase = basisM [("alert", "alert"),
("urlifyFloat", "ts"),
("urlifyTime", "ts"),
("urlifyString", "uf"),
+ ("urlifyChar", "uf"),
("urlifyBool", "ub"),
("recv", "rv"),
("strcat", "cat"),