wip - surf-adblock - Surf adblock web extension
 (HTM) git clone git://git.codemadness.org/surf-adblock
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 84d3f064e393f5856f4bbbfb519b267ed4a5aa0a
 (DIR) parent b8f2056f0393290600d79f69c0ceb0ab3eb29072
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Mon,  5 Jun 2017 13:07:51 +0200
       
       wip
       
       Diffstat:
         M TODO                                |       3 +++
         M adblock.c                           |      28 +++++++---------------------
         M surf-adblock.c                      |       6 +++---
         M tests/run.sh                        |       2 --
         M tests/tests.c                       |      20 ++++++++++----------
       
       5 files changed, 23 insertions(+), 36 deletions(-)
       ---
 (DIR) diff --git a/TODO b/TODO
       @@ -1,3 +1,6 @@
       +- loadrules: return struct rules* ?
       +  on error free rules.
       +
        - optimization: for simple patterns use: strstr, strcasestr, strcmp, strcasemp
        
        - combine rules in groups: display: none: display: initial, saves memory:
 (DIR) diff --git a/adblock.c b/adblock.c
       @@ -9,6 +9,7 @@
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
       +#include <time.h> /* DEBUG: used for clock_gettime, remove later */
        #include <wchar.h>
        #include <wctype.h>
        
       @@ -27,31 +28,17 @@ struct filterdomain {
                struct filterdomain *next;
        };
        
       -struct elementhiderule {
       -        /* is exception rule: #@# */
       -        int isexception;
       -        char *css; /* if non-NULL is CSS rule / hide element rule */
       -        struct filterdomain *domains;
       -
       -        struct elementhiderule *next;
       -};
       -
       -struct blockrule {
       +struct filterrule {
                /* type: match mask, must be atleast 32-bit, see FilterType enum */
       -        unsigned long mask;
       -        /* is exception rule: prefix @@ */
       -        int isexception;
       +        unsigned long block;
                int matchbegin;
                int matchend;
       +        /* is exception rule: prefix @@ for ABP or #@# for CSS */
       +        int isexception;
       +        char *css; /* if non-NULL is CSS rule / hide element rule */
                char *uri;
                struct filterdomain *domains;
       -
       -        struct blockrule *next;
       -};
       -
       -struct rules {
       -        struct blockrule *blockrules;
       -        struct elementhiderule *elementhiderules;
       +        struct filterrule *next;
        };
        
        enum {
       @@ -702,7 +689,6 @@ loadrules(FILE *fp)
                size_t linesiz = 0;
                ssize_t n;
                int ret;
       -        struct rules *rules;
        
                /* load rules */
                while ((n = getline(&line, &linesiz, fp)) > 0) {
 (DIR) diff --git a/surf-adblock.c b/surf-adblock.c
       @@ -38,7 +38,7 @@ static void
        documentloaded(WebKitWebPage *wp, Page *p)
        {
                WebKitDOMDocument *doc = webkit_web_page_get_dom_document(wp);
       -        WebKitDOMHTMLElement *body = webkit_dom_document_get_body(doc);
       +        WebKitDOMHTMLElement *head = webkit_dom_document_get_body(doc);
                WebKitDOMElement *el;
                const char *uri = webkit_web_page_get_uri(p->webpage);
                char *css, *globalcss;
       @@ -47,7 +47,7 @@ documentloaded(WebKitWebPage *wp, Page *p)
                        el = webkit_dom_document_create_element(doc, "style", NULL);
                        webkit_dom_element_set_attribute(el, "type", "text/css", NULL);
                        webkit_dom_element_set_inner_html(el, globalcss, NULL);
       -                webkit_dom_node_append_child(WEBKIT_DOM_NODE(body),
       +                webkit_dom_node_append_child(WEBKIT_DOM_NODE(head),
                                                     WEBKIT_DOM_NODE(el), NULL);
                }
        
       @@ -55,7 +55,7 @@ documentloaded(WebKitWebPage *wp, Page *p)
                        el = webkit_dom_document_create_element(doc, "style", NULL);
                        webkit_dom_element_set_attribute(el, "type", "text/css", NULL);
                        webkit_dom_element_set_inner_html(el, css, NULL);
       -                webkit_dom_node_append_child(WEBKIT_DOM_NODE(body),
       +                webkit_dom_node_append_child(WEBKIT_DOM_NODE(head),
                                                     WEBKIT_DOM_NODE(el), NULL);
                }
        
 (DIR) diff --git a/tests/run.sh b/tests/run.sh
       @@ -1,6 +1,4 @@
        #!/bin/sh
        rm -f *.o tests
       -#cc tests.c -o tests -Wall -ggdb -O0
       -#cc tests.c -o tests -Wall -ggdb -Os
        cc tests.c -o tests -O2 -Wall
        SURF_ADBLOCK_FILE=`pwd`/rules ./tests
 (DIR) diff --git a/tests/tests.c b/tests/tests.c
       @@ -28,34 +28,34 @@ main(void)
        
                init();
        
       -        status = checkrequest("https://tweakers.net/", "https://tweakers.net/adtracker/a");
       +        status = allowrequest("https://tweakers.net/", "https://tweakers.net/adtracker/a");
                printf("%d\n", status);
        
       -        status = checkrequest("http://tweakers.net/", "http://tweakers.net/adtracker/a");
       +        status = allowrequest("http://tweakers.net/", "http://tweakers.net/adtracker/a");
                printf("%d\n", status);
        
       -        status = checkrequest("https://tweakers.net/", "https://tweakers.net/adtracker.");
       +        status = allowrequest("https://tweakers.net/", "https://tweakers.net/adtracker.");
                printf("%d\n", status);
        
       -        status = checkrequest("https://tweakers.net/", "https://tweakers.net/index.html");
       +        status = allowrequest("https://tweakers.net/", "https://tweakers.net/index.html");
                printf("%d\n", status);
        
       -        status = checkrequest("https://360ads.com/", "https://360ads.com/index.html");
       +        status = allowrequest("https://360ads.com/", "https://360ads.com/index.html");
                printf("%d\n", status);
        
       -        status = checkrequest("https://www.360ads.com/", "https://www.360ads.com/index.html");
       +        status = allowrequest("https://www.360ads.com/", "https://www.360ads.com/index.html");
                printf("%d\n", status);
        
       -        status = checkrequest("http://www.360ads.com/", "http://360ads.com/index.html");
       +        status = allowrequest("http://www.360ads.com/", "http://360ads.com/index.html");
                printf("%d\n", status);
        
       -        status = checkrequest("https://360ads.com:8000/", "https://360ads.com/index.html");
       +        status = allowrequest("https://360ads.com:8000/", "https://360ads.com/index.html");
                printf("%d\n", status);
        
       -        status = checkrequest("https://360ads.com/", "https://360ads.com:8000/index.html");
       +        status = allowrequest("https://360ads.com/", "https://360ads.com:8000/index.html");
                printf("%d\n", status);
        
       -        status = checkrequest("https://360ads.com:8000/", "https://360ads.com:8000/index.html");
       +        status = allowrequest("https://360ads.com:8000/", "https://360ads.com:8000/index.html");
                printf("%d\n", status);
        
                /*http://statics.360ads.com/statics/images/2016/home/t3.png*/