-const char loaders_rcs[] = "$Id: loaders.c,v 1.37 2002/03/03 15:07:49 oes Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.41 2002/03/12 01:42:50 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
*
* Revisions :
* $Log: loaders.c,v $
+ * Revision 1.41 2002/03/12 01:42:50 oes
+ * Introduced modular filters
+ *
+ * Revision 1.40 2002/03/08 17:46:04 jongfoster
+ * Fixing int/size_t warnings
+ *
+ * Revision 1.39 2002/03/07 03:46:17 oes
+ * Fixed compiler warnings
+ *
+ * Revision 1.38 2002/03/06 22:54:35 jongfoster
+ * Automated function-comment nitpicking.
+ *
* Revision 1.37 2002/03/03 15:07:49 oes
* Re-enabled automatic config reloading
*
fl->active = 0;
}
- for (csp = clients; csp && (ncsp = csp->next) ; csp = csp->next)
+ for (csp = clients; csp && (NULL != (ncsp = csp->next)) ; csp = csp->next)
{
if (ncsp->flags & CSP_FLAG_ACTIVE)
{
freez(ncsp);
/* are there any more in sequence after it? */
- if( !(ncsp = csp->next) )
+ if( (ncsp = csp->next) == NULL)
break;
}
}
}
- for (fl = files; fl && (nfl = fl->next) ; fl = fl->next)
+ for (fl = files; fl && ((nfl = fl->next) != NULL) ; fl = fl->next)
{
if ( ( 0 == nfl->active ) && ( NULL != nfl->unloader ) )
{
*********************************************************************/
jb_err simple_read_line(FILE *fp, char **dest, int *newline)
{
- int len = 0;
- int buflen = BUFFER_SIZE;
+ size_t len = 0;
+ size_t buflen = BUFFER_SIZE;
char * buf;
char * p;
int ch;
#define CHAR_CR '\r' /* ASCII 13 */
#define CHAR_LF '\n' /* ASCII 10 */
- while (FOREVER)
+ for (;;)
{
ch = fgetc(fp);
if (ch == EOF)
* Otherwise, returns buf.
*
*********************************************************************/
-char *read_config_line(char *buf, int buflen, FILE *fp, unsigned long *linenum)
+char *read_config_line(char *buf, size_t buflen, FILE *fp, unsigned long *linenum)
{
jb_err err;
char *buf2 = NULL;
else
{
assert(buf2);
- assert(strlen(buf2) + 1U < (unsigned)buflen);
+ assert(strlen(buf2) + 1U < buflen);
strncpy(buf, buf2, buflen - 1);
free(buf2);
buf[buflen - 1] = '\0';
reject = 0;
p = buf;
q = p+1;
- while ((*p++ = *q++))
+ while ((*p++ = *q++) != '\0')
{
/* nop */
}
*
* Function : unload_re_filterfile
*
- * Description : Unload the re_filter list.
+ * Description : Unload the re_filter list by freeing all chained
+ * re_filterfile specs and their data.
*
* Parameters :
* 1 : f = the data structure associated with the filterfile.
*********************************************************************/
static void unload_re_filterfile(void *f)
{
- struct re_filterfile_spec *b = (struct re_filterfile_spec *)f;
+ struct re_filterfile_spec *a, *b = (struct re_filterfile_spec *)f;
- if (b == NULL)
+ while (b != NULL)
{
- return;
- }
+ a = b->next;
- destroy_list(b->patterns);
- pcrs_free_joblist(b->joblist);
- freez(b);
+ destroy_list(b->patterns);
+ pcrs_free_joblist(b->joblist);
+ freez(b);
+
+ b = a;
+ }
return;
}
+
/*********************************************************************
*
* Function : load_re_filterfile
*
- * Description : Load the re_filterfile. Each non-comment, non-empty
- * line is instantly added to the joblist, which is
- * a chained list of pcrs_job structs.
+ * Description : Load the re_filterfile.
+ * Generate a chained list of re_filterfile_spec's from
+ * the "FILTER: " blocks, compiling all their substitutions
+ * into chained lists of pcrs_job structs.
*
* Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
{
FILE *fp;
- struct re_filterfile_spec *bl;
+ struct re_filterfile_spec *bl, *new_bl;
struct file_list *fs;
char buf[BUFFER_SIZE];
unsigned long linenum = 0;
pcrs_job *dummy;
+ /*
+ * No need to reload if unchanged
+ */
if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs))
{
- /* No need to load */
if (csp)
{
csp->rlist = current_re_filterfile;
goto load_re_filterfile_error;
}
+ /*
+ * Allocate the first re_filterfile_spec struct
+ */
fs->f = bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl));
if (bl == NULL)
{
goto load_re_filterfile_error;
}
- /* Open the file or fail */
+ /*
+ * Initialize the name in case there are
+ * expressions before the first block header
+ */
+ bl->filtername = "default";
+
+ /*
+ * Open the file or fail
+ */
if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL)
{
goto load_re_filterfile_error;
}
- /* Read line by line */
+ /*
+ * Read line by line
+ */
while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
{
- enlist( bl->patterns, buf );
+ /*
+ * If this is the head of a new filter block, make it a
+ * re_filterfile spec of its own and chain it to the list:
+ */
+ if (strncmp(buf, "FILTER:", 7) == 0)
+ {
+ new_bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl));
+ if (new_bl == NULL)
+ {
+ goto load_re_filterfile_error;
+ }
+ else
+ {
+ new_bl->filtername = strdup(chomp(buf + 7));
+ bl->next = new_bl;
+ bl = new_bl;
+ }
+ continue;
+ }
+
+ /*
+ * Else, save the expression, make it a pcrs_job
+ * and chain it into the current filter's joblist
+ */
+ enlist(bl->patterns, buf);
- /* We have a meaningful line -> make it a job */
if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
{
log_error(LOG_LEVEL_RE_FILTER,
- "Adding re_filter job %s failed with error %d.", buf, error);
+ "Adding re_filter job %s to filter %s failed with error %d.", buf, bl->filtername, error);
continue;
}
else
{
dummy->next = bl->joblist;
bl->joblist = dummy;
- log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s succeeded.", buf);
+ log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s to filter %s succeeded.", buf, bl->filtername);
}
}
fclose(fp);
- /* the old one is now obsolete */
+ /*
+ * Schedule the now-obsolete old data for unloading
+ */
if ( NULL != current_re_filterfile )
{
current_re_filterfile->unloader = unload_re_filterfile;
}
+ /*
+ * Chain this file into the global list of loaded files
+ */
fs->next = files->next;
files->next = fs;
current_re_filterfile = fs;