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