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