diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-04-25 14:35:49 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-04-25 14:35:49 -0400 |
commit | 3d0a7f3cd81daaa7d49de95de7fe4eb8d1288876 (patch) | |
tree | 71212823b38e6c57adf86e66184c7c6a00c451bc /src | |
parent | 2dd6e83e23759ef4f5a27e399e43636881449345 (diff) |
Only allow single-file upload per control
Diffstat (limited to 'src')
-rw-r--r-- | src/c/driver.c | 9 | ||||
-rw-r--r-- | src/c/urweb.c | 42 | ||||
-rw-r--r-- | src/cjr_print.sml | 6 | ||||
-rw-r--r-- | src/marshalcheck.sml | 2 |
4 files changed, 23 insertions, 36 deletions
diff --git a/src/c/driver.c b/src/c/driver.c index fa4f474b..6e06f32b 100644 --- a/src/c/driver.c +++ b/src/c/driver.c @@ -393,14 +393,9 @@ static void *worker(void *data) { 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); } diff --git a/src/c/urweb.c b/src/c/urweb.c index 99564605..a73371ef 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -283,14 +283,14 @@ typedef struct { } 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 @@ char *uw_get_input(uw_context ctx, int n) { 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 @@ char *uw_get_optional_input(uw_context ctx, int n) { 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 @@ char *uw_get_optional_input(uw_context ctx, int n) { } } -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 @@ void uw_set_file_input(uw_context ctx, const char *name, uw_Basis_files fs) { 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 @@ uw_Basis_files uw_get_file_input(uw_context ctx, int n) { 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_string uw_Basis_fileName(uw_context ctx, uw_Basis_file f) { 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]; -} diff --git a/src/cjr_print.sml b/src/cjr_print.sml index d24cbfa4..07e3931f 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -456,9 +456,9 @@ fun isBlob Blob = true | 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 @@ fun p_file env (ds, ps) = (TFfi ("Basis", "bool"), _) => "optional_" | _ => "" in - if isFiles t then + if isFile t then box [string "uw_input_", p_ident x, space, diff --git a/src/marshalcheck.sml b/src/marshalcheck.sml index 3d517779..e39bf7c5 100644 --- a/src/marshalcheck.sml +++ b/src/marshalcheck.sml @@ -57,7 +57,7 @@ val clientToServer = [("Basis", "int"), ("Basis", "float"), ("Basis", "string"), ("Basis", "time"), - ("Basis", "files"), + ("Basis", "file"), ("Basis", "unit"), ("Basis", "option"), ("Basis", "bool")] |