- Assorted refinements, optimizations and fixes in the js-annoyances,
[privoxy.git] / filters.c
index c63c477..31ee85e 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,4 +1,4 @@
-const char filters_rcs[] = "$Id: filters.c,v 1.58 2002/04/24 02:11:17 oes Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.58.2.3 2002/09/25 14:51:51 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/Attic/filters.c,v $
@@ -38,6 +38,20 @@ const char filters_rcs[] = "$Id: filters.c,v 1.58 2002/04/24 02:11:17 oes Exp $"
  *
  * Revisions   :
  *    $Log: filters.c,v $
+ *    Revision 1.58.2.3  2002/09/25 14:51:51  oes
+ *    Added basic support for OPTIONS and TRACE HTTP methods:
+ *    New function direct_response which handles OPTIONS and
+ *    TRACE requests whose Max-Forwards header field is zero.
+ *
+ *    Revision 1.58.2.2  2002/08/01 17:18:28  oes
+ *    Fixed BR 537651 / SR 579724 (MSIE image detect improper for IE/Mac)
+ *
+ *    Revision 1.58.2.1  2002/07/26 15:18:53  oes
+ *    - Bugfix: Executing a filters without jobs no longer results in
+ *      turing off *all* filters.
+ *    - Security fix: Malicious web servers can't cause a seg fault
+ *      through bogus chunk sizes anymore
+ *
  *    Revision 1.58  2002/04/24 02:11:17  oes
  *    Jon's multiple AF patch: url_actions now evaluates rules
  *    from all AFs.
@@ -1078,8 +1092,9 @@ struct http_response *redirect_url(struct client_state *csp)
  *
  * Description :  Given a URL, decide whether it is an image or not,
  *                using either the info from a previous +image action
- *                or, #ifdef FEATURE_IMAGE_DETECT_MSIE, the info from
- *                the browser's accept header.
+ *                or, #ifdef FEATURE_IMAGE_DETECT_MSIE, and the browser
+ *                is MSIE and not on a Mac, tell from the browser's accept
+ *                header.
  *
  * Parameters  :
  *          1  :  csp = Current client state (buffers, headers, etc...)
@@ -1094,7 +1109,7 @@ int is_imageurl(struct client_state *csp)
    char *tmp;
 
    tmp = get_header_value(csp->headers, "User-Agent:");
-   if (tmp && strstr(tmp, "MSIE"))
+   if (tmp && strstr(tmp, "MSIE") && !strstr(tmp, "Mac_"))
    {
       tmp = get_header_value(csp->headers, "Accept:");
       if (tmp && strstr(tmp, "image/gif"))
@@ -1243,7 +1258,7 @@ int is_untrusted_url(struct client_state *csp)
  *
  * Function    :  pcrs_filter_response
  *
- * Description :  Ecexute all text substitutions from all applying
+ * Description :  Execute all text substitutions from all applying
  *                +filter actions on the text buffer that's been accumulated
  *                in csp->iob->buf. If this changes the contents, set
  *                csp->content_length to the modified size and raise the
@@ -1599,6 +1614,63 @@ const struct forward_spec * forward_url(struct http_request *http,
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  direct_response 
+ *
+ * Description :  Check if Max-Forwards == 0 for an OPTIONS or TRACE
+ *                request and if so, return a HTTP 501 to the client.
+ *
+ *                FIXME: I have a stupid name and I should handle the
+ *                requests properly. Still, what we do here is rfc-
+ *                compliant, whereas ignoring or forwarding are not.
+ *
+ * Parameters  :  
+ *          1  :  csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns     :  http_response if , NULL if nonmatch or handler fail
+ *
+ *********************************************************************/
+struct http_response *direct_response(struct client_state *csp)
+{
+   struct http_response *rsp;
+   struct list_entry *p;
+
+   if ((0 == strcmpic(csp->http->gpc, "trace"))
+      || (0 == strcmpic(csp->http->gpc, "options")))
+   {
+      for (p = csp->headers->first; (p != NULL) ; p = p->next)
+      {
+         if (!strncmp("Max-Forwards:", p->str, 13)
+             && (*(p->str+13) != '\0') && (atoi(p->str+13) == 0))
+         {
+            /* FIXME: We could handle at least TRACE here,
+               but that would require a verbatim copy of
+               the request which we don't have anymore */
+
+            log_error(LOG_LEVEL_HEADER, "Found Max-Forwards:0 in OPTIONS or TRACE request -- Returning 501");
+
+            /* Get mem for response or fail*/
+            if (NULL == (rsp = alloc_http_response()))
+            {
+               return cgi_error_memory();
+            }
+            
+            if (NULL == (rsp->status = strdup("501 Not Implemented")))
+            {
+               free_http_response(rsp);
+               return cgi_error_memory();
+            }
+
+            rsp->is_static = 1;
+            return(finish_http_response(rsp));
+         }
+      }
+   }
+   return NULL;
+}
+
+
 /*
   Local Variables:
   tab-width: 3