From 86085de07ed717fa38152fa5d1a4ab6328d1fea4 Mon Sep 17 00:00:00 2001 From: "M. Vefa Bicakci" Date: Sun, 19 Oct 2008 03:25:00 +0200 Subject: [PATCH] Patch 1: Finalize modifications to the HTML parser [Forward ported to 0.12 from bug 1004 attachment 498. --KON] --- src/document/document.c | 2 +- src/document/html/frames.c | 2 +- src/document/html/parser.c | 24 ++++++------ src/document/html/parser/forms.c | 60 ++++++++++++++--------------- src/document/html/parser/general.c | 32 +++++++-------- src/document/html/parser/link.c | 10 ++--- src/document/html/parser/parse.c | 16 ++++---- src/document/html/parser/stack.c | 6 +-- src/document/html/parser/table.c | 62 +++++++++++++++--------------- src/document/html/renderer.c | 2 +- 10 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/document/document.c b/src/document/document.c index af8c09ca..9d474b2c 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -187,7 +187,7 @@ find_tag(struct document *document, unsigned char *name, int namelen) struct tag *tag; foreach (tag, document->tags) - if (!strlcasecmp(tag->name, -1, name, namelen)) + if (!c_strlcasecmp(tag->name, -1, name, namelen)) return tag->y; return -1; diff --git a/src/document/html/frames.c b/src/document/html/frames.c index a06af548..3c40db7f 100644 --- a/src/document/html/frames.c +++ b/src/document/html/frames.c @@ -137,7 +137,7 @@ find_fd(struct session *ses, unsigned char *name, foreachback (doc_view, ses->scrn_frames) { if (doc_view->used) continue; - if (strcasecmp(doc_view->name, name)) continue; + if (c_strcasecmp(doc_view->name, name)) continue; doc_view->used = 1; doc_view->depth = depth; diff --git a/src/document/html/parser.c b/src/document/html/parser.c index 8db8e577..81b59091 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -88,7 +88,7 @@ get_target(struct document_options *options, unsigned char *a) if (!v) return NULL; - if (!*v || !strcasecmp(v, "_self")) { + if (!*v || !c_strcasecmp(v, "_self")) { mem_free_set(&v, stracpy(options->framename)); } @@ -547,7 +547,7 @@ look_for_map(unsigned char **pos, unsigned char *eof, struct uri *uri, return 1; } - if (strlcasecmp(name, namelen, "MAP", 3)) return 1; + if (c_strlcasecmp(name, namelen, "MAP", 3)) return 1; if (uri && uri->fragment) { /* FIXME (bug 784): options->cp is the terminal charset; @@ -555,7 +555,7 @@ look_for_map(unsigned char **pos, unsigned char *eof, struct uri *uri, al = get_attr_val(attr, "name", options->cp); if (!al) return 1; - if (strlcasecmp(al, -1, uri->fragment, uri->fragmentlen)) { + if (c_strlcasecmp(al, -1, uri->fragment, uri->fragmentlen)) { mem_free(al); return 1; } @@ -602,12 +602,12 @@ look_for_tag(unsigned char **pos, unsigned char *eof, if (parse_element(*pos, eof, NULL, NULL, NULL, &pos2)) return 1; - if (strlcasecmp(name, namelen, "A", 1) - && strlcasecmp(name, namelen, "/A", 2) - && strlcasecmp(name, namelen, "MAP", 3) - && strlcasecmp(name, namelen, "/MAP", 4) - && strlcasecmp(name, namelen, "AREA", 4) - && strlcasecmp(name, namelen, "/AREA", 5)) { + if (c_strlcasecmp(name, namelen, "A", 1) + && c_strlcasecmp(name, namelen, "/A", 2) + && c_strlcasecmp(name, namelen, "MAP", 3) + && c_strlcasecmp(name, namelen, "/MAP", 4) + && c_strlcasecmp(name, namelen, "AREA", 4) + && c_strlcasecmp(name, namelen, "/AREA", 5)) { *pos = pos2; return 1; } @@ -644,12 +644,12 @@ look_for_link(unsigned char **pos, unsigned char *eof, struct menu_item **menu, return 1; } - if (!strlcasecmp(name, namelen, "A", 1)) { + if (!c_strlcasecmp(name, namelen, "A", 1)) { while (look_for_tag(pos, eof, name, namelen, &label)); if (*pos >= eof) return 0; - } else if (!strlcasecmp(name, namelen, "AREA", 4)) { + } else if (!c_strlcasecmp(name, namelen, "AREA", 4)) { /* FIXME (bug 784): options->cp is the terminal charset; * should use the document charset instead. */ unsigned char *alt = get_attr_val(attr, "alt", options->cp); @@ -663,7 +663,7 @@ look_for_link(unsigned char **pos, unsigned char *eof, struct menu_item **menu, label = NULL; } - } else if (!strlcasecmp(name, namelen, "/MAP", 4)) { + } else if (!c_strlcasecmp(name, namelen, "/MAP", 4)) { /* This is the only successful return from here! */ add_to_ml(ml, (void *) *menu, (void *) NULL); return 0; diff --git a/src/document/html/parser/forms.c b/src/document/html/parser/forms.c index 1a717a8b..c34459a1 100644 --- a/src/document/html/parser/forms.c +++ b/src/document/html/parser/forms.c @@ -52,7 +52,7 @@ html_form(struct html_context *html_context, unsigned char *a, al = get_attr_val(a, "method", html_context->doc_cp); if (al) { - if (!strcasecmp(al, "post")) { + if (!c_strcasecmp(al, "post")) { unsigned char *enctype; enctype = get_attr_val(a, "enctype", @@ -60,9 +60,9 @@ html_form(struct html_context *html_context, unsigned char *a, form->method = FORM_METHOD_POST; if (enctype) { - if (!strcasecmp(enctype, "multipart/form-data")) + if (!c_strcasecmp(enctype, "multipart/form-data")) form->method = FORM_METHOD_POST_MP; - else if (!strcasecmp(enctype, "text/plain")) + else if (!c_strcasecmp(enctype, "text/plain")) form->method = FORM_METHOD_POST_TEXT_PLAIN; mem_free(enctype); } @@ -153,11 +153,11 @@ html_button(struct html_context *html_context, unsigned char *a, al = get_attr_val(a, "type", cp); if (!al) goto no_type_attr; - if (!strcasecmp(al, "button")) { + if (!c_strcasecmp(al, "button")) { type = FC_BUTTON; - } else if (!strcasecmp(al, "reset")) { + } else if (!c_strcasecmp(al, "reset")) { type = FC_RESET; - } else if (strcasecmp(al, "submit")) { + } else if (c_strcasecmp(al, "submit")) { /* unknown type */ mem_free(al); return; @@ -273,16 +273,16 @@ html_input(struct html_context *html_context, unsigned char *a, al = get_attr_val(a, "type", cp); if (al) { - if (!strcasecmp(al, "text")) fc->type = FC_TEXT; - else if (!strcasecmp(al, "hidden")) fc->type = FC_HIDDEN; - else if (!strcasecmp(al, "button")) fc->type = FC_BUTTON; - else if (!strcasecmp(al, "checkbox")) fc->type = FC_CHECKBOX; - else if (!strcasecmp(al, "radio")) fc->type = FC_RADIO; - else if (!strcasecmp(al, "password")) fc->type = FC_PASSWORD; - else if (!strcasecmp(al, "submit")) fc->type = FC_SUBMIT; - else if (!strcasecmp(al, "reset")) fc->type = FC_RESET; - else if (!strcasecmp(al, "file")) fc->type = FC_FILE; - else if (!strcasecmp(al, "image")) fc->type = FC_IMAGE; + if (!c_strcasecmp(al, "text")) fc->type = FC_TEXT; + else if (!c_strcasecmp(al, "hidden")) fc->type = FC_HIDDEN; + else if (!c_strcasecmp(al, "button")) fc->type = FC_BUTTON; + else if (!c_strcasecmp(al, "checkbox")) fc->type = FC_CHECKBOX; + else if (!c_strcasecmp(al, "radio")) fc->type = FC_RADIO; + else if (!c_strcasecmp(al, "password")) fc->type = FC_PASSWORD; + else if (!c_strcasecmp(al, "submit")) fc->type = FC_SUBMIT; + else if (!c_strcasecmp(al, "reset")) fc->type = FC_RESET; + else if (!c_strcasecmp(al, "file")) fc->type = FC_FILE; + else if (!c_strcasecmp(al, "image")) fc->type = FC_IMAGE; /* else unknown type, let it default to FC_TEXT. */ mem_free(al); } @@ -408,12 +408,12 @@ abort: closing_tag = 0; } - if (closing_tag && !strlcasecmp(name, namelen, "SELECT", 6)) { + if (closing_tag && !c_strlcasecmp(name, namelen, "SELECT", 6)) { add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); goto end_parse; } - if (!strlcasecmp(name, namelen, "OPTION", 6)) { + if (!c_strlcasecmp(name, namelen, "OPTION", 6)) { add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); if (!closing_tag) { @@ -442,7 +442,7 @@ abort: goto see; } - if (!strlcasecmp(name, namelen, "OPTGROUP", 8)) { + if (!c_strlcasecmp(name, namelen, "OPTGROUP", 8)) { add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0; @@ -586,10 +586,10 @@ sp: if (namelen < 6) goto se; if (name[0] == '/') name++, namelen--; - - if (strlcasecmp(name, namelen, "OPTION", 6) - && strlcasecmp(name, namelen, "SELECT", 6) - && strlcasecmp(name, namelen, "OPTGROUP", 8)) + + if (c_strlcasecmp(name, namelen, "OPTION", 6) + && c_strlcasecmp(name, namelen, "SELECT", 6) + && c_strlcasecmp(name, namelen, "OPTGROUP", 8)) goto se; } @@ -641,7 +641,7 @@ pp: return; } if (parse_element(p, eof, &t_name, &t_namelen, NULL, end)) goto pp; - if (strlcasecmp(t_name, t_namelen, "/TEXTAREA", 9)) goto pp; + if (c_strlcasecmp(t_name, t_namelen, "/TEXTAREA", 9)) goto pp; fc = init_form_control(FC_TEXTAREA, attr, html_context); if (!fc) return; @@ -684,14 +684,14 @@ pp: wrap_attr = get_attr_val(attr, "wrap", html_context->doc_cp); if (wrap_attr) { - if (!strcasecmp(wrap_attr, "hard") - || !strcasecmp(wrap_attr, "physical")) { + if (!c_strcasecmp(wrap_attr, "hard") + || !c_strcasecmp(wrap_attr, "physical")) { fc->wrap = FORM_WRAP_HARD; - } else if (!strcasecmp(wrap_attr, "soft") - || !strcasecmp(wrap_attr, "virtual")) { + } else if (!c_strcasecmp(wrap_attr, "soft") + || !c_strcasecmp(wrap_attr, "virtual")) { fc->wrap = FORM_WRAP_SOFT; - } else if (!strcasecmp(wrap_attr, "none") - || !strcasecmp(wrap_attr, "off")) { + } else if (!c_strcasecmp(wrap_attr, "none") + || !c_strcasecmp(wrap_attr, "off")) { fc->wrap = FORM_WRAP_NONE; } mem_free(wrap_attr); diff --git a/src/document/html/parser/general.c b/src/document/html/parser/general.c index 3b38a7ff..4ebf9f99 100644 --- a/src/document/html/parser/general.c +++ b/src/document/html/parser/general.c @@ -227,10 +227,10 @@ html_script(struct html_context *html_context, unsigned char *a, if (type) { unsigned char *pos = type; - if (!strncasecmp(type, "text/", 5)) { + if (!c_strncasecmp(type, "text/", 5)) { pos += 5; - } else if (!strncasecmp(type, "application/", 12)) { + } else if (!c_strncasecmp(type, "application/", 12)) { pos += 12; } else { @@ -241,7 +241,7 @@ not_processed: return; } - if (!strncasecmp(pos, "javascript", 10)) { + if (!c_strncasecmp(pos, "javascript", 10)) { int len = strlen(pos); if (len > 10 && !isdigit(pos[10])) { @@ -249,11 +249,11 @@ not_processed: goto not_processed; } - } else if (strcasecmp(pos, "ecmascript") - && strcasecmp(pos, "jscript") - && strcasecmp(pos, "livescript") - && strcasecmp(pos, "x-javascript") - && strcasecmp(pos, "x-ecmascript")) { + } else if (c_strcasecmp(pos, "ecmascript") + && c_strcasecmp(pos, "jscript") + && c_strcasecmp(pos, "livescript") + && c_strcasecmp(pos, "x-javascript") + && c_strcasecmp(pos, "x-ecmascript")) { mem_free(type); goto not_processed; } @@ -271,7 +271,7 @@ not_processed: if (languagelen < 10 || (languagelen > 10 && !isdigit(language[10])) - || strncasecmp(language, "javascript", 10)) { + || c_strncasecmp(language, "javascript", 10)) { mem_free(language); goto not_processed; } @@ -372,7 +372,7 @@ imported: * argument. */ if (parse_element(*end, eof, &name, &namelen, NULL, NULL)) continue; - if (strlcasecmp(name, namelen, "/script", 7)) + if (c_strlcasecmp(name, namelen, "/script", 7)) continue; /* We have won! */ break; @@ -482,13 +482,13 @@ html_linebrk(struct html_context *html_context, unsigned char *a, unsigned char *al = get_attr_val(a, "align", html_context->doc_cp); if (al) { - if (!strcasecmp(al, "left")) par_format.align = ALIGN_LEFT; - else if (!strcasecmp(al, "right")) par_format.align = ALIGN_RIGHT; - else if (!strcasecmp(al, "center")) { + if (!c_strcasecmp(al, "left")) par_format.align = ALIGN_LEFT; + else if (!c_strcasecmp(al, "right")) par_format.align = ALIGN_RIGHT; + else if (!c_strcasecmp(al, "center")) { par_format.align = ALIGN_CENTER; if (!html_context->table_level) par_format.leftmargin = par_format.rightmargin = 0; - } else if (!strcasecmp(al, "justify")) par_format.align = ALIGN_JUSTIFY; + } else if (!c_strcasecmp(al, "justify")) par_format.align = ALIGN_JUSTIFY; mem_free(al); } } @@ -745,9 +745,9 @@ html_ul(struct html_context *html_context, unsigned char *a, al = get_attr_val(a, "type", html_context->doc_cp); if (al) { - if (!strcasecmp(al, "disc") || !strcasecmp(al, "circle")) + if (!c_strcasecmp(al, "disc") || !c_strcasecmp(al, "circle")) par_format.flags = P_O; - else if (!strcasecmp(al, "square")) + else if (!c_strcasecmp(al, "square")) par_format.flags = P_PLUS; mem_free(al); } diff --git a/src/document/html/parser/link.c b/src/document/html/parser/link.c index aa22c22c..9e5c66d6 100644 --- a/src/document/html/parser/link.c +++ b/src/document/html/parser/link.c @@ -463,12 +463,12 @@ html_object(struct html_context *html_context, unsigned char *a, type = get_attr_val(a, "type", html_context->doc_cp); if (!type) { mem_free(url); return; } - if (!strncasecmp(type, "text/", 5)) { + if (!c_strncasecmp(type, "text/", 5)) { /* We will just emulate