.
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.39 2002/03/24 13:25:43 swa Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
5  *
6  * Purpose     :  Loads settings from the configuration file into
7  *                global variables.  This file contains both the
8  *                routine to load the configuration and the global
9  *                variables it writes to.
10  *
11  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
12  *                Privoxy team. http://www.privoxy.org/
13  *
14  *                Based on the Internet Junkbuster originally written
15  *                by and Copyright (C) 1997 Anonymous Coders and
16  *                Junkbusters Corporation.  http://www.junkbusters.com
17  *
18  *                This program is free software; you can redistribute it
19  *                and/or modify it under the terms of the GNU General
20  *                Public License as published by the Free Software
21  *                Foundation; either version 2 of the License, or (at
22  *                your option) any later version.
23  *
24  *                This program is distributed in the hope that it will
25  *                be useful, but WITHOUT ANY WARRANTY; without even the
26  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
27  *                PARTICULAR PURPOSE.  See the GNU General Public
28  *                License for more details.
29  *
30  *                The GNU General Public License should be included with
31  *                this file.  If not, you can view it at
32  *                http://www.gnu.org/copyleft/gpl.html
33  *                or write to the Free Software Foundation, Inc., 59
34  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
35  *
36  * Revisions   :
37  *    $Log: loadcfg.c,v $
38  *    Revision 1.39  2002/03/24 13:25:43  swa
39  *    name change related issues
40  *
41  *    Revision 1.38  2002/03/24 13:05:48  jongfoster
42  *    Renaming re_filterfile to filterfile
43  *
44  *    Revision 1.37  2002/03/16 23:54:06  jongfoster
45  *    Adding graceful termination feature, to help look for memory leaks.
46  *    If you enable this (which, by design, has to be done by hand
47  *    editing config.h) and then go to http://i.j.b/die, then the program
48  *    will exit cleanly after the *next* request.  It should free all the
49  *    memory that was used.
50  *
51  *    Revision 1.36  2002/03/13 00:27:05  jongfoster
52  *    Killing warnings
53  *
54  *    Revision 1.35  2002/03/07 03:52:44  oes
55  *    Set logging to tty for --no-daemon mode
56  *
57  *    Revision 1.34  2002/03/06 23:14:35  jongfoster
58  *    Trivial cosmetic changes to make function comments easier to find.
59  *
60  *    Revision 1.33  2002/03/05 04:52:42  oes
61  *    Deleted non-errlog debugging code
62  *
63  *    Revision 1.32  2002/03/04 18:24:53  oes
64  *    Re-enabled output of unknown config directive hash
65  *
66  *    Revision 1.31  2002/03/03 15:07:20  oes
67  *    Re-enabled automatic config reloading
68  *
69  *    Revision 1.30  2002/01/22 23:31:43  jongfoster
70  *    Replacing strsav() with string_append()
71  *
72  *    Revision 1.29  2002/01/17 21:02:30  jongfoster
73  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
74  *
75  *    Renaming free_url to free_url_spec, since it frees a struct url_spec.
76  *
77  *    Revision 1.28  2001/12/30 14:07:32  steudten
78  *    - Add signal handling (unix)
79  *    - Add SIGHUP handler (unix)
80  *    - Add creation of pidfile (unix)
81  *    - Add action 'top' in rc file (RH)
82  *    - Add entry 'SIGNALS' to manpage
83  *    - Add exit message to logfile (unix)
84  *
85  *    Revision 1.27  2001/11/07 00:02:13  steudten
86  *    Add line number in error output for lineparsing for
87  *    actionsfile and configfile.
88  *    Special handling for CLF added.
89  *
90  *    Revision 1.26  2001/11/05 21:41:43  steudten
91  *    Add changes to be a real daemon just for unix os.
92  *    (change cwd to /, detach from controlling tty, set
93  *    process group and session leader to the own process.
94  *    Add DBG() Macro.
95  *    Add some fatal-error log message for failed malloc().
96  *    Add '-d' if compiled with 'configure --with-debug' to
97  *    enable debug output.
98  *
99  *    Revision 1.25  2001/10/25 03:40:48  david__schmidt
100  *    Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
101  *    threads to call select() simultaneously.  So, it's time to do a real, live,
102  *    native OS/2 port.  See defines for __EMX__ (the porting layer) vs. __OS2__
103  *    (native). Both versions will work, but using __OS2__ offers multi-threading.
104  *
105  *    Revision 1.24  2001/10/23 21:40:30  jongfoster
106  *    Added support for enable-edit-actions and enable-remote-toggle config
107  *    file options.
108  *
109  *    Revision 1.23  2001/10/07 15:36:00  oes
110  *    Introduced new config option "buffer-limit"
111  *
112  *    Revision 1.22  2001/09/22 16:36:59  jongfoster
113  *    Removing unused parameter fs from read_config_line()
114  *
115  *    Revision 1.21  2001/09/16 17:10:43  jongfoster
116  *    Moving function savearg() here, since it was the only thing left in
117  *    showargs.c.
118  *
119  *    Revision 1.20  2001/07/30 22:08:36  jongfoster
120  *    Tidying up #defines:
121  *    - All feature #defines are now of the form FEATURE_xxx
122  *    - Permanently turned off WIN_GUI_EDIT
123  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
124  *
125  *    Revision 1.19  2001/07/15 17:45:16  jongfoster
126  *    Removing some unused #includes
127  *
128  *    Revision 1.18  2001/07/13 14:01:14  oes
129  *     - Removed all #ifdef PCRS
130  *     - Removed vim-settings
131  *
132  *    Revision 1.17  2001/06/29 13:31:03  oes
133  *    - Improved comments
134  *    - Fixed (actionsfile) and sorted hashes
135  *    - Introduced admin_address and proxy-info-url
136  *      as config parameters
137  *    - Renamed config->proxy_args_invocation (which didn't have
138  *      the invocation but the options!) to config->proxy_args
139  *    - Various adaptions
140  *    - Removed logentry from cancelled commit
141  *
142  *    Revision 1.16  2001/06/09 10:55:28  jongfoster
143  *    Changing BUFSIZ ==> BUFFER_SIZE
144  *
145  *    Revision 1.15  2001/06/07 23:13:40  jongfoster
146  *    Merging ACL and forward files into config file.
147  *    Cosmetic: Sorting config file options alphabetically.
148  *    Cosmetic: Adding brief syntax comments to config file options.
149  *
150  *    Revision 1.14  2001/06/07 14:46:25  joergs
151  *    Missing make_path() added for re_filterfile.
152  *
153  *    Revision 1.13  2001/06/05 22:33:54  jongfoster
154  *
155  *    Fixed minor memory leak.
156  *    Also now uses make_path to prepend the pathnames.
157  *
158  *    Revision 1.12  2001/06/05 20:04:09  jongfoster
159  *    Now uses _snprintf() in place of snprintf() under Win32.
160  *
161  *    Revision 1.11  2001/06/04 18:31:58  swa
162  *    files are now prefixed with either `confdir' or `logdir'.
163  *    `make redhat-dist' replaces both entries confdir and logdir
164  *    with redhat values
165  *
166  *    Revision 1.10  2001/06/03 19:11:54  oes
167  *    introduced confdir option
168  *
169  *    Revision 1.9  2001/06/01 20:06:24  jongfoster
170  *    Removed support for "tinygif" option - moved to actions file.
171  *
172  *    Revision 1.8  2001/05/31 21:27:13  jongfoster
173  *    Removed many options from the config file and into the
174  *    "actions" file: add_forwarded, suppress_vanilla_wafer,
175  *    wafer, add_header, user_agent, referer, from
176  *    Also globally replaced "permission" with "action".
177  *
178  *    Revision 1.7  2001/05/29 09:50:24  jongfoster
179  *    Unified blocklist/imagelist/permissionslist.
180  *    File format is still under discussion, but the internal changes
181  *    are (mostly) done.
182  *
183  *    Also modified interceptor behaviour:
184  *    - We now intercept all URLs beginning with one of the following
185  *      prefixes (and *only* these prefixes):
186  *        * http://i.j.b/
187  *        * http://ijbswa.sf.net/config/
188  *        * http://ijbswa.sourceforge.net/config/
189  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
190  *    - Internal changes so that intercepted and fast redirect pages
191  *      are not replaced with an image.
192  *    - Interceptors now have the option to send a binary page direct
193  *      to the client. (i.e. ijb-send-banner uses this)
194  *    - Implemented show-url-info interceptor.  (Which is why I needed
195  *      the above interceptors changes - a typical URL is
196  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
197  *      The previous mechanism would not have intercepted that, and
198  *      if it had been intercepted then it then it would have replaced
199  *      it with an image.)
200  *
201  *    Revision 1.6  2001/05/26 00:28:36  jongfoster
202  *    Automatic reloading of config file.
203  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
204  *    Most of the global variables have been moved to a new
205  *    struct configuration_spec, accessed through csp->config->globalname
206  *    Most of the globals remaining are used by the Win32 GUI.
207  *
208  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
209  *    Hard tabs->Spaces
210  *
211  *    Revision 1.4  2001/05/22 18:46:04  oes
212  *
213  *    - Enabled filtering banners by size rather than URL
214  *      by adding patterns that replace all standard banner
215  *      sizes with the "Junkbuster" gif to the re_filterfile
216  *
217  *    - Enabled filtering WebBugs by providing a pattern
218  *      which kills all 1x1 images
219  *
220  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
221  *      which is selected by the (nonstandard and therefore
222  *      capital) letter 'U' in the option string.
223  *      It causes the quantifiers to be ungreedy by default.
224  *      Appending a ? turns back to greedy (!).
225  *
226  *    - Added a new interceptor ijb-send-banner, which
227  *      sends back the "Junkbuster" gif. Without imagelist or
228  *      MSIE detection support, or if tinygif = 1, or the
229  *      URL isn't recognized as an imageurl, a lame HTML
230  *      explanation is sent instead.
231  *
232  *    - Added new feature, which permits blocking remote
233  *      script redirects and firing back a local redirect
234  *      to the browser.
235  *      The feature is conditionally compiled, i.e. it
236  *      can be disabled with --disable-fast-redirects,
237  *      plus it must be activated by a "fast-redirects"
238  *      line in the config file, has its own log level
239  *      and of course wants to be displayed by show-proxy-args
240  *      Note: Boy, all the #ifdefs in 1001 locations and
241  *      all the fumbling with configure.in and acconfig.h
242  *      were *way* more work than the feature itself :-(
243  *
244  *    - Because a generic redirect template was needed for
245  *      this, tinygif = 3 now uses the same.
246  *
247  *    - Moved GIFs, and other static HTTP response templates
248  *      to project.h
249  *
250  *    - Some minor fixes
251  *
252  *    - Removed some >400 CRs again (Jon, you really worked
253  *      a lot! ;-)
254  *
255  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
256  *    Version 2.9.4 checkin.
257  *    - Merged popupfile and cookiefile, and added control over PCRS
258  *      filtering, in new "permissionsfile".
259  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
260  *      file error you now get a message box (in the Win32 GUI) rather
261  *      than the program exiting with no explanation.
262  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
263  *      skipping.
264  *    - Removed tabs from "config"
265  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
266  *    - Bumped up version number.
267  *
268  *    Revision 1.2  2001/05/17 23:01:01  oes
269  *     - Cleaned CRLF's from the sources and related files
270  *
271  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
272  *    Initial import of version 2.9.3 source tree
273  *
274  *
275  *********************************************************************/
276 \f
277
278 #include "config.h"
279
280 #include <stdio.h>
281 #include <sys/types.h>
282 #include <stdlib.h>
283 #include <string.h>
284 #include <signal.h>
285 #include <fcntl.h>
286 #include <errno.h>
287 #include <ctype.h>
288 #include <assert.h>
289
290 #ifdef _WIN32
291
292 # include <windows.h>
293
294 # include "win32.h"
295 # ifndef _WIN_CONSOLE
296 #  include "w32log.h"
297 # endif /* ndef _WIN_CONSOLE */
298
299 /* VC++ has "_snprintf", not "snprintf" */
300 #define snprintf _snprintf
301
302 #else /* ifndef _WIN32 */
303
304 #ifndef __OS2__
305 # include <unistd.h>
306 # include <sys/wait.h>
307 #endif
308 # include <sys/time.h>
309 # include <sys/stat.h>
310 # include <signal.h>
311
312 #endif
313
314 #include "loadcfg.h"
315 #include "list.h"
316 #include "jcc.h"
317 #include "filters.h"
318 #include "loaders.h"
319 #include "miscutil.h"
320 #include "errlog.h"
321 #include "ssplit.h"
322 #include "encode.h"
323 #include "urlmatch.h"
324
325 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
326
327 /*
328  * Fix a problem with Solaris.  There should be no effect on other
329  * platforms.
330  * Solaris's isspace() is a macro which uses it's argument directly
331  * as an array index.  Therefore we need to make sure that high-bit
332  * characters generate +ve values, and ideally we also want to make
333  * the argument match the declared parameter type of "int".
334  */
335 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
336 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
337
338 #ifdef FEATURE_TOGGLE
339 /* by haroon - indicates if ijb is enabled */
340 int g_bToggleIJB        = 1;   /* JunkBusters is enabled by default. */
341 #endif /* def FEATURE_TOGGLE */
342
343 /* The filename of the configfile */
344 const char *configfile  = NULL;
345
346 /*
347  * CGI functions will later need access to the invocation args,
348  * so we will make argc and argv global.
349  */
350 int Argc = 0;
351 const char **Argv = NULL;
352
353 static struct file_list *current_configfile = NULL;
354
355
356 /*
357  * This takes the "cryptic" hash of each keyword and aliases them to
358  * something a little more readable.  This also makes changing the
359  * hash values easier if they should change or the hash algorthm changes.
360  * Use the included "hash" program to find out what the hash will be
361  * for any string supplied on the command line.  (Or just put it in the
362  * config file and read the number from the error message in the log).
363  *
364  * Please keep this list sorted alphabetically (but with the Windows
365  * console and GUI specific options last).
366  */
367
368 #define hash_actions_file              1196306641ul /* "actionsfile" */
369 #define hash_admin_address             4112573064ul /* "admin-address" */
370 #define hash_buffer_limit              1881726070ul /* "buffer-limit */
371 #define hash_confdir                      1978389ul /* "confdir" */
372 #define hash_debug                          78263ul /* "debug" */
373 #define hash_deny_access               1227333715ul /* "deny-access" */
374 #define hash_enable_edit_actions       2517097536ul /* "enable-edit-actions" */
375 #define hash_enable_remote_toggle      2979744683ul /* "enable-remote-toggle" */
376 #define hash_filterfile                 250887266ul /* "filterfile" */
377 #define hash_forward                      2029845ul /* "forward" */
378 #define hash_forward_socks4            3963965521ul /* "forward-socks4" */
379 #define hash_forward_socks4a           2639958518ul /* "forward-socks4a" */
380 #define hash_jarfile                      2046641ul /* "jarfile" */
381 #define hash_listen_address            1255650842ul /* "listen-address" */
382 #define hash_logdir                        422889ul /* "logdir" */
383 #define hash_logfile                      2114766ul /* "logfile" */
384 #define hash_permit_access             3587953268ul /* "permit-access" */
385 #define hash_proxy_info_url            3903079059ul /* "proxy-info-url" */
386 #define hash_single_threaded           4250084780ul /* "single-threaded" */
387 #define hash_suppress_blocklists       1948693308ul /* "suppress-blocklists" */
388 #define hash_toggle                        447966ul /* "toggle" */
389 #define hash_trust_info_url             430331967ul /* "trust-info-url" */
390 #define hash_trustfile                   56494766ul /* "trustfile" */
391
392 #define hash_activity_animation        1817904738ul /* "activity-animation" */
393 #define hash_close_button_minimizes    3651284693ul /* "close-button-minimizes" */
394 #define hash_hide_console              2048809870ul /* "hide-console" */
395 #define hash_log_buffer_size           2918070425ul /* "log-buffer-size" */
396 #define hash_log_font_name             2866730124ul /* "log-font-name" */
397 #define hash_log_font_size             2866731014ul /* "log-font-size" */
398 #define hash_log_highlight_messages    4032101240ul /* "log-highlight-messages" */
399 #define hash_log_max_lines             2868344173ul /* "log-max-lines" */
400 #define hash_log_messages              2291744899ul /* "log-messages" */
401 #define hash_show_on_task_bar           215410365ul /* "show-on-task-bar" */
402
403
404 static void savearg(char *command, char *argument, struct configuration_spec * config);
405
406 /*********************************************************************
407  *
408  * Function    :  unload_configfile
409  *
410  * Description :  Free the config structure and all components.
411  *
412  * Parameters  :
413  *          1  :  data: struct configuration_spec to unload
414  *
415  * Returns     :  N/A
416  *
417  *********************************************************************/
418 void unload_configfile (void * data)
419 {
420    struct configuration_spec * config = (struct configuration_spec *)data;
421    struct forward_spec *cur_fwd = config->forward;
422 #ifdef FEATURE_ACL
423    struct access_control_list *cur_acl = config->acl;
424
425    while (cur_acl != NULL)
426    {
427       struct access_control_list * next_acl = cur_acl->next;
428       free(cur_acl);
429       cur_acl = next_acl;
430    }
431    config->acl = NULL;
432 #endif /* def FEATURE_ACL */
433
434    while (cur_fwd != NULL)
435    {
436       struct forward_spec * next_fwd = cur_fwd->next;
437       free_url_spec(cur_fwd->url);
438
439       freez(cur_fwd->gateway_host);
440       freez(cur_fwd->forward_host);
441       free(cur_fwd);
442       cur_fwd = next_fwd;
443    }
444    config->forward = NULL;
445
446 #ifdef FEATURE_COOKIE_JAR
447    if ( NULL != config->jar )
448    {
449       fclose( config->jar );
450       config->jar = NULL;
451    }
452 #endif /* def FEATURE_COOKIE_JAR */
453
454    freez(config->confdir);
455    freez(config->logdir);
456
457    freez(config->haddr);
458    freez(config->logfile);
459
460    freez(config->actions_file);
461    freez(config->admin_address);
462    freez(config->proxy_info_url);
463    freez(config->proxy_args);
464
465 #ifdef FEATURE_COOKIE_JAR
466    freez(config->jarfile);
467 #endif /* def FEATURE_COOKIE_JAR */
468
469    freez(config->re_filterfile);
470
471 }
472
473
474 #ifdef FEATURE_GRACEFUL_TERMINATION
475 /*********************************************************************
476  *
477  * Function    :  unload_current_config_file
478  *
479  * Description :  Unloads current config file - reset to state at
480  *                beginning of program.
481  *
482  * Parameters  :  None
483  *
484  * Returns     :  N/A
485  *
486  *********************************************************************/
487 void unload_current_config_file(void)
488 {
489    if (current_configfile)
490    {
491       current_configfile->unloader = unload_configfile;
492       current_configfile = NULL;
493    }
494 }
495 #endif
496
497
498 /*********************************************************************
499  *
500  * Function    :  load_config
501  *
502  * Description :  Load the config file and all parameters.
503  *
504  * Parameters  :
505  *          1  :  csp = Client state (the config member will be
506  *                filled in by this function).
507  *
508  * Returns     :  0 => Ok, everything else is an error.
509  *
510  *********************************************************************/
511 struct configuration_spec * load_config(void)
512 {
513    char buf[BUFFER_SIZE];
514    char *p, *q;
515    FILE *configfp = NULL;
516    struct configuration_spec * config = NULL;
517    struct client_state * fake_csp;
518    struct file_list *fs;
519    unsigned long linenum = 0;
520
521    if ( !check_file_changed(current_configfile, configfile, &fs))
522    {
523       /* No need to load */
524       return ((struct configuration_spec *)current_configfile->f);
525    }
526    if (!fs)
527    {
528       log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s':  %E",
529                 configfile);
530    }
531
532    log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
533
534 #ifdef FEATURE_TOGGLE
535    g_bToggleIJB      = 1;
536 #endif /* def FEATURE_TOGGLE */
537
538    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
539
540    if (config==NULL)
541    {
542       freez(fs->filename);
543       freez(fs);
544       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
545       /* Never get here - LOG_LEVEL_FATAL causes program exit */
546    }
547
548    /*
549     * This is backwards from how it's usually done.
550     * Following the usual pattern, "fs" would be stored in a member
551     * variable in "csp", and then we'd access "config" from "fs->f",
552     * using a cast.  However, "config" is used so often that a
553     * cast each time would be very ugly, and the extra indirection
554     * would waste CPU cycles.  Therefore we store "config" in
555     * "csp->config", and "fs" in "csp->config->config_file_list".
556     */
557    config->config_file_list = fs;
558
559    /*
560     * Set to defaults
561     */
562
563    config->multi_threaded    = 1;
564    config->hport             = HADDR_PORT;
565    config->buffer_limit      = 4096 * 1024;
566    config->proxy_args        = strdup("");
567
568    if ((configfp = fopen(configfile, "r")) == NULL)
569    {
570       log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s':  %E",
571               configfile);
572       /* Never get here - LOG_LEVEL_FATAL causes program exit */
573    }
574
575    while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
576    {
577       char cmd[BUFFER_SIZE];
578       char arg[BUFFER_SIZE];
579       char tmp[BUFFER_SIZE];
580 #ifdef FEATURE_ACL
581       struct access_control_list *cur_acl;
582 #endif /* def FEATURE_ACL */
583       struct forward_spec *cur_fwd;
584       int vec_count;
585       char *vec[3];
586
587       strcpy(tmp, buf);
588
589       /* Copy command (i.e. up to space or tab) into cmd */
590       p = buf;
591       q = cmd;
592       while (*p && (*p != ' ') && (*p != '\t'))
593       {
594          *q++ = *p++;
595       }
596       *q = '\0';
597
598       /* Skip over the whitespace in buf */
599       while (*p && ((*p == ' ') || (*p == '\t')))
600       {
601          p++;
602       }
603
604       /* Copy the argument into arg */
605       strcpy(arg, p);
606
607       /* Should never happen, but check this anyway */
608       if (*cmd == '\0')
609       {
610          continue;
611       }
612
613       /* Make sure the command field is lower case */
614       for (p=cmd; *p; p++)
615       {
616          if (ijb_isupper(*p))
617          {
618             *p = ijb_tolower(*p);
619          }
620       }
621
622       /* Save the argument for show-proxy-args */
623       savearg(cmd, arg, config);
624
625
626       switch( hash_string( cmd ) )
627       {
628 /* *************************************************************************
629  * actionsfile actions-file-name
630  * In confdir by default
631  * *************************************************************************/
632          case hash_actions_file :
633             freez(config->actions_file);
634             config->actions_file = make_path(config->confdir, arg);
635             continue;
636
637 /* *************************************************************************
638  * admin-address email-address
639  * *************************************************************************/
640          case hash_admin_address :
641             freez(config->admin_address);
642             config->admin_address = strdup(arg);
643             continue;
644
645 /* *************************************************************************
646  * buffer-limit n
647  * *************************************************************************/
648          case hash_buffer_limit :
649             config->buffer_limit = (size_t) 1024 * atoi(arg);
650             continue;
651
652 /* *************************************************************************
653  * confdir directory-name
654  * *************************************************************************/
655          case hash_confdir :
656             freez(config->confdir);
657             config->confdir = make_path( NULL, arg);
658             continue;
659
660 /* *************************************************************************
661  * debug n
662  * Specifies debug level, multiple values are ORed together.
663  * *************************************************************************/
664          case hash_debug :
665             config->debug |= atoi(arg);
666             continue;
667
668 /* *************************************************************************
669  * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
670  * *************************************************************************/
671 #ifdef FEATURE_ACL
672          case hash_deny_access:
673             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
674
675             if ((vec_count != 1) && (vec_count != 2))
676             {
677                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
678                      "deny-access directive in configuration file.");
679                string_append(&config->proxy_args,
680                   "<br>\nWARNING: Wrong number of parameters for "
681                   "deny-access directive in configuration file.<br><br>\n");
682                continue;
683             }
684
685             /* allocate a new node */
686             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
687
688             if (cur_acl == NULL)
689             {
690                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
691                /* Never get here - LOG_LEVEL_FATAL causes program exit */
692                continue;
693             }
694             cur_acl->action = ACL_DENY;
695
696             if (acl_addr(vec[0], cur_acl->src) < 0)
697             {
698                log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access "
699                      "directive in configuration file: \"%s\"", vec[0]);
700                string_append(&config->proxy_args,
701                   "<br>\nWARNING: Invalid source IP for deny-access directive"
702                   " in configuration file: \"");
703                string_append(&config->proxy_args,
704                   vec[0]);
705                string_append(&config->proxy_args,
706                   "\"<br><br>\n");
707                freez(cur_acl);
708                continue;
709             }
710             if (vec_count == 2)
711             {
712                if (acl_addr(vec[1], cur_acl->dst) < 0)
713                {
714                   log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access "
715                         "directive in configuration file: \"%s\"", vec[0]);
716                   string_append(&config->proxy_args,
717                      "<br>\nWARNING: Invalid destination IP for deny-access directive"
718                      " in configuration file: \"");
719                   string_append(&config->proxy_args,
720                      vec[0]);
721                   string_append(&config->proxy_args,
722                      "\"<br><br>\n");
723                   freez(cur_acl);
724                   continue;
725                }
726             }
727
728             /*
729              * Add it to the list.  Note we reverse the list to get the
730              * behaviour the user expects.  With both the ACL and
731              * actions file, the last match wins.  However, the internal
732              * implementations are different:  The actions file is stored
733              * in the same order as the file, and scanned completely.
734              * With the ACL, we reverse the order as we load it, then
735              * when we scan it we stop as soon as we get a match.
736              */
737             cur_acl->next  = config->acl;
738             config->acl = cur_acl;
739
740             continue;
741 #endif /* def FEATURE_ACL */
742
743 /* *************************************************************************
744  * enable-edit-actions 0|1
745  * *************************************************************************/
746 #ifdef FEATURE_CGI_EDIT_ACTIONS
747          case hash_enable_edit_actions:
748             if ((*arg != '\0') && (0 != atoi(arg)))
749             {
750                config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
751             }
752             else
753             {
754                config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
755             }
756             continue;
757 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
758
759 /* *************************************************************************
760  * enable-remote-toggle 0|1
761  * *************************************************************************/
762 #ifdef FEATURE_CGI_EDIT_ACTIONS
763          case hash_enable_remote_toggle:
764             if ((*arg != '\0') && (0 != atoi(arg)))
765             {
766                config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
767             }
768             else
769             {
770                config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
771             }
772             continue;
773 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
774
775 /* *************************************************************************
776  * forward url-pattern (.|http-proxy-host[:port])
777  * *************************************************************************/
778          case hash_forward:
779             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
780
781             if (vec_count != 2)
782             {
783                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
784                      "directive in configuration file.");
785                string_append(&config->proxy_args,
786                   "<br>\nWARNING: Wrong number of parameters for "
787                   "forward directive in configuration file.");
788                continue;
789             }
790
791             /* allocate a new node */
792             cur_fwd = zalloc(sizeof(*cur_fwd));
793             if (cur_fwd == NULL)
794             {
795                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
796                /* Never get here - LOG_LEVEL_FATAL causes program exit */
797                continue;
798             }
799
800             cur_fwd->type = SOCKS_NONE;
801
802             /* Save the URL pattern */
803             if (create_url_spec(cur_fwd->url, vec[0]))
804             {
805                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
806                      "directive in configuration file.");
807                string_append(&config->proxy_args,
808                   "<br>\nWARNING: Bad URL specifier for "
809                   "forward directive in configuration file.");
810                continue;
811             }
812
813             /* Parse the parent HTTP proxy host:port */
814             p = vec[1];
815
816             if (strcmp(p, ".") != 0)
817             {
818                cur_fwd->forward_host = strdup(p);
819
820                if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
821                {
822                   *p++ = '\0';
823                   cur_fwd->forward_port = atoi(p);
824                }
825
826                if (cur_fwd->forward_port <= 0)
827                {
828                   cur_fwd->forward_port = 8000;
829                }
830             }
831
832             /* Add to list. */
833             cur_fwd->next = config->forward;
834             config->forward = cur_fwd;
835
836             continue;
837
838 /* *************************************************************************
839  * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
840  * *************************************************************************/
841          case hash_forward_socks4:
842             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
843
844             if (vec_count != 3)
845             {
846                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
847                      "forward-socks4 directive in configuration file.");
848                string_append(&config->proxy_args,
849                   "<br>\nWARNING: Wrong number of parameters for "
850                   "forward-socks4 directive in configuration file.");
851                continue;
852             }
853
854             /* allocate a new node */
855             cur_fwd = zalloc(sizeof(*cur_fwd));
856             if (cur_fwd == NULL)
857             {
858                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
859                /* Never get here - LOG_LEVEL_FATAL causes program exit */
860                continue;
861             }
862
863             cur_fwd->type = SOCKS_4;
864
865             /* Save the URL pattern */
866             if (create_url_spec(cur_fwd->url, vec[0]))
867             {
868                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
869                      "directive in configuration file.");
870                string_append(&config->proxy_args,
871                   "<br>\nWARNING: Bad URL specifier for "
872                   "forward-socks4 directive in configuration file.");
873                continue;
874             }
875
876             /* Parse the SOCKS proxy host[:port] */
877             p = vec[1];
878
879             if (strcmp(p, ".") != 0)
880             {
881                cur_fwd->gateway_host = strdup(p);
882
883                if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
884                {
885                   *p++ = '\0';
886                   cur_fwd->gateway_port = atoi(p);
887                }
888                if (cur_fwd->gateway_port <= 0)
889                {
890                   cur_fwd->gateway_port = 1080;
891                }
892             }
893
894             /* Parse the parent HTTP proxy host[:port] */
895             p = vec[2];
896
897             if (strcmp(p, ".") != 0)
898             {
899                cur_fwd->forward_host = strdup(p);
900
901                if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
902                {
903                   *p++ = '\0';
904                   cur_fwd->forward_port = atoi(p);
905                }
906
907                if (cur_fwd->forward_port <= 0)
908                {
909                   cur_fwd->forward_port = 8000;
910                }
911             }
912
913             /* Add to list. */
914             cur_fwd->next = config->forward;
915             config->forward = cur_fwd;
916
917             continue;
918
919 /* *************************************************************************
920  * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
921  * *************************************************************************/
922          case hash_forward_socks4a:
923             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
924
925             if (vec_count != 3)
926             {
927                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
928                      "forward-socks4a directive in configuration file.");
929                string_append(&config->proxy_args,
930                   "<br>\nWARNING: Wrong number of parameters for "
931                   "forward-socks4a directive in configuration file.");
932                continue;
933             }
934
935             /* allocate a new node */
936             cur_fwd = zalloc(sizeof(*cur_fwd));
937             if (cur_fwd == NULL)
938             {
939                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
940                /* Never get here - LOG_LEVEL_FATAL causes program exit */
941                continue;
942             }
943
944             cur_fwd->type = SOCKS_4A;
945
946             /* Save the URL pattern */
947             if (create_url_spec(cur_fwd->url, vec[0]))
948             {
949                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
950                      "directive in configuration file.");
951                string_append(&config->proxy_args,
952                   "<br>\nWARNING: Bad URL specifier for "
953                   "forward-socks4a directive in configuration file.");
954                continue;
955             }
956
957             /* Parse the SOCKS proxy host[:port] */
958             p = vec[1];
959
960             cur_fwd->gateway_host = strdup(p);
961
962             if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
963             {
964                *p++ = '\0';
965                cur_fwd->gateway_port = atoi(p);
966             }
967             if (cur_fwd->gateway_port <= 0)
968             {
969                cur_fwd->gateway_port = 1080;
970             }
971
972             /* Parse the parent HTTP proxy host[:port] */
973             p = vec[2];
974
975             if (strcmp(p, ".") != 0)
976             {
977                cur_fwd->forward_host = strdup(p);
978
979                if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
980                {
981                   *p++ = '\0';
982                   cur_fwd->forward_port = atoi(p);
983                }
984
985                if (cur_fwd->forward_port <= 0)
986                {
987                   cur_fwd->forward_port = 8000;
988                }
989             }
990
991             /* Add to list. */
992             cur_fwd->next = config->forward;
993             config->forward = cur_fwd;
994
995             continue;
996
997 /* *************************************************************************
998  * jarfile jar-file-name
999  * In logdir by default
1000  * *************************************************************************/
1001 #ifdef FEATURE_COOKIE_JAR
1002          case hash_jarfile :
1003             freez(config->jarfile);
1004             config->jarfile = make_path(config->logdir, arg);
1005             continue;
1006 #endif /* def FEATURE_COOKIE_JAR */
1007
1008 /* *************************************************************************
1009  * listen-address [ip][:port]
1010  * *************************************************************************/
1011          case hash_listen_address :
1012             freez(config->haddr);
1013             config->haddr = strdup(arg);
1014             continue;
1015
1016 /* *************************************************************************
1017  * logdir directory-name
1018  * *************************************************************************/
1019          case hash_logdir :
1020             freez(config->logdir);
1021             config->logdir = make_path(NULL, arg);
1022             continue;
1023
1024 /* *************************************************************************
1025  * logfile log-file-name
1026  * In logdir by default
1027  * *************************************************************************/
1028          case hash_logfile :
1029             freez(config->logfile);
1030             config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1031             continue;
1032
1033 /* *************************************************************************
1034  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1035  * *************************************************************************/
1036 #ifdef FEATURE_ACL
1037          case hash_permit_access:
1038             vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1039
1040             if ((vec_count != 1) && (vec_count != 2))
1041             {
1042                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1043                      "permit-access directive in configuration file.");
1044                string_append(&config->proxy_args,
1045                   "<br>\nWARNING: Wrong number of parameters for "
1046                   "permit-access directive in configuration file.<br><br>\n");
1047
1048                continue;
1049             }
1050
1051             /* allocate a new node */
1052             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1053
1054             if (cur_acl == NULL)
1055             {
1056                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1057                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1058                continue;
1059             }
1060             cur_acl->action = ACL_PERMIT;
1061
1062             if (acl_addr(vec[0], cur_acl->src) < 0)
1063             {
1064                log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access "
1065                      "directive in configuration file: \"%s\"", vec[0]);
1066                string_append(&config->proxy_args,
1067                   "<br>\nWARNING: Invalid source IP for permit-access directive"
1068                   " in configuration file: \"");
1069                string_append(&config->proxy_args,
1070                   vec[0]);
1071                string_append(&config->proxy_args,
1072                   "\"<br><br>\n");
1073                freez(cur_acl);
1074                continue;
1075             }
1076             if (vec_count == 2)
1077             {
1078                if (acl_addr(vec[1], cur_acl->dst) < 0)
1079                {
1080                   log_error(LOG_LEVEL_ERROR, "Invalid destination IP for "
1081                         "permit-access directive in configuration file: \"%s\"",
1082                         vec[0]);
1083                   string_append(&config->proxy_args,
1084                      "<br>\nWARNING: Invalid destination IP for permit-access directive"
1085                      " in configuration file: \"");
1086                   string_append(&config->proxy_args,
1087                      vec[0]);
1088                   string_append(&config->proxy_args,
1089                      "\"<br><br>\n");
1090                   freez(cur_acl);
1091                   continue;
1092                }
1093             }
1094
1095             /*
1096              * Add it to the list.  Note we reverse the list to get the
1097              * behaviour the user expects.  With both the ACL and
1098              * actions file, the last match wins.  However, the internal
1099              * implementations are different:  The actions file is stored
1100              * in the same order as the file, and scanned completely.
1101              * With the ACL, we reverse the order as we load it, then
1102              * when we scan it we stop as soon as we get a match.
1103              */
1104             cur_acl->next  = config->acl;
1105             config->acl = cur_acl;
1106
1107             continue;
1108 #endif /* def FEATURE_ACL */
1109
1110 /* *************************************************************************
1111  * proxy-info-url url
1112  * *************************************************************************/
1113          case hash_proxy_info_url :
1114             freez(config->proxy_info_url);
1115             config->proxy_info_url = strdup(arg);
1116             continue;
1117
1118 /* *************************************************************************
1119  * re_filterfile file-name
1120  * In confdir by default.
1121  * *************************************************************************/
1122          case hash_filterfile :
1123             freez(config->re_filterfile);
1124             config->re_filterfile = make_path(config->confdir, arg);
1125             continue;
1126
1127 /* *************************************************************************
1128  * single-threaded
1129  * *************************************************************************/
1130          case hash_single_threaded :
1131             config->multi_threaded = 0;
1132             continue;
1133
1134 /* *************************************************************************
1135  * toggle (0|1)
1136  * *************************************************************************/
1137 #ifdef FEATURE_TOGGLE
1138          case hash_toggle :
1139             g_bToggleIJB = atoi(arg);
1140             continue;
1141 #endif /* def FEATURE_TOGGLE */
1142
1143 /* *************************************************************************
1144  * trust-info-url url
1145  * *************************************************************************/
1146 #ifdef FEATURE_TRUST
1147          case hash_trust_info_url :
1148             enlist(config->trust_info, arg);
1149             continue;
1150 #endif /* def FEATURE_TRUST */
1151
1152 /* *************************************************************************
1153  * trustfile filename
1154  * (In confdir by default.)
1155  * *************************************************************************/
1156 #ifdef FEATURE_TRUST
1157          case hash_trustfile :
1158             freez(config->trustfile);
1159             config->trustfile = make_path(config->confdir, arg);
1160             continue;
1161 #endif /* def FEATURE_TRUST */
1162
1163
1164 /* *************************************************************************
1165  * Win32 Console options:
1166  * *************************************************************************/
1167
1168 /* *************************************************************************
1169  * hide-console
1170  * *************************************************************************/
1171 #ifdef _WIN_CONSOLE
1172          case hash_hide_console :
1173             hideConsole = 1;
1174             continue;
1175 #endif /*def _WIN_CONSOLE*/
1176
1177
1178 /* *************************************************************************
1179  * Win32 GUI options:
1180  * *************************************************************************/
1181
1182 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1183 /* *************************************************************************
1184  * activity-animation (0|1)
1185  * *************************************************************************/
1186          case hash_activity_animation :
1187             g_bShowActivityAnimation = atoi(arg);
1188             continue;
1189
1190 /* *************************************************************************
1191  *  close-button-minimizes (0|1)
1192  * *************************************************************************/
1193          case hash_close_button_minimizes :
1194             g_bCloseHidesWindow = atoi(arg);
1195             continue;
1196
1197 /* *************************************************************************
1198  * log-buffer-size (0|1)
1199  * *************************************************************************/
1200          case hash_log_buffer_size :
1201             g_bLimitBufferSize = atoi(arg);
1202             continue;
1203
1204 /* *************************************************************************
1205  * log-font-name fontnane
1206  * *************************************************************************/
1207          case hash_log_font_name :
1208             strcpy( g_szFontFaceName, arg );
1209             continue;
1210
1211 /* *************************************************************************
1212  * log-font-size n
1213  * *************************************************************************/
1214          case hash_log_font_size :
1215             g_nFontSize = atoi(arg);
1216             continue;
1217
1218 /* *************************************************************************
1219  * log-highlight-messages (0|1)
1220  * *************************************************************************/
1221          case hash_log_highlight_messages :
1222             g_bHighlightMessages = atoi(arg);
1223             continue;
1224
1225 /* *************************************************************************
1226  * log-max-lines n
1227  * *************************************************************************/
1228          case hash_log_max_lines :
1229             g_nMaxBufferLines = atoi(arg);
1230             continue;
1231
1232 /* *************************************************************************
1233  * log-messages (0|1)
1234  * *************************************************************************/
1235          case hash_log_messages :
1236             g_bLogMessages = atoi(arg);
1237             continue;
1238
1239 /* *************************************************************************
1240  * show-on-task-bar (0|1)
1241  * *************************************************************************/
1242          case hash_show_on_task_bar :
1243             g_bShowOnTaskBar = atoi(arg);
1244             continue;
1245
1246 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1247
1248
1249 /* *************************************************************************
1250  * Warnings about unsupported features
1251  * *************************************************************************/
1252 #ifndef FEATURE_ACL
1253          case hash_deny_access:
1254 #endif /* ndef FEATURE_ACL */
1255 #ifndef FEATURE_CGI_EDIT_ACTIONS
1256          case hash_enable_edit_actions:
1257          case hash_enable_remote_toggle:
1258 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1259 #ifndef FEATURE_COOKIE_JAR
1260          case hash_jarfile :
1261 #endif /* ndef FEATURE_COOKIE_JAR */
1262 #ifndef FEATURE_ACL
1263          case hash_permit_access:
1264 #endif /* ndef FEATURE_ACL */
1265 #ifndef FEATURE_TOGGLE
1266          case hash_toggle :
1267 #endif /* ndef FEATURE_TOGGLE */
1268 #ifndef FEATURE_TRUST
1269          case hash_trustfile :
1270          case hash_trust_info_url :
1271 #endif /* ndef FEATURE_TRUST */
1272
1273 #ifndef _WIN_CONSOLE
1274          case hash_hide_console :
1275 #endif /* ndef _WIN_CONSOLE */
1276
1277 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1278          case hash_activity_animation :
1279          case hash_close_button_minimizes :
1280          case hash_log_buffer_size :
1281          case hash_log_font_name :
1282          case hash_log_font_size :
1283          case hash_log_highlight_messages :
1284          case hash_log_max_lines :
1285          case hash_log_messages :
1286          case hash_show_on_task_bar :
1287 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1288             /* These warnings are annoying - so hide them. -- Jon */
1289             /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1290             continue;
1291
1292 /* *************************************************************************/
1293          default :
1294 /* *************************************************************************/
1295             /*
1296              * I decided that I liked this better as a warning than an
1297              * error.  To change back to an error, just change log level
1298              * to LOG_LEVEL_FATAL.
1299              */
1300             log_error(LOG_LEVEL_ERROR, "Unrecognized directive '%s' (%luul) in line %lu in "
1301                   "configuration file (%s).",  buf, hash_string(cmd), linenum, configfile);
1302             string_append(&config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
1303             string_append(&config->proxy_args, buf);
1304             string_append(&config->proxy_args, "<br><br>\n");
1305             continue;
1306
1307 /* *************************************************************************/
1308       } /* end switch( hash_string(cmd) ) */
1309    } /* end while ( read_config_line(...) ) */
1310
1311    fclose(configfp);
1312
1313    if (NULL == config->proxy_args)
1314    {
1315       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1316    }
1317
1318    init_error_log(Argv[0], config->logfile, config->debug);
1319
1320    if (config->actions_file)
1321    {
1322       add_loader(load_actions_file, config);
1323    }
1324
1325    if (config->re_filterfile)
1326    {
1327       add_loader(load_re_filterfile, config);
1328    }
1329
1330 #ifdef FEATURE_TRUST
1331    if (config->trustfile)
1332    {
1333       add_loader(load_trustfile, config);
1334    }
1335 #endif /* def FEATURE_TRUST */
1336
1337 #ifdef FEATURE_COOKIE_JAR
1338    if ( NULL != config->jarfile )
1339    {
1340       if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1341       {
1342          log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1343          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1344       }
1345       setbuf(config->jar, NULL);
1346    }
1347 #endif /* def FEATURE_COOKIE_JAR */
1348
1349    if ( NULL == config->haddr )
1350    {
1351       config->haddr = strdup( HADDR_DEFAULT );
1352    }
1353
1354    if ( NULL != config->haddr )
1355    {
1356       if (NULL != (p = strchr(config->haddr, ':')))
1357       {
1358          *p++ = '\0';
1359          if (*p)
1360          {
1361             config->hport = atoi(p);
1362          }
1363       }
1364
1365       if (config->hport <= 0)
1366       {
1367          *--p = ':';
1368          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1369          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1370       }
1371       if (*config->haddr == '\0')
1372       {
1373          config->haddr = NULL;
1374       }
1375    }
1376
1377    /*
1378     * Want to run all the loaders once now.
1379     *
1380     * Need to set up a fake csp, so they can get to the config.
1381     */
1382    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1383    fake_csp->config = config;
1384
1385    if (run_loader(fake_csp))
1386    {
1387       freez(fake_csp);
1388       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1389       /* Never get here - LOG_LEVEL_FATAL causes program exit */
1390    }
1391    freez(fake_csp);
1392
1393 /* FIXME: this is a kludge for win32 */
1394 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1395
1396    g_actions_file     = config->actions_file;
1397    g_re_filterfile    = config->re_filterfile;
1398
1399 #ifdef FEATURE_TRUST
1400    g_trustfile        = config->trustfile;
1401 #endif /* def FEATURE_TRUST */
1402
1403
1404 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1405 /* FIXME: end kludge */
1406
1407
1408    config->need_bind = 1;
1409
1410    if (current_configfile)
1411    {
1412       struct configuration_spec * oldcfg = (struct configuration_spec *)
1413                                            current_configfile->f;
1414       /*
1415        * Check if config->haddr,hport == oldcfg->haddr,hport
1416        *
1417        * The following could be written more compactly as a single,
1418        * (unreadably long) if statement.
1419        */
1420       config->need_bind = 0;
1421       if (config->hport != oldcfg->hport)
1422       {
1423          config->need_bind = 1;
1424       }
1425       else if (config->haddr == NULL)
1426       {
1427          if (oldcfg->haddr != NULL)
1428          {
1429             config->need_bind = 1;
1430          }
1431       }
1432       else if (oldcfg->haddr == NULL)
1433       {
1434          config->need_bind = 1;
1435       }
1436       else if (0 != strcmp(config->haddr, oldcfg->haddr))
1437       {
1438          config->need_bind = 1;
1439       }
1440
1441       current_configfile->unloader = unload_configfile;
1442    }
1443
1444    fs->next = files->next;
1445    files->next = fs;
1446
1447    current_configfile = fs;
1448
1449    return (config);
1450 }
1451
1452
1453 /*********************************************************************
1454  *
1455  * Function    :  savearg
1456  *
1457  * Description :  Called from `load_config'.  It saves each non-empty
1458  *                and non-comment line from config into
1459  *                config->proxy_args.  This is used to create the
1460  *                show-proxy-args page.  On error, frees
1461  *                config->proxy_args and sets it to NULL
1462  *
1463  * Parameters  :
1464  *          1  :  command = config setting that was found
1465  *          2  :  argument = the setting's argument (if any)
1466  *
1467  * Returns     :  N/A
1468  *
1469  *********************************************************************/
1470 static void savearg(char *command, char *argument, struct configuration_spec * config)
1471 {
1472    char * buf;
1473    char * s;
1474
1475    assert(command);
1476    assert(*command);
1477    assert(argument);
1478
1479    buf = strdup("");
1480
1481    s = html_encode(command);
1482    if (NULL == s)
1483    {
1484       freez(buf);
1485       freez(config->proxy_args);
1486       return;
1487    }
1488    string_append(&buf, "<a href=\"" REDIRECT_URL "option#");
1489    string_append(&buf, s);
1490    string_append(&buf, "\">");
1491    string_join  (&buf, s);
1492    string_append(&buf, "</a> ");
1493
1494    if ( (NULL != argument) && ('\0' != *argument) )
1495    {
1496       s = html_encode(argument);
1497       if (NULL == s)
1498       {
1499          freez(buf);
1500          freez(config->proxy_args);
1501          return;
1502       }
1503
1504       if (strncmpic(argument, "http://", 7) == 0)
1505       {
1506          string_append(&buf, "<a href=\"");
1507          string_append(&buf, s);
1508          string_append(&buf, "\">");
1509          string_join  (&buf, s);
1510          string_append(&buf, "</a>");
1511       }
1512       else
1513       {
1514          string_join  (&buf, s);
1515       }
1516    }
1517
1518    string_append(&buf, "<br>\n");
1519
1520    string_join(&config->proxy_args, buf);
1521 }
1522
1523
1524 /*
1525   Local Variables:
1526   tab-width: 3
1527   end:
1528 */