surf-adblock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 838ebd014ac9c0583d80226fe9b56c0ae6fc2580
parent d0394b41a54ade78f733057f2c43dacc7eb0b6be
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sun, 17 Jul 2016 18:38:17 +0200

better handling of initial rules loading from file

Quit on error, but also when no rules were present in the file.

Diffstat:
surf-adblock.c | 25++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/surf-adblock.c b/surf-adblock.c @@ -684,10 +684,10 @@ debugrule(struct filterrule *r) r->isexception, r->block); } -struct filterrule * +static int loadrules(FILE *fp) { - struct filterrule f, *r, *rn = NULL, *rules = NULL; + struct filterrule f, *r, *rn = NULL; char *line = NULL; size_t linesiz = 0; ssize_t n; @@ -703,17 +703,17 @@ loadrules(FILE *fp) if ((ret = parserule(&f, line) > 0)) { if (!(r = wecalloc(1, sizeof(struct filterrule)))) - return NULL; + return -1; if (!rules) rules = rn = r; else rn = rn->next = r; memcpy(rn, &f, sizeof(struct filterrule)); } else if (ret < 0) { - return NULL; + return -1; } } - return rules; + return (rules != NULL); } Page * @@ -870,12 +870,19 @@ webkit_web_extension_initialize(WebKitWebExtension *ext) filepath, strerror(errno)); return; } - if (!(rules = loadrules(fp))) { - weprintf("fatal: cannot read rules file %s: %s\n", - filepath, strerror(errno)); + + n = loadrules(fp); + fclose(fp); + if (n < 1) { + if (n < 0) { + weprintf("fatal: cannot read rules from file %s: %s\n", + filepath, strerror(errno)); + } else { + weprintf("fatal: cannot read any rule from file %s\n", + filepath); + } return; } - fclose(fp); /* general CSS rules: all sites */ for (r = rules; r; r = r->next) {