Re: Fwd: Bug#642391: dillo: sane default for http redirects [origin: [email protected]]

"corvid" <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <20110923053216.GG20052@local>
Axel wrote:
> there's probably
> need for an at least a little bit more fine grained redirect/image
> blocking configuration.

Here's some code that experiments with letting you list a
bunch of filter_auto_requests options in dillorc (same_domain,
allow_redirect, allow_image, allow_stylesheet, allow_all),
somewhat similar to search_url. Or we could turn it into
three boolean preferences. Whatever.

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
finer_filter.patch (text/plain, 4.6 KB)
diff -r 538f207b9077 src/capi.c
--- a/src/capi.c	Wed Sep 21 19:34:48 2011 +0200
+++ b/src/capi.c	Fri Sep 23 05:19:42 2011 +0000
@@ -373,7 +373,7 @@
  * by the user.
  */
 static bool_t Capi_filters_test(const DilloUrl *wanted,
-                                const DilloUrl *requester)
+                                const DilloUrl *requester, int flags)
 {
    bool_t ret;
 
@@ -381,30 +381,36 @@
       /* request made by user */
       ret = TRUE;
    } else {
-      switch (prefs.filter_auto_requests) {
-         case PREFS_FILTER_SAME_DOMAIN:
-         {
-            const char *req_host = URL_HOST(requester),
-                       *want_host = URL_HOST(wanted);
-            if (want_host[0] == '\0') {
-               ret = (req_host[0] == '\0' ||
-                      !dStrcasecmp(URL_SCHEME(wanted), "data")) ? TRUE : FALSE;
-            } else {
-               /* This will regard "www.dillo.org" and "www.dillo.org." as
-                * different, but it doesn't seem worth caring about.
-                */
-               ret = a_Url_same_organization(wanted, requester);
-            }
-            if (ret == FALSE) {
-               MSG("Capi_filters_test: deny from '%s' to '%s'\n", req_host,
-                   want_host);
-            }
-            break;
-         }
-         case PREFS_FILTER_ALLOW_ALL:
-         default:
-            ret = TRUE;
-            break;
+      switch (flags) {
+      case WEB_RootUrl:
+         ret = prefs.filter_auto_requests & PREFS_FILTER_ALLOW_REDIRECT;
+         break;
+      case WEB_Image:
+         ret = prefs.filter_auto_requests & PREFS_FILTER_ALLOW_IMAGE;
+         break;
+      case 0:
+         ret = prefs.filter_auto_requests & PREFS_FILTER_ALLOW_STYLESHEET;
+         break;
+      default:
+         MSG_ERR("Capi_filters_test: unexpected flags %d\n", flags);
+         ret = FALSE;
+      }
+   }
+   if (!ret) {
+      const char *req_host = URL_HOST(requester),
+                 *want_host = URL_HOST(wanted);
+      if (want_host[0] == '\0') {
+         ret = (req_host[0] == '\0' ||
+                !dStrcasecmp(URL_SCHEME(wanted), "data")) ? TRUE : FALSE;
+      } else {
+         /* This will regard "www.dillo.org" and "www.dillo.org." as
+          * different, but it doesn't seem worth caring about.
+          */
+         ret = a_Url_same_organization(wanted, requester);
+      }
+      if (ret == FALSE) {
+         MSG("Capi_filters_test: deny from '%s' to '%s'\n", req_host,
+             want_host);
       }
    }
    return ret;
@@ -427,8 +433,8 @@
    int safe = 0, ret = 0, use_cache = 0;
 
    dReturn_val_if_fail((a_Capi_get_flags(web->url) & CAPI_IsCached) ||
-                       Capi_filters_test(web->url, web->requester), 0);
-
+                       Capi_filters_test(web->url, web->requester, web->flags),
+                       0);
    /* reload test */
    reload = (!(a_Capi_get_flags(web->url) & CAPI_IsCached) ||
              (URL_FLAGS(web->url) & URL_E2EQuery));
diff -r 538f207b9077 src/prefs.h
--- a/src/prefs.h	Wed Sep 21 19:34:48 2011 +0200
+++ b/src/prefs.h	Fri Sep 23 05:19:42 2011 +0000
@@ -26,8 +26,11 @@
 /* Panel sizes */
 enum { P_tiny = 0, P_small, P_medium };
 
-enum {PREFS_FILTER_ALLOW_ALL,
-      PREFS_FILTER_SAME_DOMAIN};
+enum {PREFS_FILTER_SAME_DOMAIN        = 0,
+      PREFS_FILTER_ALLOW_REDIRECT     = 1,
+      PREFS_FILTER_ALLOW_IMAGE        = 2,
+      PREFS_FILTER_ALLOW_STYLESHEET   = 4,
+      PREFS_FILTER_ALLOW_ALL          = 7};
 
 typedef struct _DilloPrefs DilloPrefs;
 
diff -r 538f207b9077 src/prefsparser.cc
--- a/src/prefsparser.cc	Wed Sep 21 19:34:48 2011 +0200
+++ b/src/prefsparser.cc	Fri Sep 23 05:19:42 2011 +0000
@@ -169,11 +169,17 @@
    case PREFS_FILTER:
       if (!dStrcasecmp(value, "same_domain"))
          prefs.filter_auto_requests = PREFS_FILTER_SAME_DOMAIN;
-      else {
-         if (dStrcasecmp(value, "allow_all"))
-            MSG_WARN("prefs: unrecognized value for filter_auto_requests\n");
+      else if (!dStrcasecmp(value, "allow_all"))
          prefs.filter_auto_requests = PREFS_FILTER_ALLOW_ALL;
-      }
+      else if (!dStrcasecmp(value, "allow_redirect"))
+         prefs.filter_auto_requests |= PREFS_FILTER_ALLOW_REDIRECT;
+      else if (!dStrcasecmp(value, "allow_image"))
+         prefs.filter_auto_requests |= PREFS_FILTER_ALLOW_IMAGE;
+      else if (!dStrcasecmp(value, "allow_stylesheet"))
+         prefs.filter_auto_requests |= PREFS_FILTER_ALLOW_STYLESHEET;
+      else
+         MSG_WARN("prefs: unrecognized value '%s'for filter_auto_requests\n",
+                  value);
       break;
    case PREFS_PANEL_SIZE:
       if (!dStrcasecmp(value, "tiny"))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.