From 17f6c9b824f98abcf8c1680eaee66988bacdbd95 Mon Sep 17 00:00:00 2001 From: oes Date: Wed, 24 Apr 2002 02:10:31 +0000 Subject: [PATCH] - Jon's patch for multiple AFs: - split load_actions_file, add load_one_actions_file - make csp->actions_list files an array - remember file id with each action - Copy_action now frees dest action before copying --- actions.c | 117 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 38 deletions(-) diff --git a/actions.c b/actions.c index e0f3fcad..e3428f70 100644 --- a/actions.c +++ b/actions.c @@ -1,4 +1,4 @@ -const char actions_rcs[] = "$Id: actions.c,v 1.25 2002/03/24 13:25:43 swa Exp $"; +const char actions_rcs[] = "$Id: actions.c,v 1.26 2002/03/26 22:29:54 swa Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.c,v $ @@ -33,6 +33,9 @@ const char actions_rcs[] = "$Id: actions.c,v 1.25 2002/03/24 13:25:43 swa Exp $" * * Revisions : * $Log: actions.c,v $ + * Revision 1.26 2002/03/26 22:29:54 swa + * we have a new homepage! + * * Revision 1.25 2002/03/24 13:25:43 swa * name change related issues * @@ -226,6 +229,9 @@ static const struct action_name action_names[] = }; +static int load_one_actions_file(struct client_state *csp, int fileid); + + /********************************************************************* * * Function : merge_actions @@ -307,8 +313,6 @@ jb_err merge_actions (struct action_spec *dest, * * Description : Copy an action_specs. * Similar to "cur_action = new_action". - * Note that dest better not contain valid data - * - it's overwritten, not freed. * * Parameters : * 1 : dest = Destination of copy. @@ -323,6 +327,7 @@ jb_err copy_action (struct action_spec *dest, int i; jb_err err = JB_ERR_OK; + free_action(dest); memset(dest, '\0', sizeof(*dest)); dest->mask = src->mask; @@ -817,7 +822,10 @@ void free_current_action (struct current_action_spec *src) } -static struct file_list *current_actions_file = NULL; +static struct file_list *current_actions_file[MAX_ACTION_FILES] = { + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL +}; #ifdef FEATURE_GRACEFUL_TERMINATION @@ -903,7 +911,7 @@ void free_alias_list(struct action_alias *alias_list) * * Function : load_actions_file * - * Description : Read and parse a action file and add to files + * Description : Read and parse all the action files and add to files * list. * * Parameters : @@ -913,6 +921,45 @@ void free_alias_list(struct action_alias *alias_list) * *********************************************************************/ int load_actions_file(struct client_state *csp) +{ + int i; + int result; + + for (i = 0; i < MAX_ACTION_FILES; i++) + { + if (csp->config->actions_file[i]) + { + result = load_one_actions_file(csp, i); + if (result) + { + return result; + } + } + else if (current_actions_file[i]) + { + current_actions_file[i]->unloader = unload_actions_file; + current_actions_file[i] = NULL; + } + } + + return 0; +} + +/********************************************************************* + * + * Function : load_one_actions_file + * + * Description : Read and parse a action file and add to files + * list. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : fileid = File index to load. + * + * Returns : 0 => Ok, everything else is an error. + * + *********************************************************************/ +static int load_one_actions_file(struct client_state *csp, int fileid) { /* @@ -938,19 +985,16 @@ int load_actions_file(struct client_state *csp) struct action_alias * alias_list = NULL; unsigned long linenum = 0; - if (!check_file_changed(current_actions_file, csp->config->actions_file, &fs)) + if (!check_file_changed(current_actions_file[fileid], csp->config->actions_file[fileid], &fs)) { /* No need to load */ - if (csp) - { - csp->actions_list = current_actions_file; - } + csp->actions_list[fileid] = current_actions_file[fileid]; return 0; } if (!fs) { log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': error finding file: %E", - csp->config->actions_file); + csp->config->actions_file[fileid]); return 1; /* never get here */ } @@ -958,14 +1002,14 @@ int load_actions_file(struct client_state *csp) if (last_perm == NULL) { log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory!", - csp->config->actions_file); + csp->config->actions_file[fileid]); return 1; /* never get here */ } - if ((fp = fopen(csp->config->actions_file, "r")) == NULL) + if ((fp = fopen(csp->config->actions_file[fileid], "r")) == NULL) { log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': error opening file: %E", - csp->config->actions_file); + csp->config->actions_file[fileid]); return 1; /* never get here */ } @@ -986,7 +1030,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid line (%lu): %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } @@ -1000,7 +1044,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid line (%lu): {{ }}", - csp->config->actions_file, linenum); + csp->config->actions_file[fileid], linenum); return 1; /* never get here */ } @@ -1032,7 +1076,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': line %lu: {{settings}} must only appear once, and it must be before anything else.", - csp->config->actions_file, linenum); + csp->config->actions_file[fileid], linenum); } mode = MODE_SETTINGS; } @@ -1046,7 +1090,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': line %lu: {{description}} must only appear once, and only a {{settings}} block may be above it.", - csp->config->actions_file, linenum); + csp->config->actions_file[fileid], linenum); } mode = MODE_DESCRIPTION; } @@ -1068,7 +1112,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': line %lu: {{alias}} must only appear once, and it must be before all actions.", - csp->config->actions_file, linenum); + csp->config->actions_file[fileid], linenum); } mode = MODE_ALIAS; } @@ -1078,7 +1122,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid line (%lu): {{%s}}", - csp->config->actions_file, linenum, start); + csp->config->actions_file[fileid], linenum, start); return 1; /* never get here */ } } @@ -1109,7 +1153,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory", - csp->config->actions_file); + csp->config->actions_file[fileid]); return 1; /* never get here */ } init_action(cur_action); @@ -1125,7 +1169,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid line (%lu): %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } *end = '\0'; @@ -1139,7 +1183,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid line (%lu): %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } } @@ -1174,7 +1218,7 @@ int load_actions_file(struct client_state *csp) { log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid alias line (%lu): %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } @@ -1183,7 +1227,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory!", - csp->config->actions_file); + csp->config->actions_file[fileid]); return 1; /* never get here */ } @@ -1209,7 +1253,7 @@ int load_actions_file(struct client_state *csp) { log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid alias line (%lu): %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } @@ -1223,7 +1267,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': invalid alias line (%lu): %s = %s", - csp->config->actions_file, linenum, buf, start); + csp->config->actions_file[fileid], linenum, buf, start); return 1; /* never get here */ } @@ -1241,7 +1285,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory!", - csp->config->actions_file); + csp->config->actions_file[fileid]); return 1; /* never get here */ } @@ -1254,7 +1298,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': line %lu: cannot create URL pattern from: %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } @@ -1268,7 +1312,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': first needed line (%lu) is invalid: %s", - csp->config->actions_file, linenum, buf); + csp->config->actions_file[fileid], linenum, buf); return 1; /* never get here */ } else @@ -1277,7 +1321,7 @@ int load_actions_file(struct client_state *csp) fclose(fp); log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': INTERNAL ERROR - mode = %d", - csp->config->actions_file, mode); + csp->config->actions_file[fileid], mode); return 1; /* never get here */ } } @@ -1289,19 +1333,16 @@ int load_actions_file(struct client_state *csp) free_alias_list(alias_list); /* the old one is now obsolete */ - if (current_actions_file) + if (current_actions_file[fileid]) { - current_actions_file->unloader = unload_actions_file; + current_actions_file[fileid]->unloader = unload_actions_file; } fs->next = files->next; files->next = fs; - current_actions_file = fs; + current_actions_file[fileid] = fs; - if (csp) - { - csp->actions_list = fs; - } + csp->actions_list[fileid] = fs; return(0); -- 2.39.2