1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.60 2007/01/27 13:09:16 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.60 2007/01/27 13:09:16 fabiankeil
39 * Add new config option "templdir" to
40 * change the templates directory.
42 * Revision 1.59 2006/12/31 17:56:38 fabiankeil
43 * Added config option accept-intercepted-requests
44 * and disabled it by default.
46 * Revision 1.58 2006/12/31 14:24:29 fabiankeil
47 * Fix gcc43 compiler warnings.
49 * Revision 1.57 2006/12/21 12:57:48 fabiankeil
50 * Add config option "split-large-forms"
51 * to work around the browser bug reported
54 * Revision 1.56 2006/12/17 17:04:51 fabiankeil
55 * Move the <br> in the generated HTML for the config
56 * options from the beginning of the string to its end.
57 * Keeps the white space in balance.
59 * Revision 1.55 2006/11/28 15:31:52 fabiankeil
60 * Fix memory leak in case of config file reloads.
62 * Revision 1.54 2006/10/21 16:04:22 fabiankeil
63 * Modified kludge for win32 to make ming32 menu
64 * "Options/Edit Filters" (sort of) work again.
65 * Same limitations as for the action files apply.
68 * Revision 1.53 2006/09/06 18:45:03 fabiankeil
69 * Incorporate modified version of Roland Rosenfeld's patch to
70 * optionally access the user-manual via Privoxy. Closes patch 679075.
72 * Formatting changed to Privoxy style, added call to
73 * cgi_error_no_template if the requested file doesn't
74 * exist and modified check whether or not Privoxy itself
75 * should serve the manual. Should work cross-platform now.
77 * Revision 1.52 2006/09/06 10:43:32 fabiankeil
78 * Added config option enable-remote-http-toggle
79 * to specify if Privoxy should recognize special
80 * headers (currently only X-Filter) to change its
81 * behaviour. Disabled by default.
83 * Revision 1.51 2006/09/06 09:23:37 fabiankeil
84 * Make number of retries in case of forwarded-connect problems
85 * a config file option (forwarded-connect-retries) and use 0 as
88 * Revision 1.50 2006/07/18 14:48:46 david__schmidt
89 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
90 * with what was really the latest development (the v_3_0_branch branch)
92 * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt
93 * Don't forget to malloc space for the null terminator...
95 * Revision 1.48.2.6 2006/01/29 23:10:56 david__schmidt
96 * Multiple filter file support
98 * Revision 1.48.2.5 2003/05/08 15:17:25 oes
99 * Closed two memory leaks; hopefully the last remaining ones
100 * (in the main execution paths, anyway).
102 * Revision 1.48.2.4 2003/04/11 12:06:14 oes
103 * Addressed bug #719435
104 * - Extraneous filterfile directives now logged as errors
105 * - This and unrecnonised directives now really obvious on status page
107 * Revision 1.48.2.3 2003/03/11 11:53:59 oes
108 * Cosmetic: Renamed cryptic variable
110 * Revision 1.48.2.2 2002/11/12 16:28:20 oes
111 * Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
113 * Revision 1.48.2.1 2002/08/21 17:58:05 oes
114 * Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
116 * Revision 1.48 2002/05/14 21:30:38 oes
117 * savearg now uses own linking code instead of (now special-cased) add_help_link
119 * Revision 1.47 2002/05/12 21:36:29 jongfoster
120 * Correcting function comments
122 * Revision 1.46 2002/04/26 12:55:14 oes
123 * - New option "user-manual", defaults to our site
124 * via project.h #define
125 * - savearg now embeds option names in help links
127 * Revision 1.45 2002/04/24 02:11:54 oes
128 * Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
130 * Revision 1.44 2002/04/08 20:37:13 swa
133 * Revision 1.43 2002/04/08 20:36:50 swa
136 * Revision 1.42 2002/04/05 15:50:15 oes
137 * fix for invalid HTML proxy_args
139 * Revision 1.41 2002/03/31 17:19:00 jongfoster
140 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
142 * Revision 1.40 2002/03/26 22:29:55 swa
143 * we have a new homepage!
145 * Revision 1.39 2002/03/24 13:25:43 swa
146 * name change related issues
148 * Revision 1.38 2002/03/24 13:05:48 jongfoster
149 * Renaming re_filterfile to filterfile
151 * Revision 1.37 2002/03/16 23:54:06 jongfoster
152 * Adding graceful termination feature, to help look for memory leaks.
153 * If you enable this (which, by design, has to be done by hand
154 * editing config.h) and then go to http://i.j.b/die, then the program
155 * will exit cleanly after the *next* request. It should free all the
156 * memory that was used.
158 * Revision 1.36 2002/03/13 00:27:05 jongfoster
161 * Revision 1.35 2002/03/07 03:52:44 oes
162 * Set logging to tty for --no-daemon mode
164 * Revision 1.34 2002/03/06 23:14:35 jongfoster
165 * Trivial cosmetic changes to make function comments easier to find.
167 * Revision 1.33 2002/03/05 04:52:42 oes
168 * Deleted non-errlog debugging code
170 * Revision 1.32 2002/03/04 18:24:53 oes
171 * Re-enabled output of unknown config directive hash
173 * Revision 1.31 2002/03/03 15:07:20 oes
174 * Re-enabled automatic config reloading
176 * Revision 1.30 2002/01/22 23:31:43 jongfoster
177 * Replacing strsav() with string_append()
179 * Revision 1.29 2002/01/17 21:02:30 jongfoster
180 * Moving all our URL and URL pattern parsing code to urlmatch.c.
182 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
184 * Revision 1.28 2001/12/30 14:07:32 steudten
185 * - Add signal handling (unix)
186 * - Add SIGHUP handler (unix)
187 * - Add creation of pidfile (unix)
188 * - Add action 'top' in rc file (RH)
189 * - Add entry 'SIGNALS' to manpage
190 * - Add exit message to logfile (unix)
192 * Revision 1.27 2001/11/07 00:02:13 steudten
193 * Add line number in error output for lineparsing for
194 * actionsfile and configfile.
195 * Special handling for CLF added.
197 * Revision 1.26 2001/11/05 21:41:43 steudten
198 * Add changes to be a real daemon just for unix os.
199 * (change cwd to /, detach from controlling tty, set
200 * process group and session leader to the own process.
202 * Add some fatal-error log message for failed malloc().
203 * Add '-d' if compiled with 'configure --with-debug' to
204 * enable debug output.
206 * Revision 1.25 2001/10/25 03:40:48 david__schmidt
207 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
208 * threads to call select() simultaneously. So, it's time to do a real, live,
209 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
210 * (native). Both versions will work, but using __OS2__ offers multi-threading.
212 * Revision 1.24 2001/10/23 21:40:30 jongfoster
213 * Added support for enable-edit-actions and enable-remote-toggle config
216 * Revision 1.23 2001/10/07 15:36:00 oes
217 * Introduced new config option "buffer-limit"
219 * Revision 1.22 2001/09/22 16:36:59 jongfoster
220 * Removing unused parameter fs from read_config_line()
222 * Revision 1.21 2001/09/16 17:10:43 jongfoster
223 * Moving function savearg() here, since it was the only thing left in
226 * Revision 1.20 2001/07/30 22:08:36 jongfoster
227 * Tidying up #defines:
228 * - All feature #defines are now of the form FEATURE_xxx
229 * - Permanently turned off WIN_GUI_EDIT
230 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
232 * Revision 1.19 2001/07/15 17:45:16 jongfoster
233 * Removing some unused #includes
235 * Revision 1.18 2001/07/13 14:01:14 oes
236 * - Removed all #ifdef PCRS
237 * - Removed vim-settings
239 * Revision 1.17 2001/06/29 13:31:03 oes
240 * - Improved comments
241 * - Fixed (actionsfile) and sorted hashes
242 * - Introduced admin_address and proxy-info-url
243 * as config parameters
244 * - Renamed config->proxy_args_invocation (which didn't have
245 * the invocation but the options!) to config->proxy_args
246 * - Various adaptions
247 * - Removed logentry from cancelled commit
249 * Revision 1.16 2001/06/09 10:55:28 jongfoster
250 * Changing BUFSIZ ==> BUFFER_SIZE
252 * Revision 1.15 2001/06/07 23:13:40 jongfoster
253 * Merging ACL and forward files into config file.
254 * Cosmetic: Sorting config file options alphabetically.
255 * Cosmetic: Adding brief syntax comments to config file options.
257 * Revision 1.14 2001/06/07 14:46:25 joergs
258 * Missing make_path() added for re_filterfile.
260 * Revision 1.13 2001/06/05 22:33:54 jongfoster
262 * Fixed minor memory leak.
263 * Also now uses make_path to prepend the pathnames.
265 * Revision 1.12 2001/06/05 20:04:09 jongfoster
266 * Now uses _snprintf() in place of snprintf() under Win32.
268 * Revision 1.11 2001/06/04 18:31:58 swa
269 * files are now prefixed with either `confdir' or `logdir'.
270 * `make redhat-dist' replaces both entries confdir and logdir
273 * Revision 1.10 2001/06/03 19:11:54 oes
274 * introduced confdir option
276 * Revision 1.9 2001/06/01 20:06:24 jongfoster
277 * Removed support for "tinygif" option - moved to actions file.
279 * Revision 1.8 2001/05/31 21:27:13 jongfoster
280 * Removed many options from the config file and into the
281 * "actions" file: add_forwarded, suppress_vanilla_wafer,
282 * wafer, add_header, user_agent, referer, from
283 * Also globally replaced "permission" with "action".
285 * Revision 1.7 2001/05/29 09:50:24 jongfoster
286 * Unified blocklist/imagelist/permissionslist.
287 * File format is still under discussion, but the internal changes
290 * Also modified interceptor behaviour:
291 * - We now intercept all URLs beginning with one of the following
292 * prefixes (and *only* these prefixes):
294 * * http://ijbswa.sf.net/config/
295 * * http://ijbswa.sourceforge.net/config/
296 * - New interceptors "home page" - go to http://i.j.b/ to see it.
297 * - Internal changes so that intercepted and fast redirect pages
298 * are not replaced with an image.
299 * - Interceptors now have the option to send a binary page direct
300 * to the client. (i.e. ijb-send-banner uses this)
301 * - Implemented show-url-info interceptor. (Which is why I needed
302 * the above interceptors changes - a typical URL is
303 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
304 * The previous mechanism would not have intercepted that, and
305 * if it had been intercepted then it then it would have replaced
308 * Revision 1.6 2001/05/26 00:28:36 jongfoster
309 * Automatic reloading of config file.
310 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
311 * Most of the global variables have been moved to a new
312 * struct configuration_spec, accessed through csp->config->globalname
313 * Most of the globals remaining are used by the Win32 GUI.
315 * Revision 1.5 2001/05/25 22:34:30 jongfoster
318 * Revision 1.4 2001/05/22 18:46:04 oes
320 * - Enabled filtering banners by size rather than URL
321 * by adding patterns that replace all standard banner
322 * sizes with the "Junkbuster" gif to the re_filterfile
324 * - Enabled filtering WebBugs by providing a pattern
325 * which kills all 1x1 images
327 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
328 * which is selected by the (nonstandard and therefore
329 * capital) letter 'U' in the option string.
330 * It causes the quantifiers to be ungreedy by default.
331 * Appending a ? turns back to greedy (!).
333 * - Added a new interceptor ijb-send-banner, which
334 * sends back the "Junkbuster" gif. Without imagelist or
335 * MSIE detection support, or if tinygif = 1, or the
336 * URL isn't recognized as an imageurl, a lame HTML
337 * explanation is sent instead.
339 * - Added new feature, which permits blocking remote
340 * script redirects and firing back a local redirect
342 * The feature is conditionally compiled, i.e. it
343 * can be disabled with --disable-fast-redirects,
344 * plus it must be activated by a "fast-redirects"
345 * line in the config file, has its own log level
346 * and of course wants to be displayed by show-proxy-args
347 * Note: Boy, all the #ifdefs in 1001 locations and
348 * all the fumbling with configure.in and acconfig.h
349 * were *way* more work than the feature itself :-(
351 * - Because a generic redirect template was needed for
352 * this, tinygif = 3 now uses the same.
354 * - Moved GIFs, and other static HTTP response templates
359 * - Removed some >400 CRs again (Jon, you really worked
362 * Revision 1.3 2001/05/20 01:21:20 jongfoster
363 * Version 2.9.4 checkin.
364 * - Merged popupfile and cookiefile, and added control over PCRS
365 * filtering, in new "permissionsfile".
366 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
367 * file error you now get a message box (in the Win32 GUI) rather
368 * than the program exiting with no explanation.
369 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
371 * - Removed tabs from "config"
372 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
373 * - Bumped up version number.
375 * Revision 1.2 2001/05/17 23:01:01 oes
376 * - Cleaned CRLF's from the sources and related files
378 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
379 * Initial import of version 2.9.3 source tree
382 *********************************************************************/
388 #include <sys/types.h>
402 # include <windows.h>
405 # ifndef _WIN_CONSOLE
407 # endif /* ndef _WIN_CONSOLE */
409 /* VC++ has "_snprintf", not "snprintf" */
410 #define snprintf _snprintf
412 #else /* ifndef _WIN32 */
416 # include <sys/wait.h>
418 # include <sys/time.h>
419 # include <sys/stat.h>
429 #include "miscutil.h"
433 #include "urlmatch.h"
436 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
439 * Fix a problem with Solaris. There should be no effect on other
441 * Solaris's isspace() is a macro which uses it's argument directly
442 * as an array index. Therefore we need to make sure that high-bit
443 * characters generate +ve values, and ideally we also want to make
444 * the argument match the declared parameter type of "int".
446 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
447 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
449 #ifdef FEATURE_TOGGLE
450 /* Privoxy is enabled by default. */
451 int global_toggle_state = 1;
452 #endif /* def FEATURE_TOGGLE */
454 /* The filename of the configfile */
455 const char *configfile = NULL;
458 * CGI functions will later need access to the invocation args,
459 * so we will make argc and argv global.
462 const char **Argv = NULL;
464 static struct file_list *current_configfile = NULL;
468 * This takes the "cryptic" hash of each keyword and aliases them to
469 * something a little more readable. This also makes changing the
470 * hash values easier if they should change or the hash algorthm changes.
471 * Use the included "hash" program to find out what the hash will be
472 * for any string supplied on the command line. (Or just put it in the
473 * config file and read the number from the error message in the log).
475 * Please keep this list sorted alphabetically (but with the Windows
476 * console and GUI specific options last).
479 #define hash_actions_file 1196306641ul /* "actionsfile" */
480 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
481 #define hash_admin_address 4112573064ul /* "admin-address" */
482 #define hash_buffer_limit 1881726070ul /* "buffer-limit */
483 #define hash_confdir 1978389ul /* "confdir" */
484 #define hash_debug 78263ul /* "debug" */
485 #define hash_deny_access 1227333715ul /* "deny-access" */
486 #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */
487 #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */
488 #define hash_enable_remote_http_toggle 110543988ul /* "enable-remote-http-toggle" */
489 #define hash_filterfile 250887266ul /* "filterfile" */
490 #define hash_forward 2029845ul /* "forward" */
491 #define hash_forward_socks4 3963965521ul /* "forward-socks4" */
492 #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */
493 #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */
494 #define hash_jarfile 2046641ul /* "jarfile" */
495 #define hash_listen_address 1255650842ul /* "listen-address" */
496 #define hash_logdir 422889ul /* "logdir" */
497 #define hash_logfile 2114766ul /* "logfile" */
498 #define hash_permit_access 3587953268ul /* "permit-access" */
499 #define hash_proxy_info_url 3903079059ul /* "proxy-info-url" */
500 #define hash_single_threaded 4250084780ul /* "single-threaded" */
501 #define hash_split_large_cgi_forms 671658948ul /* "split-large-cgi-forms" */
502 #define hash_suppress_blocklists 1948693308ul /* "suppress-blocklists" */
503 #define hash_templdir 11067889ul /* "templdir" */
504 #define hash_toggle 447966ul /* "toggle" */
505 #define hash_trust_info_url 430331967ul /* "trust-info-url" */
506 #define hash_trustfile 56494766ul /* "trustfile" */
507 #define hash_usermanual 1416668518ul /* "user-manual" */
508 #define hash_activity_animation 1817904738ul /* "activity-animation" */
509 #define hash_close_button_minimizes 3651284693ul /* "close-button-minimizes" */
510 #define hash_hide_console 2048809870ul /* "hide-console" */
511 #define hash_log_buffer_size 2918070425ul /* "log-buffer-size" */
512 #define hash_log_font_name 2866730124ul /* "log-font-name" */
513 #define hash_log_font_size 2866731014ul /* "log-font-size" */
514 #define hash_log_highlight_messages 4032101240ul /* "log-highlight-messages" */
515 #define hash_log_max_lines 2868344173ul /* "log-max-lines" */
516 #define hash_log_messages 2291744899ul /* "log-messages" */
517 #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */
520 static void savearg(char *command, char *argument, struct configuration_spec * config);
522 /*********************************************************************
524 * Function : unload_configfile
526 * Description : Free the config structure and all components.
529 * 1 : data: struct configuration_spec to unload
533 *********************************************************************/
534 void unload_configfile (void * data)
536 struct configuration_spec * config = (struct configuration_spec *)data;
537 struct forward_spec *cur_fwd = config->forward;
541 struct access_control_list *cur_acl = config->acl;
543 while (cur_acl != NULL)
545 struct access_control_list * next_acl = cur_acl->next;
550 #endif /* def FEATURE_ACL */
552 while (cur_fwd != NULL)
554 struct forward_spec * next_fwd = cur_fwd->next;
555 free_url_spec(cur_fwd->url);
557 freez(cur_fwd->gateway_host);
558 freez(cur_fwd->forward_host);
562 config->forward = NULL;
564 #ifdef FEATURE_COOKIE_JAR
565 if ( NULL != config->jar )
567 fclose( config->jar );
570 #endif /* def FEATURE_COOKIE_JAR */
572 freez(config->confdir);
573 freez(config->logdir);
574 freez(config->templdir);
576 freez(config->haddr);
577 freez(config->logfile);
579 for (i = 0; i < MAX_AF_FILES; i++)
581 freez(config->actions_file_short[i]);
582 freez(config->actions_file[i]);
583 freez(config->re_filterfile_short[i]);
584 freez(config->re_filterfile[i]);
587 freez(config->admin_address);
588 freez(config->proxy_info_url);
589 freez(config->proxy_args);
590 freez(config->usermanual);
592 #ifdef FEATURE_COOKIE_JAR
593 freez(config->jarfile);
594 #endif /* def FEATURE_COOKIE_JAR */
597 freez(config->trustfile);
598 list_remove_all(config->trust_info);
599 #endif /* def FEATURE_TRUST */
601 for (i = 0; i < MAX_AF_FILES; i++)
603 freez(config->re_filterfile[i]);
610 #ifdef FEATURE_GRACEFUL_TERMINATION
611 /*********************************************************************
613 * Function : unload_current_config_file
615 * Description : Unloads current config file - reset to state at
616 * beginning of program.
622 *********************************************************************/
623 void unload_current_config_file(void)
625 if (current_configfile)
627 current_configfile->unloader = unload_configfile;
628 current_configfile = NULL;
634 /*********************************************************************
636 * Function : load_config
638 * Description : Load the config file and all parameters.
642 * Returns : The configuration_spec, or NULL on error.
644 *********************************************************************/
645 struct configuration_spec * load_config(void)
647 char buf[BUFFER_SIZE];
649 FILE *configfp = NULL;
650 struct configuration_spec * config = NULL;
651 struct client_state * fake_csp;
652 struct file_list *fs;
653 unsigned long linenum = 0;
656 if ( !check_file_changed(current_configfile, configfile, &fs))
658 /* No need to load */
659 return ((struct configuration_spec *)current_configfile->f);
663 log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E",
667 log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
669 #ifdef FEATURE_TOGGLE
670 global_toggle_state = 1;
671 #endif /* def FEATURE_TOGGLE */
673 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
679 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
680 /* Never get here - LOG_LEVEL_FATAL causes program exit */
684 * This is backwards from how it's usually done.
685 * Following the usual pattern, "fs" would be stored in a member
686 * variable in "csp", and then we'd access "config" from "fs->f",
687 * using a cast. However, "config" is used so often that a
688 * cast each time would be very ugly, and the extra indirection
689 * would waste CPU cycles. Therefore we store "config" in
690 * "csp->config", and "fs" in "csp->config->config_file_list".
692 config->config_file_list = fs;
697 config->multi_threaded = 1;
698 config->hport = HADDR_PORT;
699 config->buffer_limit = 4096 * 1024;
700 config->usermanual = strdup(USER_MANUAL_URL);
701 config->proxy_args = strdup("");
702 config->forwarded_connect_retries = 0;
703 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
704 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
705 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
707 if ((configfp = fopen(configfile, "r")) == NULL)
709 log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E",
711 /* Never get here - LOG_LEVEL_FATAL causes program exit */
714 while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
716 char cmd[BUFFER_SIZE];
717 char arg[BUFFER_SIZE];
718 char tmp[BUFFER_SIZE];
720 struct access_control_list *cur_acl;
721 #endif /* def FEATURE_ACL */
722 struct forward_spec *cur_fwd;
728 /* Copy command (i.e. up to space or tab) into cmd */
731 while (*p && (*p != ' ') && (*p != '\t'))
737 /* Skip over the whitespace in buf */
738 while (*p && ((*p == ' ') || (*p == '\t')))
743 /* Copy the argument into arg */
746 /* Should never happen, but check this anyway */
752 /* Make sure the command field is lower case */
757 *p = (char)ijb_tolower(*p);
761 /* Save the argument for show-proxy-args */
762 savearg(cmd, arg, config);
765 switch( hash_string( cmd ) )
767 /* *************************************************************************
768 * actionsfile actions-file-name
769 * In confdir by default
770 * *************************************************************************/
771 case hash_actions_file :
773 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
778 if (i >= MAX_AF_FILES)
780 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
781 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
784 config->actions_file_short[i] = strdup(arg);
785 p = malloc(strlen(arg) + sizeof(".action"));
788 log_error(LOG_LEVEL_FATAL, "Out of memory");
791 strcat(p, ".action");
792 config->actions_file[i] = make_path(config->confdir, p);
795 /* *************************************************************************
796 * accept-intercepted-requests
797 * *************************************************************************/
798 case hash_accept_intercepted_requests:
799 if ((*arg != '\0') && (0 != atoi(arg)))
801 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
805 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
809 /* *************************************************************************
810 * admin-address email-address
811 * *************************************************************************/
812 case hash_admin_address :
813 freez(config->admin_address);
814 config->admin_address = strdup(arg);
817 /* *************************************************************************
819 * *************************************************************************/
820 case hash_buffer_limit :
821 config->buffer_limit = (size_t)(1024 * atoi(arg));
824 /* *************************************************************************
825 * confdir directory-name
826 * *************************************************************************/
828 freez(config->confdir);
829 config->confdir = make_path( NULL, arg);
832 /* *************************************************************************
834 * Specifies debug level, multiple values are ORed together.
835 * *************************************************************************/
837 config->debug |= atoi(arg);
840 /* *************************************************************************
841 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
842 * *************************************************************************/
844 case hash_deny_access:
845 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
847 if ((vec_count != 1) && (vec_count != 2))
849 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
850 "deny-access directive in configuration file.");
851 string_append(&config->proxy_args,
852 "<br>\nWARNING: Wrong number of parameters for "
853 "deny-access directive in configuration file.<br><br>\n");
857 /* allocate a new node */
858 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
862 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
863 /* Never get here - LOG_LEVEL_FATAL causes program exit */
866 cur_acl->action = ACL_DENY;
868 if (acl_addr(vec[0], cur_acl->src) < 0)
870 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
871 "for deny-access directive in configuration file: \"%s\"", vec[0]);
872 string_append(&config->proxy_args,
873 "<br>\nWARNING: Invalid source address, port or netmask "
874 "for deny-access directive in configuration file: \"");
875 string_append(&config->proxy_args,
877 string_append(&config->proxy_args,
884 if (acl_addr(vec[1], cur_acl->dst) < 0)
886 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
887 "for deny-access directive in configuration file: \"%s\"", vec[1]);
888 string_append(&config->proxy_args,
889 "<br>\nWARNING: Invalid destination address, port or netmask "
890 "for deny-access directive in configuration file: \"");
891 string_append(&config->proxy_args,
893 string_append(&config->proxy_args,
901 * Add it to the list. Note we reverse the list to get the
902 * behaviour the user expects. With both the ACL and
903 * actions file, the last match wins. However, the internal
904 * implementations are different: The actions file is stored
905 * in the same order as the file, and scanned completely.
906 * With the ACL, we reverse the order as we load it, then
907 * when we scan it we stop as soon as we get a match.
909 cur_acl->next = config->acl;
910 config->acl = cur_acl;
913 #endif /* def FEATURE_ACL */
915 /* *************************************************************************
916 * enable-edit-actions 0|1
917 * *************************************************************************/
918 #ifdef FEATURE_CGI_EDIT_ACTIONS
919 case hash_enable_edit_actions:
920 if ((*arg != '\0') && (0 != atoi(arg)))
922 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
926 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
929 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
931 /* *************************************************************************
932 * enable-remote-toggle 0|1
933 * *************************************************************************/
934 #ifdef FEATURE_CGI_EDIT_ACTIONS
935 case hash_enable_remote_toggle:
936 if ((*arg != '\0') && (0 != atoi(arg)))
938 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
942 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
945 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
947 /* *************************************************************************
948 * enable-remote-http-toggle 0|1
949 * *************************************************************************/
950 case hash_enable_remote_http_toggle:
951 if ((*arg != '\0') && (0 != atoi(arg)))
953 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
957 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
961 /* *************************************************************************
962 * filterfile file-name
963 * In confdir by default.
964 * *************************************************************************/
965 case hash_filterfile :
967 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
972 if (i >= MAX_AF_FILES)
974 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
975 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
978 config->re_filterfile_short[i] = strdup(arg);
979 p = malloc(strlen(arg) + 1);
982 log_error(LOG_LEVEL_FATAL, "Out of memory");
985 config->re_filterfile[i] = make_path(config->confdir, p);
989 /* *************************************************************************
990 * forward url-pattern (.|http-proxy-host[:port])
991 * *************************************************************************/
993 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
997 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
998 "directive in configuration file.");
999 string_append(&config->proxy_args,
1000 "<br>\nWARNING: Wrong number of parameters for "
1001 "forward directive in configuration file.");
1005 /* allocate a new node */
1006 cur_fwd = zalloc(sizeof(*cur_fwd));
1007 if (cur_fwd == NULL)
1009 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1010 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1014 cur_fwd->type = SOCKS_NONE;
1016 /* Save the URL pattern */
1017 if (create_url_spec(cur_fwd->url, vec[0]))
1019 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1020 "directive in configuration file.");
1021 string_append(&config->proxy_args,
1022 "<br>\nWARNING: Bad URL specifier for "
1023 "forward directive in configuration file.");
1027 /* Parse the parent HTTP proxy host:port */
1030 if (strcmp(p, ".") != 0)
1032 cur_fwd->forward_host = strdup(p);
1034 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1037 cur_fwd->forward_port = atoi(p);
1040 if (cur_fwd->forward_port <= 0)
1042 cur_fwd->forward_port = 8000;
1047 cur_fwd->next = config->forward;
1048 config->forward = cur_fwd;
1052 /* *************************************************************************
1053 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1054 * *************************************************************************/
1055 case hash_forward_socks4:
1056 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1060 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1061 "forward-socks4 directive in configuration file.");
1062 string_append(&config->proxy_args,
1063 "<br>\nWARNING: Wrong number of parameters for "
1064 "forward-socks4 directive in configuration file.");
1068 /* allocate a new node */
1069 cur_fwd = zalloc(sizeof(*cur_fwd));
1070 if (cur_fwd == NULL)
1072 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1073 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1077 cur_fwd->type = SOCKS_4;
1079 /* Save the URL pattern */
1080 if (create_url_spec(cur_fwd->url, vec[0]))
1082 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1083 "directive in configuration file.");
1084 string_append(&config->proxy_args,
1085 "<br>\nWARNING: Bad URL specifier for "
1086 "forward-socks4 directive in configuration file.");
1090 /* Parse the SOCKS proxy host[:port] */
1093 if (strcmp(p, ".") != 0)
1095 cur_fwd->gateway_host = strdup(p);
1097 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1100 cur_fwd->gateway_port = atoi(p);
1102 if (cur_fwd->gateway_port <= 0)
1104 cur_fwd->gateway_port = 1080;
1108 /* Parse the parent HTTP proxy host[:port] */
1111 if (strcmp(p, ".") != 0)
1113 cur_fwd->forward_host = strdup(p);
1115 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1118 cur_fwd->forward_port = atoi(p);
1121 if (cur_fwd->forward_port <= 0)
1123 cur_fwd->forward_port = 8000;
1128 cur_fwd->next = config->forward;
1129 config->forward = cur_fwd;
1133 /* *************************************************************************
1134 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1135 * *************************************************************************/
1136 case hash_forward_socks4a:
1137 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1141 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1142 "forward-socks4a directive in configuration file.");
1143 string_append(&config->proxy_args,
1144 "<br>\nWARNING: Wrong number of parameters for "
1145 "forward-socks4a directive in configuration file.");
1149 /* allocate a new node */
1150 cur_fwd = zalloc(sizeof(*cur_fwd));
1151 if (cur_fwd == NULL)
1153 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1154 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1158 cur_fwd->type = SOCKS_4A;
1160 /* Save the URL pattern */
1161 if (create_url_spec(cur_fwd->url, vec[0]))
1163 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1164 "directive in configuration file.");
1165 string_append(&config->proxy_args,
1166 "<br>\nWARNING: Bad URL specifier for "
1167 "forward-socks4a directive in configuration file.");
1171 /* Parse the SOCKS proxy host[:port] */
1174 cur_fwd->gateway_host = strdup(p);
1176 if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1179 cur_fwd->gateway_port = atoi(p);
1181 if (cur_fwd->gateway_port <= 0)
1183 cur_fwd->gateway_port = 1080;
1186 /* Parse the parent HTTP proxy host[:port] */
1189 if (strcmp(p, ".") != 0)
1191 cur_fwd->forward_host = strdup(p);
1193 if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1196 cur_fwd->forward_port = atoi(p);
1199 if (cur_fwd->forward_port <= 0)
1201 cur_fwd->forward_port = 8000;
1206 cur_fwd->next = config->forward;
1207 config->forward = cur_fwd;
1211 /* *************************************************************************
1212 * forwarded-connect-retries n
1213 * *************************************************************************/
1214 case hash_forwarded_connect_retries :
1215 config->forwarded_connect_retries = atoi(arg);
1218 /* *************************************************************************
1219 * jarfile jar-file-name
1220 * In logdir by default
1221 * *************************************************************************/
1222 #ifdef FEATURE_COOKIE_JAR
1224 freez(config->jarfile);
1225 config->jarfile = make_path(config->logdir, arg);
1227 #endif /* def FEATURE_COOKIE_JAR */
1229 /* *************************************************************************
1230 * listen-address [ip][:port]
1231 * *************************************************************************/
1232 case hash_listen_address :
1233 freez(config->haddr);
1234 config->haddr = strdup(arg);
1237 /* *************************************************************************
1238 * logdir directory-name
1239 * *************************************************************************/
1241 freez(config->logdir);
1242 config->logdir = make_path(NULL, arg);
1245 /* *************************************************************************
1246 * logfile log-file-name
1247 * In logdir by default
1248 * *************************************************************************/
1250 freez(config->logfile);
1251 config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
1254 /* *************************************************************************
1255 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1256 * *************************************************************************/
1258 case hash_permit_access:
1259 vec_count = ssplit(arg, " \t", vec, SZ(vec), 1, 1);
1261 if ((vec_count != 1) && (vec_count != 2))
1263 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1264 "permit-access directive in configuration file.");
1265 string_append(&config->proxy_args,
1266 "<br>\nWARNING: Wrong number of parameters for "
1267 "permit-access directive in configuration file.<br><br>\n");
1272 /* allocate a new node */
1273 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1275 if (cur_acl == NULL)
1277 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1278 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1281 cur_acl->action = ACL_PERMIT;
1283 if (acl_addr(vec[0], cur_acl->src) < 0)
1285 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1286 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1287 string_append(&config->proxy_args,
1288 "<br>\nWARNING: Invalid source address, port or netmask for "
1289 "permit-access directive in configuration file: \"");
1290 string_append(&config->proxy_args,
1292 string_append(&config->proxy_args,
1299 if (acl_addr(vec[1], cur_acl->dst) < 0)
1301 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1302 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1303 string_append(&config->proxy_args,
1304 "<br>\nWARNING: Invalid destination address, port or netmask for "
1305 "permit-access directive in configuration file: \"");
1306 string_append(&config->proxy_args,
1308 string_append(&config->proxy_args,
1316 * Add it to the list. Note we reverse the list to get the
1317 * behaviour the user expects. With both the ACL and
1318 * actions file, the last match wins. However, the internal
1319 * implementations are different: The actions file is stored
1320 * in the same order as the file, and scanned completely.
1321 * With the ACL, we reverse the order as we load it, then
1322 * when we scan it we stop as soon as we get a match.
1324 cur_acl->next = config->acl;
1325 config->acl = cur_acl;
1328 #endif /* def FEATURE_ACL */
1330 /* *************************************************************************
1331 * proxy-info-url url
1332 * *************************************************************************/
1333 case hash_proxy_info_url :
1334 freez(config->proxy_info_url);
1335 config->proxy_info_url = strdup(arg);
1338 /* *************************************************************************
1340 * *************************************************************************/
1341 case hash_single_threaded :
1342 config->multi_threaded = 0;
1345 /* *************************************************************************
1346 * split-large-cgi-forms
1347 * *************************************************************************/
1348 case hash_split_large_cgi_forms :
1349 if ((*arg != '\0') && (0 != atoi(arg)))
1351 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1355 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1359 /* *************************************************************************
1360 * templdir directory-name
1361 * *************************************************************************/
1362 case hash_templdir :
1363 freez(config->templdir);
1364 config->templdir = make_path(NULL, arg);
1367 /* *************************************************************************
1369 * *************************************************************************/
1370 #ifdef FEATURE_TOGGLE
1372 global_toggle_state = atoi(arg);
1374 #endif /* def FEATURE_TOGGLE */
1376 /* *************************************************************************
1377 * trust-info-url url
1378 * *************************************************************************/
1379 #ifdef FEATURE_TRUST
1380 case hash_trust_info_url :
1381 enlist(config->trust_info, arg);
1383 #endif /* def FEATURE_TRUST */
1385 /* *************************************************************************
1386 * trustfile filename
1387 * (In confdir by default.)
1388 * *************************************************************************/
1389 #ifdef FEATURE_TRUST
1390 case hash_trustfile :
1391 freez(config->trustfile);
1392 config->trustfile = make_path(config->confdir, arg);
1394 #endif /* def FEATURE_TRUST */
1396 /* *************************************************************************
1398 * *************************************************************************/
1399 case hash_usermanual :
1400 freez(config->usermanual);
1401 config->usermanual = strdup(arg);
1404 /* *************************************************************************
1405 * Win32 Console options:
1406 * *************************************************************************/
1408 /* *************************************************************************
1410 * *************************************************************************/
1412 case hash_hide_console :
1415 #endif /*def _WIN_CONSOLE*/
1418 /* *************************************************************************
1419 * Win32 GUI options:
1420 * *************************************************************************/
1422 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1423 /* *************************************************************************
1424 * activity-animation (0|1)
1425 * *************************************************************************/
1426 case hash_activity_animation :
1427 g_bShowActivityAnimation = atoi(arg);
1430 /* *************************************************************************
1431 * close-button-minimizes (0|1)
1432 * *************************************************************************/
1433 case hash_close_button_minimizes :
1434 g_bCloseHidesWindow = atoi(arg);
1437 /* *************************************************************************
1438 * log-buffer-size (0|1)
1439 * *************************************************************************/
1440 case hash_log_buffer_size :
1441 g_bLimitBufferSize = atoi(arg);
1444 /* *************************************************************************
1445 * log-font-name fontnane
1446 * *************************************************************************/
1447 case hash_log_font_name :
1448 strcpy( g_szFontFaceName, arg );
1451 /* *************************************************************************
1453 * *************************************************************************/
1454 case hash_log_font_size :
1455 g_nFontSize = atoi(arg);
1458 /* *************************************************************************
1459 * log-highlight-messages (0|1)
1460 * *************************************************************************/
1461 case hash_log_highlight_messages :
1462 g_bHighlightMessages = atoi(arg);
1465 /* *************************************************************************
1467 * *************************************************************************/
1468 case hash_log_max_lines :
1469 g_nMaxBufferLines = atoi(arg);
1472 /* *************************************************************************
1473 * log-messages (0|1)
1474 * *************************************************************************/
1475 case hash_log_messages :
1476 g_bLogMessages = atoi(arg);
1479 /* *************************************************************************
1480 * show-on-task-bar (0|1)
1481 * *************************************************************************/
1482 case hash_show_on_task_bar :
1483 g_bShowOnTaskBar = atoi(arg);
1486 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1489 /* *************************************************************************
1490 * Warnings about unsupported features
1491 * *************************************************************************/
1493 case hash_deny_access:
1494 #endif /* ndef FEATURE_ACL */
1495 #ifndef FEATURE_CGI_EDIT_ACTIONS
1496 case hash_enable_edit_actions:
1497 case hash_enable_remote_toggle:
1498 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1499 #ifndef FEATURE_COOKIE_JAR
1501 #endif /* ndef FEATURE_COOKIE_JAR */
1503 case hash_permit_access:
1504 #endif /* ndef FEATURE_ACL */
1505 #ifndef FEATURE_TOGGLE
1507 #endif /* ndef FEATURE_TOGGLE */
1508 #ifndef FEATURE_TRUST
1509 case hash_trustfile :
1510 case hash_trust_info_url :
1511 #endif /* ndef FEATURE_TRUST */
1513 #ifndef _WIN_CONSOLE
1514 case hash_hide_console :
1515 #endif /* ndef _WIN_CONSOLE */
1517 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1518 case hash_activity_animation :
1519 case hash_close_button_minimizes :
1520 case hash_log_buffer_size :
1521 case hash_log_font_name :
1522 case hash_log_font_size :
1523 case hash_log_highlight_messages :
1524 case hash_log_max_lines :
1525 case hash_log_messages :
1526 case hash_show_on_task_bar :
1527 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1528 /* These warnings are annoying - so hide them. -- Jon */
1529 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1532 /* *************************************************************************/
1534 /* *************************************************************************/
1536 * I decided that I liked this better as a warning than an
1537 * error. To change back to an error, just change log level
1538 * to LOG_LEVEL_FATAL.
1540 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1541 "in configuration file (%s).", buf, hash_string(cmd), linenum, configfile);
1542 string_append(&config->proxy_args,
1543 " <b><font color=\"red\">WARNING: unrecognized directive, ignored</font></b>");
1546 /* *************************************************************************/
1547 } /* end switch( hash_string(cmd) ) */
1548 } /* end while ( read_config_line(...) ) */
1552 if (NULL == config->proxy_args)
1554 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1557 init_error_log(Argv[0], config->logfile, config->debug);
1559 if (config->actions_file[0])
1561 add_loader(load_actions_file, config);
1564 if (config->re_filterfile)
1566 add_loader(load_re_filterfile, config);
1569 #ifdef FEATURE_TRUST
1570 if (config->trustfile)
1572 add_loader(load_trustfile, config);
1574 #endif /* def FEATURE_TRUST */
1576 #ifdef FEATURE_COOKIE_JAR
1577 if ( NULL != config->jarfile )
1579 if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
1581 log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
1582 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1584 setbuf(config->jar, NULL);
1586 #endif /* def FEATURE_COOKIE_JAR */
1588 if ( NULL == config->haddr )
1590 config->haddr = strdup( HADDR_DEFAULT );
1593 if ( NULL != config->haddr )
1595 if (NULL != (p = strchr(config->haddr, ':')))
1600 config->hport = atoi(p);
1604 if (config->hport <= 0)
1607 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1608 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1610 if (*config->haddr == '\0')
1612 config->haddr = NULL;
1617 * Want to run all the loaders once now.
1619 * Need to set up a fake csp, so they can get to the config.
1621 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1622 fake_csp->config = config;
1624 if (run_loader(fake_csp))
1627 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1628 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1632 /* FIXME: this is a kludge for win32 */
1633 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1635 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1636 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1637 g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1639 #ifdef FEATURE_TRUST
1640 g_trustfile = config->trustfile;
1641 #endif /* def FEATURE_TRUST */
1644 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1645 /* FIXME: end kludge */
1648 config->need_bind = 1;
1650 if (current_configfile)
1652 struct configuration_spec * oldcfg = (struct configuration_spec *)
1653 current_configfile->f;
1655 * Check if config->haddr,hport == oldcfg->haddr,hport
1657 * The following could be written more compactly as a single,
1658 * (unreadably long) if statement.
1660 config->need_bind = 0;
1661 if (config->hport != oldcfg->hport)
1663 config->need_bind = 1;
1665 else if (config->haddr == NULL)
1667 if (oldcfg->haddr != NULL)
1669 config->need_bind = 1;
1672 else if (oldcfg->haddr == NULL)
1674 config->need_bind = 1;
1676 else if (0 != strcmp(config->haddr, oldcfg->haddr))
1678 config->need_bind = 1;
1681 current_configfile->unloader = unload_configfile;
1684 fs->next = files->next;
1687 current_configfile = fs;
1693 /*********************************************************************
1695 * Function : savearg
1697 * Description : Called from `load_config'. It saves each non-empty
1698 * and non-comment line from config into
1699 * config->proxy_args. This is used to create the
1700 * show-proxy-args page. On error, frees
1701 * config->proxy_args and sets it to NULL
1704 * 1 : command = config setting that was found
1705 * 2 : argument = the setting's argument (if any)
1706 * 3 : config = Configuration to save into.
1710 *********************************************************************/
1711 static void savearg(char *command, char *argument, struct configuration_spec * config)
1721 * Add config option name embedded in
1722 * link to it's section in the user-manual
1724 buf = strdup("\n<a href=\"");
1725 if (!strncmpic(config->usermanual, "file://", 7) ||
1726 !strncmpic(config->usermanual, "http", 4))
1728 string_append(&buf, config->usermanual);
1732 string_append(&buf, "http://");
1733 string_append(&buf, CGI_SITE_2_HOST);
1734 string_append(&buf, "/user-manual/");
1736 string_append(&buf, CONFIG_HELP_PREFIX);
1737 string_join (&buf, string_toupper(command));
1738 string_append(&buf, "\">");
1739 string_append(&buf, command);
1740 string_append(&buf, "</a> ");
1744 freez(config->proxy_args);
1748 if ( (NULL != argument) && ('\0' != *argument) )
1750 s = html_encode(argument);
1754 freez(config->proxy_args);
1758 if (strncmpic(argument, "http://", 7) == 0)
1760 string_append(&buf, "<a href=\"");
1761 string_append(&buf, s);
1762 string_append(&buf, "\">");
1763 string_join (&buf, s);
1764 string_append(&buf, "</a>");
1768 string_join (&buf, s);
1772 string_append(&buf, "<br>");
1773 string_join(&config->proxy_args, buf);