Support for FEATURE_CGI_EDIT_ACTIONS
[privoxy.git] / filters.c
index 9b45604..a30a793 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,4 +1,4 @@
-const char filters_rcs[] = "$Id: filters.c,v 1.34 2001/09/20 15:49:36 steudten Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.36 2001/10/10 16:44:16 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/filters.c,v $
@@ -38,6 +38,21 @@ const char filters_rcs[] = "$Id: filters.c,v 1.34 2001/09/20 15:49:36 steudten E
  *
  * Revisions   :
  *    $Log: filters.c,v $
+ *    Revision 1.36  2001/10/10 16:44:16  oes
+ *    Added match_portlist function
+ *
+ *    Revision 1.35  2001/10/07 15:41:23  oes
+ *    Replaced 6 boolean members of csp with one bitmap (csp->flags)
+ *
+ *    New function remove_chunked_transfer_coding that strips chunked
+ *      transfer coding to plain and is called by pcrs_filter_response
+ *      and gif_deanimate_response if neccessary
+ *
+ *    Improved handling of zero-change re_filter runs
+ *
+ *    pcrs_filter_response and gif_deanimate_response now remove
+ *      chunked transfer codeing before processing the body.
+ *
  *    Revision 1.34  2001/09/20 15:49:36  steudten
  *
  *    Fix BUG: Change int size to size_t size in pcrs_filter_response().
@@ -466,6 +481,86 @@ int acl_addr(char *aspec, struct access_control_addr *aca)
 #endif /* def FEATURE_ACL */
 
 
+/*********************************************************************
+ *
+ * Function    :  match_portlist
+ *
+ * Description :  Check if a given number is covered by a comma
+ *                separated list of numbers and ranges (a,b-c,d,..)
+ *
+ * Parameters  :
+ *          1  :  portlist = String with list
+ *          2  :  port = port to check
+ *
+ * Returns     :  0 => no match
+ *                1 => match
+ *
+ *********************************************************************/
+int match_portlist(const char *portlist, int port)
+{
+   char *min, *max, *next, *portlist_copy;
+
+   min = next = portlist_copy = strdup(portlist);
+
+   /*
+    * Zero-terminate first item and remember offset for next
+    */
+   if (NULL != (next = strchr(portlist_copy, (int) ',')))
+   {
+      *next++ = '\0';
+   }
+   
+   /*
+    * Loop through all items, checking for match
+    */
+   while(min)
+   {
+      if (NULL == (max = strchr(min, (int) '-')))
+      {
+         /*
+          * No dash, check for equality
+          */
+         if (port == atoi(min))
+         {
+            free(portlist_copy);
+            return(1);
+         }
+      }
+      else
+      {
+         /*
+          * This is a range, so check if between min and max,
+          * or, if max was omitted, between min and 65K
+          */
+         *max++ = '\0';
+         if(port >= atoi(min) && port <= (atoi(max) ? atoi(max) : 65535))
+         {
+            free(portlist_copy);
+            return(1);
+         }
+           
+      }      
+
+      /*
+       * Jump to next item
+       */
+      min = next;
+
+      /*
+       * Zero-terminate next item and remember offset for n+1
+       */
+      if ((NULL != next) && (NULL != (next = strchr(next, (int) ','))))
+      {
+         *next++ = '\0';
+      }
+   }
+   
+   free(portlist_copy);
+   return 0;
+
+}
+
+
 /*********************************************************************
  *
  * Function    :  block_url
@@ -555,7 +650,19 @@ struct http_response *block_url(struct client_state *csp)
       rsp->body = template_load(csp, "blocked");
       template_fill(&rsp->body, exports);
       free_map(exports);
-  
+
+      /* FIXME */
+#ifdef __EMX__
+      /*
+       * The entire OS/2 community will hit the stupid Netscape bug
+       * (all three of us! :-) so we'll just keep ourselves out
+       * of this contentious debate and special-case ourselves.
+       * The problem is... a this point in parsing, we don't know
+       * what the csp->http->user_agent is (yet).  So we can't use
+       * it to decide if we should work around the NS bug or not.
+       */
+      rsp->status = strdup("200 Request for blocked URL"); 
+#else
       /*
        * Workaround for stupid Netscape bug which prevents
        * pages from being displayed if loading a referenced
@@ -573,7 +680,7 @@ struct http_response *block_url(struct client_state *csp)
       {
          rsp->status = strdup("404 Request for blocked URL"); 
       }
-
+#endif /* __EMX__ */
    }
 
    return(finish_http_response(rsp));