summaryrefslogtreecommitdiff
path: root/render/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'render/html.c')
-rw-r--r--render/html.c158
1 files changed, 104 insertions, 54 deletions
diff --git a/render/html.c b/render/html.c
index 09256a6fa..4e79e085e 100644
--- a/render/html.c
+++ b/render/html.c
@@ -113,13 +113,14 @@ static void html_box_convert_done(html_content *c, bool success)
LOG(("Done XML to box (%p)", c));
/* Clean up and report error if unsuccessful or aborted */
- if ((success == false) || c->aborted) {
+ if ((success == false) || (c->aborted)) {
+ if (success == false) {
+ msg_data.errorcode = NSERROR_BOX_CONVERT;
+ } else {
+ msg_data.errorcode = NSERROR_STOPPED;
+ }
html_destroy_objects(c);
- if (success == false)
- msg_data.error = messages_get("NoMemory");
- else
- msg_data.error = messages_get("Stopped");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
content_set_error(&c->base);
return;
}
@@ -134,19 +135,22 @@ static void html_box_convert_done(html_content *c, bool success)
exc = dom_document_get_document_element(c->document, (void *) &html);
if ((exc != DOM_NO_ERR) || (html == NULL)) {
+ /** @todo should this call html_destroy_objects(c);
+ * like the other error paths
+ */
LOG(("error retrieving html element from dom"));
- msg_data.error = messages_get("ParsingFail");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ msg_data.errorcode = NSERROR_DOM;
+ content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
content_set_error(&c->base);
return;
}
/* extract image maps - can't do this sensibly in xml_to_box */
- if (imagemap_extract(c) == false) {
+ msg_data.errorcode = imagemap_extract(c);
+ if (msg_data.errorcode != NSERROR_OK) {
LOG(("imagemap extraction failed"));
html_destroy_objects(c);
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
content_set_error(&c->base);
dom_node_unref(html);
return;
@@ -159,8 +163,9 @@ static void html_box_convert_done(html_content *c, bool success)
content_set_ready(&c->base);
- if (c->base.active == 0)
+ if (c->base.active == 0) {
content_set_done(&c->base);
+ }
html_set_status(c, "");
dom_node_unref(html);
@@ -413,9 +418,62 @@ html_create(const content_handler *handler,
return NSERROR_OK;
}
+static nserror
+parse_chunk_to_nserror(dom_hubbub_error error)
+{
+ switch (error) {
+ /* HUBBUB_REPROCESS is not handled here because it can
+ * never occur outside the hubbub treebuilder
+ */
-static bool
+ case DOM_HUBBUB_OK:
+ /* parsed ok */
+ return NSERROR_OK;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED):
+ /* hubbub input paused */
+ return NSERROR_OK;
+
+ case DOM_HUBBUB_NOMEM:
+ /* out of memory error from DOM */
+ return NSERROR_NOMEM;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE):
+ /* encoding changed */
+ return NSERROR_ENCODING_CHANGE;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM):
+ /* out of memory error from parser */
+ return NSERROR_NOMEM;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM):
+ return NSERROR_BAD_PARAMETER;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID):
+ return NSERROR_INVALID;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND):
+ return NSERROR_NOT_FOUND;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA):
+ return NSERROR_NEED_DATA;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING):
+ return NSERROR_BAD_ENCODING;
+
+ case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
+ /* currently only generated by the libdom hubbub binding */
+ default:
+ /* unknown error */
+ /** @todo better error handling and reporting */
+ return NSERROR_UNKNOWN;
+ }
+ return NSERROR_UNKNOWN;
+}
+
+
+static nserror
html_process_encoding_change(struct content *c,
const char *data,
unsigned int size)
@@ -425,34 +483,30 @@ html_process_encoding_change(struct content *c,
const char *encoding;
const char *source_data;
unsigned long source_size;
- union content_msg_data msg_data;
/* Retrieve new encoding */
encoding = dom_hubbub_parser_get_encoding(html->parser,
&html->encoding_source);
-
if (encoding == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
+ return NSERROR_NOMEM;
}
- if (html->encoding != NULL)
+ if (html->encoding != NULL) {
free(html->encoding);
+ }
html->encoding = strdup(encoding);
if (html->encoding == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
+ return NSERROR_NOMEM;
}
/* Destroy binding */
dom_hubbub_parser_destroy(html->parser);
html->parser = NULL;
- if (html->document != NULL)
+ if (html->document != NULL) {
dom_node_unref(html->document);
+ }
/* Create new binding, using the new encoding */
html->parser = dom_hubbub_parser_create(html->encoding,
@@ -468,9 +522,7 @@ html_process_encoding_change(struct content *c,
free(html->encoding);
html->encoding = strdup("Windows-1252");
if (html->encoding == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
+ return NSERROR_NOMEM;
}
html->parser = dom_hubbub_parser_create(html->encoding,
@@ -486,10 +538,7 @@ html_process_encoding_change(struct content *c,
* parser errors back instead of everything being
* OOM
*/
-
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
+ return NSERROR_NOMEM;
}
}
@@ -498,21 +547,16 @@ html_process_encoding_change(struct content *c,
/* Reprocess all the data. This is safe because
* the encoding is now specified at parser start which means
- * it cannot be changed again. */
- error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *)source_data, source_size);
-
- if ((error == DOM_HUBBUB_OK) ||
- (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
- return true;
- }
-
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
-
- return false;
+ * it cannot be changed again.
+ */
+ error = dom_hubbub_parser_parse_chunk(html->parser,
+ (const uint8_t *)source_data,
+ source_size);
+ return parse_chunk_to_nserror(error);
}
+
/**
* Process data for CONTENT_HTML.
*/
@@ -524,21 +568,27 @@ html_process_data(struct content *c, const char *data, unsigned int size)
dom_hubbub_error error;
union content_msg_data msg_data;
- error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
+ msg_data.errorcode = NSERROR_OK; /* assume its all going to be ok */
- if ((error == DOM_HUBBUB_OK) ||
- (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
- return true;
- } else if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
- return html_process_encoding_change(c, data, size);
- }
+ error = dom_hubbub_parser_parse_chunk(html->parser,
+ (const uint8_t *) data,
+ size);
- /** @todo better error handling and reporting */
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
-
+ msg_data.errorcode = parse_chunk_to_nserror(error);
+
+ /* deal with encoding change */
+ if (msg_data.errorcode == NSERROR_ENCODING_CHANGE) {
+ msg_data.errorcode = html_process_encoding_change(c, data, size);
+ }
+
+ /* broadcast the error if necessary */
+ if (msg_data.errorcode != NSERROR_OK) {
+ content_broadcast(c, CONTENT_MSG_ERRORCODE, msg_data);
+ return false;
+ }
+
+ return true;
}