Don't leak csp->http->host_ip_addr_str when calling rfc2553_connect_to() multiple...
[privoxy.git] / parsers.c
index e2a70ea..940f45c 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.213 2010/06/13 12:26:04 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.218 2011/02/14 16:11:34 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -1956,7 +1956,7 @@ static jb_err crunch_server_header(struct client_state *csp, char **header)
  * Function    :  server_content_type
  *
  * Description :  Set the content-type for filterable types (text/.*,
- *                .*xml.*, javascript and image/gif) unless filtering has been
+ *                .*xml.*, .*script.* and image/gif) unless filtering has been
  *                forbidden (CT_TABOO) while parsing earlier headers.
  *                NOTE: Since text/plain is commonly used by web servers
  *                      for files whose correct type is unknown, we don't
@@ -2006,7 +2006,7 @@ static jb_err server_content_type(struct client_state *csp, char **header)
        */
       if ((strstr(*header, "text/") && !strstr(*header, "plain"))
         || strstr(*header, "xml")
-        || strstr(*header, "application/x-javascript"))
+        || strstr(*header, "script"))
       {
          csp->content_type |= CT_TEXT;
       }
@@ -2127,6 +2127,12 @@ static jb_err server_transfer_coding(struct client_state *csp, char **header)
  *                The second run is used to remove the Content-Encoding
  *                header if the decompression was successful.
  *
+ *                XXX: Doesn't properly deal with multiple or with
+ *                     unsupported but unknown encodings.
+ *                     Is case-sensitive but shouldn't be.
+ *                     The second run should be factored out into
+ *                     a different function.
+ *
  * Parameters  :
  *          1  :  csp = Current client state (buffers, headers, etc...)
  *          2  :  header = On input, pointer to header to modify.
@@ -2155,6 +2161,26 @@ static jb_err server_content_encoding(struct client_state *csp, char **header)
       log_error(LOG_LEVEL_HEADER, "Crunching: %s", *header);
       freez(*header);
    }
+   else if (strstr(*header, "sdch"))
+   {
+      /*
+       * Shared Dictionary Compression over HTTP isn't supported,
+       * filtering it anyway is pretty much guaranteed to mess up
+       * the encoding.
+       */
+      csp->content_type |= CT_TABOO;
+
+      /*
+       * Log a warning if the user expects the content to be filtered.
+       */
+      if ((csp->rlist != NULL) &&
+         (!list_is_empty(csp->action->multi[ACTION_MULTI_FILTER])))
+      {
+         log_error(LOG_LEVEL_INFO,
+            "SDCH-compressed content detected, content filtering disabled. "
+            "Consider suppressing SDCH offers made by the client.");
+      }
+   }
    else if (strstr(*header, "gzip"))
    {
       /* Mark for gzip decompression */
@@ -2174,7 +2200,16 @@ static jb_err server_content_encoding(struct client_state *csp, char **header)
       csp->content_type |= CT_TABOO;
    }
 #else /* !defined(FEATURE_ZLIB) */
-   if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
+   /*
+    * XXX: Using a black list here isn't the right approach.
+    *
+    *      In case of SDCH, building with zlib support isn't
+    *      going to help.
+    */
+   if (strstr(*header, "gzip") ||
+       strstr(*header, "compress") ||
+       strstr(*header, "deflate") ||
+       strstr(*header, "sdch"))
    {
       /*
        * Body is compressed, turn off pcrs and gif filtering.
@@ -2394,14 +2429,9 @@ static jb_err server_last_modified(struct client_state *csp, char **header)
 {
    const char *newval;
    char buf[BUFFER_SIZE];
-
+   time_t last_modified;
    char newheader[50];
-#ifdef HAVE_GMTIME_R
-   struct tm gmt;
-#endif
-   struct tm *timeptr = NULL;
-   time_t now, last_modified;                  
-   
+
    /*
     * Are we messing with the Last-Modified header?
     */
@@ -2446,16 +2476,7 @@ static jb_err server_last_modified(struct client_state *csp, char **header)
       const char *header_time = *header + sizeof("Last-Modified:");
 
       log_error(LOG_LEVEL_HEADER, "Randomizing: %s", *header);
-      now = time(NULL);
-#ifdef HAVE_GMTIME_R
-      gmtime_r(&now, &gmt);
-#elif defined(MUTEX_LOCKS_AVAILABLE)
-      privoxy_mutex_lock(&gmtime_mutex);
-      gmtime(&now);
-      privoxy_mutex_unlock(&gmtime_mutex);
-#else
-      gmtime(&now);
-#endif
+
       if (JB_ERR_OK != parse_header_time(header_time, &last_modified))
       {
          log_error(LOG_LEVEL_HEADER, "Couldn't parse: %s in %s (crunching!)", header_time, *header);
@@ -2463,7 +2484,14 @@ static jb_err server_last_modified(struct client_state *csp, char **header)
       }
       else
       {
-         long int rtime = (long int)difftime(now, last_modified);
+         time_t now;
+         struct tm *timeptr = NULL;
+         long int rtime;
+#ifdef HAVE_GMTIME_R
+         struct tm gmt;
+#endif
+         now = time(NULL);
+         rtime = (long int)difftime(now, last_modified);
          if (rtime)
          {
             long int days, hours, minutes, seconds;
@@ -2554,22 +2582,7 @@ static jb_err client_accept_encoding(struct client_state *csp, char **header)
    if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
    {
       log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress content");
-
       freez(*header);
-
-      /* Temporarily disable the correct behaviour to
-       * work around a PHP bug. 
-       *
-       * if (!strcmpic(csp->http->ver, "HTTP/1.1"))
-       * {
-       *    *header = strdup("Accept-Encoding: identity;q=1.0, *;q=0");
-       *    if (*header == NULL)
-       *    {
-       *       return JB_ERR_MEMORY;
-       *    }
-       * }
-       * 
-       */
    }
 
    return JB_ERR_OK;
@@ -4159,7 +4172,7 @@ static jb_err handle_conditional_hide_referrer_parameter(char **header,
    const char *host, const int parameter_conditional_block)
 {
    char *referer = strdup(*header);
-   const size_t hostlenght = strlen(host);
+   const size_t hostlength = strlen(host);
    const char *referer_url = NULL;
 
    if (NULL == referer)
@@ -4169,14 +4182,14 @@ static jb_err handle_conditional_hide_referrer_parameter(char **header,
    }
 
    /* referer begins with 'Referer: http[s]://' */
-   if ((hostlenght+17) < strlen(referer))
+   if ((hostlength+17) < strlen(referer))
    {
       /*
        * Shorten referer to make sure the referer is blocked
        * if www.example.org/www.example.com-shall-see-the-referer/
        * links to www.example.com/
        */
-      referer[hostlenght+17] = '\0';
+      referer[hostlength+17] = '\0';
    }
    referer_url = strstr(referer, "http://");
    if ((NULL == referer_url) || (NULL == strstr(referer_url, host)))