1 const char loaders_rcs[] = "$Id: loaders.c,v 1.38 2002/03/06 22:54:35 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
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.
11 * Copyright : Written by and Copyright (C) 2001 the SourceForge
12 * IJBSWA team. http://ijbswa.sourceforge.net
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
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.
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.
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.
38 * Revision 1.38 2002/03/06 22:54:35 jongfoster
39 * Automated function-comment nitpicking.
41 * Revision 1.37 2002/03/03 15:07:49 oes
42 * Re-enabled automatic config reloading
44 * Revision 1.36 2002/01/22 23:46:18 jongfoster
45 * Moving edit_read_line() and simple_read_line() to loaders.c, and
46 * extending them to support reading MS-DOS, Mac and UNIX style files
49 * Modifying read_config_line() (without changing it's prototype) to
50 * be a trivial wrapper for edit_read_line(). This means that we have
51 * one function to read a line and handle comments, which is common
52 * between the initialization code and the edit interface.
54 * Revision 1.35 2002/01/17 21:03:08 jongfoster
55 * Moving all our URL and URL pattern parsing code to urlmatch.c.
57 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
59 * Revision 1.34 2001/12/30 14:07:32 steudten
60 * - Add signal handling (unix)
61 * - Add SIGHUP handler (unix)
62 * - Add creation of pidfile (unix)
63 * - Add action 'top' in rc file (RH)
64 * - Add entry 'SIGNALS' to manpage
65 * - Add exit message to logfile (unix)
67 * Revision 1.33 2001/11/13 00:16:38 jongfoster
68 * Replacing references to malloc.h with the standard stdlib.h
69 * (See ANSI or K&R 2nd Ed)
71 * Revision 1.32 2001/11/07 00:02:13 steudten
72 * Add line number in error output for lineparsing for
73 * actionsfile and configfile.
74 * Special handling for CLF added.
76 * Revision 1.31 2001/10/26 17:39:01 oes
77 * Removed csp->referrer
78 * Moved ijb_isspace and ijb_tolower to project.h
80 * Revision 1.30 2001/10/25 03:40:48 david__schmidt
81 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
82 * threads to call select() simultaneously. So, it's time to do a real, live,
83 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
84 * (native). Both versions will work, but using __OS2__ offers multi-threading.
86 * Revision 1.29 2001/10/23 21:38:53 jongfoster
87 * Adding error-checking to create_url_spec()
89 * Revision 1.28 2001/10/07 15:40:39 oes
90 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
92 * Revision 1.27 2001/09/22 16:36:59 jongfoster
93 * Removing unused parameter fs from read_config_line()
95 * Revision 1.26 2001/09/22 14:05:22 jongfoster
96 * Bugfix: Multiple escaped "#" characters in a configuration
97 * file are now permitted.
98 * Also removing 3 unused headers.
100 * Revision 1.25 2001/09/13 22:44:03 jongfoster
101 * Adding {} to an if statement
103 * Revision 1.24 2001/07/30 22:08:36 jongfoster
104 * Tidying up #defines:
105 * - All feature #defines are now of the form FEATURE_xxx
106 * - Permanently turned off WIN_GUI_EDIT
107 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
109 * Revision 1.23 2001/07/20 15:51:54 oes
110 * Fixed indentation of prepocessor commands
112 * Revision 1.22 2001/07/20 15:16:17 haroon
113 * - per Guy's suggestion, added a while loop in sweep() to catch not just
114 * the last inactive CSP but all other consecutive inactive CSPs after that
117 * Revision 1.21 2001/07/18 17:26:24 oes
118 * Changed to conform to new pcrs interface
120 * Revision 1.20 2001/07/17 13:07:01 oes
121 * Fixed segv when last line in config files
122 * lacked a terminating (\r)\n
124 * Revision 1.19 2001/07/13 14:01:54 oes
125 * Removed all #ifdef PCRS
127 * Revision 1.18 2001/06/29 21:45:41 oes
128 * Indentation, CRLF->LF, Tab-> Space
130 * Revision 1.17 2001/06/29 13:31:51 oes
133 * Revision 1.16 2001/06/09 10:55:28 jongfoster
134 * Changing BUFSIZ ==> BUFFER_SIZE
136 * Revision 1.15 2001/06/07 23:14:14 jongfoster
137 * Removing ACL and forward file loaders - these
138 * files have been merged into the config file.
139 * Cosmetic: Moving unloader funcs next to their
140 * respective loader funcs
142 * Revision 1.14 2001/06/01 03:27:04 oes
143 * Fixed line continuation problem
145 * Revision 1.13 2001/05/31 21:28:49 jongfoster
146 * Removed all permissionsfile code - it's now called the actions
147 * file, and (almost) all the code is in actions.c
149 * Revision 1.12 2001/05/31 17:32:31 oes
151 * - Enhanced domain part globbing with infix and prefix asterisk
152 * matching and optional unanchored operation
154 * Revision 1.11 2001/05/29 23:25:24 oes
156 * - load_config_line() and load_permissions_file() now use chomp()
158 * Revision 1.10 2001/05/29 09:50:24 jongfoster
159 * Unified blocklist/imagelist/permissionslist.
160 * File format is still under discussion, but the internal changes
163 * Also modified interceptor behaviour:
164 * - We now intercept all URLs beginning with one of the following
165 * prefixes (and *only* these prefixes):
167 * * http://ijbswa.sf.net/config/
168 * * http://ijbswa.sourceforge.net/config/
169 * - New interceptors "home page" - go to http://i.j.b/ to see it.
170 * - Internal changes so that intercepted and fast redirect pages
171 * are not replaced with an image.
172 * - Interceptors now have the option to send a binary page direct
173 * to the client. (i.e. ijb-send-banner uses this)
174 * - Implemented show-url-info interceptor. (Which is why I needed
175 * the above interceptors changes - a typical URL is
176 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
177 * The previous mechanism would not have intercepted that, and
178 * if it had been intercepted then it then it would have replaced
181 * Revision 1.9 2001/05/26 17:12:07 jongfoster
182 * Fatal errors loading configuration files now give better error messages.
184 * Revision 1.8 2001/05/26 00:55:20 jongfoster
185 * Removing duplicated code. load_forwardfile() now uses create_url_spec()
187 * Revision 1.7 2001/05/26 00:28:36 jongfoster
188 * Automatic reloading of config file.
189 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
190 * Most of the global variables have been moved to a new
191 * struct configuration_spec, accessed through csp->config->globalname
192 * Most of the globals remaining are used by the Win32 GUI.
194 * Revision 1.6 2001/05/23 12:27:33 oes
196 * Fixed ugly indentation of my last changes
198 * Revision 1.5 2001/05/23 10:39:05 oes
199 * - Added support for escaping the comment character
200 * in config files by a backslash
201 * - Added support for line continuation in config
203 * - Fixed a buffer overflow bug with long config lines
205 * Revision 1.4 2001/05/22 18:56:28 oes
208 * Revision 1.3 2001/05/20 01:21:20 jongfoster
209 * Version 2.9.4 checkin.
210 * - Merged popupfile and cookiefile, and added control over PCRS
211 * filtering, in new "permissionsfile".
212 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
213 * file error you now get a message box (in the Win32 GUI) rather
214 * than the program exiting with no explanation.
215 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
217 * - Removed tabs from "config"
218 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
219 * - Bumped up version number.
221 * Revision 1.2 2001/05/17 23:01:01 oes
222 * - Cleaned CRLF's from the sources and related files
224 * Revision 1.1.1.1 2001/05/15 13:58:59 oes
225 * Initial import of version 2.9.3 source tree
228 *********************************************************************/
235 #include <sys/types.h>
238 #include <sys/stat.h>
242 #if !defined(_WIN32) && !defined(__OS2__)
252 #include "miscutil.h"
255 #include "urlmatch.h"
257 const char loaders_h_rcs[] = LOADERS_H_VERSION;
260 * Currently active files.
261 * These are also entered in the main linked list of files.
265 static struct file_list *current_trustfile = NULL;
266 #endif /* def FEATURE_TRUST */
268 static struct file_list *current_re_filterfile = NULL;
272 /*********************************************************************
276 * Description : Basically a mark and sweep garbage collector, it is run
277 * (by the parent thread) every once in a while to reclaim memory.
279 * It uses a mark and sweep strategy:
280 * 1) mark all files as inactive
282 * 2) check with each client:
283 * if it is active, mark its files as active
284 * if it is inactive, free its resources
286 * 3) free the resources of all of the files that
287 * are still marked as inactive (and are obsolete).
289 * N.B. files that are not obsolete don't have an unloader defined.
295 *********************************************************************/
298 struct file_list *fl, *nfl;
299 struct client_state *csp, *ncsp;
301 /* clear all of the file's active flags */
302 for ( fl = files->next; NULL != fl; fl = fl->next )
307 for (csp = clients; csp && (ncsp = csp->next) ; csp = csp->next)
309 if (ncsp->flags & CSP_FLAG_ACTIVE)
311 /* mark this client's files as active */
314 * Always have a configuration file.
315 * (Also note the slightly non-standard extra
318 ncsp->config->config_file_list->active = 1;
320 if (ncsp->actions_list) /* actions files */
322 ncsp->actions_list->active = 1;
325 if (ncsp->rlist) /* pcrsjob files */
327 ncsp->rlist->active = 1;
331 if (ncsp->tlist) /* trust files */
333 ncsp->tlist->active = 1;
335 #endif /* def FEATURE_TRUST */
340 * this client is not active, release its resources
341 * and the ones of all inactive clients that might
345 while (!(ncsp->flags & CSP_FLAG_ACTIVE))
347 csp->next = ncsp->next;
349 freez(ncsp->ip_addr_str);
350 freez(ncsp->my_ip_addr_str);
351 freez(ncsp->my_hostname);
352 freez(ncsp->x_forwarded);
353 freez(ncsp->iob->buf);
355 free_http_request(ncsp->http);
357 destroy_list(ncsp->headers);
358 destroy_list(ncsp->cookie_list);
360 free_current_action(ncsp->action);
362 #ifdef FEATURE_STATISTICS
364 if (ncsp->flags & CSP_FLAG_REJECTED)
368 #endif /* def FEATURE_STATISTICS */
372 /* are there any more in sequence after it? */
373 if( !(ncsp = csp->next) )
379 for (fl = files; fl && (nfl = fl->next) ; fl = fl->next)
381 if ( ( 0 == nfl->active ) && ( NULL != nfl->unloader ) )
383 fl->next = nfl->next;
385 (nfl->unloader)(nfl->f);
387 freez(nfl->filename);
396 /*********************************************************************
398 * Function : check_file_changed
400 * Description : Helper function to check if a file needs reloading.
401 * If "current" is still current, return it. Otherwise
402 * allocates a new (zeroed) "struct file_list", fills
403 * in the disk file name and timestamp, and returns it.
406 * 1 : current = The file_list currently being used - will
407 * be checked to see if it is out of date.
408 * May be NULL (which is treated as out of
410 * 2 : filename = Name of file to check.
411 * 3 : newfl = New file list. [Output only]
412 * This will be set to NULL, OR a struct
413 * file_list newly allocated on the
414 * heap, with the filename and lastmodified
415 * fields filled, and all others zeroed.
417 * Returns : If file unchanged: 0 (and sets newfl == NULL)
418 * If file changed: 1 and sets newfl != NULL
419 * On error: 1 and sets newfl == NULL
421 *********************************************************************/
422 int check_file_changed(const struct file_list * current,
423 const char * filename,
424 struct file_list ** newfl)
426 struct file_list *fs;
427 struct stat statbuf[1];
431 if (stat(filename, statbuf) < 0)
433 /* Error, probably file not found. */
438 && (current->lastmodified == statbuf->st_mtime)
439 && (0 == strcmp(current->filename, filename)))
444 fs = (struct file_list *)zalloc(sizeof(struct file_list));
447 /* Out of memory error */
451 fs->filename = strdup(filename);
452 fs->lastmodified = statbuf->st_mtime;
454 if (fs->filename == NULL)
456 /* Out of memory error */
465 /*********************************************************************
467 * Function : simple_read_line
469 * Description : Read a single line from a file and return it.
470 * This is basically a version of fgets() that malloc()s
471 * it's own line buffer. Note that the buffer will
472 * always be a multiple of BUFFER_SIZE bytes long.
473 * Therefore if you are going to keep the string for
474 * an extended period of time, you should probably
475 * strdup() it and free() the original, to save memory.
479 * 1 : dest = destination for newly malloc'd pointer to
480 * line data. Will be set to NULL on error.
481 * 2 : fp = File to read from
482 * 3 : newline = Standard for newlines in the file.
483 * Will be unchanged if it's value on input is not
485 * On output, may be changed from NEWLINE_UNKNOWN to
486 * actual convention in file.
488 * Returns : JB_ERR_OK on success
489 * JB_ERR_MEMORY on out-of-memory
490 * JB_ERR_FILE on EOF.
492 *********************************************************************/
493 jb_err simple_read_line(FILE *fp, char **dest, int *newline)
496 size_t buflen = BUFFER_SIZE;
500 int realnewline = NEWLINE_UNKNOWN;
502 if (NULL == (buf = malloc(buflen)))
504 return JB_ERR_MEMORY;
510 * Character codes. If you have a wierd compiler and the following are
511 * incorrect, you also need to fix NEWLINE() in loaders.h
513 #define CHAR_CR '\r' /* ASCII 13 */
514 #define CHAR_LF '\n' /* ASCII 10 */
534 else if (ch == CHAR_CR)
539 if (*newline == NEWLINE_UNKNOWN)
541 *newline = NEWLINE_DOS;
550 if (*newline == NEWLINE_UNKNOWN)
552 *newline = NEWLINE_MAC;
557 if (*newline == NEWLINE_UNKNOWN)
559 *newline = realnewline;
563 else if (ch == CHAR_LF)
567 if (*newline == NEWLINE_UNKNOWN)
569 *newline = NEWLINE_UNIX;
584 buflen += BUFFER_SIZE;
585 if (NULL == (p = realloc(buf, buflen)));
588 return JB_ERR_MEMORY;
597 /*********************************************************************
599 * Function : edit_read_line
601 * Description : Read a single non-empty line from a file and return
602 * it. Trims comments, leading and trailing whitespace
603 * and respects escaping of newline and comment char.
604 * Provides the line in 2 alternative forms: raw and
606 * - raw is the raw data read from the file. If the
607 * line is not modified, then this should be written
609 * - prefix is any comments and blank lines that were
610 * read from the file. If the line is modified, then
611 * this should be written out to the file followed
612 * by the modified data. (If this string is non-empty
613 * then it will have a newline at the end).
614 * - data is the actual data that will be parsed
615 * further by appropriate routines.
616 * On EOF, the 3 strings will all be set to NULL and
617 * 0 will be returned.
620 * 1 : fp = File to read from
621 * 2 : raw_out = destination for newly malloc'd pointer to
622 * raw line data. May be NULL if you don't want it.
623 * 3 : prefix_out = destination for newly malloc'd pointer to
624 * comments. May be NULL if you don't want it.
625 * 4 : data_out = destination for newly malloc'd pointer to
626 * line data with comments and leading/trailing spaces
627 * removed, and line continuation performed. May be
628 * NULL if you don't want it.
629 * 5 : newline = Standard for newlines in the file.
630 * On input, set to value to use or NEWLINE_UNKNOWN.
631 * On output, may be changed from NEWLINE_UNKNOWN to
632 * actual convention in file. May be NULL if you
634 * 6 : line_number = Line number in file. In "lines" as
635 * reported by a text editor, not lines containing data.
637 * Returns : JB_ERR_OK on success
638 * JB_ERR_MEMORY on out-of-memory
639 * JB_ERR_FILE on EOF.
641 *********************************************************************/
642 jb_err edit_read_line(FILE *fp,
647 unsigned long *line_number)
649 char *p; /* Temporary pointer */
650 char *linebuf; /* Line read from file */
651 char *linestart; /* Start of linebuf, usually first non-whitespace char */
652 int contflag = 0; /* Nonzero for line continuation - i.e. line ends '\' */
653 int is_empty = 1; /* Flag if not got any data yet */
654 char *raw = NULL; /* String to be stored in raw_out */
655 char *prefix = NULL; /* String to be stored in prefix_out */
656 char *data = NULL; /* String to be stored in data_out */
657 int scrapnewline; /* Used for (*newline) if newline==NULL */
658 jb_err rval = JB_ERR_OK;
661 assert(raw_out || data_out);
662 assert(newline == NULL
663 || *newline == NEWLINE_UNKNOWN
664 || *newline == NEWLINE_UNIX
665 || *newline == NEWLINE_DOS
666 || *newline == NEWLINE_MAC);
670 scrapnewline = NEWLINE_UNKNOWN;
671 newline = &scrapnewline;
674 /* Set output parameters to NULL */
688 /* Set string variables to new, empty strings. */
692 if ((raw = malloc(1)) == NULL)
694 return JB_ERR_MEMORY;
700 if ((prefix = malloc(1)) == NULL)
703 return JB_ERR_MEMORY;
709 if ((data = malloc(1)) == NULL)
713 return JB_ERR_MEMORY;
718 /* Main loop. Loop while we need more data & it's not EOF. */
720 while ( (contflag || is_empty)
721 && (JB_ERR_OK == (rval = simple_read_line(fp, &linebuf, newline))))
729 string_append(&raw,linebuf);
730 if (string_append(&raw,NEWLINE(*newline)))
735 return JB_ERR_MEMORY;
739 /* Line continuation? Trim escape and set flag. */
740 p = linebuf + strlen(linebuf) - 1;
741 contflag = ((*linebuf != '\0') && (*p == '\\'));
747 /* Trim leading spaces if we're at the start of the line */
751 /* Trim leading spaces */
752 while (*linestart && isspace((int)(unsigned char)*linestart))
758 /* Handle comment characters. */
760 while ((p = strchr(p, '#')) != NULL)
762 /* Found a comment char.. */
763 if ((p != linebuf) && (*(p-1) == '\\'))
765 /* ..and it's escaped, left-shift the line over the escape. */
767 while ((*q = *(q + 1)) != '\0')
771 /* Now scan from just after the "#". */
775 /* Real comment. Save it... */
778 /* Special case: Line only contains a comment, so all the
779 * previous whitespace is considered part of the comment.
780 * Undo the whitespace skipping, if any.
787 string_append(&prefix,p);
788 if (string_append(&prefix, NEWLINE(*newline)))
793 return JB_ERR_MEMORY;
797 /* ... and chop off the rest of the line */
800 } /* END while (there's a # character) */
802 /* Write to the buffer */
808 if (string_append(&data, linestart))
813 return JB_ERR_MEMORY;
819 } /* END while(we need more data) */
821 /* Handle simple_read_line() errors - ignore EOF */
822 if ((rval != JB_ERR_OK) && (rval != JB_ERR_FILE))
830 if (raw ? (*raw == '\0') : is_empty)
832 /* EOF and no data there. (Definition of "data" depends on whether
833 * the caller cares about "raw" or just "data").
844 /* Got at least some data */
846 /* Remove trailing whitespace */
859 *prefix_out = prefix;
878 /*********************************************************************
880 * Function : read_config_line
882 * Description : Read a single non-empty line from a file and return
883 * it. Trims comments, leading and trailing whitespace
884 * and respects escaping of newline and comment char.
887 * 1 : buf = Buffer to use.
888 * 2 : buflen = Size of buffer in bytes.
889 * 3 : fp = File to read from
890 * 4 : linenum = linenumber in file
892 * Returns : NULL on EOF or error
893 * Otherwise, returns buf.
895 *********************************************************************/
896 char *read_config_line(char *buf, size_t buflen, FILE *fp, unsigned long *linenum)
900 err = edit_read_line(fp, NULL, NULL, &buf2, NULL, linenum);
903 if (err == JB_ERR_MEMORY)
905 log_error(LOG_LEVEL_FATAL, "Out of memory loading a config file");
912 assert(strlen(buf2) + 1U < buflen);
913 strncpy(buf, buf2, buflen - 1);
915 buf[buflen - 1] = '\0';
922 /*********************************************************************
924 * Function : unload_trustfile
926 * Description : Unloads a trustfile.
929 * 1 : f = the data structure associated with the trustfile.
933 *********************************************************************/
934 static void unload_trustfile(void *f)
936 struct block_spec *b = (struct block_spec *)f;
937 if (b == NULL) return;
939 unload_trustfile(b->next); /* Stack is cheap, isn't it? */
941 free_url_spec(b->url);
948 /*********************************************************************
950 * Function : load_trustfile
952 * Description : Read and parse a trustfile and add to files list.
955 * 1 : csp = Current client state (buffers, headers, etc...)
957 * Returns : 0 => Ok, everything else is an error.
959 *********************************************************************/
960 int load_trustfile(struct client_state *csp)
964 struct block_spec *b, *bl;
965 struct url_spec **tl;
967 char buf[BUFFER_SIZE], *p, *q;
969 struct file_list *fs;
970 unsigned long linenum = 0;
972 if (!check_file_changed(current_trustfile, csp->config->trustfile, &fs))
974 /* No need to load */
977 csp->tlist = current_trustfile;
983 goto load_trustfile_error;
986 fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
989 goto load_trustfile_error;
992 if ((fp = fopen(csp->config->trustfile, "r")) == NULL)
994 goto load_trustfile_error;
997 tl = csp->config->trust_list;
999 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1015 while ((*p++ = *q++))
1021 /* skip blank lines */
1027 /* allocate a new node */
1028 if ((b = zalloc(sizeof(*b))) == NULL)
1031 goto load_trustfile_error;
1034 /* add it to the list */
1040 /* Save the URL pattern */
1041 if (create_url_spec(b->url, buf))
1044 goto load_trustfile_error;
1048 * save a pointer to URL's spec in the list of trusted URL's, too
1053 /* FIXME BUFFER OVERFLOW if >=64 entries */
1061 /* the old one is now obsolete */
1062 if (current_trustfile)
1064 current_trustfile->unloader = unload_trustfile;
1067 fs->next = files->next;
1069 current_trustfile = fs;
1078 load_trustfile_error:
1079 log_error(LOG_LEVEL_FATAL, "can't load trustfile '%s': %E",
1080 csp->config->trustfile);
1084 #endif /* def FEATURE_TRUST */
1087 /*********************************************************************
1089 * Function : unload_re_filterfile
1091 * Description : Unload the re_filter list.
1094 * 1 : f = the data structure associated with the filterfile.
1098 *********************************************************************/
1099 static void unload_re_filterfile(void *f)
1101 struct re_filterfile_spec *b = (struct re_filterfile_spec *)f;
1108 destroy_list(b->patterns);
1109 pcrs_free_joblist(b->joblist);
1115 /*********************************************************************
1117 * Function : load_re_filterfile
1119 * Description : Load the re_filterfile. Each non-comment, non-empty
1120 * line is instantly added to the joblist, which is
1121 * a chained list of pcrs_job structs.
1124 * 1 : csp = Current client state (buffers, headers, etc...)
1126 * Returns : 0 => Ok, everything else is an error.
1128 *********************************************************************/
1129 int load_re_filterfile(struct client_state *csp)
1133 struct re_filterfile_spec *bl;
1134 struct file_list *fs;
1136 char buf[BUFFER_SIZE];
1138 unsigned long linenum = 0;
1141 if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs))
1143 /* No need to load */
1146 csp->rlist = current_re_filterfile;
1152 goto load_re_filterfile_error;
1155 fs->f = bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl));
1158 goto load_re_filterfile_error;
1161 /* Open the file or fail */
1162 if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL)
1164 goto load_re_filterfile_error;
1167 /* Read line by line */
1168 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1170 enlist( bl->patterns, buf );
1172 /* We have a meaningful line -> make it a job */
1173 if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
1175 log_error(LOG_LEVEL_RE_FILTER,
1176 "Adding re_filter job %s failed with error %d.", buf, error);
1181 dummy->next = bl->joblist;
1182 bl->joblist = dummy;
1183 log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s succeeded.", buf);
1189 /* the old one is now obsolete */
1190 if ( NULL != current_re_filterfile )
1192 current_re_filterfile->unloader = unload_re_filterfile;
1195 fs->next = files->next;
1197 current_re_filterfile = fs;
1206 load_re_filterfile_error:
1207 log_error(LOG_LEVEL_FATAL, "can't load re_filterfile '%s': %E",
1208 csp->config->re_filterfile);
1214 /*********************************************************************
1216 * Function : add_loader
1218 * Description : Called from `load_config'. Called once for each input
1219 * file found in config.
1222 * 1 : loader = pointer to a function that can parse and load
1223 * the appropriate config file.
1224 * 2 : config = The configuration_spec to add the loader to.
1228 *********************************************************************/
1229 void add_loader(int (*loader)(struct client_state *),
1230 struct configuration_spec * config)
1234 for (i=0; i < NLOADERS; i++)
1236 if (config->loaders[i] == NULL)
1238 config->loaders[i] = loader;
1246 /*********************************************************************
1248 * Function : run_loader
1250 * Description : Called from `load_config' and `listen_loop'. This
1251 * function keeps the "csp" current with any file mods
1252 * since the last loop. If a file is unchanged, the
1253 * loader functions do NOT reload the file.
1256 * 1 : csp = Current client state (buffers, headers, etc...)
1257 * Must be non-null. Reads: "csp->config"
1258 * Writes: various data members.
1260 * Returns : 0 => Ok, everything else is an error.
1262 *********************************************************************/
1263 int run_loader(struct client_state *csp)
1268 for (i=0; i < NLOADERS; i++)
1270 if (csp->config->loaders[i] == NULL)
1274 ret |= (csp->config->loaders[i])(csp);