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