1 const char loaders_rcs[] = "$Id: loaders.c,v 1.35 2002/01/17 21:03:08 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.35 2002/01/17 21:03:08 jongfoster
39 * Moving all our URL and URL pattern parsing code to urlmatch.c.
41 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
43 * Revision 1.34 2001/12/30 14:07:32 steudten
44 * - Add signal handling (unix)
45 * - Add SIGHUP handler (unix)
46 * - Add creation of pidfile (unix)
47 * - Add action 'top' in rc file (RH)
48 * - Add entry 'SIGNALS' to manpage
49 * - Add exit message to logfile (unix)
51 * Revision 1.33 2001/11/13 00:16:38 jongfoster
52 * Replacing references to malloc.h with the standard stdlib.h
53 * (See ANSI or K&R 2nd Ed)
55 * Revision 1.32 2001/11/07 00:02:13 steudten
56 * Add line number in error output for lineparsing for
57 * actionsfile and configfile.
58 * Special handling for CLF added.
60 * Revision 1.31 2001/10/26 17:39:01 oes
61 * Removed csp->referrer
62 * Moved ijb_isspace and ijb_tolower to project.h
64 * Revision 1.30 2001/10/25 03:40:48 david__schmidt
65 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
66 * threads to call select() simultaneously. So, it's time to do a real, live,
67 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
68 * (native). Both versions will work, but using __OS2__ offers multi-threading.
70 * Revision 1.29 2001/10/23 21:38:53 jongfoster
71 * Adding error-checking to create_url_spec()
73 * Revision 1.28 2001/10/07 15:40:39 oes
74 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
76 * Revision 1.27 2001/09/22 16:36:59 jongfoster
77 * Removing unused parameter fs from read_config_line()
79 * Revision 1.26 2001/09/22 14:05:22 jongfoster
80 * Bugfix: Multiple escaped "#" characters in a configuration
81 * file are now permitted.
82 * Also removing 3 unused headers.
84 * Revision 1.25 2001/09/13 22:44:03 jongfoster
85 * Adding {} to an if statement
87 * Revision 1.24 2001/07/30 22:08:36 jongfoster
88 * Tidying up #defines:
89 * - All feature #defines are now of the form FEATURE_xxx
90 * - Permanently turned off WIN_GUI_EDIT
91 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
93 * Revision 1.23 2001/07/20 15:51:54 oes
94 * Fixed indentation of prepocessor commands
96 * Revision 1.22 2001/07/20 15:16:17 haroon
97 * - per Guy's suggestion, added a while loop in sweep() to catch not just
98 * the last inactive CSP but all other consecutive inactive CSPs after that
101 * Revision 1.21 2001/07/18 17:26:24 oes
102 * Changed to conform to new pcrs interface
104 * Revision 1.20 2001/07/17 13:07:01 oes
105 * Fixed segv when last line in config files
106 * lacked a terminating (\r)\n
108 * Revision 1.19 2001/07/13 14:01:54 oes
109 * Removed all #ifdef PCRS
111 * Revision 1.18 2001/06/29 21:45:41 oes
112 * Indentation, CRLF->LF, Tab-> Space
114 * Revision 1.17 2001/06/29 13:31:51 oes
117 * Revision 1.16 2001/06/09 10:55:28 jongfoster
118 * Changing BUFSIZ ==> BUFFER_SIZE
120 * Revision 1.15 2001/06/07 23:14:14 jongfoster
121 * Removing ACL and forward file loaders - these
122 * files have been merged into the config file.
123 * Cosmetic: Moving unloader funcs next to their
124 * respective loader funcs
126 * Revision 1.14 2001/06/01 03:27:04 oes
127 * Fixed line continuation problem
129 * Revision 1.13 2001/05/31 21:28:49 jongfoster
130 * Removed all permissionsfile code - it's now called the actions
131 * file, and (almost) all the code is in actions.c
133 * Revision 1.12 2001/05/31 17:32:31 oes
135 * - Enhanced domain part globbing with infix and prefix asterisk
136 * matching and optional unanchored operation
138 * Revision 1.11 2001/05/29 23:25:24 oes
140 * - load_config_line() and load_permissions_file() now use chomp()
142 * Revision 1.10 2001/05/29 09:50:24 jongfoster
143 * Unified blocklist/imagelist/permissionslist.
144 * File format is still under discussion, but the internal changes
147 * Also modified interceptor behaviour:
148 * - We now intercept all URLs beginning with one of the following
149 * prefixes (and *only* these prefixes):
151 * * http://ijbswa.sf.net/config/
152 * * http://ijbswa.sourceforge.net/config/
153 * - New interceptors "home page" - go to http://i.j.b/ to see it.
154 * - Internal changes so that intercepted and fast redirect pages
155 * are not replaced with an image.
156 * - Interceptors now have the option to send a binary page direct
157 * to the client. (i.e. ijb-send-banner uses this)
158 * - Implemented show-url-info interceptor. (Which is why I needed
159 * the above interceptors changes - a typical URL is
160 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
161 * The previous mechanism would not have intercepted that, and
162 * if it had been intercepted then it then it would have replaced
165 * Revision 1.9 2001/05/26 17:12:07 jongfoster
166 * Fatal errors loading configuration files now give better error messages.
168 * Revision 1.8 2001/05/26 00:55:20 jongfoster
169 * Removing duplicated code. load_forwardfile() now uses create_url_spec()
171 * Revision 1.7 2001/05/26 00:28:36 jongfoster
172 * Automatic reloading of config file.
173 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
174 * Most of the global variables have been moved to a new
175 * struct configuration_spec, accessed through csp->config->globalname
176 * Most of the globals remaining are used by the Win32 GUI.
178 * Revision 1.6 2001/05/23 12:27:33 oes
180 * Fixed ugly indentation of my last changes
182 * Revision 1.5 2001/05/23 10:39:05 oes
183 * - Added support for escaping the comment character
184 * in config files by a backslash
185 * - Added support for line continuation in config
187 * - Fixed a buffer overflow bug with long config lines
189 * Revision 1.4 2001/05/22 18:56:28 oes
192 * Revision 1.3 2001/05/20 01:21:20 jongfoster
193 * Version 2.9.4 checkin.
194 * - Merged popupfile and cookiefile, and added control over PCRS
195 * filtering, in new "permissionsfile".
196 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
197 * file error you now get a message box (in the Win32 GUI) rather
198 * than the program exiting with no explanation.
199 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
201 * - Removed tabs from "config"
202 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
203 * - Bumped up version number.
205 * Revision 1.2 2001/05/17 23:01:01 oes
206 * - Cleaned CRLF's from the sources and related files
208 * Revision 1.1.1.1 2001/05/15 13:58:59 oes
209 * Initial import of version 2.9.3 source tree
212 *********************************************************************/
219 #include <sys/types.h>
222 #include <sys/stat.h>
226 #if !defined(_WIN32) && !defined(__OS2__)
236 #include "miscutil.h"
239 #include "urlmatch.h"
241 const char loaders_h_rcs[] = LOADERS_H_VERSION;
244 * Currently active files.
245 * These are also entered in the main linked list of files.
249 static struct file_list *current_trustfile = NULL;
250 #endif /* def FEATURE_TRUST */
252 static struct file_list *current_re_filterfile = NULL;
256 /*********************************************************************
260 * Description : Basically a mark and sweep garbage collector, it is run
261 * (by the parent thread) every once in a while to reclaim memory.
263 * It uses a mark and sweep strategy:
264 * 1) mark all files as inactive
266 * 2) check with each client:
267 * if it is active, mark its files as active
268 * if it is inactive, free its resources
270 * 3) free the resources of all of the files that
271 * are still marked as inactive (and are obsolete).
273 * N.B. files that are not obsolete don't have an unloader defined.
279 *********************************************************************/
282 struct file_list *fl, *nfl;
283 struct client_state *csp, *ncsp;
285 /* clear all of the file's active flags */
286 for ( fl = files->next; NULL != fl; fl = fl->next )
291 for (csp = clients; csp && (ncsp = csp->next) ; csp = csp->next)
293 if (ncsp->flags & CSP_FLAG_ACTIVE)
295 /* mark this client's files as active */
298 * Always have a configuration file.
299 * (Also note the slightly non-standard extra
302 ncsp->config->config_file_list->active = 1;
304 if (ncsp->actions_list) /* actions files */
306 ncsp->actions_list->active = 1;
309 if (ncsp->rlist) /* pcrsjob files */
311 ncsp->rlist->active = 1;
315 if (ncsp->tlist) /* trust files */
317 ncsp->tlist->active = 1;
319 #endif /* def FEATURE_TRUST */
324 * this client is not active, release its resources
325 * and the ones of all inactive clients that might
329 while (!(ncsp->flags & CSP_FLAG_ACTIVE))
331 csp->next = ncsp->next;
333 freez(ncsp->ip_addr_str);
334 freez(ncsp->my_ip_addr_str);
335 freez(ncsp->my_hostname);
336 freez(ncsp->x_forwarded);
337 freez(ncsp->iob->buf);
339 free_http_request(ncsp->http);
341 destroy_list(ncsp->headers);
342 destroy_list(ncsp->cookie_list);
344 free_current_action(ncsp->action);
346 #ifdef FEATURE_STATISTICS
348 if (ncsp->flags & CSP_FLAG_REJECTED)
352 #endif /* def FEATURE_STATISTICS */
356 /* are there any more in sequence after it? */
357 if( !(ncsp = csp->next) )
363 for (fl = files; fl && (nfl = fl->next) ; fl = fl->next)
365 if ( ( 0 == nfl->active ) && ( NULL != nfl->unloader ) )
367 fl->next = nfl->next;
369 (nfl->unloader)(nfl->f);
371 freez(nfl->filename);
380 /*********************************************************************
382 * Function : check_file_changed
384 * Description : Helper function to check if a file needs reloading.
385 * If "current" is still current, return it. Otherwise
386 * allocates a new (zeroed) "struct file_list", fills
387 * in the disk file name and timestamp, and returns it.
390 * 1 : current = The file_list currently being used - will
391 * be checked to see if it is out of date.
392 * May be NULL (which is treated as out of
394 * 2 : filename = Name of file to check.
395 * 3 : newfl = New file list. [Output only]
396 * This will be set to NULL, OR a struct
397 * file_list newly allocated on the
398 * heap, with the filename and lastmodified
399 * fields filled, and all others zeroed.
401 * Returns : If file unchanged: 0 (and sets newfl == NULL)
402 * If file changed: 1 and sets newfl != NULL
403 * On error: 1 and sets newfl == NULL
405 *********************************************************************/
406 int check_file_changed(const struct file_list * current,
407 const char * filename,
408 struct file_list ** newfl)
410 struct file_list *fs;
411 struct stat statbuf[1];
415 if (stat(filename, statbuf) < 0)
417 /* Error, probably file not found. */
422 && (current->lastmodified == statbuf->st_mtime)
423 && (0 == strcmp(current->filename, filename)))
425 /* force reload of configfile and all the logs */
426 if ( !MustReload ) return 0;
429 fs = (struct file_list *)zalloc(sizeof(struct file_list));
432 /* Out of memory error */
436 fs->filename = strdup(filename);
437 fs->lastmodified = statbuf->st_mtime;
439 if (fs->filename == NULL)
441 /* Out of memory error */
450 /*********************************************************************
452 * Function : simple_read_line
454 * Description : Read a single line from a file and return it.
455 * This is basically a version of fgets() that malloc()s
456 * it's own line buffer. Note that the buffer will
457 * always be a multiple of BUFFER_SIZE bytes long.
458 * Therefore if you are going to keep the string for
459 * an extended period of time, you should probably
460 * strdup() it and free() the original, to save memory.
464 * 1 : dest = destination for newly malloc'd pointer to
465 * line data. Will be set to NULL on error.
466 * 2 : fp = File to read from
467 * 3 : newline = Standard for newlines in the file.
468 * Will be unchanged if it's value on input is not
470 * On output, may be changed from NEWLINE_UNKNOWN to
471 * actual convention in file.
473 * Returns : JB_ERR_OK on success
474 * JB_ERR_MEMORY on out-of-memory
475 * JB_ERR_FILE on EOF.
477 *********************************************************************/
478 jb_err simple_read_line(FILE *fp, char **dest, int *newline)
481 int buflen = BUFFER_SIZE;
485 int realnewline = NEWLINE_UNKNOWN;
487 if (NULL == (buf = malloc(buflen)))
489 return JB_ERR_MEMORY;
495 * Character codes. If you have a wierd compiler and the following are
496 * incorrect, you also need to fix NEWLINE() in loaders.h
498 #define CHAR_CR '\r' /* ASCII 13 */
499 #define CHAR_LF '\n' /* ASCII 10 */
519 else if (ch == CHAR_CR)
524 if (*newline == NEWLINE_UNKNOWN)
526 *newline = NEWLINE_DOS;
535 if (*newline == NEWLINE_UNKNOWN)
537 *newline = NEWLINE_MAC;
542 if (*newline == NEWLINE_UNKNOWN)
544 *newline = realnewline;
548 else if (ch == CHAR_LF)
552 if (*newline == NEWLINE_UNKNOWN)
554 *newline = NEWLINE_UNIX;
569 buflen += BUFFER_SIZE;
570 if (NULL == (p = realloc(buf, buflen)));
573 return JB_ERR_MEMORY;
582 /*********************************************************************
584 * Function : edit_read_line
586 * Description : Read a single non-empty line from a file and return
587 * it. Trims comments, leading and trailing whitespace
588 * and respects escaping of newline and comment char.
589 * Provides the line in 2 alternative forms: raw and
591 * - raw is the raw data read from the file. If the
592 * line is not modified, then this should be written
594 * - prefix is any comments and blank lines that were
595 * read from the file. If the line is modified, then
596 * this should be written out to the file followed
597 * by the modified data. (If this string is non-empty
598 * then it will have a newline at the end).
599 * - data is the actual data that will be parsed
600 * further by appropriate routines.
601 * On EOF, the 3 strings will all be set to NULL and
602 * 0 will be returned.
605 * 1 : fp = File to read from
606 * 2 : raw_out = destination for newly malloc'd pointer to
607 * raw line data. May be NULL if you don't want it.
608 * 3 : prefix_out = destination for newly malloc'd pointer to
609 * comments. May be NULL if you don't want it.
610 * 4 : data_out = destination for newly malloc'd pointer to
611 * line data with comments and leading/trailing spaces
612 * removed, and line continuation performed. May be
613 * NULL if you don't want it.
614 * 5 : newline = Standard for newlines in the file.
615 * On input, set to value to use or NEWLINE_UNKNOWN.
616 * On output, may be changed from NEWLINE_UNKNOWN to
617 * actual convention in file. May be NULL if you
619 * 6 : line_number = Line number in file. In "lines" as
620 * reported by a text editor, not lines containing data.
622 * Returns : JB_ERR_OK on success
623 * JB_ERR_MEMORY on out-of-memory
624 * JB_ERR_FILE on EOF.
626 *********************************************************************/
627 jb_err edit_read_line(FILE *fp,
632 unsigned long *line_number)
634 char *p; /* Temporary pointer */
635 char *linebuf; /* Line read from file */
636 char *linestart; /* Start of linebuf, usually first non-whitespace char */
637 int contflag = 0; /* Nonzero for line continuation - i.e. line ends '\' */
638 int is_empty = 1; /* Flag if not got any data yet */
639 char *raw = NULL; /* String to be stored in raw_out */
640 char *prefix = NULL; /* String to be stored in prefix_out */
641 char *data = NULL; /* String to be stored in data_out */
642 int scrapnewline; /* Used for (*newline) if newline==NULL */
643 jb_err rval = JB_ERR_OK;
646 assert(raw_out || data_out);
647 assert(newline == NULL
648 || *newline == NEWLINE_UNKNOWN
649 || *newline == NEWLINE_UNIX
650 || *newline == NEWLINE_DOS
651 || *newline == NEWLINE_MAC);
655 scrapnewline = NEWLINE_UNKNOWN;
656 newline = &scrapnewline;
659 /* Set output parameters to NULL */
673 /* Set string variables to new, empty strings. */
677 if ((raw = malloc(1)) == NULL)
679 return JB_ERR_MEMORY;
685 if ((prefix = malloc(1)) == NULL)
688 return JB_ERR_MEMORY;
694 if ((data = malloc(1)) == NULL)
698 return JB_ERR_MEMORY;
703 /* Main loop. Loop while we need more data & it's not EOF. */
705 while ( (contflag || is_empty)
706 && (JB_ERR_OK == (rval = simple_read_line(fp, &linebuf, newline))))
714 string_append(&raw,linebuf);
715 if (string_append(&raw,NEWLINE(*newline)))
720 return JB_ERR_MEMORY;
724 /* Line continuation? Trim escape and set flag. */
725 p = linebuf + strlen(linebuf) - 1;
726 contflag = ((*linebuf != '\0') && (*p == '\\'));
732 /* Trim leading spaces if we're at the start of the line */
736 /* Trim leading spaces */
737 while (*linestart && isspace((int)(unsigned char)*linestart))
743 /* Handle comment characters. */
745 while ((p = strchr(p, '#')) != NULL)
747 /* Found a comment char.. */
748 if ((p != linebuf) && (*(p-1) == '\\'))
750 /* ..and it's escaped, left-shift the line over the escape. */
752 while ((*q = *(q + 1)) != '\0')
756 /* Now scan from just after the "#". */
760 /* Real comment. Save it... */
763 /* Special case: Line only contains a comment, so all the
764 * previous whitespace is considered part of the comment.
765 * Undo the whitespace skipping, if any.
772 string_append(&prefix,p);
773 if (string_append(&prefix, NEWLINE(*newline)))
778 return JB_ERR_MEMORY;
782 /* ... and chop off the rest of the line */
785 } /* END while (there's a # character) */
787 /* Write to the buffer */
793 if (string_append(&data, linestart))
798 return JB_ERR_MEMORY;
804 } /* END while(we need more data) */
806 /* Handle simple_read_line() errors - ignore EOF */
807 if ((rval != JB_ERR_OK) && (rval != JB_ERR_FILE))
815 if (raw ? (*raw == '\0') : is_empty)
817 /* EOF and no data there. (Definition of "data" depends on whether
818 * the caller cares about "raw" or just "data").
829 /* Got at least some data */
831 /* Remove trailing whitespace */
844 *prefix_out = prefix;
863 /*********************************************************************
865 * Function : read_config_line
867 * Description : Read a single non-empty line from a file and return
868 * it. Trims comments, leading and trailing whitespace
869 * and respects escaping of newline and comment char.
872 * 1 : buf = Buffer to use.
873 * 2 : buflen = Size of buffer in bytes.
874 * 3 : fp = File to read from
875 * 4 : linenum = linenumber in file
877 * Returns : NULL on EOF or error
878 * Otherwise, returns buf.
880 *********************************************************************/
881 char *read_config_line(char *buf, int buflen, FILE *fp, unsigned long *linenum)
885 err = edit_read_line(fp, NULL, NULL, &buf2, NULL, linenum);
888 if (err == JB_ERR_MEMORY)
890 log_error(LOG_LEVEL_FATAL, "Out of memory loading a config file");
897 assert(strlen(buf2) + 1U < (unsigned)buflen);
898 strncpy(buf, buf2, buflen - 1);
900 buf[buflen - 1] = '\0';
907 /*********************************************************************
909 * Function : unload_trustfile
911 * Description : Unloads a trustfile.
914 * 1 : f = the data structure associated with the trustfile.
918 *********************************************************************/
919 static void unload_trustfile(void *f)
921 struct block_spec *b = (struct block_spec *)f;
922 if (b == NULL) return;
924 unload_trustfile(b->next); /* Stack is cheap, isn't it? */
926 free_url_spec(b->url);
933 /*********************************************************************
935 * Function : load_trustfile
937 * Description : Read and parse a trustfile and add to files list.
940 * 1 : csp = Current client state (buffers, headers, etc...)
942 * Returns : 0 => Ok, everything else is an error.
944 *********************************************************************/
945 int load_trustfile(struct client_state *csp)
949 struct block_spec *b, *bl;
950 struct url_spec **tl;
952 char buf[BUFFER_SIZE], *p, *q;
954 struct file_list *fs;
955 unsigned long linenum = 0;
957 if (!check_file_changed(current_trustfile, csp->config->trustfile, &fs))
959 /* No need to load */
962 csp->tlist = current_trustfile;
968 goto load_trustfile_error;
971 fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
974 goto load_trustfile_error;
977 if ((fp = fopen(csp->config->trustfile, "r")) == NULL)
979 goto load_trustfile_error;
982 tl = csp->config->trust_list;
984 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1000 while ((*p++ = *q++))
1006 /* skip blank lines */
1012 /* allocate a new node */
1013 if ((b = zalloc(sizeof(*b))) == NULL)
1016 goto load_trustfile_error;
1019 /* add it to the list */
1025 /* Save the URL pattern */
1026 if (create_url_spec(b->url, buf))
1029 goto load_trustfile_error;
1033 * save a pointer to URL's spec in the list of trusted URL's, too
1038 /* FIXME BUFFER OVERFLOW if >=64 entries */
1046 /* the old one is now obsolete */
1047 if (current_trustfile)
1049 current_trustfile->unloader = unload_trustfile;
1052 fs->next = files->next;
1054 current_trustfile = fs;
1063 load_trustfile_error:
1064 log_error(LOG_LEVEL_FATAL, "can't load trustfile '%s': %E",
1065 csp->config->trustfile);
1069 #endif /* def FEATURE_TRUST */
1072 /*********************************************************************
1074 * Function : unload_re_filterfile
1076 * Description : Unload the re_filter list.
1079 * 1 : f = the data structure associated with the filterfile.
1083 *********************************************************************/
1084 static void unload_re_filterfile(void *f)
1086 struct re_filterfile_spec *b = (struct re_filterfile_spec *)f;
1093 destroy_list(b->patterns);
1094 pcrs_free_joblist(b->joblist);
1100 /*********************************************************************
1102 * Function : load_re_filterfile
1104 * Description : Load the re_filterfile. Each non-comment, non-empty
1105 * line is instantly added to the joblist, which is
1106 * a chained list of pcrs_job structs.
1109 * 1 : csp = Current client state (buffers, headers, etc...)
1111 * Returns : 0 => Ok, everything else is an error.
1113 *********************************************************************/
1114 int load_re_filterfile(struct client_state *csp)
1118 struct re_filterfile_spec *bl;
1119 struct file_list *fs;
1121 char buf[BUFFER_SIZE];
1123 unsigned long linenum = 0;
1126 if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs))
1128 /* No need to load */
1131 csp->rlist = current_re_filterfile;
1137 goto load_re_filterfile_error;
1140 fs->f = bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl));
1143 goto load_re_filterfile_error;
1146 /* Open the file or fail */
1147 if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL)
1149 goto load_re_filterfile_error;
1152 /* Read line by line */
1153 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1155 enlist( bl->patterns, buf );
1157 /* We have a meaningful line -> make it a job */
1158 if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
1160 log_error(LOG_LEVEL_RE_FILTER,
1161 "Adding re_filter job %s failed with error %d.", buf, error);
1166 dummy->next = bl->joblist;
1167 bl->joblist = dummy;
1168 log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s succeeded.", buf);
1174 /* the old one is now obsolete */
1175 if ( NULL != current_re_filterfile )
1177 current_re_filterfile->unloader = unload_re_filterfile;
1180 fs->next = files->next;
1182 current_re_filterfile = fs;
1191 load_re_filterfile_error:
1192 log_error(LOG_LEVEL_FATAL, "can't load re_filterfile '%s': %E",
1193 csp->config->re_filterfile);
1199 /*********************************************************************
1201 * Function : add_loader
1203 * Description : Called from `load_config'. Called once for each input
1204 * file found in config.
1207 * 1 : loader = pointer to a function that can parse and load
1208 * the appropriate config file.
1209 * 2 : config = The configuration_spec to add the loader to.
1213 *********************************************************************/
1214 void add_loader(int (*loader)(struct client_state *),
1215 struct configuration_spec * config)
1219 for (i=0; i < NLOADERS; i++)
1221 if (config->loaders[i] == NULL)
1223 config->loaders[i] = loader;
1231 /*********************************************************************
1233 * Function : run_loader
1235 * Description : Called from `load_config' and `listen_loop'. This
1236 * function keeps the "csp" current with any file mods
1237 * since the last loop. If a file is unchanged, the
1238 * loader functions do NOT reload the file.
1241 * 1 : csp = Current client state (buffers, headers, etc...)
1242 * Must be non-null. Reads: "csp->config"
1243 * Writes: various data members.
1245 * Returns : 0 => Ok, everything else is an error.
1247 *********************************************************************/
1248 int run_loader(struct client_state *csp)
1253 for (i=0; i < NLOADERS; i++)
1255 if (csp->config->loaders[i] == NULL)
1259 ret |= (csp->config->loaders[i])(csp);