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