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