Report (and ignore) failure to load non-existent document. (Credit: Chris Young)

This commit is contained in:
John-Mark Bell 2012-11-11 11:31:34 +00:00
parent bb3a6bbb3b
commit ce640e59fd
3 changed files with 15 additions and 10 deletions

View File

@ -728,15 +728,18 @@ bool tree_urlfile_load(const char *filename, struct tree *tree,
dom_document *document;
dom_node *html, *body, *ul;
struct node *root;
nserror error;
tree_url_load_ctx ctx;
if (filename == NULL) {
return false;
}
document = libdom_parse_file(filename, "iso-8859-1");
if (document == NULL) {
warn_user("TreeLoadError", messages_get("ParsingFail"));
error = libdom_parse_file(filename, "iso-8859-1", &document);
if (error != NSERROR_OK) {
if (error != NSERROR_NOT_FOUND) {
warn_user("TreeLoadError", messages_get("ParsingFail"));
}
return false;
}

View File

@ -259,7 +259,7 @@ static void ignore_dom_msg(uint32_t severity, void *ctx, const char *msg, ...)
}
/* exported interface documented in libdom.h */
dom_document *libdom_parse_file(const char *filename, const char *encoding)
nserror libdom_parse_file(const char *filename, const char *encoding, dom_document **doc)
{
dom_hubbub_error error;
dom_hubbub_parser *parser;
@ -270,14 +270,14 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding)
fp = fopen(filename, "r");
if (fp == NULL) {
return NULL;
return NSERROR_NOT_FOUND;
}
parser = dom_hubbub_parser_create(encoding, false, false,
ignore_dom_msg, NULL, NULL, &document);
if (parser == NULL) {
fclose(fp);
return NULL;
return NSERROR_DOM;
}
while (feof(fp) == 0) {
@ -288,7 +288,7 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding)
dom_node_unref(document);
dom_hubbub_parser_destroy(parser);
fclose(fp);
return NULL;
return NSERROR_DOM;
}
}
@ -297,10 +297,11 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding)
dom_node_unref(document);
dom_hubbub_parser_destroy(parser);
fclose(fp);
return NULL;
return NSERROR_DOM;
}
dom_hubbub_parser_destroy(parser);
return document;
*doc = document;
return NSERROR_OK;
}

View File

@ -62,6 +62,7 @@ typedef bool (*libdom_iterate_cb)(dom_node *node, void *ctx);
void libdom_iterate_child_elements(dom_node *parent,
libdom_iterate_cb cb, void *ctx);
dom_document *libdom_parse_file(const char *filename, const char *encoding);
nserror libdom_parse_file(const char *filename, const char *encoding,
dom_document **doc);
#endif