merge Debian changes from 3.0.7 to 3.0.10
[privoxy.git] / debian / patches / 03_ipv6.dpatch
index 853c573..08f6996 100755 (executable)
@@ -5,6 +5,11 @@
 ## DP: privoxy_CVS_20030523_ipv6_5.patch.bz2 from
 ## DP: ftp://ftp.deepspace6.net/pub/ds6/sources/privoxy/privoxy_CVS_20030523_ipv6_5.patch.bz2
 ## DP: adapted to the 3.0 branch of privoxy by Roland Rosenfeld
+## DP: adapted to 3.0.4 by higuita, but i'm no programmer, so i hope i 
+## DP: didnt broke anything :)
+## DP: adapted to 3.0.6 by Petr Písa?? petrp@users.sf.net found on
+## DP: http://xpisar.wz.cz/privoxy-ipv6/ Use privoxy-3.0.6-stable-ipv6.diff.bz2
+## DP: and stripped
 
 @DPATCH@
 diff -urNad privoxy~/GNUmakefile.in privoxy/GNUmakefile.in
@@ -303,7 +308,7 @@ diff -urNad privoxy~/cgi.c privoxy/cgi.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and 
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -2167,7 +2170,6 @@
+@@ -2259,7 +2262,6 @@
   *********************************************************************/
  struct map *default_exports(const struct client_state *csp, const char *caller)
  {
@@ -311,20 +316,20 @@ diff -urNad privoxy~/cgi.c privoxy/cgi.c
     jb_err err;
     struct map * exports;
     int local_help_exists = 0;
-@@ -2199,8 +2201,7 @@
+@@ -2295,8 +2297,7 @@
     if (!err) err = map_block_killer(exports, "can-toggle");
  #endif
  
 -   snprintf(buf, 20, "%d", csp->config->hport);
 -   if (!err) err = map(exports, "my-port", 1, buf, 1);
-+      if (!err) err = map(exports, "my-port", 1, csp->my_port_str, 1);
++   if (!err) err = map(exports, "my-port", 1, csp->my_port_str, 1);
  
     if(!strcmp(CODE_STATUS, "stable"))
     {
 diff -urNad privoxy~/errlog.c privoxy/errlog.c
 --- privoxy~/errlog.c
 +++ privoxy/errlog.c
-@@ -679,6 +679,13 @@
+@@ -746,6 +746,13 @@
              break;
           case 'E':
              /* Non-standard: Print error code from errno */
@@ -341,8 +346,8 @@ diff -urNad privoxy~/errlog.c privoxy/errlog.c
 diff -urNad privoxy~/filters.c privoxy/filters.c
 --- privoxy~/filters.c
 +++ privoxy/filters.c
-@@ -14,6 +14,9 @@
-  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
+@@ -15,6 +15,9 @@
+  * Copyright   :  Written by and Copyright (C) 2001, 2004 the SourceForge
   *                Privoxy team. http://www.privoxy.org/
   *
 + *                Modified by Lionel Elie Mamane <lionel@mamane.lu>
@@ -351,7 +356,7 @@ diff -urNad privoxy~/filters.c privoxy/filters.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -427,6 +430,9 @@
+@@ -471,6 +474,9 @@
  #include <ctype.h>
  #include <string.h>
  #include <assert.h>
@@ -361,7 +366,7 @@ diff -urNad privoxy~/filters.c privoxy/filters.c
  
  #ifndef _WIN32
  #ifndef __OS2__
-@@ -461,17 +467,119 @@
+@@ -505,17 +511,119 @@
  
  const char filters_h_rcs[] = FILTERS_H_VERSION;
  
@@ -490,7 +495,7 @@ diff -urNad privoxy~/filters.c privoxy/filters.c
  /*********************************************************************
   *
   * Function    :  block_acl
-@@ -501,7 +609,7 @@
+@@ -545,7 +653,7 @@
     /* search the list */
     while (acl != NULL)
     {
@@ -499,7 +504,7 @@ diff -urNad privoxy~/filters.c privoxy/filters.c
        {
           if (dst == NULL)
           {
-@@ -511,8 +619,8 @@
+@@ -555,8 +663,8 @@
                 return(0);
              }
           }
@@ -510,7 +515,7 @@ diff -urNad privoxy~/filters.c privoxy/filters.c
           {
              if (acl->action == ACL_PERMIT)
              {
-@@ -531,81 +639,249 @@
+@@ -575,81 +683,249 @@
  
  }
  
@@ -802,20 +807,11 @@ diff -urNad privoxy~/filters.c privoxy/filters.c
  
  /*********************************************************************
   *
-@@ -1048,7 +1324,7 @@
-  *********************************************************************/
- struct http_response *redirect_url(struct client_state *csp)
- {
--   char *p, *q;
-+   const char *p, *q;
-    struct http_response *rsp;
-    p = q = csp->http->path;
 diff -urNad privoxy~/filters.h privoxy/filters.h
 --- privoxy~/filters.h
 +++ privoxy/filters.h
 @@ -15,6 +15,9 @@
-  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
+  * Copyright   :  Written by and Copyright (C) 2001, 2004 the SourceForge
   *                Privoxy team. http://www.privoxy.org/
   *
 + *                Modified by Lionel Elie Mamane <lionel@mamane.lu>
@@ -824,7 +820,7 @@ diff -urNad privoxy~/filters.h privoxy/filters.h
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and 
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -221,7 +224,11 @@
+@@ -234,7 +237,11 @@
   */
  #ifdef FEATURE_ACL
  extern int block_acl(struct access_control_addr *dst, struct client_state *csp);
@@ -850,7 +846,7 @@ diff -urNad privoxy~/gateway.c privoxy/gateway.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -199,12 +202,14 @@
+@@ -203,12 +206,14 @@
   * Returns     :  JB_INVALID_SOCKET => failure, else it is the socket file descriptor.
   *
   *********************************************************************/
@@ -867,7 +863,7 @@ diff -urNad privoxy~/gateway.c privoxy/gateway.c
  
     /* Figure out if we need to connect to the web server or a HTTP proxy. */
     if (fwd->forward_host)
-@@ -212,19 +217,23 @@
+@@ -216,19 +221,23 @@
        /* HTTP proxy */
        dest_host = fwd->forward_host;
        dest_port = fwd->forward_port;
@@ -892,7 +888,7 @@ diff -urNad privoxy~/gateway.c privoxy/gateway.c
  
        case SOCKS_4:
        case SOCKS_4A:
-@@ -258,74 +267,19 @@
+@@ -262,74 +271,19 @@
   * Returns     :  JB_INVALID_SOCKET => failure, else a socket file descriptor.
   *
   *********************************************************************/
@@ -974,7 +970,7 @@ diff -urNad privoxy~/gateway.c privoxy/gateway.c
     c->vn          = 4;
     c->cd          = 1;
     c->dstport[0]  = (target_port       >> 8  ) & 0xff;
-@@ -336,7 +290,7 @@
+@@ -340,7 +294,7 @@
     c->dstip[3]    = (web_server_addr         ) & 0xff;
  
     /* pass the request to the socks server */
@@ -983,7 +979,7 @@ diff -urNad privoxy~/gateway.c privoxy/gateway.c
  
     if (sfd == JB_INVALID_SOCKET)
     {
-@@ -391,6 +345,92 @@
+@@ -395,6 +349,92 @@
  
  }
  
@@ -1343,7 +1339,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and 
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -258,6 +262,7 @@
+@@ -285,6 +289,7 @@
  #include "jbsockets.h"
  #include "filters.h"
  #include "errlog.h"
@@ -1351,7 +1347,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
  
  const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;
  
-@@ -270,141 +275,194 @@
+@@ -297,141 +302,194 @@
   *                that this is allowed according to ACL.
   *
   * Parameters  :
@@ -1537,7 +1533,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
        }
 -   }
 +#endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) */
-+
 +      {
 +         fd_set wfds;
 +         struct timeval tv[1];
@@ -1545,7 +1541,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 +         /* wait for connection to complete */
 +         FD_ZERO(&wfds);
 +         FD_SET(fd, &wfds);
++
 +         tv->tv_sec  = 30;
 +         tv->tv_usec = 0;
 +
@@ -1608,9 +1604,8 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 -      return(JB_INVALID_SOCKET);
 +      errno = EINVAL;
 +      return fd;
-    }
--   return(fd);
++   }
++
 +   for(addrs_to_try=addrs;
 +       !is_nil_addr_list(addrs_to_try);
 +       addrs_to_try = tail_addr_list(addrs_to_try))
@@ -1621,8 +1616,9 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 +      fd = connect_to_one_ip(&addr, addrlen, host, portnum, csp);
 +      if (fd != JB_INVALID_SOCKET)
 +         break;
-+   }
-+
+    }
+-   return(fd);
 +   if (fd == JB_INVALID_SOCKET)
 +   {
 +      csp->http->host_ip_addr_str = strdup("unknown");
@@ -1633,7 +1629,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
  }
  
  
