Compare interns instead of strings in html_forms.c

This commit is contained in:
Michael Drake 2012-07-23 12:06:43 +01:00
parent 6bbe68823c
commit 26a92340e2
3 changed files with 85 additions and 37 deletions

View File

@ -40,19 +40,24 @@ parse_form_element(const char *docenc, dom_node *node)
struct form * ret = NULL;
/* Retrieve the attributes from the node */
if (dom_html_form_element_get_action(formele, &ds_action) != DOM_NO_ERR)
if (dom_html_form_element_get_action(formele,
&ds_action) != DOM_NO_ERR)
goto out;
if (dom_html_form_element_get_accept_charset(formele, &ds_charset) != DOM_NO_ERR)
if (dom_html_form_element_get_accept_charset(formele,
&ds_charset) != DOM_NO_ERR)
goto out;
if (dom_html_form_element_get_target(formele, &ds_target) != DOM_NO_ERR)
if (dom_html_form_element_get_target(formele,
&ds_target) != DOM_NO_ERR)
goto out;
if (dom_html_form_element_get_method(formele, &ds_method) != DOM_NO_ERR)
if (dom_html_form_element_get_method(formele,
&ds_method) != DOM_NO_ERR)
goto out;
if (dom_html_form_element_get_enctype(formele, &ds_enctype) != DOM_NO_ERR)
if (dom_html_form_element_get_enctype(formele,
&ds_enctype) != DOM_NO_ERR)
goto out;
/* Extract the plain attributes ready for use. We have to do this
@ -74,13 +79,13 @@ parse_form_element(const char *docenc, dom_node *node)
/* Determine the method */
method = method_GET;
if (ds_method != NULL) {
if (strncasecmp("post", dom_string_data(ds_method),
dom_string_byte_length(ds_method)) == 0) {
if (dom_string_caseless_lwc_isequal(ds_method,
corestring_lwc_post)) {
method = method_POST_URLENC;
if (ds_enctype != NULL) {
if (strncasecmp("multipart/form-data",
dom_string_data(ds_enctype),
dom_string_byte_length(ds_enctype)) == 0) {
if (dom_string_caseless_lwc_isequal(ds_enctype,
corestring_lwc_multipart_form_data)) {
method = method_POST_MULTIPART;
}
}
@ -180,7 +185,6 @@ parse_button_element(struct form *forms, dom_html_button_element *button)
dom_string *ds_type = NULL;
dom_string *ds_value = NULL;
dom_string *ds_name = NULL;
char *type = NULL;
err = dom_html_button_element_get_form(button, &form);
if (err != DOM_NO_ERR)
@ -193,11 +197,11 @@ parse_button_element(struct form *forms, dom_html_button_element *button)
if (ds_type == NULL) {
control = form_new_control(button, GADGET_SUBMIT);
} else {
type = strndup(dom_string_data(ds_type),
dom_string_byte_length(ds_type));
if (strcasecmp(type, "submit") == 0) {
if (dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_submit)) {
control = form_new_control(button, GADGET_SUBMIT);
} else if (strcasecmp(type, "reset") == 0) {
} else if (dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_reset)) {
control = form_new_control(button, GADGET_RESET);
} else {
control = form_new_control(button, GADGET_BUTTON);
@ -250,8 +254,6 @@ out:
dom_string_unref(ds_value);
if (ds_name != NULL)
dom_string_unref(ds_name);
if (type != NULL)
free(type);
return control;
}
@ -265,7 +267,6 @@ parse_input_element(struct form *forms, dom_html_input_element *input)
dom_string *ds_name = NULL;
dom_string *ds_value = NULL;
char *type = NULL;
char *name = NULL;
if (dom_html_input_element_get_form(input, &form) != DOM_NO_ERR)
@ -274,10 +275,6 @@ parse_input_element(struct form *forms, dom_html_input_element *input)
if (dom_html_input_element_get_type(input, &ds_type) != DOM_NO_ERR)
goto out;
if (ds_type != NULL)
type = strndup(dom_string_data(ds_type),
dom_string_byte_length(ds_type));
if (dom_html_input_element_get_name(input, &ds_name) != DOM_NO_ERR)
goto out;
@ -285,23 +282,32 @@ parse_input_element(struct form *forms, dom_html_input_element *input)
name = strndup(dom_string_data(ds_name),
dom_string_byte_length(ds_name));
if (type != NULL && strcasecmp(type, "password") == 0) {
if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_password)) {
control = form_new_control(input, GADGET_PASSWORD);
} else if (type != NULL && strcasecmp(type, "file") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_file)) {
control = form_new_control(input, GADGET_FILE);
} else if (type != NULL && strcasecmp(type, "hidden") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_hidden)) {
control = form_new_control(input, GADGET_HIDDEN);
} else if (type != NULL && strcasecmp(type, "checkbox") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_checkbox)) {
control = form_new_control(input, GADGET_CHECKBOX);
} else if (type != NULL && strcasecmp(type, "radio") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_radio)) {
control = form_new_control(input, GADGET_RADIO);
} else if (type != NULL && strcasecmp(type, "submit") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_submit)) {
control = form_new_control(input, GADGET_SUBMIT);
} else if (type != NULL && strcasecmp(type, "reset") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_reset)) {
control = form_new_control(input, GADGET_RESET);
} else if (type != NULL && strcasecmp(type, "button") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_button)) {
control = form_new_control(input, GADGET_BUTTON);
} else if (type != NULL && strcasecmp(type, "image") == 0) {
} else if (ds_type != NULL && dom_string_caseless_lwc_isequal(ds_type,
corestring_lwc_image)) {
control = form_new_control(input, GADGET_IMAGE);
} else {
control = form_new_control(input, GADGET_TEXTBOX);
@ -384,8 +390,6 @@ out:
if (ds_value != NULL)
dom_string_unref(ds_value);
if (type != NULL)
free(type);
if (name != NULL)
free(name);

View File

@ -38,11 +38,13 @@ lwc_string *corestring_lwc_bottom;
lwc_string *corestring_lwc_button;
lwc_string *corestring_lwc_caption;
lwc_string *corestring_lwc_center;
lwc_string *corestring_lwc_checkbox;
lwc_string *corestring_lwc_circle;
lwc_string *corestring_lwc_col;
lwc_string *corestring_lwc_default;
lwc_string *corestring_lwc_div;
lwc_string *corestring_lwc_embed;
lwc_string *corestring_lwc_file;
lwc_string *corestring_lwc_font;
lwc_string *corestring_lwc_h1;
lwc_string *corestring_lwc_h2;
@ -51,33 +53,40 @@ lwc_string *corestring_lwc_h4;
lwc_string *corestring_lwc_h5;
lwc_string *corestring_lwc_h6;
lwc_string *corestring_lwc_head;
lwc_string *corestring_lwc_hidden;
lwc_string *corestring_lwc_hr;
lwc_string *corestring_lwc_html;
lwc_string *corestring_lwc_iframe;
lwc_string *corestring_lwc_image;
lwc_string *corestring_lwc_img;
lwc_string *corestring_lwc_input;
lwc_string *corestring_lwc_justify;
lwc_string *corestring_lwc_left;
lwc_string *corestring_lwc_link;
lwc_string *corestring_lwc_middle;
lwc_string *corestring_lwc_multipart_form_data;
lwc_string *corestring_lwc_object;
lwc_string *corestring_lwc_p;
lwc_string *corestring_lwc_password;
lwc_string *corestring_lwc_poly;
lwc_string *corestring_lwc_polygon;
lwc_string *corestring_lwc_post;
lwc_string *corestring_lwc_radio;
lwc_string *corestring_lwc_rect;
lwc_string *corestring_lwc_rectangle;
lwc_string *corestring_lwc_reset;
lwc_string *corestring_lwc_right;
lwc_string *corestring_lwc_submit;
lwc_string *corestring_lwc_table;
lwc_string *corestring_lwc_tbody;
lwc_string *corestring_lwc_td;
lwc_string *corestring_lwc_text;
lwc_string *corestring_lwc_textarea;
lwc_string *corestring_lwc_texttop;
lwc_string *corestring_lwc_title;
lwc_string *corestring_lwc_tfoot;
lwc_string *corestring_lwc_th;
lwc_string *corestring_lwc_thead;
lwc_string *corestring_lwc_title;
lwc_string *corestring_lwc_top;
lwc_string *corestring_lwc_tr;
lwc_string *corestring_lwc__blank;
@ -152,11 +161,13 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(button);
CSS_LWC_STRING_UNREF(caption);
CSS_LWC_STRING_UNREF(center);
CSS_LWC_STRING_UNREF(checkbox);
CSS_LWC_STRING_UNREF(circle);
CSS_LWC_STRING_UNREF(col);
CSS_LWC_STRING_UNREF(default);
CSS_LWC_STRING_UNREF(div);
CSS_LWC_STRING_UNREF(embed);
CSS_LWC_STRING_UNREF(file);
CSS_LWC_STRING_UNREF(font);
CSS_LWC_STRING_UNREF(h1);
CSS_LWC_STRING_UNREF(h2);
@ -165,39 +176,47 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(h5);
CSS_LWC_STRING_UNREF(h6);
CSS_LWC_STRING_UNREF(head);
CSS_LWC_STRING_UNREF(hidden);
CSS_LWC_STRING_UNREF(hr);
CSS_LWC_STRING_UNREF(html);
CSS_LWC_STRING_UNREF(iframe);
CSS_LWC_STRING_UNREF(image);
CSS_LWC_STRING_UNREF(img);
CSS_LWC_STRING_UNREF(input);
CSS_LWC_STRING_UNREF(justify);
CSS_LWC_STRING_UNREF(left);
CSS_LWC_STRING_UNREF(link);
CSS_LWC_STRING_UNREF(middle);
CSS_LWC_STRING_UNREF(multipart_form_data);
CSS_LWC_STRING_UNREF(object);
CSS_LWC_STRING_UNREF(p);
CSS_LWC_STRING_UNREF(password);
CSS_LWC_STRING_UNREF(poly);
CSS_LWC_STRING_UNREF(polygon);
CSS_LWC_STRING_UNREF(post);
CSS_LWC_STRING_UNREF(radio);
CSS_LWC_STRING_UNREF(rect);
CSS_LWC_STRING_UNREF(rectangle);
CSS_LWC_STRING_UNREF(reset);
CSS_LWC_STRING_UNREF(right);
CSS_LWC_STRING_UNREF(submit);
CSS_LWC_STRING_UNREF(table);
CSS_LWC_STRING_UNREF(tbody);
CSS_LWC_STRING_UNREF(td);
CSS_LWC_STRING_UNREF(text);
CSS_LWC_STRING_UNREF(textarea);
CSS_LWC_STRING_UNREF(texttop);
CSS_LWC_STRING_UNREF(title);
CSS_LWC_STRING_UNREF(tfoot);
CSS_LWC_STRING_UNREF(th);
CSS_LWC_STRING_UNREF(thead);
CSS_LWC_STRING_UNREF(title);
CSS_LWC_STRING_UNREF(top);
CSS_LWC_STRING_UNREF(tr);
CSS_LWC_STRING_UNREF(_blank);
CSS_LWC_STRING_UNREF(_parent);
CSS_LWC_STRING_UNREF(_self);
CSS_LWC_STRING_UNREF(_top);
#undef CSS_LWC_STRING_UNREF
#define CSS_DOM_STRING_UNREF(NAME) \
@ -285,11 +304,13 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(button);
CSS_LWC_STRING_INTERN(caption);
CSS_LWC_STRING_INTERN(center);
CSS_LWC_STRING_INTERN(checkbox);
CSS_LWC_STRING_INTERN(circle);
CSS_LWC_STRING_INTERN(col);
CSS_LWC_STRING_INTERN(default);
CSS_LWC_STRING_INTERN(div);
CSS_LWC_STRING_INTERN(embed);
CSS_LWC_STRING_INTERN(file);
CSS_LWC_STRING_INTERN(font);
CSS_LWC_STRING_INTERN(h1);
CSS_LWC_STRING_INTERN(h2);
@ -298,9 +319,11 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(h5);
CSS_LWC_STRING_INTERN(h6);
CSS_LWC_STRING_INTERN(head);
CSS_LWC_STRING_INTERN(hidden);
CSS_LWC_STRING_INTERN(hr);
CSS_LWC_STRING_INTERN(html);
CSS_LWC_STRING_INTERN(iframe);
CSS_LWC_STRING_INTERN(image);
CSS_LWC_STRING_INTERN(img);
CSS_LWC_STRING_INTERN(input);
CSS_LWC_STRING_INTERN(justify);
@ -312,19 +335,23 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(password);
CSS_LWC_STRING_INTERN(poly);
CSS_LWC_STRING_INTERN(polygon);
CSS_LWC_STRING_INTERN(post);
CSS_LWC_STRING_INTERN(radio);
CSS_LWC_STRING_INTERN(rect);
CSS_LWC_STRING_INTERN(rectangle);
CSS_LWC_STRING_INTERN(reset);
CSS_LWC_STRING_INTERN(right);
CSS_LWC_STRING_INTERN(submit);
CSS_LWC_STRING_INTERN(table);
CSS_LWC_STRING_INTERN(tbody);
CSS_LWC_STRING_INTERN(td);
CSS_LWC_STRING_INTERN(text);
CSS_LWC_STRING_INTERN(textarea);
CSS_LWC_STRING_INTERN(texttop);
CSS_LWC_STRING_INTERN(title);
CSS_LWC_STRING_INTERN(tfoot);
CSS_LWC_STRING_INTERN(th);
CSS_LWC_STRING_INTERN(thead);
CSS_LWC_STRING_INTERN(title);
CSS_LWC_STRING_INTERN(top);
CSS_LWC_STRING_INTERN(tr);
CSS_LWC_STRING_INTERN(_blank);
@ -333,6 +360,14 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(_top);
#undef CSS_LWC_STRING_INTERN
lerror = lwc_intern_string("multipart/form-data",
SLEN("multipart/form-data"),
&corestring_lwc_multipart_form_data);
if ((lerror != lwc_error_ok) ||
(corestring_lwc_multipart_form_data == NULL))
goto error;
#define CSS_DOM_STRING_INTERN(NAME) \
do { \
exc = dom_string_create_interned( \

View File

@ -42,11 +42,13 @@ extern lwc_string *corestring_lwc_bottom;
extern lwc_string *corestring_lwc_button;
extern lwc_string *corestring_lwc_caption;
extern lwc_string *corestring_lwc_center;
extern lwc_string *corestring_lwc_checkbox;
extern lwc_string *corestring_lwc_circle;
extern lwc_string *corestring_lwc_col;
extern lwc_string *corestring_lwc_default;
extern lwc_string *corestring_lwc_div;
extern lwc_string *corestring_lwc_embed;
extern lwc_string *corestring_lwc_file;
extern lwc_string *corestring_lwc_font;
extern lwc_string *corestring_lwc_h1;
extern lwc_string *corestring_lwc_h2;
@ -55,33 +57,40 @@ extern lwc_string *corestring_lwc_h4;
extern lwc_string *corestring_lwc_h5;
extern lwc_string *corestring_lwc_h6;
extern lwc_string *corestring_lwc_head;
extern lwc_string *corestring_lwc_hidden;
extern lwc_string *corestring_lwc_hr;
extern lwc_string *corestring_lwc_html;
extern lwc_string *corestring_lwc_iframe;
extern lwc_string *corestring_lwc_image;
extern lwc_string *corestring_lwc_img;
extern lwc_string *corestring_lwc_input;
extern lwc_string *corestring_lwc_justify;
extern lwc_string *corestring_lwc_left;
extern lwc_string *corestring_lwc_link;
extern lwc_string *corestring_lwc_middle;
extern lwc_string *corestring_lwc_multipart_form_data;
extern lwc_string *corestring_lwc_object;
extern lwc_string *corestring_lwc_p;
extern lwc_string *corestring_lwc_password;
extern lwc_string *corestring_lwc_poly;
extern lwc_string *corestring_lwc_polygon;
extern lwc_string *corestring_lwc_post;
extern lwc_string *corestring_lwc_radio;
extern lwc_string *corestring_lwc_rect;
extern lwc_string *corestring_lwc_rectangle;
extern lwc_string *corestring_lwc_reset;
extern lwc_string *corestring_lwc_right;
extern lwc_string *corestring_lwc_submit;
extern lwc_string *corestring_lwc_table;
extern lwc_string *corestring_lwc_tbody;
extern lwc_string *corestring_lwc_td;
extern lwc_string *corestring_lwc_text;
extern lwc_string *corestring_lwc_textarea;
extern lwc_string *corestring_lwc_texttop;
extern lwc_string *corestring_lwc_title;
extern lwc_string *corestring_lwc_tfoot;
extern lwc_string *corestring_lwc_th;
extern lwc_string *corestring_lwc_thead;
extern lwc_string *corestring_lwc_title;
extern lwc_string *corestring_lwc_top;
extern lwc_string *corestring_lwc_tr;
extern lwc_string *corestring_lwc__blank;