1 const char actions_rcs[] = "$Id: actions.c,v 1.21 2002/01/17 20:54:44 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/actions.c,v $
6 * Purpose : Declares functions to work with actions files
7 * Functions declared include: FIXME
9 * Copyright : Written by and Copyright (C) 2001 the SourceForge
10 * IJBSWA team. http://ijbswa.sourceforge.net
12 * Based on the Internet Junkbuster originally written
13 * by and Copyright (C) 1997 Anonymous Coders and
14 * Junkbusters Corporation. http://www.junkbusters.com
16 * This program is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General
18 * Public License as published by the Free Software
19 * Foundation; either version 2 of the License, or (at
20 * your option) any later version.
22 * This program is distributed in the hope that it will
23 * be useful, but WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A
25 * PARTICULAR PURPOSE. See the GNU General Public
26 * License for more details.
28 * The GNU General Public License should be included with
29 * this file. If not, you can view it at
30 * http://www.gnu.org/copyleft/gpl.html
31 * or write to the Free Software Foundation, Inc., 59
32 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 * Revision 1.21 2002/01/17 20:54:44 jongfoster
37 * Renaming free_url to free_url_spec, since it frees a struct url_spec.
39 * Revision 1.20 2001/11/22 21:56:49 jongfoster
40 * Making action_spec->flags into an unsigned long rather than just an
42 * Fixing a bug in the display of -add-header and -wafer
44 * Revision 1.19 2001/11/13 00:14:07 jongfoster
45 * Fixing stupid bug now I've figured out what || means.
46 * (It always returns 0 or 1, not one of it's paramaters.)
48 * Revision 1.18 2001/11/07 00:06:06 steudten
49 * Add line number in error output for lineparsing for
52 * Revision 1.17 2001/10/25 03:40:47 david__schmidt
53 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
54 * threads to call select() simultaneously. So, it's time to do a real, live,
55 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
56 * (native). Both versions will work, but using __OS2__ offers multi-threading.
58 * Revision 1.16 2001/10/23 21:30:30 jongfoster
59 * Adding error-checking to selected functions.
61 * Revision 1.15 2001/10/14 21:58:22 jongfoster
62 * Adding support for the CGI-based editor:
63 * - Exported get_actions()
64 * - Added new function free_alias_list()
65 * - Added support for {{settings}} and {{description}} blocks
66 * in the actions file. They are currently ignored.
67 * - Added restriction to only one {{alias}} block which must appear
68 * first in the file, to simplify the editor's rewriting rules.
69 * - Note that load_actions_file() is no longer used by the CGI-based
70 * editor, but some of the other routines in this file are.
72 * Revision 1.14 2001/09/22 16:36:59 jongfoster
73 * Removing unused parameter fs from read_config_line()
75 * Revision 1.13 2001/09/16 15:47:37 jongfoster
76 * First version of CGI-based edit interface. This is very much a
77 * work-in-progress, and you can't actually use it to edit anything
78 * yet. You must #define FEATURE_CGI_EDIT_ACTIONS for these changes
81 * Revision 1.12 2001/09/16 13:21:27 jongfoster
82 * Changes to use new list functions.
84 * Revision 1.11 2001/09/14 00:17:32 jongfoster
85 * Tidying up memory allocation. New function init_action().
87 * Revision 1.10 2001/09/10 10:14:34 oes
88 * Removing unused variable
90 * Revision 1.9 2001/07/30 22:08:36 jongfoster
91 * Tidying up #defines:
92 * - All feature #defines are now of the form FEATURE_xxx
93 * - Permanently turned off WIN_GUI_EDIT
94 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
96 * Revision 1.8 2001/06/29 13:19:52 oes
97 * Removed logentry from cancelled commit
99 * Revision 1.7 2001/06/09 10:55:28 jongfoster
100 * Changing BUFSIZ ==> BUFFER_SIZE
102 * Revision 1.6 2001/06/07 23:04:34 jongfoster
103 * Made get_actions() static.
105 * Revision 1.5 2001/06/03 19:11:48 oes
106 * adapted to new enlist_unique arg format
108 * Revision 1.4 2001/06/01 20:03:42 jongfoster
109 * Better memory management - current_action->strings[] now
110 * contains copies of the strings, not the original.
112 * Revision 1.3 2001/06/01 18:49:17 jongfoster
113 * Replaced "list_share" with "list" - the tiny memory gain was not
114 * worth the extra complexity.
116 * Revision 1.2 2001/05/31 21:40:00 jongfoster
117 * Removing some commented out, obsolete blocks of code.
119 * Revision 1.1 2001/05/31 21:16:46 jongfoster
120 * Moved functions to process the action list into this new file.
123 *********************************************************************/
137 #include "miscutil.h"
140 #ifdef FEATURE_CGI_EDIT_ACTIONS
142 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
143 #include "urlmatch.h"
145 const char actions_h_rcs[] = ACTIONS_H_VERSION;
149 * We need the main list of options.
151 * First, we need a way to tell between boolean, string, and multi-string
152 * options. For string and multistring options, we also need to be
153 * able to tell the difference between a "+" and a "-". (For bools,
154 * the "+"/"-" information is encoded in "add" and "mask"). So we use
155 * an enumerated type (well, the preprocessor equivalent). Here are
158 #define AV_NONE 0 /* +opt -opt */
159 #define AV_ADD_STRING 1 /* +stropt{string} */
160 #define AV_REM_STRING 2 /* -stropt */
161 #define AV_ADD_MULTI 3 /* +multiopt{string} +multiopt{string2} */
162 #define AV_REM_MULTI 4 /* -multiopt{string} -multiopt */
165 * We need a structure to hold the name, flag changes,
166 * type, and string index.
171 unsigned mask; /* a bit set to "0" = remove action */
172 unsigned add; /* a bit set to "1" = add action */
173 int takes_value; /* an AV_... constant */
174 int index; /* index into strings[] or multi[] */
178 * And with those building blocks in place, here's the array.
180 static const struct action_name action_names[] =
183 * Well actually there's no data here - it's in actionlist.h
184 * This keeps it together to make it easy to change.
186 * Here's the macros used to format it:
188 #define DEFINE_ACTION_MULTI(name,index) \
189 { "+" name, ACTION_MASK_ALL, 0, AV_ADD_MULTI, index }, \
190 { "-" name, ACTION_MASK_ALL, 0, AV_REM_MULTI, index },
191 #define DEFINE_ACTION_STRING(name,flag,index) \
192 { "+" name, ACTION_MASK_ALL, flag, AV_ADD_STRING, index }, \
193 { "-" name, ~flag, 0, AV_REM_STRING, index },
194 #define DEFINE_ACTION_BOOL(name,flag) \
195 { "+" name, ACTION_MASK_ALL, flag }, \
196 { "-" name, ~flag, 0 },
197 #define DEFINE_ACTION_ALIAS 1 /* Want aliases please */
199 #include "actionlist.h"
201 #undef DEFINE_ACTION_MULTI
202 #undef DEFINE_ACTION_STRING
203 #undef DEFINE_ACTION_BOOL
204 #undef DEFINE_ACTION_ALIAS
206 { NULL, 0, 0 } /* End marker */
210 /*********************************************************************
212 * Function : merge_actions
214 * Description : Merge two actions together.
215 * Similar to "cur_action += new_action".
218 * 1 : cur_action = Current actions, to modify.
219 * 2 : new_action = Action to add.
221 * Returns : JB_ERR_OK or JB_ERR_MEMORY
223 *********************************************************************/
224 jb_err merge_actions (struct action_spec *dest,
225 const struct action_spec *src)
230 dest->mask &= src->mask;
231 dest->add &= src->mask;
232 dest->add |= src->add;
234 for (i = 0; i < ACTION_STRING_COUNT; i++)
236 char * str = src->string[i];
239 freez(dest->string[i]);
240 dest->string[i] = strdup(str);
241 if (NULL == dest->string[i])
243 return JB_ERR_MEMORY;
248 for (i = 0; i < ACTION_MULTI_COUNT; i++)
250 if (src->multi_remove_all[i])
252 /* Remove everything from dest */
253 list_remove_all(dest->multi_remove[i]);
254 dest->multi_remove_all[i] = 1;
256 err = list_duplicate(dest->multi_add[i], src->multi_add[i]);
258 else if (dest->multi_remove_all[i])
261 * dest already removes everything, so we only need to worry
264 list_remove_list(dest->multi_add[i], src->multi_remove[i]);
265 err = list_append_list_unique(dest->multi_add[i], src->multi_add[i]);
269 /* No "remove all"s to worry about. */
270 list_remove_list(dest->multi_add[i], src->multi_remove[i]);
271 err = list_append_list_unique(dest->multi_remove[i], src->multi_remove[i]);
272 if (!err) err = list_append_list_unique(dest->multi_add[i], src->multi_add[i]);
285 /*********************************************************************
287 * Function : copy_action
289 * Description : Copy an action_specs.
290 * Similar to "cur_action = new_action".
291 * Note that dest better not contain valid data
292 * - it's overwritten, not freed.
295 * 1 : dest = Destination of copy.
296 * 2 : src = Source for copy.
300 *********************************************************************/
301 jb_err copy_action (struct action_spec *dest,
302 const struct action_spec *src)
305 jb_err err = JB_ERR_OK;
307 memset(dest, '\0', sizeof(*dest));
309 dest->mask = src->mask;
310 dest->add = src->add;
312 for (i = 0; i < ACTION_STRING_COUNT; i++)
314 char * str = src->string[i];
320 return JB_ERR_MEMORY;
322 dest->string[i] = str;
326 for (i = 0; i < ACTION_MULTI_COUNT; i++)
328 dest->multi_remove_all[i] = src->multi_remove_all[i];
329 err = list_duplicate(dest->multi_remove[i], src->multi_remove[i]);
334 err = list_duplicate(dest->multi_add[i], src->multi_add[i]);
344 /*********************************************************************
346 * Function : free_action
348 * Description : Destroy an action_spec. Frees memory used by it,
349 * except for the memory used by the struct action_spec
353 * 1 : src = Source to free.
357 *********************************************************************/
358 void free_action (struct action_spec *src)
367 for (i = 0; i < ACTION_STRING_COUNT; i++)
369 freez(src->string[i]);
372 for (i = 0; i < ACTION_MULTI_COUNT; i++)
374 destroy_list(src->multi_remove[i]);
375 destroy_list(src->multi_add[i]);
378 memset(src, '\0', sizeof(*src));
382 /*********************************************************************
384 * Function : get_action_token
386 * Description : Parses a line for the first action.
387 * Modifies it's input array, doesn't allocate memory.
389 * *line=" +abc{def} -ghi "
396 * 1 : line = [in] The line containing the action.
397 * [out] Start of next action on line, or
398 * NULL if we reached the end of line before
399 * we found an action.
400 * 2 : name = [out] Start of action name, null
401 * terminated. NULL on EOL
402 * 3 : value = [out] Start of action value, null
403 * terminated. NULL if none or EOL.
405 * Returns : JB_ERR_OK => Ok
406 * JB_ERR_PARSE => Mismatched {} (line was trashed anyway)
408 *********************************************************************/
409 jb_err get_action_token(char **line, char **name, char **value)
414 /* set default returns */
419 /* Eat any leading whitespace */
420 while ((*str == ' ') || (*str == '\t'))
432 /* null name, just value is prohibited */
439 while (((ch = *str) != '\0') &&
440 (ch != ' ') && (ch != '\t') && (ch != '{'))
444 /* error, '}' without '{' */
456 /* EOL - be careful not to run off buffer */
461 /* More to parse next time. */
470 str = strchr(str, '}');
488 /*********************************************************************
490 * Function : get_actions
492 * Description : Parses a list of actions.
495 * 1 : line = The string containing the actions.
496 * Will be written to by this function.
497 * 2 : aliases = Custom alias list, or NULL for none.
498 * 3 : cur_action = Where to store the action. Caller
501 * Returns : JB_ERR_OK => Ok
502 * JB_ERR_PARSE => Parse error (line was trashed anyway)
503 * nonzero => Out of memory (line was trashed anyway)
505 *********************************************************************/
506 jb_err get_actions(char *line,
507 struct action_alias * alias_list,
508 struct action_spec *cur_action)
511 init_action(cur_action);
512 cur_action->mask = ACTION_MASK_ALL;
516 char * option = NULL;
519 err = get_action_token(&line, &option, &value);
527 /* handle option in 'option' */
529 /* Check for standard action name */
530 const struct action_name * action = action_names;
532 while ( (action->name != NULL) && (0 != strcmpic(action->name, option)) )
536 if (action->name != NULL)
539 cur_action->mask &= action->mask;
540 cur_action->add &= action->mask;
541 cur_action->add |= action->add;
543 switch (action->takes_value)
546 /* ignore any option. */
550 /* add single string. */
552 if ((value == NULL) || (*value == '\0'))
556 /* FIXME: should validate option string here */
557 freez (cur_action->string[action->index]);
558 cur_action->string[action->index] = strdup(value);
559 if (NULL == cur_action->string[action->index])
561 return JB_ERR_MEMORY;
567 /* remove single string. */
569 freez (cur_action->string[action->index]);
574 /* append multi string. */
576 struct list * remove = cur_action->multi_remove[action->index];
577 struct list * add = cur_action->multi_add[action->index];
579 if ((value == NULL) || (*value == '\0'))
584 list_remove_item(remove, value);
585 err = enlist_unique(add, value, 0);
594 /* remove multi string. */
596 struct list * remove = cur_action->multi_remove[action->index];
597 struct list * add = cur_action->multi_add[action->index];
599 if ( (value == NULL) || (*value == '\0')
600 || ((*value == '*') && (value[1] == '\0')) )
603 * no option, or option == "*".
607 list_remove_all(remove);
608 list_remove_all(add);
609 cur_action->multi_remove_all[action->index] = 1;
613 /* Valid option - remove only 1 option */
615 if ( !cur_action->multi_remove_all[action->index] )
617 /* there isn't a catch-all in the remove list already */
618 err = enlist_unique(remove, value, 0);
624 list_remove_item(add, value);
629 /* Shouldn't get here unless there's memory corruption. */
636 /* try user aliases. */
637 const struct action_alias * alias = alias_list;
639 while ( (alias != NULL) && (0 != strcmpic(alias->name, option)) )
646 merge_actions(cur_action, alias->action);
650 /* Bad action name */
661 /*********************************************************************
663 * Function : init_current_action
665 * Description : Zero out an action.
668 * 1 : dest = An uninitialized current_action_spec.
672 *********************************************************************/
673 void init_current_action (struct current_action_spec *dest)
675 memset(dest, '\0', sizeof(*dest));
677 dest->flags = ACTION_MOST_COMPATIBLE;
681 /*********************************************************************
683 * Function : init_action
685 * Description : Zero out an action.
688 * 1 : dest = An uninitialized action_spec.
692 *********************************************************************/
693 void init_action (struct action_spec *dest)
695 memset(dest, '\0', sizeof(*dest));
699 /*********************************************************************
701 * Function : merge_current_action
703 * Description : Merge two actions together.
704 * Similar to "dest += src".
705 * Differences between this and merge_actions()
706 * is that this one doesn't allocate memory for
707 * strings (so "src" better be in memory for at least
708 * as long as "dest" is, and you'd better free
709 * "dest" using "free_current_action").
710 * Also, there is no mask or remove lists in dest.
711 * (If we're applying it to a URL, we don't need them)
714 * 1 : dest = Current actions, to modify.
715 * 2 : src = Action to add.
717 * Returns 0 : no error
718 * !=0 : error, probably JB_ERR_MEMORY.
720 *********************************************************************/
721 jb_err merge_current_action (struct current_action_spec *dest,
722 const struct action_spec *src)
725 jb_err err = JB_ERR_OK;
727 dest->flags &= src->mask;
728 dest->flags |= src->add;
730 for (i = 0; i < ACTION_STRING_COUNT; i++)
732 char * str = src->string[i];
738 return JB_ERR_MEMORY;
740 freez(dest->string[i]);
741 dest->string[i] = str;
745 for (i = 0; i < ACTION_MULTI_COUNT; i++)
747 if (src->multi_remove_all[i])
749 /* Remove everything from dest, then add src->multi_add */
750 err = list_duplicate(dest->multi[i], src->multi_add[i]);
758 list_remove_list(dest->multi[i], src->multi_remove[i]);
759 err = list_append_list_unique(dest->multi[i], src->multi_add[i]);
770 /*********************************************************************
772 * Function : free_current_action
774 * Description : Free memory used by a current_action_spec.
775 * Does not free the current_action_spec itself.
778 * 1 : src = Source to free.
782 *********************************************************************/
783 void free_current_action (struct current_action_spec *src)
787 for (i = 0; i < ACTION_STRING_COUNT; i++)
789 freez(src->string[i]);
792 for (i = 0; i < ACTION_MULTI_COUNT; i++)
794 destroy_list(src->multi[i]);
797 memset(src, '\0', sizeof(*src));
801 /*********************************************************************
803 * Function : unload_actions_file
805 * Description : Unloads an actions module.
808 * 1 : file_data = the data structure associated with the
813 *********************************************************************/
814 void unload_actions_file(void *file_data)
816 struct url_actions * next;
817 struct url_actions * cur = (struct url_actions *)file_data;
821 free_url_spec(cur->url);
822 free_action(cur->action);
830 /*********************************************************************
832 * Function : free_alias_list
834 * Description : Free memory used by a list of aliases.
837 * 1 : alias_list = Linked list to free.
841 *********************************************************************/
842 void free_alias_list(struct action_alias *alias_list)
844 while (alias_list != NULL)
846 struct action_alias * next = alias_list->next;
847 alias_list->next = NULL;
848 freez(alias_list->name);
849 free_action(alias_list->action);
856 /*********************************************************************
858 * Function : load_actions_file
860 * Description : Read and parse a action file and add to files
864 * 1 : csp = Current client state (buffers, headers, etc...)
866 * Returns : 0 => Ok, everything else is an error.
868 *********************************************************************/
869 int load_actions_file(struct client_state *csp)
871 static struct file_list *current_actions_file = NULL;
875 * Note: Keep these in the order they occur in the file, they are
876 * sometimes tested with <=
878 #define MODE_START_OF_FILE 1
879 #define MODE_SETTINGS 2
880 #define MODE_DESCRIPTION 3
882 #define MODE_ACTIONS 5
884 int mode = MODE_START_OF_FILE;
887 struct url_actions *last_perm;
888 struct url_actions *perm;
889 char buf[BUFFER_SIZE];
890 struct file_list *fs;
891 struct action_spec * cur_action = NULL;
892 int cur_action_used = 0;
893 struct action_alias * alias_list = NULL;
894 unsigned long linenum = 0;
896 if (!check_file_changed(current_actions_file, csp->config->actions_file, &fs))
898 /* No need to load */
901 csp->actions_list = current_actions_file;
907 log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': error finding file: %E",
908 csp->config->actions_file);
909 return 1; /* never get here */
912 fs->f = last_perm = (struct url_actions *)zalloc(sizeof(*last_perm));
913 if (last_perm == NULL)
915 log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory!",
916 csp->config->actions_file);
917 return 1; /* never get here */
920 if ((fp = fopen(csp->config->actions_file, "r")) == NULL)
922 log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': error opening file: %E",
923 csp->config->actions_file);
924 return 1; /* never get here */
927 while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
931 /* It's a header block */
934 /* It's {{settings}} or {{alias}} */
935 int len = strlen(buf);
936 char * start = buf + 2;
937 char * end = buf + len - 1;
938 if ((len < 5) || (*end-- != '}') || (*end-- != '}'))
942 log_error(LOG_LEVEL_FATAL,
943 "can't load actions file '%s': invalid line (%lu): %s",
944 csp->config->actions_file, linenum, buf);
945 return 1; /* never get here */
948 /* Trim leading and trailing whitespace. */
956 log_error(LOG_LEVEL_FATAL,
957 "can't load actions file '%s': invalid line (%lu): {{ }}",
958 csp->config->actions_file, linenum);
959 return 1; /* never get here */
963 * An actionsfile can optionally contain the following blocks.
964 * They *MUST* be in this order, to simplify processing:
970 * ...free text, format TBD, but no line may start with a '{'...
975 * The actual actions must be *after* these special blocks.
976 * None of these special blocks may be repeated.
979 if (0 == strcmpic(start, "settings"))
981 /* it's a {{settings}} block */
982 if (mode >= MODE_SETTINGS)
984 /* {{settings}} must be first thing in file and must only
988 log_error(LOG_LEVEL_FATAL,
989 "can't load actions file '%s': line %lu: {{settings}} must only appear once, and it must be before anything else.",
990 csp->config->actions_file, linenum);
992 mode = MODE_SETTINGS;
994 else if (0 == strcmpic(start, "description"))
996 /* it's a {{description}} block */
997 if (mode >= MODE_DESCRIPTION)
999 /* {{description}} is a singleton and only {{settings}} may proceed it
1002 log_error(LOG_LEVEL_FATAL,
1003 "can't load actions file '%s': line %lu: {{description}} must only appear once, and only a {{settings}} block may be above it.",
1004 csp->config->actions_file, linenum);
1006 mode = MODE_DESCRIPTION;
1008 else if (0 == strcmpic(start, "alias"))
1010 /* it's an {{alias}} block */
1011 if (mode >= MODE_ALIAS)
1013 /* {{alias}} must be first thing in file, possibly after
1014 * {{settings}} and {{description}}
1016 * {{alias}} must only appear once.
1018 * Note that these are new restrictions introduced in
1019 * v2.9.10 in order to make actionsfile editing simpler.
1020 * (Otherwise, reordering actionsfile entries without
1021 * completely rewriting the file becomes non-trivial)
1024 log_error(LOG_LEVEL_FATAL,
1025 "can't load actions file '%s': line %lu: {{alias}} must only appear once, and it must be before all actions.",
1026 csp->config->actions_file, linenum);
1032 /* invalid {{something}} block */
1034 log_error(LOG_LEVEL_FATAL,
1035 "can't load actions file '%s': invalid line (%lu): {{%s}}",
1036 csp->config->actions_file, linenum, start);
1037 return 1; /* never get here */
1042 /* It's an actions block */
1044 char actions_buf[BUFFER_SIZE];
1048 mode = MODE_ACTIONS;
1050 /* free old action */
1053 if (!cur_action_used)
1055 free_action(cur_action);
1060 cur_action_used = 0;
1061 cur_action = (struct action_spec *)zalloc(sizeof(*cur_action));
1062 if (cur_action == NULL)
1065 log_error(LOG_LEVEL_FATAL,
1066 "can't load actions file '%s': out of memory",
1067 csp->config->actions_file);
1068 return 1; /* never get here */
1070 init_action(cur_action);
1073 strcpy(actions_buf, buf + 1);
1075 /* check we have a trailing } and then trim it */
1076 end = actions_buf + strlen(actions_buf) - 1;
1081 log_error(LOG_LEVEL_FATAL,
1082 "can't load actions file '%s': invalid line (%lu): %s",
1083 csp->config->actions_file, linenum, buf);
1084 return 1; /* never get here */
1088 /* trim any whitespace immediately inside {} */
1091 if (get_actions(actions_buf, alias_list, cur_action))
1095 log_error(LOG_LEVEL_FATAL,
1096 "can't load actions file '%s': invalid line (%lu): %s",
1097 csp->config->actions_file, linenum, buf);
1098 return 1; /* never get here */
1102 else if (mode == MODE_SETTINGS)
1105 * Part of the {{settings}} block.
1106 * Ignore for now, but we may want to read & check permissions
1107 * when we go multi-user.
1110 else if (mode == MODE_DESCRIPTION)
1113 * Part of the {{description}} block.
1117 else if (mode == MODE_ALIAS)
1122 char actions_buf[BUFFER_SIZE];
1123 struct action_alias * new_alias;
1125 char * start = strchr(buf, '=');
1128 if ((start == NULL) || (start == buf))
1130 log_error(LOG_LEVEL_FATAL,
1131 "can't load actions file '%s': invalid alias line (%lu): %s",
1132 csp->config->actions_file, linenum, buf);
1133 return 1; /* never get here */
1136 if ((new_alias = zalloc(sizeof(*new_alias))) == NULL)
1139 log_error(LOG_LEVEL_FATAL,
1140 "can't load actions file '%s': out of memory!",
1141 csp->config->actions_file);
1142 return 1; /* never get here */
1145 /* Eat any the whitespace before the '=' */
1147 while ((*end == ' ') || (*end == '\t'))
1150 * we already know we must have at least 1 non-ws char
1151 * at start of buf - no need to check
1157 /* Eat any the whitespace after the '=' */
1159 while ((*start == ' ') || (*start == '\t'))
1165 log_error(LOG_LEVEL_FATAL,
1166 "can't load actions file '%s': invalid alias line (%lu): %s",
1167 csp->config->actions_file, linenum, buf);
1168 return 1; /* never get here */
1171 new_alias->name = strdup(buf);
1173 strcpy(actions_buf, start);
1175 if (get_actions(actions_buf, alias_list, new_alias->action))
1179 log_error(LOG_LEVEL_FATAL,
1180 "can't load actions file '%s': invalid alias line (%lu): %s = %s",
1181 csp->config->actions_file, linenum, buf, start);
1182 return 1; /* never get here */
1186 new_alias->next = alias_list;
1187 alias_list = new_alias;
1189 else if (mode == MODE_ACTIONS)
1191 /* it's a URL pattern */
1193 /* allocate a new node */
1194 if ((perm = zalloc(sizeof(*perm))) == NULL)
1197 log_error(LOG_LEVEL_FATAL,
1198 "can't load actions file '%s': out of memory!",
1199 csp->config->actions_file);
1200 return 1; /* never get here */
1204 copy_action (perm->action, cur_action);
1206 /* Save the URL pattern */
1207 if (create_url_spec(perm->url, buf))
1210 log_error(LOG_LEVEL_FATAL,
1211 "can't load actions file '%s': line %lu: cannot create URL pattern from: %s",
1212 csp->config->actions_file, linenum, buf);
1213 return 1; /* never get here */
1216 /* add it to the list */
1217 last_perm->next = perm;
1220 else if (mode == MODE_START_OF_FILE)
1222 /* oops - please have a {} line as 1st line in file. */
1224 log_error(LOG_LEVEL_FATAL,
1225 "can't load actions file '%s': first needed line (%lu) is invalid: %s",
1226 csp->config->actions_file, linenum, buf);
1227 return 1; /* never get here */
1231 /* How did we get here? This is impossible! */
1233 log_error(LOG_LEVEL_FATAL,
1234 "can't load actions file '%s': INTERNAL ERROR - mode = %d",
1235 csp->config->actions_file, mode);
1236 return 1; /* never get here */
1242 free_action(cur_action);
1244 free_alias_list(alias_list);
1246 /* the old one is now obsolete */
1247 if (current_actions_file)
1249 current_actions_file->unloader = unload_actions_file;
1252 fs->next = files->next;
1254 current_actions_file = fs;
1258 csp->actions_list = fs;
1266 /*********************************************************************
1268 * Function : actions_to_text
1270 * Description : Converts a actionsfile entry from numeric form
1271 * ("mask" and "add") to text.
1274 * 1 : mask = As from struct url_actions
1275 * 2 : add = As from struct url_actions
1277 * Returns : A string. Caller must free it.
1278 * NULL on out-of-memory error.
1280 *********************************************************************/
1281 char * actions_to_text(struct action_spec *action)
1283 unsigned mask = action->mask;
1284 unsigned add = action->add;
1285 char * result = strdup("");
1286 struct list_entry * lst;
1288 /* sanity - prevents "-feature +feature" */
1292 #define DEFINE_ACTION_BOOL(__name, __bit) \
1293 if (!(mask & __bit)) \
1295 string_append(&result, " -" __name); \
1297 else if (add & __bit) \
1299 string_append(&result, " +" __name); \
1302 #define DEFINE_ACTION_STRING(__name, __bit, __index) \
1303 if (!(mask & __bit)) \
1305 string_append(&result, " -" __name); \
1307 else if (add & __bit) \
1309 string_append(&result, " +" __name "{"); \
1310 string_append(&result, action->string[__index]); \
1311 string_append(&result, "}"); \
1314 #define DEFINE_ACTION_MULTI(__name, __index) \
1315 if (action->multi_remove_all[__index]) \
1317 string_append(&result, " -" __name); \
1321 lst = action->multi_remove[__index]->first; \
1324 string_append(&result, " -" __name "{"); \
1325 string_append(&result, lst->str); \
1326 string_append(&result, "}"); \
1330 lst = action->multi_add[__index]->first; \
1333 string_append(&result, " +" __name "{"); \
1334 string_append(&result, lst->str); \
1335 string_append(&result, "}"); \
1339 #define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
1341 #include "actionlist.h"
1343 #undef DEFINE_ACTION_MULTI
1344 #undef DEFINE_ACTION_STRING
1345 #undef DEFINE_ACTION_BOOL
1346 #undef DEFINE_ACTION_ALIAS
1352 #ifdef FEATURE_CGI_EDIT_ACTIONS
1353 /*********************************************************************
1355 * Function : actions_to_html
1357 * Description : Converts a actionsfile entry from numeric form
1358 * ("mask" and "add") to a <br>-seperated HTML string.
1361 * 1 : mask = As from struct url_actions
1362 * 2 : add = As from struct url_actions
1364 * Returns : A string. Caller must free it.
1365 * NULL on out-of-memory error.
1367 *********************************************************************/
1368 char * actions_to_html(struct action_spec *action)
1370 unsigned mask = action->mask;
1371 unsigned add = action->add;
1372 char * result = strdup("");
1374 struct list_entry * lst;
1376 /* sanity - prevents "-feature +feature" */
1380 #define DEFINE_ACTION_BOOL(__name, __bit) \
1381 if (!(mask & __bit)) \
1383 string_append(&result, "\n<br>-" __name); \
1385 else if (add & __bit) \
1387 string_append(&result, "\n<br>+" __name); \
1390 #define DEFINE_ACTION_STRING(__name, __bit, __index) \
1391 if (!(mask & __bit)) \
1393 string_append(&result, "\n<br>-" __name); \
1395 else if (add & __bit) \
1397 string_append(&result, "\n<br>+" __name "{"); \
1398 if (NULL == result) \
1402 enc_str = html_encode(action->string[__index]);\
1403 if (NULL == enc_str) \
1408 string_append(&result, enc_str); \
1410 string_append(&result, "}"); \
1413 #define DEFINE_ACTION_MULTI(__name, __index) \
1414 if (action->multi_remove_all[__index]) \
1416 string_append(&result, "\n<br>-" __name); \
1420 lst = action->multi_remove[__index]->first; \
1423 string_append(&result, "\n<br>-" __name "{");\
1424 if (NULL == result) \
1428 enc_str = html_encode(lst->str); \
1429 if (NULL == enc_str) \
1434 string_append(&result, enc_str); \
1436 string_append(&result, "}"); \
1440 lst = action->multi_add[__index]->first; \
1443 string_append(&result, "\n<br>+" __name "{"); \
1444 if (NULL == result) \
1448 enc_str = html_encode(lst->str); \
1449 if (NULL == enc_str) \
1454 string_append(&result, enc_str); \
1456 string_append(&result, "}"); \
1460 #define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
1462 #include "actionlist.h"
1464 #undef DEFINE_ACTION_MULTI
1465 #undef DEFINE_ACTION_STRING
1466 #undef DEFINE_ACTION_BOOL
1467 #undef DEFINE_ACTION_ALIAS
1469 /* trim leading <br> */
1470 if (result && *result)
1473 result = strdup(result + 5);
1479 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1482 /*********************************************************************
1484 * Function : current_actions_to_text
1486 * Description : Converts a actionsfile entry to text.
1489 * 1 : action = Action
1491 * Returns : A string. Caller must free it.
1492 * NULL on out-of-memory error.
1494 *********************************************************************/
1495 char * current_action_to_text(struct current_action_spec *action)
1497 unsigned long flags = action->flags;
1498 char * result = strdup("");
1499 struct list_entry * lst;
1501 #define DEFINE_ACTION_BOOL(__name, __bit) \
1502 if (flags & __bit) \
1504 string_append(&result, " +" __name); \
1508 string_append(&result, " -" __name); \
1511 #define DEFINE_ACTION_STRING(__name, __bit, __index) \
1512 if (flags & __bit) \
1514 string_append(&result, " +" __name "{"); \
1515 string_append(&result, action->string[__index]); \
1516 string_append(&result, "}"); \
1520 string_append(&result, " -" __name); \
1523 #define DEFINE_ACTION_MULTI(__name, __index) \
1524 lst = action->multi[__index]->first; \
1527 string_append(&result, " -" __name); \
1533 string_append(&result, " +" __name "{"); \
1534 string_append(&result, lst->str); \
1535 string_append(&result, "}"); \
1540 #define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
1542 #include "actionlist.h"
1544 #undef DEFINE_ACTION_MULTI
1545 #undef DEFINE_ACTION_STRING
1546 #undef DEFINE_ACTION_BOOL
1547 #undef DEFINE_ACTION_ALIAS