1 const char loaders_rcs[] = "$Id: loaders.c,v 1.39 2002/03/07 03:46:17 oes 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.39 2002/03/07 03:46:17 oes
39 * Fixed compiler warnings
41 * Revision 1.38 2002/03/06 22:54:35 jongfoster
42 * Automated function-comment nitpicking.
44 * Revision 1.37 2002/03/03 15:07:49 oes
45 * Re-enabled automatic config reloading
47 * Revision 1.36 2002/01/22 23:46:18 jongfoster
48 * Moving edit_read_line() and simple_read_line() to loaders.c, and
49 * extending them to support reading MS-DOS, Mac and UNIX style files
52 * Modifying read_config_line() (without changing it's prototype) to
53 * be a trivial wrapper for edit_read_line(). This means that we have
54 * one function to read a line and handle comments, which is common
55 * between the initialization code and the edit interface.
57 * Revision 1.35 2002/01/17 21:03:08 jongfoster
58 * Moving all our URL and URL pattern parsing code to urlmatch.c.
60 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
62 * Revision 1.34 2001/12/30 14:07:32 steudten
63 * - Add signal handling (unix)
64 * - Add SIGHUP handler (unix)
65 * - Add creation of pidfile (unix)
66 * - Add action 'top' in rc file (RH)
67 * - Add entry 'SIGNALS' to manpage
68 * - Add exit message to logfile (unix)
70 * Revision 1.33 2001/11/13 00:16:38 jongfoster
71 * Replacing references to malloc.h with the standard stdlib.h
72 * (See ANSI or K&R 2nd Ed)
74 * Revision 1.32 2001/11/07 00:02:13 steudten
75 * Add line number in error output for lineparsing for
76 * actionsfile and configfile.
77 * Special handling for CLF added.
79 * Revision 1.31 2001/10/26 17:39:01 oes
80 * Removed csp->referrer
81 * Moved ijb_isspace and ijb_tolower to project.h
83 * Revision 1.30 2001/10/25 03:40:48 david__schmidt
84 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
85 * threads to call select() simultaneously. So, it's time to do a real, live,
86 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
87 * (native). Both versions will work, but using __OS2__ offers multi-threading.
89 * Revision 1.29 2001/10/23 21:38:53 jongfoster
90 * Adding error-checking to create_url_spec()
92 * Revision 1.28 2001/10/07 15:40:39 oes
93 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
95 * Revision 1.27 2001/09/22 16:36:59 jongfoster
96 * Removing unused parameter fs from read_config_line()
98 * Revision 1.26 2001/09/22 14:05:22 jongfoster
99 * Bugfix: Multiple escaped "#" characters in a configuration
100 * file are now permitted.
101 * Also removing 3 unused headers.
103 * Revision 1.25 2001/09/13 22:44:03 jongfoster
104 * Adding {} to an if statement
106 * Revision 1.24 2001/07/30 22:08:36 jongfoster
107 * Tidying up #defines:
108 * - All feature #defines are now of the form FEATURE_xxx
109 * - Permanently turned off WIN_GUI_EDIT
110 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
112 * Revision 1.23 2001/07/20 15:51:54 oes
113 * Fixed indentation of prepocessor commands
115 * Revision 1.22 2001/07/20 15:16:17 haroon
116 * - per Guy's suggestion, added a while loop in sweep() to catch not just
117 * the last inactive CSP but all other consecutive inactive CSPs after that
120 * Revision 1.21 2001/07/18 17:26:24 oes
121 * Changed to conform to new pcrs interface
123 * Revision 1.20 2001/07/17 13:07:01 oes
124 * Fixed segv when last line in config files
125 * lacked a terminating (\r)\n
127 * Revision 1.19 2001/07/13 14:01:54 oes
128 * Removed all #ifdef PCRS
130 * Revision 1.18 2001/06/29 21:45:41 oes
131 * Indentation, CRLF->LF, Tab-> Space
133 * Revision 1.17 2001/06/29 13:31:51 oes
136 * Revision 1.16 2001/06/09 10:55:28 jongfoster
137 * Changing BUFSIZ ==> BUFFER_SIZE
139 * Revision 1.15 2001/06/07 23:14:14 jongfoster
140 * Removing ACL and forward file loaders - these
141 * files have been merged into the config file.
142 * Cosmetic: Moving unloader funcs next to their
143 * respective loader funcs
145 * Revision 1.14 2001/06/01 03:27:04 oes
146 * Fixed line continuation problem
148 * Revision 1.13 2001/05/31 21:28:49 jongfoster
149 * Removed all permissionsfile code - it's now called the actions
150 * file, and (almost) all the code is in actions.c
152 * Revision 1.12 2001/05/31 17:32:31 oes
154 * - Enhanced domain part globbing with infix and prefix asterisk
155 * matching and optional unanchored operation
157 * Revision 1.11 2001/05/29 23:25:24 oes
159 * - load_config_line() and load_permissions_file() now use chomp()
161 * Revision 1.10 2001/05/29 09:50:24 jongfoster
162 * Unified blocklist/imagelist/permissionslist.
163 * File format is still under discussion, but the internal changes
166 * Also modified interceptor behaviour:
167 * - We now intercept all URLs beginning with one of the following
168 * prefixes (and *only* these prefixes):
170 * * http://ijbswa.sf.net/config/
171 * * http://ijbswa.sourceforge.net/config/
172 * - New interceptors "home page" - go to http://i.j.b/ to see it.
173 * - Internal changes so that intercepted and fast redirect pages
174 * are not replaced with an image.
175 * - Interceptors now have the option to send a binary page direct
176 * to the client. (i.e. ijb-send-banner uses this)
177 * - Implemented show-url-info interceptor. (Which is why I needed
178 * the above interceptors changes - a typical URL is
179 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
180 * The previous mechanism would not have intercepted that, and
181 * if it had been intercepted then it then it would have replaced
184 * Revision 1.9 2001/05/26 17:12:07 jongfoster
185 * Fatal errors loading configuration files now give better error messages.
187 * Revision 1.8 2001/05/26 00:55:20 jongfoster
188 * Removing duplicated code. load_forwardfile() now uses create_url_spec()
190 * Revision 1.7 2001/05/26 00:28:36 jongfoster
191 * Automatic reloading of config file.
192 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
193 * Most of the global variables have been moved to a new
194 * struct configuration_spec, accessed through csp->config->globalname
195 * Most of the globals remaining are used by the Win32 GUI.
197 * Revision 1.6 2001/05/23 12:27:33 oes
199 * Fixed ugly indentation of my last changes
201 * Revision 1.5 2001/05/23 10:39:05 oes
202 * - Added support for escaping the comment character
203 * in config files by a backslash
204 * - Added support for line continuation in config
206 * - Fixed a buffer overflow bug with long config lines
208 * Revision 1.4 2001/05/22 18:56:28 oes
211 * Revision 1.3 2001/05/20 01:21:20 jongfoster
212 * Version 2.9.4 checkin.
213 * - Merged popupfile and cookiefile, and added control over PCRS
214 * filtering, in new "permissionsfile".
215 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
216 * file error you now get a message box (in the Win32 GUI) rather
217 * than the program exiting with no explanation.
218 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
220 * - Removed tabs from "config"
221 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
222 * - Bumped up version number.
224 * Revision 1.2 2001/05/17 23:01:01 oes
225 * - Cleaned CRLF's from the sources and related files
227 * Revision 1.1.1.1 2001/05/15 13:58:59 oes
228 * Initial import of version 2.9.3 source tree
231 *********************************************************************/
238 #include <sys/types.h>
241 #include <sys/stat.h>
245 #if !defined(_WIN32) && !defined(__OS2__)
255 #include "miscutil.h"
258 #include "urlmatch.h"
260 const char loaders_h_rcs[] = LOADERS_H_VERSION;
263 * Currently active files.
264 * These are also entered in the main linked list of files.
268 static struct file_list *current_trustfile = NULL;
269 #endif /* def FEATURE_TRUST */
271 static struct file_list *current_re_filterfile = NULL;
275 /*********************************************************************
279 * Description : Basically a mark and sweep garbage collector, it is run
280 * (by the parent thread) every once in a while to reclaim memory.
282 * It uses a mark and sweep strategy:
283 * 1) mark all files as inactive
285 * 2) check with each client:
286 * if it is active, mark its files as active
287 * if it is inactive, free its resources
289 * 3) free the resources of all of the files that
290 * are still marked as inactive (and are obsolete).
292 * N.B. files that are not obsolete don't have an unloader defined.
298 *********************************************************************/
301 struct file_list *fl, *nfl;
302 struct client_state *csp, *ncsp;
304 /* clear all of the file's active flags */
305 for ( fl = files->next; NULL != fl; fl = fl->next )
310 for (csp = clients; csp && (ncsp = csp->next) ; csp = csp->next)
312 if (ncsp->flags & CSP_FLAG_ACTIVE)
314 /* mark this client's files as active */
317 * Always have a configuration file.
318 * (Also note the slightly non-standard extra
321 ncsp->config->config_file_list->active = 1;
323 if (ncsp->actions_list) /* actions files */
325 ncsp->actions_list->active = 1;
328 if (ncsp->rlist) /* pcrsjob files */
330 ncsp->rlist->active = 1;
334 if (ncsp->tlist) /* trust files */
336 ncsp->tlist->active = 1;
338 #endif /* def FEATURE_TRUST */
343 * this client is not active, release its resources
344 * and the ones of all inactive clients that might
348 while (!(ncsp->flags & CSP_FLAG_ACTIVE))
350 csp->next = ncsp->next;
352 freez(ncsp->ip_addr_str);
353 freez(ncsp->my_ip_addr_str);
354 freez(ncsp->my_hostname);
355 freez(ncsp->x_forwarded);
356 freez(ncsp->iob->buf);
358 free_http_request(ncsp->http);
360 destroy_list(ncsp->headers);
361 destroy_list(ncsp->cookie_list);
363 free_current_action(ncsp->action);
365 #ifdef FEATURE_STATISTICS
367 if (ncsp->flags & CSP_FLAG_REJECTED)
371 #endif /* def FEATURE_STATISTICS */
375 /* are there any more in sequence after it? */
376 if( !(ncsp = csp->next) )
382 for (fl = files; fl && (nfl = fl->next) ; fl = fl->next)
384 if ( ( 0 == nfl->active ) && ( NULL != nfl->unloader ) )
386 fl->next = nfl->next;
388 (nfl->unloader)(nfl->f);
390 freez(nfl->filename);
399 /*********************************************************************
401 * Function : check_file_changed
403 * Description : Helper function to check if a file needs reloading.
404 * If "current" is still current, return it. Otherwise
405 * allocates a new (zeroed) "struct file_list", fills
406 * in the disk file name and timestamp, and returns it.
409 * 1 : current = The file_list currently being used - will
410 * be checked to see if it is out of date.
411 * May be NULL (which is treated as out of
413 * 2 : filename = Name of file to check.
414 * 3 : newfl = New file list. [Output only]
415 * This will be set to NULL, OR a struct
416 * file_list newly allocated on the
417 * heap, with the filename and lastmodified
418 * fields filled, and all others zeroed.
420 * Returns : If file unchanged: 0 (and sets newfl == NULL)
421 * If file changed: 1 and sets newfl != NULL
422 * On error: 1 and sets newfl == NULL
424 *********************************************************************/
425 int check_file_changed(const struct file_list * current,
426 const char * filename,
427 struct file_list ** newfl)
429 struct file_list *fs;
430 struct stat statbuf[1];
434 if (stat(filename, statbuf) < 0)
436 /* Error, probably file not found. */
441 && (current->lastmodified == statbuf->st_mtime)
442 && (0 == strcmp(current->filename, filename)))
447 fs = (struct file_list *)zalloc(sizeof(struct file_list));
450 /* Out of memory error */
454 fs->filename = strdup(filename);
455 fs->lastmodified = statbuf->st_mtime;
457 if (fs->filename == NULL)
459 /* Out of memory error */
468 /*********************************************************************
470 * Function : simple_read_line
472 * Description : Read a single line from a file and return it.
473 * This is basically a version of fgets() that malloc()s
474 * it's own line buffer. Note that the buffer will
475 * always be a multiple of BUFFER_SIZE bytes long.
476 * Therefore if you are going to keep the string for
477 * an extended period of time, you should probably
478 * strdup() it and free() the original, to save memory.
482 * 1 : dest = destination for newly malloc'd pointer to
483 * line data. Will be set to NULL on error.
484 * 2 : fp = File to read from
485 * 3 : newline = Standard for newlines in the file.
486 * Will be unchanged if it's value on input is not
488 * On output, may be changed from NEWLINE_UNKNOWN to
489 * actual convention in file.
491 * Returns : JB_ERR_OK on success
492 * JB_ERR_MEMORY on out-of-memory
493 * JB_ERR_FILE on EOF.
495 *********************************************************************/
496 jb_err simple_read_line(FILE *fp, char **dest, int *newline)
499 size_t buflen = BUFFER_SIZE;
503 int realnewline = NEWLINE_UNKNOWN;
505 if (NULL == (buf = malloc(buflen)))
507 return JB_ERR_MEMORY;
513 * Character codes. If you have a wierd compiler and the following are
514 * incorrect, you also need to fix NEWLINE() in loaders.h
516 #define CHAR_CR '\r' /* ASCII 13 */
517 #define CHAR_LF '\n' /* ASCII 10 */
537 else if (ch == CHAR_CR)
542 if (*newline == NEWLINE_UNKNOWN)
544 *newline = NEWLINE_DOS;
553 if (*newline == NEWLINE_UNKNOWN)
555 *newline = NEWLINE_MAC;
560 if (*newline == NEWLINE_UNKNOWN)
562 *newline = realnewline;
566 else if (ch == CHAR_LF)
570 if (*newline == NEWLINE_UNKNOWN)
572 *newline = NEWLINE_UNIX;
587 buflen += BUFFER_SIZE;
588 if (NULL == (p = realloc(buf, buflen)));
591 return JB_ERR_MEMORY;
600 /*********************************************************************
602 * Function : edit_read_line
604 * Description : Read a single non-empty line from a file and return
605 * it. Trims comments, leading and trailing whitespace
606 * and respects escaping of newline and comment char.
607 * Provides the line in 2 alternative forms: raw and
609 * - raw is the raw data read from the file. If the
610 * line is not modified, then this should be written
612 * - prefix is any comments and blank lines that were
613 * read from the file. If the line is modified, then
614 * this should be written out to the file followed
615 * by the modified data. (If this string is non-empty
616 * then it will have a newline at the end).
617 * - data is the actual data that will be parsed
618 * further by appropriate routines.
619 * On EOF, the 3 strings will all be set to NULL and
620 * 0 will be returned.
623 * 1 : fp = File to read from
624 * 2 : raw_out = destination for newly malloc'd pointer to
625 * raw line data. May be NULL if you don't want it.
626 * 3 : prefix_out = destination for newly malloc'd pointer to
627 * comments. May be NULL if you don't want it.
628 * 4 : data_out = destination for newly malloc'd pointer to
629 * line data with comments and leading/trailing spaces
630 * removed, and line continuation performed. May be
631 * NULL if you don't want it.
632 * 5 : newline = Standard for newlines in the file.
633 * On input, set to value to use or NEWLINE_UNKNOWN.
634 * On output, may be changed from NEWLINE_UNKNOWN to
635 * actual convention in file. May be NULL if you
637 * 6 : line_number = Line number in file. In "lines" as
638 * reported by a text editor, not lines containing data.
640 * Returns : JB_ERR_OK on success
641 * JB_ERR_MEMORY on out-of-memory
642 * JB_ERR_FILE on EOF.
644 *********************************************************************/
645 jb_err edit_read_line(FILE *fp,
650 unsigned long *line_number)
652 char *p; /* Temporary pointer */
653 char *linebuf; /* Line read from file */
654 char *linestart; /* Start of linebuf, usually first non-whitespace char */
655 int contflag = 0; /* Nonzero for line continuation - i.e. line ends '\' */
656 int is_empty = 1; /* Flag if not got any data yet */
657 char *raw = NULL; /* String to be stored in raw_out */
658 char *prefix = NULL; /* String to be stored in prefix_out */
659 char *data = NULL; /* String to be stored in data_out */
660 int scrapnewline; /* Used for (*newline) if newline==NULL */
661 jb_err rval = JB_ERR_OK;
664 assert(raw_out || data_out);
665 assert(newline == NULL
666 || *newline == NEWLINE_UNKNOWN
667 || *newline == NEWLINE_UNIX
668 || *newline == NEWLINE_DOS
669 || *newline == NEWLINE_MAC);
673 scrapnewline = NEWLINE_UNKNOWN;
674 newline = &scrapnewline;
677 /* Set output parameters to NULL */
691 /* Set string variables to new, empty strings. */
695 if ((raw = malloc(1)) == NULL)
697 return JB_ERR_MEMORY;
703 if ((prefix = malloc(1)) == NULL)
706 return JB_ERR_MEMORY;
712 if ((data = malloc(1)) == NULL)
716 return JB_ERR_MEMORY;
721 /* Main loop. Loop while we need more data & it's not EOF. */
723 while ( (contflag || is_empty)
724 && (JB_ERR_OK == (rval = simple_read_line(fp, &linebuf, newline))))
732 string_append(&raw,linebuf);
733 if (string_append(&raw,NEWLINE(*newline)))
738 return JB_ERR_MEMORY;
742 /* Line continuation? Trim escape and set flag. */
743 p = linebuf + strlen(linebuf) - 1;
744 contflag = ((*linebuf != '\0') && (*p == '\\'));
750 /* Trim leading spaces if we're at the start of the line */
754 /* Trim leading spaces */
755 while (*linestart && isspace((int)(unsigned char)*linestart))
761 /* Handle comment characters. */
763 while ((p = strchr(p, '#')) != NULL)
765 /* Found a comment char.. */
766 if ((p != linebuf) && (*(p-1) == '\\'))
768 /* ..and it's escaped, left-shift the line over the escape. */
770 while ((*q = *(q + 1)) != '\0')
774 /* Now scan from just after the "#". */
778 /* Real comment. Save it... */
781 /* Special case: Line only contains a comment, so all the
782 * previous whitespace is considered part of the comment.
783 * Undo the whitespace skipping, if any.
790 string_append(&prefix,p);
791 if (string_append(&prefix, NEWLINE(*newline)))
796 return JB_ERR_MEMORY;
800 /* ... and chop off the rest of the line */
803 } /* END while (there's a # character) */
805 /* Write to the buffer */
811 if (string_append(&data, linestart))
816 return JB_ERR_MEMORY;
822 } /* END while(we need more data) */
824 /* Handle simple_read_line() errors - ignore EOF */
825 if ((rval != JB_ERR_OK) && (rval != JB_ERR_FILE))
833 if (raw ? (*raw == '\0') : is_empty)
835 /* EOF and no data there. (Definition of "data" depends on whether
836 * the caller cares about "raw" or just "data").
847 /* Got at least some data */
849 /* Remove trailing whitespace */
862 *prefix_out = prefix;
881 /*********************************************************************
883 * Function : read_config_line
885 * Description : Read a single non-empty line from a file and return
886 * it. Trims comments, leading and trailing whitespace
887 * and respects escaping of newline and comment char.
890 * 1 : buf = Buffer to use.
891 * 2 : buflen = Size of buffer in bytes.
892 * 3 : fp = File to read from
893 * 4 : linenum = linenumber in file
895 * Returns : NULL on EOF or error
896 * Otherwise, returns buf.
898 *********************************************************************/
899 char *read_config_line(char *buf, size_t buflen, FILE *fp, unsigned long *linenum)
903 err = edit_read_line(fp, NULL, NULL, &buf2, NULL, linenum);
906 if (err == JB_ERR_MEMORY)
908 log_error(LOG_LEVEL_FATAL, "Out of memory loading a config file");
915 assert(strlen(buf2) + 1U < buflen);
916 strncpy(buf, buf2, buflen - 1);
918 buf[buflen - 1] = '\0';
925 /*********************************************************************
927 * Function : unload_trustfile
929 * Description : Unloads a trustfile.
932 * 1 : f = the data structure associated with the trustfile.
936 *********************************************************************/
937 static void unload_trustfile(void *f)
939 struct block_spec *b = (struct block_spec *)f;
940 if (b == NULL) return;
942 unload_trustfile(b->next); /* Stack is cheap, isn't it? */
944 free_url_spec(b->url);
951 /*********************************************************************
953 * Function : load_trustfile
955 * Description : Read and parse a trustfile and add to files list.
958 * 1 : csp = Current client state (buffers, headers, etc...)
960 * Returns : 0 => Ok, everything else is an error.
962 *********************************************************************/
963 int load_trustfile(struct client_state *csp)
967 struct block_spec *b, *bl;
968 struct url_spec **tl;
970 char buf[BUFFER_SIZE], *p, *q;
972 struct file_list *fs;
973 unsigned long linenum = 0;
975 if (!check_file_changed(current_trustfile, csp->config->trustfile, &fs))
977 /* No need to load */
980 csp->tlist = current_trustfile;
986 goto load_trustfile_error;
989 fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
992 goto load_trustfile_error;
995 if ((fp = fopen(csp->config->trustfile, "r")) == NULL)
997 goto load_trustfile_error;
1000 tl = csp->config->trust_list;
1002 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1018 while ((*p++ = *q++))
1024 /* skip blank lines */
1030 /* allocate a new node */
1031 if ((b = zalloc(sizeof(*b))) == NULL)
1034 goto load_trustfile_error;
1037 /* add it to the list */
1043 /* Save the URL pattern */
1044 if (create_url_spec(b->url, buf))
1047 goto load_trustfile_error;
1051 * save a pointer to URL's spec in the list of trusted URL's, too
1056 /* FIXME BUFFER OVERFLOW if >=64 entries */
1064 /* the old one is now obsolete */
1065 if (current_trustfile)
1067 current_trustfile->unloader = unload_trustfile;
1070 fs->next = files->next;
1072 current_trustfile = fs;
1081 load_trustfile_error:
1082 log_error(LOG_LEVEL_FATAL, "can't load trustfile '%s': %E",
1083 csp->config->trustfile);
1087 #endif /* def FEATURE_TRUST */
1090 /*********************************************************************
1092 * Function : unload_re_filterfile
1094 * Description : Unload the re_filter list.
1097 * 1 : f = the data structure associated with the filterfile.
1101 *********************************************************************/
1102 static void unload_re_filterfile(void *f)
1104 struct re_filterfile_spec *b = (struct re_filterfile_spec *)f;
1111 destroy_list(b->patterns);
1112 pcrs_free_joblist(b->joblist);
1118 /*********************************************************************
1120 * Function : load_re_filterfile
1122 * Description : Load the re_filterfile. Each non-comment, non-empty
1123 * line is instantly added to the joblist, which is
1124 * a chained list of pcrs_job structs.
1127 * 1 : csp = Current client state (buffers, headers, etc...)
1129 * Returns : 0 => Ok, everything else is an error.
1131 *********************************************************************/
1132 int load_re_filterfile(struct client_state *csp)
1136 struct re_filterfile_spec *bl;
1137 struct file_list *fs;
1139 char buf[BUFFER_SIZE];
1141 unsigned long linenum = 0;
1144 if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs))
1146 /* No need to load */
1149 csp->rlist = current_re_filterfile;
1155 goto load_re_filterfile_error;
1158 fs->f = bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl));
1161 goto load_re_filterfile_error;
1164 /* Open the file or fail */
1165 if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL)
1167 goto load_re_filterfile_error;
1170 /* Read line by line */
1171 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
1173 enlist( bl->patterns, buf );
1175 /* We have a meaningful line -> make it a job */
1176 if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
1178 log_error(LOG_LEVEL_RE_FILTER,
1179 "Adding re_filter job %s failed with error %d.", buf, error);
1184 dummy->next = bl->joblist;
1185 bl->joblist = dummy;
1186 log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s succeeded.", buf);
1192 /* the old one is now obsolete */
1193 if ( NULL != current_re_filterfile )
1195 current_re_filterfile->unloader = unload_re_filterfile;
1198 fs->next = files->next;
1200 current_re_filterfile = fs;
1209 load_re_filterfile_error:
1210 log_error(LOG_LEVEL_FATAL, "can't load re_filterfile '%s': %E",
1211 csp->config->re_filterfile);
1217 /*********************************************************************
1219 * Function : add_loader
1221 * Description : Called from `load_config'. Called once for each input
1222 * file found in config.
1225 * 1 : loader = pointer to a function that can parse and load
1226 * the appropriate config file.
1227 * 2 : config = The configuration_spec to add the loader to.
1231 *********************************************************************/
1232 void add_loader(int (*loader)(struct client_state *),
1233 struct configuration_spec * config)
1237 for (i=0; i < NLOADERS; i++)
1239 if (config->loaders[i] == NULL)
1241 config->loaders[i] = loader;
1249 /*********************************************************************
1251 * Function : run_loader
1253 * Description : Called from `load_config' and `listen_loop'. This
1254 * function keeps the "csp" current with any file mods
1255 * since the last loop. If a file is unchanged, the
1256 * loader functions do NOT reload the file.
1259 * 1 : csp = Current client state (buffers, headers, etc...)
1260 * Must be non-null. Reads: "csp->config"
1261 * Writes: various data members.
1263 * Returns : 0 => Ok, everything else is an error.
1265 *********************************************************************/
1266 int run_loader(struct client_state *csp)
1271 for (i=0; i < NLOADERS; i++)
1273 if (csp->config->loaders[i] == NULL)
1277 ret |= (csp->config->loaders[i])(csp);