-@@ -544,55 +602,30 @@
+@@ -571,55 +629,30 @@
  
  /*********************************************************************
   *
@@ -1698,7 +1694,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
  
  #ifdef _WIN32
     if (fd == JB_INVALID_SOCKET)
-@@ -618,8 +651,17 @@
+@@ -645,8 +678,17 @@
      */
     setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
  #endif /* ndef _WIN32 */
@@ -1718,7 +1714,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
     {
  #ifdef _WIN32
        errno = WSAGetLastError();
-@@ -638,7 +680,7 @@
+@@ -665,7 +707,7 @@
        }
     }
  
@@ -1727,7 +1723,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
     {
        if (errno != EINTR)
        {
-@@ -646,7 +688,11 @@
+@@ -673,7 +715,11 @@
        }
     }
  
@@ -1740,7 +1736,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
     return 0;
  
  }
-@@ -654,6 +700,91 @@
+@@ -681,6 +727,91 @@
  
  /*********************************************************************
   *
@@ -1809,12 +1805,12 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 +                      "There may be another Privoxy or some other "
 +                      "proxy running on port %s",
 +                      log_host, port, numeric_hostname, numeric_port, numeric_port);
-+                              break;
++            break;
 +         case -2 :
 +            log_error(LOG_LEVEL_ERROR, "can't bind to %s:%s (%s:%s): "
 +                      "Out of memory",
 +                      log_host, port, numeric_hostname, numeric_port);
-+                              break;
++            break;
 +         default :
 +            log_error(LOG_LEVEL_ERROR, "can't bind to %s:%s: because %E",
 +                      log_host, numeric_port);
@@ -1832,7 +1828,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
   * Function    :  accept_connection
   *
   * Description :  Accepts a connection on a socket.  Socket must have
-@@ -670,8 +801,7 @@
+@@ -697,8 +828,7 @@
   *********************************************************************/
  int accept_connection(struct client_state * csp, jb_socket fd)
  {
@@ -1842,7 +1838,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
     jb_socket afd;
  #if defined(_WIN32) || defined(__OS2__) || defined(__APPLE_CC__) || defined(AMIGA)
     /* Wierdness - fix a warning. */
-@@ -679,15 +809,7 @@
+@@ -706,15 +836,7 @@
  #else
     socklen_t c_length, s_length;
  #endif
@@ -1859,7 +1855,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
  
     c_length = s_length = sizeof(client);
  
-@@ -707,6 +829,12 @@
+@@ -734,6 +856,12 @@
        return 0;
     }
  #endif
