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