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