@@ -1872,7 +1868,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
  
     /* 
      * Determine the IP-Adress that the client used to reach us
-@@ -714,49 +842,50 @@
+@@ -741,49 +869,50 @@
      */
     if (!getsockname(afd, (struct sockaddr *) &server, &s_length))
     {
@@ -1911,7 +1907,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 +         log_error(LOG_LEVEL_ERROR, "accept: Could not get my own hostname because %E");
 +         strncpy(hostname,"unknown host",NI_MAXHOST);
        }
--#elif defined(OSX_DARWIN)
+-#elif FEATURE_PTHREAD
 -      pthread_mutex_lock(&gethostbyaddr_mutex);
 -      host = gethostbyaddr((const char *)&server.sin_addr, 
 -                           sizeof(server.sin_addr), AF_INET);
@@ -1957,7 +1953,7 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
  
     return 1;
  
-@@ -767,90 +896,41 @@
+@@ -794,108 +923,48 @@
   *
   * Function    :  resolve_hostname_to_ip
   *
@@ -1976,10 +1972,18 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
   *
   *********************************************************************/
 -unsigned long resolve_hostname_to_ip(const char *host)
-+addr_list *resolve_hostname_to_ip(const char *host, const char *port, int pf)
- {
+-{
 -   struct sockaddr_in inaddr;
 -   struct hostent *hostp;
++addr_list *resolve_hostname_to_ip(const char *host, const char *port, int pf)
++ {
++   /* TODO 
++    * Do all supported platforms have "getaddrinfo"?
++    */
++    
++   struct addrinfo hints, *res0;
++   int result;
+    unsigned int dns_retries = 0;
 -#if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS) || defined(HAVE_GETHOSTBYNAME_R_3_ARGS)
 -   struct hostent result;
 -#if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
@@ -1989,30 +1993,24 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 -   struct hostent_data hdata;
 -#endif /* def HAVE_GETHOSTBYNAME_R_(6|5)_ARGS */
 -#endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
--
 -   if ((host == NULL) || (*host == '\0'))
 -   {
 -      return(INADDR_ANY);
 -   }
 -
 -   memset((char *) &inaddr, 0, sizeof inaddr);
-+   /* TODO 
-+    * Do all supported platforms have "getaddrinfo"?
-+    */
-+    
-+   struct addrinfo hints, *res0;
-+   int result;
-+   memset(&hints, 0, sizeof(hints));
-+   hints.ai_family = pf;
-+   hints.ai_socktype = SOCK_STREAM;
+-
 -   if ((inaddr.sin_addr.s_addr = inet_addr(host)) == -1)
-+   result = getaddrinfo(host, port, &hints, &res0);
-+   if ( result != 0 )
-    {
+-   {
 -#if defined(HAVE_GETHOSTBYNAME_R_6_ARGS)
--      gethostbyname_r(host, &result, hbuf,
--                      HOSTENT_BUFFER_SIZE, &hostp, &thd_err);
+-       while ( gethostbyname_r(host, &result, hbuf,
+-                      HOSTENT_BUFFER_SIZE, &hostp, &thd_err)
+-               && (thd_err == TRY_AGAIN) && (dns_retries++ < 10) )
+-      {   
+-         log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
+-                                                dns_retries, host);
+-      }
 -#elif defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
 -      hostp = gethostbyname_r(host, &result, hbuf,
 -                      HOSTENT_BUFFER_SIZE, &thd_err);
@@ -2025,12 +2023,22 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 -      {
 -         hostp = NULL;
 -      }
--#elif OSX_DARWIN
+-#elif FEATURE_PTHREAD
 -      pthread_mutex_lock(&gethostbyname_mutex);
--      hostp = gethostbyname(host);
+-      while ( NULL == (hostp = gethostbyname(host))
+-            && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) )
+-      {   
+-         log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
+-                                                dns_retries, host);
+-      }
 -      pthread_mutex_unlock(&gethostbyname_mutex);
 -#else
--      hostp = gethostbyname(host);
+-      while ( NULL == (hostp = gethostbyname(host))
+-            && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) )
+-      {
+-         log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
+-                                                dns_retries, host);
+-      }
 -#endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
 -      /*
 -       * On Mac OSX, if a domain exists but doesn't have a type A
@@ -2059,20 +2067,35 @@ diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
 -         (char *) hostp->h_addr,
 -         sizeof(inaddr.sin_addr)
 -      );
++   memset(&hints, 0, sizeof(hints));
++   hints.ai_family = pf;
++   hints.ai_socktype = SOCK_STREAM;
++  
++   while ((result = getaddrinfo(host, port, &hints, &res0)) 
++          && (result == EAI_AGAIN) && (dns_retries++ < 10)) {
++      log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
++                dns_retries, host);
+    }
+-   return(inaddr.sin_addr.s_addr);
+-
+-}
+-
++   if ( result != 0 )
++     {
 +      log_error(LOG_LEVEL_ERROR, "could not resolve hostname %s because %s", host,gai_strerror(result));
 +      if (result == EAI_SYSTEM)
 +         log_error(LOG_LEVEL_ERROR, "The system error is %E");
 +      return NULL;
-    }
--   return(inaddr.sin_addr.s_addr);
++     }
 +   else
 +      if (res0==0)
 +         log_error(LOG_LEVEL_ERROR, "Problem in resolving hostname %s: succeeded, but no information returned", host);
++  
 +   return res0;
- }
++ }
  
+ /*
+   Local Variables:
 diff -urNad privoxy~/jbsockets.h privoxy/jbsockets.h
 --- privoxy~/jbsockets.h
 +++ privoxy/jbsockets.h
@@ -2086,7 +2109,7 @@ diff -urNad privoxy~/jbsockets.h privoxy/jbsockets.h
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and 
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -100,9 +103,11 @@
+@@ -104,9 +107,11 @@
  extern "C" {
  #endif
  
@@ -2099,7 +2122,7 @@ diff -urNad privoxy~/jbsockets.h privoxy/jbsockets.h
  #ifdef AMIGA
  extern int write_socket(jb_socket fd, const char *buf, ssize_t n);
  #else
-@@ -111,10 +116,10 @@
+@@ -115,10 +120,10 @@
  extern int read_socket(jb_socket fd, char *buf, int n);
  extern void close_socket(jb_socket fd);
  
@@ -2115,7 +2138,7 @@ diff -urNad privoxy~/jbsockets.h privoxy/jbsockets.h
 diff -urNad privoxy~/jcc.c privoxy/jcc.c
 --- privoxy~/jcc.c
 +++ privoxy/jcc.c
-@@ -676,6 +676,7 @@
+@@ -767,6 +767,7 @@
  #include "cgi.h"
  #include "loadcfg.h"
  #include "urlmatch.h"
@@ -2123,7 +2146,7 @@ diff -urNad privoxy~/jcc.c privoxy/jcc.c
  
  const char jcc_h_rcs[] = JCC_H_VERSION;
  const char project_h_rcs[] = PROJECT_H_VERSION;
-@@ -2112,61 +2113,78 @@
+@@ -2338,61 +2339,78 @@
   * Returns     :  Port that was opened.
   *
   *********************************************************************/
