diff options
Diffstat (limited to 'render')
-rw-r--r-- | render/box_construct.c | 47 | ||||
-rw-r--r-- | render/html.c | 21 | ||||
-rw-r--r-- | render/textplain.c | 53 |
3 files changed, 90 insertions, 31 deletions
diff --git a/render/box_construct.c b/render/box_construct.c index 5fdb23b5a..990fa380c 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -1257,17 +1257,44 @@ bool box_object(BOX_SPECIAL_PARAMS) * (classid || !classid) && data => data is used (consult type) * !classid && !data => invalid; ignored */ - if (params->classid && !params->data && params->codetype && - content_factory_type_from_mime_type(params->codetype) == - CONTENT_NONE) - /* can't handle this MIME type */ - return true; + if (params->classid != NULL && params->data == NULL && + params->codetype != NULL) { + lwc_string *icodetype; + lwc_error lerror; + + lerror = lwc_intern_string(params->codetype, + strlen(params->codetype), &icodetype); + if (lerror != lwc_error_ok) + return false; - if (params->data && params->type && - content_factory_type_from_mime_type(params->type) == - CONTENT_NONE) - /* can't handle this MIME type */ - return true; + if (content_factory_type_from_mime_type(icodetype) == + CONTENT_NONE) { + /* can't handle this MIME type */ + lwc_string_unref(icodetype); + return true; + } + + lwc_string_unref(icodetype); + } + + if (params->data != NULL && params->type != NULL) { + lwc_string *itype; + lwc_error lerror; + + lerror = lwc_intern_string(params->type, strlen(params->type), + &itype); + if (lerror != lwc_error_ok) + return false; + + if (content_factory_type_from_mime_type(itype) == + CONTENT_NONE) { + /* can't handle this MIME type */ + lwc_string_unref(itype); + return true; + } + + lwc_string_unref(itype); + } /* add parameters to linked list */ for (c = n->children; c; c = c->next) { diff --git a/render/html.c b/render/html.c index 9e2b4c338..6f76bf6ac 100644 --- a/render/html.c +++ b/render/html.c @@ -138,6 +138,7 @@ static const char *html_types[] = { }; static lwc_string *html_mime_types[NOF_ELEMENTS(html_types)]; +static lwc_string *html_charset; nserror html_init(void) { @@ -145,6 +146,12 @@ nserror html_init(void) lwc_error lerror; nserror error; + lerror = lwc_intern_string("charset", SLEN("charset"), &html_charset); + if (lerror != lwc_error_ok) { + error = NSERROR_NOMEM; + goto error; + } + for (i = 0; i < NOF_ELEMENTS(html_mime_types); i++) { lerror = lwc_intern_string(html_types[i], strlen(html_types[i]), @@ -176,6 +183,9 @@ void html_fini(void) if (html_mime_types[i] != NULL) lwc_string_unref(html_mime_types[i]); } + + if (html_charset != NULL) + lwc_string_unref(html_charset); } /** @@ -217,7 +227,7 @@ nserror html_create(const content_handler *handler, nserror html_create_html_data(html_content *c, const http_parameter *params) { - const char *charset; + lwc_string *charset; union content_msg_data msg_data; binding_error error; nserror nerror; @@ -245,10 +255,13 @@ nserror html_create_html_data(html_content *c, const http_parameter *params) c->font_func = &nsfont; c->scrollbar = NULL; - nerror = http_parameter_list_find_item(params, "charset", &charset); + nerror = http_parameter_list_find_item(params, html_charset, &charset); if (nerror == NSERROR_OK) { - c->encoding = talloc_strdup(c, charset); - if (!c->encoding) { + c->encoding = talloc_strdup(c, lwc_string_data(charset)); + + lwc_string_unref(charset); + + if (c->encoding == NULL) { error = BINDING_NOMEM; goto error; } diff --git a/render/textplain.c b/render/textplain.c index 873f277aa..247afc90d 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -58,7 +58,7 @@ struct textplain_line { typedef struct textplain_content { struct content base; - char *encoding; + lwc_string *encoding; void *inputstream; char *utf8_data; size_t utf8_data_size; @@ -93,7 +93,7 @@ static nserror textplain_create(const content_handler *handler, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c); static nserror textplain_create_internal(textplain_content *c, - const char *charset); + lwc_string *charset); static bool textplain_process_data(struct content *c, const char *data, unsigned int size); static bool textplain_convert(struct content *c); @@ -140,6 +140,8 @@ static const content_handler textplain_content_handler = { }; static lwc_string *textplain_mime_type; +static lwc_string *textplain_charset; +static lwc_string *textplain_default_charset; /** * Initialise the text content handler @@ -154,10 +156,28 @@ nserror textplain_init(void) if (lerror != lwc_error_ok) return NSERROR_NOMEM; + lerror = lwc_intern_string("charset", SLEN("charset"), + &textplain_charset); + if (lerror != lwc_error_ok) { + lwc_string_unref(textplain_mime_type); + return NSERROR_NOMEM; + } + + lerror = lwc_intern_string("Windows-1252", SLEN("Windows-1252"), + &textplain_default_charset); + if (lerror != lwc_error_ok) { + lwc_string_unref(textplain_charset); + lwc_string_unref(textplain_mime_type); + return NSERROR_NOMEM; + } + error = content_factory_register_handler(textplain_mime_type, &textplain_content_handler); - if (error != NSERROR_OK) + if (error != NSERROR_OK) { + lwc_string_unref(textplain_default_charset); + lwc_string_unref(textplain_charset); lwc_string_unref(textplain_mime_type); + } return error; } @@ -167,6 +187,8 @@ nserror textplain_init(void) */ void textplain_fini(void) { + lwc_string_unref(textplain_default_charset); + lwc_string_unref(textplain_charset); lwc_string_unref(textplain_mime_type); } @@ -181,7 +203,7 @@ nserror textplain_create(const content_handler *handler, { textplain_content *text; nserror error; - const char *encoding; + lwc_string *encoding; text = talloc_zero(0, textplain_content); if (text == NULL) @@ -194,17 +216,21 @@ nserror textplain_create(const content_handler *handler, return error; } - error = http_parameter_list_find_item(params, "charset", &encoding); + error = http_parameter_list_find_item(params, textplain_charset, + &encoding); if (error != NSERROR_OK) { - encoding = "Windows-1252"; + encoding = lwc_string_ref(textplain_default_charset); } error = textplain_create_internal(text, encoding); if (error != NSERROR_OK) { + lwc_string_unref(encoding); talloc_free(text); return error; } + lwc_string_unref(encoding); + *c = (struct content *) text; return NSERROR_OK; @@ -226,7 +252,7 @@ parserutils_error textplain_charset_hack(const uint8_t *data, size_t len, return PARSERUTILS_OK; } -nserror textplain_create_internal(textplain_content *c, const char *encoding) +nserror textplain_create_internal(textplain_content *c, lwc_string *encoding) { char *utf8_data; parserutils_inputstream *stream; @@ -239,7 +265,7 @@ nserror textplain_create_internal(textplain_content *c, const char *encoding) if (utf8_data == NULL) goto no_memory; - error = parserutils_inputstream_create(encoding, 0, + error = parserutils_inputstream_create(lwc_string_data(encoding), 0, textplain_charset_hack, ns_realloc, NULL, &stream); if (error == PARSERUTILS_BADENCODING) { /* Fall back to Windows-1252 */ @@ -252,13 +278,7 @@ nserror textplain_create_internal(textplain_content *c, const char *encoding) goto no_memory; } - c->encoding = strdup(encoding); - if (c->encoding == NULL) { - talloc_free(utf8_data); - parserutils_inputstream_destroy(stream); - goto no_memory; - } - + c->encoding = lwc_string_ref(encoding); c->inputstream = stream; c->utf8_data = utf8_data; c->utf8_data_size = 0; @@ -527,8 +547,7 @@ void textplain_destroy(struct content *c) { textplain_content *text = (textplain_content *) c; - if (text->encoding != NULL) - free(text->encoding); + lwc_string_unref(text->encoding); if (text->inputstream != NULL) parserutils_inputstream_destroy(text->inputstream); |