Fix most recent release which is still 3.0.28
[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,
1167                   &cur_fwd->forward_host, &cur_fwd->forward_port,
1168                   NULL, NULL);
1169             }
1170
1171             /* Add to list. */
1172             cur_fwd->next = config->forward;
1173             config->forward = cur_fwd;
1174
1175             break;
1176
1177 /* *************************************************************************
1178  * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1179  * *************************************************************************/
1180          case hash_forward_socks4:
1181             strlcpy(tmp, arg, sizeof(tmp));
1182             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1183
1184             if (vec_count != 3)
1185             {
1186                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1187                      "forward-socks4 directive in configuration file.");
1188                string_append(&config->proxy_args,
1189                   "<br>\nWARNING: Wrong number of parameters for "
1190                   "forward-socks4 directive in configuration file.");
1191                break;
1192             }
1193
1194             /* allocate a new node */
1195             cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1196             cur_fwd->type = SOCKS_4;
1197
1198             /* Save the URL pattern */
1199             if (create_pattern_spec(cur_fwd->url, vec[0]))
1200             {
1201                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1202                      "directive in configuration file.");
1203                string_append(&config->proxy_args,
1204                   "<br>\nWARNING: Bad URL specifier for "
1205                   "forward-socks4 directive in configuration file.");
1206                freez(cur_fwd);
1207                break;
1208             }
1209
1210             /* Parse the SOCKS proxy host[:port] */
1211             p = vec[1];
1212
1213             /* XXX: This check looks like a bug. */
1214             if (strcmp(p, ".") != 0)
1215             {
1216                cur_fwd->gateway_port = 1080;
1217                parse_forwarder_address(p,
1218                   &cur_fwd->gateway_host, &cur_fwd->gateway_port,
1219                   NULL, NULL);
1220             }
1221
1222             /* Parse the parent HTTP proxy host[:port] */
1223             p = vec[2];
1224
1225             if (strcmp(p, ".") != 0)
1226             {
1227                cur_fwd->forward_port = 8000;
1228                parse_forwarder_address(p,
1229                   &cur_fwd->forward_host, &cur_fwd->forward_port,
1230                   NULL, NULL);
1231             }
1232
1233             /* Add to list. */
1234             cur_fwd->next = config->forward;
1235             config->forward = cur_fwd;
1236
1237             break;
1238
1239 /* *************************************************************************
1240  * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1241  * *************************************************************************/
1242          case hash_forward_socks4a:
1243          case hash_forward_socks5:
1244          case hash_forward_socks5t:
1245             strlcpy(tmp, arg, sizeof(tmp));
1246             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1247
1248             if (vec_count != 3)
1249             {
1250                log_error(LOG_LEVEL_ERROR,
1251                   "Wrong number of parameters for %s in configuration file.",
1252                   cmd);
1253                string_append(&config->proxy_args,
1254                   "<br>\nWARNING: Wrong number of parameters for ");
1255                string_append(&config->proxy_args, cmd);
1256                string_append(&config->proxy_args,
1257                   "directive in configuration file.");
1258                break;
1259             }
1260
1261             /* allocate a new node */
1262             cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
1263
1264             if (directive_hash == hash_forward_socks4a)
1265             {
1266                cur_fwd->type = SOCKS_4A;
1267             }
1268             else if (directive_hash == hash_forward_socks5)
1269             {
1270                cur_fwd->type = SOCKS_5;
1271             }
1272             else
1273             {
1274                assert(directive_hash == hash_forward_socks5t);
1275                cur_fwd->type = SOCKS_5T;
1276             }
1277
1278             /* Save the URL pattern */
1279             if (create_pattern_spec(cur_fwd->url, vec[0]))
1280             {
1281                log_error(LOG_LEVEL_ERROR,
1282                   "Bad URL specifier for %s in configuration file.",
1283                   cmd);
1284                string_append(&config->proxy_args,
1285                   "<br>\nWARNING: Bad URL specifier for ");
1286                string_append(&config->proxy_args, cmd);
1287                string_append(&config->proxy_args,
1288                   "directive in configuration file.");
1289                freez(cur_fwd);
1290                break;
1291             }
1292
1293             /* Parse the SOCKS proxy [user:pass@]host[:port] */
1294             p = vec[1];
1295
1296             cur_fwd->gateway_port = 1080;
1297             parse_forwarder_address(p,
1298                &cur_fwd->gateway_host, &cur_fwd->gateway_port,
1299                &cur_fwd->auth_username, &cur_fwd->auth_password);
1300
1301             /* Parse the parent HTTP proxy host[:port] */
1302             p = vec[2];
1303
1304             if (strcmp(p, ".") != 0)
1305             {
1306                cur_fwd->forward_port = 8000;
1307                parse_forwarder_address(p,
1308                   &cur_fwd->forward_host, &cur_fwd->forward_port,
1309                   NULL, NULL);
1310             }
1311
1312             /* Add to list. */
1313             cur_fwd->next = config->forward;
1314             config->forward = cur_fwd;
1315
1316             break;
1317
1318 /* *************************************************************************
1319  * forwarded-connect-retries n
1320  * *************************************************************************/
1321          case hash_forwarded_connect_retries :
1322             config->forwarded_connect_retries = parse_numeric_value(cmd, arg);
1323             break;
1324
1325 /* *************************************************************************
1326  * handle-as-empty-doc-returns-ok 0|1
1327  *
1328  * Workaround for firefox hanging on blocked javascript pages.
1329  *   Block with the "+handle-as-empty-document" flag and set the
1330  *   "handle-as-empty-doc-returns-ok" run-time config flag so that
1331  *   Privoxy returns a 200/OK status instead of a 403/Forbidden status
1332  *   to the browser for blocked pages.
1333  ***************************************************************************/
1334          case hash_handle_as_empty_returns_ok:
1335             if (parse_toggle_state(cmd, arg) == 1)
1336             {
1337                config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1338             }
1339             else
1340             {
1341                config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK;
1342             }
1343             break;
1344
1345 /* *************************************************************************
1346  * hostname hostname-to-show-on-cgi-pages
1347  * *************************************************************************/
1348          case hash_hostname :
1349             freez(config->hostname);
1350             config->hostname = strdup_or_die(arg);
1351             break;
1352
1353 /* *************************************************************************
1354  * keep-alive-timeout timeout
1355  * *************************************************************************/
1356 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1357          case hash_keep_alive_timeout :
1358          {
1359             int timeout = parse_numeric_value(cmd, arg);
1360             if (0 < timeout)
1361             {
1362                config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1363                config->keep_alive_timeout = (unsigned int)timeout;
1364             }
1365             else
1366             {
1367                config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1368             }
1369             break;
1370          }
1371 #endif
1372
1373 /* *************************************************************************
1374  * listen-address [ip][:port]
1375  * *************************************************************************/
1376          case hash_listen_address :
1377             i = 0;
1378             while ((i < MAX_LISTENING_SOCKETS) && (NULL != config->haddr[i]))
1379             {
1380                i++;
1381             }
1382
1383             if (i >= MAX_LISTENING_SOCKETS)
1384             {
1385                log_error(LOG_LEVEL_FATAL, "Too many 'listen-address' directives in config file - limit is %d.\n"
1386                   "(You can increase this limit by changing MAX_LISTENING_SOCKETS in project.h and recompiling).",
1387                   MAX_LISTENING_SOCKETS);
1388             }
1389             config->haddr[i] = strdup_or_die(arg);
1390             break;
1391
1392 /* *************************************************************************
1393  * listen-backlog n
1394  * *************************************************************************/
1395          case hash_listen_backlog :
1396             /*
1397              * We don't enfore an upper or lower limit because on
1398              * many platforms all values are valid and negative
1399              * number mean "use the highest value allowed".
1400              */
1401             config->listen_backlog = parse_numeric_value(cmd, arg);
1402             break;
1403
1404 /* *************************************************************************
1405  * logdir directory-name
1406  * *************************************************************************/
1407          case hash_logdir :
1408             freez(config->logdir);
1409             config->logdir = make_path(NULL, arg);
1410             break;
1411
1412 /* *************************************************************************
1413  * logfile log-file-name
1414  * In logdir by default
1415  * *************************************************************************/
1416          case hash_logfile :
1417             if (daemon_mode)
1418             {
1419                logfile = make_path(config->logdir, arg);
1420                if (NULL == logfile)
1421                {
1422                   log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1423                }
1424             }
1425             break;
1426
1427 /* *************************************************************************
1428  * max-client-connections number
1429  * *************************************************************************/
1430          case hash_max_client_connections :
1431          {
1432             int max_client_connections = parse_numeric_value(cmd, arg);
1433
1434 #if !defined(_WIN32) && !defined(HAVE_POLL)
1435             /*
1436              * Reject values below 1 for obvious reasons and values above
1437              * FD_SETSIZE/2 because Privoxy needs two sockets to serve
1438              * client connections that need forwarding.
1439              *
1440              * We ignore the fact that the first three file descriptors
1441              * are usually set to /dev/null, one is used for logging
1442              * and yet another file descriptor is required to load
1443              * config files.
1444              */
1445             if ((max_client_connections < 1) || (FD_SETSIZE/2 < max_client_connections))
1446             {
1447                log_error(LOG_LEVEL_FATAL, "max-client-connections value %d"
1448                   " is invalid. Value needs to be above 1 and below %d"
1449                   " (FD_SETSIZE/2).", max_client_connections, FD_SETSIZE/2);
1450             }
1451 #else
1452             /*
1453              * The Windows libc uses FD_SETSIZE for an array used
1454              * by select(), but has no problems with file descriptors
1455              * above the limit as long as no more than FD_SETSIZE are
1456              * passed to select().
1457              * https://msdn.microsoft.com/en-us/library/windows/desktop/ms739169%28v=vs.85%29.aspx
1458              *
1459              * On platforms were we use poll() we don't have to enforce
1460              * an upper connection limit either.
1461              *
1462              * XXX: Do OS/2 etc. belong here as well?
1463              */
1464             if (max_client_connections < 1)
1465             {
1466                log_error(LOG_LEVEL_FATAL, "max-client-connections value"
1467                   " has to be a number above 1. %d is invalid.",
1468                   max_client_connections);
1469             }
1470 #endif
1471             config->max_client_connections = max_client_connections;
1472             break;
1473          }
1474
1475 /* *************************************************************************
1476  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1477  * *************************************************************************/
1478 #ifdef FEATURE_ACL
1479          case hash_permit_access:
1480             strlcpy(tmp, arg, sizeof(tmp));
1481             vec_count = ssplit(tmp, " \t", vec, SZ(vec));
1482
1483             if ((vec_count != 1) && (vec_count != 2))
1484             {
1485                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1486                      "permit-access directive in configuration file.");
1487                string_append(&config->proxy_args,
1488                   "<br>\nWARNING: Wrong number of parameters for "
1489                   "permit-access directive in configuration file.<br><br>\n");
1490
1491                break;
1492             }
1493
1494             /* allocate a new node */
1495             cur_acl = zalloc_or_die(sizeof(*cur_acl));
1496             cur_acl->action = ACL_PERMIT;
1497
1498             if (acl_addr(vec[0], cur_acl->src) < 0)
1499             {
1500                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1501                   "for permit-access directive in configuration file: \"%s\"", vec[0]);
1502                string_append(&config->proxy_args,
1503                   "<br>\nWARNING: Invalid source address, port or netmask for "
1504                   "permit-access directive in configuration file: \"");
1505                string_append(&config->proxy_args,
1506                   vec[0]);
1507                string_append(&config->proxy_args,
1508                   "\"<br><br>\n");
1509                freez(cur_acl);
1510                break;
1511             }
1512             if (vec_count == 2)
1513             {
1514                if (acl_addr(vec[1], cur_acl->dst) < 0)
1515                {
1516                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1517                      "for permit-access directive in configuration file: \"%s\"", vec[1]);
1518                   string_append(&config->proxy_args,
1519                      "<br>\nWARNING: Invalid destination address, port or netmask for "
1520                      "permit-access directive in configuration file: \"");
1521                   string_append(&config->proxy_args,
1522                      vec[1]);
1523                   string_append(&config->proxy_args,
1524                      "\"<br><br>\n");
1525                   freez(cur_acl);
1526                   break;
1527                }
1528             }
1529 #ifdef HAVE_RFC2553
1530             else
1531             {
1532                cur_acl->wildcard_dst = 1;
1533             }
1534 #endif /* def HAVE_RFC2553 */
1535
1536             /*
1537              * Add it to the list.  Note we reverse the list to get the
1538              * behaviour the user expects.  With both the ACL and
1539              * actions file, the last match wins.  However, the internal
1540              * implementations are different:  The actions file is stored
1541              * in the same order as the file, and scanned completely.
1542              * With the ACL, we reverse the order as we load it, then
1543              * when we scan it we stop as soon as we get a match.
1544              */
1545             cur_acl->next  = config->acl;
1546             config->acl = cur_acl;
1547
1548             break;
1549 #endif /* def FEATURE_ACL */
1550
1551 /* *************************************************************************
1552  * proxy-info-url url
1553  * *************************************************************************/
1554          case hash_proxy_info_url :
1555             freez(config->proxy_info_url);
1556             config->proxy_info_url = strdup_or_die(arg);
1557             break;
1558
1559
1560 /* *************************************************************************
1561  * receive-buffer-size n
1562  * *************************************************************************/
1563          case hash_receive_buffer_size :
1564             config->receive_buffer_size = (size_t)parse_numeric_value(cmd, arg);
1565             if (config->receive_buffer_size < BUFFER_SIZE)
1566             {
1567                log_error(LOG_LEVEL_INFO,
1568                   "receive-buffer-size %d seems low and may cause problems."
1569                   "Consider setting it to at least %d.",
1570                   config->receive_buffer_size, BUFFER_SIZE);
1571             }
1572             break;
1573
1574 /* *************************************************************************
1575  * single-threaded 0|1
1576  * *************************************************************************/
1577          case hash_single_threaded :
1578             config->multi_threaded =  0 == parse_toggle_state(cmd, arg);
1579             break;
1580
1581 /* *************************************************************************
1582  * socket-timeout numer_of_seconds
1583  * *************************************************************************/
1584          case hash_socket_timeout :
1585          {
1586             int socket_timeout = parse_numeric_value(cmd, arg);
1587             if (0 <= socket_timeout)
1588             {
1589                config->socket_timeout = socket_timeout;
1590             }
1591             else
1592             {
1593                log_error(LOG_LEVEL_FATAL, "Invalid socket-timeout: '%s'", arg);
1594             }
1595             break;
1596          }
1597
1598 /* *************************************************************************
1599  * split-large-cgi-forms
1600  * *************************************************************************/
1601          case hash_split_large_cgi_forms :
1602             if (parse_toggle_state(cmd, arg) == 1)
1603             {
1604                config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1605             }
1606             else
1607             {
1608                config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1609             }
1610             break;
1611
1612 /* *************************************************************************
1613  * templdir directory-name
1614  * *************************************************************************/
1615          case hash_templdir :
1616             freez(config->templdir);
1617             config->templdir = make_path(NULL, arg);
1618             break;
1619
1620 #ifdef FEATURE_EXTERNAL_FILTERS
1621 /* *************************************************************************
1622  * temporary-directory directory-name
1623  * *************************************************************************/
1624          case hash_temporary_directory :
1625             freez(config->temporary_directory);
1626             config->temporary_directory = make_path(NULL, arg);
1627             break;
1628 #endif
1629
1630 /* *************************************************************************
1631  * tolerate-pipelining (0|1)
1632  * *************************************************************************/
1633          case hash_tolerate_pipelining :
1634             if (parse_toggle_state(cmd, arg) == 1)
1635             {
1636                config->feature_flags |= RUNTIME_FEATURE_TOLERATE_PIPELINING;
1637             }
1638             else
1639             {
1640                config->feature_flags &= ~RUNTIME_FEATURE_TOLERATE_PIPELINING;
1641             }
1642             break;
1643
1644 /* *************************************************************************
1645  * toggle (0|1)
1646  * *************************************************************************/
1647 #ifdef FEATURE_TOGGLE
1648          case hash_toggle :
1649             global_toggle_state = parse_toggle_state(cmd, arg);
1650             break;
1651 #endif /* def FEATURE_TOGGLE */
1652
1653 /* *************************************************************************
1654  * trust-info-url url
1655  * *************************************************************************/
1656 #ifdef FEATURE_TRUST
1657          case hash_trust_info_url :
1658             enlist(config->trust_info, arg);
1659             break;
1660 #endif /* def FEATURE_TRUST */
1661
1662 /* *************************************************************************
1663  * trust-x-forwarded-for (0|1)
1664  * *************************************************************************/
1665          case hash_trust_x_forwarded_for :
1666             config->trust_x_forwarded_for = parse_toggle_state(cmd, arg);
1667             break;
1668
1669 /* *************************************************************************
1670  * trusted-cgi-referrer http://www.example.org/some/path.html
1671  * *************************************************************************/
1672          case hash_trusted_cgi_referrer :
1673             /*
1674              * We don't validate the specified referrer as
1675              * it's only used for string comparison.
1676              */
1677             freez(config->trusted_cgi_referrer);
1678             config->trusted_cgi_referrer = strdup_or_die(arg);
1679             break;
1680
1681 /* *************************************************************************
1682  * trustfile filename
1683  * (In confdir by default.)
1684  * *************************************************************************/
1685 #ifdef FEATURE_TRUST
1686          case hash_trustfile :
1687             freez(config->trustfile);
1688             config->trustfile = make_path(config->confdir, arg);
1689             break;
1690 #endif /* def FEATURE_TRUST */
1691
1692 /* *************************************************************************
1693  * usermanual url
1694  * *************************************************************************/
1695          case hash_usermanual :
1696             /*
1697              * XXX: If this isn't the first config directive, the
1698              * show-status page links to the website documentation
1699              * for the directives that were already parsed. Lame.
1700              */
1701             freez(config->usermanual);
1702             config->usermanual = strdup_or_die(arg);
1703             break;
1704
1705 /* *************************************************************************
1706  * Win32 Console options:
1707  * *************************************************************************/
1708
1709 /* *************************************************************************
1710  * hide-console
1711  * *************************************************************************/
1712 #ifdef _WIN_CONSOLE
1713          case hash_hide_console :
1714             hideConsole = 1;
1715             break;
1716 #endif /*def _WIN_CONSOLE*/
1717
1718
1719 /* *************************************************************************
1720  * Win32 GUI options:
1721  * *************************************************************************/
1722
1723 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1724 /* *************************************************************************
1725  * activity-animation (0|1)
1726  * *************************************************************************/
1727          case hash_activity_animation :
1728             g_bShowActivityAnimation = parse_toggle_state(cmd, arg);
1729             break;
1730
1731 /* *************************************************************************
1732  *  close-button-minimizes (0|1)
1733  * *************************************************************************/
1734          case hash_close_button_minimizes :
1735             g_bCloseHidesWindow = parse_toggle_state(cmd, arg);
1736             break;
1737
1738 /* *************************************************************************
1739  * log-buffer-size (0|1)
1740  * *************************************************************************/
1741          case hash_log_buffer_size :
1742             g_bLimitBufferSize = parse_toggle_state(cmd, arg);
1743             break;
1744
1745 /* *************************************************************************
1746  * log-font-name fontname
1747  * *************************************************************************/
1748          case hash_log_font_name :
1749             if (strlcpy(g_szFontFaceName, arg,
1750                    sizeof(g_szFontFaceName)) >= sizeof(g_szFontFaceName))
1751             {
1752                log_error(LOG_LEVEL_FATAL,
1753                   "log-font-name argument '%s' is longer than %u characters.",
1754                   arg, sizeof(g_szFontFaceName)-1);
1755             }
1756             break;
1757
1758 /* *************************************************************************
1759  * log-font-size n
1760  * *************************************************************************/
1761          case hash_log_font_size :
1762             g_nFontSize = parse_numeric_value(cmd, arg);
1763             break;
1764
1765 /* *************************************************************************
1766  * log-highlight-messages (0|1)
1767  * *************************************************************************/
1768          case hash_log_highlight_messages :
1769             g_bHighlightMessages = parse_toggle_state(cmd, arg);
1770             break;
1771
1772 /* *************************************************************************
1773  * log-max-lines n
1774  * *************************************************************************/
1775          case hash_log_max_lines :
1776             g_nMaxBufferLines = parse_numeric_value(cmd, arg);
1777             break;
1778
1779 /* *************************************************************************
1780  * log-messages (0|1)
1781  * *************************************************************************/
1782          case hash_log_messages :
1783             g_bLogMessages = parse_toggle_state(cmd, arg);
1784             break;
1785
1786 /* *************************************************************************
1787  * show-on-task-bar (0|1)
1788  * *************************************************************************/
1789          case hash_show_on_task_bar :
1790             g_bShowOnTaskBar = parse_toggle_state(cmd, arg);
1791             break;
1792
1793 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1794
1795
1796 /* *************************************************************************
1797  * Warnings about unsupported features
1798  * *************************************************************************/
1799 #ifndef FEATURE_ACL
1800          case hash_deny_access:
1801 #endif /* ndef FEATURE_ACL */
1802 #ifndef FEATURE_CGI_EDIT_ACTIONS
1803          case hash_enable_edit_actions:
1804 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1805 #ifndef FEATURE_TOGGLE
1806          case hash_enable_remote_toggle:
1807 #endif /* ndef FEATURE_TOGGLE */
1808 #ifndef FEATURE_ACL
1809          case hash_permit_access:
1810 #endif /* ndef FEATURE_ACL */
1811 #ifndef FEATURE_TOGGLE
1812          case hash_toggle :
1813 #endif /* ndef FEATURE_TOGGLE */
1814 #ifndef FEATURE_TRUST
1815          case hash_trustfile :
1816          case hash_trust_info_url :
1817 #endif /* ndef FEATURE_TRUST */
1818
1819 #ifndef _WIN_CONSOLE
1820          case hash_hide_console :
1821 #endif /* ndef _WIN_CONSOLE */
1822
1823 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1824          case hash_activity_animation :
1825          case hash_close_button_minimizes :
1826          case hash_log_buffer_size :
1827          case hash_log_font_name :
1828          case hash_log_font_size :
1829          case hash_log_highlight_messages :
1830          case hash_log_max_lines :
1831          case hash_log_messages :
1832          case hash_show_on_task_bar :
1833 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1834             /* These warnings are annoying - so hide them. -- Jon */
1835             /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1836             break;
1837
1838 /* *************************************************************************/
1839          default :
1840 /* *************************************************************************/
1841             /*
1842              * I decided that I liked this better as a warning than an
1843              * error.  To change back to an error, just change log level
1844              * to LOG_LEVEL_FATAL.
1845              */
1846             log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive "
1847                "'%s' (%uU) in line %lu in configuration file (%s).",
1848                buf, directive_hash, linenum, configfile);
1849             string_append(&config->proxy_args,
1850                " <strong class='warning'>Warning: Ignoring unrecognized directive:</strong>");
1851             break;
1852
1853 /* *************************************************************************/
1854       } /* end switch(hash_string(cmd)) */
1855
1856       /* Save the argument for the show-status page. */
1857       savearg(cmd, arg, config);
1858       freez(buf);
1859    } /* end while (read_config_line(...)) */
1860
1861    fclose(configfp);
1862
1863    set_debug_level(config->debug);
1864
1865    freez(config->logfile);
1866
1867    if (daemon_mode)
1868    {
1869       if (NULL != logfile)
1870       {
1871          config->logfile = logfile;
1872          init_error_log(Argv[0], config->logfile);
1873       }
1874       else
1875       {
1876          disable_logging();
1877       }
1878    }
1879
1880 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1881    if (config->default_server_timeout > config->keep_alive_timeout)
1882    {
1883       log_error(LOG_LEVEL_ERROR,
1884          "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.",
1885          config->default_server_timeout, config->keep_alive_timeout);
1886       config->default_server_timeout = config->keep_alive_timeout;
1887    }
1888 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
1889
1890 #ifdef FEATURE_CONNECTION_SHARING
1891    if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1892    {
1893       if (!config->multi_threaded)
1894       {
1895          /*
1896           * While we could use keep-alive without multiple threads
1897           * if we didn't bother with enforcing the connection timeout,
1898           * that might make Tor users sad, even though they shouldn't
1899           * enable the single-threaded option anyway.
1900           *
1901           * XXX: We could still use Proxy-Connection: keep-alive.
1902           */
1903          config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1904          log_error(LOG_LEVEL_ERROR,
1905             "Config option single-threaded disables connection keep-alive.");
1906       }
1907    }
1908    else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
1909    {
1910       log_error(LOG_LEVEL_ERROR, "Config option connection-sharing "
1911          "has no effect if keep-alive-timeout isn't set.");
1912       config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING;
1913    }
1914 #endif /* def FEATURE_CONNECTION_SHARING */
1915
1916    if (NULL == config->proxy_args)
1917    {
1918       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1919    }
1920
1921    if (config->re_filterfile[0])
1922    {
1923       add_loader(load_re_filterfiles, config);
1924    }
1925
1926    if (config->actions_file[0])
1927    {
1928       add_loader(load_action_files, config);
1929    }
1930
1931 #ifdef FEATURE_TRUST
1932    if (config->trustfile)
1933    {
1934       add_loader(load_trustfile, config);
1935    }
1936 #endif /* def FEATURE_TRUST */
1937
1938    if (NULL == config->haddr[0])
1939    {
1940       config->haddr[0] = strdup_or_die(HADDR_DEFAULT);
1941    }
1942
1943    for (i = 0; i < MAX_LISTENING_SOCKETS && NULL != config->haddr[i]; i++)
1944    {
1945       if ((*config->haddr[i] == '[')
1946          && (NULL != (p = strchr(config->haddr[i], ']')))
1947          && (p[1] == ':')
1948          && (0 < (config->hport[i] = atoi(p + 2))))
1949       {
1950          *p = '\0';
1951          memmove((void *)config->haddr[i], config->haddr[i] + 1,
1952             (size_t)(p - config->haddr[i]));
1953       }
1954       else if (NULL != (p = strchr(config->haddr[i], ':'))
1955          && (0 < (config->hport[i] = atoi(p + 1))))
1956       {
1957          *p = '\0';
1958       }
1959       else
1960       {
1961          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr[i]);
1962          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1963       }
1964       if (*config->haddr[i] == '\0')
1965       {
1966          /*
1967           * Only the port specified. We stored it in config->hport[i]
1968           * and don't need its text representation anymore.
1969           * Use config->hport[i] == 0 to iterate listening addresses since
1970           * now.
1971           */
1972          freez(config->haddr[i]);
1973       }
1974    }
1975
1976    /*
1977     * Want to run all the loaders once now.
1978     *
1979     * Need to set up a fake csp, so they can get to the config.
1980     */
1981    fake_csp = zalloc_or_die(sizeof(*fake_csp));
1982    fake_csp->config = config;
1983
1984    if (run_loader(fake_csp))
1985    {
1986       freez(fake_csp);
1987       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1988       /* Never get here - LOG_LEVEL_FATAL causes program exit */
1989    }
1990    freez(fake_csp);
1991
1992 /* FIXME: this is a kludge for win32 */
1993 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1994
1995    g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1996    g_user_actions_file  = config->actions_file[2];  /* FIXME Hope this is user.action */
1997    g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1998    g_user_filterfile    = config->re_filterfile[1]; /* FIXME Hope this is user.filter */
1999
2000 #ifdef FEATURE_TRUST
2001    g_trustfile        = config->trustfile;
2002 #endif /* def FEATURE_TRUST */
2003
2004
2005 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
2006 /* FIXME: end kludge */
2007
2008
2009    if (current_configfile == NULL)
2010    {
2011       config->need_bind = 1;
2012    }
2013    else
2014    {
2015       struct configuration_spec * oldcfg = (struct configuration_spec *)
2016                                            current_configfile->f;
2017       /*
2018        * Check if config->haddr[i],hport[i] == oldcfg->haddr[i],hport[i]
2019        */
2020       config->need_bind = 0;
2021
2022       for (i = 0; i < MAX_LISTENING_SOCKETS; i++)
2023       {
2024          if (config->hport[i] != oldcfg->hport[i])
2025          {
2026             config->need_bind = 1;
2027          }
2028          else if (config->haddr[i] == NULL)
2029          {
2030             if (oldcfg->haddr[i] != NULL)
2031             {
2032                config->need_bind = 1;
2033             }
2034          }
2035          else if (oldcfg->haddr[i] == NULL)
2036          {
2037             config->need_bind = 1;
2038          }
2039          else if (0 != strcmp(config->haddr[i], oldcfg->haddr[i]))
2040          {
2041             config->need_bind = 1;
2042          }
2043       }
2044
2045       current_configfile->unloader = unload_configfile;
2046    }
2047
2048    fs->next = files->next;
2049    files->next = fs;
2050
2051    current_configfile = fs;
2052
2053    return (config);
2054 }
2055
2056
2057 /*********************************************************************
2058  *
2059  * Function    :  savearg
2060  *
2061  * Description :  Called from `load_config'.  It saves each non-empty
2062  *                and non-comment line from config into
2063  *                config->proxy_args.  This is used to create the
2064  *                show-status page.  On error, frees
2065  *                config->proxy_args and sets it to NULL
2066  *
2067  * Parameters  :
2068  *          1  :  command = config setting that was found
2069  *          2  :  argument = the setting's argument (if any)
2070  *          3  :  config = Configuration to save into.
2071  *
2072  * Returns     :  N/A
2073  *
2074  *********************************************************************/
2075 static void savearg(char *command, char *argument, struct configuration_spec * config)
2076 {
2077    char * buf;
2078    char * s;
2079
2080    assert(command);
2081    assert(argument);
2082
2083    /*
2084     * Add config option name embedded in
2085     * link to its section in the user-manual
2086     */
2087    buf = strdup_or_die("\n<a href=\"");
2088    if (!strncmpic(config->usermanual, "file://", 7) ||
2089        !strncmpic(config->usermanual, "http", 4))
2090    {
2091       string_append(&buf, config->usermanual);
2092    }
2093    else
2094    {
2095       string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
2096    }
2097    string_append(&buf, CONFIG_HELP_PREFIX);
2098    string_join  (&buf, string_toupper(command));
2099    string_append(&buf, "\">");
2100    string_append(&buf, command);
2101    string_append(&buf, "</a> ");
2102
2103    if (NULL == buf)
2104    {
2105       freez(config->proxy_args);
2106       return;
2107    }
2108
2109    if ((NULL != argument) && ('\0' != *argument))
2110    {
2111       s = html_encode(argument);
2112       if (NULL == s)
2113       {
2114          freez(buf);
2115          freez(config->proxy_args);
2116          return;
2117       }
2118
2119       if (strncmpic(argument, "http://", 7) == 0)
2120       {
2121          string_append(&buf, "<a href=\"");
2122          string_append(&buf, s);
2123          string_append(&buf, "\">");
2124          string_join  (&buf, s);
2125          string_append(&buf, "</a>");
2126       }
2127       else
2128       {
2129          string_join  (&buf, s);
2130       }
2131    }
2132
2133    string_append(&buf, "<br>");
2134    string_join(&config->proxy_args, buf);
2135 }
2136
2137
2138 /*
2139   Local Variables:
2140   tab-width: 3
2141   end:
2142 */