Hard tabs->Spaces
[privoxy.git] / loadcfg.c
index f29d665..ae33439 100644 (file)
--- a/loadcfg.c
+++ b/loadcfg.c
@@ -1,7 +1,7 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrator Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.4 2001/05/22 18:46:04 oes Exp $";
 /*********************************************************************
  *
- * File        :  $Source: /home/administrator/cvs/ijb/loadcfg.c,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
  *
  * Purpose     :  Loads settings from the configuration file into
  *                global variables.  This file contains both the 
@@ -35,6 +35,69 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrat
  *
  * Revisions   :
  *    $Log: loadcfg.c,v $
+ *    Revision 1.4  2001/05/22 18:46:04  oes
+ *
+ *    - Enabled filtering banners by size rather than URL
+ *      by adding patterns that replace all standard banner
+ *      sizes with the "Junkbuster" gif to the re_filterfile
+ *
+ *    - Enabled filtering WebBugs by providing a pattern
+ *      which kills all 1x1 images
+ *
+ *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
+ *      which is selected by the (nonstandard and therefore
+ *      capital) letter 'U' in the option string.
+ *      It causes the quantifiers to be ungreedy by default.
+ *      Appending a ? turns back to greedy (!).
+ *
+ *    - Added a new interceptor ijb-send-banner, which
+ *      sends back the "Junkbuster" gif. Without imagelist or
+ *      MSIE detection support, or if tinygif = 1, or the
+ *      URL isn't recognized as an imageurl, a lame HTML
+ *      explanation is sent instead.
+ *
+ *    - Added new feature, which permits blocking remote
+ *      script redirects and firing back a local redirect
+ *      to the browser.
+ *      The feature is conditionally compiled, i.e. it
+ *      can be disabled with --disable-fast-redirects,
+ *      plus it must be activated by a "fast-redirects"
+ *      line in the config file, has its own log level
+ *      and of course wants to be displayed by show-proxy-args
+ *      Note: Boy, all the #ifdefs in 1001 locations and
+ *      all the fumbling with configure.in and acconfig.h
+ *      were *way* more work than the feature itself :-(
+ *
+ *    - Because a generic redirect template was needed for
+ *      this, tinygif = 3 now uses the same.
+ *
+ *    - Moved GIFs, and other static HTTP response templates
+ *      to project.h
+ *
+ *    - Some minor fixes
+ *
+ *    - Removed some >400 CRs again (Jon, you really worked
+ *      a lot! ;-)
+ *
+ *    Revision 1.3  2001/05/20 01:21:20  jongfoster
+ *    Version 2.9.4 checkin.
+ *    - Merged popupfile and cookiefile, and added control over PCRS
+ *      filtering, in new "permissionsfile".
+ *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
+ *      file error you now get a message box (in the Win32 GUI) rather
+ *      than the program exiting with no explanation.
+ *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
+ *      skipping.
+ *    - Removed tabs from "config"
+ *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
+ *    - Bumped up version number.
+ *
+ *    Revision 1.2  2001/05/17 23:01:01  oes
+ *     - Cleaned CRLF's from the sources and related files
+ *
+ *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
+ *    Initial import of version 2.9.3 source tree
+ *
  *
  *********************************************************************/
 \f
@@ -119,7 +182,7 @@ int multi_threaded      = 1;
 
 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
 int tinygif             = 0;
-const char *tinygifurl  = NULL;\r
+const char *tinygifurl  = NULL;
 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
 
 const char *logfile     = NULL;
@@ -127,7 +190,7 @@ const char *logfile     = NULL;
 const char *configfile  = NULL;
 
 const char *blockfile   = NULL;
-const char *cookiefile  = NULL;
+const char *permissions_file  = NULL;
 const char *forwardfile = NULL;
 
 #ifdef ACL_FILES
@@ -138,16 +201,19 @@ const char *aclfile     = NULL;
 const char *imagefile   = NULL;
 #endif /* def USE_IMAGE_LIST */
 
-#ifdef KILLPOPUPS
-const char *popupfile   = NULL;
-int kill_all_popups     = 0;     /* Not recommended really ... */
-#endif /* def KILLPOPUPS */
+/*
+ * Permissions to use for URLs not in the permissions list.
+ */
+int default_permissions = PERMIT_RE_FILTER;
 
 #ifdef PCRS
 const char *re_filterfile = NULL;
-int re_filter_all       = 0;
 #endif /* def PCRS */
 
+#ifdef FAST_REDIRECTS
+int fast_redirects = 0;
+#endif /* def FAST_REDIRECTS */
+
 #ifdef TRUST_FILES
 const char *trustfile   = NULL;
 #endif /* def TRUST_FILES */
