Now uses _snprintf() in place of snprintf() under Win32.
[privoxy.git] / loadcfg.c
1 const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.11 2001/06/04 18:31:58 swa 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 the SourceForge
12  *                IJBSWA team.  http://ijbswa.sourceforge.net
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.11  2001/06/04 18:31:58  swa
39  *    files are now prefixed with either `confdir' or `logdir'.
40  *    `make redhat-dist' replaces both entries confdir and logdir
41  *    with redhat values
42  *
43  *    Revision 1.10  2001/06/03 19:11:54  oes
44  *    introduced confdir option
45  *
46  *    Revision 1.10  2001/06/03 11:03:48  oes
47  *    Makefile/in
48  *
49  *    introduced cgi.c
50  *
51  *    actions.c:
52  *
53  *    adapted to new enlist_unique arg format
54  *
55  *    conf loadcfg.c
56  *
57  *    introduced confdir option
58  *
59  *    filters.c filtrers.h
60  *
61  *     extracted-CGI relevant stuff
62  *
63  *    jbsockets.c
64  *
65  *     filled comment
66  *
67  *    jcc.c
68  *
69  *     support for new cgi mechansim
70  *
71  *    list.c list.h
72  *
73  *    functions for new list type: "map"
74  *    extended enlist_unique
75  *
76  *    miscutil.c .h
77  *    introduced bindup()
78  *
79  *    parsers.c parsers.h
80  *
81  *    deleted const struct interceptors
82  *
83  *    pcrs.c
84  *    added FIXME
85  *
86  *    project.h
87  *
88  *    added struct map
89  *    added struct http_response
90  *    changes struct interceptors to struct cgi_dispatcher
91  *    moved HTML stuff to cgi.h
92  *
93  *    re_filterfile:
94  *
95  *    changed
96  *
97  *    showargs.c
98  *    NO TIME LEFT
99  *
100  *    Revision 1.9  2001/06/01 20:06:24  jongfoster
101  *    Removed support for "tinygif" option - moved to actions file.
102  *
103  *    Revision 1.8  2001/05/31 21:27:13  jongfoster
104  *    Removed many options from the config file and into the
105  *    "actions" file: add_forwarded, suppress_vanilla_wafer,
106  *    wafer, add_header, user_agent, referer, from
107  *    Also globally replaced "permission" with "action".
108  *
109  *    Revision 1.7  2001/05/29 09:50:24  jongfoster
110  *    Unified blocklist/imagelist/permissionslist.
111  *    File format is still under discussion, but the internal changes
112  *    are (mostly) done.
113  *
114  *    Also modified interceptor behaviour:
115  *    - We now intercept all URLs beginning with one of the following
116  *      prefixes (and *only* these prefixes):
117  *        * http://i.j.b/
118  *        * http://ijbswa.sf.net/config/
119  *        * http://ijbswa.sourceforge.net/config/
120  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
121  *    - Internal changes so that intercepted and fast redirect pages
122  *      are not replaced with an image.
123  *    - Interceptors now have the option to send a binary page direct
124  *      to the client. (i.e. ijb-send-banner uses this)
125  *    - Implemented show-url-info interceptor.  (Which is why I needed
126  *      the above interceptors changes - a typical URL is
127  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
128  *      The previous mechanism would not have intercepted that, and
129  *      if it had been intercepted then it then it would have replaced
130  *      it with an image.)
131  *
132  *    Revision 1.6  2001/05/26 00:28:36  jongfoster
133  *    Automatic reloading of config file.
134  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
135  *    Most of the global variables have been moved to a new
136  *    struct configuration_spec, accessed through csp->config->globalname
137  *    Most of the globals remaining are used by the Win32 GUI.
138  *
139  *    Revision 1.5  2001/05/25 22:34:30  jongfoster
140  *    Hard tabs->Spaces
141  *
142  *    Revision 1.4  2001/05/22 18:46:04  oes
143  *
144  *    - Enabled filtering banners by size rather than URL
145  *      by adding patterns that replace all standard banner
146  *      sizes with the "Junkbuster" gif to the re_filterfile
147  *
148  *    - Enabled filtering WebBugs by providing a pattern
149  *      which kills all 1x1 images
150  *
151  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
152  *      which is selected by the (nonstandard and therefore
153  *      capital) letter 'U' in the option string.
154  *      It causes the quantifiers to be ungreedy by default.
155  *      Appending a ? turns back to greedy (!).
156  *
157  *    - Added a new interceptor ijb-send-banner, which
158  *      sends back the "Junkbuster" gif. Without imagelist or
159  *      MSIE detection support, or if tinygif = 1, or the
160  *      URL isn't recognized as an imageurl, a lame HTML
161  *      explanation is sent instead.
162  *
163  *    - Added new feature, which permits blocking remote
164  *      script redirects and firing back a local redirect
165  *      to the browser.
166  *      The feature is conditionally compiled, i.e. it
167  *      can be disabled with --disable-fast-redirects,
168  *      plus it must be activated by a "fast-redirects"
169  *      line in the config file, has its own log level
170  *      and of course wants to be displayed by show-proxy-args
171  *      Note: Boy, all the #ifdefs in 1001 locations and
172  *      all the fumbling with configure.in and acconfig.h
173  *      were *way* more work than the feature itself :-(
174  *
175  *    - Because a generic redirect template was needed for
176  *      this, tinygif = 3 now uses the same.
177  *
178  *    - Moved GIFs, and other static HTTP response templates
179  *      to project.h
180  *
181  *    - Some minor fixes
182  *
183  *    - Removed some >400 CRs again (Jon, you really worked
184  *      a lot! ;-)
185  *
186  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
187  *    Version 2.9.4 checkin.
188  *    - Merged popupfile and cookiefile, and added control over PCRS
189  *      filtering, in new "permissionsfile".
190  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
191  *      file error you now get a message box (in the Win32 GUI) rather
192  *      than the program exiting with no explanation.
193  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
194  *      skipping.
195  *    - Removed tabs from "config"
196  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
197  *    - Bumped up version number.
198  *
199  *    Revision 1.2  2001/05/17 23:01:01  oes
200  *     - Cleaned CRLF's from the sources and related files
201  *
202  *    Revision 1.1.1.1  2001/05/15 13:58:58  oes
203  *    Initial import of version 2.9.3 source tree
204  *
205  *
206  *********************************************************************/
207 \f
208
209 #include "config.h"
210
211 #include <stdio.h>
212 #include <sys/types.h>
213 #include <stdlib.h>
214 #include <string.h>
215 #include <signal.h>
216 #include <fcntl.h>
217 #include <errno.h>
218 #include <ctype.h>
219
220 #ifdef _WIN32
221
222 # include <sys/timeb.h>
223 # include <windows.h>
224 # include <io.h>
225 # include <process.h>
226 # ifdef TOGGLE
227 #  include <time.h>
228 # endif /* def TOGGLE */
229
230 # include "win32.h"
231 # ifndef _WIN_CONSOLE
232 #  include "w32log.h"
233 # endif /* ndef _WIN_CONSOLE */
234
235 /* VC++ has "_snprintf", not "snprintf" */
236 #define snprintf _snprintf
237
238 #else /* ifndef _WIN32 */
239
240 # include <unistd.h>
241 # include <sys/time.h>
242 # include <sys/wait.h>
243 # include <sys/stat.h>
244 # include <signal.h>
245
246 #endif
247
248 #include "loadcfg.h"
249 #include "list.h"
250 #include "jcc.h"
251 #include "filters.h"
252 #include "loaders.h"
253 #include "showargs.h"
254 #include "parsers.h"
255 #include "killpopup.h"
256 #include "miscutil.h"
257 #include "errlog.h"
258 #include "jbsockets.h"
259 #include "gateway.h"
260
261 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
262
263 /*
264  * Fix a problem with Solaris.  There should be no effect on other
265  * platforms.
266  * Solaris's isspace() is a macro which uses it's argument directly
267  * as an array index.  Therefore we need to make sure that high-bit
268  * characters generate +ve values, and ideally we also want to make
269  * the argument match the declared parameter type of "int".
270  */
271 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
272 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
273
274 #ifdef TOGGLE
275 /* by haroon - indicates if ijb is enabled */
276 int g_bToggleIJB        = 1;   /* JunkBusters is enabled by default. */
277 #endif
278
279 /* The filename of the configfile */
280 const char *configfile  = NULL;
281
282 /*
283  * The load_config function is now going to call `init_proxy_args',
284  * so it will need argc and argv.  So we need to have these
285  * globally available.
286  */
287 int Argc = 0;
288 const char **Argv = NULL;
289
290 static struct file_list *current_configfile = NULL;
291
292
293 /*
294  * This takes the "cryptic" hash of each keyword and aliases them to
295  * something a little more readable.  This also makes changing the
296  * hash values easier if they should change or the hash algorthm changes.
297  * Use the included "hash" program to find out what the hash will be
298  * for any string supplied on the command line.  (Or just put it in the
299  * config file and read the number from the error message in the log).
300  */
301
302
303 #define hash_aclfile                      1908516ul
304 #define hash_actions_file              3825730796ul /* FIXME "permissionsfile" */
305 #define hash_debug                          78263ul
306 #define hash_confdir                      1978389lu
307 #define hash_logdir                        422889lu
308 #define hash_forwardfile               1268669141ul
309 #define hash_jarfile                      2046641ul
310 #define hash_listen_address            1255650842ul
311 #define hash_logfile                      2114766ul
312 #define hash_re_filterfile             3877522444ul
313 #define hash_single_threaded           4250084780ul
314 #define hash_suppress_blocklists       1948693308ul
315 #define hash_toggle                        447966ul
316 #define hash_trust_info_url             449869467ul
317 #define hash_trustfile                   56494766ul
318
319 #define hash_hide_console              2048809870ul
320
321 #define hash_activity_animation        1817904738ul
322 #define hash_close_button_minimizes    3651284693ul
323 #define hash_log_buffer_size           2918070425ul
324 #define hash_log_font_name             2866730124ul
325 #define hash_log_font_size             2866731014ul
326 #define hash_log_highlight_messages    4032101240ul
327 #define hash_log_max_lines             2868344173ul
328 #define hash_log_messages              2291744899ul
329 #define hash_show_on_task_bar           215410365ul
330
331
332
333 /*********************************************************************
334  *
335  * Function    :  unload_configfile
336  *
337  * Description :  Free the config structure and all components.
338  *
339  * Parameters  :
340  *          1  :  data: struct configuration_spec to unload
341  *
342  * Returns     :  N/A
343  *
344  *********************************************************************/
345 void unload_configfile (void * data)
346 {
347    struct configuration_spec * config = (struct configuration_spec *)data;
348
349 #ifdef JAR_FILES
350    if ( NULL != config->jar )
351    {
352       fclose( config->jar );
353       config->jar = NULL;
354    }
355 #endif /* def JAR_FILES */
356
357    freez((char *)config->haddr);
358    freez((char *)config->logfile);
359
360    freez((char *)config->actions_file);
361    freez((char *)config->forwardfile);
362
363 #ifdef ACL_FILES
364    freez((char *)config->aclfile);
365 #endif /* def ACL_FILES */
366
367 #ifdef JAR_FILES
368    freez((char *)config->jarfile);
369 #endif /* def JAR_FILES */
370
371 #ifndef SPLIT_PROXY_ARGS
372    freez((char *)config->suppress_message);
373 #endif /* ndef SPLIT_PROXY_ARGS */
374
375 #ifdef PCRS
376    freez((char *)config->re_filterfile);
377 #endif /* def PCRS */
378
379 }
380
381
382 /*********************************************************************
383  *
384  * Function    :  load_config
385  *
386  * Description :  Load the config file and all parameters.
387  *
388  * Parameters  :
389  *          1  :  csp = Client state (the config member will be 
390  *                filled in by this function).
391  *
392  * Returns     :  0 => Ok, everything else is an error.
393  *
394  *********************************************************************/
395 struct configuration_spec * load_config(void)
396 {
397    char buf[BUFSIZ];
398    char *p, *q;
399    FILE *configfp = NULL;
400    struct configuration_spec * config = NULL;
401    struct client_state * fake_csp;
402
403    struct file_list *fs;
404
405    if (!check_file_changed(current_configfile, configfile, &fs))
406    {
407       /* No need to load */
408       return ((struct configuration_spec *)current_configfile->f);
409    }
410    if (!fs)
411    {
412       log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s':  %E",
413                 configfile);
414    }
415
416    log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile);
417
418 #ifdef TOGGLE
419    g_bToggleIJB      = 1;
420 #endif
421
422    fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
423
424    if (config==NULL)
425    {
426       freez(fs->filename);
427       freez(fs);
428       log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
429       /* Never get here - LOG_LEVEL_FATAL causes program exit */
430    }
431
432    /*
433     * This is backwards from how it's usually done.
434     * Following the usual pattern, "fs" would be stored in a member 
435     * variable in "csp", and then we'd access "config" from "fs->f",
436     * using a cast.  However, "config" is used so often that a 
437     * cast each time would be very ugly, and the extra indirection
438     * would waste CPU cycles.  Therefore we store "config" in
439     * "csp->config", and "fs" in "csp->config->config_file_list".
440     */
441    config->config_file_list = fs;
442
443    init_proxy_args(Argc, Argv, config);
444
445    /*
446     * Set to defaults
447     */
448
449    config->multi_threaded    = 1;
450    config->hport             = HADDR_PORT;
451
452    if ((configfp = fopen(configfile, "r")) == NULL)
453    {
454       log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s':  %E",
455               configfile);
456       /* Never get here - LOG_LEVEL_FATAL causes program exit */
457    }
458
459    while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL)
460    {
461       char cmd[BUFSIZ];
462       char arg[BUFSIZ];
463       char tmp[BUFSIZ];
464
465       char arg2[BUFSIZ];
466
467       strcpy(tmp, buf);
468
469       /* Copy command (i.e. up to space or tab) into cmd */
470       p = buf;
471       q = cmd;
472       while (*p && (*p != ' ') && (*p != '\t'))
473       {
474          *q++ = *p++;
475       }
476       *q = '\0';
477
478       /* Skip over the whitespace in buf */
479       while (*p && ((*p == ' ') || (*p == '\t')))
480       {
481          p++;
482       }
483
484       /* Copy the argument into arg */
485       strcpy(arg, p);
486
487       /* Should never happen, but check this anyway */
488       if (*cmd == '\0')
489       {
490          continue;
491       }
492
493       /* Make sure the command field is lower case */
494       for (p=cmd; *p; p++)
495       {
496          if (ijb_isupper(*p))
497          {
498             *p = ijb_tolower(*p);
499          }
500       }
501
502       /* Save the argument for show-proxy-args */
503       savearg(cmd, arg, config);
504
505
506       switch( hash_string( cmd ) )
507       {
508 #ifdef TRUST_FILES
509          case hash_trustfile :
510             freez((char *)config->trustfile);
511                                 snprintf(arg2, BUFSIZ, "%s/%s", config->confdir, arg);
512             config->trustfile = strdup(arg2);
513             continue;
514
515          case hash_trust_info_url :
516             enlist(config->trust_info, arg);
517             continue;
518 #endif /* def TRUST_FILES */
519
520          case hash_debug :
521             config->debug |= atoi(arg);
522             continue;
523
524          case hash_confdir :
525             config->confdir = strdup(arg);
526             continue;            
527
528          case hash_logdir :
529             config->logdir = strdup(arg);
530             continue;            
531
532          case hash_single_threaded :
533             config->multi_threaded = 0;
534             continue;
535
536          case hash_actions_file :
537             freez((char *)config->actions_file);
538                                 snprintf(arg2, BUFSIZ, "%s/%s", config->confdir, arg);
539             config->actions_file = strdup(arg2);
540             continue;
541
542          case hash_logfile :
543             freez((char *)config->logfile);
544                                 snprintf(arg2, BUFSIZ, "%s/%s", config->logdir, arg);
545             config->logfile = strdup(arg2);
546             continue;
547
548 #ifdef JAR_FILES
549          case hash_jarfile :
550             freez((char *)config->jarfile);
551                                 snprintf(arg2, BUFSIZ, "%s/%s", config->logdir, arg);
552             config->jarfile = strdup(arg2);
553             continue;
554 #endif /* def JAR_FILES */
555
556          case hash_listen_address :
557             freez((char *)config->haddr);
558             config->haddr = strdup(arg);
559             continue;
560
561          case hash_forwardfile :
562             freez((char *)config->forwardfile);
563                                 snprintf(arg2, BUFSIZ, "%s/%s", config->confdir, arg);
564             config->forwardfile = strdup(arg2);
565             continue;
566
567 #ifdef ACL_FILES
568          case hash_aclfile :
569             freez((char *)config->aclfile);
570                                 snprintf(arg2, BUFSIZ, "%s/%s", config->confdir, arg);
571             config->aclfile = strdup(arg2);
572             continue;
573 #endif /* def ACL_FILES */
574
575 #ifdef PCRS
576          case hash_re_filterfile :
577             freez((char *)config->re_filterfile);
578             config->re_filterfile = strdup(arg);
579             continue;
580 #endif /* def PCRS */
581
582 #ifdef _WIN_CONSOLE
583          case hash_hide_console :
584             hideConsole = 1;
585             continue;
586 #endif /*def _WIN_CONSOLE*/
587
588 #ifndef SPLIT_PROXY_ARGS
589          case hash_suppress_blocklists :
590             if (arg[0] != '\0')
591             {
592                config->suppress_message = strdup(arg);
593             }
594             else
595             {
596                /* There will be NO reference in proxy-args. */
597                config->suppress_message = NULL;
598             }
599
600             config->suppress_blocklists = 1;
601             continue;
602 #endif /* ndef SPLIT_PROXY_ARGS */
603
604 #ifdef TOGGLE
605          case hash_toggle :
606             g_bToggleIJB = atoi(arg);
607             continue;
608 #endif /* def TOGGLE */
609
610 #if defined(_WIN32) && ! defined(_WIN_CONSOLE)
611          case hash_activity_animation :
612             g_bShowActivityAnimation = atoi(arg);
613             continue;
614
615          case hash_log_messages :
616             g_bLogMessages = atoi(arg);
617             continue;
618
619          case hash_log_highlight_messages :
620             g_bHighlightMessages = atoi(arg);
621             continue;
622
623          case hash_log_buffer_size :
624             g_bLimitBufferSize = atoi(arg);
625             continue;
626
627          case hash_log_max_lines :
628             g_nMaxBufferLines = atoi(arg);
629             continue;
630
631          case hash_log_font_name :
632             strcpy( g_szFontFaceName, arg );
633             continue;
634
635          case hash_log_font_size :
636             g_nFontSize = atoi(arg);
637             continue;
638
639          case hash_show_on_task_bar :
640             g_bShowOnTaskBar = atoi(arg);
641             continue;
642
643          case hash_close_button_minimizes :
644             g_bCloseHidesWindow = atoi(arg);
645             continue;
646 #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */
647
648          /* Warnings about unsupported features */
649
650 #ifndef PCRS
651          case hash_re_filterfile :
652 #endif /* ndef PCRS */
653 #ifndef TOGGLE
654          case hash_toggle :
655 #endif /* ndef TOGGLE */
656 #if defined(_WIN_CONSOLE) || ! defined(_WIN32)
657          case hash_activity_animation :
658          case hash_log_messages :
659          case hash_log_highlight_messages :
660          case hash_log_buffer_size :
661          case hash_log_max_lines :
662          case hash_log_font_name :
663          case hash_log_font_size :
664          case hash_show_on_task_bar :
665          case hash_close_button_minimizes :
666 #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */
667 #ifndef _WIN_CONSOLE
668          case hash_hide_console :
669 #endif /* ndef _WIN_CONSOLE */
670 #ifndef JAR_FILES
671          case hash_jarfile :
672 #endif /* ndef JAR_FILES */
673 #ifndef ACL_FILES
674          case hash_aclfile :
675 #endif /* ndef ACL_FILES */
676 #ifdef SPLIT_PROXY_ARGS
677          case hash_suppress_blocklists :
678 #endif /* def SPLIT_PROXY_ARGS */
679             log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd);
680             continue;
681
682          default :
683             /*
684              * I decided that I liked this better as a warning than an
685              * error.  To change back to an error, just change log level
686              * to LOG_LEVEL_FATAL.
687              */
688             log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in "
689                   "configuration file: \"%s\"", hash_string( cmd ), buf);
690             p = malloc( BUFSIZ );
691             if (p != NULL)
692             {
693                sprintf( p, "<br>\nWARNING: unrecognized directive : %s<br><br>\n", buf );
694                config->proxy_args_invocation = strsav( config->proxy_args_invocation, p );
695                freez( p );
696             }
697             continue;
698       } /* end switch( hash_string(cmd) ) */
699    } /* end while ( read_config_line(...) ) */
700
701    fclose(configfp);
702
703    init_error_log(Argv[0], config->logfile, config->debug);
704
705    if (config->actions_file)
706    {
707       add_loader(load_actions_file, config);
708    }
709
710    if (config->forwardfile)
711    {
712       add_loader(load_forwardfile, config);
713    }
714
715 #ifdef ACL_FILES
716    if (config->aclfile)
717    {
718       add_loader(load_aclfile, config);
719    }
720 #endif /* def ACL_FILES */
721
722 #ifdef PCRS
723    if (config->re_filterfile)
724    {
725       add_loader(load_re_filterfile, config);
726    }
727 #endif /* def PCRS */
728
729 #ifdef TRUST_FILES
730    if (config->trustfile)
731    {
732       add_loader(load_trustfile, config);
733    }
734 #endif
735
736 #ifdef JAR_FILES
737    if ( NULL != config->jarfile )
738    {
739       if ( NULL == (config->jar = fopen(config->jarfile, "a")) )
740       {
741          log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile);
742          /* Never get here - LOG_LEVEL_FATAL causes program exit */
743       }
744       setbuf(config->jar, NULL);
745    }
746 #endif /* def JAR_FILES */
747
748    if ( NULL == config->haddr )
749    {
750       config->haddr = strdup( HADDR_DEFAULT );
751    }
752
753    if ( NULL != config->haddr )
754    {
755       if ((p = strchr(config->haddr, ':')))
756       {
757          *p++ = '\0';
758          if (*p)
759          {
760             config->hport = atoi(p);
761          }
762       }
763
764       if (config->hport <= 0)
765       {
766          *--p = ':';
767          log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr);
768          /* Never get here - LOG_LEVEL_FATAL causes program exit */
769       }
770       if (*config->haddr == '\0')
771       {
772          config->haddr = NULL;
773       }
774    }
775
776    /*
777     * Want to run all the loaders once now.
778     *
779     * Need to set up a fake csp, so they can get to the config.
780     */
781    fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
782    fake_csp->config = config;
783
784    if (run_loader(fake_csp))
785    {
786       freez(fake_csp);
787       log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting.");
788       /* Never get here - LOG_LEVEL_FATAL causes program exit */
789    }
790    freez(fake_csp);
791
792 #ifndef SPLIT_PROXY_ARGS
793    if (!suppress_blocklists)
794    {
795       fs->proxy_args = strsav(fs->proxy_args, "</pre>");
796    }
797 #endif /* ndef SPLIT_PROXY_ARGS */
798
799 /* FIXME: this is a kludge for win32 */
800 #if defined(_WIN32) && !defined (_WIN_CONSOLE)
801
802    g_actions_file     = config->actions_file;
803    g_forwardfile      = config->forwardfile;
804 #ifdef ACL_FILES
805    g_aclfile          = config->aclfile;
806 #endif /* def ACL_FILES */
807 #ifdef PCRS
808    g_re_filterfile    = config->re_filterfile;
809 #endif
810 #ifdef TRUST_FILES
811    g_trustfile        = config->trustfile;
812 #endif
813    
814
815 #endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */
816 /* FIXME: end kludge */
817
818
819    config->need_bind = 1;
820
821    if (current_configfile)
822    {
823       struct configuration_spec * oldcfg = (struct configuration_spec *)
824                                            current_configfile->f;
825       /*
826        * Check if config->haddr,hport == oldcfg->haddr,hport
827        *
828        * The following could be written more compactly as a single,
829        * (unreadably long) if statement.
830        */
831       config->need_bind = 0;
832       if (config->hport != oldcfg->hport)
833       {
834          config->need_bind = 1;
835       }
836       else if (config->haddr == NULL)
837       {
838          if (oldcfg->haddr != NULL)
839          {
840             config->need_bind = 1;
841          }
842       }
843       else if (oldcfg->haddr == NULL)
844       {
845          config->need_bind = 1;
846       }
847       else if (0 != strcmp(config->haddr, oldcfg->haddr))
848       {
849          config->need_bind = 1;
850       }
851
852       current_configfile->unloader = unload_configfile;
853    }
854
855    fs->next = files->next;
856    files->next = fs;
857
858    current_configfile = fs;
859
860    return (config);
861 }
862
863
864 /*
865   Local Variables:
866   tab-width: 3
867   end:
868 */