@@ -2204,7 +2227,7 @@ diff -urNad privoxy~/jcc.c privoxy/jcc.c
 +               "proxy running on port %s",
 +               (NULL != bs->haddr) ? bs->haddr : "INADDR_ANY",
 +                      bs->hport, bs->hport);
-+                              break;
++            break;
  
           case -2 :
 -            log_error(LOG_LEVEL_FATAL, "can't bind to %s:%d: " 
@@ -2212,7 +2235,7 @@ diff -urNad privoxy~/jcc.c privoxy/jcc.c
                 "The hostname is not resolvable",
 -               (NULL != config->haddr) ? config->haddr : "INADDR_ANY", config->hport);
 +               (NULL != bs->haddr) ? bs->haddr : "INADDR_ANY", bs->hport);
-+                              break;
++            break;
  
           default :
 -            log_error(LOG_LEVEL_FATAL, "can't bind to %s:%d: because %E",
@@ -2238,7 +2261,7 @@ diff -urNad privoxy~/jcc.c privoxy/jcc.c
  }
  
  
-@@ -2184,12 +2202,18 @@
+@@ -2421,12 +2439,18 @@
  static void listen_loop(void)
  {
     struct client_state *csp = NULL;
@@ -2259,7 +2282,7 @@ diff -urNad privoxy~/jcc.c privoxy/jcc.c
  
  #ifdef FEATURE_GRACEFUL_TERMINATION
     while (!g_terminate)
-@@ -2263,14 +2287,55 @@
+@@ -2500,14 +2524,55 @@
            * that this will hurt people's feelings.
            */
  
@@ -2318,7 +2341,7 @@ diff -urNad privoxy~/jcc.c privoxy/jcc.c
        {
           log_error(LOG_LEVEL_CONNECT, "accept failed: %E");
  
-@@ -2288,6 +2353,8 @@
+@@ -2525,6 +2590,8 @@
           log_error(LOG_LEVEL_CONNECT, "OK");
        }
  
@@ -2340,7 +2363,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -372,6 +375,7 @@
+@@ -408,6 +411,7 @@
  #include "encode.h"
  #include "urlmatch.h"
  #include "cgi.h"
@@ -2348,7 +2371,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
  
  const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
  
-@@ -489,8 +493,8 @@
+@@ -527,8 +531,8 @@
        struct forward_spec * next_fwd = cur_fwd->next;
        free_url_spec(cur_fwd->url);
  
@@ -2359,7 +2382,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
        free(cur_fwd);
        cur_fwd = next_fwd;
     }
