surf-adblock

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

commit f34202b8786c190d5935210e0289123943239730
parent 3217c9e3ead5b5cf40df1e624e8475d93574ae1e
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 16 Jul 2016 12:19:28 +0200

allow setting surf adblock file using env

Diffstat:
surf-adblock.c | 19++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/surf-adblock.c b/surf-adblock.c @@ -784,23 +784,28 @@ webpagecreated(WebKitWebExtension *e, WebKitWebPage *p, gpointer unused) } G_MODULE_EXPORT void -webkit_web_extension_initialize(WebKitWebExtension *e) +webkit_web_extension_initialize(WebKitWebExtension *ext) { struct filterrule *r; FILE *fp; - char filepath[PATH_MAX], *home; + char filepath[PATH_MAX], *e; int n; - home = getenv("HOME"); - n = snprintf(filepath, sizeof(filepath), "%s%s.surf/adblockrules", - home ? home : "", home ? "/" : ""); + if ((e = getenv("SURF_ADBLOCK_FILE"))) { + n = snprintf(filepath, sizeof(filepath), "%s", e); + } else { + if (!(e = getenv("HOME"))) + e = ""; + n = snprintf(filepath, sizeof(filepath), "%s%s.surf/adblockrules", + e, e[0] && e[strlen(e) - 1] != '/' ? "/" : ""); + } if (n < 0 || (size_t)n >= sizeof(filepath)) { fprintf(stderr, "fatal: path too long, truncated\n"); return; } if (!(fp = fopen(filepath, "r"))) { - fprintf(stderr, "fatal: cannot read rules file: %s: %s\n", + fprintf(stderr, "fatal: cannot read rules from file: %s: %s\n", filepath, strerror(errno)); return; } @@ -820,6 +825,6 @@ webkit_web_extension_initialize(WebKitWebExtension *e) string_append(&globalcss, STRP("{display:none;}")); } - g_signal_connect(e, "page-created", + g_signal_connect(ext, "page-created", G_CALLBACK(webpagecreated), NULL); }