1 const char actions_rcs[] = "$Id: actions.c,v ???? $";
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.
37 *********************************************************************/
53 const char actions_h_rcs[] = ACTIONS_H_VERSION;
55 /* This structure is used to hold user-defined aliases */
59 struct action_spec action[1];
60 struct action_alias * next;
65 * Must declare this in this file for the above structure.
66 * FIXME: Make this static or put structure in header.
68 extern int get_actions (char *line, struct action_alias * alias_list,
69 struct action_spec *cur_action);
72 * We need the main list of options.
74 * First, we need a way to tell between boolean, string, and multi-string
75 * options. For string and multistring options, we also need to be
76 * able to tell the difference between a "+" and a "-". (For bools,
77 * the "+"/"-" information is encoded in "add" and "mask"). So we use
78 * an enumerated type (well, the preprocessor equivalent). Here are
81 #define AV_NONE 0 /* +opt -opt */
82 #define AV_ADD_STRING 1 /* +stropt{string} */
83 #define AV_REM_STRING 2 /* -stropt */
84 #define AV_ADD_MULTI 3 /* +multiopt{string} +multiopt{string2} */
85 #define AV_REM_MULTI 4 /* -multiopt{string} -multiopt{*} */
88 * We need a structure to hold the name, flag changes,
89 * type, and string index.
94 unsigned mask; /* a bit set to "0" = remove action */
95 unsigned add; /* a bit set to "1" = add action */
96 int takes_value; /* an AV_... constant */
97 int index; /* index into strings[] or multi[] */
101 * And with those building blocks in place, here's the array.
103 static const struct action_name action_names[] =
106 * Well actually there's no data here - it's in actionlist.h
107 * This keeps it together to make it easy to change.
109 * Here's the macros used to format it:
111 #define DEFINE_ACTION_MULTI(name,index) \
112 { "+" name, ACTION_MASK_ALL, 0, AV_ADD_MULTI, index }, \
113 { "-" name, ACTION_MASK_ALL, 0, AV_REM_MULTI, index },
114 #define DEFINE_ACTION_STRING(name,flag,index) \
115 { "+" name, ACTION_MASK_ALL, flag, AV_ADD_STRING, index }, \
116 { "-" name, ~flag, 0, AV_REM_STRING, index },
117 #define DEFINE_ACTION_BOOL(name,flag) \
118 { "+" name, ACTION_MASK_ALL, flag }, \
119 { "-" name, ~flag, 0 },
120 #define DEFINE_ACTION_ALIAS 1 /* Want aliases please */
122 #include "actionlist.h"
124 #undef DEFINE_ACTION_MULTI
125 #undef DEFINE_ACTION_STRING
126 #undef DEFINE_ACTION_BOOL
127 #undef DEFINE_ACTION_ALIAS
130 { "+add-header", ACTION_MASK_ALL, 0, AV_ADD_MULTI, ACTION_MULTI_ADD_HEADER },
131 { "+block", ACTION_MASK_ALL, ACTION_BLOCK },
132 { "+fast-redirects", ACTION_MASK_ALL, ACTION_FAST_REDIRECTS },
133 { "+filter", ACTION_MASK_ALL, ACTION_FILTER },
134 { "+hide-forwarded", ACTION_MASK_ALL, ACTION_HIDE_FORWARDED },
135 { "+hide-from", ACTION_MASK_ALL, ACTION_HIDE_FROM, AV_ADD_STRING, ACTION_STRING_FROM },
136 { "+hide-referer", ACTION_MASK_ALL, ACTION_HIDE_REFERER, AV_ADD_STRING, ACTION_STRING_REFERER },
137 { "+hide-referrer", ACTION_MASK_ALL, ACTION_HIDE_REFERER, AV_ADD_STRING, ACTION_STRING_REFERER },
138 { "+hide-user-agent", ACTION_MASK_ALL, ACTION_HIDE_USER_AGENT, AV_ADD_STRING, ACTION_STRING_USER_AGENT },
139 { "+image", ACTION_MASK_ALL, ACTION_IMAGE },
140 { "+no-cookies-read", ACTION_MASK_ALL, ACTION_NO_COOKIE_READ },
141 { "+no-cookies-set", ACTION_MASK_ALL, ACTION_NO_COOKIE_SET },
142 { "+no-popup", ACTION_MASK_ALL, ACTION_NO_POPUPS },
143 { "+no-popups", ACTION_MASK_ALL, ACTION_NO_POPUPS },
144 { "+vanilla-wafer", ACTION_MASK_ALL, ACTION_VANILLA_WAFER },
145 { "+wafer", ACTION_MASK_ALL, 0, AV_ADD_MULTI, ACTION_MULTI_WAFER },
146 { "-add-header", ACTION_MASK_ALL, 0, AV_REM_MULTI, ACTION_MULTI_ADD_HEADER },
147 { "-block", ~ACTION_BLOCK, 0 },
148 { "-fast-redirects", ~ACTION_FAST_REDIRECTS, 0 },
149 { "-filter", ~ACTION_FILTER, 0 },
150 { "-hide-forwarded", ~ACTION_HIDE_FORWARDED, 0 },
151 { "-hide-from", ~ACTION_HIDE_FROM, 0, AV_REM_STRING, ACTION_STRING_FROM },
152 { "-hide-referer", ~ACTION_HIDE_REFERER, 0, AV_REM_STRING, ACTION_STRING_REFERER },
153 { "-hide-referrer", ~ACTION_HIDE_REFERER, 0, AV_REM_STRING, ACTION_STRING_REFERER },
154 { "-hide-user-agent", ~ACTION_HIDE_USER_AGENT, 0, AV_REM_STRING, ACTION_STRING_USER_AGENT },
155 { "-image", ~ACTION_IMAGE, 0 },
156 { "-no-cookies-read", ~ACTION_NO_COOKIE_READ, 0 },
157 { "-no-cookies-set", ~ACTION_NO_COOKIE_SET, 0 },
158 { "-no-popup", ~ACTION_NO_POPUPS, 0 },
159 { "-no-popups", ~ACTION_NO_POPUPS, 0 },
160 { "-vanilla-wafer", ~ACTION_VANILLA_WAFER, 0 },
161 { "-wafer", ACTION_MASK_ALL, 0, AV_REM_MULTI, ACTION_MULTI_WAFER },
163 { NULL, 0, 0 } /* End marker */
167 /*********************************************************************
169 * Function : merge_actions
171 * Description : Merge two actions together.
172 * Similar to "cur_action += new_action".
175 * 1 : cur_action = Current actions, to modify.
176 * 2 : new_action = Action to add.
180 *********************************************************************/
181 void merge_actions (struct action_spec *dest,
182 const struct action_spec *src)
186 dest->mask &= src->mask;
187 dest->add &= src->mask;
188 dest->add |= src->add;
190 for (i = 0; i < ACTION_STRING_COUNT; i++)
192 char * str = src->string[i];
195 freez(dest->string[i]);
196 dest->string[i] = strdup(str);
200 for (i = 0; i < ACTION_MULTI_COUNT; i++)
202 if (src->multi_remove_all[i])
204 /* Remove everything from dest */
205 destroy_list(dest->multi_remove[i]);
206 destroy_list(dest->multi_add[i]);
207 dest->multi_remove_all[i] = 1;
208 list_duplicate(dest->multi_add[i], src->multi_add[i]);
210 else if (dest->multi_remove_all[i])
213 * dest already removes everything, so we only need to worry
216 list_remove_list(dest->multi_add[i], src->multi_remove[i]);
217 list_append_list_unique(dest->multi_add[i], src->multi_add[i]);
221 /* No "remove all"s to worry about. */
222 list_remove_list(dest->multi_add[i], src->multi_remove[i]);
223 list_append_list_unique(dest->multi_remove[i], src->multi_remove[i]);
224 list_append_list_unique(dest->multi_add[i], src->multi_add[i]);
230 /*********************************************************************
232 * Function : copy_action
234 * Description : Copy an action_specs.
235 * Similar to "cur_action = new_action".
238 * 1 : dest = Destination of copy.
239 * 2 : src = Source for copy.
243 *********************************************************************/
244 void copy_action (struct action_spec *dest,
245 const struct action_spec *src)
249 dest->mask = src->mask;
250 dest->add = src->add;
252 for (i = 0; i < ACTION_STRING_COUNT; i++)
254 char * str = src->string[i];
255 dest->string[i] = (str ? strdup(str) : NULL);
258 for (i = 0; i < ACTION_MULTI_COUNT; i++)
260 dest->multi_remove_all[i] = src->multi_remove_all[i];
261 list_duplicate(dest->multi_remove[i], src->multi_remove[i]);
262 list_duplicate(dest->multi_add[i], src->multi_add[i]);
267 /*********************************************************************
269 * Function : free_action
271 * Description : Free an action_specs.
274 * 1 : src = Source to free.
278 *********************************************************************/
279 void free_action (struct action_spec *src)
283 for (i = 0; i < ACTION_STRING_COUNT; i++)
285 freez(src->string[i]);
288 for (i = 0; i < ACTION_MULTI_COUNT; i++)
290 destroy_list(src->multi_remove[i]);
291 destroy_list(src->multi_add[i]);
294 memset(src, '\0', sizeof(*src));
298 /*********************************************************************
300 * Function : get_action_token
302 * Description : Parses a line for the first action.
303 * Modifies it's input array, doesn't allocate memory.
305 * *line=" +abc{def} -ghi "
312 * 1 : line = [in] The line containing the action.
313 * [out] Start of next action on line, or
314 * NULL if we reached the end of line before
315 * we found an action.
316 * 2 : name = [out] Start of action name, null
317 * terminated. NULL on EOL
318 * 3 : value = [out] Start of action value, null
319 * terminated. NULL if none or EOL.
322 * nonzero => Mismatched {} (line was trashed anyway)
324 *********************************************************************/
325 int get_action_token(char **line, char **name, char **value)
330 /* set default returns */
335 /* Eat any leading whitespace */
336 while ((*str == ' ') || (*str == '\t'))
348 /* null name, just value is prohibited */
355 while (((ch = *str) != '\0') &&
356 (ch != ' ') && (ch != '\t') && (ch != '{'))
372 /* EOL - be careful not to run off buffer */
377 /* More to parse next time. */
386 str = strchr(str, '}');
404 /*********************************************************************
406 * Function : get_actions
408 * Description : Parses a list of actions.
411 * 1 : line = The string containing the actions.
412 * Will be written to by this function.
413 * 2 : aliases = Custom alias list, or NULL for none.
414 * 3 : cur_action = Where to store the action. Caller
418 * nonzero => Error (line was trashed anyway)
420 *********************************************************************/
421 int get_actions(char *line, struct action_alias * alias_list,
422 struct action_spec *cur_action)
424 memset(cur_action, '\0', sizeof(*cur_action));
425 cur_action->mask = ACTION_MASK_ALL;
429 char * option = NULL;
432 if (get_action_token(&line, &option, &value))
439 /* handle option in 'option' */
441 /* Check for standard action name */
442 const struct action_name * action = action_names;
444 while ( (action->name != NULL) && (0 != strcmpic(action->name, option)) )
448 if (action->name != NULL)
451 cur_action->mask &= action->mask;
452 cur_action->add &= action->mask;
453 cur_action->add |= action->add;
455 switch (action->takes_value)
458 /* ignore any option. */
462 /* add single string. */
464 if ((value == NULL) || (*value == '\0'))
468 /* FIXME: should validate option string here */
469 freez (cur_action->string[action->index]);
470 cur_action->string[action->index] = strdup(value);
475 /* remove single string. */
477 freez (cur_action->string[action->index]);
482 /* append multi string. */
484 struct list * remove = cur_action->multi_remove[action->index];
485 struct list * add = cur_action->multi_add[action->index];
487 if ((value == NULL) || (*value == '\0'))
492 list_remove_item(remove, value);
493 enlist_unique(add, value);
498 /* remove multi string. */
500 struct list * remove = cur_action->multi_remove[action->index];
501 struct list * add = cur_action->multi_add[action->index];
503 if ( (value == NULL) || (*value == '\0')
504 || ((*value == '*') && (value[1] == '\0')) )
507 * no option, or option == "*".
511 destroy_list(remove);
513 cur_action->multi_remove_all[action->index] = 1;
517 /* Valid option - remove only 1 option */
519 if ( !cur_action->multi_remove_all[action->index] )
521 /* there isn't a catch-all in the remove list already */
522 enlist_unique(remove, value);
524 list_remove_item(add, value);
529 /* Shouldn't get here unless there's memory corruption. */
535 /* try user aliases. */
536 const struct action_alias * alias = alias_list;
538 while ( (alias != NULL) && (0 != strcmpic(alias->name, option)) )
545 merge_actions(cur_action, alias->action);
549 /* Bad action name */
560 /*********************************************************************
562 * Function : actions_to_text
564 * Description : Converts a actionsfile entry from numeric form
565 * ("mask" and "add") to text.
568 * 1 : mask = As from struct url_actions
569 * 2 : add = As from struct url_actions
571 * Returns : A string. Caller must free it.
573 *********************************************************************/
574 char * actions_to_text(struct action_spec *action)
576 unsigned mask = action->mask;
577 unsigned add = action->add;
578 char * result = strdup("");
581 /* sanity - prevents "-feature +feature" */
585 #define DEFINE_ACTION_BOOL(__name, __bit) \
586 if (!(mask & __bit)) \
588 result = strsav(result, " -" __name); \
590 else if (add & __bit) \
592 result = strsav(result, " +" __name); \
595 #define DEFINE_ACTION_STRING(__name, __bit, __index) \
596 if (!(mask & __bit)) \
598 result = strsav(result, " -" __name); \
600 else if (add & __bit) \
602 result = strsav(result, " +" __name "{"); \
603 result = strsav(result, action->string[__index]); \
604 result = strsav(result, "}"); \
607 #define DEFINE_ACTION_MULTI(__name, __index) \
608 if (action->multi_remove_all[__index]) \
610 result = strsav(result, " -" __name "{*}"); \
614 lst = action->multi_remove[__index]->next; \
617 result = strsav(result, " -" __name "{"); \
618 result = strsav(result, lst->str); \
619 result = strsav(result, "}"); \
623 lst = action->multi_add[__index]->next; \
626 result = strsav(result, " +" __name "{"); \
627 result = strsav(result, lst->str); \
628 result = strsav(result, "}"); \
632 #define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
634 #include "actionlist.h"
636 #undef DEFINE_ACTION_MULTI
637 #undef DEFINE_ACTION_STRING
638 #undef DEFINE_ACTION_BOOL
639 #undef DEFINE_ACTION_ALIAS
641 ACTION_MULTI_TO_TEXT ( "add-header", ACTION_MULTI_ADD_HEADER)
642 ACTION_TO_TEXT (ACTION_BLOCK, "block");
643 ACTION_TO_TEXT (ACTION_FAST_REDIRECTS, "fast-redirects");
644 ACTION_TO_TEXT (ACTION_FILTER, "filter");
645 ACTION_TO_TEXT (ACTION_HIDE_FORWARDED, "hide-forwarded");
646 ACTION_STRING_TO_TEXT(ACTION_HIDE_FROM, "hide-from", ACTION_STRING_FROM);
647 ACTION_STRING_TO_TEXT(ACTION_HIDE_REFERER, "hide-referer", ACTION_STRING_REFERER);
648 ACTION_STRING_TO_TEXT(ACTION_HIDE_USER_AGENT, "hide-user-agent", ACTION_STRING_USER_AGENT);
649 ACTION_TO_TEXT (ACTION_IMAGE, "image");
650 ACTION_TO_TEXT (ACTION_NO_COOKIE_READ, "no-cookies-read");
651 ACTION_TO_TEXT (ACTION_NO_COOKIE_SET, "no-cookies-set");
652 ACTION_TO_TEXT (ACTION_NO_POPUPS, "no-popups");
653 ACTION_TO_TEXT (ACTION_VANILLA_WAFER, "vanilla-wafer");
654 ACTION_MULTI_TO_TEXT ( "wafer", ACTION_MULTI_WAFER);
656 #undef ACTION_TO_TEXT
657 #undef ACTION_STRING_TO_TEXT
658 #undef ACTION_MULTI_TO_TEXT
664 /*********************************************************************
666 * Function : current_actions_to_text
668 * Description : Converts a actionsfile entry to text.
671 * 1 : action = Action
673 * Returns : A string. Caller must free it.
675 *********************************************************************/
676 char * current_action_to_text(struct current_action_spec *action)
678 unsigned flags = action->flags;
679 char * result = strdup("");
680 struct list_share * lst;
682 #define DEFINE_ACTION_BOOL(__name, __bit) \
685 result = strsav(result, " +" __name); \
689 result = strsav(result, " -" __name); \
692 #define DEFINE_ACTION_STRING(__name, __bit, __index) \
695 result = strsav(result, " +" __name "{"); \
696 result = strsav(result, action->string[__index]); \
697 result = strsav(result, "}"); \
701 result = strsav(result, " -" __name); \
704 #define DEFINE_ACTION_MULTI(__name, __index) \
705 lst = action->multi[__index]->next; \
708 result = strsav(result, " -" __name); \
714 result = strsav(result, " +" __name "{"); \
715 result = strsav(result, lst->str); \
716 result = strsav(result, "}"); \
721 #define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
723 #include "actionlist.h"
725 #undef DEFINE_ACTION_MULTI
726 #undef DEFINE_ACTION_STRING
727 #undef DEFINE_ACTION_BOOL
728 #undef DEFINE_ACTION_ALIAS
731 ACTION_MULTI_TO_TEXT ( "add-header", ACTION_MULTI_ADD_HEADER)
732 ACTION_TO_TEXT (ACTION_BLOCK, "block");
733 ACTION_TO_TEXT (ACTION_FAST_REDIRECTS, "fast-redirects");
734 ACTION_TO_TEXT (ACTION_FILTER, "filter");
735 ACTION_TO_TEXT (ACTION_HIDE_FORWARDED, "hide-forwarded");
736 ACTION_STRING_TO_TEXT(ACTION_HIDE_FROM, "hide-from", ACTION_STRING_FROM);
737 ACTION_STRING_TO_TEXT(ACTION_HIDE_REFERER, "hide-referer", ACTION_STRING_REFERER);
738 ACTION_STRING_TO_TEXT(ACTION_HIDE_USER_AGENT, "hide-user-agent", ACTION_STRING_USER_AGENT);
739 ACTION_TO_TEXT (ACTION_IMAGE, "image");
740 ACTION_TO_TEXT (ACTION_NO_COOKIE_READ, "no-cookies-read");
741 ACTION_TO_TEXT (ACTION_NO_COOKIE_SET, "no-cookies-set");
742 ACTION_TO_TEXT (ACTION_NO_POPUPS, "no-popups");
743 ACTION_TO_TEXT (ACTION_VANILLA_WAFER, "vanilla-wafer");
744 ACTION_MULTI_TO_TEXT ( "wafer", ACTION_MULTI_WAFER);
746 #undef ACTION_TO_TEXT
747 #undef ACTION_STRING_TO_TEXT
748 #undef ACTION_MULTI_TO_TEXT
754 /*********************************************************************
756 * Function : init_current_action
758 * Description : Zero out an action.
761 * 1 : dest = An uninitialized current_action_spec.
765 *********************************************************************/
766 void init_current_action (struct current_action_spec *dest)
768 memset(dest, '\0', sizeof(*dest));
769 dest->flags = ACTION_MOST_COMPATIBLE;
773 /*********************************************************************
775 * Function : merge_current_action
777 * Description : Merge two actions together.
778 * Similar to "dest += src".
779 * Differences between this and merge_actions()
780 * is that this one doesn't allocate memory for
781 * strings (so "src" better be in memory for at least
782 * as long as "dest" is, and you'd better free
783 * "dest" using "current_free_action").
784 * Also, there is no mask or remove lists in dest.
785 * (If we're applying it to a URL, we don't need them)
788 * 1 : dest = Current actions, to modify.
789 * 2 : src = Action to add.
793 *********************************************************************/
794 void merge_current_action (struct current_action_spec *dest,
795 const struct action_spec *src)
799 dest->flags &= src->mask;
800 dest->flags |= src->add;
802 for (i = 0; i < ACTION_STRING_COUNT; i++)
804 char * str = src->string[i];
807 dest->string[i] = str;
811 for (i = 0; i < ACTION_MULTI_COUNT; i++)
813 if (src->multi_remove_all[i])
815 /* Remove everything from dest */
816 destroy_list_share(dest->multi[i]);
817 list_duplicate_share(dest->multi[i], src->multi_add[i]);
821 list_remove_list_share(dest->multi[i], src->multi_remove[i]);
822 list_append_list_unique_share(dest->multi[i], src->multi_add[i]);
828 /*********************************************************************
830 * Function : free_current_action
832 * Description : Free a current_action_spec.
835 * 1 : src = Source to free.
839 *********************************************************************/
840 void free_current_action (struct current_action_spec *src)
844 for (i = 0; i < ACTION_MULTI_COUNT; i++)
846 destroy_list_share(src->multi[i]);
849 memset(src, '\0', sizeof(*src));
853 /*********************************************************************
855 * Function : unload_actions_file
857 * Description : Unloads an actions module.
860 * 1 : file_data = the data structure associated with the
865 *********************************************************************/
866 void unload_actions_file(void *file_data)
868 struct url_actions * next;
869 struct url_actions * cur = (struct url_actions *)file_data;
881 /*********************************************************************
883 * Function : load_actions_file
885 * Description : Read and parse a action file and add to files
889 * 1 : csp = Current client state (buffers, headers, etc...)
891 * Returns : 0 => Ok, everything else is an error.
893 *********************************************************************/
894 int load_actions_file(struct client_state *csp)
896 static struct file_list *current_actions_file = NULL;
900 struct url_actions *last_perm;
901 struct url_actions *perm;
903 struct file_list *fs;
904 #define MODE_START_OF_FILE 1
905 #define MODE_ACTIONS 2
907 int mode = MODE_START_OF_FILE;
908 struct action_spec cur_action[1];
909 struct action_alias * alias_list = NULL;
911 memset(cur_action, '\0', sizeof(*cur_action));
913 if (!check_file_changed(current_actions_file, csp->config->actions_file, &fs))
915 /* No need to load */
918 csp->actions_list = current_actions_file;
924 log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': error finding file: %E",
925 csp->config->actions_file);
926 return 1; /* never get here */
929 fs->f = last_perm = (struct url_actions *)zalloc(sizeof(*last_perm));
930 if (last_perm == NULL)
932 log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory!",
933 csp->config->actions_file);
934 return 1; /* never get here */
937 if ((fp = fopen(csp->config->actions_file, "r")) == NULL)
939 log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': error opening file: %E",
940 csp->config->actions_file);
941 return 1; /* never get here */
944 while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
948 /* It's a header block */
951 /* It's {{settings}} or {{alias}} */
952 int len = strlen(buf);
953 char * start = buf + 2;
954 char * end = buf + len - 1;
955 if ((len < 5) || (*end-- != '}') || (*end-- != '}'))
959 log_error(LOG_LEVEL_FATAL,
960 "can't load actions file '%s': invalid line: %s",
961 csp->config->actions_file, buf);
962 return 1; /* never get here */
965 /* Trim leading and trailing whitespace. */
973 log_error(LOG_LEVEL_FATAL,
974 "can't load actions file '%s': invalid line: {{ }}",
975 csp->config->actions_file);
976 return 1; /* never get here */
979 if (0 == strcmpic(start, "alias"))
981 /* it's an {{alias}} block */
987 /* invalid {{something}} block */
989 log_error(LOG_LEVEL_FATAL,
990 "can't load actions file '%s': invalid line: {{%s}}",
991 csp->config->actions_file, start);
992 return 1; /* never get here */
997 /* It's an actions block */
999 char actions_buf[BUFSIZ];
1003 mode = MODE_ACTIONS;
1005 /* free old action */
1006 free_action(cur_action);
1009 strcpy(actions_buf, buf + 1);
1011 /* check we have a trailing } and then trim it */
1012 end = actions_buf + strlen(actions_buf) - 1;
1017 log_error(LOG_LEVEL_FATAL,
1018 "can't load actions file '%s': invalid line: %s",
1019 csp->config->actions_file, buf);
1020 return 1; /* never get here */
1024 /* trim any whitespace immediately inside {} */
1027 if (*actions_buf == '\0')
1031 log_error(LOG_LEVEL_FATAL,
1032 "can't load actions file '%s': invalid line: %s",
1033 csp->config->actions_file, buf);
1034 return 1; /* never get here */
1037 if (get_actions(actions_buf, alias_list, cur_action))
1041 log_error(LOG_LEVEL_FATAL,
1042 "can't load actions file '%s': invalid line: %s",
1043 csp->config->actions_file, buf);
1044 return 1; /* never get here */
1048 else if (mode == MODE_ALIAS)
1050 /* define an alias */
1051 char actions_buf[BUFSIZ];
1052 struct action_alias * new_alias;
1055 char * start = strchr(buf, '=');
1058 if ((start == NULL) || (start == buf))
1060 log_error(LOG_LEVEL_FATAL,
1061 "can't load actions file '%s': invalid alias line: %s",
1062 csp->config->actions_file, buf);
1063 return 1; /* never get here */
1066 if ((new_alias = zalloc(sizeof(*new_alias))) == NULL)
1069 log_error(LOG_LEVEL_FATAL,
1070 "can't load actions file '%s': out of memory!",
1071 csp->config->actions_file);
1072 return 1; /* never get here */
1075 /* Eat any the whitespace before the '=' */
1077 while ((*end == ' ') || (*end == '\t'))
1080 * we already know we must have at least 1 non-ws char
1081 * at start of buf - no need to check
1087 /* Eat any the whitespace after the '=' */
1089 while ((*start == ' ') || (*start == '\t'))
1095 log_error(LOG_LEVEL_FATAL,
1096 "can't load actions file '%s': invalid alias line: %s",
1097 csp->config->actions_file, buf);
1098 return 1; /* never get here */
1101 new_alias->name = strdup(buf);
1103 strcpy(actions_buf, start);
1105 if (get_actions(actions_buf, alias_list, new_alias->action))
1109 log_error(LOG_LEVEL_FATAL,
1110 "can't load actions file '%s': invalid alias line: %s = %s",
1111 csp->config->actions_file, buf, start);
1112 return 1; /* never get here */
1116 new_alias->next = alias_list;
1117 alias_list = new_alias;
1119 else if (mode == MODE_ACTIONS)
1121 /* it's a URL pattern */
1123 /* allocate a new node */
1124 if ((perm = zalloc(sizeof(*perm))) == NULL)
1127 log_error(LOG_LEVEL_FATAL,
1128 "can't load actions file '%s': out of memory!",
1129 csp->config->actions_file);
1130 return 1; /* never get here */
1134 copy_action (perm->action, cur_action);
1136 /* Save the URL pattern */
1137 if (create_url_spec(perm->url, buf))
1140 log_error(LOG_LEVEL_FATAL,
1141 "can't load actions file '%s': cannot create URL pattern from: %s",
1142 csp->config->actions_file, buf);
1143 return 1; /* never get here */
1146 /* add it to the list */
1147 last_perm->next = perm;
1150 else if (mode == MODE_START_OF_FILE)
1152 /* oops - please have a {} line as 1st line in file. */
1154 log_error(LOG_LEVEL_FATAL,
1155 "can't load actions file '%s': first line is invalid: %s",
1156 csp->config->actions_file, buf);
1157 return 1; /* never get here */
1161 /* How did we get here? This is impossible! */
1163 log_error(LOG_LEVEL_FATAL,
1164 "can't load actions file '%s': INTERNAL ERROR - mode = %d",
1165 csp->config->actions_file, mode);
1166 return 1; /* never get here */
1172 free_action(cur_action);
1174 while (alias_list != NULL)
1176 struct action_alias * next = alias_list->next;
1177 freez((char *)alias_list->name);
1178 free_action(alias_list->action);
1183 #ifndef SPLIT_PROXY_ARGS
1184 if (!suppress_blocklists)
1186 fs->proxy_args = strsav(fs->proxy_args, "</pre>");
1188 #endif /* ndef SPLIT_PROXY_ARGS */
1190 /* the old one is now obsolete */
1191 if (current_actions_file)
1193 current_actions_file->unloader = unload_actions_file;
1196 fs->next = files->next;
1198 current_actions_file = fs;
1202 csp->actions_list = fs;