netsurf: branch master updated. 617d655c7bbcccd5168514c9d29e5b329eec63d4

Chris Young chris.young at unsatisfactorysoftware.co.uk
Sat Nov 10 16:51:11 GMT 2012


> +	document = domutils_parse_file(filename, "iso-8859-1");
> +	if (document == NULL) {
> +		warn_user("TreeLoadError", messages_get("ParsingFail"));
>  		return false;
>  	}

It has been reported to me that the above error is getting triggered
on first run (ie. when Hotlist file does not exist).

The attached patch fixes this.

Chris
-------------- next part --------------
diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c
index 8cc3e05..92f0aa1 100644
--- a/desktop/tree_url_node.c
+++ b/desktop/tree_url_node.c
@@ -727,14 +727,17 @@ bool tree_urlfile_load(const char *filename, struct tree *tree,
 	dom_node *html, *body, *ul;
 	struct node *root;
 	tree_url_load_ctx ctx;
+	nserror error;
 
 	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;
 	}
 
diff --git a/utils/libdom.c b/utils/libdom.c
index 756465a..ee911c3 100644
--- a/utils/libdom.c
+++ b/utils/libdom.c
@@ -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;
 }
diff --git a/utils/libdom.h b/utils/libdom.h
index f2da405..e0e8964 100644
--- a/utils/libdom.h
+++ b/utils/libdom.h
@@ -62,6 +62,6 @@ 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


More information about the netsurf-dev mailing list