improvements, fix parse of domain - 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 6c346e74c3f8ccf71c543ef327b6f123bee908ba
 (DIR) parent ede99e9ea359312250db995e663de8ce73405f62
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Mon,  5 Jun 2017 17:56:14 +0200
       
       improvements, fix parse of domain
       
       Diffstat:
         M TODO                                |       4 ++++
         M adblock.c                           |      20 ++++++++++++++++----
         M tests/tests.c                       |       3 +++
       
       3 files changed, 23 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/TODO b/TODO
       @@ -1,3 +1,7 @@
       +- elementhiding: reverse exception rule are not supported (per domain).
       +- block rule: exception rules are not supported: these are also abused sometimes
       +  to whitelist certain sites.
       +
        - simplify match, there are only a few rules with multiple *.
        
        - loadrules: return struct rules* ?
 (DIR) diff --git a/adblock.c b/adblock.c
       @@ -252,7 +252,14 @@ escaped:
        static int
        casefold(int k)
        {
       -        int c = towupper(k);
       +        int c;
       +
       +        /* optimization: -2% last measured.
       +        if ((unsigned)k < 128) {
       +                c = toupper(k);
       +                return c == k ? tolower(k) : c;
       +        }*/
       +        c = towupper(k);
                return c == k ? towlower(k) : c;
        }
        
       @@ -777,7 +784,7 @@ getdocumentcss(const char *fromuri)
                if ((s = strstr(fromuri, "://")))
                        fromuri = s + sizeof("://") - 1;
                len = strcspn(fromuri, "/"); /* TODO: ":/" */
       -        memcpy(fromdomain, s, len);
       +        memcpy(fromdomain, fromuri, len);
                fromdomain[len] = '\0';
        
                printf("fromuri:    %s\n", fromuri);
       @@ -862,26 +869,31 @@ allowrequest(const char *fromuri, const char *requri)
                fromrel = &fromuri[strcspn(fromuri, "/")];
                reqrel = &requri[strcspn(requri, "/")];
        
       +#if 0
                printf("req %s = %s\n", requri, reqrel);
                printf("from %s = %s\n", fromuri, fromrel);
       +#endif
        
                /* DEBUG: timing */
                struct timespec tp_start, tp_end, tp_diff;
       -        if (clock_gettime(CLOCK_MONOTONIC, &tp_start) == -1) {
       +        if (clock_gettime(CLOCK_MONOTONIC, &tp_start) == -1)
                        fprintf(stderr, "clock_gettime: %s\n", strerror(errno));
       -        }
        
                /* match rules */
                for (r = rules; r; r = r->next) {
                        if (!r->css && matchrule(r, fromuri, fromdomain,
                                                 fromrel, requri, reqdomain, reqrel, "csio^")) {
       +#if 0
                                printf("reqrel:      %s\n", reqrel);
                                printf("reqdomain:   %s\n", reqdomain);
                                printf("requri:      %s\n", requri);
                                printf("from uri:    %s\n", fromuri);
                                printf("from domain: %s\n", fromdomain);
       +#endif
        
                                fprintf(stderr, "blocked: %s, %s\n", fromdomain, requri);
       +                        fprintf(stderr, "rule:    %s\n", r->uri);
       +                        fprintf(stderr, "===\n");
        
                                /* DEBUG: for showing the timing */
                                status = 0;
 (DIR) diff --git a/tests/tests.c b/tests/tests.c
       @@ -54,6 +54,9 @@ main(void)
                status = allowrequest("https://360ads.com:8000/", "https://360ads.com:8000/index.html");
                printf("%d\n", status);
        
       +        status = allowrequest("https://google.com/", "https://google.com/index.html");
       +        printf("%d\n", status);
       +
                /*http://statics.360ads.com/statics/images/2016/home/t3.png*/
        
                cleanup();