diff options
author | Adam Chlipala <adam@chlipala.net> | 2012-07-21 15:34:07 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2012-07-21 15:34:07 -0400 |
commit | 0d70a2d0f26350db55d68836a04fbefaabbd6e8a (patch) | |
tree | 5d99ec63c6f0e52226ec8b82736968d686bf73a0 | |
parent | efeb64a601c052ed533caee0131befe2c96bb91c (diff) |
Get regular forms working again
-rw-r--r-- | include/urweb/types.h | 1 | ||||
-rw-r--r-- | src/c/request.c | 10 | ||||
-rw-r--r-- | src/c/urweb.c | 33 |
3 files changed, 24 insertions, 20 deletions
diff --git a/include/urweb/types.h b/include/urweb/types.h index 152f4392..be7edb32 100644 --- a/include/urweb/types.h +++ b/include/urweb/types.h @@ -47,6 +47,7 @@ typedef struct uw_Basis_file { typedef struct uw_Basis_postBody { uw_Basis_string type, data; + size_t len; } uw_Basis_postBody; typedef uw_Basis_string uw_Basis_queryString; diff --git a/src/c/request.c b/src/c/request.c index b23c251f..21011bd0 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -246,7 +246,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx, char *inputs; const char *prefix = uw_get_url_prefix(ctx); char *s; - int had_error = 0; + int had_error = 0, is_fancy = 0; char errmsg[ERROR_BUF_LEN]; uw_reset(ctx); @@ -284,6 +284,10 @@ request_result uw_request(uw_request_context rc, uw_context ctx, uw_isPost(ctx); clen_s = uw_Basis_requestHeader(ctx, "Content-type"); + + if (!clen_s || strcasecmp(clen_s, "application/x-www-form-urlencoded")) + is_fancy = 1; + if (clen_s && !strncasecmp(clen_s, "multipart/form-data", 19)) { if (strncasecmp(clen_s + 19, "; boundary=", 11)) { log_error(logger_data, "Bad multipart boundary spec"); @@ -295,7 +299,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx, boundary[1] = '-'; boundary_len = strlen(boundary); } else if (clen_s) { - uw_Basis_postBody pb = {clen_s, body}; + uw_Basis_postBody pb = {clen_s, body, body_len}; uw_postBody(ctx, pb); } } else if (strcmp(method, "GET")) { @@ -430,7 +434,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx, } } } - else if (!uw_hasPostBody(ctx)) { + else if (!is_fancy) { inputs = is_post ? body : query_string; if (inputs) { diff --git a/src/c/urweb.c b/src/c/urweb.c index 0ccc418a..8d44088d 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -4100,29 +4100,28 @@ uw_Basis_string uw_Basis_remainingFields(uw_context ctx, uw_Basis_postField f) { } uw_Basis_postField *uw_Basis_firstFormField(uw_context ctx, uw_Basis_string s) { - char *amp, *eq, *unurl, *copy; + char *unurl; uw_Basis_postField *f; - if (s[0] == 0) - return NULL; + if (!ctx->hasPostBody) + uw_error(ctx, FATAL, "firstFormField called when there is no POST body"); - amp = strchr(s, '&'); - copy = uw_malloc(ctx, amp ? amp - s + 1 : strlen(s) + 1); - if (amp) { - strncpy(copy, s, amp - s); - copy[amp - s] = 0; - } else - strcpy(copy, s); - - eq = strchr(copy, '='); - if (eq) - *eq++ = 0; + if (s < ctx->postBody.data || s >= ctx->postBody.data + ctx->postBody.len) + return NULL; f = uw_malloc(ctx, sizeof(uw_Basis_postField)); - unurl = copy; + unurl = s; f->name = uw_Basis_unurlifyString(ctx, &unurl); - f->value = eq ? (unurl = eq, uw_Basis_unurlifyString(ctx, &unurl)) : ""; - f->remaining = amp ? amp+1 : ""; + s = strchr(s, 0); + if (!s) + uw_error(ctx, FATAL, "firstFormField: Missing null terminator"); + ++s; + unurl = s; + f->value = uw_Basis_unurlifyString(ctx, &unurl); + s = strchr(s, 0); + if (!s) + uw_error(ctx, FATAL, "firstFormField: Missing null terminator"); + f->remaining = s+1; return f; } |