-@@ -507,7 +511,16 @@
+@@ -545,7 +549,16 @@
     freez(config->confdir);
     freez(config->logdir);
  
@@ -2376,8 +2399,8 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
 +   freez(config->hspecs);
     freez(config->logfile);
  
-    for (i = 0; i < MAX_ACTION_FILES; i++)
-@@ -570,6 +583,28 @@
+    for (i = 0; i < MAX_AF_FILES; i++)
+@@ -612,6 +625,28 @@
   * Returns     :  The configuration_spec, or NULL on error.
   *
   *********************************************************************/
@@ -2406,7 +2429,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
  struct configuration_spec * load_config(void)
  {
     char buf[BUFFER_SIZE];
-@@ -601,12 +636,7 @@
+@@ -643,12 +678,7 @@
     fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
  
     if (config==NULL)
@@ -2420,16 +2443,16 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
  
     /*
      * This is backwards from how it's usually done.
-@@ -623,7 +653,7 @@
+@@ -665,7 +695,7 @@
      * Set to defaults
      */
-    config->multi_threaded    = 1;
--   config->hport             = HADDR_PORT;
-+   config->hspecs            = NULL;
-    config->buffer_limit      = 4096 * 1024;
-    config->usermanual        = strdup(USER_MANUAL_URL);
-    config->proxy_args        = strdup("");
-@@ -640,9 +670,6 @@
+    config->multi_threaded            = 1;
+-   config->hport                     = HADDR_PORT;
++   config->hspecs                    = NULL;
+    config->buffer_limit              = 4096 * 1024;
+    config->usermanual                = strdup(USER_MANUAL_URL);
+    config->proxy_args                = strdup("");
+@@ -684,9 +714,6 @@
        char cmd[BUFFER_SIZE];
        char arg[BUFFER_SIZE];
        char tmp[BUFFER_SIZE];
@@ -2439,7 +2462,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
        struct forward_spec *cur_fwd;
        int vec_count;
        char *vec[3];
-@@ -753,74 +780,23 @@
+@@ -797,74 +824,23 @@
   * *************************************************************************/
  #ifdef FEATURE_ACL
           case hash_deny_access:
@@ -2494,10 +2517,10 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
 -                     vec[0]);
 +               case 1:
 +                  config->acl = add_to_acl_list(config->acl, ACL_DENY, vec[0], NULL, &config->proxy_args);
