1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.63 2007/04/09 18:11:36 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
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.
11 * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge
12 * Privoxy team. http://www.privoxy.org/
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
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.
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.
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.
38 * Revision 1.63 2007/04/09 18:11:36 fabiankeil
39 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
41 * Revision 1.62 2007/03/17 15:20:05 fabiankeil
42 * New config option: enforce-blocks.
44 * Revision 1.61 2007/03/16 16:47:35 fabiankeil
45 * - Mention other reasons why acl directive loading might have failed.
46 * - Don't log the acl source if the acl destination is to blame.
48 * Revision 1.60 2007/01/27 13:09:16 fabiankeil
49 * Add new config option "templdir" to
50 * change the templates directory.
52 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
53 * Added config option accept-intercepted-requests
54 * and disabled it by default.
56 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
57 * Fix gcc43 compiler warnings.
59 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
60 * Add config option "split-large-forms"
61 * to work around the browser bug reported
64 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
65 * Move the <br> in the generated HTML for the config
66 * options from the beginning of the string to its end.
67 * Keeps the white space in balance.
69 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
70 * Fix memory leak in case of config file reloads.
72 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
73 * Modified kludge for win32 to make ming32 menu
74 * "Options/Edit Filters" (sort of) work again.
75 * Same limitations as for the action files apply.
78 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
79 * Incorporate modified version of Roland Rosenfeld's patch to
80 * optionally access the user-manual via Privoxy. Closes patch 679075.
82 * Formatting changed to Privoxy style, added call to
83 * cgi_error_no_template if the requested file doesn't
84 * exist and modified check whether or not Privoxy itself
85 * should serve the manual. Should work cross-platform now.
87 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
88 * Added config option enable-remote-http-toggle
89 * to specify if Privoxy should recognize special
90 * headers (currently only X-Filter) to change its
91 * behaviour. Disabled by default.
93 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
94 * Make number of retries in case of forwarded-connect problems
95 * a config file option (forwarded-connect-retries) and use 0 as
98 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
99 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
100 * with what was really the latest development (the v_3_0_branch branch)
102 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
103 * Don't forget to malloc space for the null terminator...
105 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
106 * Multiple filter file support
108 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
109 * Closed two memory leaks; hopefully the last remaining ones
110 * (in the main execution paths, anyway).
112 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
113 * Addressed bug #719435
114 * - Extraneous filterfile directives now logged as errors
115 * - This and unrecnonised directives now really obvious on status page
117 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
118 * Cosmetic: Renamed cryptic variable
120 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
121 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
123 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
124 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
126 * Revision 1.48 2002/05/14 21:30:38 oes
127 * savearg now uses own linking code instead of (now special-cased) add_help_link
129 * Revision 1.47 2002/05/12 21:36:29 jongfoster
130 * Correcting function comments
132 * Revision 1.46 2002/04/26 12:55:14 oes
133 * - New option "user-manual", defaults to our site
134 * via project.h #define
135 * - savearg now embeds option names in help links
137 * Revision 1.45 2002/04/24 02:11:54 oes
138 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
140 * Revision 1.44 2002/04/08 20:37:13 swa
143 * Revision 1.43 2002/04/08 20:36:50 swa
146 * Revision 1.42 2002/04/05 15:50:15 oes
147 * fix for invalid HTML proxy_args
149 * Revision 1.41 2002/03/31 17:19:00 jongfoster
150 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
152 * Revision 1.40 2002/03/26 22:29:55 swa
153 * we have a new homepage!
155 * Revision 1.39 2002/03/24 13:25:43 swa
156 * name change related issues
158 * Revision 1.38 2002/03/24 13:05:48 jongfoster
159 * Renaming re_filterfile to filterfile
161 * Revision 1.37 2002/03/16 23:54:06 jongfoster
162 * Adding graceful termination feature, to help look for memory leaks.
163 * If you enable this (which, by design, has to be done by hand
164 * editing config.h) and then go to http://i.j.b/die, then the program
165 * will exit cleanly after the *next* request. It should free all the
166 * memory that was used.
168 * Revision 1.36 2002/03/13 00:27:05 jongfoster
171 * Revision 1.35 2002/03/07 03:52:44 oes
172 * Set logging to tty for --no-daemon mode
174 * Revision 1.34 2002/03/06 23:14:35 jongfoster
175 * Trivial cosmetic changes to make function comments easier to find.
177 * Revision 1.33 2002/03/05 04:52:42 oes
178 * Deleted non-errlog debugging code
180 * Revision 1.32 2002/03/04 18:24:53 oes
181 * Re-enabled output of unknown config directive hash
183 * Revision 1.31 2002/03/03 15:07:20 oes
184 * Re-enabled automatic config reloading
186 * Revision 1.30 2002/01/22 23:31:43 jongfoster
187 * Replacing strsav() with string_append()
189 * Revision 1.29 2002/01/17 21:02:30 jongfoster
190 * Moving all our URL and URL pattern parsing code to urlmatch.c.
192 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
194 * Revision 1.28 2001/12/30 14:07:32 steudten
195 * - Add signal handling (unix)
196 * - Add SIGHUP handler (unix)
197 * - Add creation of pidfile (unix)
198 * - Add action 'top' in rc file (RH)
199 * - Add entry 'SIGNALS' to manpage
200 * - Add exit message to logfile (unix)
202 * Revision 1.27 2001/11/07 00:02:13 steudten
203 * Add line number in error output for lineparsing for
204 * actionsfile and configfile.
205 * Special handling for CLF added.
207 * Revision 1.26 2001/11/05 21:41:43 steudten
208 * Add changes to be a real daemon just for unix os.
209 * (change cwd to /, detach from controlling tty, set
210 * process group and session leader to the own process.
212 * Add some fatal-error log message for failed malloc().
213 * Add '-d' if compiled with 'configure --with-debug' to
214 * enable debug output.
216 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
217 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
218 * threads to call select() simultaneously. So, it's time to do a real, live,
219 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
220 * (native). Both versions will work, but using __OS2__ offers multi-threading.
222 * Revision 1.24 2001/10/23 21:40:30 jongfoster
223 * Added support for enable-edit-actions and enable-remote-toggle config
226 * Revision 1.23 2001/10/07 15:36:00 oes
227 * Introduced new config option "buffer-limit"
229 * Revision 1.22 2001/09/22 16:36:59 jongfoster
230 * Removing unused parameter fs from read_config_line()
232 * Revision 1.21 2001/09/16 17:10:43 jongfoster
233 * Moving function savearg() here, since it was the only thing left in
236 * Revision 1.20 2001/07/30 22:08:36 jongfoster
237 * Tidying up #defines:
238 * - All feature #defines are now of the form FEATURE_xxx
239 * - Permanently turned off WIN_GUI_EDIT
240 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
242 * Revision 1.19 2001/07/15 17:45:16 jongfoster
243 * Removing some unused #includes
245 * Revision 1.18 2001/07/13 14:01:14 oes
246 * - Removed all #ifdef PCRS
247 * - Removed vim-settings
249 * Revision 1.17 2001/06/29 13:31:03 oes
250 * - Improved comments
251 * - Fixed (actionsfile) and sorted hashes
252 * - Introduced admin_address and proxy-info-url
253 * as config parameters
254 * - Renamed config->proxy_args_invocation (which didn't have
255 * the invocation but the options!) to config->proxy_args
256 * - Various adaptions
257 * - Removed logentry from cancelled commit
259 * Revision 1.16 2001/06/09 10:55:28 jongfoster
260 * Changing BUFSIZ ==> BUFFER_SIZE
262 * Revision 1.15 2001/06/07 23:13:40 jongfoster
263 * Merging ACL and forward files into config file.
264 * Cosmetic: Sorting config file options alphabetically.
265 * Cosmetic: Adding brief syntax comments to config file options.
267 * Revision 1.14 2001/06/07 14:46:25 joergs
268 * Missing make_path() added for re_filterfile.
270 * Revision 1.13 2001/06/05 22:33:54 jongfoster
272 * Fixed minor memory leak.
273 * Also now uses make_path to prepend the pathnames.
275 * Revision 1.12 2001/06/05 20:04:09 jongfoster
276 * Now uses _snprintf() in place of snprintf() under Win32.
278 * Revision 1.11 2001/06/04 18:31:58 swa
279 * files are now prefixed with either `confdir' or `logdir'.
280 * `make redhat-dist' replaces both entries confdir and logdir
283 * Revision 1.10 2001/06/03 19:11:54 oes
284 * introduced confdir option
286 * Revision 1.9 2001/06/01 20:06:24 jongfoster
287 * Removed support for "tinygif" option - moved to actions file.
289 * Revision 1.8 2001/05/31 21:27:13 jongfoster
290 * Removed many options from the config file and into the
291 * "actions" file: add_forwarded, suppress_vanilla_wafer,
292 * wafer, add_header, user_agent, referer, from
293 * Also globally replaced "permission" with "action".
295 * Revision 1.7 2001/05/29 09:50:24 jongfoster
296 * Unified blocklist/imagelist/permissionslist.
297 * File format is still under discussion, but the internal changes
300 * Also modified interceptor behaviour:
301 * - We now intercept all URLs beginning with one of the following
302 * prefixes (and *only* these prefixes):
304 * * http://ijbswa.sf.net/config/
305 * * http://ijbswa.sourceforge.net/config/
306 * - New interceptors "home page" - go to http://i.j.b/ to see it.
307 * - Internal changes so that intercepted and fast redirect pages
308 * are not replaced with an image.
309 * - Interceptors now have the option to send a binary page direct
310 * to the client. (i.e. ijb-send-banner uses this)
311 * - Implemented show-url-info interceptor. (Which is why I needed
312 * the above interceptors changes - a typical URL is
313 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
314 * The previous mechanism would not have intercepted that, and
315 * if it had been intercepted then it then it would have replaced
318 * Revision 1.6 2001/05/26 00:28:36 jongfoster
319 * Automatic reloading of config file.
320 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
321 * Most of the global variables have been moved to a new
322 * struct configuration_spec, accessed through csp->config->globalname
323 * Most of the globals remaining are used by the Win32 GUI.
325 * Revision 1.5 2001/05/25 22:34:30 jongfoster
328 * Revision 1.4 2001/05/22 18:46:04 oes
330 * - Enabled filtering banners by size rather than URL
331 * by adding patterns that replace all standard banner
332 * sizes with the "Junkbuster" gif to the re_filterfile
334 * - Enabled filtering WebBugs by providing a pattern
335 * which kills all 1x1 images
337 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
338 * which is selected by the (nonstandard and therefore
339 * capital) letter 'U' in the option string.
340 * It causes the quantifiers to be ungreedy by default.
341 * Appending a ? turns back to greedy (!).
343 * - Added a new interceptor ijb-send-banner, which
344 * sends back the "Junkbuster" gif. Without imagelist or
345 * MSIE detection support, or if tinygif = 1, or the
346 * URL isn't recognized as an imageurl, a lame HTML
347 * explanation is sent instead.
349 * - Added new feature, which permits blocking remote
350 * script redirects and firing back a local redirect
352 * The feature is conditionally compiled, i.e. it
353 * can be disabled with --disable-fast-redirects,
354 * plus it must be activated by a "fast-redirects"
355 * line in the config file, has its own log level
356 * and of course wants to be displayed by show-proxy-args
357 * Note: Boy, all the #ifdefs in 1001 locations and
358 * all the fumbling with configure.in and acconfig.h
359 * were *way* more work than the feature itself :-(
361 * - Because a generic redirect template was needed for
362 * this, tinygif = 3 now uses the same.
364 * - Moved GIFs, and other static HTTP response templates
369 * - Removed some >400 CRs again (Jon, you really worked
372 * Revision 1.3 2001/05/20 01:21:20 jongfoster
373 * Version 2.9.4 checkin.
374 * - Merged popupfile and cookiefile, and added control over PCRS
375 * filtering, in new "permissionsfile".
376 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
377 * file error you now get a message box (in the Win32 GUI) rather
378 * than the program exiting with no explanation.
379 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
381 * - Removed tabs from "config"
382 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
383 * - Bumped up version number.
385 * Revision 1.2 2001/05/17 23:01:01 oes
386 * - Cleaned CRLF's from the sources and related files
388 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
389 * Initial import of version 2.9.3 source tree
392 *********************************************************************/
398 #include <sys/types.h>
412 # include <windows.h>
415 # ifndef _WIN_CONSOLE
417 # endif /* ndef _WIN_CONSOLE */
419 #else /* ifndef _WIN32 */
423 # include <sys/wait.h>
425 # include <sys/time.h>
426 # include <sys/stat.h>
436 #include "miscutil.h"
440 #include "urlmatch.h"
443 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
446 * Fix a problem with Solaris. There should be no effect on other
448 * Solaris's isspace() is a macro which uses it's argument directly
449 * as an array index. Therefore we need to make sure that high-bit
450 * characters generate +ve values, and ideally we also want to make
451 * the argument match the declared parameter type of "int".
453 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
454 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
456 #ifdef FEATURE_TOGGLE
457 /* Privoxy is enabled by default. */
458 int global_toggle_state = 1;
459 #endif /* def FEATURE_TOGGLE */
461 /* The filename of the configfile */
462 const char *configfile = NULL;
465 * CGI functions will later need access to the invocation args,
466 * so we will make argc and argv global.
469 const char **Argv = NULL;
471 static struct file_list *current_configfile = NULL;
475 * This takes the "cryptic" hash of each keyword and aliases them to
476 * something a little more readable. This also makes changing the
477 * hash values easier if they should change or the hash algorthm changes.
478 * Use the included "hash" program to find out what the hash will be
479 * for any string supplied on the command line. (Or just put it in the
480 * config file and read the number from the error message in the log).
482 * Please keep this list sorted alphabetically (but with the Windows
483 * console and GUI specific options last).
486 #define hash_actions_file 1196306641ul /* "actionsfile" */
487 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
488 #define hash_admin_address 4112573064ul /* "admin-address" */
489 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
490 #define hash_confdir 1978389ul /* "confdir" */
491 #define hash_debug 78263ul /* "debug" */
492 #define hash_deny_access 1227333715ul /* "deny-access" */
493 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
494 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
495 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
496 #define hash_enforce_blocks 1862427469ul /* "enforce-blocks" */
497 #define hash_filterfile 250887266ul /* "filterfile" */
498 #define hash_forward 2029845ul /* "forward" */
499 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
500 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
501 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
502 #define hash_jarfile 2046641ul /* "jarfile" */
503 #define hash_listen_address 1255650842ul /* "listen-address" */
504 #define hash_logdir 422889ul /* "logdir" */
505 #define hash_logfile 2114766ul /* "logfile" */
506 #define hash_permit_access 3587953268ul /* "permit-access" */
507 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
508 #define hash_single_threaded 4250084780ul /* "single-threaded" */
509 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
510 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
511 #define hash_templdir 11067889ul /* "templdir" */
512 #define hash_toggle 447966ul /* "toggle" */
513 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
514 #define hash_trustfile 56494766ul /* "trustfile" */
515 #define hash_usermanual 1416668518ul /* "user-manual" */
516 #define hash_activity_animation 1817904738ul /* "activity-animation" */
517 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
518 #define hash_hide_console 2048809870ul /* "hide-console" */
519 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
520 #define hash_log_font_name 2866730124ul /* "log-font-name" */
521 #define hash_log_font_size 2866731014ul /* "log-font-size" */
522 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
523 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
524 #define hash_log_messages 2291744899ul /* "log-messages" */
525 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
528 static void savearg(char *command, char *argument, struct configuration_spec * config);
530 /*********************************************************************
532 * Function : unload_configfile
534 * Description : Free the config structure and all components.
537 * 1 : data: struct configuration_spec to unload
541 *********************************************************************/
542 void unload_configfile (void * data)
544 struct configuration_spec * config = (struct configuration_spec *)data;
545 struct forward_spec *cur_fwd = config->forward;
549 struct access_control_list *cur_acl = config->acl;
551 while (cur_acl != NULL)
553 struct access_control_list * next_acl = cur_acl->next;
558 #endif /* def FEATURE_ACL */
560 while (cur_fwd != NULL)
562 struct forward_spec * next_fwd = cur_fwd->next;
563 free_url_spec(cur_fwd->url);
565 freez(cur_fwd->gateway_host);
566 freez(cur_fwd->forward_host);
570 config->forward = NULL;
572 #ifdef FEATURE_COOKIE_JAR
573 if ( NULL != config->jar )
575 fclose( config->jar );
578 #endif /* def FEATURE_COOKIE_JAR */
580 freez(config->confdir);
581 freez(config->logdir);
582 freez(config->templdir);
584 freez(config->haddr);
585 freez(config->logfile);
587 for (i = 0; i < MAX_AF_FILES; i++)
589 freez(config->actions_file_short[i]);
590 freez(config->actions_file[i]);
591 freez(config->re_filterfile_short[i]);
592 freez(config->re_filterfile[i]);
595 freez(config->admin_address);
596 freez(config->proxy_info_url);
597 freez(config->proxy_args);
598 freez(config->usermanual);
600 #ifdef FEATURE_COOKIE_JAR
601 freez(config->jarfile);
602 #endif /* def FEATURE_COOKIE_JAR */
605 freez(config->trustfile);
606 list_remove_all(config->trust_info);
607 #endif /* def FEATURE_TRUST */
609 for (i = 0; i < MAX_AF_FILES; i++)
611 freez(config->re_filterfile[i]);
618 #ifdef FEATURE_GRACEFUL_TERMINATION
619 /*********************************************************************
621 * Function : unload_current_config_file
623 * Description : Unloads current config file - reset to state at
624 * beginning of program.
630 *********************************************************************/
631 void unload_current_config_file(void)
633 if (current_configfile)
635 current_configfile->unloader = unload_configfile;
636 current_configfile = NULL;
642 /*********************************************************************
644 * Function : load_config
646 * Description : Load the config file and all parameters.
650 * Returns : The configuration_spec, or NULL on error.
652 *********************************************************************/
653 struct configuration_spec * load_config(void)
655 char buf[BUFFER_SIZE];
657 FILE *configfp = NULL;
658 struct configuration_spec * config = NULL;
659 struct client_state * fake_csp;
660 struct file_list *fs;
661 unsigned long linenum = 0;
664 if ( !check_file_changed(current_configfile, configfile, &fs))
666 /* No need to load */
667 return ((struct configuration_spec *)current_configfile->f);
671 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
675 if (NULL != current_configfile)
677 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
680 #ifdef FEATURE_TOGGLE
681 global_toggle_state = 1;
682 #endif /* def FEATURE_TOGGLE */
684 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
690 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
691 /* Never get here - LOG_LEVEL_FATAL causes program exit */
695 * This is backwards from how it's usually done.
696 * Following the usual pattern, "fs" would be stored in a member
697 * variable in "csp", and then we'd access "config" from "fs->f",
698 * using a cast. However, "config" is used so often that a
699 * cast each time would be very ugly, and the extra indirection
700 * would waste CPU cycles. Therefore we store "config" in
701 * "csp->config", and "fs" in "csp->config->config_file_list".
703 config->config_file_list = fs;
708 config->multi_threaded = 1;
709 config->hport = HADDR_PORT;
710 config->buffer_limit = 4096 * 1024;
711 config->usermanual = strdup(USER_MANUAL_URL);
712 config->proxy_args = strdup("");
713 config->forwarded_connect_retries = 0;
714 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
715 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
716 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
718 if ((configfp = fopen(configfile, "r")) == NULL)
720 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
722 /* Never get here - LOG_LEVEL_FATAL causes program exit */
725 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
727 char cmd[BUFFER_SIZE];
728 char arg[BUFFER_SIZE];
729 char tmp[BUFFER_SIZE];
731 struct access_control_list *cur_acl;
732 #endif /* def FEATURE_ACL */
733 struct forward_spec *cur_fwd;
737 strlcpy(tmp, buf, sizeof(tmp));
739 /* Copy command (i.e. up to space or tab) into cmd */
742 while (*p && (*p != ' ') && (*p != '\t'))
748 /* Skip over the whitespace in buf */
749 while (*p && ((*p == ' ') || (*p == '\t')))
754 /* Copy the argument into arg */
755 strlcpy(arg, p, sizeof(arg));
757 /* Should never happen, but check this anyway */
763 /* Make sure the command field is lower case */
768 *p = (char)ijb_tolower(*p);
772 /* Save the argument for show-proxy-args */
773 savearg(cmd, arg, config);
776 switch( hash_string( cmd ) )
778 /* *************************************************************************
779 * actionsfile actions-file-name
780 * In confdir by default
781 * *************************************************************************/
782 case hash_actions_file :
784 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
789 if (i >= MAX_AF_FILES)
791 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
792 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
795 config->actions_file_short[i] = strdup(arg);
796 config->actions_file[i] = make_path(config->confdir, arg);
799 /* *************************************************************************
800 * accept-intercepted-requests
801 * *************************************************************************/
802 case hash_accept_intercepted_requests:
803 if ((*arg != '\0') && (0 != atoi(arg)))
805 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
809 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
813 /* *************************************************************************
814 * admin-address email-address
815 * *************************************************************************/
816 case hash_admin_address :
817 freez(config->admin_address);
818 config->admin_address = strdup(arg);
821 /* *************************************************************************
823 * *************************************************************************/
824 case hash_buffer_limit :
825 config->buffer_limit = (size_t)(1024 * atoi(arg));
828 /* *************************************************************************
829 * confdir directory-name
830 * *************************************************************************/
832 freez(config->confdir);
833 config->confdir = make_path( NULL, arg);
836 /* *************************************************************************
838 * Specifies debug level, multiple values are ORed together.
839 * *************************************************************************/
841 config->debug |= atoi(arg);
844 /* *************************************************************************
845 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
846 * *************************************************************************/
848 case hash_deny_access:
849 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
851 if ((vec_count != 1) && (vec_count != 2))
853 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
854 "deny-access directive in configuration file.");
855 string_append(&config->proxy_args,
856 "<br>\nWARNING: Wrong number of parameters for "
857 "deny-access directive in configuration file.<br><br>\n");
861 /* allocate a new node */
862 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
866 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
867 /* Never get here - LOG_LEVEL_FATAL causes program exit */
870 cur_acl->action = ACL_DENY;
872 if (acl_addr(vec[0], cur_acl->src) < 0)
874 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
875 "for deny-access directive in configuration file: \"%s\"", vec[0]);
876 string_append(&config->proxy_args,
877 "<br>\nWARNING: Invalid source address, port or netmask "
878 "for deny-access directive in configuration file: \"");
879 string_append(&config->proxy_args,
881 string_append(&config->proxy_args,
888 if (acl_addr(vec[1], cur_acl->dst) < 0)
890 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
891 "for deny-access directive in configuration file: \"%s\"", vec[1]);
892 string_append(&config->proxy_args,
893 "<br>\nWARNING: Invalid destination address, port or netmask "
894 "for deny-access directive in configuration file: \"");
895 string_append(&config->proxy_args,
897 string_append(&config->proxy_args,
905 * Add it to the list. Note we reverse the list to get the
906 * behaviour the user expects. With both the ACL and
907 * actions file, the last match wins. However, the internal
908 * implementations are different: The actions file is stored
909 * in the same order as the file, and scanned completely.
910 * With the ACL, we reverse the order as we load it, then
911 * when we scan it we stop as soon as we get a match.
913 cur_acl->next = config->acl;
914 config->acl = cur_acl;
917 #endif /* def FEATURE_ACL */
919 /* *************************************************************************
920 * enable-edit-actions 0|1
921 * *************************************************************************/
922 #ifdef FEATURE_CGI_EDIT_ACTIONS
923 case hash_enable_edit_actions:
924 if ((*arg != '\0') && (0 != atoi(arg)))
926 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
930 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
933 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
935 /* *************************************************************************
936 * enable-remote-toggle 0|1
937 * *************************************************************************/
938 #ifdef FEATURE_CGI_EDIT_ACTIONS
939 case hash_enable_remote_toggle:
940 if ((*arg != '\0') && (0 != atoi(arg)))
942 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
946 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
949 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
951 /* *************************************************************************
952 * enable-remote-http-toggle 0|1
953 * *************************************************************************/
954 case hash_enable_remote_http_toggle:
955 if ((*arg != '\0') && (0 != atoi(arg)))
957 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
961 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
965 /* *************************************************************************
966 * hash_enforce_blocks 0|1
967 * *************************************************************************/
968 #ifdef FEATURE_FORCE_LOAD
969 case hash_enforce_blocks:
970 if ((*arg != '\0') && (0 != atoi(arg)))
972 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
976 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
979 #endif /* def FEATURE_FORCE_LOAD */
981 /* *************************************************************************
982 * filterfile file-name
983 * In confdir by default.
984 * *************************************************************************/
985 case hash_filterfile :
987 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
992 if (i >= MAX_AF_FILES)
994 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
995 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
998 config->re_filterfile_short[i] = strdup(arg);
999 config->re_filterfile[i] = make_path(config->confdir, arg);
1003 /* *************************************************************************
1004 * forward url-pattern (.|http-proxy-host[:port])
1005 * *************************************************************************/
1007 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1011 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1012 "directive in configuration file.");
1013 string_append(&config->proxy_args,
1014 "<br>\nWARNING: Wrong number of parameters for "
1015 "forward directive in configuration file.");
1019 /* allocate a new node */
1020 cur_fwd = zalloc(sizeof(*cur_fwd));
1021 if (cur_fwd == NULL)
1023 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1024 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1028 cur_fwd->type = SOCKS_NONE;
1030 /* Save the URL pattern */
1031 if (create_url_spec(cur_fwd->url, vec[0]))
1033 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1034 "directive in configuration file.");
1035 string_append(&config->proxy_args,
1036 "<br>\nWARNING: Bad URL specifier for "
1037 "forward directive in configuration file.");
1041 /* Parse the parent HTTP proxy host:port */
1044 if (strcmp(p, ".") != 0)
1046 cur_fwd->forward_host = strdup(p);
1048 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1051 cur_fwd->forward_port = atoi(p);
1054 if (cur_fwd->forward_port <= 0)
1056 cur_fwd->forward_port = 8000;
1061 cur_fwd->next = config->forward;
1062 config->forward = cur_fwd;
1066 /* *************************************************************************
1067 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1068 * *************************************************************************/
1069 case hash_forward_socks4:
1070 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1074 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1075 "forward-socks4 directive in configuration file.");
1076 string_append(&config->proxy_args,
1077 "<br>\nWARNING: Wrong number of parameters for "
1078 "forward-socks4 directive in configuration file.");
1082 /* allocate a new node */
1083 cur_fwd = zalloc(sizeof(*cur_fwd));
1084 if (cur_fwd == NULL)
1086 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1087 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1091 cur_fwd->type = SOCKS_4;
1093 /* Save the URL pattern */
1094 if (create_url_spec(cur_fwd->url, vec[0]))
1096 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1097 "directive in configuration file.");
1098 string_append(&config->proxy_args,
1099 "<br>\nWARNING: Bad URL specifier for "
1100 "forward-socks4 directive in configuration file.");
1104 /* Parse the SOCKS proxy host[:port] */
1107 if (strcmp(p, ".") != 0)
1109 cur_fwd->gateway_host = strdup(p);
1111 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1114 cur_fwd->gateway_port = atoi(p);
1116 if (cur_fwd->gateway_port <= 0)
1118 cur_fwd->gateway_port = 1080;
1122 /* Parse the parent HTTP proxy host[:port] */
1125 if (strcmp(p, ".") != 0)
1127 cur_fwd->forward_host = strdup(p);
1129 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1132 cur_fwd->forward_port = atoi(p);
1135 if (cur_fwd->forward_port <= 0)
1137 cur_fwd->forward_port = 8000;
1142 cur_fwd->next = config->forward;
1143 config->forward = cur_fwd;
1147 /* *************************************************************************
1148 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1149 * *************************************************************************/
1150 case hash_forward_socks4a:
1151 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1155 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1156 "forward-socks4a directive in configuration file.");
1157 string_append(&config->proxy_args,
1158 "<br>\nWARNING: Wrong number of parameters for "
1159 "forward-socks4a directive in configuration file.");
1163 /* allocate a new node */
1164 cur_fwd = zalloc(sizeof(*cur_fwd));
1165 if (cur_fwd == NULL)
1167 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1168 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1172 cur_fwd->type = SOCKS_4A;
1174 /* Save the URL pattern */
1175 if (create_url_spec(cur_fwd->url, vec[0]))
1177 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1178 "directive in configuration file.");
1179 string_append(&config->proxy_args,
1180 "<br>\nWARNING: Bad URL specifier for "
1181 "forward-socks4a directive in configuration file.");
1185 /* Parse the SOCKS proxy host[:port] */
1188 cur_fwd->gateway_host = strdup(p);
1190 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1193 cur_fwd->gateway_port = atoi(p);
1195 if (cur_fwd->gateway_port <= 0)
1197 cur_fwd->gateway_port = 1080;
1200 /* Parse the parent HTTP proxy host[:port] */
1203 if (strcmp(p, ".") != 0)
1205 cur_fwd->forward_host = strdup(p);
1207 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1210 cur_fwd->forward_port = atoi(p);
1213 if (cur_fwd->forward_port <= 0)
1215 cur_fwd->forward_port = 8000;
1220 cur_fwd->next = config->forward;
1221 config->forward = cur_fwd;
1225 /* *************************************************************************
1226 * forwarded-connect-retries n
1227 * *************************************************************************/
1228 case hash_forwarded_connect_retries :
1229 config->forwarded_connect_retries = atoi(arg);
1232 /* *************************************************************************
1233 * jarfile jar-file-name
1234 * In logdir by default
1235 * *************************************************************************/
1236 #ifdef FEATURE_COOKIE_JAR
1238 freez(config->jarfile);
1239 config->jarfile = make_path(config->logdir, arg);
1241 #endif /* def FEATURE_COOKIE_JAR */
1243 /* *************************************************************************
1244 * listen-address [ip][:port]
1245 * *************************************************************************/
1246 case hash_listen_address :
1247 freez(config->haddr);
1248 config->haddr = strdup(arg);
1251 /* *************************************************************************
1252 * logdir directory-name
1253 * *************************************************************************/
1255 freez(config->logdir);
1256 config->logdir = make_path(NULL, arg);
1259 /* *************************************************************************
1260 * logfile log-file-name
1261 * In logdir by default
1262 * *************************************************************************/
1264 freez(config->logfile);
1265 config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1268 /* *************************************************************************
1269 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1270 * *************************************************************************/
1272 case hash_permit_access:
1273 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1275 if ((vec_count != 1) && (vec_count != 2))
1277 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1278 "permit-access directive in configuration file.");
1279 string_append(&config->proxy_args,
1280 "<br>\nWARNING: Wrong number of parameters for "
1281 "permit-access directive in configuration file.<br><br>\n");
1286 /* allocate a new node */
1287 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1289 if (cur_acl == NULL)
1291 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1292 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1295 cur_acl->action = ACL_PERMIT;
1297 if (acl_addr(vec[0], cur_acl->src) < 0)
1299 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1300 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1301 string_append(&config->proxy_args,
1302 "<br>\nWARNING: Invalid source address, port or netmask for "
1303 "permit-access directive in configuration file: \"");
1304 string_append(&config->proxy_args,
1306 string_append(&config->proxy_args,
1313 if (acl_addr(vec[1], cur_acl->dst) < 0)
1315 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1316 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1317 string_append(&config->proxy_args,
1318 "<br>\nWARNING: Invalid destination address, port or netmask for "
1319 "permit-access directive in configuration file: \"");
1320 string_append(&config->proxy_args,
1322 string_append(&config->proxy_args,
1330 * Add it to the list. Note we reverse the list to get the
1331 * behaviour the user expects. With both the ACL and
1332 * actions file, the last match wins. However, the internal
1333 * implementations are different: The actions file is stored
1334 * in the same order as the file, and scanned completely.
1335 * With the ACL, we reverse the order as we load it, then
1336 * when we scan it we stop as soon as we get a match.
1338 cur_acl->next = config->acl;
1339 config->acl = cur_acl;
1342 #endif /* def FEATURE_ACL */
1344 /* *************************************************************************
1345 * proxy-info-url url
1346 * *************************************************************************/
1347 case hash_proxy_info_url :
1348 freez(config->proxy_info_url);
1349 config->proxy_info_url = strdup(arg);
1352 /* *************************************************************************
1354 * *************************************************************************/
1355 case hash_single_threaded :
1356 config->multi_threaded = 0;
1359 /* *************************************************************************
1360 * split-large-cgi-forms
1361 * *************************************************************************/
1362 case hash_split_large_cgi_forms :
1363 if ((*arg != '\0') && (0 != atoi(arg)))
1365 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1369 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1373 /* *************************************************************************
1374 * templdir directory-name
1375 * *************************************************************************/
1376 case hash_templdir :
1377 freez(config->templdir);
1378 config->templdir = make_path(NULL, arg);
1381 /* *************************************************************************
1383 * *************************************************************************/
1384 #ifdef FEATURE_TOGGLE
1386 global_toggle_state = atoi(arg);
1388 #endif /* def FEATURE_TOGGLE */
1390 /* *************************************************************************
1391 * trust-info-url url
1392 * *************************************************************************/
1393 #ifdef FEATURE_TRUST
1394 case hash_trust_info_url :
1395 enlist(config->trust_info, arg);
1397 #endif /* def FEATURE_TRUST */
1399 /* *************************************************************************
1400 * trustfile filename
1401 * (In confdir by default.)
1402 * *************************************************************************/
1403 #ifdef FEATURE_TRUST
1404 case hash_trustfile :
1405 freez(config->trustfile);
1406 config->trustfile = make_path(config->confdir, arg);
1408 #endif /* def FEATURE_TRUST */
1410 /* *************************************************************************
1412 * *************************************************************************/
1413 case hash_usermanual :
1414 freez(config->usermanual);
1415 config->usermanual = strdup(arg);
1418 /* *************************************************************************
1419 * Win32 Console options:
1420 * *************************************************************************/
1422 /* *************************************************************************
1424 * *************************************************************************/
1426 case hash_hide_console :
1429 #endif /*def _WIN_CONSOLE*/
1432 /* *************************************************************************
1433 * Win32 GUI options:
1434 * *************************************************************************/
1436 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1437 /* *************************************************************************
1438 * activity-animation (0|1)
1439 * *************************************************************************/
1440 case hash_activity_animation :
1441 g_bShowActivityAnimation = atoi(arg);
1444 /* *************************************************************************
1445 * close-button-minimizes (0|1)
1446 * *************************************************************************/
1447 case hash_close_button_minimizes :
1448 g_bCloseHidesWindow = atoi(arg);
1451 /* *************************************************************************
1452 * log-buffer-size (0|1)
1453 * *************************************************************************/
1454 case hash_log_buffer_size :
1455 g_bLimitBufferSize = atoi(arg);
1458 /* *************************************************************************
1459 * log-font-name fontnane
1460 * *************************************************************************/
1461 case hash_log_font_name :
1462 strcpy( g_szFontFaceName, arg );
1465 /* *************************************************************************
1467 * *************************************************************************/
1468 case hash_log_font_size :
1469 g_nFontSize = atoi(arg);
1472 /* *************************************************************************
1473 * log-highlight-messages (0|1)
1474 * *************************************************************************/
1475 case hash_log_highlight_messages :
1476 g_bHighlightMessages = atoi(arg);
1479 /* *************************************************************************
1481 * *************************************************************************/
1482 case hash_log_max_lines :
1483 g_nMaxBufferLines = atoi(arg);
1486 /* *************************************************************************
1487 * log-messages (0|1)
1488 * *************************************************************************/
1489 case hash_log_messages :
1490 g_bLogMessages = atoi(arg);
1493 /* *************************************************************************
1494 * show-on-task-bar (0|1)
1495 * *************************************************************************/
1496 case hash_show_on_task_bar :
1497 g_bShowOnTaskBar = atoi(arg);
1500 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1503 /* *************************************************************************
1504 * Warnings about unsupported features
1505 * *************************************************************************/
1507 case hash_deny_access:
1508 #endif /* ndef FEATURE_ACL */
1509 #ifndef FEATURE_CGI_EDIT_ACTIONS
1510 case hash_enable_edit_actions:
1511 case hash_enable_remote_toggle:
1512 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1513 #ifndef FEATURE_COOKIE_JAR
1515 #endif /* ndef FEATURE_COOKIE_JAR */
1517 case hash_permit_access:
1518 #endif /* ndef FEATURE_ACL */
1519 #ifndef FEATURE_TOGGLE
1521 #endif /* ndef FEATURE_TOGGLE */
1522 #ifndef FEATURE_TRUST
1523 case hash_trustfile :
1524 case hash_trust_info_url :
1525 #endif /* ndef FEATURE_TRUST */
1527 #ifndef _WIN_CONSOLE
1528 case hash_hide_console :
1529 #endif /* ndef _WIN_CONSOLE */
1531 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1532 case hash_activity_animation :
1533 case hash_close_button_minimizes :
1534 case hash_log_buffer_size :
1535 case hash_log_font_name :
1536 case hash_log_font_size :
1537 case hash_log_highlight_messages :
1538 case hash_log_max_lines :
1539 case hash_log_messages :
1540 case hash_show_on_task_bar :
1541 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1542 /* These warnings are annoying - so hide them. -- Jon */
1543 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1546 /* *************************************************************************/
1548 /* *************************************************************************/
1550 * I decided that I liked this better as a warning than an
1551 * error. To change back to an error, just change log level
1552 * to LOG_LEVEL_FATAL.
1554 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1555 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1556 string_append(&config->proxy_args,
1557 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1560 /* *************************************************************************/
1561 } /* end switch( hash_string(cmd) ) */
1562 } /* end while ( read_config_line(...) ) */
1566 if (NULL == config->proxy_args)
1568 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1571 init_error_log(Argv[0], config->logfile, config->debug);
1573 if (config->actions_file[0])
1575 add_loader(load_actions_file, config);
1578 if (config->re_filterfile)
1580 add_loader(load_re_filterfile, config);
1583 #ifdef FEATURE_TRUST
1584 if (config->trustfile)
1586 add_loader(load_trustfile, config);
1588 #endif /* def FEATURE_TRUST */
1590 #ifdef FEATURE_COOKIE_JAR
1591 if ( NULL != config->jarfile )
1593 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1595 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1596 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1598 setbuf(config->jar, NULL);
1600 #endif /* def FEATURE_COOKIE_JAR */
1602 if ( NULL == config->haddr )
1604 config->haddr = strdup( HADDR_DEFAULT );
1607 if ( NULL != config->haddr )
1609 if (NULL != (p = strchr(config->haddr, ':')))
1614 config->hport = atoi(p);
1618 if (config->hport <= 0)
1621 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1622 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1624 if (*config->haddr == '\0')
1626 config->haddr = NULL;
1631 * Want to run all the loaders once now.
1633 * Need to set up a fake csp, so they can get to the config.
1635 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1636 fake_csp->config = config;
1638 if (run_loader(fake_csp))
1641 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1642 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1646 /* FIXME: this is a kludge for win32 */
1647 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1649 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1650 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1651 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1653 #ifdef FEATURE_TRUST
1654 g_trustfile = config->trustfile;
1655 #endif /* def FEATURE_TRUST */
1658 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1659 /* FIXME: end kludge */
1662 config->need_bind = 1;
1664 if (current_configfile)
1666 struct configuration_spec * oldcfg = (struct configuration_spec *)
1667 current_configfile->f;
1669 * Check if config->haddr,hport == oldcfg->haddr,hport
1671 * The following could be written more compactly as a single,
1672 * (unreadably long) if statement.
1674 config->need_bind = 0;
1675 if (config->hport != oldcfg->hport)
1677 config->need_bind = 1;
1679 else if (config->haddr == NULL)
1681 if (oldcfg->haddr != NULL)
1683 config->need_bind = 1;
1686 else if (oldcfg->haddr == NULL)
1688 config->need_bind = 1;
1690 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1692 config->need_bind = 1;
1695 current_configfile->unloader = unload_configfile;
1698 fs->next = files->next;
1701 current_configfile = fs;
1707 /*********************************************************************
1709 * Function : savearg
1711 * Description : Called from `load_config'. It saves each non-empty
1712 * and non-comment line from config into
1713 * config->proxy_args. This is used to create the
1714 * show-proxy-args page. On error, frees
1715 * config->proxy_args and sets it to NULL
1718 * 1 : command = config setting that was found
1719 * 2 : argument = the setting's argument (if any)
1720 * 3 : config = Configuration to save into.
1724 *********************************************************************/
1725 static void savearg(char *command, char *argument, struct configuration_spec * config)
1735 * Add config option name embedded in
1736 * link to it's section in the user-manual
1738 buf = strdup("\n<a href=\"");
1739 if (!strncmpic(config->usermanual, "file://", 7) ||
1740 !strncmpic(config->usermanual, "http", 4))
1742 string_append(&buf, config->usermanual);
1746 string_append(&buf, "http://");
1747 string_append(&buf, CGI_SITE_2_HOST);
1748 string_append(&buf, "/user-manual/");
1750 string_append(&buf, CONFIG_HELP_PREFIX);
1751 string_join (&buf, string_toupper(command));
1752 string_append(&buf, "\">");
1753 string_append(&buf, command);
1754 string_append(&buf, "</a> ");
1758 freez(config->proxy_args);
1762 if ( (NULL != argument) && ('\0' != *argument) )
1764 s = html_encode(argument);
1768 freez(config->proxy_args);
1772 if (strncmpic(argument, "http://", 7) == 0)
1774 string_append(&buf, "<a href=\"");
1775 string_append(&buf, s);
1776 string_append(&buf, "\">");
1777 string_join (&buf, s);
1778 string_append(&buf, "</a>");
1782 string_join (&buf, s);
1786 string_append(&buf, "<br>");
1787 string_join(&config->proxy_args, buf);