@@ -166,7 +232,7 @@ const char *suppress_message = NULL;
 #endif /* ndef SPLIT_PROXY_ARGS */
 
 int suppress_vanilla_wafer = 0;
-int add_forwarded       = 0;
+int add_forwarded          = 0;
 
 struct list wafer_list[1];
 struct list xtra_list[1];
@@ -207,7 +273,8 @@ const char **Argv = NULL;
  * something a little more readable.  This also makes changing the
  * hash values easier if they should change or the hash algorthm changes.
  * Use the included "hash" program to find out what the hash will be
- * for any string supplied on the command line.
+ * for any string supplied on the command line.  (Or just put it in the
+ * config file and read the number from the error message in the log).
  */
 
 #define hash_trustfile                 56494766ul
@@ -219,7 +286,7 @@ const char **Argv = NULL;
 #define hash_suppress_vanilla_wafer    3121233547ul
 #define hash_wafer                     89669ul
 #define hash_add_header                237434619ul
-#define hash_cookiefile                247469766ul
+#define hash_permissions_file          3825730796lu /* "permissionsfile" */
 #define hash_logfile                   2114766ul
 #define hash_blockfile                 48845391ul
 #define hash_imagefile                 51447891ul
@@ -227,14 +294,12 @@ const char **Argv = NULL;
 #define hash_listen_address            1255650842ul
 #define hash_forwardfile               1268669141ul
 #define hash_aclfile                   1908516ul
-#define hash_popupfile                 54623516ul
-#define hash_kill_all_popups           2311539906ul
 #define hash_re_filterfile             3877522444ul
-#define hash_re_filter_all             3877521376ul
 #define hash_user_agent                283326691ul
 #define hash_referrer                  10883969ul
 #define hash_referer                   2176719ul
 #define hash_from                      16264ul
+#define hash_fast_redirects            464873764lu
 #define hash_hide_console              2048809870ul
 #define hash_include_stats             2174146548ul
 #define hash_suppress_blocklists       1948693308ul
@@ -273,7 +338,7 @@ void load_config( int signum )
    char *p, *q;
    FILE *configfp = NULL;
 
-   configret = 0;
+   configret = 0; /* FIXME: This is obsolete, always 0. */
    config_changed = 1;
 
    log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
@@ -282,9 +347,9 @@ void load_config( int signum )
 
 
    /* (Waste of memory [not quite a "leak"] here.  The 
-    * last blockfile/popupfile/... etc will not be 
+    * last blockfile/permissions file/... etc will not be 
     * unloaded until we load a new one.  If the 
-    * block/popup/... feature has been disabled in 
+    * block/... feature has been disabled in 
     * the new config file, then we're wasting some 
     * memory we could otherwise reclaim.
     */
@@ -297,19 +362,21 @@ void load_config( int signum )
     * But leave changing the logfile until after we're done loading.
     */
 
-   #ifdef JAR_FILES
+#ifdef JAR_FILES
    if ( NULL != jar )
    {
       fclose( jar );
       jar = NULL;
    }
-   #endif /* def JAR_FILES */
+#endif /* def JAR_FILES */
 
    debug             = 0;
    multi_threaded    = 1;
 
+   default_permissions = PERMIT_RE_FILTER;
+
 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
-   tinygif           = 0;\r
+   tinygif           = 0;
    freez((char *)tinygifurl);
 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
 
@@ -321,14 +388,6 @@ void load_config( int signum )
    hideConsole       = 0;
 #endif /*def _WIN_CONSOLE*/
 
-#ifdef PCRS
-   re_filter_all     = 0;
-#endif /* def PCRS */
-
-#ifdef KILLPOPUPS
-   kill_all_popups   = 0;
-#endif /* def KILLPOPUPS */
-
 #ifdef TOGGLE
    g_bToggleIJB      = 1;
 #endif
@@ -350,7 +409,7 @@ void load_config( int signum )
 
 
    freez((char *)blockfile);
-   freez((char *)cookiefile);
+   freez((char *)permissions_file);
    freez((char *)forwardfile);
 
 #ifdef ACL_FILES
@@ -365,10 +424,6 @@ void load_config( int signum )
    freez((char *)jarfile);
 #endif /* def JAR_FILES */
 
-#ifdef KILLPOPUPS
-   freez((char *)popupfile);
-#endif /* def KILLPOPUPS */
-
 #ifndef SPLIT_PROXY_ARGS
    freez((char *)suppress_message);
 #endif /* ndef SPLIT_PROXY_ARGS */
@@ -381,14 +436,17 @@ void load_config( int signum )
    freez((char *)re_filterfile);
 #endif /* def PCRS */
 
