chat(): Remove pointless NULL-pointer check
[privoxy.git] / loadcfg.c
1 /*********************************************************************
2  *
3  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
4  *
5  * Purpose     :  Loads settings from the configuration file into
6  *                global variables.  This file contains both the
7  *                routine to load the configuration and the global
8  *                variables it writes to.
9  *
10  * Copyright   :  Written by and Copyright (C) 2001-2017 the
11  *                Privoxy team. https://www.privoxy.org/
12  *
13  *                Based on the Internet Junkbuster originally written
14  *                by and Copyright (C) 1997 Anonymous Coders and
15  *                Junkbusters Corporation.  http://www.junkbusters.com
16  *
17  *                This program is free software; you can redistribute it
18  *                and/or modify it under the terms of the GNU General
19  *                Public License as published by the Free Software
20  *                Foundation; either version 2 of the License, or (at
21  *                your option) any later version.
22  *
23  *                This program is distributed in the hope that it will
24  *                be useful, but WITHOUT ANY WARRANTY; without even the
25  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
26  *                PARTICULAR PURPOSE.  See the GNU General Public
27  *                License for more details.
28  *
29  *                The GNU General Public License should be included with
30  *                this file.  If not, you can view it at
31  *                http://www.gnu.org/copyleft/gpl.html
32  *                or write to the Free Software Foundation, Inc., 59
33  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
34  *
35  *********************************************************************/
36
37
38 #include "config.h"
39
40 #include <stdio.h>
41 #include <sys/types.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <signal.h>
45 #include <fcntl.h>
46 #include <errno.h>
47 #include <ctype.h>
48 #include <assert.h>
49
50 #ifdef _WIN32
51
52 # ifndef STRICT
53 #  define STRICT
54 # endif
55 # include <winsock2.h>
56 # include <windows.h>
57
58 # include "win32.h"
59 # ifndef _WIN_CONSOLE
60 #  include "w32log.h"
61 # endif /* ndef _WIN_CONSOLE */
62
63 #else /* ifndef _WIN32 */
64
65 # include <unistd.h>
66 # include <sys/wait.h>
67 # include <sys/time.h>
68 # include <sys/stat.h>
69 # include <signal.h>
70
71 #endif
72
73 #include "project.h"
74 #include "loadcfg.h"
75 #include "list.h"
76 #include "jcc.h"
77 #include "filters.h"
78 #include "loaders.h"
79 #include "miscutil.h"
80 #include "errlog.h"
81 #include "ssplit.h"
82 #include "encode.h"
83 #include "urlmatch.h"
84 #include "cgi.h"
85 #include "gateway.h"
86 #ifdef FEATURE_CLIENT_TAGS
87 #include "client-tags.h"
88 #endif
89
90 /*
91  * Default number of seconds after which an
92  * open connection will no longer be reused.
93  */
94 #define DEFAULT_KEEP_ALIVE_TIMEOUT 180
95
96 /*
97  * Default backlog passed to listen().
98  */
99 #define DEFAULT_LISTEN_BACKLOG 128
100
101 #ifdef FEATURE_TOGGLE
102 /* Privoxy is enabled by default. */
103 int global_toggle_state = 1;
104 #endif /* def FEATURE_TOGGLE */
105
106 /* The filename of the configfile */
107 const char *configfile  = NULL;
108
109 /*
110  * CGI functions will later need access to the invocation args,
111  * so we will make argc and argv global.
112  */
113 int Argc = 0;
114 char * const * Argv = NULL;
115
116 static struct file_list *current_configfile = NULL;
117
118
119 /*
120  * This takes the "cryptic" hash of each keyword and aliases them to
121  * something a little more readable.  This also makes changing the
122  * hash values easier if they should change or the hash algorithm changes.
123  * Use the included "hash" program to find out what the hash will be
124  * for any string supplied on the command line.  (Or just put it in the
125  * config file and read the number from the error message in the log).
126  *
127  * Please keep this list sorted alphabetically (but with the Windows
128  * console and GUI specific options last).
129  */
130
131 #define hash_actions_file                1196306641U /* "actionsfile" */
132 #define hash_accept_intercepted_requests 1513024973U /* "accept-intercepted-requests" */
133 #define hash_admin_address               4112573064U /* "admin-address" */
134 #define hash_allow_cgi_request_crunching  258915987U /* "allow-cgi-request-crunching" */
135 #define hash_buffer_limit                1881726070U /* "buffer-limit */
136 #define hash_ca_cert_file                1622923720U /* "ca-cert-file" */
137 #define hash_ca_directory                1623615670U /* "ca-directory" */
138 #define hash_ca_key_file                 1184187891U /* "ca-key-file" */
139 #define hash_ca_password                 1184543320U /* "ca-password" */
140 #define hash_certificate_directory       1367994217U /* "certificate-directory" */
141 #define hash_client_header_order         2701453514U /* "client-header-order" */
142 #define hash_client_specific_tag         3353703383U /* "client-specific-tag" */
143 #define hash_client_tag_lifetime          647957580U /* "client-tag-lifetime" */
144 #define hash_compression_level           2464423563U /* "compression-level" */
145 #define hash_confdir                        1978389U /* "confdir" */
146 #define hash_connection_sharing          1348841265U /* "connection-sharing" */
147 #define hash_cors_allowed_origin         2769345637U /* "cors-allowed-origin" */
148 #define hash_debug                            78263U /* "debug" */
149 #define hash_default_server_timeout      2530089913U /* "default-server-timeout" */
150 #define hash_deny_access                 1227333715U /* "deny-access" */
151 #define hash_enable_accept_filter        2909040407U /* "enable-accept-filter" */
152 #define hash_enable_edit_actions         2517097536U /* "enable-edit-actions" */
153 #define hash_enable_compression          3943696946U /* "enable-compression" */
154 #define hash_enable_proxy_authentication_forwarding 4040610791U /* enable-proxy-authentication-forwarding */
155 #define hash_enable_remote_toggle        2979744683U /* "enable-remote-toggle" */
156 #define hash_enable_remote_http_toggle    110543988U /* "enable-remote-http-toggle" */
157 #define hash_enforce_blocks              1862427469U /* "enforce-blocks" */
158 #define hash_filterfile                   250887266U /* "filterfile" */
159 #define hash_forward                        2029845U /* "forward" */
160 #define hash_forward_socks4              3963965521U /* "forward-socks4" */
161 #define hash_forward_socks4a             2639958518U /* "forward-socks4a" */
162 #define hash_forward_socks5              3963965522U /* "forward-socks5" */
163 #define hash_forward_socks5t             2639958542U /* "forward-socks5t" */
164 #define hash_forwarded_connect_retries    101465292U /* "forwarded-connect-retries" */
165 #define hash_handle_as_empty_returns_ok  1444873247U /* "handle-as-empty-doc-returns-ok" */
166 #define hash_hostname                      10308071U /* "hostname" */
167 #define hash_keep_alive_timeout          3878599515U /* "keep-alive-timeout" */
168 #define hash_listen_address              1255650842U /* "listen-address" */
169 #define hash_listen_backlog              1255655735U /* "listen-backlog" */
170 #define hash_logdir                          422889U /* "logdir" */
171 #define hash_logfile                        2114766U /* "logfile" */
172 #define hash_max_client_connections      3595884446U /* "max-client-connections" */
173 #define hash_permit_access               3587953268U /* "permit-access" */
174 #define hash_proxy_info_url              3903079059U /* "proxy-info-url" */
175 #define hash_receive_buffer_size         2880297454U /* "receive-buffer-size */
176 #define hash_single_threaded             4250084780U /* "single-threaded" */
177 #define hash_socket_timeout              1809001761U /* "socket-timeout" */
178 #define hash_split_large_cgi_forms        671658948U /* "split-large-cgi-forms" */
179 #define hash_suppress_blocklists         1948693308U /* "suppress-blocklists" */
180 #define hash_templdir                      11067889U /* "templdir" */
181 #define hash_temporary_directory         1824125181U /* "temporary-directory" */
182 #define hash_tolerate_pipelining         1360286620U /* "tolerate-pipelining" */
183 #define hash_toggle                          447966U /* "toggle" */
184 #define hash_trust_info_url               430331967U /* "trust-info-url" */
185 #define hash_trust_x_forwarded_for       2971537414U /* "trust-x-forwarded-for" */
186 #define hash_trusted_cgi_referrer        4270883427U /* "trusted-cgi-referrer" */
187 #define hash_trusted_cas_file            2679803024U /* "trusted-cas-files" */
188 #define hash_trustfile                     56494766U /* "trustfile" */
189 #define hash_usermanual                  1416668518U /* "user-manual" */
190 #define hash_activity_animation          1817904738U /* "activity-animation" */
191 #define hash_close_button_minimizes      3651284693U /* "close-button-minimizes" */
192 #define hash_hide_console                2048809870U /* "hide-console" */
193 #define hash_log_buffer_size             2918070425U /* "log-buffer-size" */
194 #define hash_log_font_name               2866730124U /* "log-font-name" */
195 #define hash_log_font_size               2866731014U /* "log-font-size" */
196 #define hash_log_highlight_messages      4032101240U /* "log-highlight-messages" */
197 #define hash_log_max_lines               2868344173U /* "log-max-lines" */
198 #define hash_log_messages                2291744899U /* "log-messages" */
199 #define hash_show_on_task_bar             215410365U /* "show-on-task-bar" */
200
201
202 static void savearg(char *command, char *argument, struct configuration_spec * config);
203 #ifdef FEATURE_CLIENT_TAGS
204 static void free_client_specific_tags(struct client_tag_spec *tag_list);
205 #endif
206
207 /*********************************************************************
208  *
209  * Function    :  unload_configfile
210  *
211  * Description :  Free the config structure and all components.
212  *
213  * Parameters  :
214  *          1  :  data: struct configuration_spec to unload
215  *
216  * Returns     :  N/A
217  *
218  *********************************************************************/
219 static void unload_configfile (void * data)
220 {
221    struct configuration_spec * config = (struct configuration_spec *)data;
222    struct forward_spec *cur_fwd = config->forward;
223    int i;
224
225 #ifdef FEATURE_ACL
226    struct access_control_list *cur_acl = config->acl;
227
228    while (cur_acl != NULL)
229    {
230       struct access_control_list * next_acl = cur_acl->next;
231       free(cur_acl);
232       cur_acl = next_acl;
233    }
234    config->acl = NULL;
235 #endif /* def FEATURE_ACL */
236
237    while (cur_fwd != NULL)
238    {
239       struct forward_spec * next_fwd = cur_fwd->next;
240
241       unload_forward_spec(cur_fwd);
242
243       cur_fwd = next_fwd;
244    }
245    config->forward = NULL;
246
247    freez(config->confdir);
248    freez(config->logdir);
249    freez(config->templdir);
250    freez(config->hostname);
251 #ifdef FEATURE_EXTERNAL_FILTERS
252    freez(config->temporary_directory);
253 #endif
254
255    for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
256    {
257       freez(config->haddr[i]);
258    }
259    freez(config->logfile);
260
261    for (i = 0; i < MAX_AF_FILES; i++)
262    {
263       freez(config->actions_file_short[i]);
264       freez(config->actions_file[i]);
265       freez(config->re_filterfile_short[i]);
266       freez(config->re_filterfile[i]);
267    }
268
269    list_remove_all(config->ordered_client_headers);
270
271    freez(config->admin_address);
272    freez(config->cors_allowed_origin);
273    freez(config->proxy_info_url);
274    freez(config->proxy_args);
275    freez(config->usermanual);
276    freez(config->trusted_cgi_referrer);
277
278 #ifdef FEATURE_HTTPS_INSPECTION
279    freez(config->ca_password);
280    freez(config->ca_directory);
281    freez(config->ca_cert_file);
282    freez(config->ca_key_file);
283    freez(config->certificate_directory);
284    freez(config->trusted_cas_file);
285 #endif
286
287 #ifdef FEATURE_TRUST
288    freez(config->trustfile);
289    list_remove_all(config->trust_info);
290 #endif /* def FEATURE_TRUST */
291
292 #ifdef FEATURE_CLIENT_TAGS
293    free_client_specific_tags(config->client_tags);
294 #endif
295
296    freez(config);
297 }
298
299
300 #ifdef FEATURE_GRACEFUL_TERMINATION
301 /*********************************************************************
302  *
303  * Function    :  unload_current_config_file
304  *
305  * Description :  Unloads current config file - reset to state at
306  *                beginning of program.
307  *
308  * Parameters  :  None
309  *
310  * Returns     :  N/A
311  *
312  *********************************************************************/
313 void unload_current_config_file(void)
314 {
315    if (current_configfile)
316    {
317       current_configfile->unloader = unload_configfile;
318       current_configfile = NULL;
319    }
320 }
321 #endif
322
323
324 #ifdef FEATURE_CLIENT_TAGS
325 /*********************************************************************
326  *
327  * Function    :  register_tag
328  *
329  * Description :  Registers a client-specific-tag and its description
330  *
331  * Parameters  :
332  *          1  :  config: The tag list
333  *          2  :  name:  The name of the client-specific-tag
334  *          3  :  description: The human-readable description for the tag
335  *
336  * Returns     :  N/A
337  *
338  *********************************************************************/
339 static void register_tag(struct client_tag_spec *tag_list,
340    const char *name, const char *description)
341 {
342    struct client_tag_spec *new_tag;
343    struct client_tag_spec *last_tag;
344
345    last_tag = tag_list;
346    while (last_tag->next != NULL)
347    {
348       last_tag = last_tag->next;
349    }
350    if (last_tag->name == NULL)
351    {
352       /* First entry */
353       new_tag = last_tag;
354    }
355    else
356    {
357       new_tag = zalloc_or_die(sizeof(struct client_tag_spec));
358    }
359    new_tag->name = strdup_or_die(name);
360    new_tag->description = strdup_or_die(description);
361    if (new_tag != last_tag)
362    {
363       last_tag->next = new_tag;
364    }
365 }
366
367
368 /*********************************************************************
369  *
370  * Function    :  free_client_specific_tags
371  *
372  * Description :  Frees client-specific tags and their descriptions
373  *
374  * Parameters  :
375  *          1  :  tag_list: The tag list to free
376  *
377  * Returns     :  N/A
378  *
379  *********************************************************************/
380 static void free_client_specific_tags(struct client_tag_spec *tag_list)
381 {
382    struct client_tag_spec *this_tag;
383    struct client_tag_spec *next_tag;
384
385    next_tag = tag_list;
386    do
387    {
388       this_tag = next_tag;
389       next_tag = next_tag->next;
390
391       freez(this_tag->name);
392       freez(this_tag->description);
393
394       if (this_tag != tag_list)
395       {
396          freez(this_tag);
397       }
398    } while (next_tag != NULL);
399 }
400 #endif /* def FEATURE_CLIENT_TAGS */
401
402
403 /*********************************************************************
404  *
405  * Function    :  parse_numeric_value
406  *
407  * Description :  Parse the value of a directive that can only have
408  *                a single numeric value. Terminates with a fatal error
409  *                if the value is NULL or not numeric.
410  *
411  * Parameters  :
412  *          1  :  name:  The name of the directive. Used for log messages.
413  *          2  :  value: The value to parse
414  *
415  *
416  * Returns     :  The numerical value as integer
417  *
418  *********************************************************************/
419 static int parse_numeric_value(const char *name, const char *value)
420 {
421    int number;
422    char *endptr;
423
424    assert(name != NULL);
425    assert(value != NULL);
426
427    if ((value == NULL) || (*value == '\0'))
428    {
429       log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
430    }
431
432    number = (int)strtol(value, &endptr, 0);
433    if (*endptr != '\0')
434    {
435       log_error(LOG_LEVEL_FATAL,
436          "Directive '%s' used with non-numerical value: '%s'", name, value);
437    }
438
439    return number;
440
441 }
442
443
444 /*********************************************************************
445  *
446  * Function    :  parse_toggle_value
447  *
448  * Description :  Parse the value of a directive that can only be
449  *                enabled or disabled. Terminates with a fatal error
450  *                if the value is NULL or something other than 0 or 1.
451  *
452  * Parameters  :
453  *          1  :  name:  The name of the directive. Used for log messages.
454  *          2  :  value: The value to parse
455  *
456  *
457  * Returns     :  The numerical toggle state
458  *
459  *********************************************************************/
460 static int parse_toggle_state(const char *name, const char *value)
461 {
462    int toggle_state;
463    assert(name != NULL);
464    assert(value != NULL);
465
466    if ((value == NULL) || (*value == '\0'))
467    {
468       log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
469    }
470
471    toggle_state = atoi(value);
472
473    /*
474     * Also check the length as atoi() doesn't mind
475     * garbage after a valid integer, but we do.
476     */
477    if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
478    {
479       log_error(LOG_LEVEL_FATAL,
480          "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
481          name, value);
482    }
483
484    return toggle_state;
485
486 }
487
488
489 /*********************************************************************
490  *
491  * Function    :  parse_client_header_order
492  *
493  * Description :  Parse the value of the header-order directive
494  *
495  * Parameters  :
496  *          1  :  ordered_header_list:  List to insert the ordered
497  *                                      headers into.
498  *          2  :  ordered_headers:  The ordered header names separated
499  *                                  by spaces or tabs.
500  *
501  *
502  * Returns     :  N/A
503  *
504  *********************************************************************/
505 static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
506 {
507    char *original_headers_copy;
508    char **vector;
509    size_t max_segments;
510    int number_of_headers;
511    int i;
512
513    assert(ordered_header_list != NULL);
514    assert(ordered_headers != NULL);
515
516    if (ordered_headers == NULL)
517    {
518       log_error(LOG_LEVEL_FATAL, "header-order used without argument");
519    }
520
521    /*
522     * XXX: This estimate is guaranteed to be high enough as we
523     *      let ssplit() ignore empty fields, but also a bit wasteful.
524     *      The same hack is used in get_last_url() so it looks like
525     *      a real solution is needed.
526     */
527    max_segments = strlen(ordered_headers) / 2;
528    if (max_segments == 0)
529    {
530       max_segments = 1;
531    }
532    vector = malloc_or_die(max_segments * sizeof(char *));
533
534    original_headers_copy = strdup_or_die(ordered_headers);
535
536    number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
537    if (number_of_headers == -1)
538    {
539       log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
540    }
541
542    for (i = 0; i < number_of_headers; i++)
543    {
544       if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
545       {
546          log_error(LOG_LEVEL_FATAL,
547             "Failed to enlist ordered header: %s", vector[i]);
548       }
549    }
550
551    freez(vector);
552    freez(original_headers_copy);
553
554    return;
555
556 }
557
558
559 /*********************************************************************
560  *
561  * Function    :  load_config
562  *
563  * Description :  Load the config file and all parameters.
564  *
565  *                XXX: more than thousand lines long
566  *                and thus in serious need of refactoring.
567  *
568  * Parameters  :  None
569  *
570  * Returns     :  The configuration_spec, or NULL on error.
571  *
572  *********************************************************************/
573 struct configuration_spec * load_config(void)
574 {
575    char *buf = NULL;
576    char *p, *q;
577    FILE *configfp = NULL;
578    struct configuration_spec * config = NULL;
579    struct client_state * fake_csp;
580    struct file_list *fs;
581    unsigned long linenum = 0;
582    int i;
583    char *logfile          = NULL;
584 #ifdef FEATURE_HTTPS_INSPECTION
585    char *ca_cert_file     = NULL;
586    char *ca_key_file      = NULL;
587    char *ca_directory     = NULL;
588    char *trusted_cas_file = NULL;
589    char *certificate_directory = NULL;
590 #endif
591
592    if (!check_file_changed(current_configfile, configfile, &fs))
593    {
594       /* No need to load */
595       return ((struct configuration_spec *)current_configfile->f);
596    }
597    if (NULL == fs)
598    {
599       log_error(LOG_LEVEL_FATAL,
600          "can't check configuration file '%s':  %E", configfile);
601       return NULL;
602    }
603
604    if (NULL != current_configfile)
605    {
606       log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
607    }
608
609 #ifdef FEATURE_TOGGLE
610    global_toggle_state = 1;
611 #endif /* def FEATURE_TOGGLE */
612
613    fs->f = config = zalloc_or_die(sizeof(*config));
614
615    /*
616     * This is backwards from how it's usually done.
617     * Following the usual pattern, "fs" would be stored in a member
618     * variable in "csp", and then we'd access "config" from "fs->f",
619     * using a cast.  However, "config" is used so often that a
620     * cast each time would be very ugly, and the extra indirection
621     * would waste CPU cycles.  Therefore we store "config" in
622     * "csp->config", and "fs" in "csp->config->config_file_list".
623     */
624    config->config_file_list = fs;
625
626    /*
627     * Set to defaults
628     */
629    config->multi_threaded            = 1;
630    config->buffer_limit              = 4096 * 1024;
631    config->receive_buffer_size       = BUFFER_SIZE;
632    config->usermanual                = strdup_or_die(USER_MANUAL_URL);
633    config->proxy_args                = strdup_or_die("");
634    config->forwarded_connect_retries = 0;
635 #ifdef FEATURE_HTTPS_INSPECTION
636    config->ca_password               = strdup("");
637    ca_cert_file                      = strdup("cacert.crt");
638    ca_key_file                       = strdup("cakey.pem");
639    ca_directory                      = strdup("./CA");
640    trusted_cas_file                  = strdup("trustedCAs.pem");
641    certificate_directory             = strdup("./certs");
642 #endif
643
644 #ifdef FEATURE_CLIENT_TAGS
645    config->client_tag_lifetime       = 60;
646 #endif
647    config->trust_x_forwarded_for     = 0;
648 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
649    config->enable_accept_filter      = 0;
650 #endif
651    config->listen_backlog            = DEFAULT_LISTEN_BACKLOG;
652    config->trusted_cgi_referrer      = NULL;
653    /*
654     * 128 client sockets ought to be enough for everybody who can't
655     * be bothered to read the documentation to figure out how to
656     * increase the limit.
657     */
658    config->max_client_connections    = 128;
659    config->socket_timeout            = 300; /* XXX: Should be a macro. */
660 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
661    config->default_server_timeout    = 0;
662    config->keep_alive_timeout        = DEFAULT_KEEP_ALIVE_TIMEOUT;
663    config->feature_flags            &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
664    config->feature_flags            &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
665 #endif
666    config->feature_flags            &= ~RUNTIME_FEATURE_CGI_TOGGLE;
667    config->feature_flags            &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
668    config->feature_flags            &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
669    config->feature_flags            &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
670    config->feature_flags            &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
671 #ifdef FEATURE_COMPRESSION
672    config->feature_flags            &= ~RUNTIME_FEATURE_COMPRESSION;
673    /*
674     * XXX: Run some benchmarks to see if there are better default values.
675     */
676    config->compression_level         = 1;
677 #endif
678    config->feature_flags            &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
679    config->cors_allowed_origin       = NULL;
680
681    configfp = fopen(configfile, "r");
682    if (NULL == configfp)
683    {
684       log_error(LOG_LEVEL_FATAL,
685          "can't open configuration file '%s':  %E", configfile);
686       /* Never get here - LOG_LEVEL_FATAL causes program exit */
687    }
688
689    while (read_config_line(configfp, &linenum, &buf) != NULL)
690    {
691       char cmd[BUFFER_SIZE];
692       char arg[BUFFER_SIZE];
693       char tmp[BUFFER_SIZE];
694 #ifdef FEATURE_ACL
695       struct access_control_list *cur_acl;
696 #endif /* def FEATURE_ACL */
697       struct forward_spec *cur_fwd;
698       int vec_count;
699       char *vec[3];
700       unsigned int directive_hash;
701
702       strlcpy(tmp, buf, sizeof(tmp));
703
704       /* Copy command (i.e. up to space or tab) into cmd */
705       p = buf;
706       q = cmd;
707       while (*p && (*p != ' ') && (*p != '\t'))
708       {
709          *q++ = *p++;
710       }
711       *q = '\0';
712
713       /* Skip over the whitespace in buf */
714       while (*p && ((*p == ' ') || (*p == '\t')))
715       {
716          p++;
717       }
718
719       /* Copy the argument into arg */
720       if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
721       {
722          log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
723       }
724
725       /* Should never happen, but check this anyway */
726       if (*cmd == '\0')
727       {
728          freez(buf);
729          continue;
730       }
731
732       /* Make sure the command field is lower case */
733       for (p = cmd; *p; p++)
734       {
735          if (privoxy_isupper(*p))
736          {
737             *p = (char)privoxy_tolower(*p);
738          }
739       }
740
741       directive_hash = hash_string(cmd);
742       switch (directive_hash)
743       {
744 /* *************************************************************************
745  * actionsfile actions-file-name
746  * In confdir by default
747  * *************************************************************************/
748          case hash_actions_file :
749             i = 0;
750             while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
751             {
752                i++;
753             }
754
755             if (i >= MAX_AF_FILES)
756             {
757                log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
758                   "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
759                   MAX_AF_FILES);
760             }
761             config->actions_file_short[i] = strdup_or_die(arg);
762             config->actions_file[i] = make_path(config->confdir, arg);
763
764             break;
765 /* *************************************************************************
766  * accept-intercepted-requests
767  * *************************************************************************/
768          case hash_accept_intercepted_requests:
769             if (parse_toggle_state(cmd, arg) == 1)
770             {
771                config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
772             }
773             else
774             {
775                config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
776             }
777             break;
778
779 /* *************************************************************************
780  * admin-address email-address
781  * *************************************************************************/
782          case hash_admin_address :
783             freez(config->admin_address);
784             config->admin_address = strdup_or_die(arg);
785             break;
786
787 /* *************************************************************************
788  * allow-cgi-request-crunching
789  * *************************************************************************/
790          case hash_allow_cgi_request_crunching:
791             if (parse_toggle_state(cmd, arg) == 1)
792             {
793                config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
794             }
795             else
796             {
797                config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
798             }
799             break;
800
801 /* *************************************************************************
802  * buffer-limit n
803  * *************************************************************************/
804          case hash_buffer_limit :
805             config->buffer_limit = (size_t)(1024 * parse_numeric_value(cmd, arg));
806             break;
807
808 /* *************************************************************************
809  * client-header-order header-1 header-2 ... header-n
810  * *************************************************************************/
811          case hash_client_header_order:
812             list_remove_all(config->ordered_client_headers);
813             parse_client_header_order(config->ordered_client_headers, arg);
814             break;
815
816 /* *************************************************************************
817  * client-specific-tag tag-name description
818  * *************************************************************************/
819 #ifdef FEATURE_CLIENT_TAGS
820          case hash_client_specific_tag:
821             {
822                char *name;
823                char *description;
824
825                name = arg;
826                description = strstr(arg, " ");
827                if (description == NULL)
828                {
829                   log_error(LOG_LEVEL_FATAL,
830                      "client-specific-tag '%s' lacks a description.", name);
831                }
832                *description = '\0';
833                /*
834                 * The length is limited because we don't want truncated
835                 * HTML caused by the cgi interface using static buffer
836                 * sizes.
837                 */
838                if (strlen(name) > CLIENT_TAG_LENGTH_MAX)
839                {
840                   log_error(LOG_LEVEL_FATAL,
841                      "client-specific-tag '%s' is longer than %d characters.",
842                      name, CLIENT_TAG_LENGTH_MAX);
843                }
844                description++;
845                register_tag(config->client_tags, name, description);
846             }
847             break;
848 #endif /* def FEATURE_CLIENT_TAGS */
849
850 /* *************************************************************************
851  * client-tag-lifetime ttl
852  * *************************************************************************/
853 #ifdef FEATURE_CLIENT_TAGS
854          case hash_client_tag_lifetime:
855          {
856             int ttl = parse_numeric_value(cmd, arg);
857             if (0 <= ttl)
858             {
859                config->client_tag_lifetime = (unsigned)ttl;
860             }
861             else
862             {
863                log_error(LOG_LEVEL_FATAL,
864                   "client-tag-lifetime can't be negative.");
865             }
866             break;
867          }
868 #endif /* def FEATURE_CLIENT_TAGS */
869
870 /* *************************************************************************
871  * confdir directory-name
872  * *************************************************************************/
873          case hash_confdir :
874             freez(config->confdir);
875             config->confdir = make_path(NULL, arg);
876             break;
877
878 /* *************************************************************************
879  * compression-level 0-9
880  * *************************************************************************/
881 #ifdef FEATURE_COMPRESSION
882          case hash_compression_level :
883          {
884             int compression_level = parse_numeric_value(cmd, arg);
885             if (-1 <= compression_level && compression_level <= 9)
886             {
887                config->compression_level = compression_level;
888             }
889             else
890             {
891                log_error(LOG_LEVEL_FATAL,
892                   "Invalid compression-level value: %s", arg);
893             }
894             break;
895          }
896 #endif
897
898 /* *************************************************************************
899  * connection-sharing (0|1)
900  * *************************************************************************/
901 #ifdef FEATURE_CONNECTION_SHARING
902          case hash_connection_sharing :
903             if (parse_toggle_state(cmd, arg) == 1)
904             {
905                config->feature_flags |= RUNTIME_FEATURE_CONNECTION_SHARING;
906             }
907             else
908             {
909                config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
910             }
911             break;
912 #endif
913
914 /* *************************************************************************
915  * cors-allowed-origin http://www.example.org
916  * *************************************************************************/
917          case hash_cors_allowed_origin :
918             /*
919              * We don't validate the specified referrer as
920              * it's only used for string comparison.
921              */
922             freez(config->cors_allowed_origin);
923             config->cors_allowed_origin = strdup_or_die(arg);
924             break;
925
926 /* *************************************************************************
927  * debug n
928  * Specifies debug level, multiple values are ORed together.
929  * *************************************************************************/
930          case hash_debug :
931             config->debug |= parse_numeric_value(cmd, arg);
932             break;
933
934 /* *************************************************************************
935  * default-server-timeout timeout
936  * *************************************************************************/
937 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
938          case hash_default_server_timeout :
939          {
940             int timeout = parse_numeric_value(cmd, arg);
941             if (0 <= timeout)
942             {
943                config->default_server_timeout = (unsigned int)timeout;
944             }
945             else
946             {
947                log_error(LOG_LEVEL_FATAL,
948                   "Invalid default-server-timeout value: %s", arg);
949             }
950             break;
951          }
952 #endif
953
954 /* *************************************************************************
955  * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
956  * *************************************************************************/
957 #ifdef FEATURE_ACL
958          case hash_deny_access:
959             strlcpy(tmp, arg, sizeof(tmp));
960             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
961
962             if ((vec_count != 1) && (vec_count != 2))
963             {
964                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
965                      "deny-access directive in configuration file.");
966                string_append(&config->proxy_args,
967                   "<br>\nWARNING: Wrong number of parameters for "
968                   "deny-access directive in configuration file.<br><br>\n");
969                break;
970             }
971
972             /* allocate a new node */
973             cur_acl = zalloc_or_die(sizeof(*cur_acl));
974             cur_acl->action = ACL_DENY;
975
976             if (acl_addr(vec[0], cur_acl->src) < 0)
977             {
978                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
979                   "for deny-access directive in configuration file: \"%s\"", vec[0]);
980                string_append(&config->proxy_args,
981                   "<br>\nWARNING: Invalid source address, port or netmask "
982                   "for deny-access directive in configuration file: \"");
983                string_append(&config->proxy_args,
984                   vec[0]);
985                string_append(&config->proxy_args,
986                   "\"<br><br>\n");
987                freez(cur_acl);
988                break;
989             }
990             if (vec_count == 2)
991             {
992                if (acl_addr(vec[1], cur_acl->dst) < 0)
993                {
994                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
995                      "for deny-access directive in configuration file: \"%s\"", vec[1]);
996                   string_append(&config->proxy_args,
997                      "<br>\nWARNING: Invalid destination address, port or netmask "
998                      "for deny-access directive in configuration file: \"");
999                   string_append(&config->proxy_args,
1000                      vec[1]);
1001                   string_append(&config->proxy_args,
1002                      "\"<br><br>\n");
1003                   freez(cur_acl);
1004                   break;
1005                }
1006             }
1007 #ifdef HAVE_RFC2553
1008             else
1009             {
1010                cur_acl->wildcard_dst = 1;
1011             }
1012 #endif /* def HAVE_RFC2553 */
1013
1014             /*
1015              * Add it to the list.  Note we reverse the list to get the
1016              * behaviour the user expects.  With both the ACL and
1017              * actions file, the last match wins.  However, the internal
1018              * implementations are different:  The actions file is stored
1019              * in the same order as the file, and scanned completely.
1020              * With the ACL, we reverse the order as we load it, then
1021              * when we scan it we stop as soon as we get a match.
1022              */
1023             cur_acl->next  = config->acl;
1024             config->acl = cur_acl;
1025
1026             break;
1027 #endif /* def FEATURE_ACL */
1028
1029 #if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
1030 /* *************************************************************************
1031  * enable-accept-filter 0|1
1032  * *************************************************************************/
1033          case hash_enable_accept_filter :
1034             config->enable_accept_filter = parse_toggle_state(cmd, arg);
1035             break;
1036 #endif /* defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER) */
1037
1038 /* *************************************************************************
1039  * enable-edit-actions 0|1
1040  * *************************************************************************/
1041 #ifdef FEATURE_CGI_EDIT_ACTIONS
1042          case hash_enable_edit_actions:
1043             if (parse_toggle_state(cmd, arg) == 1)
1044             {
1045                config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1046             }
1047             else
1048             {
1049                config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1050             }
1051             break;
1052 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1053
1054 /* *************************************************************************
1055  * enable-compression 0|1
1056  * *************************************************************************/
1057 #ifdef FEATURE_COMPRESSION
1058          case hash_enable_compression:
1059             if (parse_toggle_state(cmd, arg) == 1)
1060             {
1061                config->feature_flags |= RUNTIME_FEATURE_COMPRESSION;
1062             }
1063             else
1064             {
1065                config->feature_flags &= ~RUNTIME_FEATURE_COMPRESSION;
1066             }
1067             break;
1068 #endif /* def FEATURE_COMPRESSION */
1069
1070 /* *************************************************************************
1071  * enable-proxy-authentication-forwarding 0|1
1072  * *************************************************************************/
1073          case hash_enable_proxy_authentication_forwarding:
1074             if (parse_toggle_state(cmd, arg) == 1)
1075             {
1076                config->feature_flags |= RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1077             }
1078             else
1079             {
1080                config->feature_flags &= ~RUNTIME_FEATURE_FORWARD_PROXY_AUTHENTICATION_HEADERS;
1081             }
1082             break;
1083
1084 /* *************************************************************************
1085  * enable-remote-toggle 0|1
1086  * *************************************************************************/
1087 #ifdef FEATURE_TOGGLE
1088          case hash_enable_remote_toggle:
1089             if (parse_toggle_state(cmd, arg) == 1)
1090             {
1091                config->feature_flags |= RUNTIME_FEATURE_CGI_TOGGLE;
1092             }
1093             else
1094             {
1095                config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE;
1096             }
1097             break;
1098 #endif /* def FEATURE_TOGGLE */
1099
1100 /* *************************************************************************
1101  * enable-remote-http-toggle 0|1
1102  * *************************************************************************/
1103          case hash_enable_remote_http_toggle:
1104             if (parse_toggle_state(cmd, arg) == 1)
1105             {
1106                config->feature_flags |= RUNTIME_FEATURE_HTTP_TOGGLE;
1107             }
1108             else
1109             {
1110                config->feature_flags &= ~RUNTIME_FEATURE_HTTP_TOGGLE;
1111             }
1112             break;
1113
1114 /* *************************************************************************
1115  * enforce-blocks 0|1
1116  * *************************************************************************/
1117          case hash_enforce_blocks:
1118 #ifdef FEATURE_FORCE_LOAD
1119             if (parse_toggle_state(cmd, arg) == 1)
1120             {
1121                config->feature_flags |= RUNTIME_FEATURE_ENFORCE_BLOCKS;
1122             }
1123             else
1124             {
1125                config->feature_flags &= ~RUNTIME_FEATURE_ENFORCE_BLOCKS;
1126             }
1127 #else
1128             log_error(LOG_LEVEL_ERROR, "Ignoring directive 'enforce-blocks'. "
1129                "FEATURE_FORCE_LOAD is disabled, blocks will always be enforced.");
1130 #endif /* def FEATURE_FORCE_LOAD */
1131             break;
1132
1133 /* *************************************************************************
1134  * filterfile file-name
1135  * In confdir by default.
1136  * *************************************************************************/
1137          case hash_filterfile :
1138             i = 0;
1139             while ((i < MAX_AF_FILES) && (NULL != config->re_filterfile[i]))
1140             {
1141                i++;
1142             }
1143
1144             if (i >= MAX_AF_FILES)
1145             {
1146                log_error(LOG_LEVEL_FATAL, "Too many 'filterfile' directives in config file - limit is %d.\n"
1147                   "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
1148                   MAX_AF_FILES);
1149             }
1150             config->re_filterfile_short[i] = strdup_or_die(arg);
1151             config->re_filterfile[i] = make_path(config->confdir, arg);
1152
1153             break;
1154
1155 /* *************************************************************************
1156  * forward url-pattern (.|http-proxy-host[:port])
1157  * *************************************************************************/
1158          case hash_forward:
1159             strlcpy(tmp, arg, sizeof(tmp));
1160             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1161
1162             if (vec_count != 2)
1163             {
1164                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward "
1165                      "directive in configuration file.");
1166                string_append(&config->proxy_args,
1167                   "<br>\nWARNING: Wrong number of parameters for "
1168                   "forward directive in configuration file.");
1169                break;
1170             }
1171
1172             /* allocate a new node */
1173             cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1174             cur_fwd->type = SOCKS_NONE;
1175
1176             /* Save the URL pattern */
1177             if (create_pattern_spec(cur_fwd->url, vec[0]))
1178             {
1179                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1180                      "directive in configuration file.");
1181                string_append(&config->proxy_args,
1182                   "<br>\nWARNING: Bad URL specifier for "
1183                   "forward directive in configuration file.");
1184                freez(cur_fwd);
1185                break;
1186             }
1187
1188             /* Parse the parent HTTP proxy host:port */
1189             p = vec[1];
1190
1191             if (strcmp(p, ".") != 0)
1192             {
1193                cur_fwd->forward_port = 8000;
1194                parse_forwarder_address(p,
1195                   &cur_fwd->forward_host, &cur_fwd->forward_port,
1196                   NULL, NULL);
1197             }
1198
1199             /* Add to list. */
1200             cur_fwd->next = config->forward;
1201             config->forward = cur_fwd;
1202
1203             break;
1204
1205 /* *************************************************************************
1206  * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1207  * *************************************************************************/
1208          case hash_forward_socks4:
1209             strlcpy(tmp, arg, sizeof(tmp));
1210             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1211
1212             if (vec_count != 3)
1213             {
1214                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1215                      "forward-socks4 directive in configuration file.");
1216                string_append(&config->proxy_args,
1217                   "<br>\nWARNING: Wrong number of parameters for "
1218                   "forward-socks4 directive in configuration file.");
1219                break;
1220             }
1221
1222             /* allocate a new node */
1223             cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1224             cur_fwd->type = SOCKS_4;
1225
1226             /* Save the URL pattern */
1227             if (create_pattern_spec(cur_fwd->url, vec[0]))
1228             {
1229                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1230                      "directive in configuration file.");
1231                string_append(&config->proxy_args,
1232                   "<br>\nWARNING: Bad URL specifier for "
1233                   "forward-socks4 directive in configuration file.");
1234                freez(cur_fwd);
1235                break;
1236             }
1237
1238             /* Parse the SOCKS proxy host[:port] */
1239             p = vec[1];
1240
1241             /* XXX: This check looks like a bug. */
1242             if (strcmp(p, ".") != 0)
1243             {
1244                cur_fwd->gateway_port = 1080;
1245                parse_forwarder_address(p,
1246                   &cur_fwd->gateway_host, &cur_fwd->gateway_port,
1247                   NULL, NULL);
1248             }
1249
1250             /* Parse the parent HTTP proxy host[:port] */
1251             p = vec[2];
1252
1253             if (strcmp(p, ".") != 0)
1254             {
1255                cur_fwd->forward_port = 8000;
1256                parse_forwarder_address(p,
1257                   &cur_fwd->forward_host, &cur_fwd->forward_port,
1258                   NULL, NULL);
1259             }
1260
1261             /* Add to list. */
1262             cur_fwd->next = config->forward;
1263             config->forward = cur_fwd;
1264
1265             break;
1266
1267 /* *************************************************************************
1268  * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1269  * *************************************************************************/
1270          case hash_forward_socks4a:
1271          case hash_forward_socks5:
1272          case hash_forward_socks5t:
1273             strlcpy(tmp, arg, sizeof(tmp));
1274             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1275
1276             if (vec_count != 3)
1277             {
1278                log_error(LOG_LEVEL_ERROR,
1279                   "Wrong number of parameters for %s in configuration file.",
1280                   cmd);
1281                string_append(&config->proxy_args,
1282                   "<br>\nWARNING: Wrong number of parameters for ");
1283                string_append(&config->proxy_args, cmd);
1284                string_append(&config->proxy_args,
1285                   "directive in configuration file.");
1286                break;
1287             }
1288
1289             /* allocate a new node */
1290             cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1291
1292             if (directive_hash == hash_forward_socks4a)
1293             {
1294                cur_fwd->type = SOCKS_4A;
1295             }
1296             else if (directive_hash == hash_forward_socks5)
1297             {
1298                cur_fwd->type = SOCKS_5;
1299             }
1300             else
1301             {
1302                assert(directive_hash == hash_forward_socks5t);
1303                cur_fwd->type = SOCKS_5T;
1304             }
1305
1306             /* Save the URL pattern */
1307             if (create_pattern_spec(cur_fwd->url, vec[0]))
1308             {
1309                log_error(LOG_LEVEL_ERROR,
1310                   "Bad URL specifier for %s in configuration file.",
1311                   cmd);
1312                string_append(&config->proxy_args,
1313                   "<br>\nWARNING: Bad URL specifier for ");
1314                string_append(&config->proxy_args, cmd);
1315                string_append(&config->proxy_args,
1316                   "directive in configuration file.");
1317                freez(cur_fwd);
1318                break;
1319             }
1320
1321             /* Parse the SOCKS proxy [user:pass@]host[:port] */
1322             p = vec[1];
1323
1324             cur_fwd->gateway_port = 1080;
1325             parse_forwarder_address(p,
1326                &cur_fwd->gateway_host, &cur_fwd->gateway_port,
1327                &cur_fwd->auth_username, &cur_fwd->auth_password);
1328
1329             /* Parse the parent HTTP proxy host[:port] */
1330             p = vec[2];
1331
1332             if (strcmp(p, ".") != 0)
1333             {
1334                cur_fwd->forward_port = 8000;
1335                parse_forwarder_address(p,
1336                   &cur_fwd->forward_host, &cur_fwd->forward_port,
1337                   NULL, NULL);
1338             }
1339
1340             /* Add to list. */
1341             cur_fwd->next = config->forward;
1342             config->forward = cur_fwd;
1343
1344             break;
1345
1346 /* *************************************************************************
1347  * forwarded-connect-retries n
1348  * *************************************************************************/
1349          case hash_forwarded_connect_retries :
1350             config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1351             break;
1352
1353 /* *************************************************************************
1354  * handle-as-empty-doc-returns-ok 0|1
1355  *
1356  * Workaround for firefox hanging on blocked javascript pages.
1357  *   Block with the "+handle-as-empty-document" flag and set the
1358  *   "handle-as-empty-doc-returns-ok" run-time config flag so that
1359  *   Privoxy returns a 200/OK status instead of a 403/Forbidden status
1360  *   to the browser for blocked pages.
1361  ***************************************************************************/
1362          case hash_handle_as_empty_returns_ok:
1363             if (parse_toggle_state(cmd, arg) == 1)
1364             {
1365                config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1366             }
1367             else
1368             {
1369                config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1370             }
1371             break;
1372
1373 /* *************************************************************************
1374  * hostname hostname-to-show-on-cgi-pages
1375  * *************************************************************************/
1376          case hash_hostname :
1377             freez(config->hostname);
1378             config->hostname = strdup_or_die(arg);
1379             break;
1380
1381 /* *************************************************************************
1382  * keep-alive-timeout timeout
1383  * *************************************************************************/
1384 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1385          case hash_keep_alive_timeout :
1386          {
1387             int timeout = parse_numeric_value(cmd, arg);
1388             if (0 < timeout)
1389             {
1390                config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1391                config->keep_alive_timeout = (unsigned int)timeout;
1392             }
1393             else
1394             {
1395                config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1396             }
1397             break;
1398          }
1399 #endif
1400
1401 /* *************************************************************************
1402  * listen-address [ip][:port]
1403  * *************************************************************************/
1404          case hash_listen_address :
1405             i = 0;
1406             while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1407             {
1408                i++;
1409             }
1410
1411             if (i >= MAX_LISTENING_SOCKETS)
1412             {
1413                log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1414                   "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1415                   MAX_LISTENING_SOCKETS);
1416             }
1417             config->haddr[i] = strdup_or_die(arg);
1418             break;
1419
1420 /* *************************************************************************
1421  * listen-backlog n
1422  * *************************************************************************/
1423          case hash_listen_backlog :
1424             /*
1425              * We don't enfore an upper or lower limit because on
1426              * many platforms all values are valid and negative
1427              * number mean "use the highest value allowed".
1428              */
1429             config->listen_backlog = parse_numeric_value(cmd, arg);
1430             break;
1431
1432 /* *************************************************************************
1433  * logdir directory-name
1434  * *************************************************************************/
1435          case hash_logdir :
1436             freez(config->logdir);
1437             config->logdir = make_path(NULL, arg);
1438             break;
1439
1440 /* *************************************************************************
1441  * logfile log-file-name
1442  * In logdir by default
1443  * *************************************************************************/
1444          case hash_logfile :
1445             if (daemon_mode)
1446             {
1447                logfile = make_path(config->logdir, arg);
1448                if (NULL == logfile)
1449                {
1450                   log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1451                }
1452             }
1453             break;
1454
1455 /* *************************************************************************
1456  * max-client-connections number
1457  * *************************************************************************/
1458          case hash_max_client_connections :
1459          {
1460             int max_client_connections = parse_numeric_value(cmd, arg);
1461
1462 #if !defined(_WIN32) && !defined(HAVE_POLL)
1463             /*
1464              * Reject values below 1 for obvious reasons and values above
1465              * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1466              * client connections that need forwarding.
1467              *
1468              * We ignore the fact that the first three file descriptors
1469              * are usually set to /dev/null, one is used for logging
1470              * and yet another file descriptor is required to load
1471              * config files.
1472              */
1473             if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1474             {
1475                log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1476                   " is invalid. Value needs to be above 1 and below %d"
1477                   " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1478             }
1479 #else
1480             /*
1481              * The Windows libc uses FD_SETSIZE for an array used
1482              * by select(), but has no problems with file descriptors
1483              * above the limit as long as no more than FD_SETSIZE are
1484              * passed to select().
1485              * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1486              *
1487              * On platforms were we use poll() we don't have to enforce
1488              * an upper connection limit either.
1489              */
1490             if (max_client_connections < 1)
1491             {
1492                log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1493                   " has to be a number above 1. %d is invalid.",
1494                   max_client_connections);
1495             }
1496 #endif
1497             config->max_client_connections = max_client_connections;
1498             break;
1499          }
1500
1501 /* *************************************************************************
1502  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1503  * *************************************************************************/
1504 #ifdef FEATURE_ACL
1505          case hash_permit_access:
1506             strlcpy(tmp, arg, sizeof(tmp));
1507             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1508
1509             if ((vec_count != 1) && (vec_count != 2))
1510             {
1511                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1512                      "permit-access directive in configuration file.");
1513                string_append(&config->proxy_args,
1514                   "<br>\nWARNING: Wrong number of parameters for "
1515                   "permit-access directive in configuration file.<br><br>\n");
1516
1517                break;
1518             }
1519
1520             /* allocate a new node */
1521             cur_acl = zalloc_or_die(sizeof(*cur_acl));
1522             cur_acl->action = ACL_PERMIT;
1523
1524             if (acl_addr(vec[0], cur_acl->src) < 0)
1525             {
1526                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1527                   "for permit-access directive in configuration file: \"%s\"", vec[0]);
1528                string_append(&config->proxy_args,
1529                   "<br>\nWARNING: Invalid source address, port or netmask for "
1530                   "permit-access directive in configuration file: \"");
1531                string_append(&config->proxy_args,
1532                   vec[0]);
1533                string_append(&config->proxy_args,
1534                   "\"<br><br>\n");
1535                freez(cur_acl);
1536                break;
1537             }
1538             if (vec_count == 2)
1539             {
1540                if (acl_addr(vec[1], cur_acl->dst) < 0)
1541                {
1542                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1543                      "for permit-access directive in configuration file: \"%s\"", vec[1]);
1544                   string_append(&config->proxy_args,
1545                      "<br>\nWARNING: Invalid destination address, port or netmask for "
1546                      "permit-access directive in configuration file: \"");
1547                   string_append(&config->proxy_args,
1548                      vec[1]);
1549                   string_append(&config->proxy_args,
1550                      "\"<br><br>\n");
1551                   freez(cur_acl);
1552                   break;
1553                }
1554             }
1555 #ifdef HAVE_RFC2553
1556             else
1557             {
1558                cur_acl->wildcard_dst = 1;
1559             }
1560 #endif /* def HAVE_RFC2553 */
1561
1562             /*
1563              * Add it to the list.  Note we reverse the list to get the
1564              * behaviour the user expects.  With both the ACL and
1565              * actions file, the last match wins.  However, the internal
1566              * implementations are different:  The actions file is stored
1567              * in the same order as the file, and scanned completely.
1568              * With the ACL, we reverse the order as we load it, then
1569              * when we scan it we stop as soon as we get a match.
1570              */
1571             cur_acl->next  = config->acl;
1572             config->acl = cur_acl;
1573
1574             break;
1575 #endif /* def FEATURE_ACL */
1576
1577 /* *************************************************************************
1578  * proxy-info-url url
1579  * *************************************************************************/
1580          case hash_proxy_info_url :
1581             freez(config->proxy_info_url);
1582             config->proxy_info_url = strdup_or_die(arg);
1583             break;
1584
1585
1586 /* *************************************************************************
1587  * receive-buffer-size n
1588  * *************************************************************************/
1589          case hash_receive_buffer_size :
1590             config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1591             if (config->receive_buffer_size < BUFFER_SIZE)
1592             {
1593                log_error(LOG_LEVEL_INFO,
1594                   "receive-buffer-size %d seems low and may cause problems."
1595                   "Consider setting it to at least %d.",
1596                   config->receive_buffer_size, BUFFER_SIZE);
1597             }
1598             break;
1599
1600 /* *************************************************************************
1601  * single-threaded 0|1
1602  * *************************************************************************/
1603          case hash_single_threaded :
1604             config->multi_threaded =  0 == parse_toggle_state(cmd, arg);
1605             break;
1606
1607 /* *************************************************************************
1608  * socket-timeout numer_of_seconds
1609  * *************************************************************************/
1610          case hash_socket_timeout :
1611          {
1612             int socket_timeout = parse_numeric_value(cmd, arg);
1613             if (0 <= socket_timeout)
1614             {
1615                config->socket_timeout = socket_timeout;
1616             }
1617             else
1618             {
1619                log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1620             }
1621             break;
1622          }
1623
1624 /* *************************************************************************
1625  * split-large-cgi-forms
1626  * *************************************************************************/
1627          case hash_split_large_cgi_forms :
1628             if (parse_toggle_state(cmd, arg) == 1)
1629             {
1630                config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1631             }
1632             else
1633             {
1634                config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1635             }
1636             break;
1637
1638 /* *************************************************************************
1639  * templdir directory-name
1640  * *************************************************************************/
1641          case hash_templdir :
1642             freez(config->templdir);
1643             config->templdir = make_path(NULL, arg);
1644             break;
1645
1646 #ifdef FEATURE_EXTERNAL_FILTERS
1647 /* *************************************************************************
1648  * temporary-directory directory-name
1649  * *************************************************************************/
1650          case hash_temporary_directory :
1651             freez(config->temporary_directory);
1652             config->temporary_directory = make_path(NULL, arg);
1653             break;
1654 #endif
1655
1656 /* *************************************************************************
1657  * tolerate-pipelining (0|1)
1658  * *************************************************************************/
1659          case hash_tolerate_pipelining :
1660             if (parse_toggle_state(cmd, arg) == 1)
1661             {
1662                config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1663             }
1664             else
1665             {
1666                config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1667             }
1668             break;
1669
1670 /* *************************************************************************
1671  * toggle (0|1)
1672  * *************************************************************************/
1673 #ifdef FEATURE_TOGGLE
1674          case hash_toggle :
1675             global_toggle_state = parse_toggle_state(cmd, arg);
1676             break;
1677 #endif /* def FEATURE_TOGGLE */
1678
1679 /* *************************************************************************
1680  * trust-info-url url
1681  * *************************************************************************/
1682 #ifdef FEATURE_TRUST
1683          case hash_trust_info_url :
1684             enlist(config->trust_info, arg);
1685             break;
1686 #endif /* def FEATURE_TRUST */
1687
1688 /* *************************************************************************
1689  * trust-x-forwarded-for (0|1)
1690  * *************************************************************************/
1691          case hash_trust_x_forwarded_for :
1692             config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1693             break;
1694
1695 /* *************************************************************************
1696  * trusted-cgi-referrer http://www.example.org/some/path.html
1697  * *************************************************************************/
1698          case hash_trusted_cgi_referrer :
1699             /*
1700              * We don't validate the specified referrer as
1701              * it's only used for string comparison.
1702              */
1703             freez(config->trusted_cgi_referrer);
1704             config->trusted_cgi_referrer = strdup_or_die(arg);
1705             break;
1706
1707 /* *************************************************************************
1708  * trustfile filename
1709  * (In confdir by default.)
1710  * *************************************************************************/
1711 #ifdef FEATURE_TRUST
1712          case hash_trustfile :
1713             freez(config->trustfile);
1714             config->trustfile = make_path(config->confdir, arg);
1715             break;
1716 #endif /* def FEATURE_TRUST */
1717
1718 /* *************************************************************************
1719  * usermanual url
1720  * *************************************************************************/
1721          case hash_usermanual :
1722             /*
1723              * XXX: If this isn't the first config directive, the
1724              * show-status page links to the website documentation
1725              * for the directives that were already parsed. Lame.
1726              */
1727             freez(config->usermanual);
1728             config->usermanual = strdup_or_die(arg);
1729             break;
1730
1731 #ifdef FEATURE_HTTPS_INSPECTION
1732 /* *************************************************************************
1733  * ca private key file password
1734  * *************************************************************************/
1735          case hash_ca_password:
1736             freez(config->ca_password);
1737             config->ca_password = strdup(arg);
1738             break;
1739
1740 /* *************************************************************************
1741  * ca-directory directory
1742  * *************************************************************************/
1743          case hash_ca_directory:
1744             freez(ca_directory);
1745             ca_directory = make_path(NULL, arg);
1746
1747             if (NULL == ca_directory)
1748             {
1749                log_error(LOG_LEVEL_FATAL, "Out of memory while creating ca dir path");
1750             }
1751
1752             break;
1753
1754 /* *************************************************************************
1755  * ca cert file ca-cert-file
1756  * In ca dir by default
1757  * *************************************************************************/
1758          case hash_ca_cert_file:
1759             freez(ca_cert_file);
1760             ca_cert_file = make_path(config->ca_directory, arg);
1761
1762             if (NULL == ca_cert_file)
1763             {
1764                log_error(LOG_LEVEL_FATAL, "Out of memory while creating ca certificate file path");
1765             }
1766
1767             break;
1768
1769 /* *************************************************************************
1770  * ca key file ca-key-file
1771  * In ca dir by default
1772  * *************************************************************************/
1773          case hash_ca_key_file:
1774             freez(ca_key_file);
1775             ca_key_file = make_path(config->ca_directory, arg);
1776
1777             if (NULL == ca_key_file)
1778             {
1779                log_error(LOG_LEVEL_FATAL, "Out of memory while creating ca key file path");
1780             }
1781
1782             break;
1783
1784 /* *************************************************************************
1785  * certificate-directory directory
1786  * *************************************************************************/
1787          case hash_certificate_directory:
1788             freez(certificate_directory);
1789             certificate_directory = make_path(NULL, arg);
1790
1791             if (NULL == certificate_directory)
1792             {
1793                log_error(LOG_LEVEL_FATAL,
1794                   "Out of memory while creating certificate directory path");
1795             }
1796
1797             break;
1798
1799 /* *************************************************************************
1800  * trusted CAs file name trusted-cas-file
1801  * *************************************************************************/
1802          case hash_trusted_cas_file:
1803             freez(trusted_cas_file);
1804             trusted_cas_file = make_path(config->ca_directory, arg);
1805
1806             if (NULL == trusted_cas_file)
1807             {
1808                log_error(LOG_LEVEL_FATAL, "Out of memory while creating trusted CAs file path");
1809             }
1810
1811             break;
1812 #endif
1813
1814 /* *************************************************************************
1815  * Win32 Console options:
1816  * *************************************************************************/
1817
1818 /* *************************************************************************
1819  * hide-console
1820  * *************************************************************************/
1821 #ifdef _WIN_CONSOLE
1822          case hash_hide_console :
1823             hideConsole = 1;
1824             break;
1825 #endif /*def _WIN_CONSOLE*/
1826
1827
1828 /* *************************************************************************
1829  * Win32 GUI options:
1830  * *************************************************************************/
1831
1832 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1833 /* *************************************************************************
1834  * activity-animation (0|1)
1835  * *************************************************************************/
1836          case hash_activity_animation :
1837             g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1838             break;
1839
1840 /* *************************************************************************
1841  *  close-button-minimizes (0|1)
1842  * *************************************************************************/
1843          case hash_close_button_minimizes :
1844             g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1845             break;
1846
1847 /* *************************************************************************
1848  * log-buffer-size (0|1)
1849  * *************************************************************************/
1850          case hash_log_buffer_size :
1851             g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1852             break;
1853
1854 /* *************************************************************************
1855  * log-font-name fontname
1856  * *************************************************************************/
1857          case hash_log_font_name :
1858             if (strlcpy(g_szFontFaceName, arg,
1859                    sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1860             {
1861                log_error(LOG_LEVEL_FATAL,
1862                   "log-font-name argument '%s' is longer than %u characters.",
1863                   arg, sizeof(g_szFontFaceName)-1);
1864             }
1865             break;
1866
1867 /* *************************************************************************
1868  * log-font-size n
1869  * *************************************************************************/
1870          case hash_log_font_size :
1871             g_nFontSize = parse_numeric_value(cmd, arg);
1872             break;
1873
1874 /* *************************************************************************
1875  * log-highlight-messages (0|1)
1876  * *************************************************************************/
1877          case hash_log_highlight_messages :
1878             g_bHighlightMessages = parse_toggle_state(cmd, arg);
1879             break;
1880
1881 /* *************************************************************************
1882  * log-max-lines n
1883  * *************************************************************************/
1884          case hash_log_max_lines :
1885             g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1886             break;
1887
1888 /* *************************************************************************
1889  * log-messages (0|1)
1890  * *************************************************************************/
1891          case hash_log_messages :
1892             g_bLogMessages = parse_toggle_state(cmd, arg);
1893             break;
1894
1895 /* *************************************************************************
1896  * show-on-task-bar (0|1)
1897  * *************************************************************************/
1898          case hash_show_on_task_bar :
1899             g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1900             break;
1901
1902 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1903
1904
1905 /* *************************************************************************
1906  * Warnings about unsupported features
1907  * *************************************************************************/
1908 #ifndef FEATURE_ACL
1909          case hash_deny_access:
1910 #endif /* ndef FEATURE_ACL */
1911 #ifndef FEATURE_CGI_EDIT_ACTIONS
1912          case hash_enable_edit_actions:
1913 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1914 #ifndef FEATURE_TOGGLE
1915          case hash_enable_remote_toggle:
1916 #endif /* ndef FEATURE_TOGGLE */
1917 #ifndef FEATURE_ACL
1918          case hash_permit_access:
1919 #endif /* ndef FEATURE_ACL */
1920 #ifndef FEATURE_TOGGLE
1921          case hash_toggle :
1922 #endif /* ndef FEATURE_TOGGLE */
1923 #ifndef FEATURE_TRUST
1924          case hash_trustfile :
1925          case hash_trust_info_url :
1926 #endif /* ndef FEATURE_TRUST */
1927
1928 #ifndef _WIN_CONSOLE
1929          case hash_hide_console :
1930 #endif /* ndef _WIN_CONSOLE */
1931
1932 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1933          case hash_activity_animation :
1934          case hash_close_button_minimizes :
1935          case hash_log_buffer_size :
1936          case hash_log_font_name :
1937          case hash_log_font_size :
1938          case hash_log_highlight_messages :
1939          case hash_log_max_lines :
1940          case hash_log_messages :
1941          case hash_show_on_task_bar :
1942 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1943             /* These warnings are annoying - so hide them. -- Jon */
1944             /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1945             break;
1946
1947 /* *************************************************************************/
1948          default :
1949 /* *************************************************************************/
1950             /*
1951              * I decided that I liked this better as a warning than an
1952              * error.  To change back to an error, just change log level
1953              * to LOG_LEVEL_FATAL.
1954              */
1955             log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1956                "'%s' (%uU) in line %lu in configuration file (%s).",
1957                buf, directive_hash, linenum, configfile);
1958             string_append(&config->proxy_args,
1959                " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1960             break;
1961
1962 /* *************************************************************************/
1963       } /* end switch(hash_string(cmd)) */
1964
1965       /* Save the argument for the show-status page. */
1966       savearg(cmd, arg, config);
1967       freez(buf);
1968    } /* end while (read_config_line(...)) */
1969
1970    fclose(configfp);
1971
1972    set_debug_level(config->debug);
1973
1974    freez(config->logfile);
1975
1976    if (daemon_mode)
1977    {
1978       if (NULL != logfile)
1979       {
1980          config->logfile = logfile;
1981          init_error_log(Argv[0], config->logfile);
1982       }
1983       else
1984       {
1985          disable_logging();
1986       }
1987    }
1988
1989 #ifdef FEATURE_HTTPS_INSPECTION
1990    /*
1991     * Setting SSL parameters from loaded values into structures
1992     */
1993    freez(config->ca_directory);
1994    config->ca_directory = make_path(NULL, ca_directory);
1995    freez(ca_directory);
1996
1997    freez(config->ca_cert_file);
1998    config->ca_cert_file = make_path(config->ca_directory, ca_cert_file);
1999    freez(ca_cert_file);
2000
2001    freez(config->ca_key_file);
2002    config->ca_key_file  = make_path(config->ca_directory, ca_key_file);
2003    freez(ca_key_file);
2004
2005    freez(config->trusted_cas_file);
2006    config->trusted_cas_file = make_path(config->ca_directory, trusted_cas_file);
2007    freez(trusted_cas_file);
2008
2009    freez(config->certificate_directory);
2010    config->certificate_directory = make_path(NULL, certificate_directory);
2011    freez(certificate_directory);
2012 #endif
2013 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
2014    if (config->default_server_timeout > config->keep_alive_timeout)
2015    {
2016       log_error(LOG_LEVEL_ERROR,
2017          "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
2018          config->default_server_timeout, config->keep_alive_timeout);
2019       config->default_server_timeout = config->keep_alive_timeout;
2020    }
2021 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
2022
2023 #ifdef FEATURE_CONNECTION_SHARING
2024    if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
2025    {
2026       if (!config->multi_threaded)
2027       {
2028          /*
2029           * While we could use keep-alive without multiple threads
2030           * if we didn't bother with enforcing the connection timeout,
2031           * that might make Tor users sad, even though they shouldn't
2032           * enable the single-threaded option anyway.
2033           *
2034           * XXX: We could still use Proxy-Connection: keep-alive.
2035           */
2036          config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
2037          log_error(LOG_LEVEL_ERROR,
2038             "Config option single-threaded disables connection keep-alive.");
2039       }
2040    }
2041    else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
2042    {
2043       log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
2044          "has no effect if keep-alive-timeout isn't set.");
2045       config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
2046    }
2047 #endif /* def FEATURE_CONNECTION_SHARING */
2048
2049    if (NULL == config->proxy_args)
2050    {
2051       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
2052    }
2053
2054    if (config->re_filterfile[0])
2055    {
2056       add_loader(load_re_filterfiles, config);
2057    }
2058
2059    if (config->actions_file[0])
2060    {
2061       add_loader(load_action_files, config);
2062    }
2063
2064 #ifdef FEATURE_TRUST
2065    if (config->trustfile)
2066    {
2067       add_loader(load_trustfile, config);
2068    }
2069 #endif /* def FEATURE_TRUST */
2070
2071    if (NULL == config->haddr[0])
2072    {
2073       config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
2074    }
2075
2076    for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
2077    {
2078       if ((*config->haddr[i] == '[')
2079          && (NULL != (p = strchr(config->haddr[i], ']')))
2080          && (p[1] == ':')
2081          && (0 < (config->hport[i] = atoi(p + 2))))
2082       {
2083          *p = '\0';
2084          memmove((void *)config->haddr[i], config->haddr[i] + 1,
2085             (size_t)(p - config->haddr[i]));
2086       }
2087       else if (NULL != (p = strchr(config->haddr[i], ':'))
2088          && (0 < (config->hport[i] = atoi(p + 1))))
2089       {
2090          *p = '\0';
2091       }
2092       else
2093       {
2094          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
2095          /* Never get here - LOG_LEVEL_FATAL causes program exit */
2096       }
2097       if (*config->haddr[i] == '\0')
2098       {
2099          /*
2100           * Only the port specified. We stored it in config->hport[i]
2101           * and don't need its text representation anymore.
2102           * Use config->hport[i] == 0 to iterate listening addresses since
2103           * now.
2104           */
2105          freez(config->haddr[i]);
2106       }
2107    }
2108
2109    /*
2110     * Want to run all the loaders once now.
2111     *
2112     * Need to set up a fake csp, so they can get to the config.
2113     */
2114    fake_csp = zalloc_or_die(sizeof(*fake_csp));
2115    fake_csp->config = config;
2116
2117    if (run_loader(fake_csp))
2118    {
2119       freez(fake_csp);
2120       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
2121       /* Never get here - LOG_LEVEL_FATAL causes program exit */
2122    }
2123    freez(fake_csp);
2124
2125 /* FIXME: this is a kludge for win32 */
2126 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
2127
2128    g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
2129    g_user_actions_file  = config->actions_file[2];  /* FIXME Hope this is user.action */
2130    g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
2131    g_user_filterfile    = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
2132
2133 #ifdef FEATURE_TRUST
2134    g_trustfile        = config->trustfile;
2135 #endif /* def FEATURE_TRUST */
2136
2137
2138 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
2139 /* FIXME: end kludge */
2140
2141
2142    if (current_configfile == NULL)
2143    {
2144       config->need_bind = 1;
2145    }
2146    else
2147    {
2148       struct configuration_spec * oldcfg = (struct configuration_spec *)
2149                                            current_configfile->f;
2150       /*
2151        * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
2152        */
2153       config->need_bind = 0;
2154
2155       for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
2156       {
2157          if (config->hport[i] != oldcfg->hport[i])
2158          {
2159             config->need_bind = 1;
2160          }
2161          else if (config->haddr[i] == NULL)
2162          {
2163             if (oldcfg->haddr[i] != NULL)
2164             {
2165                config->need_bind = 1;
2166             }
2167          }
2168          else if (oldcfg->haddr[i] == NULL)
2169          {
2170             config->need_bind = 1;
2171          }
2172          else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2173          {
2174             config->need_bind = 1;
2175          }
2176       }
2177
2178       current_configfile->unloader = unload_configfile;
2179    }
2180
2181    fs->next = files->next;
2182    files->next = fs;
2183
2184    current_configfile = fs;
2185
2186    return (config);
2187 }
2188
2189
2190 /*********************************************************************
2191  *
2192  * Function    :  savearg
2193  *
2194  * Description :  Called from `load_config'.  It saves each non-empty
2195  *                and non-comment line from config into
2196  *                config->proxy_args.  This is used to create the
2197  *                show-status page.  On error, frees
2198  *                config->proxy_args and sets it to NULL
2199  *
2200  * Parameters  :
2201  *          1  :  command = config setting that was found
2202  *          2  :  argument = the setting's argument (if any)
2203  *          3  :  config = Configuration to save into.
2204  *
2205  * Returns     :  N/A
2206  *
2207  *********************************************************************/
2208 static void savearg(char *command, char *argument, struct configuration_spec * config)
2209 {
2210    char * buf;
2211    char * s;
2212
2213    assert(command);
2214    assert(argument);
2215
2216    /*
2217     * Add config option name embedded in
2218     * link to its section in the user-manual
2219     */
2220    buf = strdup_or_die("\n<a href=\"");
2221    if (!strncmpic(config->usermanual, "file://", 7) ||
2222        !strncmpic(config->usermanual, "http", 4))
2223    {
2224       string_append(&buf, config->usermanual);
2225    }
2226    else
2227    {
2228       string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2229    }
2230    string_append(&buf, CONFIG_HELP_PREFIX);
2231    string_join  (&buf, string_toupper(command));
2232    string_append(&buf, "\">");
2233    string_append(&buf, command);
2234    string_append(&buf, "</a> ");
2235
2236    if (NULL == buf)
2237    {
2238       freez(config->proxy_args);
2239       return;
2240    }
2241
2242    if ((NULL != argument) && ('\0' != *argument))
2243    {
2244       s = html_encode(argument);
2245       if (NULL == s)
2246       {
2247          freez(buf);
2248          freez(config->proxy_args);
2249          return;
2250       }
2251
2252       if (strncmpic(argument, "http://", 7) == 0)
2253       {
2254          string_append(&buf, "<a href=\"");
2255          string_append(&buf, s);
2256          string_append(&buf, "\">");
2257          string_join  (&buf, s);
2258          string_append(&buf, "</a>");
2259       }
2260       else
2261       {
2262          string_join  (&buf, s);
2263       }
2264    }
2265
2266    string_append(&buf, "<br>");
2267    string_join(&config->proxy_args, buf);
2268 }
2269
2270
2271 /*
2272   Local Variables:
2273   tab-width: 3
2274   end:
2275 */