56f2938ca1c831c46bdc84f4d969279bc63af7ed
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.88 2009/02/28 10:57:10 fabiankeil Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
5  *
6  * Purpose     :  Loads settings from the configuration file into
7  *                global variables.  This file contains both the
8  *                routine to load the configuration and the global
9  *                variables it writes to.
10  *
11  * Copyright   :  Written by and Copyright (C) 2001-2009 the
12  *                Privoxy team. http://www.privoxy.org/
13  *
14  *                Based on the Internet Junkbuster originally written
15  *                by and Copyright (C) 1997 Anonymous Coders and
16  *                Junkbusters Corporation.  http://www.junkbusters.com
17  *
18  *                This program is free software; you can redistribute it
19  *                and/or modify it under the terms of the GNU General
20  *                Public License as published by the Free Software
21  *                Foundation; either version 2 of the License, or (at
22  *                your option) any later version.
23  *
24  *                This program is distributed in the hope that it will
25  *                be useful, but WITHOUT ANY WARRANTY; without even the
26  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
27  *                PARTICULAR PURPOSE.  See the GNU General Public
28  *                License for more details.
29  *
30  *                The GNU General Public License should be included with
31  *                this file.  If not, you can view it at
32  *                http://www.gnu.org/copyleft/gpl.html
33  *                or write to the Free Software Foundation, Inc., 59
34  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
35  *
36  * Revisions   :
37  *    $Log: loadcfg.c,v $
38  *    Revision 1.88  2009/02/28 10:57:10  fabiankeil
39  *    Gimme a break or two. Don't let the show-status page
40  *    link to the website documentation for the user-manual
41  *    directive itself.
42  *
43  *    Revision 1.87  2009/02/15 07:56:13  fabiankeil
44  *    Increase default socket timeout to 300 seconds.
45  *
46  *    Revision 1.86  2009/02/08 19:18:57  fabiankeil
47  *    Now that we have the match-all.action file, the other action
48  *    files changed their position in config->actions_file[] back
49  *    to the way it was before standard.action got removed and the
50  *    changes from revision 1.84 have to be reverted.
51  *
52  *    Revision 1.85  2009/01/22 12:06:26  fabiankeil
53  *    Don't keep connections alive when running single-threaded.
54  *
55  *    Revision 1.84  2009/01/14 16:14:36  fabiankeil
56  *    Due to the standard.action file removal, the other action
57  *    files changed their position in config->actions_file[].
58  *    Update mingw32 kludge accordingly.
59  *
60  *    Revision 1.83  2008/12/20 14:53:55  fabiankeil
61  *    Add config option socket-timeout to control the time
62  *    Privoxy waits for data to arrive on a socket. Useful
63  *    in case of stale ssh tunnels or when fuzz-testing.
64  *
65  *    Revision 1.82  2008/11/16 12:43:49  fabiankeil
66  *    Turn keep-alive support into a runtime feature
67  *    that is disabled by setting keep-alive-timeout
68  *    to a negative value.
69  *
70  *    Revision 1.81  2008/11/13 09:08:42  fabiankeil
71  *    Add new config option: keep-alive-timeout.
72  *
73  *    Revision 1.80  2008/08/31 15:59:03  fabiankeil
74  *    There's no reason to let remote toggling support depend
75  *    on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
76  *
77  *    Revision 1.79  2008/08/30 12:03:07  fabiankeil
78  *    Remove FEATURE_COOKIE_JAR.
79  *
80  *    Revision 1.78  2008/08/02 08:23:22  fabiankeil
81  *    If the enforce-blocks directive is used with FEATURE_FORCE_LOAD
82  *    disabled, log a message that blocks will always be enforced
83  *    instead of complaining about an unrecognized directive.
84  *    Reported by Pietro Leone.
85  *
86  *    Revision 1.77  2008/05/26 16:13:22  fabiankeil
87  *    Reuse directive_hash and don't hash the same directive twice.
88  *
89  *    Revision 1.76  2008/05/10 09:03:16  fabiankeil
90  *    - Merge three string_append() calls.
91  *    - Remove useless assertion.
92  *
93  *    Revision 1.75  2008/03/30 14:52:05  fabiankeil
94  *    Rename load_actions_file() and load_re_filterfile()
95  *    as they load multiple files "now".
96  *
97  *    Revision 1.74  2008/03/26 18:07:07  fabiankeil
98  *    Add hostname directive. Closes PR#1918189.
99  *
100  *    Revision 1.73  2008/02/16 16:54:51  fabiankeil
101  *    Fix typo.
102  *
103  *    Revision 1.72  2008/02/03 13:46:15  fabiankeil
104  *    Add SOCKS5 support. Patch #1862863 by Eric M. Hopper with minor changes.
105  *
106  *    Revision 1.71  2007/12/23 15:24:56  fabiankeil
107  *    Reword "unrecognized directive" warning, use better
108  *    mark up and add a <br>. Fixes parts of #1856559.
109  *
110  *    Revision 1.70  2007/12/15 14:24:05  fabiankeil
111  *    Plug memory leak if listen-address only specifies the port.
112  *
113  *    Revision 1.69  2007/10/27 13:02:27  fabiankeil
114  *    Relocate daemon-mode-related log messages to make sure
115  *    they aren't shown again in case of configuration reloads.
116  *
117  *    Revision 1.68  2007/10/19 16:32:34  fabiankeil
118  *    Plug memory leak introduced with my last commit.
119  *
120  *    Revision 1.67  2007/10/14 14:12:41  fabiankeil
121  *    When in daemon mode, close stderr after the configuration file has been
122  *    parsed the first time. If logfile isn't set, stop logging. Fixes BR#897436.
123  *
124  *    Revision 1.66  2007/08/05 14:02:09  fabiankeil
125  *    #1763173 from Stefan Huehner: declare unload_configfile() static.
126  *
127  *    Revision 1.65  2007/07/21 11:51:36  fabiankeil
128  *    As Hal noticed, checking dispatch_cgi() as the last cruncher
129  *    looks like a bug if CGI requests are blocked unintentionally,
130  *    so don't do it unless the user enabled the new config option
131  *    "allow-cgi-request-crunching".
132  *
133  *    Revision 1.64  2007/05/21 10:44:08  fabiankeil
134  *    - Use strlcpy() instead of strcpy().
135  *    - Stop treating actions files special. Expect a complete file name
136  *      (with or without path) like it's done for the rest of the files.
137  *      Closes FR#588084.
138  *    - Remove an unnecessary temporary memory allocation.
139  *    - Don't log anything to the console when running as
140  *      daemon and no errors occurred.
141  *
142  *    Revision 1.63  2007/04/09 18:11:36  fabiankeil
143  *    Don't mistake VC++'s _snprintf() for a snprintf() replacement.
144  *
145  *    Revision 1.62  2007/03/17 15:20:05  fabiankeil
146  *    New config option: enforce-blocks.
147  *
148  *    Revision 1.61  2007/03/16 16:47:35  fabiankeil
149  *    - Mention other reasons why acl directive loading might have failed.
150  *    - Don't log the acl source if the acl destination is to blame.
151  *
152  *    Revision 1.60  2007/01/27 13:09:16  fabiankeil
153  *    Add new config option "templdir" to
154  *    change the templates directory.
155  *
156  *    Revision 1.59  2006/12/31 17:56:38  fabiankeil
157  *    Added config option accept-intercepted-requests
158  *    and disabled it by default.
159  *
160  *    Revision 1.58  2006/12/31 14:24:29  fabiankeil
161  *    Fix gcc43 compiler warnings.
162  *
163  *    Revision 1.57  2006/12/21 12:57:48  fabiankeil
164  *    Add config option "split-large-forms"
165  *    to work around the browser bug reported
166  *    in BR #1570678.
167  *
168  *    Revision 1.56  2006/12/17 17:04:51  fabiankeil
169  *    Move the <br> in the generated HTML for the config
170  *    options from the beginning of the string to its end.
171  *    Keeps the white space in balance.
172  *
173  *    Revision 1.55  2006/11/28 15:31:52  fabiankeil
174  *    Fix memory leak in case of config file reloads.
175  *
176  *    Revision 1.54  2006/10/21 16:04:22  fabiankeil
177  *    Modified kludge for win32 to make ming32 menu
178  *    "Options/Edit Filters" (sort of) work again.
179  *    Same limitations as for the action files apply.
180  *    Fixes BR 1567373.
181  *
182  *    Revision 1.53  2006/09/06 18:45:03  fabiankeil
183  *    Incorporate modified version of Roland Rosenfeld's patch to
184  *    optionally access the user-manual via Privoxy. Closes patch 679075.
185  *
186  *    Formatting changed to Privoxy style, added call to
187  *    cgi_error_no_template if the requested file doesn't
188  *    exist and modified check whether or not Privoxy itself
189  *    should serve the manual. Should work cross-platform now.
190  *
191  *    Revision 1.52  2006/09/06 10:43:32  fabiankeil
192  *    Added config option enable-remote-http-toggle
193  *    to specify if Privoxy should recognize special
194  *    headers (currently only X-Filter) to change its
195  *    behaviour. Disabled by default.
196  *
197  *    Revision 1.51  2006/09/06 09:23:37  fabiankeil
198  *    Make number of retries in case of forwarded-connect problems
199  *    a config file option (forwarded-connect-retries) and use 0 as
200  *    default.
201  *
202  *    Revision 1.50  2006/07/18 14:48:46  david__schmidt
203  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
204  *    with what was really the latest development (the v_3_0_branch branch)
205  *
206  *    Revision 1.48.2.7  2006/02/02 17:29:16  david__schmidt
207  *    Don't forget to malloc space for the null terminator...
208  *
209  *    Revision 1.48.2.6  2006/01/29 23:10:56  david__schmidt
210  *    Multiple filter file support
211  *
212  *    Revision 1.48.2.5  2003/05/08 15:17:25  oes
213  *    Closed two memory leaks; hopefully the last remaining ones
214  *    (in the main execution paths, anyway).
215  *
216  *    Revision 1.48.2.4  2003/04/11 12:06:14  oes
217  *    Addressed bug #719435
218  *     - Extraneous filterfile directives now logged as errors
219  *     - This and unrecnonised directives now really obvious on status page
220  *
221  *    Revision 1.48.2.3  2003/03/11 11:53:59  oes
222  *    Cosmetic: Renamed cryptic variable
223  *
224  *    Revision 1.48.2.2  2002/11/12 16:28:20  oes
225  *    Move unrelated variable declaration out of #ifdef FEATURE_ACL; fixes bug #636655
226  *
227  *    Revision 1.48.2.1  2002/08/21 17:58:05  oes
228  *    Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
229  *
230  *    Revision 1.48  2002/05/14 21:30:38  oes
231  *    savearg now uses own linking code instead of (now special-cased) add_help_link
232  *
233  *    Revision 1.47  2002/05/12 21:36:29  jongfoster
234  *    Correcting function comments
235  *
236  *    Revision 1.46  2002/04/26 12:55:14  oes
237  *     - New option "user-manual", defaults to our site
238  *       via project.h #define
239  *     - savearg now embeds option names in help links
240  *
241  *    Revision 1.45  2002/04/24 02:11:54  oes
242  *    Jon's multiple AF patch: Allow up to MAX_AF_FILES actionsfile options
243  *
244  *    Revision 1.44  2002/04/08 20:37:13  swa
245  *    fixed JB spelling
246  *
247  *    Revision 1.43  2002/04/08 20:36:50  swa
248  *    fixed JB spelling
249  *
250  *    Revision 1.42  2002/04/05 15:50:15  oes
251  *    fix for invalid HTML proxy_args
252  *
253  *    Revision 1.41  2002/03/31 17:19:00  jongfoster
254  *    Win32 only: Enabling STRICT to fix a VC++ compile warning.
255  *
256  *    Revision 1.40  2002/03/26 22:29:55  swa
257  *    we have a new homepage!
258  *
259  *    Revision 1.39  2002/03/24 13:25:43  swa
260  *    name change related issues
261  *
262  *    Revision 1.38  2002/03/24 13:05:48  jongfoster
263  *    Renaming re_filterfile to filterfile
264  *
265  *    Revision 1.37  2002/03/16 23:54:06  jongfoster
266  *    Adding graceful termination feature, to help look for memory leaks.
267  *    If you enable this (which, by design, has to be done by hand
268  *    editing config.h) and then go to http://i.j.b/die, then the program
269  *    will exit cleanly after the *next* request.  It should free all the
270  *    memory that was used.
271  *
272  *    Revision 1.36  2002/03/13 00:27:05  jongfoster
273  *    Killing warnings
274  *
275  *    Revision 1.35  2002/03/07 03:52:44  oes
276  *    Set logging to tty for --no-daemon mode
277  *
278  *    Revision 1.34  2002/03/06 23:14:35  jongfoster
279  *    Trivial cosmetic changes to make function comments easier to find.
280  *
281  *    Revision 1.33  2002/03/05 04:52:42  oes
282  *    Deleted non-errlog debugging code
283  *
284  *    Revision 1.32  2002/03/04 18:24:53  oes
285  *    Re-enabled output of unknown config directive hash
286  *
287  *    Revision 1.31  2002/03/03 15:07:20  oes
288  *    Re-enabled automatic config reloading
289  *
290  *    Revision 1.30  2002/01/22 23:31:43  jongfoster
291  *    Replacing strsav() with string_append()
292  *
293  *    Revision 1.29  2002/01/17 21:02:30  jongfoster
294  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
295  *
296  *    Renaming free_url to free_url_spec, since it frees a struct url_spec.
297  *
298  *    Revision 1.28  2001/12/30 14:07:32  steudten
299  *    - Add signal handling (unix)
300  *    - Add SIGHUP handler (unix)
301  *    - Add creation of pidfile (unix)
302  *    - Add action 'top' in rc file (RH)
303  *    - Add entry 'SIGNALS' to manpage
304  *    - Add exit message to logfile (unix)
305  *
306  *    Revision 1.27  2001/11/07 00:02:13  steudten
307  *    Add line number in error output for lineparsing for
308  *    actionsfile and configfile.
309  *    Special handling for CLF added.
310  *
311  *    Revision 1.26  2001/11/05 21:41:43  steudten
312  *    Add changes to be a real daemon just for unix os.
313  *    (change cwd to /, detach from controlling tty, set
314  *    process group and session leader to the own process.
315  *    Add DBG() Macro.
316  *    Add some fatal-error log message for failed malloc().
317  *    Add '-d' if compiled with 'configure --with-debug' to
318  *    enable debug output.
319  *
320  *    Revision 1.25  2001/10/25 03:40:48  david__schmidt
321  *    Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
322  *    threads to call select() simultaneously.  So, it's time to do a real, live,
323  *    native OS/2 port.  See defines for __EMX__ (the porting layer) vs. __OS2__
324  *    (native). Both versions will work, but using __OS2__ offers multi-threading.
325  *
326  *    Revision 1.24  2001/10/23 21:40:30  jongfoster
327  *    Added support for enable-edit-actions and enable-remote-toggle config
328  *    file options.
329  *
330  *    Revision 1.23  2001/10/07 15:36:00  oes
331  *    Introduced new config option "buffer-limit"
332  *
333  *    Revision 1.22  2001/09/22 16:36:59  jongfoster
334  *    Removing unused parameter fs from read_config_line()
335  *
336  *    Revision 1.21  2001/09/16 17:10:43  jongfoster
337  *    Moving function savearg() here, since it was the only thing left in
338  *    showargs.c.
339  *
340  *    Revision 1.20  2001/07/30 22:08:36  jongfoster
341  *    Tidying up #defines:
342  *    - All feature #defines are now of the form FEATURE_xxx
343  *    - Permanently turned off WIN_GUI_EDIT
344  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
345  *
346  *    Revision 1.19  2001/07/15 17:45:16  jongfoster
347  *    Removing some unused #includes
348  *
349  *    Revision 1.18  2001/07/13 14:01:14  oes
350  *     - Removed all #ifdef PCRS
351  *     - Removed vim-settings
352  *
353  *    Revision 1.17  2001/06/29 13:31:03  oes
354  *    - Improved comments
355  *    - Fixed (actionsfile) and sorted hashes
356  *    - Introduced admin_address and proxy-info-url
357  *      as config parameters
358  *    - Renamed config->proxy_args_invocation (which didn't have
359  *      the invocation but the options!) to config->proxy_args
360  *    - Various adaptions
361  *    - Removed logentry from cancelled commit
362  *
363  *    Revision 1.16  2001/06/09 10:55:28  jongfoster
364  *    Changing BUFSIZ ==> BUFFER_SIZE
365  *
366  *    Revision 1.15  2001/06/07 23:13:40  jongfoster
367  *    Merging ACL and forward files into config file.
368  *    Cosmetic: Sorting config file options alphabetically.
369  *    Cosmetic: Adding brief syntax comments to config file options.
370  *
371  *    Revision 1.14  2001/06/07 14:46:25  joergs
372  *    Missing make_path() added for re_filterfile.
373  *
374  *    Revision 1.13  2001/06/05 22:33:54  jongfoster
375  *
376  *    Fixed minor memory leak.
377  *    Also now uses make_path to prepend the pathnames.
378  *
379  *    Revision 1.12  2001/06/05 20:04:09  jongfoster
380  *    Now uses _snprintf() in place of snprintf() under Win32.
381  *
382  *    Revision 1.11  2001/06/04 18:31:58  swa
383  *    files are now prefixed with either `confdir' or `logdir'.
384  *    `make redhat-dist' replaces both entries confdir and logdir
385  *    with redhat values
386  *
387  *    Revision 1.10  2001/06/03 19:11:54  oes
388  *    introduced confdir option
389  *
390  *    Revision 1.9  2001/06/01 20:06:24  jongfoster
391  *    Removed support for "tinygif" option - moved to actions file.
392  *
393  *    Revision 1.8  2001/05/31 21:27:13  jongfoster
394  *    Removed many options from the config file and into the
395  *    "actions" file: add_forwarded, suppress_vanilla_wafer,
396  *    wafer, add_header, user_agent, referer, from
397  *    Also globally replaced "permission" with "action".
398  *
399  *    Revision 1.7  2001/05/29 09:50:24  jongfoster
400  *    Unified blocklist/imagelist/permissionslist.
401  *    File format is still under discussion, but the internal changes
402  *    are (mostly) done.
403  *
404  *    Also modified interceptor behaviour:
405  *    - We now intercept all URLs beginning with one of the following
406  *      prefixes (and *only* these prefixes):
407  *        * http://i.j.b/
408  *        * http://ijbswa.sf.net/config/
409  *        * http://ijbswa.sourceforge.net/config/
410  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
411  *    - Internal changes so that intercepted and fast redirect pages
412  *      are not replaced with an image.
413  *    - Interceptors now have the option to send a binary page direct
414  *      to the client. (i.e. ijb-send-banner uses this)
415  *    - Implemented show-url-info interceptor.  (Which is why I needed
416  *      the above interceptors changes - a typical URL is
417  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
418  *      The previous mechanism would not have intercepted that, and
419  *      if it had been intercepted then it then it would have replaced
420  *      it with an image.)
421  *
422  *    Revision 1.6  2001/05/26 00:28:36  jongfoster
423  *    Automatic reloading of config file.
424  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
425  *    Most of the global variables have been moved to a new
426  *    struct configuration_spec, accessed through csp->config->globalname
427  *    Most of the globals remaining are used by the Win32 GUI.
428  *
429  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
430  *    Hard tabs->Spaces
431  *
432  *    Revision 1.4  2001/05/22 18:46:04  oes
433  *
434  *    - Enabled filtering banners by size rather than URL
435  *      by adding patterns that replace all standard banner
436  *      sizes with the "Junkbuster" gif to the re_filterfile
437  *
438  *    - Enabled filtering WebBugs by providing a pattern
439  *      which kills all 1x1 images
440  *
441  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
442  *      which is selected by the (nonstandard and therefore
443  *      capital) letter 'U' in the option string.
444  *      It causes the quantifiers to be ungreedy by default.
445  *      Appending a ? turns back to greedy (!).
446  *
447  *    - Added a new interceptor ijb-send-banner, which
448  *      sends back the "Junkbuster" gif. Without imagelist or
449  *      MSIE detection support, or if tinygif = 1, or the
450  *      URL isn't recognized as an imageurl, a lame HTML
451  *      explanation is sent instead.
452  *
453  *    - Added new feature, which permits blocking remote
454  *      script redirects and firing back a local redirect
455  *      to the browser.
456  *      The feature is conditionally compiled, i.e. it
457  *      can be disabled with --disable-fast-redirects,
458  *      plus it must be activated by a "fast-redirects"
459  *      line in the config file, has its own log level
460  *      and of course wants to be displayed by show-proxy-args
461  *      Note: Boy, all the #ifdefs in 1001 locations and
462  *      all the fumbling with configure.in and acconfig.h
463  *      were *way* more work than the feature itself :-(
464  *
465  *    - Because a generic redirect template was needed for
466  *      this, tinygif = 3 now uses the same.
467  *
468  *    - Moved GIFs, and other static HTTP response templates
469  *      to project.h
470  *
471  *    - Some minor fixes
472  *
473  *    - Removed some >400 CRs again (Jon, you really worked
474  *      a lot! ;-)
475  *
476  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
477  *    Version 2.9.4 checkin.
478  *    - Merged popupfile and cookiefile, and added control over PCRS
479  *      filtering, in new "permissionsfile".
480  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
481  *      file error you now get a message box (in the Win32 GUI) rather
482  *      than the program exiting with no explanation.
483  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
484  *      skipping.
485  *    - Removed tabs from "config"
486  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
487  *    - Bumped up version number.
488  *
489  *    Revision 1.2  2001/05/17 23:01:01  oes
490  *     - Cleaned CRLF's from the sources and related files
491  *
492  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
493  *    Initial import of version 2.9.3 source tree
494  *
495  *
496  *********************************************************************/
497 \f
498
499 #include "config.h"
500
501 #include <stdio.h>
502 #include <sys/types.h>
503 #include <stdlib.h>
504 #include <string.h>
505 #include <signal.h>
506 #include <fcntl.h>
507 #include <errno.h>
508 #include <ctype.h>
509 #include <assert.h>
510
511 #ifdef _WIN32
512
513 # ifndef STRICT
514 #  define STRICT
515 # endif
516 # include <windows.h>
517
518 # include "win32.h"
519 # ifndef _WIN_CONSOLE
520 #  include "w32log.h"
521 # endif /* ndef _WIN_CONSOLE */
522
523 #else /* ifndef _WIN32 */
524
525 #ifndef __OS2__
526 # include <unistd.h>
527 # include <sys/wait.h>
528 #endif
529 # include <sys/time.h>
530 # include <sys/stat.h>
531 # include <signal.h>
532
533 #endif
534
535 #include "loadcfg.h"
536 #include "list.h"
537 #include "jcc.h"
538 #include "filters.h"
539 #include "loaders.h"
540 #include "miscutil.h"
541 #include "errlog.h"
542 #include "ssplit.h"
543 #include "encode.h"
544 #include "urlmatch.h"
545 #include "cgi.h"
546 #include "gateway.h"
547
548 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
549
550 /*
551  * Fix a problem with Solaris.  There should be no effect on other
552  * platforms.
553  * Solaris's isspace() is a macro which uses it's argument directly
554  * as an array index.  Therefore we need to make sure that high-bit
555  * characters generate +ve values, and ideally we also want to make
556  * the argument match the declared parameter type of "int".
557  */
558 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
559 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
560
561 #ifdef FEATURE_TOGGLE
562 /* Privoxy is enabled by default. */
563 int global_toggle_state = 1;
564 #endif /* def FEATURE_TOGGLE */
565
566 /* The filename of the configfile */
567 const char *configfile  = NULL;
568
569 /*
570  * CGI functions will later need access to the invocation args,
571  * so we will make argc and argv global.
572  */
573 int Argc = 0;
574 const char **Argv = NULL;
575
576 static struct file_list *current_configfile = NULL;
577
578
579 /*
580  * This takes the "cryptic" hash of each keyword and aliases them to
581  * something a little more readable.  This also makes changing the
582  * hash values easier if they should change or the hash algorthm changes.
583  * Use the included "hash" program to find out what the hash will be
584  * for any string supplied on the command line.  (Or just put it in the
585  * config file and read the number from the error message in the log).
586  *
587  * Please keep this list sorted alphabetically (but with the Windows
588  * console and GUI specific options last).
589  */
590
591 #define hash_actions_file                1196306641ul /* "actionsfile" */
592 #define hash_accept_intercepted_requests 1513024973ul /* "accept-intercepted-requests" */
593 #define hash_admin_address               4112573064ul /* "admin-address" */
594 #define hash_allow_cgi_request_crunching  258915987ul /* "allow-cgi-request-crunching" */
595 #define hash_buffer_limit                1881726070ul /* "buffer-limit */
596 #define hash_confdir                        1978389ul /* "confdir" */
597 #define hash_debug                            78263ul /* "debug" */
598 #define hash_deny_access                 1227333715ul /* "deny-access" */
599 #define hash_enable_edit_actions         2517097536ul /* "enable-edit-actions" */
600 #define hash_enable_remote_toggle        2979744683ul /* "enable-remote-toggle" */
601 #define hash_enable_remote_http_toggle    110543988ul /* "enable-remote-http-toggle" */
602 #define hash_enforce_blocks              1862427469ul /* "enforce-blocks" */
603 #define hash_filterfile                   250887266ul /* "filterfile" */
604 #define hash_forward                        2029845ul /* "forward" */
605 #define hash_forward_socks4              3963965521ul /* "forward-socks4" */
606 #define hash_forward_socks4a             2639958518ul /* "forward-socks4a" */
607 #define hash_forward_socks5              3963965522ul /* "forward-socks5" */
608 #define hash_forwarded_connect_retries    101465292ul /* "forwarded-connect-retries" */
609 #define hash_hostname                      10308071ul /* "hostname" */
610 #define hash_keep_alive_timeout          3878599515ul /* "keep-alive-timeout" */
611 #define hash_listen_address              1255650842ul /* "listen-address" */
612 #define hash_logdir                          422889ul /* "logdir" */
613 #define hash_logfile                        2114766ul /* "logfile" */
614 #define hash_permit_access               3587953268ul /* "permit-access" */
615 #define hash_proxy_info_url              3903079059ul /* "proxy-info-url" */
616 #define hash_single_threaded             4250084780ul /* "single-threaded" */
617 #define hash_socket_timeout              1809001761ul /* "socket-timeout" */
618 #define hash_split_large_cgi_forms        671658948ul /* "split-large-cgi-forms" */
619 #define hash_suppress_blocklists         1948693308ul /* "suppress-blocklists" */
620 #define hash_templdir                      11067889ul /* "templdir" */
621 #define hash_toggle                          447966ul /* "toggle" */
622 #define hash_trust_info_url               430331967ul /* "trust-info-url" */
623 #define hash_trustfile                     56494766ul /* "trustfile" */
624 #define hash_usermanual                  1416668518ul /* "user-manual" */
625 #define hash_activity_animation          1817904738ul /* "activity-animation" */
626 #define hash_close_button_minimizes      3651284693ul /* "close-button-minimizes" */
627 #define hash_hide_console                2048809870ul /* "hide-console" */
628 #define hash_log_buffer_size             2918070425ul /* "log-buffer-size" */
629 #define hash_log_font_name               2866730124ul /* "log-font-name" */
630 #define hash_log_font_size               2866731014ul /* "log-font-size" */
631 #define hash_log_highlight_messages      4032101240ul /* "log-highlight-messages" */
632 #define hash_log_max_lines               2868344173ul /* "log-max-lines" */
633 #define hash_log_messages                2291744899ul /* "log-messages" */
634 #define hash_show_on_task_bar             215410365ul /* "show-on-task-bar" */
635
636
637 static void savearg(char *command, char *argument, struct configuration_spec * config);
638
639 /*********************************************************************
640  *
641  * Function    :  unload_configfile
642  *
643  * Description :  Free the config structure and all components.
644  *
645  * Parameters  :
646  *          1  :  data: struct configuration_spec to unload
647  *
648  * Returns     :  N/A
649  *
650  *********************************************************************/
651 static void unload_configfile (void * data)
652 {
653    struct configuration_spec * config = (struct configuration_spec *)data;
654    struct forward_spec *cur_fwd = config->forward;
655    int i;
656
657 #ifdef FEATURE_ACL
658    struct access_control_list *cur_acl = config->acl;
659
660    while (cur_acl != NULL)
661    {
662       struct access_control_list * next_acl = cur_acl->next;
663       free(cur_acl);
664       cur_acl = next_acl;
665    }
666    config->acl = NULL;
667 #endif /* def FEATURE_ACL */
668
669    while (cur_fwd != NULL)
670    {
671       struct forward_spec * next_fwd = cur_fwd->next;
672       free_url_spec(cur_fwd->url);
673
674       freez(cur_fwd->gateway_host);
675       freez(cur_fwd->forward_host);
676       free(cur_fwd);
677       cur_fwd = next_fwd;
678    }
679    config->forward = NULL;
680
681    freez(config->confdir);
682    freez(config->logdir);
683    freez(config->templdir);
684    freez(config->hostname);
685
686    freez(config->haddr);
687    freez(config->logfile);
688
689    for (i = 0; i < MAX_AF_FILES; i++)
690    {
691       freez(config->actions_file_short[i]);
692       freez(config->actions_file[i]);
693       freez(config->re_filterfile_short[i]);
694       freez(config->re_filterfile[i]);
695    }
696
697    freez(config->admin_address);
698    freez(config->proxy_info_url);
699    freez(config->proxy_args);
700    freez(config->usermanual);
701
702 #ifdef FEATURE_TRUST
703    freez(config->trustfile);
704    list_remove_all(config->trust_info);
705 #endif /* def FEATURE_TRUST */
706
707    for (i = 0; i < MAX_AF_FILES; i++)
708    {
709       freez(config->re_filterfile[i]);
710    }
711
712    freez(config);
713 }
714
715
716 #ifdef FEATURE_GRACEFUL_TERMINATION
717 /*********************************************************************
718  *
719  * Function    :  unload_current_config_file
720  *
721  * Description :  Unloads current config file - reset to state at
722  *                beginning of program.
723  *
724  * Parameters  :  None
725  *
726  * Returns     :  N/A
727  *
728  *********************************************************************/
729 void unload_current_config_file(void)
730 {
731    if (current_configfile)
732    {
733       current_configfile->unloader = unload_configfile;
734       current_configfile = NULL;
735    }
736 }
737 #endif
738
739
740 /*********************************************************************
741  *
742  * Function    :  load_config
743  *
744  * Description :  Load the config file and all parameters.
745  *
746  *                XXX: more than thousand lines long
747  *                and thus in serious need of refactoring.
748  *
749  * Parameters  :  None
750  *
751  * Returns     :  The configuration_spec, or NULL on error.
752  *
753  *********************************************************************/
754 struct configuration_spec * load_config(void)
755 {
756    char buf[BUFFER_SIZE];
757    char *p, *q;
758    FILE *configfp = NULL;
759    struct configuration_spec * config = NULL;
760    struct client_state * fake_csp;
761    struct file_list *fs;
762    unsigned long linenum = 0;
763    int i;
764    char *logfile = NULL;
765 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
766    int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
767 #endif
768
769    if (!check_file_changed(current_configfile, configfile, &fs))
770    {
771       /* No need to load */
772       return ((struct configuration_spec *)current_configfile->f);
773    }
774    if (NULL == fs)
775    {
776       log_error(LOG_LEVEL_FATAL,
777          "can't check configuration file '%s':  %E", configfile);
778       return NULL;
779    }
780
781    if (NULL != current_configfile)
782    {
783       log_error(LOG_LEVEL_INFO, "Reloading configuration file '%s'", configfile);
784    }
785
786 #ifdef FEATURE_TOGGLE
787    global_toggle_state = 1;
788 #endif /* def FEATURE_TOGGLE */
789
790    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
791
792    if (NULL == config)
793    {
794       freez(fs->filename);
795       freez(fs);
796       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
797       return NULL;
798    }
799
800    /*
801     * This is backwards from how it's usually done.
802     * Following the usual pattern, "fs" would be stored in a member
803     * variable in "csp", and then we'd access "config" from "fs->f",
804     * using a cast.  However, "config" is used so often that a
805     * cast each time would be very ugly, and the extra indirection
806     * would waste CPU cycles.  Therefore we store "config" in
807     * "csp->config", and "fs" in "csp->config->config_file_list".
808     */
809    config->config_file_list = fs;
810
811    /*
812     * Set to defaults
813     */
814    config->multi_threaded            = 1;
815    config->hport                     = HADDR_PORT;
816    config->buffer_limit              = 4096 * 1024;
817    config->usermanual                = strdup(USER_MANUAL_URL);
818    config->proxy_args                = strdup("");
819    config->forwarded_connect_retries = 0;
820    config->socket_timeout            = 300; /* XXX: Should be a macro. */
821    config->feature_flags            &= ~RUNTIME_FEATURE_CGI_TOGGLE;
822    config->feature_flags            &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
823    config->feature_flags            &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
824
825    configfp = fopen(configfile, "r");
826    if (NULL == configfp)
827    {
828       log_error(LOG_LEVEL_FATAL,
829          "can't open configuration file '%s':  %E", configfile);
830       /* Never get here - LOG_LEVEL_FATAL causes program exit */
831    }
832
833    while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
834    {
835       char cmd[BUFFER_SIZE];
836       char arg[BUFFER_SIZE];
837       char tmp[BUFFER_SIZE];
838 #ifdef FEATURE_ACL
839       struct access_control_list *cur_acl;
840 #endif /* def FEATURE_ACL */
841       struct forward_spec *cur_fwd;
842       int vec_count;
843       char *vec[3];
844       unsigned long directive_hash;
845
846       strlcpy(tmp, buf, sizeof(tmp));
847
848       /* Copy command (i.e. up to space or tab) into cmd */
849       p = buf;
850       q = cmd;
851       while (*p && (*p != ' ') && (*p != '\t'))
852       {
853          *q++ = *p++;
854       }
855       *q = '\0';
856
857       /* Skip over the whitespace in buf */
858       while (*p && ((*p == ' ') || (*p == '\t')))
859       {
860          p++;
861       }
862
863       /* Copy the argument into arg */
864       strlcpy(arg, p, sizeof(arg));
865
866       /* Should never happen, but check this anyway */
867       if (*cmd == '\0')
868       {
869          continue;
870       }
871
872       /* Make sure the command field is lower case */
873       for (p = cmd; *p; p++)
874       {
875          if (ijb_isupper(*p))
876          {
877             *p = (char)ijb_tolower(*p);
878          }
879       }
880
881       directive_hash = hash_string(cmd);
882       switch (directive_hash)
883       {
884 /* *************************************************************************
885  * actionsfile actions-file-name
886  * In confdir by default
887  * *************************************************************************/
888          case hash_actions_file :
889             i = 0;
890             while ((i < MAX_AF_FILES) && (NULL != config->actions_file[i]))
891             {
892                i++;
893             }
894
895             if (i >= MAX_AF_FILES)
896             {
897                log_error(LOG_LEVEL_FATAL, "Too many 'actionsfile' directives in config file - limit is %d.\n"
898                   "(You can increase this limit by changing MAX_AF_FILES in project.h and recompiling).",
899                   MAX_AF_FILES);
900             }
901             config->actions_file_short[i] = strdup(arg);
902             config->actions_file[i] = make_path(config->confdir, arg);
903
904             break;
905 /* *************************************************************************
906  * accept-intercepted-requests
907  * *************************************************************************/
908          case hash_accept_intercepted_requests:
909             if ((*arg != '\0') && (0 != atoi(arg)))
910             {
911                config->feature_flags |= RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
912             }
913             else
914             {
915                config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
916             }
917             break;
918
919 /* *************************************************************************
920  * admin-address email-address
921  * *************************************************************************/
922          case hash_admin_address :
923             freez(config->admin_address);
924             config->admin_address = strdup(arg);
925             break;
926
927 /* *************************************************************************
928  * allow-cgi-request-crunching
929  * *************************************************************************/
930          case hash_allow_cgi_request_crunching:
931             if ((*arg != '\0') && (0 != atoi(arg)))
932             {
933                config->feature_flags |= RUNTIME_FEATURE_CGI_CRUNCHING;
934             }
935             else
936             {
937                config->feature_flags &= ~RUNTIME_FEATURE_CGI_CRUNCHING;
938             }
939             break;
940
941 /* *************************************************************************
942  * buffer-limit n
943  * *************************************************************************/
944          case hash_buffer_limit :
945             config->buffer_limit = (size_t)(1024 * atoi(arg));
946             break;
947
948 /* *************************************************************************
949  * confdir directory-name
950  * *************************************************************************/
951          case hash_confdir :
952             freez(config->confdir);
953             config->confdir = make_path( NULL, arg);
954             break;
955
956 /* *************************************************************************
957  * debug n
958  * Specifies debug level, multiple values are ORed together.
959  * *************************************************************************/
960          case hash_debug :
961             config->debug |= atoi(arg);
962             break;
963
964 /* *************************************************************************
965  * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
966  * *************************************************************************/
967 #ifdef FEATURE_ACL
968          case hash_deny_access:
969             strlcpy(tmp, arg, sizeof(tmp));
970             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
971
972             if ((vec_count != 1) && (vec_count != 2))
973             {
974                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
975                      "deny-access directive in configuration file.");
976                string_append(&config->proxy_args,
977                   "<br>\nWARNING: Wrong number of parameters for "
978                   "deny-access directive in configuration file.<br><br>\n");
979                break;
980             }
981
982             /* allocate a new node */
983             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
984
985             if (cur_acl == NULL)
986             {
987                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
988                /* Never get here - LOG_LEVEL_FATAL causes program exit */
989                break;
990             }
991             cur_acl->action = ACL_DENY;
992
993             if (acl_addr(vec[0], cur_acl->src) < 0)
994             {
995                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
996                   "for deny-access directive in configuration file: \"%s\"", vec[0]);
997                string_append(&config->proxy_args,
998                   "<br>\nWARNING: Invalid source address, port or netmask "
999                   "for deny-access directive in configuration file: \"");
1000                string_append(&config->proxy_args,
1001                   vec[0]);
1002                string_append(&config->proxy_args,
1003                   "\"<br><br>\n");
1004                freez(cur_acl);
1005                break;
1006             }
1007             if (vec_count == 2)
1008             {
1009                if (acl_addr(vec[1], cur_acl->dst) < 0)
1010                {
1011                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1012                      "for deny-access directive in configuration file: \"%s\"", vec[1]);
1013                   string_append(&config->proxy_args,
1014                      "<br>\nWARNING: Invalid destination address, port or netmask "
1015                      "for deny-access directive in configuration file: \"");
1016                   string_append(&config->proxy_args,
1017                      vec[1]);
1018                   string_append(&config->proxy_args,
1019                      "\"<br><br>\n");
1020                   freez(cur_acl);
1021                   break;
1022                }
1023             }
1024
1025             /*
1026              * Add it to the list.  Note we reverse the list to get the
1027              * behaviour the user expects.  With both the ACL and
1028              * actions file, the last match wins.  However, the internal
1029              * implementations are different:  The actions file is stored
1030              * in the same order as the file, and scanned completely.
1031              * With the ACL, we reverse the order as we load it, then
1032              * when we scan it we stop as soon as we get a match.
1033              */
1034             cur_acl->next  = config->acl;
1035             config->acl = cur_acl;
1036
1037             break;
1038 #endif /* def FEATURE_ACL */
1039
1040 /* *************************************************************************
1041  * enable-edit-actions 0|1
1042  * *************************************************************************/
1043 #ifdef FEATURE_CGI_EDIT_ACTIONS
1044          case hash_enable_edit_actions:
1045             if ((*arg != '\0') && (0 != atoi(arg)))
1046             {
1047                config->feature_flags |= RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1048             }
1049             else
1050             {
1051                config->feature_flags &= ~RUNTIME_FEATURE_CGI_EDIT_ACTIONS;
1052             }
1053             break;
1054 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1055
1056 /* *************************************************************************
1057  * enable-remote-toggle 0|1
1058  * *************************************************************************/
1059 #ifdef FEATURE_TOGGLE
1060          case hash_enable_remote_toggle:
1061             if ((*arg != '\0') && (0 != atoi(arg)))
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 ((*arg != '\0') && (0 != atoi(arg)))
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 ((*arg != '\0') && (0 != atoi(arg)))
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(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), 1, 1);
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(sizeof(*cur_fwd));
1146             if (cur_fwd == NULL)
1147             {
1148                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1149                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1150                break;
1151             }
1152
1153             cur_fwd->type = SOCKS_NONE;
1154
1155             /* Save the URL pattern */
1156             if (create_url_spec(cur_fwd->url, vec[0]))
1157             {
1158                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward "
1159                      "directive in configuration file.");
1160                string_append(&config->proxy_args,
1161                   "<br>\nWARNING: Bad URL specifier for "
1162                   "forward directive in configuration file.");
1163                break;
1164             }
1165
1166             /* Parse the parent HTTP proxy host:port */
1167             p = vec[1];
1168
1169             if (strcmp(p, ".") != 0)
1170             {
1171                cur_fwd->forward_host = strdup(p);
1172
1173                if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1174                {
1175                   *p++ = '\0';
1176                   cur_fwd->forward_port = atoi(p);
1177                }
1178
1179                if (cur_fwd->forward_port <= 0)
1180                {
1181                   cur_fwd->forward_port = 8000;
1182                }
1183             }
1184
1185             /* Add to list. */
1186             cur_fwd->next = config->forward;
1187             config->forward = cur_fwd;
1188
1189             break;
1190
1191 /* *************************************************************************
1192  * forward-socks4 url-pattern socks-proxy[:port] (.|http-proxy[:port])
1193  * *************************************************************************/
1194          case hash_forward_socks4:
1195             strlcpy(tmp, arg, sizeof(tmp));
1196             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1197
1198             if (vec_count != 3)
1199             {
1200                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1201                      "forward-socks4 directive in configuration file.");
1202                string_append(&config->proxy_args,
1203                   "<br>\nWARNING: Wrong number of parameters for "
1204                   "forward-socks4 directive in configuration file.");
1205                break;
1206             }
1207
1208             /* allocate a new node */
1209             cur_fwd = zalloc(sizeof(*cur_fwd));
1210             if (cur_fwd == NULL)
1211             {
1212                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1213                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1214                break;
1215             }
1216
1217             cur_fwd->type = SOCKS_4;
1218
1219             /* Save the URL pattern */
1220             if (create_url_spec(cur_fwd->url, vec[0]))
1221             {
1222                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 "
1223                      "directive in configuration file.");
1224                string_append(&config->proxy_args,
1225                   "<br>\nWARNING: Bad URL specifier for "
1226                   "forward-socks4 directive in configuration file.");
1227                break;
1228             }
1229
1230             /* Parse the SOCKS proxy host[:port] */
1231             p = vec[1];
1232
1233             if (strcmp(p, ".") != 0)
1234             {
1235                cur_fwd->gateway_host = strdup(p);
1236
1237                if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1238                {
1239                   *p++ = '\0';
1240                   cur_fwd->gateway_port = atoi(p);
1241                }
1242                if (cur_fwd->gateway_port <= 0)
1243                {
1244                   cur_fwd->gateway_port = 1080;
1245                }
1246             }
1247
1248             /* Parse the parent HTTP proxy host[:port] */
1249             p = vec[2];
1250
1251             if (strcmp(p, ".") != 0)
1252             {
1253                cur_fwd->forward_host = strdup(p);
1254
1255                if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1256                {
1257                   *p++ = '\0';
1258                   cur_fwd->forward_port = atoi(p);
1259                }
1260
1261                if (cur_fwd->forward_port <= 0)
1262                {
1263                   cur_fwd->forward_port = 8000;
1264                }
1265             }
1266
1267             /* Add to list. */
1268             cur_fwd->next = config->forward;
1269             config->forward = cur_fwd;
1270
1271             break;
1272
1273 /* *************************************************************************
1274  * forward-socks4a url-pattern socks-proxy[:port] (.|http-proxy[:port])
1275  * *************************************************************************/
1276          case hash_forward_socks4a:
1277          case hash_forward_socks5:
1278             strlcpy(tmp, arg, sizeof(tmp));
1279             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1280
1281             if (vec_count != 3)
1282             {
1283                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1284                      "forward-socks4a directive in configuration file.");
1285                string_append(&config->proxy_args,
1286                   "<br>\nWARNING: Wrong number of parameters for "
1287                   "forward-socks4a directive in configuration file.");
1288                break;
1289             }
1290
1291             /* allocate a new node */
1292             cur_fwd = zalloc(sizeof(*cur_fwd));
1293             if (cur_fwd == NULL)
1294             {
1295                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1296                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1297                break;
1298             }
1299
1300             if (directive_hash == hash_forward_socks4a)
1301             {
1302                cur_fwd->type = SOCKS_4A;
1303             }
1304             else
1305             {
1306                cur_fwd->type = SOCKS_5;
1307             }
1308
1309             /* Save the URL pattern */
1310             if (create_url_spec(cur_fwd->url, vec[0]))
1311             {
1312                log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a "
1313                      "directive in configuration file.");
1314                string_append(&config->proxy_args,
1315                   "<br>\nWARNING: Bad URL specifier for "
1316                   "forward-socks4a directive in configuration file.");
1317                break;
1318             }
1319
1320             /* Parse the SOCKS proxy host[:port] */
1321             p = vec[1];
1322
1323             cur_fwd->gateway_host = strdup(p);
1324
1325             if (NULL != (p = strchr(cur_fwd->gateway_host, ':')))
1326             {
1327                *p++ = '\0';
1328                cur_fwd->gateway_port = atoi(p);
1329             }
1330             if (cur_fwd->gateway_port <= 0)
1331             {
1332                cur_fwd->gateway_port = 1080;
1333             }
1334
1335             /* Parse the parent HTTP proxy host[:port] */
1336             p = vec[2];
1337
1338             if (strcmp(p, ".") != 0)
1339             {
1340                cur_fwd->forward_host = strdup(p);
1341
1342                if (NULL != (p = strchr(cur_fwd->forward_host, ':')))
1343                {
1344                   *p++ = '\0';
1345                   cur_fwd->forward_port = atoi(p);
1346                }
1347
1348                if (cur_fwd->forward_port <= 0)
1349                {
1350                   cur_fwd->forward_port = 8000;
1351                }
1352             }
1353
1354             /* Add to list. */
1355             cur_fwd->next = config->forward;
1356             config->forward = cur_fwd;
1357
1358             break;
1359
1360 /* *************************************************************************
1361  * forwarded-connect-retries n
1362  * *************************************************************************/
1363          case hash_forwarded_connect_retries :
1364             config->forwarded_connect_retries = atoi(arg);
1365             break;
1366
1367 /* *************************************************************************
1368  * hostname hostname-to-show-on-cgi-pages
1369  * *************************************************************************/
1370          case hash_hostname :
1371             freez(config->hostname);
1372             config->hostname = strdup(arg);
1373             if (NULL == config->hostname)
1374             {
1375                log_error(LOG_LEVEL_FATAL, "Out of memory saving hostname.");
1376             }
1377             break;
1378
1379 /* *************************************************************************
1380  * keep-alive-timeout timeout
1381  * *************************************************************************/
1382 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1383          case hash_keep_alive_timeout :
1384             if (*arg != '\0')
1385             {
1386                int timeout = atoi(arg);
1387                if (0 <= timeout)
1388                {
1389                   config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1390                   keep_alive_timeout = timeout;
1391                }
1392                else
1393                {
1394                   config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1395                }
1396             }
1397             break;
1398 #endif
1399
1400 /* *************************************************************************
1401  * listen-address [ip][:port]
1402  * *************************************************************************/
1403          case hash_listen_address :
1404             freez(config->haddr);
1405             config->haddr = strdup(arg);
1406             break;
1407
1408 /* *************************************************************************
1409  * logdir directory-name
1410  * *************************************************************************/
1411          case hash_logdir :
1412             freez(config->logdir);
1413             config->logdir = make_path(NULL, arg);
1414             break;
1415
1416 /* *************************************************************************
1417  * logfile log-file-name
1418  * In logdir by default
1419  * *************************************************************************/
1420          case hash_logfile :
1421             if (!no_daemon)
1422             {
1423                logfile = make_path(config->logdir, arg);
1424                if (NULL == logfile)
1425                {
1426                   log_error(LOG_LEVEL_FATAL, "Out of memory while creating logfile path");
1427                }
1428             }
1429             break;
1430
1431 /* *************************************************************************
1432  * permit-access source-ip[/significant-bits] [dest-ip[/significant-bits]]
1433  * *************************************************************************/
1434 #ifdef FEATURE_ACL
1435          case hash_permit_access:
1436             strlcpy(tmp, arg, sizeof(tmp));
1437             vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
1438
1439             if ((vec_count != 1) && (vec_count != 2))
1440             {
1441                log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for "
1442                      "permit-access directive in configuration file.");
1443                string_append(&config->proxy_args,
1444                   "<br>\nWARNING: Wrong number of parameters for "
1445                   "permit-access directive in configuration file.<br><br>\n");
1446
1447                break;
1448             }
1449
1450             /* allocate a new node */
1451             cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
1452
1453             if (cur_acl == NULL)
1454             {
1455                log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
1456                /* Never get here - LOG_LEVEL_FATAL causes program exit */
1457                break;
1458             }
1459             cur_acl->action = ACL_PERMIT;
1460
1461             if (acl_addr(vec[0], cur_acl->src) < 0)
1462             {
1463                log_error(LOG_LEVEL_ERROR, "Invalid source address, port or netmask "
1464                   "for permit-access directive in configuration file: \"%s\"", vec[0]);
1465                string_append(&config->proxy_args,
1466                   "<br>\nWARNING: Invalid source address, port or netmask for "
1467                   "permit-access directive in configuration file: \"");
1468                string_append(&config->proxy_args,
1469                   vec[0]);
1470                string_append(&config->proxy_args,
1471                   "\"<br><br>\n");
1472                freez(cur_acl);
1473                break;
1474             }
1475             if (vec_count == 2)
1476             {
1477                if (acl_addr(vec[1], cur_acl->dst) < 0)
1478                {
1479                   log_error(LOG_LEVEL_ERROR, "Invalid destination address, port or netmask "
1480                      "for permit-access directive in configuration file: \"%s\"", vec[1]);
1481                   string_append(&config->proxy_args,
1482                      "<br>\nWARNING: Invalid destination address, port or netmask for "
1483                      "permit-access directive in configuration file: \"");
1484                   string_append(&config->proxy_args,
1485                      vec[1]);
1486                   string_append(&config->proxy_args,
1487                      "\"<br><br>\n");
1488                   freez(cur_acl);
1489                   break;
1490                }
1491             }
1492
1493             /*
1494              * Add it to the list.  Note we reverse the list to get the
1495              * behaviour the user expects.  With both the ACL and
1496              * actions file, the last match wins.  However, the internal
1497              * implementations are different:  The actions file is stored
1498              * in the same order as the file, and scanned completely.
1499              * With the ACL, we reverse the order as we load it, then
1500              * when we scan it we stop as soon as we get a match.
1501              */
1502             cur_acl->next  = config->acl;
1503             config->acl = cur_acl;
1504
1505             break;
1506 #endif /* def FEATURE_ACL */
1507
1508 /* *************************************************************************
1509  * proxy-info-url url
1510  * *************************************************************************/
1511          case hash_proxy_info_url :
1512             freez(config->proxy_info_url);
1513             config->proxy_info_url = strdup(arg);
1514             break;
1515
1516 /* *************************************************************************
1517  * single-threaded
1518  * *************************************************************************/
1519          case hash_single_threaded :
1520             config->multi_threaded = 0;
1521             break;
1522
1523 /* *************************************************************************
1524  * socket-timeout numer_of_seconds
1525  * *************************************************************************/
1526          case hash_socket_timeout :
1527             if (*arg != '\0')
1528             {
1529                int socket_timeout = atoi(arg);
1530                if (0 < socket_timeout)
1531                {
1532                   config->socket_timeout = socket_timeout;
1533                }
1534                else
1535                {
1536                   log_error(LOG_LEVEL_FATAL,
1537                      "Invalid socket-timeout: '%s'", arg);
1538                }
1539             }
1540             break;
1541
1542 /* *************************************************************************
1543  * split-large-cgi-forms
1544  * *************************************************************************/
1545          case hash_split_large_cgi_forms :
1546             if ((*arg != '\0') && (0 != atoi(arg)))
1547             {
1548                config->feature_flags |= RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1549             }
1550             else
1551             {
1552                config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
1553             }
1554             break;
1555
1556 /* *************************************************************************
1557  * templdir directory-name
1558  * *************************************************************************/
1559          case hash_templdir :
1560             freez(config->templdir);
1561             config->templdir = make_path(NULL, arg);
1562             break;
1563
1564 /* *************************************************************************
1565  * toggle (0|1)
1566  * *************************************************************************/
1567 #ifdef FEATURE_TOGGLE
1568          case hash_toggle :
1569             global_toggle_state = atoi(arg);
1570             break;
1571 #endif /* def FEATURE_TOGGLE */
1572
1573 /* *************************************************************************
1574  * trust-info-url url
1575  * *************************************************************************/
1576 #ifdef FEATURE_TRUST
1577          case hash_trust_info_url :
1578             enlist(config->trust_info, arg);
1579             break;
1580 #endif /* def FEATURE_TRUST */
1581
1582 /* *************************************************************************
1583  * trustfile filename
1584  * (In confdir by default.)
1585  * *************************************************************************/
1586 #ifdef FEATURE_TRUST
1587          case hash_trustfile :
1588             freez(config->trustfile);
1589             config->trustfile = make_path(config->confdir, arg);
1590             break;
1591 #endif /* def FEATURE_TRUST */
1592
1593 /* *************************************************************************
1594  * usermanual url
1595  * *************************************************************************/
1596          case hash_usermanual :
1597             /*
1598              * XXX: If this isn't the first config directive, the
1599              * show-status page links to the website documentation
1600              * for the directives that were already parsed. Lame.
1601              */
1602             freez(config->usermanual);
1603             config->usermanual = strdup(arg);
1604             break;
1605
1606 /* *************************************************************************
1607  * Win32 Console options:
1608  * *************************************************************************/
1609
1610 /* *************************************************************************
1611  * hide-console
1612  * *************************************************************************/
1613 #ifdef _WIN_CONSOLE
1614          case hash_hide_console :
1615             hideConsole = 1;
1616             break;
1617 #endif /*def _WIN_CONSOLE*/
1618
1619
1620 /* *************************************************************************
1621  * Win32 GUI options:
1622  * *************************************************************************/
1623
1624 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
1625 /* *************************************************************************
1626  * activity-animation (0|1)
1627  * *************************************************************************/
1628          case hash_activity_animation :
1629             g_bShowActivityAnimation = atoi(arg);
1630             break;
1631
1632 /* *************************************************************************
1633  *  close-button-minimizes (0|1)
1634  * *************************************************************************/
1635          case hash_close_button_minimizes :
1636             g_bCloseHidesWindow = atoi(arg);
1637             break;
1638
1639 /* *************************************************************************
1640  * log-buffer-size (0|1)
1641  * *************************************************************************/
1642          case hash_log_buffer_size :
1643             g_bLimitBufferSize = atoi(arg);
1644             break;
1645
1646 /* *************************************************************************
1647  * log-font-name fontnane
1648  * *************************************************************************/
1649          case hash_log_font_name :
1650             strcpy( g_szFontFaceName, arg );
1651             break;
1652
1653 /* *************************************************************************
1654  * log-font-size n
1655  * *************************************************************************/
1656          case hash_log_font_size :
1657             g_nFontSize = atoi(arg);
1658             break;
1659
1660 /* *************************************************************************
1661  * log-highlight-messages (0|1)
1662  * *************************************************************************/
1663          case hash_log_highlight_messages :
1664             g_bHighlightMessages = atoi(arg);
1665             break;
1666
1667 /* *************************************************************************
1668  * log-max-lines n
1669  * *************************************************************************/
1670          case hash_log_max_lines :
1671             g_nMaxBufferLines = atoi(arg);
1672             break;
1673
1674 /* *************************************************************************
1675  * log-messages (0|1)
1676  * *************************************************************************/
1677          case hash_log_messages :
1678             g_bLogMessages = atoi(arg);
1679             break;
1680
1681 /* *************************************************************************
1682  * show-on-task-bar (0|1)
1683  * *************************************************************************/
1684          case hash_show_on_task_bar :
1685             g_bShowOnTaskBar = atoi(arg);
1686             break;
1687
1688 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
1689
1690
1691 /* *************************************************************************
1692  * Warnings about unsupported features
1693  * *************************************************************************/
1694 #ifndef FEATURE_ACL
1695          case hash_deny_access:
1696 #endif /* ndef FEATURE_ACL */
1697 #ifndef FEATURE_CGI_EDIT_ACTIONS
1698          case hash_enable_edit_actions:
1699 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
1700 #ifndef FEATURE_TOGGLE
1701          case hash_enable_remote_toggle:
1702 #endif /* ndef FEATURE_TOGGLE */
1703 #ifndef FEATURE_ACL
1704          case hash_permit_access:
1705 #endif /* ndef FEATURE_ACL */
1706 #ifndef FEATURE_TOGGLE
1707          case hash_toggle :
1708 #endif /* ndef FEATURE_TOGGLE */
1709 #ifndef FEATURE_TRUST
1710          case hash_trustfile :
1711          case hash_trust_info_url :
1712 #endif /* ndef FEATURE_TRUST */
1713
1714 #ifndef _WIN_CONSOLE
1715          case hash_hide_console :
1716 #endif /* ndef _WIN_CONSOLE */
1717
1718 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
1719          case hash_activity_animation :
1720          case hash_close_button_minimizes :
1721          case hash_log_buffer_size :
1722          case hash_log_font_name :
1723          case hash_log_font_size :
1724          case hash_log_highlight_messages :
1725          case hash_log_max_lines :
1726          case hash_log_messages :
1727          case hash_show_on_task_bar :
1728 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
1729             /* These warnings are annoying - so hide them. -- Jon */
1730             /* log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); */
1731             break;
1732
1733 /* *************************************************************************/
1734          default :
1735 /* *************************************************************************/
1736             /*
1737              * I decided that I liked this better as a warning than an
1738              * error.  To change back to an error, just change log level
1739              * to LOG_LEVEL_FATAL.
1740              */
1741             log_error(LOG_LEVEL_ERROR, "Ignoring unrecognized directive '%s' (%luul) in line %lu "
1742                   "in configuration file (%s).",  buf, directive_hash, linenum, configfile);
1743             string_append(&config->proxy_args,
1744                " <strong class='warning'>Warning: ignored unrecognized directive above.</strong><br>");
1745             break;
1746
1747 /* *************************************************************************/
1748       } /* end switch( hash_string(cmd) ) */
1749
1750       /* Save the argument for the show-status page. */
1751       savearg(cmd, arg, config);
1752
1753    } /* end while ( read_config_line(...) ) */
1754
1755    fclose(configfp);
1756
1757    set_debug_level(config->debug);
1758
1759    freez(config->logfile);
1760
1761    if (!no_daemon)
1762    {
1763       if (NULL != logfile)
1764       {
1765          config->logfile = logfile;
1766          init_error_log(Argv[0], config->logfile);
1767       }
1768       else
1769       {
1770          disable_logging();
1771       }
1772    }
1773
1774 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
1775    if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
1776    {
1777       if (config->multi_threaded)
1778       {
1779          set_keep_alive_timeout(keep_alive_timeout);
1780       }
1781       else
1782       {
1783          /*
1784           * While we could use keep-alive without multiple threads
1785           * if we didn't bother with enforcing the connection timeout,
1786           * that might make Tor users sad, even though they shouldn't
1787           * enable the single-threaded option anyway.
1788           */
1789          config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE;
1790          log_error(LOG_LEVEL_ERROR,
1791             "Config option single-threaded disables connection keep-alive.");
1792       }
1793    }
1794 #endif
1795
1796    if (NULL == config->proxy_args)
1797    {
1798       log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
1799    }
1800
1801    if (config->actions_file[0])
1802    {
1803       add_loader(load_action_files, config);
1804    }
1805
1806    if (config->re_filterfile[0])
1807    {
1808       add_loader(load_re_filterfiles, config);
1809    }
1810
1811 #ifdef FEATURE_TRUST
1812    if (config->trustfile)
1813    {
1814       add_loader(load_trustfile, config);
1815    }
1816 #endif /* def FEATURE_TRUST */
1817
1818    if ( NULL == config->haddr )
1819    {
1820       config->haddr = strdup( HADDR_DEFAULT );
1821    }
1822
1823    if ( NULL != config->haddr )
1824    {
1825       if (NULL != (p = strchr(config->haddr, ':')))
1826       {
1827          *p++ = '\0';
1828          if (*p)
1829          {
1830             config->hport = atoi(p);
1831          }
1832       }
1833
1834       if (config->hport <= 0)
1835       {
1836          *--p = ':';
1837          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
1838          /* Never get here - LOG_LEVEL_FATAL causes program exit */
1839       }
1840       if (*config->haddr == '\0')
1841       {
1842          /*
1843           * Only the port specified. We stored it in config->hport
1844           * and don't need its text representation anymore.
1845           */
1846          freez(config->haddr);
1847       }
1848    }
1849
1850    /*
1851     * Want to run all the loaders once now.
1852     *
1853     * Need to set up a fake csp, so they can get to the config.
1854     */
1855    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
1856    fake_csp->config = config;
1857
1858    if (run_loader(fake_csp))
1859    {
1860       freez(fake_csp);
1861       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
1862       /* Never get here - LOG_LEVEL_FATAL causes program exit */
1863    }
1864    freez(fake_csp);
1865
1866 /* FIXME: this is a kludge for win32 */
1867 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
1868
1869    g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */
1870    g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */
1871    g_re_filterfile    = config->re_filterfile[0]; /* FIXME Hope this is default.filter */
1872
1873 #ifdef FEATURE_TRUST
1874    g_trustfile        = config->trustfile;
1875 #endif /* def FEATURE_TRUST */
1876
1877
1878 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
1879 /* FIXME: end kludge */
1880
1881
1882    config->need_bind = 1;
1883
1884    if (current_configfile)
1885    {
1886       struct configuration_spec * oldcfg = (struct configuration_spec *)
1887                                            current_configfile->f;
1888       /*
1889        * Check if config->haddr,hport == oldcfg->haddr,hport
1890        *
1891        * The following could be written more compactly as a single,
1892        * (unreadably long) if statement.
1893        */
1894       config->need_bind = 0;
1895       if (config->hport != oldcfg->hport)
1896       {
1897          config->need_bind = 1;
1898       }
1899       else if (config->haddr == NULL)
1900       {
1901          if (oldcfg->haddr != NULL)
1902          {
1903             config->need_bind = 1;
1904          }
1905       }
1906       else if (oldcfg->haddr == NULL)
1907       {
1908          config->need_bind = 1;
1909       }
1910       else if (0 != strcmp(config->haddr, oldcfg->haddr))
1911       {
1912          config->need_bind = 1;
1913       }
1914
1915       current_configfile->unloader = unload_configfile;
1916    }
1917
1918    fs->next = files->next;
1919    files->next = fs;
1920
1921    current_configfile = fs;
1922
1923    return (config);
1924 }
1925
1926
1927 /*********************************************************************
1928  *
1929  * Function    :  savearg
1930  *
1931  * Description :  Called from `load_config'.  It saves each non-empty
1932  *                and non-comment line from config into
1933  *                config->proxy_args.  This is used to create the
1934  *                show-proxy-args page.  On error, frees
1935  *                config->proxy_args and sets it to NULL
1936  *
1937  * Parameters  :
1938  *          1  :  command = config setting that was found
1939  *          2  :  argument = the setting's argument (if any)
1940  *          3  :  config = Configuration to save into.
1941  *
1942  * Returns     :  N/A
1943  *
1944  *********************************************************************/
1945 static void savearg(char *command, char *argument, struct configuration_spec * config)
1946 {
1947    char * buf;
1948    char * s;
1949
1950    assert(command);
1951    assert(argument);
1952
1953    /*
1954     * Add config option name embedded in
1955     * link to its section in the user-manual
1956     */
1957    buf = strdup("\n<a href=\"");
1958    if (!strncmpic(config->usermanual, "file://", 7) ||
1959        !strncmpic(config->usermanual, "http", 4))
1960    {
1961       string_append(&buf, config->usermanual);
1962    }
1963    else
1964    {
1965       string_append(&buf, "http://" CGI_SITE_2_HOST "/user-manual/");
1966    }
1967    string_append(&buf, CONFIG_HELP_PREFIX);
1968    string_join  (&buf, string_toupper(command));
1969    string_append(&buf, "\">");
1970    string_append(&buf, command);
1971    string_append(&buf, "</a> ");
1972
1973    if (NULL == buf)
1974    {
1975       freez(config->proxy_args);
1976       return;
1977    }
1978
1979    if ( (NULL != argument) && ('\0' != *argument) )
1980    {
1981       s = html_encode(argument);
1982       if (NULL == s)
1983       {
1984          freez(buf);
1985          freez(config->proxy_args);
1986          return;
1987       }
1988
1989       if (strncmpic(argument, "http://", 7) == 0)
1990       {
1991          string_append(&buf, "<a href=\"");
1992          string_append(&buf, s);
1993          string_append(&buf, "\">");
1994          string_join  (&buf, s);
1995          string_append(&buf, "</a>");
1996       }
1997       else
1998       {
1999          string_join  (&buf, s);
2000       }
2001    }
2002
2003    string_append(&buf, "<br>");
2004    string_join(&config->proxy_args, buf);
2005 }
2006
2007
2008 /*
2009   Local Variables:
2010   tab-width: 3
2011   end:
2012 */