+#ifdef FAST_REDIRECTS
+   fast_redirects = 0;
+#endif /* def FAST_REDIRECTS */
+
    if (NULL != configfile)
    {
       if ((configfp = fopen(configfile, "r")) == NULL)
       {
-         log_error(LOG_LEVEL_ERROR, "can't open configuration file '%s':  %E",
+         log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s':  %E",
                  configfile);
-         configret = 1;
-         return;
+         /* Never get here - LOG_LEVEL_FATAL causes program exit */
       }
    }
 
@@ -443,7 +501,7 @@ void load_config( int signum )
          switch( hash_string( cmd ) )
          {
 #ifdef TRUST_FILES
-            case hash_trustfile :\r
+            case hash_trustfile :
                freez((char *)trustfile);
                trustfile = strdup(arg);
                continue;
@@ -458,37 +516,37 @@ void load_config( int signum )
                continue;
 
 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
-            case hash_tinygif :\r
+            case hash_tinygif :
                freez((char *)tinygifurl);
                tinygif = atoi(arg);
-               if(3 == tinygif)\r
-               {\r
-                  p = arg;\r
-                  while((*p >= '0') && (*p <= '9'))\r
-                  {\r
-                     p++;\r
-                  }\r
-                  while((*p == ' ') || (*p == '\t'))\r
-                  {\r
-                     p++;\r
-                  }\r
-                  if (*p)\r
-                  {\r
-                     q = malloc(strlen(p) + 5);\r
-                     if (q)\r
-                     {\r
-                        strcpy(q, p);\r
-                        strcat(q, "\r\n\r\n");\r
-                        tinygifurl = q;\r
-                     }\r
-                  }\r
-               }\r
-               if ((tinygif != 1) && \r
-                   (tinygif != 2) && \r
-                   ((tinygif != 3) || (tinygifurl==NULL)) )\r
-               {\r
-                  log_error(LOG_LEVEL_ERROR, "tinygif setting invalid.");\r
-               }\r
+               if(3 == tinygif)
+               {
+                  p = arg;
+                  while((*p >= '0') && (*p <= '9'))
+                  {
+                     p++;
+                  }
+                  while((*p == ' ') || (*p == '\t'))
+                  {
+                     p++;
+                  }
+                  if (*p)
+                  {
+                     q = malloc(strlen(p) + 5);
+                     if (q)
+                     {
+                        strcpy(q, p);
+                        strcat(q, "\r\n\r\n");
+                        tinygifurl = q;
+                     }
+                  }
+               }
+               if ((tinygif != 1) && 
+                   (tinygif != 2) && 
+                   ((tinygif != 3) || (tinygifurl==NULL)) )
+               {
+                  log_error(LOG_LEVEL_ERROR, "tinygif setting invalid.");
+               }
                continue;
 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
 
@@ -512,77 +570,60 @@ void load_config( int signum )
                enlist(xtra_list, arg);
                continue;
 
-            case hash_cookiefile :\r
-               freez((char *)cookiefile);
-               cookiefile = strdup(arg);
+            case hash_permissions_file :
+               freez((char *)permissions_file);
+               permissions_file = strdup(arg);
                continue;
 
-            case hash_logfile :\r
+            case hash_logfile :
                freez((char *)logfile);
                logfile = strdup(arg);
                continue;
 
-            case hash_blockfile :\r
+            case hash_blockfile :
                freez((char *)blockfile);
                blockfile = strdup(arg);
                continue;
 
 #ifdef USE_IMAGE_LIST
-            case hash_imagefile :\r
+            case hash_imagefile :
                freez((char *)imagefile);
                imagefile = strdup(arg);
                continue;
 #endif /* def USE_IMAGE_LIST */
 
 #ifdef JAR_FILES
-            case hash_jarfile :\r
+            case hash_jarfile :
                freez((char *)jarfile);
                jarfile = strdup(arg);
                continue;
 #endif /* def JAR_FILES */
 
-            case hash_listen_address :\r
+            case hash_listen_address :
                freez((char *)haddr);
                haddr = strdup(arg);
                continue;
 
-            case hash_forwardfile :\r
+            case hash_forwardfile :
                freez((char *)forwardfile);
                forwardfile = strdup(arg);
                continue;
 
 #ifdef ACL_FILES
-            case hash_aclfile :\r
+            case hash_aclfile :
                freez((char *)aclfile);
                aclfile = strdup(arg);
                continue;
 #endif /* def ACL_FILES */
 
-#ifdef KILLPOPUPS
-            case hash_popupfile :\r
-               freez((char *)popupfile);
-               popupfile = strdup(arg);
-               continue;
-
-            case hash_kill_all_popups :
-               kill_all_popups = 1;
-               continue;
-#endif /* def KILLPOPUPS */
-
 #ifdef PCRS
-            case hash_re_filterfile :\r
+            case hash_re_filterfile :
                freez((char *)re_filterfile);
                re_filterfile = strdup(arg);
                continue;
-
-            case hash_re_filter_all :
-               re_filter_all = 1;
-               log_error(LOG_LEVEL_REF, "re_filter policy is %s.",
-                          re_filter_all ? "RADICAL" : "SEMI-SMART");
-               continue;
 #endif /* def PCRS */
 
-            case hash_user_agent :\r
+            case hash_user_agent :
                freez((char *)uagent);
                uagent = strdup(arg);
                continue;
@@ -592,16 +633,22 @@ void load_config( int signum )
                 * or the misspelling used in the HTTP spec.
                 */
             case hash_referrer :
-            case hash_referer :\r
+            case hash_referer :
                freez((char *)referrer);
                referrer = strdup(arg);
                continue;
 
-            case hash_from :\r
+            case hash_from :
                freez((char *)from);
                from = strdup(arg);
                continue;
 
+#ifdef FAST_REDIRECTS
+            case hash_fast_redirects :
+               fast_redirects = 1;
+               continue;
+#endif /* def FAST_REDIRECTS */
+
 #ifdef _WIN_CONSOLE
             case hash_hide_console :
                hideConsole = 1;
@@ -679,7 +726,6 @@ void load_config( int signum )
 #endif /* ndef USE_IMAGE_LIST */
 #ifndef PCRS
             case hash_re_filterfile :
-            case hash_re_filter_all :
 #endif /* ndef PCRS */
 #ifndef TOGGLE
             case hash_toggle :
@@ -701,10 +747,6 @@ void load_config( int signum )
 #if !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST)
             case hash_tinygif :
 #endif /* !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) */
-#ifndef KILLPOPUPS
-            case hash_popupfile :
-            case hash_kill_all_popups :
-#endif /* ndef KILLPOPUPS */
 #ifndef JAR_FILES
             case hash_jarfile :
 #endif /* ndef JAR_FILES */
@@ -719,6 +761,11 @@ void load_config( int signum )
                continue;
 
             default :
+               /*
+                * I decided that I liked this better as a warning than an
+                * error.  To change back to an error, just change log level
+                * to LOG_LEVEL_FATAL.
+                */
                log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in "
                      "configuration file: \"%s\"", hash_string( cmd ), buf);
                p = malloc( BUFSIZ );