-+                                              break;
++                  break;
 +               case 2:
 +                  config->acl = add_to_acl_list(config->acl, ACL_DENY, vec[0], vec[1], &config->proxy_args);
-+                                              break;
++                  break;
 +               default:
 +                  log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
 +                            "deny-access directive in configuration file.");
@@ -2527,7 +2550,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
  #endif /* def FEATURE_ACL */
  
  /* *************************************************************************
-@@ -914,16 +890,18 @@
+@@ -984,16 +960,18 @@
  
              if (strcmp(p, ".") != 0)
              {
@@ -2552,7 +2575,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
                    cur_fwd->forward_port = 8000;
                 }
              }
-@@ -977,15 +955,27 @@
+@@ -1047,15 +1025,27 @@
  
              if (strcmp(p, ".") != 0)
              {
@@ -2584,7 +2607,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
                    cur_fwd->gateway_port = 1080;
                 }
              }
-@@ -995,16 +985,26 @@
+@@ -1065,16 +1055,26 @@
  
              if (strcmp(p, ".") != 0)
              {
@@ -2615,7 +2638,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
                    cur_fwd->forward_port = 8000;
                 }
              }
-@@ -1056,16 +1056,30 @@
+@@ -1126,16 +1126,30 @@
              /* Parse the SOCKS proxy host[:port] */
              p = vec[1];
  
@@ -2655,7 +2678,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
              }
  
              /* Parse the parent HTTP proxy host[:port] */
-@@ -1073,16 +1087,26 @@
+@@ -1143,16 +1157,26 @@
  
              if (strcmp(p, ".") != 0)
              {
@@ -2686,7 +2709,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
                    cur_fwd->forward_port = 8000;
                 }
              }
-@@ -1108,10 +1132,49 @@
+@@ -1185,10 +1209,49 @@
   * listen-address [ip][:port]
   * *************************************************************************/
           case hash_listen_address :
@@ -2739,7 +2762,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
  /* *************************************************************************
   * logdir directory-name
   * *************************************************************************/
-@@ -1134,75 +1197,21 @@
+@@ -1211,75 +1274,21 @@
   * *************************************************************************/
  #ifdef FEATURE_ACL
           case hash_permit_access:
@@ -2796,10 +2819,10 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
 -                     vec[0]);
 +               case 1:
 +                  config->acl = add_to_acl_list(config->acl, ACL_PERMIT, vec[0], NULL, &config->proxy_args);
-+                                              break;
++                  break;
 +               case 2:
 +                  config->acl = add_to_acl_list(config->acl, ACL_PERMIT, vec[0], vec[1], &config->proxy_args);
-+                                              break;
++                  break;
 +               default:
 +                  log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
 +                            "permit-access directive in configuration file.");
@@ -2827,7 +2850,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
              continue;
  #endif /* def FEATURE_ACL */
  
-@@ -1442,32 +1451,33 @@
+@@ -1519,32 +1528,33 @@
     }
  #endif /* def FEATURE_COOKIE_JAR */
  
