surf-adblock

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

commit 95c5c0d4bd55049c2fbf2eff49580076ac749023
parent bce26341429ed8cb04c3df51aa55e08a5698785d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 17 Jul 2016 14:08:42 +0200

minor code-cleanup and simplifications

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

diff --git a/surf-adblock.c b/surf-adblock.c @@ -107,8 +107,8 @@ static struct filtertype filtertypes[] = { /* NOTE: site-key not supported */ }; -static Page *pages; static String globalcss; +static Page *pages; static struct filterrule *rules; static void @@ -612,9 +612,7 @@ parserule(struct filterrule *f, char *s) } /* has options */ - *p = '\0'; - f->uri = estrdup(s); - *p = '$'; + f->uri = estrndup(s, p - s); s = ++p; /* blockmask, has options? default: allow all options, case-sensitive @@ -724,17 +722,15 @@ documentloaded(WebKitWebPage *wp, Page *p) WebKitDOMElement *el; String sitecss; struct filterrule *r; - const char *s, *uri = webkit_web_page_get_uri(p->webpage); + const char *uri = webkit_web_page_get_uri(p->webpage); char *domain; - if (!uri || strncmp(uri, "http://", sizeof("http://") - 1) && - strncmp(uri, "https://", sizeof("https://") - 1)) + if (!uri || (strncmp(uri, "http://", sizeof("http://") - 1) && + strncmp(uri, "https://", sizeof("https://") - 1))) return; domain = strstr(uri, "://") + sizeof("://") - 1; - if (!(s = strchr(domain, '/'))) - for(s = domain; *s; ++s) ; - domain = estrndup(domain, s - domain); + domain = estrndup(domain, strcspn(domain, "/")); printf("uri: %s\n", uri); printf("domain: %s\n", domain); @@ -780,20 +776,17 @@ sendrequest(WebKitWebPage *wp, WebKitURIRequest *req, WebKitURIResponse *res, Page *p) { struct filterrule *r; - - const char *s, *uri = webkit_web_page_get_uri(p->webpage), + const char *uri = webkit_web_page_get_uri(p->webpage), *requri = webkit_uri_request_get_uri(req); char *domain; if (!uri || !strcmp(requri, uri) || - strncmp(uri, "http://", sizeof("http://") - 1) && - strncmp(uri, "https://", sizeof("https://") - 1)) + (strncmp(uri, "http://", sizeof("http://") - 1) && + strncmp(uri, "https://", sizeof("https://") - 1))) return FALSE; domain = strstr(uri, "://") + sizeof("://") - 1; - if (!(s = strchr(domain, '/'))) - for(s = domain; *s; ++s) ; - domain = estrndup(domain, s - domain); + domain = estrndup(domain, strcspn(domain, "/")); /* match rules */ for (r = rules; r; r = r->next) { @@ -803,6 +796,7 @@ sendrequest(WebKitWebPage *wp, WebKitURIRequest *req, printf("domain: %s\n", domain); fprintf(stderr, "blocked: %s, %s\n", domain, requri); + free(domain); return TRUE; } @@ -817,10 +811,10 @@ webpagecreated(WebKitWebExtension *e, WebKitWebPage *p, gpointer unused) { Page *np = newpage(p); - g_signal_connect(p, "send-request", - G_CALLBACK(sendrequest), np); g_signal_connect(p, "document-loaded", G_CALLBACK(documentloaded), np); + g_signal_connect(p, "send-request", + G_CALLBACK(sendrequest), np); } G_MODULE_EXPORT void