Indentation, CRLF->LF, Tab-> Space
[privoxy.git] / filters.c
index 3586be0..129efbf 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,4 +1,4 @@
-const char filters_rcs[] = "$Id: filters.c,v 1.17 2001/06/09 10:55:28 jongfoster Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.18 2001/06/29 13:27:38 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/filters.c,v $
@@ -38,6 +38,32 @@ const char filters_rcs[] = "$Id: filters.c,v 1.17 2001/06/09 10:55:28 jongfoster
  *
  * Revisions   :
  *    $Log: filters.c,v $
+ *    Revision 1.18  2001/06/29 13:27:38  oes
+ *    - Cleaned up, renamed and reorderd functions
+ *      and improved comments
+ *
+ *    - block_url:
+ *      - Ported to CGI platform. Now delivers
+ *        http_response or NULL
+ *      - Unified HTML and GIF generation (moved image detection
+ *        and GIF generation here from jcc.c:chat())
+ *      - Fixed HTTP status to:
+ *       -  403 (Forbidden) for the "blocked" HTML message
+ *       -  200 (OK) for GIF answers
+ *       -  302 (Redirect) for redirect to GIF
+ *
+ *    - trust_url:
+ *      - Ported to CGI platform. Now delivers
+ *        http_response or NULL
+ *      - Separated detection of untrusted URL into
+ *        (bool)is_untrusted_url
+ *      - Added enforcement of untrusted requests
+ *
+ *    - Moved redirect_url() from cgi.c to here
+ *      and ported it to the CGI platform
+ *
+ *    - Removed logentry from cancelled commit
+ *
  *    Revision 1.17  2001/06/09 10:55:28  jongfoster
  *    Changing BUFSIZ ==> BUFFER_SIZE
  *
@@ -251,8 +277,7 @@ const char filters_h_rcs[] = FILTERS_H_VERSION;
  * Returns     : 0 = FALSE (don't block) and 1 = TRUE (do block)
  *
  *********************************************************************/
-int block_acl(struct access_control_addr *dst,
-              struct client_state *csp)
+int block_acl(struct access_control_addr *dst, struct client_state *csp)
 {
    struct access_control_list *acl = csp->config->acl;
 
@@ -387,7 +412,7 @@ int acl_addr(char *aspec, struct access_control_addr *aca)
 struct http_response *block_url(struct client_state *csp)
 {
    char *p;
-       struct http_response *rsp;
+   struct http_response *rsp;
    struct map *exports = NULL;
 
    /* 
@@ -411,10 +436,10 @@ struct http_response *block_url(struct client_state *csp)
     * as specified by the relevant +image action
     */
 #ifdef IMAGE_BLOCKING
-       if (((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
+   if (((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
         && is_imageurl(csp))
-       {
-          /* determine HOW images should be blocked */
+   {
+      /* determine HOW images should be blocked */
       p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
 
       /* and handle accordingly: */
@@ -446,7 +471,7 @@ struct http_response *block_url(struct client_state *csp)
     */
    {
 
-          exports = default_exports(csp, NULL);           
+      exports = default_exports(csp, NULL);       
 #ifdef FORCE_LOAD
       exports = map(exports, "force-prefix", 1, FORCE_PREFIX, 1);
 #else
@@ -495,7 +520,7 @@ struct http_response *trust_url(struct client_state *csp)
     */
    if (!is_untrusted_url(csp))
    {
-     return NULL;
+      return NULL;
    }
 
    /* 
@@ -509,7 +534,7 @@ struct http_response *trust_url(struct client_state *csp)
 
    /* 
     * Export the host, port, and referrer information
-        */
+    */
    exports = map(exports, "hostport", 1, csp->http->hostport, 1);
    exports = map(exports, "path", 1, csp->http->path, 1);
    exports = map(exports, "hostport-html", 1, html_encode(csp->http->hostport), 0);
@@ -546,25 +571,23 @@ struct http_response *trust_url(struct client_state *csp)
 
       for (l = csp->config->trust_info->next; 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);
          p = strsav(p, buf);
       }
       exports = map(exports, "trust-info", 1, p, 0);
    }
    else
-       {
-          exports = map_block_killer(exports, "have-trust-info");
-       }
+   {
+      exports = map_block_killer(exports, "have-trust-info");
+   }
    
    /*
     * Export the force prefix or the force conditional block killer
     */
 #ifdef FORCE_LOAD
-      exports = map(exports, "force-prefix", 1, FORCE_PREFIX, 1);
+   exports = map(exports, "force-prefix", 1, FORCE_PREFIX, 1);
 #else
-      exports = map_block_killer(exports, "force-support");
+   exports = map_block_killer(exports, "force-support");
 #endif /* ndef FORCE_LOAD */
 
    /*
@@ -744,7 +767,7 @@ int is_untrusted_url(struct client_state *csp)
    if ((csp->referrer == NULL)|| (strlen(csp->referrer) <= 9))
    {
       /* no referrer was supplied */
-          return(1);
+      return(1);
    }
 
    /* forge a URL from the referrer so we can use
@@ -919,6 +942,7 @@ void url_actions(struct http_request *http,
    }
 
    apply_url_actions(csp->action, http, b);
+
 }
 
 
@@ -1069,12 +1093,13 @@ struct url_spec dsplit(char *domain)
 
    if (domain[strlen(domain) - 1] == '.')
    {
-         ret->unanchored |= ANCHOR_RIGHT;
-       }
-       if (domain[0] == '.')
+      ret->unanchored |= ANCHOR_RIGHT;
+   }
+
+   if (domain[0] == '.')
    {
-         ret->unanchored |= ANCHOR_LEFT;
-       }
+      ret->unanchored |= ANCHOR_LEFT;
+   }
 
    ret->dbuf = strdup(domain);
 
@@ -1098,7 +1123,6 @@ struct url_spec dsplit(char *domain)
       memcpy(ret->dvec, v, size);
    }
 
-
    return(*ret);
 
 }
@@ -1136,6 +1160,7 @@ static int simple_domaincmp(char **pv, char **fv, int len)
    }
 
    return 0;
+
 }
 
 
@@ -1218,8 +1243,8 @@ int domaincmp(struct url_spec *pattern, struct url_spec *fqdn)
       }
       return 1;
    }
-}
 
+}
 
 
 /*