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