Mercurial > urweb
changeset 739:4bb7e1c0550a
Only allow single-file upload per control
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 25 Apr 2009 14:35:49 -0400 (2009-04-25) |
parents | 7fa4871e8272 |
children | b302b6e35f93 |
files | include/types.h include/urweb.h lib/ur/basis.urs src/c/driver.c src/c/urweb.c src/cjr_print.sml src/marshalcheck.sml tests/blob.ur |
diffstat | 8 files changed, 30 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/include/types.h Sat Apr 25 14:04:38 2009 -0400 +++ b/include/types.h Sat Apr 25 14:35:49 2009 -0400 @@ -33,11 +33,6 @@ uw_Basis_blob data; } uw_Basis_file; -typedef struct uw_Basis_files { - size_t size; - uw_Basis_file *files; -} uw_Basis_files; - typedef enum { SUCCESS, FATAL, BOUNDED_RETRY, UNLIMITED_RETRY } failure_kind;
--- a/include/urweb.h Sat Apr 25 14:04:38 2009 -0400 +++ b/include/urweb.h Sat Apr 25 14:35:49 2009 -0400 @@ -43,8 +43,8 @@ char *uw_get_input(uw_context, int name); char *uw_get_optional_input(uw_context, int name); -void uw_set_file_input(uw_context, char *name, uw_Basis_files fs); -uw_Basis_files uw_get_file_input(uw_context, int name); +void uw_set_file_input(uw_context, char *name, uw_Basis_file); +uw_Basis_file uw_get_file_input(uw_context, int name); void uw_write(uw_context, const char*); @@ -164,5 +164,4 @@ uw_Basis_string uw_Basis_fileName(uw_context, uw_Basis_file); uw_Basis_blob uw_Basis_fileData(uw_context, uw_Basis_file); -uw_Basis_int uw_Basis_numFiles(uw_context, uw_Basis_files); -uw_Basis_file uw_Basis_fileNum(uw_context, uw_Basis_files, uw_Basis_int); +
--- a/lib/ur/basis.urs Sat Apr 25 14:04:38 2009 -0400 +++ b/lib/ur/basis.urs Sat Apr 25 14:35:49 2009 -0400 @@ -518,11 +518,7 @@ val fileName : file -> option string val fileData : file -> blob -type files -val numFiles : files -> int -val fileNum : files -> int -> file - -val upload : formTag files [] [Value = string, Size = int] +val upload : formTag file [] [Value = string, Size = int] con radio = [Body, Radio] val radio : formTag string radio []
--- a/src/c/driver.c Sat Apr 25 14:04:38 2009 -0400 +++ b/src/c/driver.c Sat Apr 25 14:35:49 2009 -0400 @@ -393,14 +393,9 @@ part += boundary_len; if (filename) { - uw_Basis_file *f = malloc(sizeof(uw_Basis_file)); - uw_Basis_files fs = { 1, f }; + uw_Basis_file f = {filename, {part_len, after_sub_headers}}; - f->name = filename; - f->data.size = part_len; - f->data.data = after_sub_headers; - - uw_set_file_input(ctx, name, fs); + uw_set_file_input(ctx, name, f); } else uw_set_input(ctx, name, after_sub_headers); }
--- a/src/c/urweb.c Sat Apr 25 14:04:38 2009 -0400 +++ b/src/c/urweb.c Sat Apr 25 14:35:49 2009 -0400 @@ -283,14 +283,14 @@ } delta; typedef enum { - UNSET, NORMAL, FILES + UNSET, NORMAL, FIL } input_kind; typedef struct { input_kind kind; union { char *normal; - uw_Basis_files files; + uw_Basis_file file; } data; } input; @@ -580,8 +580,8 @@ switch (ctx->inputs[n].kind) { case UNSET: return NULL; - case FILES: - uw_error(ctx, FATAL, "Tried to read a files form input as normal"); + case FIL: + uw_error(ctx, FATAL, "Tried to read a file form input as normal"); case NORMAL: return ctx->inputs[n].data.normal; default: @@ -598,8 +598,8 @@ switch (ctx->inputs[n].kind) { case UNSET: return ""; - case FILES: - uw_error(ctx, FATAL, "Tried to read a files form input as normal"); + case FIL: + uw_error(ctx, FATAL, "Tried to read a file form input as normal"); case NORMAL: return ctx->inputs[n].data.normal; default: @@ -607,7 +607,7 @@ } } -void uw_set_file_input(uw_context ctx, const char *name, uw_Basis_files fs) { +void uw_set_file_input(uw_context ctx, const char *name, uw_Basis_file f) { int n = uw_input_num(name); if (n < 0) @@ -616,11 +616,13 @@ if (n >= uw_inputs_len) uw_error(ctx, FATAL, "For file input name %s, index %d is out of range", name, n); - ctx->inputs[n].kind = FILES; - ctx->inputs[n].data.files = fs; + ctx->inputs[n].kind = FIL; + ctx->inputs[n].data.file = f; } -uw_Basis_files uw_get_file_input(uw_context ctx, int n) { +void *uw_malloc(uw_context ctx, size_t len); + +uw_Basis_file uw_get_file_input(uw_context ctx, int n) { if (n < 0) uw_error(ctx, FATAL, "Negative file input index %d", n); if (n >= uw_inputs_len) @@ -629,11 +631,12 @@ switch (ctx->inputs[n].kind) { case UNSET: { - uw_Basis_files fs = {}; - return fs; + char *data = uw_malloc(ctx, 0); + uw_Basis_file f = {"", {0, data}}; + return f; } - case FILES: - return ctx->inputs[n].data.files; + case FIL: + return ctx->inputs[n].data.file; case NORMAL: uw_error(ctx, FATAL, "Tried to read a normal form input as files"); default: @@ -2128,14 +2131,3 @@ uw_Basis_blob uw_Basis_fileData(uw_context ctx, uw_Basis_file f) { return f.data; } - -uw_Basis_int uw_Basis_numFiles(uw_context ctx, uw_Basis_files fs) { - return fs.size; -} - -uw_Basis_file uw_Basis_fileNum(uw_context ctx, uw_Basis_files fs, uw_Basis_int n) { - if (n < 0 || n >= fs.size) - uw_error(ctx, FATAL, "Files index out of bounds"); - else - return fs.files[n]; -}
--- a/src/cjr_print.sml Sat Apr 25 14:04:38 2009 -0400 +++ b/src/cjr_print.sml Sat Apr 25 14:35:49 2009 -0400 @@ -456,9 +456,9 @@ | isBlob (Nullable t) = isBlob t | isBlob _ = false -fun isFiles (t : typ) = +fun isFile (t : typ) = case #1 t of - TFfi ("Basis", "files") => true + TFfi ("Basis", "file") => true | _ => false fun p_sql_type' t = @@ -2423,7 +2423,7 @@ (TFfi ("Basis", "bool"), _) => "optional_" | _ => "" in - if isFiles t then + if isFile t then box [string "uw_input_", p_ident x, space,
--- a/src/marshalcheck.sml Sat Apr 25 14:04:38 2009 -0400 +++ b/src/marshalcheck.sml Sat Apr 25 14:35:49 2009 -0400 @@ -57,7 +57,7 @@ ("Basis", "float"), ("Basis", "string"), ("Basis", "time"), - ("Basis", "files"), + ("Basis", "file"), ("Basis", "unit"), ("Basis", "option"), ("Basis", "bool")]
--- a/tests/blob.ur Sat Apr 25 14:04:38 2009 -0400 +++ b/tests/blob.ur Sat Apr 25 14:35:49 2009 -0400 @@ -2,16 +2,9 @@ table t : { Id : int, Nam : option string, Data : blob, Desc : string } fun save r = - if numFiles r.Data <> 1 then - error <xml>Please submit exactly one file.</xml> - else - let - val f = fileNum r.Data 0 - in - id <- nextval s; - dml (INSERT INTO t (Id, Nam, Data, Desc) VALUES ({[id]}, {[fileName f]}, {[fileData f]}, {[r.Desc]})); - main () - end + id <- nextval s; + dml (INSERT INTO t (Id, Nam, Data, Desc) VALUES ({[id]}, {[fileName r.Data]}, {[fileData r.Data]}, {[r.Desc]})); + main () and main () = return <xml><body> <form>