Disable prevent-compression for all default
[privoxy.git] / loaders.c
1 const char loaders_rcs[] = "$Id: loaders.c,v 1.57 2006/12/21 12:22:22 fabiankeil Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/loaders.c,v $
5  *
6  * Purpose     :  Functions to load and unload the various
7  *                configuration files.  Also contains code to manage
8  *                the list of active loaders, and to automatically
9  *                unload files that are no longer in use.
10  *
11  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
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: loaders.c,v $
38  *    Revision 1.57  2006/12/21 12:22:22  fabiankeil
39  *    html_encode filter descriptions.
40  *
41  *    Have "Ignoring job ..." error messages
42  *    print the filter file name correctly.
43  *
44  *    Revision 1.56  2006/09/07 10:40:30  fabiankeil
45  *    Turns out trusted referrers above our arbitrary
46  *    limit are downgraded too ordinary trusted URLs.
47  *    Adjusted error message.
48  *
49  *    Revision 1.55  2006/09/07 10:25:39  fabiankeil
50  *    Fix typo.
51  *
52  *    Revision 1.54  2006/09/07 10:22:20  fabiankeil
53  *    If too many trusted referrers are used,
54  *    print only one error message instead of logging
55  *    every single trusted referrer above the arbitrary
56  *    limit.
57  *
58  *    Revision 1.53  2006/08/31 16:25:06  fabiankeil
59  *    Work around a buffer overflow that caused Privoxy to
60  *    segfault if too many trusted referrers were used. Good
61  *    enough for now, but should be replaced with a real
62  *    solution after the next release.
63  *
64  *    Revision 1.52  2006/07/18 14:48:46  david__schmidt
65  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
66  *    with what was really the latest development (the v_3_0_branch branch)
67  *
68  *    Revision 1.50.2.8  2006/01/30 15:16:25  david__schmidt
69  *    Remove a little residual debugging info
70  *
71  *    Revision 1.50.2.7  2006/01/29 23:10:56  david__schmidt
72  *    Multiple filter file support
73  *
74  *    Revision 1.50.2.6  2003/10/24 10:17:54  oes
75  *    Nit: Allowed tabs as separators in filter headings
76  *
77  *    Revision 1.50.2.5  2003/05/08 15:19:15  oes
78  *    sweep: Made loop structure of sweep step mirror that of mark step
79  *
80  *    Revision 1.50.2.4  2003/05/06 15:57:12  oes
81  *    Bugfix: Update last_active pointer in sweep() before
82  *    leaving an active client. Closes bugs #724395, #727882
83  *
84  *    Revision 1.50.2.3  2002/11/20 17:12:30  oes
85  *    Ooops, forgot one change.
86  *
87  *    Revision 1.50.2.2  2002/11/20 14:38:15  oes
88  *    Fixed delayed/incomplete freeing of client resources and
89  *    simplified loop structure in sweep.
90  *    Thanks to Oliver Stoeneberg for the hint.
91  *
92  *    Revision 1.50.2.1  2002/07/26 15:19:24  oes
93  *    - PCRS jobs now chained in order of appearance. Previous
94  *      reverse chaining was counter-intuitive.
95  *    - Changed loglevel of PCRS job compile errors to
96  *      LOG_LEVEL_ERROR
97  *
98  *    Revision 1.50  2002/04/24 02:12:16  oes
99  *    Jon's multiple AF patch: Sweep now takes care of all AFs
100  *
101  *    Revision 1.49  2002/04/19 16:53:25  jongfoster
102  *    Optimize away a function call by using an equivalent macro
103  *
104  *    Revision 1.48  2002/04/05 00:56:09  gliptak
105  *    Correcting typo to clean up on realloc failure
106  *
107  *    Revision 1.47  2002/03/26 22:29:55  swa
108  *    we have a new homepage!
109  *
110  *    Revision 1.46  2002/03/24 13:25:43  swa
111  *    name change related issues
112  *
113  *    Revision 1.45  2002/03/16 23:54:06  jongfoster
114  *    Adding graceful termination feature, to help look for memory leaks.
115  *    If you enable this (which, by design, has to be done by hand
116  *    editing config.h) and then go to http://i.j.b/die, then the program
117  *    will exit cleanly after the *next* request.  It should free all the
118  *    memory that was used.
119  *
120  *    Revision 1.44  2002/03/16 21:51:00  jongfoster
121  *    Fixing free(NULL).
122  *
123  *    Revision 1.43  2002/03/16 20:28:34  oes
124  *    Added descriptions to the filters so users will know what they select in the cgi editor
125  *
126  *    Revision 1.42  2002/03/13 00:27:05  jongfoster
127  *    Killing warnings
128  *
129  *    Revision 1.41  2002/03/12 01:42:50  oes
130  *    Introduced modular filters
131  *
132  *    Revision 1.40  2002/03/08 17:46:04  jongfoster
133  *    Fixing int/size_t warnings
134  *
135  *    Revision 1.39  2002/03/07 03:46:17  oes
136  *    Fixed compiler warnings
137  *
138  *    Revision 1.38  2002/03/06 22:54:35  jongfoster
139  *    Automated function-comment nitpicking.
140  *
141  *    Revision 1.37  2002/03/03 15:07:49  oes
142  *    Re-enabled automatic config reloading
143  *
144  *    Revision 1.36  2002/01/22 23:46:18  jongfoster
145  *    Moving edit_read_line() and simple_read_line() to loaders.c, and
146  *    extending them to support reading MS-DOS, Mac and UNIX style files
147  *    on all platforms.
148  *
149  *    Modifying read_config_line() (without changing it's prototype) to
150  *    be a trivial wrapper for edit_read_line().  This means that we have
151  *    one function to read a line and handle comments, which is common
152  *    between the initialization code and the edit interface.
153  *
154  *    Revision 1.35  2002/01/17 21:03:08  jongfoster
155  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
156  *
157  *    Renaming free_url to free_url_spec, since it frees a struct url_spec.
158  *
159  *    Revision 1.34  2001/12/30 14:07:32  steudten
160  *    - Add signal handling (unix)
161  *    - Add SIGHUP handler (unix)
162  *    - Add creation of pidfile (unix)
163  *    - Add action 'top' in rc file (RH)
164  *    - Add entry 'SIGNALS' to manpage
165  *    - Add exit message to logfile (unix)
166  *
167  *    Revision 1.33  2001/11/13 00:16:38  jongfoster
168  *    Replacing references to malloc.h with the standard stdlib.h
169  *    (See ANSI or K&R 2nd Ed)
170  *
171  *    Revision 1.32  2001/11/07 00:02:13  steudten
172  *    Add line number in error output for lineparsing for
173  *    actionsfile and configfile.
174  *    Special handling for CLF added.
175  *
176  *    Revision 1.31  2001/10/26 17:39:01  oes
177  *    Removed csp->referrer
178  *    Moved ijb_isspace and ijb_tolower to project.h
179  *
180  *    Revision 1.30  2001/10/25 03:40:48  david__schmidt
181  *    Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
182  *    threads to call select() simultaneously.  So, it's time to do a real, live,
183  *    native OS/2 port.  See defines for __EMX__ (the porting layer) vs. __OS2__
184  *    (native). Both versions will work, but using __OS2__ offers multi-threading.
185  *
186  *    Revision 1.29  2001/10/23 21:38:53  jongfoster
187  *    Adding error-checking to create_url_spec()
188  *
189  *    Revision 1.28  2001/10/07 15:40:39  oes
190  *    Replaced 6 boolean members of csp with one bitmap (csp->flags)
191  *
192  *    Revision 1.27  2001/09/22 16:36:59  jongfoster
193  *    Removing unused parameter fs from read_config_line()
194  *
195  *    Revision 1.26  2001/09/22 14:05:22  jongfoster
196  *    Bugfix: Multiple escaped "#" characters in a configuration
197  *    file are now permitted.
198  *    Also removing 3 unused headers.
199  *
200  *    Revision 1.25  2001/09/13 22:44:03  jongfoster
201  *    Adding {} to an if statement
202  *
203  *    Revision 1.24  2001/07/30 22:08:36  jongfoster
204  *    Tidying up #defines:
205  *    - All feature #defines are now of the form FEATURE_xxx
206  *    - Permanently turned off WIN_GUI_EDIT
207  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
208  *
209  *    Revision 1.23  2001/07/20 15:51:54  oes
210  *    Fixed indentation of prepocessor commands
211  *
212  *    Revision 1.22  2001/07/20 15:16:17  haroon
213  *    - per Guy's suggestion, added a while loop in sweep() to catch not just
214  *      the last inactive CSP but all other consecutive inactive CSPs after that
215  *      as well
216  *
217  *    Revision 1.21  2001/07/18 17:26:24  oes
218  *    Changed to conform to new pcrs interface
219  *
220  *    Revision 1.20  2001/07/17 13:07:01  oes
221  *    Fixed segv when last line in config files
222  *     lacked a terminating (\r)\n
223  *
224  *    Revision 1.19  2001/07/13 14:01:54  oes
225  *    Removed all #ifdef PCRS
226  *
227  *    Revision 1.18  2001/06/29 21:45:41  oes
228  *    Indentation, CRLF->LF, Tab-> Space
229  *
230  *    Revision 1.17  2001/06/29 13:31:51  oes
231  *    Various adaptions
232  *
233  *    Revision 1.16  2001/06/09 10:55:28  jongfoster
234  *    Changing BUFSIZ ==> BUFFER_SIZE
235  *
236  *    Revision 1.15  2001/06/07 23:14:14  jongfoster
237  *    Removing ACL and forward file loaders - these
238  *    files have been merged into the config file.
239  *    Cosmetic: Moving unloader funcs next to their
240  *    respective loader funcs
241  *
242  *    Revision 1.14  2001/06/01 03:27:04  oes
243  *    Fixed line continuation problem
244  *
245  *    Revision 1.13  2001/05/31 21:28:49  jongfoster
246  *    Removed all permissionsfile code - it's now called the actions
247  *    file, and (almost) all the code is in actions.c
248  *
249  *    Revision 1.12  2001/05/31 17:32:31  oes
250  *
251  *     - Enhanced domain part globbing with infix and prefix asterisk
252  *       matching and optional unanchored operation
253  *
254  *    Revision 1.11  2001/05/29 23:25:24  oes
255  *
256  *     - load_config_line() and load_permissions_file() now use chomp()
257  *
258  *    Revision 1.10  2001/05/29 09:50:24  jongfoster
259  *    Unified blocklist/imagelist/permissionslist.
260  *    File format is still under discussion, but the internal changes
261  *    are (mostly) done.
262  *
263  *    Also modified interceptor behaviour:
264  *    - We now intercept all URLs beginning with one of the following
265  *      prefixes (and *only* these prefixes):
266  *        * http://i.j.b/
267  *        * http://ijbswa.sf.net/config/
268  *        * http://ijbswa.sourceforge.net/config/
269  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
270  *    - Internal changes so that intercepted and fast redirect pages
271  *      are not replaced with an image.
272  *    - Interceptors now have the option to send a binary page direct
273  *      to the client. (i.e. ijb-send-banner uses this)
274  *    - Implemented show-url-info interceptor.  (Which is why I needed
275  *      the above interceptors changes - a typical URL is
276  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
277  *      The previous mechanism would not have intercepted that, and
278  *      if it had been intercepted then it then it would have replaced
279  *      it with an image.)
280  *
281  *    Revision 1.9  2001/05/26 17:12:07  jongfoster
282  *    Fatal errors loading configuration files now give better error messages.
283  *
284  *    Revision 1.8  2001/05/26 00:55:20  jongfoster
285  *    Removing duplicated code.  load_forwardfile() now uses create_url_spec()
286  *
287  *    Revision 1.7  2001/05/26 00:28:36  jongfoster
288  *    Automatic reloading of config file.
289  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
290  *    Most of the global variables have been moved to a new
291  *    struct configuration_spec, accessed through csp->config->globalname
292  *    Most of the globals remaining are used by the Win32 GUI.
293  *
294  *    Revision 1.6  2001/05/23 12:27:33  oes
295  *
296  *    Fixed ugly indentation of my last changes
297  *
298  *    Revision 1.5  2001/05/23 10:39:05  oes
299  *    - Added support for escaping the comment character
300  *      in config files by a backslash
301  *    - Added support for line continuation in config
302  *      files
303  *    - Fixed a buffer overflow bug with long config lines
304  *
305  *    Revision 1.4  2001/05/22 18:56:28  oes
306  *    CRLF -> LF
307  *
308  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
309  *    Version 2.9.4 checkin.
310  *    - Merged popupfile and cookiefile, and added control over PCRS
311  *      filtering, in new "permissionsfile".
312  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
313  *      file error you now get a message box (in the Win32 GUI) rather
314  *      than the program exiting with no explanation.
315  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
316  *      skipping.
317  *    - Removed tabs from "config"
318  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
319  *    - Bumped up version number.
320  *
321  *    Revision 1.2  2001/05/17 23:01:01  oes
322  *     - Cleaned CRLF's from the sources and related files
323  *
324  *    Revision 1.1.1.1  2001/05/15 13:58:59  oes
325  *    Initial import of version 2.9.3 source tree
326  *
327  *
328  *********************************************************************/
329 \f
330
331 #include "config.h"
332
333 #include <stdio.h>
334 #include <stdlib.h>
335 #include <sys/types.h>
336 #include <string.h>
337 #include <errno.h>
338 #include <sys/stat.h>
339 #include <ctype.h>
340 #include <assert.h>
341
342 #if !defined(_WIN32) && !defined(__OS2__)
343 #include <unistd.h>
344 #endif
345
346 #include "project.h"
347 #include "list.h"
348 #include "loaders.h"
349 #include "filters.h"
350 #include "parsers.h"
351 #include "jcc.h"
352 #include "miscutil.h"
353 #include "errlog.h"
354 #include "actions.h"
355 #include "urlmatch.h"
356 #include "encode.h"
357
358 const char loaders_h_rcs[] = LOADERS_H_VERSION;
359
360 /*
361  * Currently active files.
362  * These are also entered in the main linked list of files.
363  */
364
365 #ifdef FEATURE_TRUST
366 static struct file_list *current_trustfile      = NULL;
367 #endif /* def FEATURE_TRUST */
368
369 static int load_one_re_filterfile(struct client_state *csp, int fileid);
370
371 static struct file_list *current_re_filterfile[MAX_AF_FILES]  = {
372    NULL, NULL, NULL, NULL, NULL,
373    NULL, NULL, NULL, NULL, NULL
374 };
375
376
377
378 /*********************************************************************
379  *
380  * Function    :  sweep
381  *
382  * Description :  Basically a mark and sweep garbage collector, it is run
383  *                (by the parent thread) every once in a while to reclaim memory.
384  *
385  * It uses a mark and sweep strategy:
386  *   1) mark all files as inactive
387  *
388  *   2) check with each client:
389  *       if it is active,   mark its files as active
390  *       if it is inactive, free its resources
391  *
392  *   3) free the resources of all of the files that
393  *      are still marked as inactive (and are obsolete).
394  *
395  *   N.B. files that are not obsolete don't have an unloader defined.
396  *
397  * Parameters  :  None
398  *
399  * Returns     :  N/A
400  *
401  *********************************************************************/
402 void sweep(void)
403 {
404    struct file_list *fl, *nfl;
405    struct client_state *csp, *last_active;
406    int i;
407
408    /* clear all of the file's active flags */
409    for ( fl = files->next; NULL != fl; fl = fl->next )
410    {
411       fl->active = 0;
412    }
413
414    last_active = clients;
415    csp = clients->next;
416
417    while (NULL != csp)
418    {
419       if (csp->flags & CSP_FLAG_ACTIVE)
420       {
421          /* Mark this client's files as active */
422
423          /*
424           * Always have a configuration file.
425           * (Also note the slightly non-standard extra
426           * indirection here.)
427           */
428          csp->config->config_file_list->active = 1;
429
430          /* 
431           * Actions files
432           */
433          for (i = 0; i < MAX_AF_FILES; i++)
434          {
435             if (csp->actions_list[i])     
436             {
437                csp->actions_list[i]->active = 1;
438             }
439          }
440
441          /*
442           * Filter files
443           */
444          for (i = 0; i < MAX_AF_FILES; i++)
445          {
446             if (csp->rlist[i])     
447             {
448                csp->rlist[i]->active = 1;
449             }
450          }
451
452          /*
453           * Trust file
454           */
455 #ifdef FEATURE_TRUST
456          if (csp->tlist)
457          {
458             csp->tlist->active = 1;
459          }
460 #endif /* def FEATURE_TRUST */
461          
462          last_active = csp;
463          csp = csp->next;
464
465       }
466       else 
467       /*
468        * This client is not active. Free its resources.
469        */
470       {
471          last_active->next = csp->next;
472
473          freez(csp->ip_addr_str);
474          freez(csp->my_ip_addr_str);
475          freez(csp->my_hostname);
476          freez(csp->x_forwarded);
477          freez(csp->iob->buf);
478
479          free_http_request(csp->http);
480
481          destroy_list(csp->headers);
482          destroy_list(csp->cookie_list);
483
484          free_current_action(csp->action);
485
486 #ifdef FEATURE_STATISTICS
487          urls_read++;
488          if (csp->flags & CSP_FLAG_REJECTED)
489          {
490             urls_rejected++;
491          }
492 #endif /* def FEATURE_STATISTICS */
493
494          freez(csp);
495          
496          csp = last_active->next;
497       }
498    }
499
500    nfl = files;
501    fl = files->next;
502
503    while (fl != NULL)
504    {
505       if ( ( 0 == fl->active ) && ( NULL != fl->unloader ) )
506       {
507          nfl->next = fl->next;
508
509          (fl->unloader)(fl->f);
510
511          freez(fl->filename);
512          freez(fl);
513
514          fl = nfl->next;
515       }
516       else
517       {
518          nfl = fl;
519          fl = fl->next;
520       }
521    }
522
523 }
524
525
526 /*********************************************************************
527  *
528  * Function    :  check_file_changed
529  *
530  * Description :  Helper function to check if a file needs reloading.
531  *                If "current" is still current, return it.  Otherwise
532  *                allocates a new (zeroed) "struct file_list", fills
533  *                in the disk file name and timestamp, and returns it.
534  *
535  * Parameters  :
536  *          1  :  current = The file_list currently being used - will
537  *                          be checked to see if it is out of date.
538  *                          May be NULL (which is treated as out of
539  *                          date).
540  *          2  :  filename = Name of file to check.
541  *          3  :  newfl    = New file list. [Output only]
542  *                           This will be set to NULL, OR a struct
543  *                           file_list newly allocated on the
544  *                           heap, with the filename and lastmodified
545  *                           fields filled, and all others zeroed.
546  *
547  * Returns     :  If file unchanged: 0 (and sets newfl == NULL)
548  *                If file changed: 1 and sets newfl != NULL
549  *                On error: 1 and sets newfl == NULL
550  *
551  *********************************************************************/
552 int check_file_changed(const struct file_list * current,
553                        const char * filename,
554                        struct file_list ** newfl)
555 {
556    struct file_list *fs;
557    struct stat statbuf[1];
558
559    *newfl = NULL;
560
561    if (stat(filename, statbuf) < 0)
562    {
563       /* Error, probably file not found. */
564       return 1;
565    }
566
567    if (current
568        && (current->lastmodified == statbuf->st_mtime)
569        && (0 == strcmp(current->filename, filename)))
570    {
571       return 0;
572    }
573
574    fs = (struct file_list *)zalloc(sizeof(struct file_list));
575    if (fs == NULL)
576    {
577       /* Out of memory error */
578       return 1;
579    }
580
581
582    fs->filename = strdup(filename);
583    fs->lastmodified = statbuf->st_mtime;
584
585    if (fs->filename == NULL)
586    {
587       /* Out of memory error */
588       freez (fs);
589       return 1;
590    }
591    *newfl = fs;
592    return 1;
593 }
594
595
596 /*********************************************************************
597  *
598  * Function    :  simple_read_line
599  *
600  * Description :  Read a single line from a file and return it.
601  *                This is basically a version of fgets() that malloc()s
602  *                it's own line buffer.  Note that the buffer will
603  *                always be a multiple of BUFFER_SIZE bytes long.
604  *                Therefore if you are going to keep the string for
605  *                an extended period of time, you should probably
606  *                strdup() it and free() the original, to save memory.
607  *
608  *
609  * Parameters  :
610  *          1  :  dest = destination for newly malloc'd pointer to
611  *                line data.  Will be set to NULL on error.
612  *          2  :  fp = File to read from
613  *          3  :  newline = Standard for newlines in the file.
614  *                Will be unchanged if it's value on input is not
615  *                NEWLINE_UNKNOWN.
616  *                On output, may be changed from NEWLINE_UNKNOWN to
617  *                actual convention in file.
618  *
619  * Returns     :  JB_ERR_OK     on success
620  *                JB_ERR_MEMORY on out-of-memory
621  *                JB_ERR_FILE   on EOF.
622  *
623  *********************************************************************/
624 jb_err simple_read_line(FILE *fp, char **dest, int *newline)
625 {
626    size_t len = 0;
627    size_t buflen = BUFFER_SIZE;
628    char * buf;
629    char * p;
630    int ch;
631    int realnewline = NEWLINE_UNKNOWN;
632
633    if (NULL == (buf = malloc(buflen)))
634    {
635       return JB_ERR_MEMORY;
636    }
637
638    p = buf;
639
640 /*
641  * Character codes.  If you have a wierd compiler and the following are
642  * incorrect, you also need to fix NEWLINE() in loaders.h
643  */
644 #define CHAR_CR '\r' /* ASCII 13 */
645 #define CHAR_LF '\n' /* ASCII 10 */
646
647    for (;;)
648    {
649       ch = getc(fp);
650       if (ch == EOF)
651       {
652          if (len > 0)
653          {
654             *p = '\0';
655             *dest = buf;
656             return JB_ERR_OK;
657          }
658          else
659          {
660             free(buf);
661             *dest = NULL;
662             return JB_ERR_FILE;
663          }
664       }
665       else if (ch == CHAR_CR)
666       {
667          ch = getc(fp);
668          if (ch == CHAR_LF)
669          {
670             if (*newline == NEWLINE_UNKNOWN)
671             {
672                *newline = NEWLINE_DOS;
673             }
674          }
675          else
676          {
677             if (ch != EOF)
678             {
679                ungetc(ch, fp);
680             }
681             if (*newline == NEWLINE_UNKNOWN)
682             {
683                *newline = NEWLINE_MAC;
684             }
685          }
686          *p = '\0';
687          *dest = buf;
688          if (*newline == NEWLINE_UNKNOWN)
689          {
690             *newline = realnewline;
691          }
692          return JB_ERR_OK;
693       }
694       else if (ch == CHAR_LF)
695       {
696          *p = '\0';
697          *dest = buf;
698          if (*newline == NEWLINE_UNKNOWN)
699          {
700             *newline = NEWLINE_UNIX;
701          }
702          return JB_ERR_OK;
703       }
704       else if (ch == 0)
705       {
706          *p = '\0';
707          *dest = buf;
708          return JB_ERR_OK;
709       }
710
711       *p++ = (char)ch;
712
713       if (++len >= buflen)
714       {
715          buflen += BUFFER_SIZE;
716          if (NULL == (p = realloc(buf, buflen)))
717          {
718             free(buf);
719             return JB_ERR_MEMORY;
720          }
721          buf = p;
722          p = buf + len;
723       }
724    }
725 }
726
727
728 /*********************************************************************
729  *
730  * Function    :  edit_read_line
731  *
732  * Description :  Read a single non-empty line from a file and return
733  *                it.  Trims comments, leading and trailing whitespace
734  *                and respects escaping of newline and comment char.
735  *                Provides the line in 2 alternative forms: raw and
736  *                preprocessed.
737  *                - raw is the raw data read from the file.  If the
738  *                  line is not modified, then this should be written
739  *                  to the new file.
740  *                - prefix is any comments and blank lines that were
741  *                  read from the file.  If the line is modified, then
742  *                  this should be written out to the file followed
743  *                  by the modified data.  (If this string is non-empty
744  *                  then it will have a newline at the end).
745  *                - data is the actual data that will be parsed
746  *                  further by appropriate routines.
747  *                On EOF, the 3 strings will all be set to NULL and
748  *                0 will be returned.
749  *
750  * Parameters  :
751  *          1  :  fp = File to read from
752  *          2  :  raw_out = destination for newly malloc'd pointer to
753  *                raw line data.  May be NULL if you don't want it.
754  *          3  :  prefix_out = destination for newly malloc'd pointer to
755  *                comments.  May be NULL if you don't want it.
756  *          4  :  data_out = destination for newly malloc'd pointer to
757  *                line data with comments and leading/trailing spaces
758  *                removed, and line continuation performed.  May be
759  *                NULL if you don't want it.
760  *          5  :  newline = Standard for newlines in the file.
761  *                On input, set to value to use or NEWLINE_UNKNOWN.
762  *                On output, may be changed from NEWLINE_UNKNOWN to
763  *                actual convention in file.  May be NULL if you
764  *                don't want it.
765  *          6  :  line_number = Line number in file.  In "lines" as
766  *                reported by a text editor, not lines containing data.
767  *
768  * Returns     :  JB_ERR_OK     on success
769  *                JB_ERR_MEMORY on out-of-memory
770  *                JB_ERR_FILE   on EOF.
771  *
772  *********************************************************************/
773 jb_err edit_read_line(FILE *fp,
774                       char **raw_out,
775                       char **prefix_out,
776                       char **data_out,
777                       int *newline,
778                       unsigned long *line_number)
779 {
780    char *p;          /* Temporary pointer   */
781    char *linebuf;    /* Line read from file */
782    char *linestart;  /* Start of linebuf, usually first non-whitespace char */
783    int contflag = 0; /* Nonzero for line continuation - i.e. line ends '\' */
784    int is_empty = 1; /* Flag if not got any data yet */
785    char *raw    = NULL; /* String to be stored in raw_out    */
786    char *prefix = NULL; /* String to be stored in prefix_out */
787    char *data   = NULL; /* String to be stored in data_out   */
788    int scrapnewline;    /* Used for (*newline) if newline==NULL */
789    jb_err rval = JB_ERR_OK;
790
791    assert(fp);
792    assert(raw_out || data_out);
793    assert(newline == NULL
794        || *newline == NEWLINE_UNKNOWN
795        || *newline == NEWLINE_UNIX
796        || *newline == NEWLINE_DOS
797        || *newline == NEWLINE_MAC);
798
799    if (newline == NULL)
800    {
801       scrapnewline = NEWLINE_UNKNOWN;
802       newline = &scrapnewline;
803    }
804
805    /* Set output parameters to NULL */
806    if (raw_out)
807    {
808       *raw_out    = NULL;
809    }
810    if (prefix_out)
811    {
812       *prefix_out = NULL;
813    }
814    if (data_out)
815    {
816       *data_out   = NULL;
817    }
818
819    /* Set string variables to new, empty strings. */
820
821    if (raw_out)
822    {
823       if ((raw = malloc(1)) == NULL)
824       {
825          return JB_ERR_MEMORY;
826       }
827       *raw = '\0';
828    }
829    if (prefix_out)
830    {
831       if ((prefix = malloc(1)) == NULL)
832       {
833          freez(raw);
834          return JB_ERR_MEMORY;
835       }
836       *prefix = '\0';
837    }
838    if (data_out)
839    {
840       if ((data = malloc(1)) == NULL)
841       {
842          freez(raw);
843          freez(prefix);
844          return JB_ERR_MEMORY;
845       }
846       *data = '\0';
847    }
848
849    /* Main loop.  Loop while we need more data & it's not EOF. */
850
851    while ( (contflag || is_empty)
852         && (JB_ERR_OK == (rval = simple_read_line(fp, &linebuf, newline))))
853    {
854       if (line_number)
855       {
856          (*line_number)++;
857       }
858       if (raw)
859       {
860          string_append(&raw,linebuf);
861          if (string_append(&raw,NEWLINE(*newline)))
862          {
863             freez(prefix);
864             freez(data);
865             free(linebuf);
866             return JB_ERR_MEMORY;
867          }
868       }
869
870       /* Line continuation? Trim escape and set flag. */
871       p = linebuf + strlen(linebuf) - 1;
872       contflag = ((*linebuf != '\0') && (*p == '\\'));
873       if (contflag)
874       {
875          *p = '\0';
876       }
877
878       /* Trim leading spaces if we're at the start of the line */
879       linestart = linebuf;
880       if (*data == '\0')
881       {
882          /* Trim leading spaces */
883          while (*linestart && isspace((int)(unsigned char)*linestart))
884          {
885             linestart++;
886          }
887       }
888
889       /* Handle comment characters. */
890       p = linestart;
891       while ((p = strchr(p, '#')) != NULL)
892       {
893          /* Found a comment char.. */
894          if ((p != linebuf) && (*(p-1) == '\\'))
895          {
896             /* ..and it's escaped, left-shift the line over the escape. */
897             char *q = p - 1;
898             while ((*q = *(q + 1)) != '\0')
899             {
900                q++;
901             }
902             /* Now scan from just after the "#". */
903          }
904          else
905          {
906             /* Real comment.  Save it... */
907             if (p == linestart)
908             {
909                /* Special case:  Line only contains a comment, so all the
910                 * previous whitespace is considered part of the comment.
911                 * Undo the whitespace skipping, if any.
912                 */
913                linestart = linebuf;
914                p = linestart;
915             }
916             if (prefix)
917             {
918                string_append(&prefix,p);
919                if (string_append(&prefix, NEWLINE(*newline)))
920                {
921                   freez(raw);
922                   freez(data);
923                   free(linebuf);
924                   return JB_ERR_MEMORY;
925                }
926             }
927
928             /* ... and chop off the rest of the line */
929             *p = '\0';
930          }
931       } /* END while (there's a # character) */
932
933       /* Write to the buffer */
934       if (*linestart)
935       {
936          is_empty = 0;
937          if (data)
938          {
939             if (string_append(&data, linestart))
940             {
941                freez(raw);
942                freez(prefix);
943                free(linebuf);
944                return JB_ERR_MEMORY;
945             }
946          }
947       }
948
949       free(linebuf);
950    } /* END while(we need more data) */
951
952    /* Handle simple_read_line() errors - ignore EOF */
953    if ((rval != JB_ERR_OK) && (rval != JB_ERR_FILE))
954    {
955       freez(raw);
956       freez(prefix);
957       freez(data);
958       return rval;
959    }
960
961    if (raw ? (*raw == '\0') : is_empty)
962    {
963       /* EOF and no data there.  (Definition of "data" depends on whether
964        * the caller cares about "raw" or just "data").
965        */
966
967       freez(raw);
968       freez(prefix);
969       freez(data);
970
971       return JB_ERR_FILE;
972    }
973    else
974    {
975       /* Got at least some data */
976
977       /* Remove trailing whitespace */
978       chomp(data);
979
980       if (raw_out)
981       {
982          *raw_out    = raw;
983       }
984       else
985       {
986          freez(raw);
987       }
988       if (prefix_out)
989       {
990          *prefix_out = prefix;
991       }
992       else
993       {
994          freez(prefix);
995       }
996       if (data_out)
997       {
998          *data_out   = data;
999       }
1000       else
1001       {
1002          freez(data);
1003       }
1004       return JB_ERR_OK;
1005    }
1006 }
1007
1008
1009 /*********************************************************************
1010  *
1011  * Function    :  read_config_line
1012  *
1013  * Description :  Read a single non-empty line from a file and return
1014  *                it.  Trims comments, leading and trailing whitespace
1015  *                and respects escaping of newline and comment char.
1016  *
1017  * Parameters  :
1018  *          1  :  buf = Buffer to use.
1019  *          2  :  buflen = Size of buffer in bytes.
1020  *          3  :  fp = File to read from
1021  *          4  :  linenum = linenumber in file
1022  *
1023  * Returns     :  NULL on EOF or error
1024  *                Otherwise, returns buf.
1025  *
1026  *********************************************************************/
1027 char *read_config_line(char *buf, size_t buflen, FILE *fp, unsigned long *linenum)
1028 {
1029    jb_err err;
1030    char *buf2 = NULL;
1031    err = edit_read_line(fp, NULL, NULL, &buf2, NULL, linenum);
1032    if (err)
1033    {
1034       if (err == JB_ERR_MEMORY)
1035       {
1036          log_error(LOG_LEVEL_FATAL, "Out of memory loading a config file");
1037       }
1038       return NULL;
1039    }
1040    else
1041    {
1042       assert(buf2);
1043       assert(strlen(buf2) + 1U < buflen);
1044       strncpy(buf, buf2, buflen - 1);
1045       free(buf2);
1046       buf[buflen - 1] = '\0';
1047       return buf;
1048    }
1049 }
1050
1051
1052 #ifdef FEATURE_TRUST
1053 /*********************************************************************
1054  *
1055  * Function    :  unload_trustfile
1056  *
1057  * Description :  Unloads a trustfile.
1058  *
1059  * Parameters  :
1060  *          1  :  f = the data structure associated with the trustfile.
1061  *
1062  * Returns     :  N/A
1063  *
1064  *********************************************************************/
1065 static void unload_trustfile(void *f)
1066 {
1067    struct block_spec *cur = (struct block_spec *)f;
1068    struct block_spec *next;
1069
1070    while (cur != NULL)
1071    {
1072       next = cur->next;
1073
1074       free_url_spec(cur->url);
1075       free(cur);
1076
1077       cur = next;
1078    }
1079
1080 }
1081
1082
1083 #ifdef FEATURE_GRACEFUL_TERMINATION
1084 /*********************************************************************
1085  *
1086  * Function    :  unload_current_trust_file
1087  *
1088  * Description :  Unloads current trust file - reset to state at
1089  *                beginning of program.
1090  *
1091  * Parameters  :  None
1092  *
1093  * Returns     :  N/A
1094  *
1095  *********************************************************************/
1096 void unload_current_trust_file(void)
1097 {
1098    if (current_trustfile)
1099    {
1100       current_trustfile->unloader = unload_trustfile;
1101       current_trustfile = NULL;
1102    }
1103 }
1104 #endif /* FEATURE_GRACEFUL_TERMINATION */
1105
1106
1107 /*********************************************************************
1108  *
1109  * Function    :  load_trustfile
1110  *
1111  * Description :  Read and parse a trustfile and add to files list.
1112  *
1113  * Parameters  :
1114  *          1  :  csp = Current client state (buffers, headers, etc...)
1115  *
1116  * Returns     :  0 => Ok, everything else is an error.
1117  *
1118  *********************************************************************/
1119 int load_trustfile(struct client_state *csp)
1120 {
1121    FILE *fp;
1122
1123    struct block_spec *b, *bl;
1124    struct url_spec **tl;
1125
1126    char  buf[BUFFER_SIZE], *p, *q;
1127    int reject, trusted;
1128    struct file_list *fs;
1129    unsigned long linenum = 0;
1130    int trusted_referrers = 0;
1131
1132    if (!check_file_changed(current_trustfile, csp->config->trustfile, &fs))
1133    {
1134       /* No need to load */
1135       if (csp)
1136       {
1137          csp->tlist = current_trustfile;
1138       }
1139       return(0);
1140    }
1141    if (!fs)
1142    {
1143       goto load_trustfile_error;
1144    }
1145
1146    fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
1147    if (bl == NULL)
1148    {
1149       goto load_trustfile_error;
1150    }
1151
1152    if ((fp = fopen(csp->config->trustfile, "r")) == NULL)
1153    {
1154       goto load_trustfile_error;
1155    }
1156
1157    tl = csp->config->trust_list;
1158
1159    while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1160    {
1161       trusted = 0;
1162       reject  = 1;
1163
1164       if (*buf == '+')
1165       {
1166          trusted = 1;
1167          *buf = '~';
1168       }
1169
1170       if (*buf == '~')
1171       {
1172          reject = 0;
1173          p = buf;
1174          q = p+1;
1175          while ((*p++ = *q++) != '\0')
1176          {
1177             /* nop */
1178          }
1179       }
1180
1181       /* skip blank lines */
1182       if (*buf == '\0')
1183       {
1184          continue;
1185       }
1186
1187       /* allocate a new node */
1188       if ((b = zalloc(sizeof(*b))) == NULL)
1189       {
1190          fclose(fp);
1191          goto load_trustfile_error;
1192       }
1193
1194       /* add it to the list */
1195       b->next  = bl->next;
1196       bl->next = b;
1197
1198       b->reject = reject;
1199
1200       /* Save the URL pattern */
1201       if (create_url_spec(b->url, buf))
1202       {
1203          fclose(fp);
1204          goto load_trustfile_error;
1205       }
1206
1207       /*
1208        * save a pointer to URL's spec in the list of trusted URL's, too
1209        */
1210       if (trusted)
1211       {
1212          if(++trusted_referrers < MAX_TRUSTED_REFERRERS)
1213          {
1214             *tl++ = b->url;
1215          }
1216       }
1217    }
1218
1219    if(trusted_referrers >= MAX_TRUSTED_REFERRERS) 
1220    {
1221       /*
1222        * FIXME: ... after Privoxy 3.0.4 is out.
1223        */
1224        log_error(LOG_LEVEL_ERROR, "Too many trusted referrers. Current limit is %d, you are using %d.\n"
1225           "  Additional trusted referrers are treated like ordinary trusted URLs.\n"
1226           "  (You can increase this limit by changing MAX_TRUSTED_REFERRERS in project.h and recompiling).",
1227           MAX_TRUSTED_REFERRERS, trusted_referrers);
1228    }
1229
1230    *tl = NULL;
1231
1232    fclose(fp);
1233
1234    /* the old one is now obsolete */
1235    if (current_trustfile)
1236    {
1237       current_trustfile->unloader = unload_trustfile;
1238    }
1239
1240    fs->next    = files->next;
1241    files->next = fs;
1242    current_trustfile = fs;
1243
1244    if (csp)
1245    {
1246       csp->tlist = fs;
1247    }
1248
1249    return(0);
1250
1251 load_trustfile_error:
1252    log_error(LOG_LEVEL_FATAL, "can't load trustfile '%s': %E",
1253              csp->config->trustfile);
1254    return(-1);
1255
1256 }
1257 #endif /* def FEATURE_TRUST */
1258
1259
1260 /*********************************************************************
1261  *
1262  * Function    :  unload_re_filterfile
1263  *
1264  * Description :  Unload the re_filter list by freeing all chained
1265  *                re_filterfile specs and their data.
1266  *
1267  * Parameters  :
1268  *          1  :  f = the data structure associated with the filterfile.
1269  *
1270  * Returns     :  N/A
1271  *
1272  *********************************************************************/
1273 static void unload_re_filterfile(void *f)
1274 {
1275    struct re_filterfile_spec *a, *b = (struct re_filterfile_spec *)f;
1276
1277    while (b != NULL)
1278    {
1279       a = b->next;
1280
1281       destroy_list(b->patterns);
1282       pcrs_free_joblist(b->joblist);
1283       freez(b->name);
1284       freez(b->description);
1285       freez(b);
1286
1287       b = a;
1288    }
1289
1290    return;
1291 }
1292
1293
1294 #ifdef FEATURE_GRACEFUL_TERMINATION
1295 /*********************************************************************
1296  *
1297  * Function    :  unload_current_re_filterfile
1298  *
1299  * Description :  Unloads current re_filter file - reset to state at
1300  *                beginning of program.
1301  *
1302  * Parameters  :  None
1303  *
1304  * Returns     :  N/A
1305  *
1306  *********************************************************************/
1307 void unload_current_re_filterfile(void)
1308 {
1309    int i;
1310
1311    for (i = 0; i < MAX_AF_FILES; i++)
1312    {
1313       if (current_re_filterfile[i])
1314       {
1315          current_re_filterfile[i]->unloader = unload_re_filterfile;
1316          current_re_filterfile[i] = NULL;
1317       }
1318    }
1319 }
1320 #endif
1321
1322
1323 /*********************************************************************
1324  *
1325  * Function    :  load_re_filterfile
1326  *
1327  * Description :  Load the re_filterfile. 
1328  *                Generate a chained list of re_filterfile_spec's from
1329  *                the "FILTER: " blocks, compiling all their substitutions
1330  *                into chained lists of pcrs_job structs.
1331  *
1332  * Parameters  :
1333  *          1  :  csp = Current client state (buffers, headers, etc...)
1334  *
1335  * Returns     :  0 => Ok, everything else is an error.
1336  *
1337  *********************************************************************/
1338 int load_re_filterfile(struct client_state *csp)
1339 {
1340    int i;
1341    int result;
1342
1343    for (i = 0; i < MAX_AF_FILES; i++)
1344    {
1345       if (csp->config->re_filterfile[i])
1346       {
1347          result = load_one_re_filterfile(csp, i);
1348          if (result)
1349          {
1350             return result;
1351          }
1352       }
1353       else if (current_re_filterfile[i])
1354       {
1355          current_re_filterfile[i]->unloader = unload_re_filterfile;
1356          current_re_filterfile[i] = NULL;
1357       }
1358    }
1359
1360    return 0;
1361 }
1362
1363 /*********************************************************************
1364  *
1365  * Function    :  load_one_re_filterfile
1366  *
1367  * Description :  Load a re_filterfile. 
1368  *                Generate a chained list of re_filterfile_spec's from
1369  *                the "FILTER: " blocks, compiling all their substitutions
1370  *                into chained lists of pcrs_job structs.
1371  *
1372  * Parameters  :
1373  *          1  :  csp = Current client state (buffers, headers, etc...)
1374  *
1375  * Returns     :  0 => Ok, everything else is an error.
1376  *
1377  *********************************************************************/
1378 int load_one_re_filterfile(struct client_state *csp, int fileid)
1379 {
1380    FILE *fp;
1381
1382    struct re_filterfile_spec *new_bl, *bl = NULL;
1383    struct file_list *fs;
1384
1385    char  buf[BUFFER_SIZE];
1386    int error;
1387    unsigned long linenum = 0;
1388    pcrs_job *dummy, *lastjob = NULL;
1389
1390    /*
1391     * No need to reload if unchanged
1392     */
1393    if (!check_file_changed(current_re_filterfile[fileid], csp->config->re_filterfile[fileid], &fs))
1394    {
1395       if (csp)
1396       {
1397          csp->rlist[fileid] = current_re_filterfile[fileid];
1398       }
1399       return(0);
1400    }
1401    if (!fs)
1402    {
1403       goto load_re_filterfile_error;
1404    }
1405
1406    /* 
1407     * Open the file or fail
1408     */
1409    if ((fp = fopen(csp->config->re_filterfile[fileid], "r")) == NULL)
1410    {
1411       goto load_re_filterfile_error;
1412    }
1413
1414    /* 
1415     * Read line by line
1416     */
1417    while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1418    {
1419       /*
1420        * If this is the head of a new filter block, make it a
1421        * re_filterfile spec of its own and chain it to the list:
1422        */
1423       if (strncmp(buf, "FILTER:", 7) == 0)
1424       {
1425          new_bl = (struct re_filterfile_spec  *)zalloc(sizeof(*bl));
1426          if (new_bl == NULL)
1427          {
1428             goto load_re_filterfile_error;
1429          }
1430
1431          new_bl->name = chomp(buf + 7);
1432
1433          /*
1434           * If a filter description is available,
1435           * encode it to HTML and save it.
1436           */
1437          if (NULL != (new_bl->description = strpbrk(new_bl->name, " \t")))
1438          {
1439             *new_bl->description++ = '\0';
1440             new_bl->description = html_encode(chomp(new_bl->description));
1441             if (NULL == new_bl->description)
1442             {
1443                new_bl->description = strdup("Out of memory while encoding this filter's description to HTML");
1444             }
1445          }
1446          else
1447          {
1448             new_bl->description = strdup("No description available for this filter");
1449          }
1450
1451          new_bl->name = strdup(chomp(new_bl->name));
1452          
1453          /*
1454           * If this is the first filter block, chain it
1455           * to the file_list rather than its (nonexistant)
1456           * predecessor
1457           */
1458          if (fs->f == NULL)
1459          {
1460             fs->f = new_bl;
1461          }
1462          else
1463          {
1464             bl->next = new_bl;
1465          }
1466          bl = new_bl;
1467
1468          log_error(LOG_LEVEL_RE_FILTER, "Reading in filter \"%s\" (\"%s\")", bl->name, bl->description);
1469
1470          continue;
1471       }
1472
1473       /* 
1474        * Else, save the expression, make it a pcrs_job
1475        * and chain it into the current filter's joblist 
1476        */
1477       if (bl != NULL)
1478       {
1479          enlist(bl->patterns, buf);
1480
1481          if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
1482          {
1483             log_error(LOG_LEVEL_ERROR,
1484                       "Adding re_filter job %s to filter %s failed with error %d.", buf, bl->name, error);
1485             continue;
1486          }
1487          else
1488          {
1489             if (bl->joblist == NULL)
1490             {
1491                bl->joblist = dummy;
1492             }
1493             else
1494             {
1495                lastjob->next = dummy;
1496             }
1497             lastjob = dummy;
1498             log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s to filter %s succeeded.", buf, bl->name);
1499          }
1500       }
1501       else
1502       {
1503          log_error(LOG_LEVEL_ERROR, "Ignoring job %s outside filter block in %s, line %d",
1504             buf, csp->config->re_filterfile[fileid], linenum);
1505       }
1506    }
1507
1508    fclose(fp);
1509
1510    /* 
1511     * Schedule the now-obsolete old data for unloading
1512     */
1513    if ( NULL != current_re_filterfile[fileid] )
1514    {
1515       current_re_filterfile[fileid]->unloader = unload_re_filterfile;
1516    }
1517
1518    /*
1519     * Chain this file into the global list of loaded files
1520     */
1521    fs->next    = files->next;
1522    files->next = fs;
1523    current_re_filterfile[fileid] = fs;
1524
1525    if (csp)
1526    {
1527       csp->rlist[fileid] = fs;
1528    }
1529
1530    return( 0 );
1531
1532 load_re_filterfile_error:
1533    log_error(LOG_LEVEL_FATAL, "can't load re_filterfile '%s': %E",
1534              csp->config->re_filterfile[fileid]);
1535    return(-1);
1536
1537 }
1538
1539
1540 /*********************************************************************
1541  *
1542  * Function    :  add_loader
1543  *
1544  * Description :  Called from `load_config'.  Called once for each input
1545  *                file found in config.
1546  *
1547  * Parameters  :
1548  *          1  :  loader = pointer to a function that can parse and load
1549  *                the appropriate config file.
1550  *          2  :  config = The configuration_spec to add the loader to.
1551  *
1552  * Returns     :  N/A
1553  *
1554  *********************************************************************/
1555 void add_loader(int (*loader)(struct client_state *),
1556                 struct configuration_spec * config)
1557 {
1558    int i;
1559
1560    for (i=0; i < NLOADERS; i++)
1561    {
1562       if (config->loaders[i] == NULL)
1563       {
1564          config->loaders[i] = loader;
1565          break;
1566       }
1567    }
1568
1569 }
1570
1571
1572 /*********************************************************************
1573  *
1574  * Function    :  run_loader
1575  *
1576  * Description :  Called from `load_config' and `listen_loop'.  This
1577  *                function keeps the "csp" current with any file mods
1578  *                since the last loop.  If a file is unchanged, the
1579  *                loader functions do NOT reload the file.
1580  *
1581  * Parameters  :
1582  *          1  :  csp = Current client state (buffers, headers, etc...)
1583  *                      Must be non-null.  Reads: "csp->config"
1584  *                      Writes: various data members.
1585  *
1586  * Returns     :  0 => Ok, everything else is an error.
1587  *
1588  *********************************************************************/
1589 int run_loader(struct client_state *csp)
1590 {
1591    int ret = 0;
1592    int i;
1593
1594    for (i=0; i < NLOADERS; i++)
1595    {
1596       if (csp->config->loaders[i] == NULL)
1597       {
1598          break;
1599       }
1600       ret |= (csp->config->loaders[i])(csp);
1601    }
1602    return(ret);
1603
1604 }
1605
1606
1607 /*
1608   Local Variables:
1609   tab-width: 3
1610   end:
1611 */