@@ -728,15 +775,6 @@ void load_config( int signum )
                   proxy_args->invocation = strsav( proxy_args->invocation, p );
                   freez( p );
                }
-               /*
-                * I decided that I liked this better as a warning than an
-                * error.
-                */
-
-               /*
-                * configret = 1;
-                * return;
-                */
                continue;
          }
       }
@@ -745,9 +783,9 @@ void load_config( int signum )
 
    init_error_log(Argv[0], logfile, debug);
 
-   if (cookiefile)
+   if (permissions_file)
    {
-      add_loader(load_cookiefile);
+      add_loader(load_permissions_file);
    }
 
    if (blockfile)
@@ -781,13 +819,6 @@ void load_config( int signum )
    }
 #endif /* def ACL_FILES */
 
-#ifdef KILLPOPUPS
-   if (popupfile)
-   {
-      add_loader(load_popupfile);
-   }
-#endif /* def KILLPOPUPS */
-
 #ifdef PCRS
    if (re_filterfile)
    {
@@ -800,9 +831,8 @@ void load_config( int signum )
    {
       if ( NULL == (jar = fopen(jarfile, "a")) )
       {
-         log_error(LOG_LEVEL_ERROR, "can't open jarfile '%s': %E", jarfile);
-         configret = 1;
-         return;
+         log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", jarfile);
+         /* Never get here - LOG_LEVEL_FATAL causes program exit */
       }
       setbuf(jar, NULL);
    }
@@ -827,9 +857,8 @@ void load_config( int signum )
       if (hport <= 0)
       {
          *--p = ':';
-         log_error(LOG_LEVEL_ERROR, "invalid bind port spec %s", haddr);
-         configret = 1;
-         return;
+         log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", haddr);
+         /* Never get here - LOG_LEVEL_FATAL causes program exit */
       }
       if (*haddr == '\0')
       {
@@ -839,8 +868,8 @@ void load_config( int signum )
 
    if (run_loader(NULL))
    {
-      configret = 1;
-      return;
+      log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
+      /* Never get here - LOG_LEVEL_FATAL causes program exit */
    }
 
 #ifdef JAR_FILES