@@ -2886,7 +2909,7 @@ diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
     }
  
     /*
-@@ -1509,31 +1519,29 @@
+@@ -1586,31 +1596,29 @@
        struct configuration_spec * oldcfg = (struct configuration_spec *)
                                             current_configfile->f;
        /*
@@ -2948,7 +2971,7 @@ diff -urNad privoxy~/loaders.c privoxy/loaders.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -427,6 +430,7 @@
+@@ -465,6 +468,7 @@
  
           freez(csp->ip_addr_str);
           freez(csp->my_ip_addr_str);
@@ -2959,7 +2982,7 @@ diff -urNad privoxy~/loaders.c privoxy/loaders.c
 diff -urNad privoxy~/miscutil.h privoxy/miscutil.h
 --- privoxy~/miscutil.h
 +++ privoxy/miscutil.h
-@@ -142,6 +142,15 @@
+@@ -162,6 +162,15 @@
  
  #include "project.h"
  
@@ -2988,9 +3011,9 @@ diff -urNad privoxy~/parsers.c privoxy/parsers.c
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -1953,6 +1956,167 @@
+@@ -1951,6 +1954,167 @@
+    return JB_ERR_OK;
  }
- #endif /* def FEATURE_FORCE_LOAD */
  
 +/*********************************************************************
 + *
@@ -3154,8 +3177,8 @@ diff -urNad privoxy~/parsers.c privoxy/parsers.c
 +}
 +
  
- /*
-   Local Variables:
+ /*********************************************************************
+  *
 diff -urNad privoxy~/parsers.h privoxy/parsers.h
 --- privoxy~/parsers.h
 +++ privoxy/parsers.h
@@ -3169,9 +3192,9 @@ diff -urNad privoxy~/parsers.h privoxy/parsers.h
   *                Based on the Internet Junkbuster originally written
   *                by and Copyright (C) 1997 Anonymous Coders and 
   *                Junkbusters Corporation.  http://www.junkbusters.com
-@@ -227,6 +230,10 @@
- extern jb_err server_transfer_coding (struct client_state *csp, char **header);
- extern jb_err server_http            (struct client_state *csp, char **header);
+@@ -270,6 +273,10 @@
+ extern jb_err server_last_modified   (struct client_state *csp, char **header);
+ extern jb_err server_content_disposition(struct client_state *csp, char **header);
  
 +extern int parse_pf_ip_netmask(char *string, char **host, char **port, int *pf, int *masklength);
 +extern int parse_pf_ip(char *string, char ** host, char ** port, int *pf);
@@ -3183,7 +3206,7 @@ diff -urNad privoxy~/parsers.h privoxy/parsers.h
 diff -urNad privoxy~/project.h privoxy/project.h
 --- privoxy~/project.h
 +++ privoxy/project.h
-@@ -549,6 +549,20 @@
+@@ -607,6 +607,20 @@
  
  #endif /* ndef _WIN32 */
  
@@ -3204,7 +3227,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
  
  /**
   * A standard error code.  This should be JB_ERR_OK or one of the JB_ERR_xxx
-@@ -618,19 +632,6 @@
+@@ -681,19 +695,6 @@
   */
  #define FOREVER 1
  
@@ -3224,7 +3247,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
  /* Forward def for struct client_state */
  struct configuration_spec;
  
-@@ -709,13 +710,16 @@
+@@ -772,13 +773,16 @@
     char *ver;      /**< Protocol version */
     int status;     /**< HTTP Status */
  
@@ -3242,7 +3265,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
                                  of host's IP. NULL before connect_to() */
  
     char  *dbuffer; /**< Buffer with '\0'-delimited domain name.           */
-@@ -1039,13 +1043,16 @@
+@@ -1158,13 +1162,16 @@
         As a string. */
     char *ip_addr_str;
     /** Client PC's IP address, as reported by the accept() function.
@@ -3261,7 +3284,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
     /** Our hostname. I.e. the reverse DNS of the IP address that the client
         used to reach us, as a string. */
     char *my_hostname;
-@@ -1214,18 +1221,33 @@
+@@ -1339,18 +1346,33 @@
     /** Connection type.  Must be SOCKS_NONE, SOCKS_4, or SOCKS_4A. */
     int   type;
  
@@ -3295,7 +3318,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
     /** Next entry in the linked list. */
     struct forward_spec *next;
  };
-@@ -1234,7 +1256,7 @@
+@@ -1359,7 +1381,7 @@
  /**
   * Initializer for a static struct forward_spec.
   */
@@ -3304,7 +3327,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
  
  
  /**
-@@ -1263,7 +1285,8 @@
+@@ -1388,7 +1410,8 @@
   */
  struct access_control_addr
  {
@@ -3314,9 +3337,9 @@ diff -urNad privoxy~/project.h privoxy/project.h
     unsigned long mask;  /**< The network mask as an integer. */
     unsigned long port;  /**< The port number. */
  };
