Allow metrics.torproject.org
[privoxy.git] / filters.c
index 5ef0ff1..a08dcba 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,4 +1,4 @@
-const char filters_rcs[] = "$Id: filters.c,v 1.120 2009/04/17 11:45:19 fabiankeil Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.127 2010/04/03 13:22:56 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/filters.c,v $
@@ -13,7 +13,7 @@ const char filters_rcs[] = "$Id: filters.c,v 1.120 2009/04/17 11:45:19 fabiankei
  *                   `execute_single_pcrs_command', `rewrite_url',
  *                   `get_last_url'
  *
- * Copyright   :  Written by and Copyright (C) 2001, 2004-2008 the SourceForge
+ * Copyright   :  Written by and Copyright (C) 2001, 2004-2009 the
  *                Privoxy team. http://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
@@ -119,8 +119,9 @@ static jb_err prepare_for_filtering(struct client_state *csp);
  * Returns     :  0 = no errror; -1 otherwise.
  *
  *********************************************************************/
-int sockaddr_storage_to_ip(const struct sockaddr_storage *addr, uint8_t **ip,
-      unsigned int *len, in_port_t **port)
+static int sockaddr_storage_to_ip(const struct sockaddr_storage *addr,
+                                  uint8_t **ip, unsigned int *len,
+                                  in_port_t **port)
 {
    if (NULL == addr)
    {
@@ -183,9 +184,9 @@ int sockaddr_storage_to_ip(const struct sockaddr_storage *addr, uint8_t **ip,
  * Returns     :  0 = doesn't match; 1 = does match
  *
  *********************************************************************/
-int match_sockaddr(const struct sockaddr_storage *network,
-      const struct sockaddr_storage *netmask,
-      const struct sockaddr_storage *address)
+static int match_sockaddr(const struct sockaddr_storage *network,
+                          const struct sockaddr_storage *netmask,
+                          const struct sockaddr_storage *address)
 {
    uint8_t *network_addr, *netmask_addr, *address_addr;
    unsigned int addr_len;
@@ -418,14 +419,15 @@ int acl_addr(const char *aspec, struct access_control_addr *aca)
    hints.ai_socktype = SOCK_STREAM;
 
    i = getaddrinfo(acl_spec, ((p) ? ++p : NULL), &hints, &result);
-   freez(acl_spec);
 
    if (i != 0)
    {
       log_error(LOG_LEVEL_ERROR, "Can not resolve [%s]:%s: %s",
          acl_spec, p, gai_strerror(i));
+      freez(acl_spec);
       return(-1);
    }
+   freez(acl_spec);
 
    /* TODO: Allow multihomed hostnames */
    memcpy(&(aca->addr), result->ai_addr, result->ai_addrlen);
@@ -597,7 +599,6 @@ struct http_response *block_url(struct client_state *csp)
       {
          log_error(LOG_LEVEL_ERROR, "handle-as-empty-document overruled by handle-as-image.");
       }
-#if 1 /* Two alternative strategies, use this one for now: */
 
       /* and handle accordingly: */
       if ((p == NULL) || (0 == strcmpic(p, "pattern")))
@@ -622,7 +623,6 @@ struct http_response *block_url(struct client_state *csp)
             return cgi_error_memory();
          }
       }
-
       else if (0 == strcmpic(p, "blank"))
       {
          rsp->status = strdup("403 Request blocked by Privoxy");
@@ -645,7 +645,6 @@ struct http_response *block_url(struct client_state *csp)
             return cgi_error_memory();
          }
       }
-
       else
       {
          rsp->status = strdup("302 Local Redirect from Privoxy");
@@ -662,32 +661,10 @@ struct http_response *block_url(struct client_state *csp)
          }
       }
 
-#else /* Following code is disabled for now */
-
-      /* and handle accordingly: */
-      if ((p == NULL) || (0 == strcmpic(p, "pattern")))
-      {
-         p = CGI_PREFIX "send-banner?type=pattern";
-      }
-      else if (0 == strcmpic(p, "blank"))
-      {
-         p = CGI_PREFIX "send-banner?type=blank";
-      }
-      rsp->status = strdup("302 Local Redirect from Privoxy");
-      if (rsp->status == NULL)
-      {
-         free_http_response(rsp);
-         return cgi_error_memory();
-      }
-
-      if (enlist_unique_header(rsp->headers, "Location", p))
-      {
-         free_http_response(rsp);
-         return cgi_error_memory();
-      }
-#endif /* Preceeding code is disabled for now */
    }
-   else if(csp->action->flags & ACTION_HANDLE_AS_EMPTY_DOCUMENT)
+   else
+#endif /* def FEATURE_IMAGE_BLOCKING */
+   if(csp->action->flags & ACTION_HANDLE_AS_EMPTY_DOCUMENT)
    {
      /*
       *  Send empty document.               
@@ -698,7 +675,21 @@ struct http_response *block_url(struct client_state *csp)
       rsp->body = strdup(" ");
       rsp->content_length = 1;
 
-      rsp->status = strdup("403 Request blocked by Privoxy");
+      if (csp->config->feature_flags & RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK)
+      {
+         /*
+          * Workaround for firefox bug 492459
+          *   https://bugzilla.mozilla.org/show_bug.cgi?id=492459
+          * Return a 200 OK status for pages blocked with +handle-as-empty-document
+          * if the "handle-as-empty-doc-returns-ok" runtime config option is set.
+          */
+         rsp->status = strdup("200 Request blocked by Privoxy");
+      }
+      else
+      {
+         rsp->status = strdup("403 Request blocked by Privoxy");
+      }
+
       if (rsp->status == NULL)
       {
          free_http_response(rsp);
@@ -715,7 +706,6 @@ struct http_response *block_url(struct client_state *csp)
       }
    }
    else
-#endif /* def FEATURE_IMAGE_BLOCKING */
 
    /*
     * Else, generate an HTML "blocked" message:
@@ -1769,6 +1759,12 @@ filter_function_ptr get_filter_function(struct client_state *csp)
 {
    filter_function_ptr filter_function = NULL;
 
+   if ((csp->content_type & CT_TABOO)
+      && !(csp->action->flags & ACTION_FORCE_TEXT_MODE))
+   {
+      return NULL;
+   }
+
    /*
     * Are we enabling text mode by force?
     */