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