A quick catch up.
[privoxy.git] / filters.c
index a1dc75f..ff70ac5 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,4 +1,4 @@
-const char filters_rcs[] = "$Id: filters.c,v 1.46 2002/03/12 01:42:49 oes Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.57 2002/04/08 20:38:34 swa Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/filters.c,v $
@@ -12,7 +12,7 @@ const char filters_rcs[] = "$Id: filters.c,v 1.46 2002/03/12 01:42:49 oes Exp $"
  *                   'ijb_send_banner', and `trust_url'
  *
  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
- *                IJBSWA team.  http://ijbswa.sourceforge.net
+ *                Privoxy team. http://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
  *                by and Copyright (C) 1997 Anonymous Coders and
@@ -38,6 +38,42 @@ const char filters_rcs[] = "$Id: filters.c,v 1.46 2002/03/12 01:42:49 oes Exp $"
  *
  * Revisions   :
  *    $Log: filters.c,v $
+ *    Revision 1.57  2002/04/08 20:38:34  swa
+ *    fixed JB spelling
+ *
+ *    Revision 1.56  2002/04/05 15:51:24  oes
+ *     - bugfix: error-pages now get correct request protocol
+ *     - fix for invalid HTML in trust info
+ *
+ *    Revision 1.55  2002/04/02 16:13:51  oes
+ *    Fix: No "Go there anyway" for SSL
+ *
+ *    Revision 1.54  2002/04/02 14:55:56  oes
+ *    Bugfix: is_untrusted_url() now depends on FEATURE_TRUST, not FEATURE_COOKIE_JAR
+ *
+ *    Revision 1.53  2002/03/26 22:29:54  swa
+ *    we have a new homepage!
+ *
+ *    Revision 1.52  2002/03/24 16:35:57  jongfoster
+ *    Removing logo
+ *
+ *    Revision 1.51  2002/03/24 15:23:33  jongfoster
+ *    Name changes
+ *
+ *    Revision 1.50  2002/03/24 13:25:43  swa
+ *    name change related issues
+ *
+ *    Revision 1.49  2002/03/16 20:29:14  oes
+ *    Cosmetics
+ *
+ *    Revision 1.48  2002/03/13 20:25:34  oes
+ *    Better logging for content filters
+ *
+ *    Revision 1.47  2002/03/13 00:30:52  jongfoster
+ *    Killing warnings
+ *    Added option of always sending redirect for imageblock,
+ *    currently disabled with #if 0.
+ *
  *    Revision 1.46  2002/03/12 01:42:49  oes
  *    Introduced modular filters
  *
@@ -337,7 +373,7 @@ const char filters_rcs[] = "$Id: filters.c,v 1.46 2002/03/12 01:42:49 oes Exp $"
  *      a lot! ;-)
  *
  *    Revision 1.3  2001/05/20 16:44:47  jongfoster
- *    Removing last hardcoded JunkBusters.com URLs.
+ *    Removing last hardcoded Junkbusters.com URLs.
  *
  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
  *    Version 2.9.4 checkin.
@@ -676,15 +712,15 @@ struct http_response *block_url(struct client_state *csp)
 #if 1 /* Two alternative strategies, use this one for now: */
 
       /* and handle accordingly: */
-      if ((p == NULL) || (0 == strcmpic(p, "logo")))
+      if ((p == NULL) || (0 == strcmpic(p, "pattern")))
       {
-         rsp->body = bindup(image_logo_data, image_logo_length);
+         rsp->body = bindup(image_pattern_data, image_pattern_length);
          if (rsp->body == NULL)
          {
             free_http_response(rsp);
             return cgi_error_memory();
          }
-         rsp->content_length = image_logo_length;
+         rsp->content_length = image_pattern_length;
 
          if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE))
          {
@@ -710,26 +746,9 @@ struct http_response *block_url(struct client_state *csp)
          }
       }
 
-      else if (0 == strcmpic(p, "pattern"))
-      {
-         rsp->body = bindup(image_pattern_data, image_pattern_length);
-         if (rsp->body == NULL)
-         {
-            free_http_response(rsp);
-            return cgi_error_memory();
-         }
-         rsp->content_length = image_pattern_length;
-
-         if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE))
-         {
-            free_http_response(rsp);
-            return cgi_error_memory();
-         }
-      }
-
       else
       {
-         rsp->status = strdup("302 Local Redirect from Junkbuster");
+         rsp->status = strdup("302 Local Redirect from Privoxy");
          if (rsp->status == NULL)
          {
             free_http_response(rsp);
@@ -746,19 +765,15 @@ 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, "logo")))
+      if ((p == NULL) || (0 == strcmpic(p, "pattern")))
       {
-         p = CGI_PREFIX "send-banner?type=logo";
+         p = CGI_PREFIX "send-banner?type=pattern";
       }
       else if (0 == strcmpic(p, "blank"))
       {
          p = CGI_PREFIX "send-banner?type=blank";
       }
-      else if (0 == strcmpic(p, "pattern"))
-      {
-         p = CGI_PREFIX "send-banner?type=pattern";
-      }
-      rsp->status = strdup("302 Local Redirect from Junkbuster");
+      rsp->status = strdup("302 Local Redirect from Privoxy");
       if (rsp->status == NULL)
       {
          free_http_response(rsp);
@@ -816,10 +831,13 @@ struct http_response *block_url(struct client_state *csp)
 
 #ifdef FEATURE_FORCE_LOAD
       err = map(exports, "force-prefix", 1, FORCE_PREFIX, 1);
-#else /* ifndef FEATURE_FORCE_LOAD */
-      err = map_block_killer(exports, "force-support");
+      if (csp->http->ssl != 0)
 #endif /* ndef FEATURE_FORCE_LOAD */
+      {
+         err = map_block_killer(exports, "force-support");
+      }
 
+      if (!err) err = map(exports, "protocol", 1, csp->http->ssl ? "https://" : "http://", 1);
       if (!err) err = map(exports, "hostport", 1, html_encode(csp->http->hostport), 0);
       if (!err) err = map(exports, "path", 1, html_encode(csp->http->path), 0);
 
@@ -891,9 +909,10 @@ struct http_response *trust_url(struct client_state *csp)
    }
 
    /*
-    * Export the host, port, and referrer information
+    * Export the protocol, host, port, and referrer information
     */
    err = map(exports, "hostport", 1, csp->http->hostport, 1);
+   if (!err) err = map(exports, "protocol", 1, csp->http->ssl ? "https://" : "http://", 1); 
    if (!err) err = map(exports, "path", 1, csp->http->path, 1);
 
    if (NULL != (p = get_header_value(csp->headers, "Referer:")))
@@ -940,7 +959,7 @@ struct http_response *trust_url(struct client_state *csp)
       p = strdup("");
       for (l = csp->config->trust_info->first; l ; l = l->next)
       {
-         sprintf(buf, "<li> <a href=%s>%s</a><br>\n",l->str, l->str);
+         sprintf(buf, "<li> <a href=\"%s\">%s</a><br>\n",l->str, l->str);
          string_append(&p, buf);
       }
       err = map(exports, "trust-info", 1, p, 0);
@@ -1031,7 +1050,7 @@ struct http_response *redirect_url(struct client_state *csp)
       }
 
       if ( enlist_unique_header(rsp->headers, "Location", q)
-        || (NULL == (rsp->status = strdup("302 Local Redirect from Junkbuster"))) )
+        || (NULL == (rsp->status = strdup("302 Local Redirect from Privoxy"))) )
       {
          free_http_response(rsp);
          return cgi_error_memory();
@@ -1094,7 +1113,7 @@ int is_imageurl(struct client_state *csp)
 #endif /* def FEATURE_IMAGE_BLOCKING */
 
 
-#ifdef FEATURE_COOKIE_JAR
+#ifdef FEATURE_TRUST
 /*********************************************************************
  *
  * Function    :  is_untrusted_url
@@ -1148,15 +1167,10 @@ int is_untrusted_url(struct client_state *csp)
       return 1;
    }
 
-   /*
-    * If not, do we maybe trust its referrer?
-    */
-
 
    /*
-    * Parse the URL from the referrer
+    * If not, do we maybe trust its referrer?
     */
-
    err = parse_http_url(referer, rhttp, csp);
    if (err)
    {
@@ -1218,7 +1232,7 @@ int is_untrusted_url(struct client_state *csp)
    }
    return 1;
 }
-#endif /* def FEATURE_COOKIE_JAR */
+#endif /* def FEATURE_TRUST */
 
 
 /*********************************************************************
@@ -1290,26 +1304,29 @@ char *pcrs_filter_response(struct client_state *csp)
       for (filtername = csp->action->multi[ACTION_MULTI_FILTER]->first;
            filtername ; filtername = filtername->next)
       {
-         if (strcmp(b->filtername, filtername->str) == 0)
+         if (strcmp(b->name, filtername->str) == 0)
          {
+            int current_hits = 0;
+
             if ( NULL == b->joblist )
             {
-               log_error(LOG_LEVEL_RE_FILTER, "Filter %s has empty joblist. Nothing to do.", b->filtername);
+               log_error(LOG_LEVEL_RE_FILTER, "Filter %s has empty joblist. Nothing to do.", b->name);
                return(NULL);
             }
 
             log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) with filter %s...",
-                      csp->http->hostport, csp->http->path, size, b->filtername);
+                      csp->http->hostport, csp->http->path, size, b->name);
 
             /* Apply all jobs from the joblist */
             for (job = b->joblist; NULL != job; job = job->next)
             {
-               hits += pcrs_execute(job, old, size, &new, &size);
+               current_hits += pcrs_execute(job, old, size, &new, &size);
                if (old != csp->iob->cur) free(old);
                old=new;
             }
 
-            log_error(LOG_LEVEL_RE_FILTER, " ...produced %d hits (new size %d).", hits, size);
+            log_error(LOG_LEVEL_RE_FILTER, " ...produced %d hits (new size %d).", current_hits, size);
+            hits += current_hits;
          }
       }
    }
@@ -1388,7 +1405,14 @@ char *gif_deanimate_response(struct client_state *csp)
    }
    else
    {
-      log_error(LOG_LEVEL_DEANIMATE, "Success! GIF shrunk from %d bytes to %d.", size, out->offset);
+      if ((int)size == out->offset)
+      {
+         log_error(LOG_LEVEL_DEANIMATE, "GIF not changed.");
+      }
+      else
+      {
+         log_error(LOG_LEVEL_DEANIMATE, "Success! GIF shrunk from %d bytes to %d.", size, out->offset);
+      }
       csp->content_length = out->offset;
       csp->flags |= CSP_FLAG_MODIFIED;
       p = out->buffer;
@@ -1477,16 +1501,21 @@ void url_actions(struct http_request *http,
 {
    struct file_list *fl;
    struct url_actions *b;
+   int i;
 
    init_current_action(csp->action);
 
-   if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
+   for (i = 0; i < MAX_ACTION_FILES; i++)
    {
-      return;
-   }
+      if (((fl = csp->actions_list[i]) == NULL) || ((b = fl->f) == NULL))
+      {
+         return;
+      }
 
-   apply_url_actions(csp->action, http, b);
+      apply_url_actions(csp->action, http, b);
+   }
 
+   return;
 }