1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
5 * Purpose : Functions to load and unload the various
6 * configuration files. Also contains code to manage
7 * the list of active loaders, and to automatically
8 * unload files that are no longer in use.
10 * Copyright : Written by and Copyright (C) 2001-2014 the
11 * Privoxy team. http://www.privoxy.org/
13 * Based on the Internet Junkbuster originally written
14 * by and Copyright (C) 1997 Anonymous Coders and
15 * Junkbusters Corporation. http://www.junkbusters.com
17 * This program is free software; you can redistribute it
18 * and/or modify it under the terms of the GNU General
19 * Public License as published by the Free Software
20 * Foundation; either version 2 of the License, or (at
21 * your option) any later version.
23 * This program is distributed in the hope that it will
24 * be useful, but WITHOUT ANY WARRANTY; without even the
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A
26 * PARTICULAR PURPOSE. See the GNU General Public
27 * License for more details.
29 * The GNU General Public License should be included with
30 * this file. If not, you can view it at
31 * http://www.gnu.org/copyleft/gpl.html
32 * or write to the Free Software Foundation, Inc., 59
33 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 *********************************************************************/
42 #include <sys/types.h>
49 #if !defined(_WIN32) && !defined(__OS2__)
66 * Currently active files.
67 * These are also entered in the main linked list of files.
71 static struct file_list *current_trustfile = NULL;
72 #endif /* def FEATURE_TRUST */
75 static int load_one_re_filterfile(struct client_state *csp, int fileid);
78 static struct file_list *current_re_filterfile[MAX_AF_FILES] = {
79 NULL, NULL, NULL, NULL, NULL,
80 NULL, NULL, NULL, NULL, NULL
83 /*********************************************************************
85 * Function : free_csp_resources
87 * Description : Frees memory referenced by the csp that isn't
88 * shared with other csps.
91 * 1 : csp = Current client state (buffers, headers, etc...)
95 *********************************************************************/
96 void free_csp_resources(struct client_state *csp)
98 freez(csp->ip_addr_str);
99 #ifdef FEATURE_CLIENT_TAGS
100 freez(csp->client_address);
102 freez(csp->listen_addr_str);
103 freez(csp->client_iob->buf);
104 freez(csp->iob->buf);
105 freez(csp->error_message);
107 if (csp->action->flags & ACTION_FORWARD_OVERRIDE &&
110 unload_forward_spec(csp->fwd);
112 free_http_request(csp->http);
114 destroy_list(csp->headers);
115 destroy_list(csp->tags);
117 free_current_action(csp->action);
120 /*********************************************************************
124 * Description : Basically a mark and sweep garbage collector, it is run
125 * (by the parent thread) every once in a while to reclaim memory.
127 * It uses a mark and sweep strategy:
128 * 1) mark all files as inactive
130 * 2) check with each client:
131 * if it is active, mark its files as active
132 * if it is inactive, free its resources
134 * 3) free the resources of all of the files that
135 * are still marked as inactive (and are obsolete).
137 * N.B. files that are not obsolete don't have an unloader defined.
141 * Returns : The number of threads that are still active.
143 *********************************************************************/
144 unsigned int sweep(void)
146 struct file_list *fl, *nfl;
147 struct client_state *csp;
148 struct client_states *last_active, *client_list;
150 unsigned int active_threads = 0;
152 /* clear all of the file's active flags */
153 for (fl = files->next; NULL != fl; fl = fl->next)
158 last_active = clients;
159 client_list = clients->next;
161 while (NULL != client_list)
163 csp = &client_list->csp;
164 if (csp->flags & CSP_FLAG_ACTIVE)
166 /* Mark this client's files as active */
169 * Always have a configuration file.
170 * (Also note the slightly non-standard extra
173 csp->config->config_file_list->active = 1;
178 for (i = 0; i < MAX_AF_FILES; i++)
180 if (csp->actions_list[i])
182 csp->actions_list[i]->active = 1;
189 for (i = 0; i < MAX_AF_FILES; i++)
193 csp->rlist[i]->active = 1;
203 csp->tlist->active = 1;
205 #endif /* def FEATURE_TRUST */
209 last_active = client_list;
210 client_list = client_list->next;
214 * This client is not active. Free its resources.
217 last_active->next = client_list->next;
219 #ifdef FEATURE_STATISTICS
221 if (csp->flags & CSP_FLAG_REJECTED)
225 #endif /* def FEATURE_STATISTICS */
229 client_list = last_active->next;
238 if ((0 == fl->active) && (NULL != fl->unloader))
240 nfl->next = fl->next;
242 (fl->unloader)(fl->f);
256 return active_threads;
261 /*********************************************************************
263 * Function : check_file_changed
265 * Description : Helper function to check if a file needs reloading.
266 * If "current" is still current, return it. Otherwise
267 * allocates a new (zeroed) "struct file_list", fills
268 * in the disk file name and timestamp, and returns it.
271 * 1 : current = The file_list currently being used - will
272 * be checked to see if it is out of date.
273 * May be NULL (which is treated as out of
275 * 2 : filename = Name of file to check.
276 * 3 : newfl = New file list. [Output only]
277 * This will be set to NULL, OR a struct
278 * file_list newly allocated on the
279 * heap, with the filename and lastmodified
280 * fields filled, and all others zeroed.
282 * Returns : If file unchanged: 0 (and sets newfl == NULL)
283 * If file changed: 1 and sets newfl != NULL
284 * On error: 1 and sets newfl == NULL
286 *********************************************************************/
287 int check_file_changed(const struct file_list * current,
288 const char * filename,
289 struct file_list ** newfl)
291 struct file_list *fs;
292 struct stat statbuf[1];
296 if (stat(filename, statbuf) < 0)
298 /* Error, probably file not found. */
303 && (current->lastmodified == statbuf->st_mtime)
304 && (0 == strcmp(current->filename, filename)))
309 fs = zalloc_or_die(sizeof(struct file_list));
310 fs->filename = strdup_or_die(filename);
311 fs->lastmodified = statbuf->st_mtime;
318 /*********************************************************************
320 * Function : simple_read_line
322 * Description : Read a single line from a file and return it.
323 * This is basically a version of fgets() that malloc()s
324 * it's own line buffer. Note that the buffer will
325 * always be a multiple of BUFFER_SIZE bytes long.
326 * Therefore if you are going to keep the string for
327 * an extended period of time, you should probably
328 * strdup() it and free() the original, to save memory.
332 * 1 : dest = destination for newly malloc'd pointer to
333 * line data. Will be set to NULL on error.
334 * 2 : fp = File to read from
335 * 3 : newline = Standard for newlines in the file.
336 * Will be unchanged if it's value on input is not
338 * On output, may be changed from NEWLINE_UNKNOWN to
339 * actual convention in file.
341 * Returns : JB_ERR_OK on success
342 * JB_ERR_MEMORY on out-of-memory
343 * JB_ERR_FILE on EOF.
345 *********************************************************************/
346 jb_err simple_read_line(FILE *fp, char **dest, int *newline)
349 size_t buflen = BUFFER_SIZE;
353 int realnewline = NEWLINE_UNKNOWN;
355 if (NULL == (buf = malloc(buflen)))
357 return JB_ERR_MEMORY;
363 * Character codes. If you have a weird compiler and the following are
364 * incorrect, you also need to fix NEWLINE() in loaders.h
366 #define CHAR_CR '\r' /* ASCII 13 */
367 #define CHAR_LF '\n' /* ASCII 10 */
388 else if (ch == CHAR_CR)
393 if (*newline == NEWLINE_UNKNOWN)
395 *newline = NEWLINE_DOS;
404 if (*newline == NEWLINE_UNKNOWN)
406 *newline = NEWLINE_MAC;
411 if (*newline == NEWLINE_UNKNOWN)
413 *newline = realnewline;
417 else if (ch == CHAR_LF)
421 if (*newline == NEWLINE_UNKNOWN)
423 *newline = NEWLINE_UNIX;
429 /* XXX: Why do we allow this anyway? */
439 buflen += BUFFER_SIZE;
440 if (NULL == (p = realloc(buf, buflen)))
443 return JB_ERR_MEMORY;
452 /*********************************************************************
454 * Function : edit_read_line
456 * Description : Read a single non-empty line from a file and return
457 * it. Trims comments, leading and trailing whitespace
458 * and respects escaping of newline and comment char.
459 * Provides the line in 2 alternative forms: raw and
461 * - raw is the raw data read from the file. If the
462 * line is not modified, then this should be written
464 * - prefix is any comments and blank lines that were
465 * read from the file. If the line is modified, then
466 * this should be written out to the file followed
467 * by the modified data. (If this string is non-empty
468 * then it will have a newline at the end).
469 * - data is the actual data that will be parsed
470 * further by appropriate routines.
471 * On EOF, the 3 strings will all be set to NULL and
472 * 0 will be returned.
475 * 1 : fp = File to read from
476 * 2 : raw_out = destination for newly malloc'd pointer to
477 * raw line data. May be NULL if you don't want it.
478 * 3 : prefix_out = destination for newly malloc'd pointer to
479 * comments. May be NULL if you don't want it.
480 * 4 : data_out = destination for newly malloc'd pointer to
481 * line data with comments and leading/trailing spaces
482 * removed, and line continuation performed. May be
483 * NULL if you don't want it.
484 * 5 : newline = Standard for newlines in the file.
485 * On input, set to value to use or NEWLINE_UNKNOWN.
486 * On output, may be changed from NEWLINE_UNKNOWN to
487 * actual convention in file. May be NULL if you
489 * 6 : line_number = Line number in file. In "lines" as
490 * reported by a text editor, not lines containing data.
492 * Returns : JB_ERR_OK on success
493 * JB_ERR_MEMORY on out-of-memory
494 * JB_ERR_FILE on EOF.
496 *********************************************************************/
497 jb_err edit_read_line(FILE *fp,
502 unsigned long *line_number)
504 char *p; /* Temporary pointer */
505 char *linebuf; /* Line read from file */
506 char *linestart; /* Start of linebuf, usually first non-whitespace char */
507 int contflag = 0; /* Nonzero for line continuation - i.e. line ends '\' */
508 int is_empty = 1; /* Flag if not got any data yet */
509 char *raw = NULL; /* String to be stored in raw_out */
510 char *prefix = NULL; /* String to be stored in prefix_out */
511 char *data = NULL; /* String to be stored in data_out */
512 int scrapnewline; /* Used for (*newline) if newline==NULL */
513 jb_err rval = JB_ERR_OK;
516 assert(raw_out || data_out);
517 assert(newline == NULL
518 || *newline == NEWLINE_UNKNOWN
519 || *newline == NEWLINE_UNIX
520 || *newline == NEWLINE_DOS
521 || *newline == NEWLINE_MAC);
525 scrapnewline = NEWLINE_UNKNOWN;
526 newline = &scrapnewline;
529 /* Set output parameters to NULL */
543 /* Set string variables to new, empty strings. */
547 raw = strdup_or_die("");
551 prefix = strdup_or_die("");
555 data = strdup_or_die("");
558 /* Main loop. Loop while we need more data & it's not EOF. */
560 while ((contflag || is_empty)
561 && (JB_ERR_OK == (rval = simple_read_line(fp, &linebuf, newline))))
569 string_append(&raw,linebuf);
570 if (string_append(&raw,NEWLINE(*newline)))
575 return JB_ERR_MEMORY;
579 /* Line continuation? Trim escape and set flag. */
580 p = linebuf + strlen(linebuf) - 1;
581 contflag = ((*linebuf != '\0') && (*p == '\\'));
587 /* Trim leading spaces if we're at the start of the line */
589 assert(NULL != data);
592 /* Trim leading spaces */
593 while (*linestart && isspace((int)(unsigned char)*linestart))
599 /* Handle comment characters. */
601 while ((p = strchr(p, '#')) != NULL)
603 /* Found a comment char.. */
604 if ((p != linebuf) && (*(p-1) == '\\'))
606 /* ..and it's escaped, left-shift the line over the escape. */
608 while ((*q = *(q + 1)) != '\0')
612 /* Now scan from just after the "#". */
616 /* Real comment. Save it... */
619 /* Special case: Line only contains a comment, so all the
620 * previous whitespace is considered part of the comment.
621 * Undo the whitespace skipping, if any.
628 string_append(&prefix,p);
629 if (string_append(&prefix, NEWLINE(*newline)))
634 return JB_ERR_MEMORY;
638 /* ... and chop off the rest of the line */
641 } /* END while (there's a # character) */
643 /* Write to the buffer */
647 if (string_append(&data, linestart))
652 return JB_ERR_MEMORY;
657 } /* END while(we need more data) */
659 /* Handle simple_read_line() errors - ignore EOF */
660 if ((rval != JB_ERR_OK) && (rval != JB_ERR_FILE))
668 if (raw ? (*raw == '\0') : is_empty)
670 /* EOF and no data there. (Definition of "data" depends on whether
671 * the caller cares about "raw" or just "data").
682 /* Got at least some data */
684 /* Remove trailing whitespace */
697 *prefix_out = prefix;
716 /*********************************************************************
718 * Function : read_config_line
720 * Description : Read a single non-empty line from a file and return
721 * it. Trims comments, leading and trailing whitespace
722 * and respects escaping of newline and comment char.
725 * 1 : fp = File to read from
726 * 2 : linenum = linenumber in file
727 * 3 : buf = Pointer to a pointer to set to the data buffer.
729 * Returns : NULL on EOF or error
730 * Otherwise, returns buf.
732 *********************************************************************/
733 char *read_config_line(FILE *fp, unsigned long *linenum, char **buf)
736 err = edit_read_line(fp, NULL, NULL, buf, NULL, linenum);
739 if (err == JB_ERR_MEMORY)
741 log_error(LOG_LEVEL_FATAL, "Out of memory loading a config file");
750 /*********************************************************************
752 * Function : unload_trustfile
754 * Description : Unloads a trustfile.
757 * 1 : f = the data structure associated with the trustfile.
761 *********************************************************************/
762 static void unload_trustfile(void *f)
764 struct block_spec *cur = (struct block_spec *)f;
765 struct block_spec *next;
771 free_pattern_spec(cur->url);
780 #ifdef FEATURE_GRACEFUL_TERMINATION
781 /*********************************************************************
783 * Function : unload_current_trust_file
785 * Description : Unloads current trust file - reset to state at
786 * beginning of program.
792 *********************************************************************/
793 void unload_current_trust_file(void)
795 if (current_trustfile)
797 current_trustfile->unloader = unload_trustfile;
798 current_trustfile = NULL;
801 #endif /* FEATURE_GRACEFUL_TERMINATION */
804 /*********************************************************************
806 * Function : load_trustfile
808 * Description : Read and parse a trustfile and add to files list.
811 * 1 : csp = Current client state (buffers, headers, etc...)
813 * Returns : 0 => Ok, everything else is an error.
815 *********************************************************************/
816 int load_trustfile(struct client_state *csp)
820 struct block_spec *b, *bl;
821 struct pattern_spec **tl;
825 struct file_list *fs;
826 unsigned long linenum = 0;
827 int trusted_referrers = 0;
829 if (!check_file_changed(current_trustfile, csp->config->trustfile, &fs))
831 /* No need to load */
832 csp->tlist = current_trustfile;
837 goto load_trustfile_error;
840 fs->f = bl = zalloc_or_die(sizeof(*bl));
842 if ((fp = fopen(csp->config->trustfile, "r")) == NULL)
844 goto load_trustfile_error;
846 log_error(LOG_LEVEL_INFO, "Loading trust file: %s", csp->config->trustfile);
848 tl = csp->config->trust_list;
850 while (read_config_line(fp, &linenum, &buf) != NULL)
869 while ((*p++ = *q++) != '\0')
875 /* skip blank lines */
882 /* allocate a new node */
883 b = zalloc_or_die(sizeof(*b));
885 /* add it to the list */
891 /* Save the URL pattern */
892 if (create_pattern_spec(b->url, buf))
895 goto load_trustfile_error;
899 * save a pointer to URL's spec in the list of trusted URL's, too
903 if (++trusted_referrers < MAX_TRUSTED_REFERRERS)
911 if (trusted_referrers >= MAX_TRUSTED_REFERRERS)
914 * FIXME: ... after Privoxy 3.0.4 is out.
916 log_error(LOG_LEVEL_ERROR, "Too many trusted referrers. Current limit is %d, you are using %d.\n"
917 " Additional trusted referrers are treated like ordinary trusted URLs.\n"
918 " (You can increase this limit by changing MAX_TRUSTED_REFERRERS in project.h and recompiling).",
919 MAX_TRUSTED_REFERRERS, trusted_referrers);
926 /* the old one is now obsolete */
927 if (current_trustfile)
929 current_trustfile->unloader = unload_trustfile;
932 fs->next = files->next;
934 current_trustfile = fs;
939 load_trustfile_error:
940 log_error(LOG_LEVEL_FATAL, "can't load trustfile '%s': %E",
941 csp->config->trustfile);
946 #endif /* def FEATURE_TRUST */
949 /*********************************************************************
951 * Function : unload_re_filterfile
953 * Description : Unload the re_filter list by freeing all chained
954 * re_filterfile specs and their data.
957 * 1 : f = the data structure associated with the filterfile.
961 *********************************************************************/
962 static void unload_re_filterfile(void *f)
964 struct re_filterfile_spec *a, *b = (struct re_filterfile_spec *)f;
970 destroy_list(b->patterns);
971 pcrs_free_joblist(b->joblist);
973 freez(b->description);
982 /*********************************************************************
984 * Function : unload_forward_spec
986 * Description : Unload the forward spec settings by freeing all
987 * memory referenced by members and the memory for
991 * 1 : fwd = the forward spec.
995 *********************************************************************/
996 void unload_forward_spec(struct forward_spec *fwd)
998 free_pattern_spec(fwd->url);
999 freez(fwd->gateway_host);
1000 freez(fwd->forward_host);
1001 freez(fwd->auth_username);
1002 freez(fwd->auth_password);
1009 #ifdef FEATURE_GRACEFUL_TERMINATION
1010 /*********************************************************************
1012 * Function : unload_current_re_filterfile
1014 * Description : Unloads current re_filter file - reset to state at
1015 * beginning of program.
1021 *********************************************************************/
1022 void unload_current_re_filterfile(void)
1026 for (i = 0; i < MAX_AF_FILES; i++)
1028 if (current_re_filterfile[i])
1030 current_re_filterfile[i]->unloader = unload_re_filterfile;
1031 current_re_filterfile[i] = NULL;
1038 /*********************************************************************
1040 * Function : load_re_filterfiles
1042 * Description : Loads all the filterfiles.
1043 * Generate a chained list of re_filterfile_spec's from
1044 * the "FILTER: " blocks, compiling all their substitutions
1045 * into chained lists of pcrs_job structs.
1048 * 1 : csp = Current client state (buffers, headers, etc...)
1050 * Returns : 0 => Ok, everything else is an error.
1052 *********************************************************************/
1053 int load_re_filterfiles(struct client_state *csp)
1058 for (i = 0; i < MAX_AF_FILES; i++)
1060 if (csp->config->re_filterfile[i])
1062 result = load_one_re_filterfile(csp, i);
1068 else if (current_re_filterfile[i])
1070 current_re_filterfile[i]->unloader = unload_re_filterfile;
1071 current_re_filterfile[i] = NULL;
1079 /*********************************************************************
1081 * Function : load_one_re_filterfile
1083 * Description : Load a re_filterfile.
1084 * Generate a chained list of re_filterfile_spec's from
1085 * the "FILTER: " blocks, compiling all their substitutions
1086 * into chained lists of pcrs_job structs.
1089 * 1 : csp = Current client state (buffers, headers, etc...)
1091 * Returns : 0 => Ok, everything else is an error.
1093 *********************************************************************/
1094 int load_one_re_filterfile(struct client_state *csp, int fileid)
1098 struct re_filterfile_spec *new_bl, *bl = NULL;
1099 struct file_list *fs;
1102 unsigned long linenum = 0;
1103 pcrs_job *dummy, *lastjob = NULL;
1106 * No need to reload if unchanged
1108 if (!check_file_changed(current_re_filterfile[fileid], csp->config->re_filterfile[fileid], &fs))
1110 csp->rlist[fileid] = current_re_filterfile[fileid];
1115 goto load_re_filterfile_error;
1119 * Open the file or fail
1121 if ((fp = fopen(csp->config->re_filterfile[fileid], "r")) == NULL)
1123 goto load_re_filterfile_error;
1126 log_error(LOG_LEVEL_INFO, "Loading filter file: %s", csp->config->re_filterfile[fileid]);
1131 while (read_config_line(fp, &linenum, &buf) != NULL)
1133 enum filter_type new_filter = FT_INVALID_FILTER;
1135 if (strncmp(buf, "FILTER:", 7) == 0)
1137 new_filter = FT_CONTENT_FILTER;
1139 else if (strncmp(buf, "SERVER-HEADER-FILTER:", 21) == 0)
1141 new_filter = FT_SERVER_HEADER_FILTER;
1143 else if (strncmp(buf, "CLIENT-HEADER-FILTER:", 21) == 0)
1145 new_filter = FT_CLIENT_HEADER_FILTER;
1147 else if (strncmp(buf, "CLIENT-HEADER-TAGGER:", 21) == 0)
1149 new_filter = FT_CLIENT_HEADER_TAGGER;
1151 else if (strncmp(buf, "SERVER-HEADER-TAGGER:", 21) == 0)
1153 new_filter = FT_SERVER_HEADER_TAGGER;
1155 #ifdef FEATURE_EXTERNAL_FILTERS
1156 else if (strncmp(buf, "EXTERNAL-FILTER:", 16) == 0)
1158 new_filter = FT_EXTERNAL_CONTENT_FILTER;
1163 * If this is the head of a new filter block, make it a
1164 * re_filterfile spec of its own and chain it to the list:
1166 if (new_filter != FT_INVALID_FILTER)
1168 new_bl = zalloc_or_die(sizeof(*bl));
1169 if (new_filter == FT_CONTENT_FILTER)
1171 new_bl->name = chomp(buf + 7);
1173 #ifdef FEATURE_EXTERNAL_FILTERS
1174 else if (new_filter == FT_EXTERNAL_CONTENT_FILTER)
1176 new_bl->name = chomp(buf + 16);
1181 new_bl->name = chomp(buf + 21);
1183 new_bl->type = new_filter;
1186 * If a filter description is available,
1187 * encode it to HTML and save it.
1189 if (NULL != (new_bl->description = strpbrk(new_bl->name, " \t")))
1191 *new_bl->description++ = '\0';
1192 new_bl->description = html_encode(chomp(new_bl->description));
1193 if (NULL == new_bl->description)
1195 new_bl->description = strdup_or_die("Out of memory while "
1196 "encoding filter description to HTML");
1201 new_bl->description = strdup_or_die("No description available");
1204 new_bl->name = strdup_or_die(chomp(new_bl->name));
1207 * If this is the first filter block, chain it
1208 * to the file_list rather than its (nonexistant)
1222 log_error(LOG_LEVEL_RE_FILTER, "Reading in filter \"%s\" (\"%s\")", bl->name, bl->description);
1228 #ifdef FEATURE_EXTERNAL_FILTERS
1229 if ((bl != NULL) && (bl->type == FT_EXTERNAL_CONTENT_FILTER))
1232 /* Save the code as "pattern", but do not compile anything. */
1233 if (bl->patterns->first != NULL)
1235 log_error(LOG_LEVEL_FATAL, "External filter '%s' contains several jobss. "
1236 "Did you forget to escape a line break?",
1239 jb_error = enlist(bl->patterns, buf);
1240 if (JB_ERR_MEMORY == jb_error)
1242 log_error(LOG_LEVEL_FATAL,
1243 "Out of memory while enlisting external filter code \'%s\' for filter %s.",
1255 * Save the expression, make it a pcrs_job
1256 * and chain it into the current filter's joblist
1258 jb_error = enlist(bl->patterns, buf);
1259 if (JB_ERR_MEMORY == jb_error)
1261 log_error(LOG_LEVEL_FATAL,
1262 "Out of memory while enlisting re_filter job \'%s\' for filter %s.", buf, bl->name);
1264 assert(JB_ERR_OK == jb_error);
1266 if (pcrs_job_is_dynamic(buf))
1269 * Dynamic pattern that might contain variables
1270 * and has to be recompiled for every request
1272 if (bl->joblist != NULL)
1274 pcrs_free_joblist(bl->joblist);
1278 log_error(LOG_LEVEL_RE_FILTER,
1279 "Adding dynamic re_filter job \'%s\' to filter %s succeeded.", buf, bl->name);
1283 else if (bl->dynamic)
1286 * A previous job was dynamic and as we
1287 * recompile the whole filter anyway, it
1288 * makes no sense to compile this job now.
1290 log_error(LOG_LEVEL_RE_FILTER,
1291 "Adding static re_filter job \'%s\' to dynamic filter %s succeeded.", buf, bl->name);
1296 if ((dummy = pcrs_compile_command(buf, &pcrs_error)) == NULL)
1298 log_error(LOG_LEVEL_ERROR,
1299 "Adding re_filter job \'%s\' to filter %s failed: %s",
1300 buf, bl->name, pcrs_strerror(pcrs_error));
1306 if (bl->joblist == NULL)
1308 bl->joblist = dummy;
1310 else if (NULL != lastjob)
1312 lastjob->next = dummy;
1315 log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job \'%s\' to filter %s succeeded.", buf, bl->name);
1320 log_error(LOG_LEVEL_ERROR, "Ignoring job %s outside filter block in %s, line %d",
1321 buf, csp->config->re_filterfile[fileid], linenum);
1329 * Schedule the now-obsolete old data for unloading
1331 if (NULL != current_re_filterfile[fileid])
1333 current_re_filterfile[fileid]->unloader = unload_re_filterfile;
1337 * Chain this file into the global list of loaded files
1339 fs->next = files->next;
1341 current_re_filterfile[fileid] = fs;
1342 csp->rlist[fileid] = fs;
1346 load_re_filterfile_error:
1347 log_error(LOG_LEVEL_FATAL, "can't load re_filterfile '%s': %E",
1348 csp->config->re_filterfile[fileid]);
1354 /*********************************************************************
1356 * Function : add_loader
1358 * Description : Called from `load_config'. Called once for each input
1359 * file found in config.
1362 * 1 : loader = pointer to a function that can parse and load
1363 * the appropriate config file.
1364 * 2 : config = The configuration_spec to add the loader to.
1368 *********************************************************************/
1369 void add_loader(int (*loader)(struct client_state *),
1370 struct configuration_spec * config)
1374 for (i = 0; i < NLOADERS; i++)
1376 if (config->loaders[i] == NULL)
1378 config->loaders[i] = loader;
1386 /*********************************************************************
1388 * Function : run_loader
1390 * Description : Called from `load_config' and `listen_loop'. This
1391 * function keeps the "csp" current with any file mods
1392 * since the last loop. If a file is unchanged, the
1393 * loader functions do NOT reload the file.
1396 * 1 : csp = Current client state (buffers, headers, etc...)
1397 * Must be non-null. Reads: "csp->config"
1398 * Writes: various data members.
1400 * Returns : 0 => Ok, everything else is an error.
1402 *********************************************************************/
1403 int run_loader(struct client_state *csp)
1408 for (i = 0; i < NLOADERS; i++)
1410 if (csp->config->loaders[i] == NULL)
1414 ret |= (csp->config->loaders[i])(csp);
1420 /*********************************************************************
1422 * Function : file_has_been_modified
1424 * Description : Helper function to check if a file has been changed
1427 * 1 : filename = The name of the file to check
1428 * 2 : last_known_modification = The time of the last known
1431 * Returns : TRUE if the file has been changed,
1434 *********************************************************************/
1435 static int file_has_been_modified(const char *filename, time_t last_know_modification)
1437 struct stat statbuf[1];
1439 if (stat(filename, statbuf) < 0)
1441 /* Error, probably file not found which counts as change. */
1445 return (last_know_modification != statbuf->st_mtime);
1449 /*********************************************************************
1451 * Function : any_loaded_file_changed
1453 * Description : Helper function to check if any loaded file has been
1454 * changed since the time it has been loaded.
1456 * XXX: Should we cache the return value for x seconds?
1459 * 1 : files_to_check = List of files to check
1461 * Returns : TRUE if any file has been changed,
1464 *********************************************************************/
1465 int any_loaded_file_changed(const struct client_state *csp)
1467 const struct file_list *file_to_check = csp->config->config_file_list;
1470 if (file_has_been_modified(file_to_check->filename, file_to_check->lastmodified))
1475 for (i = 0; i < MAX_AF_FILES; i++)
1477 if (csp->actions_list[i])
1479 file_to_check = csp->actions_list[i];
1480 if (file_has_been_modified(file_to_check->filename, file_to_check->lastmodified))
1487 for (i = 0; i < MAX_AF_FILES; i++)
1491 file_to_check = csp->rlist[i];
1492 if (file_has_been_modified(file_to_check->filename, file_to_check->lastmodified))
1499 #ifdef FEATURE_TRUST
1502 if (file_has_been_modified(csp->tlist->filename, csp->tlist->lastmodified))
1507 #endif /* def FEATURE_TRUST */