1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.129 2012/06/08 15:15:11 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-2009 the
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.
36 *********************************************************************/
42 #include <sys/types.h>
61 # endif /* ndef _WIN_CONSOLE */
63 #else /* ifndef _WIN32 */
67 # include <sys/wait.h>
69 # include <sys/time.h>
70 # include <sys/stat.h>
89 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
92 /* Privoxy is enabled by default. */
93 int global_toggle_state = 1;
94 #endif /* def FEATURE_TOGGLE */
96 /* The filename of the configfile */
97 const char *configfile = NULL;
100 * CGI functions will later need access to the invocation args,
101 * so we will make argc and argv global.
104 char * const * Argv = NULL;
106 static struct file_list *current_configfile = NULL;
110 * This takes the "cryptic" hash of each keyword and aliases them to
111 * something a little more readable. This also makes changing the
112 * hash values easier if they should change or the hash algorthm changes.
113 * Use the included "hash" program to find out what the hash will be
114 * for any string supplied on the command line. (Or just put it in the
115 * config file and read the number from the error message in the log).
117 * Please keep this list sorted alphabetically (but with the Windows
118 * console and GUI specific options last).
121 #define hash_actions_file 1196306641U /* "actionsfile" */
122 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
123 #define hash_admin_address 4112573064U /* "admin-address" */
124 #define hash_allow_cgi_request_crunching 258915987U /* "allow-cgi-request-crunching" */
125 #define hash_buffer_limit 1881726070U /* "buffer-limit */
126 #define hash_client_header_order 2701453514U /* "client-header-order" */
127 #define hash_compression_level 2464423563U /* "compression-level" */
128 #define hash_confdir 1978389U /* "confdir" */
129 #define hash_connection_sharing 1348841265U /* "connection-sharing" */
130 #define hash_debug 78263U /* "debug" */
131 #define hash_default_server_timeout 2530089913U /* "default-server-timeout" */
132 #define hash_deny_access 1227333715U /* "deny-access" */
133 #define hash_enable_edit_actions 2517097536U /* "enable-edit-actions" */
134 #define hash_enable_compression 3943696946U /* "enable-compression" */
135 #define hash_enable_remote_toggle 2979744683U /* "enable-remote-toggle" */
136 #define hash_enable_remote_http_toggle 110543988U /* "enable-remote-http-toggle" */
137 #define hash_enforce_blocks 1862427469U /* "enforce-blocks" */
138 #define hash_filterfile 250887266U /* "filterfile" */
139 #define hash_forward 2029845U /* "forward" */
140 #define hash_forward_socks4 3963965521U /* "forward-socks4" */
141 #define hash_forward_socks4a 2639958518U /* "forward-socks4a" */
142 #define hash_forward_socks5 3963965522U /* "forward-socks5" */
143 #define hash_forwarded_connect_retries 101465292U /* "forwarded-connect-retries" */
144 #define hash_handle_as_empty_returns_ok 1444873247U /* "handle-as-empty-doc-returns-ok" */
145 #define hash_hostname 10308071U /* "hostname" */
146 #define hash_keep_alive_timeout 3878599515U /* "keep-alive-timeout" */
147 #define hash_listen_address 1255650842U /* "listen-address" */
148 #define hash_logdir 422889U /* "logdir" */
149 #define hash_logfile 2114766U /* "logfile" */
150 #define hash_max_client_connections 3595884446U /* "max-client-connections" */
151 #define hash_permit_access 3587953268U /* "permit-access" */
152 #define hash_proxy_info_url 3903079059U /* "proxy-info-url" */
153 #define hash_single_threaded 4250084780U /* "single-threaded" */
154 #define hash_socket_timeout 1809001761U /* "socket-timeout" */
155 #define hash_split_large_cgi_forms 671658948U /* "split-large-cgi-forms" */
156 #define hash_suppress_blocklists 1948693308U /* "suppress-blocklists" */
157 #define hash_templdir 11067889U /* "templdir" */
158 #define hash_toggle 447966U /* "toggle" */
159 #define hash_trust_info_url 430331967U /* "trust-info-url" */
160 #define hash_trustfile 56494766U /* "trustfile" */
161 #define hash_usermanual 1416668518U /* "user-manual" */
162 #define hash_activity_animation 1817904738U /* "activity-animation" */
163 #define hash_close_button_minimizes 3651284693U /* "close-button-minimizes" */
164 #define hash_hide_console 2048809870U /* "hide-console" */
165 #define hash_log_buffer_size 2918070425U /* "log-buffer-size" */
166 #define hash_log_font_name 2866730124U /* "log-font-name" */
167 #define hash_log_font_size 2866731014U /* "log-font-size" */
168 #define hash_log_highlight_messages 4032101240U /* "log-highlight-messages" */
169 #define hash_log_max_lines 2868344173U /* "log-max-lines" */
170 #define hash_log_messages 2291744899U /* "log-messages" */
171 #define hash_show_on_task_bar 215410365U /* "show-on-task-bar" */
174 static void savearg(char *command, char *argument, struct configuration_spec * config);
176 /*********************************************************************
178 * Function : unload_configfile
180 * Description : Free the config structure and all components.
183 * 1 : data: struct configuration_spec to unload
187 *********************************************************************/
188 static void unload_configfile (void * data)
190 struct configuration_spec * config = (struct configuration_spec *)data;
191 struct forward_spec *cur_fwd = config->forward;
195 struct access_control_list *cur_acl = config->acl;
197 while (cur_acl != NULL)
199 struct access_control_list * next_acl = cur_acl->next;
204 #endif /* def FEATURE_ACL */
206 while (cur_fwd != NULL)
208 struct forward_spec * next_fwd = cur_fwd->next;
209 free_url_spec(cur_fwd->url);
211 freez(cur_fwd->gateway_host);
212 freez(cur_fwd->forward_host);
216 config->forward = NULL;
218 freez(config->confdir);
219 freez(config->logdir);
220 freez(config->templdir);
221 freez(config->hostname);
223 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
225 freez(config->haddr[i]);
227 freez(config->logfile);
229 for (i = 0; i < MAX_AF_FILES; i++)
231 freez(config->actions_file_short[i]);
232 freez(config->actions_file[i]);
233 freez(config->re_filterfile_short[i]);
234 freez(config->re_filterfile[i]);
237 list_remove_all(config->ordered_client_headers);
239 freez(config->admin_address);
240 freez(config->proxy_info_url);
241 freez(config->proxy_args);
242 freez(config->usermanual);
245 freez(config->trustfile);
246 list_remove_all(config->trust_info);
247 #endif /* def FEATURE_TRUST */
253 #ifdef FEATURE_GRACEFUL_TERMINATION
254 /*********************************************************************
256 * Function : unload_current_config_file
258 * Description : Unloads current config file - reset to state at
259 * beginning of program.
265 *********************************************************************/
266 void unload_current_config_file(void)
268 if (current_configfile)
270 current_configfile->unloader = unload_configfile;
271 current_configfile = NULL;
277 /*********************************************************************
279 * Function : parse_toggle_value
281 * Description : Parse the value of a directive that can only be
282 * enabled or disabled. Terminates with a fatal error
283 * if the value is NULL or something other than 0 or 1.
286 * 1 : name: The name of the directive. Used for log messages.
287 * 2 : value: The value to parse
290 * Returns : The numerical toggle state
292 *********************************************************************/
293 static int parse_toggle_state(const char *name, const char *value)
296 assert(name != NULL);
297 assert(value != NULL);
299 if ((value == NULL) || (*value == '\0'))
301 log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
304 toggle_state = atoi(value);
307 * Also check the length as atoi() doesn't mind
308 * garbage after a valid integer, but we do.
310 if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
312 log_error(LOG_LEVEL_FATAL,
313 "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
322 /*********************************************************************
324 * Function : parse_client_header_order
326 * Description : Parse the value of the header-order directive
329 * 1 : ordered_header_list: List to insert the ordered
331 * 2 : ordered_headers: The ordered header names separated
337 *********************************************************************/
338 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
340 char *original_headers_copy;
342 int number_of_headers;
345 assert(ordered_header_list != NULL);
346 assert(ordered_headers != NULL);
348 if (ordered_headers == NULL)
350 log_error(LOG_LEVEL_FATAL, "header-order used without argument");
354 * XXX: This estimate is guaranteed to be high enough as we
355 * let ssplit() ignore empty fields, but also a bit wasteful.
356 * The same hack is used in get_last_url() so it looks like
357 * a real solution is needed.
359 size_t max_segments = strlen(ordered_headers) / 2;
360 if (max_segments == 0)
364 vector = malloc_or_die(max_segments * sizeof(char *));
366 original_headers_copy = strdup_or_die(ordered_headers);
368 number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
369 if (number_of_headers == -1)
371 log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
374 for (i = 0; i < number_of_headers; i++)
376 if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
378 log_error(LOG_LEVEL_FATAL,
379 "Failed to enlist ordered header: %s", vector[i]);
384 freez(original_headers_copy);
391 /*********************************************************************
393 * Function : load_config
395 * Description : Load the config file and all parameters.
397 * XXX: more than thousand lines long
398 * and thus in serious need of refactoring.
402 * Returns : The configuration_spec, or NULL on error.
404 *********************************************************************/
405 struct configuration_spec * load_config(void)
409 FILE *configfp = NULL;
410 struct configuration_spec * config = NULL;
411 struct client_state * fake_csp;
412 struct file_list *fs;
413 unsigned long linenum = 0;
415 char *logfile = NULL;
417 if (!check_file_changed(current_configfile, configfile, &fs))
419 /* No need to load */
420 return ((struct configuration_spec *)current_configfile->f);
424 log_error(LOG_LEVEL_FATAL,
425 "can't check configuration file '%s': %E", configfile);
429 if (NULL != current_configfile)
431 log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
434 #ifdef FEATURE_TOGGLE
435 global_toggle_state = 1;
436 #endif /* def FEATURE_TOGGLE */
438 fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
444 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
449 * This is backwards from how it's usually done.
450 * Following the usual pattern, "fs" would be stored in a member
451 * variable in "csp", and then we'd access "config" from "fs->f",
452 * using a cast. However, "config" is used so often that a
453 * cast each time would be very ugly, and the extra indirection
454 * would waste CPU cycles. Therefore we store "config" in
455 * "csp->config", and "fs" in "csp->config->config_file_list".
457 config->config_file_list = fs;
462 config->multi_threaded = 1;
463 config->buffer_limit = 4096 * 1024;
464 config->usermanual = strdup(USER_MANUAL_URL);
465 config->proxy_args = strdup("");
466 config->forwarded_connect_retries = 0;
467 config->max_client_connections = 0;
468 config->socket_timeout = 300; /* XXX: Should be a macro. */
469 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
470 config->default_server_timeout = 0;
471 config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
472 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
473 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
475 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
476 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
477 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
478 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
479 #ifdef FEATURE_COMPRESSION
480 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
482 * XXX: Run some benchmarks to see if there are better default values.
484 config->compression_level = 1;
487 configfp = fopen(configfile, "r");
488 if (NULL == configfp)
490 log_error(LOG_LEVEL_FATAL,
491 "can't open configuration file '%s': %E", configfile);
492 /* Never get here - LOG_LEVEL_FATAL causes program exit */
495 while (read_config_line(configfp, &linenum, &buf) != NULL)
497 char cmd[BUFFER_SIZE];
498 char arg[BUFFER_SIZE];
499 char tmp[BUFFER_SIZE];
501 struct access_control_list *cur_acl;
502 #endif /* def FEATURE_ACL */
503 struct forward_spec *cur_fwd;
506 unsigned int directive_hash;
508 strlcpy(tmp, buf, sizeof(tmp));
510 /* Copy command (i.e. up to space or tab) into cmd */
513 while (*p && (*p != ' ') && (*p != '\t'))
519 /* Skip over the whitespace in buf */
520 while (*p && ((*p == ' ') || (*p == '\t')))
525 /* Copy the argument into arg */
526 if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
528 log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
531 /* Should never happen, but check this anyway */
538 /* Make sure the command field is lower case */
539 for (p = cmd; *p; p++)
541 if (privoxy_isupper(*p))
543 *p = (char)privoxy_tolower(*p);
547 directive_hash = hash_string(cmd);
548 switch (directive_hash)
550 /* *************************************************************************
551 * actionsfile actions-file-name
552 * In confdir by default
553 * *************************************************************************/
554 case hash_actions_file :
556 while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
561 if (i >= MAX_AF_FILES)
563 log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
564 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
567 config->actions_file_short[i] = strdup(arg);
568 config->actions_file[i] = make_path(config->confdir, arg);
571 /* *************************************************************************
572 * accept-intercepted-requests
573 * *************************************************************************/
574 case hash_accept_intercepted_requests:
575 if (parse_toggle_state(cmd, arg) == 1)
577 config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
581 config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
585 /* *************************************************************************
586 * admin-address email-address
587 * *************************************************************************/
588 case hash_admin_address :
589 freez(config->admin_address);
590 config->admin_address = strdup(arg);
593 /* *************************************************************************
594 * allow-cgi-request-crunching
595 * *************************************************************************/
596 case hash_allow_cgi_request_crunching:
597 if (parse_toggle_state(cmd, arg) == 1)
599 config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
603 config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
607 /* *************************************************************************
609 * *************************************************************************/
610 case hash_buffer_limit :
611 config->buffer_limit = (size_t)(1024 * atoi(arg));
614 /* *************************************************************************
615 * client-header-order header-1 header-2 ... header-n
616 * *************************************************************************/
617 case hash_client_header_order:
618 list_remove_all(config->ordered_client_headers);
619 parse_client_header_order(config->ordered_client_headers, arg);
622 /* *************************************************************************
623 * confdir directory-name
624 * *************************************************************************/
626 freez(config->confdir);
627 config->confdir = make_path(NULL, arg);
630 /* *************************************************************************
631 * compression-level 0-9
632 * *************************************************************************/
633 #ifdef FEATURE_COMPRESSION
634 case hash_compression_level :
637 int compression_level = atoi(arg);
638 if (-1 <= compression_level && compression_level <= 9)
640 config->compression_level = compression_level;;
644 log_error(LOG_LEVEL_FATAL,
645 "Invalid compression-level value: %s", arg);
650 log_error(LOG_LEVEL_FATAL,
651 "Invalid compression-level directive. Compression value missing");
656 /* *************************************************************************
657 * connection-sharing (0|1)
658 * *************************************************************************/
659 #ifdef FEATURE_CONNECTION_SHARING
660 case hash_connection_sharing :
661 if (parse_toggle_state(cmd, arg) == 1)
663 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
667 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
672 /* *************************************************************************
674 * Specifies debug level, multiple values are ORed together.
675 * *************************************************************************/
677 config->debug |= atoi(arg);
680 /* *************************************************************************
681 * default-server-timeout timeout
682 * *************************************************************************/
683 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
684 case hash_default_server_timeout :
687 int timeout = atoi(arg);
690 config->default_server_timeout = (unsigned int)timeout;
694 log_error(LOG_LEVEL_FATAL,
695 "Invalid default-server-timeout value: %s", arg);
701 /* *************************************************************************
702 * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
703 * *************************************************************************/
705 case hash_deny_access:
706 strlcpy(tmp, arg, sizeof(tmp));
707 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
709 if ((vec_count != 1) && (vec_count != 2))
711 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
712 "deny-access directive in configuration file.");
713 string_append(&config->proxy_args,
714 "<br>\nWARNING: Wrong number of parameters for "
715 "deny-access directive in configuration file.<br><br>\n");
719 /* allocate a new node */
720 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
724 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
725 /* Never get here - LOG_LEVEL_FATAL causes program exit */
728 cur_acl->action = ACL_DENY;
730 if (acl_addr(vec[0], cur_acl->src) < 0)
732 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
733 "for deny-access directive in configuration file: \"%s\"", vec[0]);
734 string_append(&config->proxy_args,
735 "<br>\nWARNING: Invalid source address, port or netmask "
736 "for deny-access directive in configuration file: \"");
737 string_append(&config->proxy_args,
739 string_append(&config->proxy_args,
746 if (acl_addr(vec[1], cur_acl->dst) < 0)
748 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
749 "for deny-access directive in configuration file: \"%s\"", vec[1]);
750 string_append(&config->proxy_args,
751 "<br>\nWARNING: Invalid destination address, port or netmask "
752 "for deny-access directive in configuration file: \"");
753 string_append(&config->proxy_args,
755 string_append(&config->proxy_args,
764 cur_acl->wildcard_dst = 1;
766 #endif /* def HAVE_RFC2553 */
769 * Add it to the list. Note we reverse the list to get the
770 * behaviour the user expects. With both the ACL and
771 * actions file, the last match wins. However, the internal
772 * implementations are different: The actions file is stored
773 * in the same order as the file, and scanned completely.
774 * With the ACL, we reverse the order as we load it, then
775 * when we scan it we stop as soon as we get a match.
777 cur_acl->next = config->acl;
778 config->acl = cur_acl;
781 #endif /* def FEATURE_ACL */
783 /* *************************************************************************
784 * enable-edit-actions 0|1
785 * *************************************************************************/
786 #ifdef FEATURE_CGI_EDIT_ACTIONS
787 case hash_enable_edit_actions:
788 if (parse_toggle_state(cmd, arg) == 1)
790 config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
794 config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
797 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
799 /* *************************************************************************
800 * enable-compression 0|1
801 * *************************************************************************/
802 #ifdef FEATURE_COMPRESSION
803 case hash_enable_compression:
804 if (parse_toggle_state(cmd, arg) == 1)
806 config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
810 config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
813 #endif /* def FEATURE_COMPRESSION */
816 /* *************************************************************************
817 * enable-remote-toggle 0|1
818 * *************************************************************************/
819 #ifdef FEATURE_TOGGLE
820 case hash_enable_remote_toggle:
821 if (parse_toggle_state(cmd, arg) == 1)
823 config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
827 config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
830 #endif /* def FEATURE_TOGGLE */
832 /* *************************************************************************
833 * enable-remote-http-toggle 0|1
834 * *************************************************************************/
835 case hash_enable_remote_http_toggle:
836 if (parse_toggle_state(cmd, arg) == 1)
838 config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
842 config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
846 /* *************************************************************************
848 * *************************************************************************/
849 case hash_enforce_blocks:
850 #ifdef FEATURE_FORCE_LOAD
851 if (parse_toggle_state(cmd, arg) == 1)
853 config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
857 config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
860 log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
861 "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
862 #endif /* def FEATURE_FORCE_LOAD */
865 /* *************************************************************************
866 * filterfile file-name
867 * In confdir by default.
868 * *************************************************************************/
869 case hash_filterfile :
871 while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
876 if (i >= MAX_AF_FILES)
878 log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
879 "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
882 config->re_filterfile_short[i] = strdup(arg);
883 config->re_filterfile[i] = make_path(config->confdir, arg);
887 /* *************************************************************************
888 * forward url-pattern (.|http-proxy-host[:port])
889 * *************************************************************************/
891 strlcpy(tmp, arg, sizeof(tmp));
892 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
896 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
897 "directive in configuration file.");
898 string_append(&config->proxy_args,
899 "<br>\nWARNING: Wrong number of parameters for "
900 "forward directive in configuration file.");
904 /* allocate a new node */
905 cur_fwd = zalloc(sizeof(*cur_fwd));
908 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
909 /* Never get here - LOG_LEVEL_FATAL causes program exit */
913 cur_fwd->type = SOCKS_NONE;
915 /* Save the URL pattern */
916 if (create_url_spec(cur_fwd->url, vec[0]))
918 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
919 "directive in configuration file.");
920 string_append(&config->proxy_args,
921 "<br>\nWARNING: Bad URL specifier for "
922 "forward directive in configuration file.");
926 /* Parse the parent HTTP proxy host:port */
929 if (strcmp(p, ".") != 0)
931 cur_fwd->forward_port = 8000;
932 parse_forwarder_address(p, &cur_fwd->forward_host,
933 &cur_fwd->forward_port);
937 cur_fwd->next = config->forward;
938 config->forward = cur_fwd;
942 /* *************************************************************************
943 * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
944 * *************************************************************************/
945 case hash_forward_socks4:
946 strlcpy(tmp, arg, sizeof(tmp));
947 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
951 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
952 "forward-socks4 directive in configuration file.");
953 string_append(&config->proxy_args,
954 "<br>\nWARNING: Wrong number of parameters for "
955 "forward-socks4 directive in configuration file.");
959 /* allocate a new node */
960 cur_fwd = zalloc(sizeof(*cur_fwd));
963 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
964 /* Never get here - LOG_LEVEL_FATAL causes program exit */
968 cur_fwd->type = SOCKS_4;
970 /* Save the URL pattern */
971 if (create_url_spec(cur_fwd->url, vec[0]))
973 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
974 "directive in configuration file.");
975 string_append(&config->proxy_args,
976 "<br>\nWARNING: Bad URL specifier for "
977 "forward-socks4 directive in configuration file.");
981 /* Parse the SOCKS proxy host[:port] */
984 /* XXX: This check looks like a bug. */
985 if (strcmp(p, ".") != 0)
987 cur_fwd->gateway_port = 1080;
988 parse_forwarder_address(p, &cur_fwd->gateway_host,
989 &cur_fwd->gateway_port);
992 /* Parse the parent HTTP proxy host[:port] */
995 if (strcmp(p, ".") != 0)
997 cur_fwd->forward_port = 8000;
998 parse_forwarder_address(p, &cur_fwd->forward_host,
999 &cur_fwd->forward_port);
1003 cur_fwd->next = config->forward;
1004 config->forward = cur_fwd;
1008 /* *************************************************************************
1009 * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1010 * *************************************************************************/
1011 case hash_forward_socks4a:
1012 case hash_forward_socks5:
1013 strlcpy(tmp, arg, sizeof(tmp));
1014 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1018 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1019 "forward-socks4a directive in configuration file.");
1020 string_append(&config->proxy_args,
1021 "<br>\nWARNING: Wrong number of parameters for "
1022 "forward-socks4a directive in configuration file.");
1026 /* allocate a new node */
1027 cur_fwd = zalloc(sizeof(*cur_fwd));
1028 if (cur_fwd == NULL)
1030 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1031 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1035 if (directive_hash == hash_forward_socks4a)
1037 cur_fwd->type = SOCKS_4A;
1041 cur_fwd->type = SOCKS_5;
1044 /* Save the URL pattern */
1045 if (create_url_spec(cur_fwd->url, vec[0]))
1047 log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1048 "directive in configuration file.");
1049 string_append(&config->proxy_args,
1050 "<br>\nWARNING: Bad URL specifier for "
1051 "forward-socks4a directive in configuration file.");
1055 /* Parse the SOCKS proxy host[:port] */
1058 cur_fwd->gateway_port = 1080;
1059 parse_forwarder_address(p, &cur_fwd->gateway_host,
1060 &cur_fwd->gateway_port);
1062 /* Parse the parent HTTP proxy host[:port] */
1065 if (strcmp(p, ".") != 0)
1067 cur_fwd->forward_port = 8000;
1068 parse_forwarder_address(p, &cur_fwd->forward_host,
1069 &cur_fwd->forward_port);
1073 cur_fwd->next = config->forward;
1074 config->forward = cur_fwd;
1078 /* *************************************************************************
1079 * forwarded-connect-retries n
1080 * *************************************************************************/
1081 case hash_forwarded_connect_retries :
1082 config->forwarded_connect_retries = atoi(arg);
1085 /* *************************************************************************
1086 * handle-as-empty-doc-returns-ok 0|1
1088 * Workaround for firefox hanging on blocked javascript pages.
1089 * Block with the "+handle-as-empty-document" flag and set the
1090 * "handle-as-empty-doc-returns-ok" run-time config flag so that
1091 * Privoxy returns a 200/OK status instead of a 403/Forbidden status
1092 * to the browser for blocked pages.
1093 ***************************************************************************/
1094 case hash_handle_as_empty_returns_ok:
1095 if (parse_toggle_state(cmd, arg) == 1)
1097 config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1101 config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1105 /* *************************************************************************
1106 * hostname hostname-to-show-on-cgi-pages
1107 * *************************************************************************/
1108 case hash_hostname :
1109 freez(config->hostname);
1110 config->hostname = strdup(arg);
1111 if (NULL == config->hostname)
1113 log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1117 /* *************************************************************************
1118 * keep-alive-timeout timeout
1119 * *************************************************************************/
1120 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1121 case hash_keep_alive_timeout :
1124 int timeout = atoi(arg);
1127 config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1128 config->keep_alive_timeout = (unsigned int)timeout;
1132 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1138 /* *************************************************************************
1139 * listen-address [ip][:port]
1140 * *************************************************************************/
1141 case hash_listen_address :
1143 while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1148 if (i >= MAX_LISTENING_SOCKETS)
1150 log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1151 "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1152 MAX_LISTENING_SOCKETS);
1154 config->haddr[i] = strdup(arg);
1155 if (NULL == config->haddr[i])
1157 log_error(LOG_LEVEL_FATAL, "Out of memory while copying listening address");
1161 /* *************************************************************************
1162 * logdir directory-name
1163 * *************************************************************************/
1165 freez(config->logdir);
1166 config->logdir = make_path(NULL, arg);
1169 /* *************************************************************************
1170 * logfile log-file-name
1171 * In logdir by default
1172 * *************************************************************************/
1176 logfile = make_path(config->logdir, arg);
1177 if (NULL == logfile)
1179 log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1184 /* *************************************************************************
1185 * max-client-connections number
1186 * *************************************************************************/
1187 case hash_max_client_connections :
1190 int max_client_connections = atoi(arg);
1191 if (0 <= max_client_connections)
1193 config->max_client_connections = max_client_connections;
1198 /* *************************************************************************
1199 * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1200 * *************************************************************************/
1202 case hash_permit_access:
1203 strlcpy(tmp, arg, sizeof(tmp));
1204 vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1206 if ((vec_count != 1) && (vec_count != 2))
1208 log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1209 "permit-access directive in configuration file.");
1210 string_append(&config->proxy_args,
1211 "<br>\nWARNING: Wrong number of parameters for "
1212 "permit-access directive in configuration file.<br><br>\n");
1217 /* allocate a new node */
1218 cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1220 if (cur_acl == NULL)
1222 log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1223 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1226 cur_acl->action = ACL_PERMIT;
1228 if (acl_addr(vec[0], cur_acl->src) < 0)
1230 log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1231 "for permit-access directive in configuration file: \"%s\"", vec[0]);
1232 string_append(&config->proxy_args,
1233 "<br>\nWARNING: Invalid source address, port or netmask for "
1234 "permit-access directive in configuration file: \"");
1235 string_append(&config->proxy_args,
1237 string_append(&config->proxy_args,
1244 if (acl_addr(vec[1], cur_acl->dst) < 0)
1246 log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1247 "for permit-access directive in configuration file: \"%s\"", vec[1]);
1248 string_append(&config->proxy_args,
1249 "<br>\nWARNING: Invalid destination address, port or netmask for "
1250 "permit-access directive in configuration file: \"");
1251 string_append(&config->proxy_args,
1253 string_append(&config->proxy_args,
1262 cur_acl->wildcard_dst = 1;
1264 #endif /* def HAVE_RFC2553 */
1267 * Add it to the list. Note we reverse the list to get the
1268 * behaviour the user expects. With both the ACL and
1269 * actions file, the last match wins. However, the internal
1270 * implementations are different: The actions file is stored
1271 * in the same order as the file, and scanned completely.
1272 * With the ACL, we reverse the order as we load it, then
1273 * when we scan it we stop as soon as we get a match.
1275 cur_acl->next = config->acl;
1276 config->acl = cur_acl;
1279 #endif /* def FEATURE_ACL */
1281 /* *************************************************************************
1282 * proxy-info-url url
1283 * *************************************************************************/
1284 case hash_proxy_info_url :
1285 freez(config->proxy_info_url);
1286 config->proxy_info_url = strdup(arg);
1289 /* *************************************************************************
1291 * *************************************************************************/
1292 case hash_single_threaded :
1293 config->multi_threaded = 0;
1296 /* *************************************************************************
1297 * socket-timeout numer_of_seconds
1298 * *************************************************************************/
1299 case hash_socket_timeout :
1302 int socket_timeout = atoi(arg);
1303 if (0 <= socket_timeout)
1305 config->socket_timeout = socket_timeout;
1309 log_error(LOG_LEVEL_FATAL,
1310 "Invalid socket-timeout: '%s'", arg);
1315 /* *************************************************************************
1316 * split-large-cgi-forms
1317 * *************************************************************************/
1318 case hash_split_large_cgi_forms :
1319 if (parse_toggle_state(cmd, arg) == 1)
1321 config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1325 config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1329 /* *************************************************************************
1330 * templdir directory-name
1331 * *************************************************************************/
1332 case hash_templdir :
1333 freez(config->templdir);
1334 config->templdir = make_path(NULL, arg);
1337 /* *************************************************************************
1339 * *************************************************************************/
1340 #ifdef FEATURE_TOGGLE
1342 global_toggle_state = atoi(arg);
1344 #endif /* def FEATURE_TOGGLE */
1346 /* *************************************************************************
1347 * trust-info-url url
1348 * *************************************************************************/
1349 #ifdef FEATURE_TRUST
1350 case hash_trust_info_url :
1351 enlist(config->trust_info, arg);
1353 #endif /* def FEATURE_TRUST */
1355 /* *************************************************************************
1356 * trustfile filename
1357 * (In confdir by default.)
1358 * *************************************************************************/
1359 #ifdef FEATURE_TRUST
1360 case hash_trustfile :
1361 freez(config->trustfile);
1362 config->trustfile = make_path(config->confdir, arg);
1364 #endif /* def FEATURE_TRUST */
1366 /* *************************************************************************
1368 * *************************************************************************/
1369 case hash_usermanual :
1371 * XXX: If this isn't the first config directive, the
1372 * show-status page links to the website documentation
1373 * for the directives that were already parsed. Lame.
1375 freez(config->usermanual);
1376 config->usermanual = strdup(arg);
1379 /* *************************************************************************
1380 * Win32 Console options:
1381 * *************************************************************************/
1383 /* *************************************************************************
1385 * *************************************************************************/
1387 case hash_hide_console :
1390 #endif /*def _WIN_CONSOLE*/
1393 /* *************************************************************************
1394 * Win32 GUI options:
1395 * *************************************************************************/
1397 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1398 /* *************************************************************************
1399 * activity-animation (0|1)
1400 * *************************************************************************/
1401 case hash_activity_animation :
1402 g_bShowActivityAnimation = atoi(arg);
1405 /* *************************************************************************
1406 * close-button-minimizes (0|1)
1407 * *************************************************************************/
1408 case hash_close_button_minimizes :
1409 g_bCloseHidesWindow = atoi(arg);
1412 /* *************************************************************************
1413 * log-buffer-size (0|1)
1414 * *************************************************************************/
1415 case hash_log_buffer_size :
1416 g_bLimitBufferSize = atoi(arg);
1419 /* *************************************************************************
1420 * log-font-name fontname
1421 * *************************************************************************/
1422 case hash_log_font_name :
1423 if (strlcpy(g_szFontFaceName, arg,
1424 sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1426 log_error(LOG_LEVEL_FATAL,
1427 "log-font-name argument '%s' is longer than %u characters.",
1428 arg, sizeof(g_szFontFaceName)-1);
1432 /* *************************************************************************
1434 * *************************************************************************/
1435 case hash_log_font_size :
1436 g_nFontSize = atoi(arg);
1439 /* *************************************************************************
1440 * log-highlight-messages (0|1)
1441 * *************************************************************************/
1442 case hash_log_highlight_messages :
1443 g_bHighlightMessages = atoi(arg);
1446 /* *************************************************************************
1448 * *************************************************************************/
1449 case hash_log_max_lines :
1450 g_nMaxBufferLines = atoi(arg);
1453 /* *************************************************************************
1454 * log-messages (0|1)
1455 * *************************************************************************/
1456 case hash_log_messages :
1457 g_bLogMessages = atoi(arg);
1460 /* *************************************************************************
1461 * show-on-task-bar (0|1)
1462 * *************************************************************************/
1463 case hash_show_on_task_bar :
1464 g_bShowOnTaskBar = atoi(arg);
1467 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1470 /* *************************************************************************
1471 * Warnings about unsupported features
1472 * *************************************************************************/
1474 case hash_deny_access:
1475 #endif /* ndef FEATURE_ACL */
1476 #ifndef FEATURE_CGI_EDIT_ACTIONS
1477 case hash_enable_edit_actions:
1478 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1479 #ifndef FEATURE_TOGGLE
1480 case hash_enable_remote_toggle:
1481 #endif /* ndef FEATURE_TOGGLE */
1483 case hash_permit_access:
1484 #endif /* ndef FEATURE_ACL */
1485 #ifndef FEATURE_TOGGLE
1487 #endif /* ndef FEATURE_TOGGLE */
1488 #ifndef FEATURE_TRUST
1489 case hash_trustfile :
1490 case hash_trust_info_url :
1491 #endif /* ndef FEATURE_TRUST */
1493 #ifndef _WIN_CONSOLE
1494 case hash_hide_console :
1495 #endif /* ndef _WIN_CONSOLE */
1497 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1498 case hash_activity_animation :
1499 case hash_close_button_minimizes :
1500 case hash_log_buffer_size :
1501 case hash_log_font_name :
1502 case hash_log_font_size :
1503 case hash_log_highlight_messages :
1504 case hash_log_max_lines :
1505 case hash_log_messages :
1506 case hash_show_on_task_bar :
1507 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1508 /* These warnings are annoying - so hide them. -- Jon */
1509 /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1512 /* *************************************************************************/
1514 /* *************************************************************************/
1516 * I decided that I liked this better as a warning than an
1517 * error. To change back to an error, just change log level
1518 * to LOG_LEVEL_FATAL.
1520 log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1521 "'%s' (%uU) in line %lu in configuration file (%s).",
1522 buf, directive_hash, linenum, configfile);
1523 string_append(&config->proxy_args,
1524 " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1527 /* *************************************************************************/
1528 } /* end switch(hash_string(cmd)) */
1530 /* Save the argument for the show-status page. */
1531 savearg(cmd, arg, config);
1533 } /* end while (read_config_line(...)) */
1537 set_debug_level(config->debug);
1539 freez(config->logfile);
1543 if (NULL != logfile)
1545 config->logfile = logfile;
1546 init_error_log(Argv[0], config->logfile);
1554 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1555 if (config->default_server_timeout > config->keep_alive_timeout)
1557 log_error(LOG_LEVEL_ERROR,
1558 "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1559 config->default_server_timeout, config->keep_alive_timeout);
1560 config->default_server_timeout = config->keep_alive_timeout;
1562 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1564 #ifdef FEATURE_CONNECTION_SHARING
1565 if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1567 if (config->multi_threaded)
1569 set_keep_alive_timeout(config->keep_alive_timeout);
1574 * While we could use keep-alive without multiple threads
1575 * if we didn't bother with enforcing the connection timeout,
1576 * that might make Tor users sad, even though they shouldn't
1577 * enable the single-threaded option anyway.
1579 * XXX: We could still use Proxy-Connection: keep-alive.
1581 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1582 log_error(LOG_LEVEL_ERROR,
1583 "Config option single-threaded disables connection keep-alive.");
1586 else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1588 log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1589 "has no effect if keep-alive-timeout isn't set.");
1590 config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1592 #endif /* def FEATURE_CONNECTION_SHARING */
1594 if (NULL == config->proxy_args)
1596 log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1599 if (config->re_filterfile[0])
1601 add_loader(load_re_filterfiles, config);
1604 if (config->actions_file[0])
1606 add_loader(load_action_files, config);
1609 #ifdef FEATURE_TRUST
1610 if (config->trustfile)
1612 add_loader(load_trustfile, config);
1614 #endif /* def FEATURE_TRUST */
1616 if (NULL == config->haddr[0])
1618 config->haddr[0] = strdup(HADDR_DEFAULT);
1619 if (NULL == config->haddr[0])
1621 log_error(LOG_LEVEL_FATAL, "Out of memory while copying default listening address");
1625 for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1627 if ((*config->haddr[i] == '[')
1628 && (NULL != (p = strchr(config->haddr[i], ']')))
1630 && (0 < (config->hport[i] = atoi(p + 2))))
1633 memmove((void *)config->haddr[i], config->haddr[i] + 1,
1634 (size_t)(p - config->haddr[i]));
1636 else if (NULL != (p = strchr(config->haddr[i], ':'))
1637 && (0 < (config->hport[i] = atoi(p + 1))))
1643 log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1644 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1646 if (*config->haddr[i] == '\0')
1649 * Only the port specified. We stored it in config->hport[i]
1650 * and don't need its text representation anymore.
1651 * Use config->hport[i] == 0 to iterate listening addresses since
1654 freez(config->haddr[i]);
1659 * Want to run all the loaders once now.
1661 * Need to set up a fake csp, so they can get to the config.
1663 fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1664 fake_csp->config = config;
1666 if (run_loader(fake_csp))
1669 log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1670 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1674 /* FIXME: this is a kludge for win32 */
1675 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1677 g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1678 g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1679 g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1680 g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1682 #ifdef FEATURE_TRUST
1683 g_trustfile = config->trustfile;
1684 #endif /* def FEATURE_TRUST */
1687 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1688 /* FIXME: end kludge */
1691 config->need_bind = 1;
1693 if (current_configfile)
1695 struct configuration_spec * oldcfg = (struct configuration_spec *)
1696 current_configfile->f;
1698 * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
1700 * The following could be written more compactly as a single,
1701 * (unreadably long) if statement.
1703 config->need_bind = 0;
1705 for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
1707 if (config->hport[i] != oldcfg->hport[i])
1709 config->need_bind = 1;
1711 else if (config->haddr[i] == NULL)
1713 if (oldcfg->haddr[i] != NULL)
1715 config->need_bind = 1;
1718 else if (oldcfg->haddr[i] == NULL)
1720 config->need_bind = 1;
1722 else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
1724 config->need_bind = 1;
1728 current_configfile->unloader = unload_configfile;
1731 fs->next = files->next;
1734 current_configfile = fs;
1740 /*********************************************************************
1742 * Function : savearg
1744 * Description : Called from `load_config'. It saves each non-empty
1745 * and non-comment line from config into
1746 * config->proxy_args. This is used to create the
1747 * show-proxy-args page. On error, frees
1748 * config->proxy_args and sets it to NULL
1751 * 1 : command = config setting that was found
1752 * 2 : argument = the setting's argument (if any)
1753 * 3 : config = Configuration to save into.
1757 *********************************************************************/
1758 static void savearg(char *command, char *argument, struct configuration_spec * config)
1767 * Add config option name embedded in
1768 * link to its section in the user-manual
1770 buf = strdup("\n<a href=\"");
1771 if (!strncmpic(config->usermanual, "file://", 7) ||
1772 !strncmpic(config->usermanual, "http", 4))
1774 string_append(&buf, config->usermanual);
1778 string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1780 string_append(&buf, CONFIG_HELP_PREFIX);
1781 string_join (&buf, string_toupper(command));
1782 string_append(&buf, "\">");
1783 string_append(&buf, command);
1784 string_append(&buf, "</a> ");
1788 freez(config->proxy_args);
1792 if ((NULL != argument) && ('\0' != *argument))
1794 s = html_encode(argument);
1798 freez(config->proxy_args);
1802 if (strncmpic(argument, "http://", 7) == 0)
1804 string_append(&buf, "<a href=\"");
1805 string_append(&buf, s);
1806 string_append(&buf, "\">");
1807 string_join (&buf, s);
1808 string_append(&buf, "</a>");
1812 string_join (&buf, s);
1816 string_append(&buf, "<br>");
1817 string_join(&config->proxy_args, buf);