Remove old form_successful_controls
This commit is contained in:
parent
6bf609a1a4
commit
0d5960a68c
349
render/form.c
349
render/form.c
|
@ -831,355 +831,6 @@ dom_no_memory:
|
|||
}
|
||||
#undef ENCODE_ITEM
|
||||
|
||||
/**
|
||||
* Identify 'successful' controls.
|
||||
*
|
||||
* All text strings in the successful controls list will be in the charset most
|
||||
* appropriate for submission. Therefore, no utf8_to_* processing should be
|
||||
* performed upon them.
|
||||
*
|
||||
* \todo The chosen charset needs to be made available such that it can be
|
||||
* included in the submission request (e.g. in the fetch's Content-Type header)
|
||||
*
|
||||
* \param form form to search for successful controls
|
||||
* \param submit_button control used to submit the form, if any
|
||||
* \param successful_controls updated to point to linked list of
|
||||
* fetch_multipart_data, 0 if no controls
|
||||
* \return true on success, false on memory exhaustion
|
||||
*
|
||||
* See HTML 4.01 section 17.13.2.
|
||||
*/
|
||||
bool form_successful_controls(struct form *form,
|
||||
struct form_control *submit_button,
|
||||
struct fetch_multipart_data **successful_controls)
|
||||
{
|
||||
struct form_control *control;
|
||||
struct form_option *option;
|
||||
struct fetch_multipart_data sentinel, *last_success, *success_new;
|
||||
char *value = NULL;
|
||||
bool had_submit = false;
|
||||
char *charset, *rawfile_temp;
|
||||
|
||||
last_success = &sentinel;
|
||||
sentinel.next = NULL;
|
||||
|
||||
charset = form_acceptable_charset(form);
|
||||
if (charset == NULL)
|
||||
return false;
|
||||
|
||||
#define ENCODE_ITEM(i) form_encode_item((i), 0, charset, form->document_charset)
|
||||
|
||||
for (control = form->controls; control; control = control->next) {
|
||||
/* ignore disabled controls */
|
||||
if (control->disabled)
|
||||
continue;
|
||||
|
||||
/* ignore controls with no name */
|
||||
if (!control->name)
|
||||
continue;
|
||||
|
||||
switch (control->type) {
|
||||
case GADGET_HIDDEN:
|
||||
if (control->value)
|
||||
value = ENCODE_ITEM(control->value);
|
||||
else
|
||||
value = ENCODE_ITEM("");
|
||||
if (!value) {
|
||||
LOG(("failed to duplicate value"
|
||||
"'%s' for control %s",
|
||||
control->value,
|
||||
control->name));
|
||||
goto no_memory;
|
||||
}
|
||||
break;
|
||||
|
||||
case GADGET_RADIO:
|
||||
case GADGET_CHECKBOX:
|
||||
/* ignore checkboxes and radio buttons which
|
||||
* aren't selected */
|
||||
if (!control->selected)
|
||||
continue;
|
||||
if (control->value)
|
||||
value = ENCODE_ITEM(control->value);
|
||||
else
|
||||
value = ENCODE_ITEM("on");
|
||||
if (!value) {
|
||||
LOG(("failed to duplicate"
|
||||
"value '%s' for"
|
||||
"control %s",
|
||||
control->value,
|
||||
control->name));
|
||||
goto no_memory;
|
||||
}
|
||||
break;
|
||||
|
||||
case GADGET_SELECT:
|
||||
/* select */
|
||||
for (option = control->data.select.items;
|
||||
option != NULL;
|
||||
option = option->next) {
|
||||
if (!option->selected)
|
||||
continue;
|
||||
success_new =
|
||||
malloc(sizeof(*success_new));
|
||||
if (!success_new) {
|
||||
LOG(("malloc failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
success_new->file = false;
|
||||
success_new->name =
|
||||
ENCODE_ITEM(control->name);
|
||||
success_new->value =
|
||||
ENCODE_ITEM(option->value);
|
||||
success_new->next = NULL;
|
||||
last_success->next = success_new;
|
||||
last_success = success_new;
|
||||
if (!success_new->name ||
|
||||
!success_new->value) {
|
||||
LOG(("strdup failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
break;
|
||||
|
||||
case GADGET_TEXTBOX:
|
||||
case GADGET_PASSWORD:
|
||||
case GADGET_TEXTAREA:
|
||||
{
|
||||
char *v2;
|
||||
int ta_len = textarea_get_text(
|
||||
control->data.text.ta,
|
||||
NULL, 0);
|
||||
|
||||
value = malloc(ta_len);
|
||||
if (!value) {
|
||||
LOG(("failed handling textarea"));
|
||||
goto no_memory;
|
||||
}
|
||||
textarea_get_text(control->data.text.ta,
|
||||
value, ta_len);
|
||||
|
||||
if (control->type == GADGET_TEXTAREA &&
|
||||
value[0] == '\0') {
|
||||
/* Textarea not submitted if empty */
|
||||
free(value);
|
||||
continue;
|
||||
}
|
||||
|
||||
v2 = ENCODE_ITEM(value);
|
||||
if (!v2) {
|
||||
LOG(("failed handling textarea"));
|
||||
free(value);
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
free(value);
|
||||
value = v2;
|
||||
}
|
||||
break;
|
||||
|
||||
case GADGET_IMAGE: {
|
||||
/* image */
|
||||
size_t len;
|
||||
char *name;
|
||||
|
||||
if (control != submit_button)
|
||||
/* only the activated submit button
|
||||
* is successful */
|
||||
continue;
|
||||
|
||||
name = ENCODE_ITEM(control->name);
|
||||
if (name == NULL)
|
||||
goto no_memory;
|
||||
|
||||
len = strlen(name) + 3;
|
||||
|
||||
/* x */
|
||||
success_new = malloc(sizeof(*success_new));
|
||||
if (!success_new) {
|
||||
free(name);
|
||||
LOG(("malloc failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
success_new->file = false;
|
||||
success_new->name = malloc(len);
|
||||
success_new->value = malloc(20);
|
||||
if (!success_new->name ||
|
||||
!success_new->value) {
|
||||
free(success_new->name);
|
||||
free(success_new->value);
|
||||
free(success_new);
|
||||
free(name);
|
||||
LOG(("malloc failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
sprintf(success_new->name, "%s.x", name);
|
||||
sprintf(success_new->value, "%i",
|
||||
control->data.image.mx);
|
||||
success_new->next = 0;
|
||||
last_success->next = success_new;
|
||||
last_success = success_new;
|
||||
|
||||
/* y */
|
||||
success_new = malloc(sizeof(*success_new));
|
||||
if (!success_new) {
|
||||
free(name);
|
||||
LOG(("malloc failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
success_new->file = false;
|
||||
success_new->name = malloc(len);
|
||||
success_new->value = malloc(20);
|
||||
if (!success_new->name ||
|
||||
!success_new->value) {
|
||||
free(success_new->name);
|
||||
free(success_new->value);
|
||||
free(success_new);
|
||||
free(name);
|
||||
LOG(("malloc failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
sprintf(success_new->name, "%s.y", name);
|
||||
sprintf(success_new->value, "%i",
|
||||
control->data.image.my);
|
||||
success_new->next = 0;
|
||||
last_success->next = success_new;
|
||||
last_success = success_new;
|
||||
|
||||
free(name);
|
||||
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
case GADGET_SUBMIT:
|
||||
if (!submit_button && !had_submit)
|
||||
/* no submit button specified, so
|
||||
* use first declared in form */
|
||||
had_submit = true;
|
||||
else if (control != submit_button)
|
||||
/* only the activated submit button
|
||||
* is successful */
|
||||
continue;
|
||||
if (control->value)
|
||||
value = ENCODE_ITEM(control->value);
|
||||
else
|
||||
value = ENCODE_ITEM("");
|
||||
if (!value) {
|
||||
LOG(("failed to duplicate value"
|
||||
"'%s' for control %s",
|
||||
control->value,
|
||||
control->name));
|
||||
goto no_memory;
|
||||
}
|
||||
break;
|
||||
|
||||
case GADGET_RESET:
|
||||
/* ignore reset */
|
||||
continue;
|
||||
break;
|
||||
|
||||
case GADGET_FILE:
|
||||
/* file */
|
||||
/* Handling of blank file entries is
|
||||
* implementation defined - we're perfectly
|
||||
* within our rights to treat it as an
|
||||
* unsuccessful control. Unfortunately, every
|
||||
* other browser submits the field with
|
||||
* a blank filename and no content. So,
|
||||
* that's what we have to do, too.
|
||||
*/
|
||||
success_new = malloc(sizeof(*success_new));
|
||||
if (!success_new) {
|
||||
LOG(("malloc failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
success_new->file = true;
|
||||
success_new->name = ENCODE_ITEM(control->name);
|
||||
success_new->value =
|
||||
ENCODE_ITEM(control->value ?
|
||||
control->value : "");
|
||||
success_new->rawfile = NULL;
|
||||
/* Retrieve the filename from the DOM annotation */
|
||||
if (dom_node_get_user_data(
|
||||
control->node,
|
||||
corestring_dom___ns_key_file_name_node_data,
|
||||
&rawfile_temp) != DOM_NO_ERR) {
|
||||
LOG(("unable to get rawfile"));
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
if (rawfile_temp == NULL) {
|
||||
/* No annotation means the file was not
|
||||
*/
|
||||
success_new->rawfile = strdup("");
|
||||
} else {
|
||||
success_new->rawfile = strdup(rawfile_temp);
|
||||
}
|
||||
|
||||
if (success_new->rawfile == NULL) {
|
||||
LOG(("strdup failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
success_new->next = 0;
|
||||
last_success->next = success_new;
|
||||
last_success = success_new;
|
||||
if (!success_new->name ||
|
||||
!success_new->value) {
|
||||
LOG(("strdup failed"));
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
continue;
|
||||
break;
|
||||
|
||||
case GADGET_BUTTON:
|
||||
/* Ignore it */
|
||||
continue;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
success_new = malloc(sizeof(*success_new));
|
||||
if (!success_new) {
|
||||
LOG(("malloc failed"));
|
||||
free(value);
|
||||
goto no_memory;
|
||||
}
|
||||
success_new->file = false;
|
||||
success_new->name = ENCODE_ITEM(control->name);
|
||||
success_new->value = value;
|
||||
success_new->next = NULL;
|
||||
last_success->next = success_new;
|
||||
last_success = success_new;
|
||||
if (!success_new->name) {
|
||||
LOG(("failed to duplicate name '%s'",
|
||||
control->name));
|
||||
goto no_memory;
|
||||
}
|
||||
}
|
||||
|
||||
free(charset);
|
||||
|
||||
*successful_controls = sentinel.next;
|
||||
return true;
|
||||
|
||||
no_memory:
|
||||
warn_user("NoMemory", 0);
|
||||
free(charset);
|
||||
fetch_multipart_data_destroy(sentinel.next);
|
||||
return false;
|
||||
|
||||
#undef ENCODE_ITEM
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode controls using application/x-www-form-urlencoded.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue