comparison src/c/urweb.c @ 1788:f57983ba2a36

Get regular forms working again
author Adam Chlipala <adam@chlipala.net>
date Sat, 21 Jul 2012 15:34:07 -0400
parents 69daa6d70299
children 3d922a28370b
comparison
equal deleted inserted replaced
1787:69daa6d70299 1788:f57983ba2a36
4098 uw_Basis_string uw_Basis_remainingFields(uw_context ctx, uw_Basis_postField f) { 4098 uw_Basis_string uw_Basis_remainingFields(uw_context ctx, uw_Basis_postField f) {
4099 return f.remaining; 4099 return f.remaining;
4100 } 4100 }
4101 4101
4102 uw_Basis_postField *uw_Basis_firstFormField(uw_context ctx, uw_Basis_string s) { 4102 uw_Basis_postField *uw_Basis_firstFormField(uw_context ctx, uw_Basis_string s) {
4103 char *amp, *eq, *unurl, *copy; 4103 char *unurl;
4104 uw_Basis_postField *f; 4104 uw_Basis_postField *f;
4105 4105
4106 if (s[0] == 0) 4106 if (!ctx->hasPostBody)
4107 uw_error(ctx, FATAL, "firstFormField called when there is no POST body");
4108
4109 if (s < ctx->postBody.data || s >= ctx->postBody.data + ctx->postBody.len)
4107 return NULL; 4110 return NULL;
4108 4111
4109 amp = strchr(s, '&');
4110 copy = uw_malloc(ctx, amp ? amp - s + 1 : strlen(s) + 1);
4111 if (amp) {
4112 strncpy(copy, s, amp - s);
4113 copy[amp - s] = 0;
4114 } else
4115 strcpy(copy, s);
4116
4117 eq = strchr(copy, '=');
4118 if (eq)
4119 *eq++ = 0;
4120
4121 f = uw_malloc(ctx, sizeof(uw_Basis_postField)); 4112 f = uw_malloc(ctx, sizeof(uw_Basis_postField));
4122 unurl = copy; 4113 unurl = s;
4123 f->name = uw_Basis_unurlifyString(ctx, &unurl); 4114 f->name = uw_Basis_unurlifyString(ctx, &unurl);
4124 f->value = eq ? (unurl = eq, uw_Basis_unurlifyString(ctx, &unurl)) : ""; 4115 s = strchr(s, 0);
4125 f->remaining = amp ? amp+1 : ""; 4116 if (!s)
4117 uw_error(ctx, FATAL, "firstFormField: Missing null terminator");
4118 ++s;
4119 unurl = s;
4120 f->value = uw_Basis_unurlifyString(ctx, &unurl);
4121 s = strchr(s, 0);
4122 if (!s)
4123 uw_error(ctx, FATAL, "firstFormField: Missing null terminator");
4124 f->remaining = s+1;
4126 4125
4127 return f; 4126 return f;
4128 } 4127 }