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