Mercurial > urweb
comparison src/c/urweb.c @ 739:4bb7e1c0550a
Only allow single-file upload per control
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 25 Apr 2009 14:35:49 -0400 |
parents | d049d31a1966 |
children | b302b6e35f93 |
comparison
equal
deleted
inserted
replaced
738:7fa4871e8272 | 739:4bb7e1c0550a |
---|---|
281 unsigned client; | 281 unsigned client; |
282 buf msgs; | 282 buf msgs; |
283 } delta; | 283 } delta; |
284 | 284 |
285 typedef enum { | 285 typedef enum { |
286 UNSET, NORMAL, FILES | 286 UNSET, NORMAL, FIL |
287 } input_kind; | 287 } input_kind; |
288 | 288 |
289 typedef struct { | 289 typedef struct { |
290 input_kind kind; | 290 input_kind kind; |
291 union { | 291 union { |
292 char *normal; | 292 char *normal; |
293 uw_Basis_files files; | 293 uw_Basis_file file; |
294 } data; | 294 } data; |
295 } input; | 295 } input; |
296 | 296 |
297 struct uw_context { | 297 struct uw_context { |
298 char *headers, *headers_end; | 298 char *headers, *headers_end; |
578 uw_error(ctx, FATAL, "Out-of-bounds input index %d", n); | 578 uw_error(ctx, FATAL, "Out-of-bounds input index %d", n); |
579 | 579 |
580 switch (ctx->inputs[n].kind) { | 580 switch (ctx->inputs[n].kind) { |
581 case UNSET: | 581 case UNSET: |
582 return NULL; | 582 return NULL; |
583 case FILES: | 583 case FIL: |
584 uw_error(ctx, FATAL, "Tried to read a files form input as normal"); | 584 uw_error(ctx, FATAL, "Tried to read a file form input as normal"); |
585 case NORMAL: | 585 case NORMAL: |
586 return ctx->inputs[n].data.normal; | 586 return ctx->inputs[n].data.normal; |
587 default: | 587 default: |
588 uw_error(ctx, FATAL, "Impossible input kind"); | 588 uw_error(ctx, FATAL, "Impossible input kind"); |
589 } | 589 } |
596 uw_error(ctx, FATAL, "Out-of-bounds input index %d", n); | 596 uw_error(ctx, FATAL, "Out-of-bounds input index %d", n); |
597 | 597 |
598 switch (ctx->inputs[n].kind) { | 598 switch (ctx->inputs[n].kind) { |
599 case UNSET: | 599 case UNSET: |
600 return ""; | 600 return ""; |
601 case FILES: | 601 case FIL: |
602 uw_error(ctx, FATAL, "Tried to read a files form input as normal"); | 602 uw_error(ctx, FATAL, "Tried to read a file form input as normal"); |
603 case NORMAL: | 603 case NORMAL: |
604 return ctx->inputs[n].data.normal; | 604 return ctx->inputs[n].data.normal; |
605 default: | 605 default: |
606 uw_error(ctx, FATAL, "Impossible input kind"); | 606 uw_error(ctx, FATAL, "Impossible input kind"); |
607 } | 607 } |
608 } | 608 } |
609 | 609 |
610 void uw_set_file_input(uw_context ctx, const char *name, uw_Basis_files fs) { | 610 void uw_set_file_input(uw_context ctx, const char *name, uw_Basis_file f) { |
611 int n = uw_input_num(name); | 611 int n = uw_input_num(name); |
612 | 612 |
613 if (n < 0) | 613 if (n < 0) |
614 uw_error(ctx, FATAL, "Bad file input name %s", name); | 614 uw_error(ctx, FATAL, "Bad file input name %s", name); |
615 | 615 |
616 if (n >= uw_inputs_len) | 616 if (n >= uw_inputs_len) |
617 uw_error(ctx, FATAL, "For file input name %s, index %d is out of range", name, n); | 617 uw_error(ctx, FATAL, "For file input name %s, index %d is out of range", name, n); |
618 | 618 |
619 ctx->inputs[n].kind = FILES; | 619 ctx->inputs[n].kind = FIL; |
620 ctx->inputs[n].data.files = fs; | 620 ctx->inputs[n].data.file = f; |
621 } | 621 } |
622 | 622 |
623 uw_Basis_files uw_get_file_input(uw_context ctx, int n) { | 623 void *uw_malloc(uw_context ctx, size_t len); |
624 | |
625 uw_Basis_file uw_get_file_input(uw_context ctx, int n) { | |
624 if (n < 0) | 626 if (n < 0) |
625 uw_error(ctx, FATAL, "Negative file input index %d", n); | 627 uw_error(ctx, FATAL, "Negative file input index %d", n); |
626 if (n >= uw_inputs_len) | 628 if (n >= uw_inputs_len) |
627 uw_error(ctx, FATAL, "Out-of-bounds file input index %d", n); | 629 uw_error(ctx, FATAL, "Out-of-bounds file input index %d", n); |
628 | 630 |
629 switch (ctx->inputs[n].kind) { | 631 switch (ctx->inputs[n].kind) { |
630 case UNSET: | 632 case UNSET: |
631 { | 633 { |
632 uw_Basis_files fs = {}; | 634 char *data = uw_malloc(ctx, 0); |
633 return fs; | 635 uw_Basis_file f = {"", {0, data}}; |
634 } | 636 return f; |
635 case FILES: | 637 } |
636 return ctx->inputs[n].data.files; | 638 case FIL: |
639 return ctx->inputs[n].data.file; | |
637 case NORMAL: | 640 case NORMAL: |
638 uw_error(ctx, FATAL, "Tried to read a normal form input as files"); | 641 uw_error(ctx, FATAL, "Tried to read a normal form input as files"); |
639 default: | 642 default: |
640 uw_error(ctx, FATAL, "Impossible input kind"); | 643 uw_error(ctx, FATAL, "Impossible input kind"); |
641 } | 644 } |
2126 } | 2129 } |
2127 | 2130 |
2128 uw_Basis_blob uw_Basis_fileData(uw_context ctx, uw_Basis_file f) { | 2131 uw_Basis_blob uw_Basis_fileData(uw_context ctx, uw_Basis_file f) { |
2129 return f.data; | 2132 return f.data; |
2130 } | 2133 } |
2131 | |
2132 uw_Basis_int uw_Basis_numFiles(uw_context ctx, uw_Basis_files fs) { | |
2133 return fs.size; | |
2134 } | |
2135 | |
2136 uw_Basis_file uw_Basis_fileNum(uw_context ctx, uw_Basis_files fs, uw_Basis_int n) { | |
2137 if (n < 0 || n >= fs.size) | |
2138 uw_error(ctx, FATAL, "Files index out of bounds"); | |
2139 else | |
2140 return fs.files[n]; | |
2141 } |