better handling of initial rules loading from file - surf-adblock - Surf adbloc… | |
git clone git://git.codemadness.org/surf-adblock | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 141791dac93c6f5c7bc5a7525806897b3c3a4255 | |
parent 9014575ee36dc784da9f519c41d44932d248b772 | |
Author: Quentin Rameau <[email protected]> | |
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: | |
M 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) { |