-@@ -1295,6 +1318,17 @@
- /** configuration_spec::feature_flags: Web-based toggle. */
- #define RUNTIME_FEATURE_CGI_TOGGLE        2
+@@ -1423,6 +1446,17 @@
+ /** configuration_spec::feature_flags: HTTP-header-based toggle. */
+ #define RUNTIME_FEATURE_HTTP_TOGGLE       4
  
 +struct bind_spec
 +{
@@ -3329,10 +3352,10 @@ diff -urNad privoxy~/project.h privoxy/project.h
 +   /** Address family */
 +   int pf;
 +};
  /**
   * Data loaded from the configuration file.
-@@ -1355,11 +1389,13 @@
+  *
+@@ -1486,11 +1520,13 @@
  
  #endif /* def FEATURE_COOKIE_JAR */
  
@@ -3354,7 +3377,7 @@ diff -urNad privoxy~/project.h privoxy/project.h
 diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
 --- privoxy~/urlmatch.c
 +++ privoxy/urlmatch.c
-@@ -133,6 +133,7 @@
+@@ -137,6 +137,7 @@
  #include "ssplit.h"
  #include "miscutil.h"
  #include "errlog.h"
@@ -3362,7 +3385,7 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
  
  const char urlmatch_h_rcs[] = URLMATCH_H_VERSION;
  
-@@ -156,7 +157,7 @@
+@@ -160,7 +161,7 @@
     freez(http->cmd);
     freez(http->ocmd);
     freez(http->gpc);
@@ -3371,7 +3394,7 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
     freez(http->url);
     freez(http->hostport);
     freez(http->path);
-@@ -298,8 +299,6 @@
+@@ -302,8 +303,6 @@
      */
     {
        char *buf;
@@ -3380,11 +3403,11 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
  
        buf = strdup(http->hostport);
        if (buf == NULL)
-@@ -307,38 +306,34 @@
+@@ -311,38 +310,34 @@
           return JB_ERR_MEMORY;
        }
  
-+              http->host_port_malloc = buf;
++      http->host_port_malloc = buf;
 +
        /* check if url contains username and/or password */
 -      host = strchr(buf, '@');
@@ -3419,9 +3442,8 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
        else
        {
           /* No port specified. */
--         http->port = (http->ssl ? 443 : 80);
 +         http->port_str = (http->ssl ? "143" : "80");
-+                      http->port = (http->ssl ? 443 : 80);
+          http->port = (http->ssl ? 443 : 80);
        }
  
 -      http->host = strdup(host);
@@ -3431,7 +3453,7 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
        if (http->host == NULL)
        {
           return JB_ERR_MEMORY;
-@@ -662,9 +657,8 @@
+@@ -666,9 +661,8 @@
   *                               written to system log)
   *
   *********************************************************************/
@@ -3442,7 +3464,7 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
  
     assert(url);
     assert(buf);
-@@ -681,22 +675,25 @@
+@@ -685,21 +679,24 @@
     {
        return JB_ERR_MEMORY;
     }
@@ -3463,6 +3485,11 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
 +         }
 +         url->pathlen = strlen(url->path);
 +         *p = '\0';
++      }
++      else
++      {
++         url->path    = NULL;
++         url->pathlen = 0;
        }
 -      url->pathlen = strlen(url->path);
 -      *p = '\0';
@@ -3471,17 +3498,10 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
 -   {
 -      url->path    = NULL;
 -      url->pathlen = 0;
--   }
-+      else
-+      {
-+         url->path    = NULL;
-+         url->pathlen = 0;
-+      }
-+      }
+    }
     if (url->path)
     {
-       int errcode;
-@@ -735,15 +732,12 @@
+@@ -739,14 +736,11 @@
           return JB_ERR_PARSE;
        }
     }
@@ -3494,15 +3514,13 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
     {
 -      *p++ = '\0';
 -      url->port = atoi(p);
--   }
 +     char *p;
 +     parse_ip(buf,&buf,&p);
 +     url->port = atoi(p);
-+      }
+    }
  
     if (buf[0] != '\0')
-    {
-@@ -775,12 +769,13 @@
+@@ -779,12 +773,13 @@
           return JB_ERR_MEMORY;
        }
  
@@ -3524,7 +3542,7 @@ diff -urNad privoxy~/urlmatch.c privoxy/urlmatch.c
 diff -urNad privoxy~/urlmatch.h privoxy/urlmatch.h
 --- privoxy~/urlmatch.h
 +++ privoxy/urlmatch.h
-@@ -79,7 +79,7 @@
+@@ -83,7 +83,7 @@
  extern int url_match(const struct url_spec *pattern,
                       const struct http_request *url);