X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=actions.c;h=113024edd078c8cb2481caddd53949de17122c95;hb=12a2bf491d067ee8f05938c056f987a89d308718;hp=c9ec3fafed1d3f9d4e0c65c542c91e3e4585733e;hpb=ab8780ebe7187a05cbf53b4743ed9fbffb89d30b;p=privoxy.git
diff --git a/actions.c b/actions.c
index c9ec3faf..113024ed 100644
--- a/actions.c
+++ b/actions.c
@@ -1,4 +1,4 @@
-const char actions_rcs[] = "$Id: actions.c,v 1.20 2001/11/22 21:56:49 jongfoster Exp $";
+const char actions_rcs[] = "$Id: actions.c,v 1.21 2002/01/17 20:54:44 jongfoster Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/actions.c,v $
@@ -33,6 +33,9 @@ const char actions_rcs[] = "$Id: actions.c,v 1.20 2001/11/22 21:56:49 jongfoster
*
* Revisions :
* $Log: actions.c,v $
+ * Revision 1.21 2002/01/17 20:54:44 jongfoster
+ * Renaming free_url to free_url_spec, since it frees a struct url_spec.
+ *
* Revision 1.20 2001/11/22 21:56:49 jongfoster
* Making action_spec->flags into an unsigned long rather than just an
* unsigned int.
@@ -356,6 +359,11 @@ void free_action (struct action_spec *src)
{
int i;
+ if (src == NULL)
+ {
+ return;
+ }
+
for (i = 0; i < ACTION_STRING_COUNT; i++)
{
freez(src->string[i]);
@@ -652,484 +660,197 @@ jb_err get_actions(char *line,
/*********************************************************************
*
- * Function : actions_to_text
+ * Function : init_current_action
*
- * Description : Converts a actionsfile entry from numeric form
- * ("mask" and "add") to text.
+ * Description : Zero out an action.
*
* Parameters :
- * 1 : mask = As from struct url_actions
- * 2 : add = As from struct url_actions
+ * 1 : dest = An uninitialized current_action_spec.
*
- * Returns : A string. Caller must free it.
- * NULL on out-of-memory error.
+ * Returns : N/A
*
*********************************************************************/
-char * actions_to_text(struct action_spec *action)
+void init_current_action (struct current_action_spec *dest)
{
- unsigned mask = action->mask;
- unsigned add = action->add;
- char * result = strdup("");
- struct list_entry * lst;
+ memset(dest, '\0', sizeof(*dest));
- /* sanity - prevents "-feature +feature" */
- mask |= add;
+ dest->flags = ACTION_MOST_COMPATIBLE;
+}
-#define DEFINE_ACTION_BOOL(__name, __bit) \
- if (!(mask & __bit)) \
- { \
- string_append(&result, " -" __name); \
- } \
- else if (add & __bit) \
- { \
- string_append(&result, " +" __name); \
- }
+/*********************************************************************
+ *
+ * Function : init_action
+ *
+ * Description : Zero out an action.
+ *
+ * Parameters :
+ * 1 : dest = An uninitialized action_spec.
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void init_action (struct action_spec *dest)
+{
+ memset(dest, '\0', sizeof(*dest));
+}
-#define DEFINE_ACTION_STRING(__name, __bit, __index) \
- if (!(mask & __bit)) \
- { \
- string_append(&result, " -" __name); \
- } \
- else if (add & __bit) \
- { \
- string_append(&result, " +" __name "{"); \
- string_append(&result, action->string[__index]); \
- string_append(&result, "}"); \
+
+/*********************************************************************
+ *
+ * Function : merge_current_action
+ *
+ * Description : Merge two actions together.
+ * Similar to "dest += src".
+ * Differences between this and merge_actions()
+ * is that this one doesn't allocate memory for
+ * strings (so "src" better be in memory for at least
+ * as long as "dest" is, and you'd better free
+ * "dest" using "free_current_action").
+ * Also, there is no mask or remove lists in dest.
+ * (If we're applying it to a URL, we don't need them)
+ *
+ * Parameters :
+ * 1 : dest = Current actions, to modify.
+ * 2 : src = Action to add.
+ *
+ * Returns 0 : no error
+ * !=0 : error, probably JB_ERR_MEMORY.
+ *
+ *********************************************************************/
+jb_err merge_current_action (struct current_action_spec *dest,
+ const struct action_spec *src)
+{
+ int i;
+ jb_err err = JB_ERR_OK;
+
+ dest->flags &= src->mask;
+ dest->flags |= src->add;
+
+ for (i = 0; i < ACTION_STRING_COUNT; i++)
+ {
+ char * str = src->string[i];
+ if (str)
+ {
+ str = strdup(str);
+ if (!str)
+ {
+ return JB_ERR_MEMORY;
+ }
+ freez(dest->string[i]);
+ dest->string[i] = str;
+ }
}
-#define DEFINE_ACTION_MULTI(__name, __index) \
- if (action->multi_remove_all[__index]) \
- { \
- string_append(&result, " -" __name); \
- } \
- else \
- { \
- lst = action->multi_remove[__index]->first; \
- while (lst) \
- { \
- string_append(&result, " -" __name "{"); \
- string_append(&result, lst->str); \
- string_append(&result, "}"); \
- lst = lst->next; \
- } \
- } \
- lst = action->multi_add[__index]->first; \
- while (lst) \
- { \
- string_append(&result, " +" __name "{"); \
- string_append(&result, lst->str); \
- string_append(&result, "}"); \
- lst = lst->next; \
+ for (i = 0; i < ACTION_MULTI_COUNT; i++)
+ {
+ if (src->multi_remove_all[i])
+ {
+ /* Remove everything from dest, then add src->multi_add */
+ err = list_duplicate(dest->multi[i], src->multi_add[i]);
+ if (err)
+ {
+ return err;
+ }
+ }
+ else
+ {
+ list_remove_list(dest->multi[i], src->multi_remove[i]);
+ err = list_append_list_unique(dest->multi[i], src->multi_add[i]);
+ if (err)
+ {
+ return err;
+ }
+ }
}
+ return err;
+}
-#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
-#include "actionlist.h"
+/*********************************************************************
+ *
+ * Function : free_current_action
+ *
+ * Description : Free memory used by a current_action_spec.
+ * Does not free the current_action_spec itself.
+ *
+ * Parameters :
+ * 1 : src = Source to free.
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void free_current_action (struct current_action_spec *src)
+{
+ int i;
-#undef DEFINE_ACTION_MULTI
-#undef DEFINE_ACTION_STRING
-#undef DEFINE_ACTION_BOOL
-#undef DEFINE_ACTION_ALIAS
+ for (i = 0; i < ACTION_STRING_COUNT; i++)
+ {
+ freez(src->string[i]);
+ }
- return result;
+ for (i = 0; i < ACTION_MULTI_COUNT; i++)
+ {
+ destroy_list(src->multi[i]);
+ }
+
+ memset(src, '\0', sizeof(*src));
}
-#ifdef FEATURE_CGI_EDIT_ACTIONS
/*********************************************************************
*
- * Function : actions_to_html
+ * Function : unload_actions_file
*
- * Description : Converts a actionsfile entry from numeric form
- * ("mask" and "add") to a
-seperated HTML string.
+ * Description : Unloads an actions module.
*
* Parameters :
- * 1 : mask = As from struct url_actions
- * 2 : add = As from struct url_actions
+ * 1 : file_data = the data structure associated with the
+ * actions file.
*
- * Returns : A string. Caller must free it.
- * NULL on out-of-memory error.
+ * Returns : N/A
*
*********************************************************************/
-char * actions_to_html(struct action_spec *action)
+void unload_actions_file(void *file_data)
{
- unsigned mask = action->mask;
- unsigned add = action->add;
- char * result = strdup("");
- char * enc_str;
- struct list_entry * lst;
+ struct url_actions * next;
+ struct url_actions * cur = (struct url_actions *)file_data;
+ while (cur != NULL)
+ {
+ next = cur->next;
+ free_url_spec(cur->url);
+ free_action(cur->action);
+ freez(cur);
+ cur = next;
+ }
- /* sanity - prevents "-feature +feature" */
- mask |= add;
+}
-#define DEFINE_ACTION_BOOL(__name, __bit) \
- if (!(mask & __bit)) \
- { \
- string_append(&result, "\n
-" __name); \
- } \
- else if (add & __bit) \
- { \
- string_append(&result, "\n
+" __name); \
+/*********************************************************************
+ *
+ * Function : free_alias_list
+ *
+ * Description : Free memory used by a list of aliases.
+ *
+ * Parameters :
+ * 1 : alias_list = Linked list to free.
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void free_alias_list(struct action_alias *alias_list)
+{
+ while (alias_list != NULL)
+ {
+ struct action_alias * next = alias_list->next;
+ alias_list->next = NULL;
+ freez(alias_list->name);
+ free_action(alias_list->action);
+ free(alias_list);
+ alias_list = next;
}
-
-#define DEFINE_ACTION_STRING(__name, __bit, __index) \
- if (!(mask & __bit)) \
- { \
- string_append(&result, "\n
-" __name); \
- } \
- else if (add & __bit) \
- { \
- string_append(&result, "\n
+" __name "{"); \
- if (NULL == result) \
- { \
- return NULL; \
- } \
- enc_str = html_encode(action->string[__index]);\
- if (NULL == enc_str) \
- { \
- free(result); \
- return NULL; \
- } \
- string_append(&result, enc_str); \
- free(enc_str); \
- string_append(&result, "}"); \
- }
-
-#define DEFINE_ACTION_MULTI(__name, __index) \
- if (action->multi_remove_all[__index]) \
- { \
- string_append(&result, "\n
-" __name); \
- } \
- else \
- { \
- lst = action->multi_remove[__index]->first; \
- while (lst) \
- { \
- string_append(&result, "\n
-" __name "{");\
- if (NULL == result) \
- { \
- return NULL; \
- } \
- enc_str = html_encode(lst->str); \
- if (NULL == enc_str) \
- { \
- free(result); \
- return NULL; \
- } \
- string_append(&result, enc_str); \
- free(enc_str); \
- string_append(&result, "}"); \
- lst = lst->next; \
- } \
- } \
- lst = action->multi_add[__index]->first; \
- while (lst) \
- { \
- string_append(&result, "\n
+" __name "{"); \
- if (NULL == result) \
- { \
- return NULL; \
- } \
- enc_str = html_encode(lst->str); \
- if (NULL == enc_str) \
- { \
- free(result); \
- return NULL; \
- } \
- string_append(&result, enc_str); \
- free(enc_str); \
- string_append(&result, "}"); \
- lst = lst->next; \
- }
-
-#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
-
-#include "actionlist.h"
-
-#undef DEFINE_ACTION_MULTI
-#undef DEFINE_ACTION_STRING
-#undef DEFINE_ACTION_BOOL
-#undef DEFINE_ACTION_ALIAS
-
- /* trim leading
*/
- if (result && *result)
- {
- char * s = result;
- result = strdup(result + 5);
- free(s);
- }
-
- return result;
-}
-#endif /* def FEATURE_CGI_EDIT_ACTIONS */
-
-
-/*********************************************************************
- *
- * Function : current_actions_to_text
- *
- * Description : Converts a actionsfile entry to text.
- *
- * Parameters :
- * 1 : action = Action
- *
- * Returns : A string. Caller must free it.
- * NULL on out-of-memory error.
- *
- *********************************************************************/
-char * current_action_to_text(struct current_action_spec *action)
-{
- unsigned long flags = action->flags;
- char * result = strdup("");
- struct list_entry * lst;
-
-#define DEFINE_ACTION_BOOL(__name, __bit) \
- if (flags & __bit) \
- { \
- string_append(&result, " +" __name); \
- } \
- else \
- { \
- string_append(&result, " -" __name); \
- }
-
-#define DEFINE_ACTION_STRING(__name, __bit, __index) \
- if (flags & __bit) \
- { \
- string_append(&result, " +" __name "{"); \
- string_append(&result, action->string[__index]); \
- string_append(&result, "}"); \
- } \
- else \
- { \
- string_append(&result, " -" __name); \
- }
-
-#define DEFINE_ACTION_MULTI(__name, __index) \
- lst = action->multi[__index]->first; \
- if (lst == NULL) \
- { \
- string_append(&result, " -" __name); \
- } \
- else \
- { \
- while (lst) \
- { \
- string_append(&result, " +" __name "{"); \
- string_append(&result, lst->str); \
- string_append(&result, "}"); \
- lst = lst->next; \
- } \
- }
-
-#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
-
-#include "actionlist.h"
-
-#undef DEFINE_ACTION_MULTI
-#undef DEFINE_ACTION_STRING
-#undef DEFINE_ACTION_BOOL
-#undef DEFINE_ACTION_ALIAS
-
- return result;
-}
-
-
-/*********************************************************************
- *
- * Function : init_current_action
- *
- * Description : Zero out an action.
- *
- * Parameters :
- * 1 : dest = An uninitialized current_action_spec.
- *
- * Returns : N/A
- *
- *********************************************************************/
-void init_current_action (struct current_action_spec *dest)
-{
- memset(dest, '\0', sizeof(*dest));
-
- dest->flags = ACTION_MOST_COMPATIBLE;
-}
-
-
-/*********************************************************************
- *
- * Function : init_action
- *
- * Description : Zero out an action.
- *
- * Parameters :
- * 1 : dest = An uninitialized action_spec.
- *
- * Returns : N/A
- *
- *********************************************************************/
-void init_action (struct action_spec *dest)
-{
- memset(dest, '\0', sizeof(*dest));
-}
-
-
-/*********************************************************************
- *
- * Function : merge_current_action
- *
- * Description : Merge two actions together.
- * Similar to "dest += src".
- * Differences between this and merge_actions()
- * is that this one doesn't allocate memory for
- * strings (so "src" better be in memory for at least
- * as long as "dest" is, and you'd better free
- * "dest" using "free_current_action").
- * Also, there is no mask or remove lists in dest.
- * (If we're applying it to a URL, we don't need them)
- *
- * Parameters :
- * 1 : dest = Current actions, to modify.
- * 2 : src = Action to add.
- *
- * Returns 0 : no error
- * !=0 : error
- *
- *********************************************************************/
-jb_err merge_current_action (struct current_action_spec *dest,
- const struct action_spec *src)
-{
- int i;
- jb_err err = JB_ERR_OK;
-
- dest->flags &= src->mask;
- dest->flags |= src->add;
-
- for (i = 0; i < ACTION_STRING_COUNT; i++)
- {
- char * str = src->string[i];
- if (str)
- {
- str = strdup(str);
- if (!str)
- {
- return JB_ERR_MEMORY;
- }
- freez(dest->string[i]);
- dest->string[i] = str;
- }
- }
-
- for (i = 0; i < ACTION_MULTI_COUNT; i++)
- {
- if (src->multi_remove_all[i])
- {
- /* Remove everything from dest, then add src->multi_add */
- err = list_duplicate(dest->multi[i], src->multi_add[i]);
- if (err)
- {
- return err;
- }
- }
- else
- {
- list_remove_list(dest->multi[i], src->multi_remove[i]);
- err = list_append_list_unique(dest->multi[i], src->multi_add[i]);
- if (err)
- {
- return err;
- }
- }
- }
- return err;
-}
-
-
-/*********************************************************************
- *
- * Function : free_current_action
- *
- * Description : Free memory used by a current_action_spec.
- * Does not free the current_action_spec itself.
- *
- * Parameters :
- * 1 : src = Source to free.
- *
- * Returns : N/A
- *
- *********************************************************************/
-void free_current_action (struct current_action_spec *src)
-{
- int i;
-
- for (i = 0; i < ACTION_STRING_COUNT; i++)
- {
- freez(src->string[i]);
- }
-
- for (i = 0; i < ACTION_MULTI_COUNT; i++)
- {
- destroy_list(src->multi[i]);
- }
-
- memset(src, '\0', sizeof(*src));
-}
-
-
-/*********************************************************************
- *
- * Function : unload_actions_file
- *
- * Description : Unloads an actions module.
- *
- * Parameters :
- * 1 : file_data = the data structure associated with the
- * actions file.
- *
- * Returns : N/A
- *
- *********************************************************************/
-void unload_actions_file(void *file_data)
-{
- struct url_actions * next;
- struct url_actions * cur = (struct url_actions *)file_data;
- while (cur != NULL)
- {
- next = cur->next;
- free_url_spec(cur->url);
- free_action(cur->action);
- freez(cur);
- cur = next;
- }
-
-}
-
-
-/*********************************************************************
- *
- * Function : free_alias_list
- *
- * Description : Free memory used by a list of aliases.
- *
- * Parameters :
- * 1 : alias_list = Linked list to free.
- *
- * Returns : N/A
- *
- *********************************************************************/
-void free_alias_list(struct action_alias *alias_list)
-{
- while (alias_list != NULL)
- {
- struct action_alias * next = alias_list->next;
- alias_list->next = NULL;
- freez(alias_list->name);
- free_action(alias_list->action);
- free(alias_list);
- alias_list = next;
- }
-}
+}
/*********************************************************************
@@ -1447,96 +1168,383 @@ int load_actions_file(struct client_state *csp)
return 1; /* never get here */
}
- new_alias->name = strdup(buf);
+ new_alias->name = strdup(buf);
+
+ strcpy(actions_buf, start);
+
+ if (get_actions(actions_buf, alias_list, new_alias->action))
+ {
+ /* error */
+ 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);
+ return 1; /* never get here */
+ }
+
+ /* add to list */
+ new_alias->next = alias_list;
+ alias_list = new_alias;
+ }
+ else if (mode == MODE_ACTIONS)
+ {
+ /* it's a URL pattern */
+
+ /* allocate a new node */
+ if ((perm = zalloc(sizeof(*perm))) == NULL)
+ {
+ fclose(fp);
+ log_error(LOG_LEVEL_FATAL,
+ "can't load actions file '%s': out of memory!",
+ csp->config->actions_file);
+ return 1; /* never get here */
+ }
+
+ /* Save flags */
+ copy_action (perm->action, cur_action);
+
+ /* Save the URL pattern */
+ if (create_url_spec(perm->url, buf))
+ {
+ 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);
+ return 1; /* never get here */
+ }
+
+ /* add it to the list */
+ last_perm->next = perm;
+ last_perm = perm;
+ }
+ else if (mode == MODE_START_OF_FILE)
+ {
+ /* oops - please have a {} line as 1st line in file. */
+ 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);
+ return 1; /* never get here */
+ }
+ else
+ {
+ /* How did we get here? This is impossible! */
+ fclose(fp);
+ log_error(LOG_LEVEL_FATAL,
+ "can't load actions file '%s': INTERNAL ERROR - mode = %d",
+ csp->config->actions_file, mode);
+ return 1; /* never get here */
+ }
+ }
+
+ fclose(fp);
+
+ free_action(cur_action);
+
+ free_alias_list(alias_list);
+
+ /* the old one is now obsolete */
+ if (current_actions_file)
+ {
+ current_actions_file->unloader = unload_actions_file;
+ }
+
+ fs->next = files->next;
+ files->next = fs;
+ current_actions_file = fs;
+
+ if (csp)
+ {
+ csp->actions_list = fs;
+ }
+
+ return(0);
+
+}
+
+
+/*********************************************************************
+ *
+ * Function : actions_to_text
+ *
+ * Description : Converts a actionsfile entry from numeric form
+ * ("mask" and "add") to text.
+ *
+ * Parameters :
+ * 1 : mask = As from struct url_actions
+ * 2 : add = As from struct url_actions
+ *
+ * Returns : A string. Caller must free it.
+ * NULL on out-of-memory error.
+ *
+ *********************************************************************/
+char * actions_to_text(struct action_spec *action)
+{
+ unsigned mask = action->mask;
+ unsigned add = action->add;
+ char * result = strdup("");
+ struct list_entry * lst;
+
+ /* sanity - prevents "-feature +feature" */
+ mask |= add;
+
+
+#define DEFINE_ACTION_BOOL(__name, __bit) \
+ if (!(mask & __bit)) \
+ { \
+ string_append(&result, " -" __name); \
+ } \
+ else if (add & __bit) \
+ { \
+ string_append(&result, " +" __name); \
+ }
+
+#define DEFINE_ACTION_STRING(__name, __bit, __index) \
+ if (!(mask & __bit)) \
+ { \
+ string_append(&result, " -" __name); \
+ } \
+ else if (add & __bit) \
+ { \
+ string_append(&result, " +" __name "{"); \
+ string_append(&result, action->string[__index]); \
+ string_append(&result, "}"); \
+ }
+
+#define DEFINE_ACTION_MULTI(__name, __index) \
+ if (action->multi_remove_all[__index]) \
+ { \
+ string_append(&result, " -" __name); \
+ } \
+ else \
+ { \
+ lst = action->multi_remove[__index]->first; \
+ while (lst) \
+ { \
+ string_append(&result, " -" __name "{"); \
+ string_append(&result, lst->str); \
+ string_append(&result, "}"); \
+ lst = lst->next; \
+ } \
+ } \
+ lst = action->multi_add[__index]->first; \
+ while (lst) \
+ { \
+ string_append(&result, " +" __name "{"); \
+ string_append(&result, lst->str); \
+ string_append(&result, "}"); \
+ lst = lst->next; \
+ }
+
+#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
+
+#include "actionlist.h"
+
+#undef DEFINE_ACTION_MULTI
+#undef DEFINE_ACTION_STRING
+#undef DEFINE_ACTION_BOOL
+#undef DEFINE_ACTION_ALIAS
+
+ return result;
+}
- strcpy(actions_buf, start);
- if (get_actions(actions_buf, alias_list, new_alias->action))
- {
- /* error */
- 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);
- return 1; /* never get here */
- }
+#ifdef FEATURE_CGI_EDIT_ACTIONS
+/*********************************************************************
+ *
+ * Function : actions_to_html
+ *
+ * Description : Converts a actionsfile entry from numeric form
+ * ("mask" and "add") to a
-seperated HTML string.
+ *
+ * Parameters :
+ * 1 : mask = As from struct url_actions
+ * 2 : add = As from struct url_actions
+ *
+ * Returns : A string. Caller must free it.
+ * NULL on out-of-memory error.
+ *
+ *********************************************************************/
+char * actions_to_html(struct action_spec *action)
+{
+ unsigned mask = action->mask;
+ unsigned add = action->add;
+ char * result = strdup("");
+ char * enc_str;
+ struct list_entry * lst;
- /* add to list */
- new_alias->next = alias_list;
- alias_list = new_alias;
- }
- else if (mode == MODE_ACTIONS)
- {
- /* it's a URL pattern */
+ /* sanity - prevents "-feature +feature" */
+ mask |= add;
- /* allocate a new node */
- if ((perm = zalloc(sizeof(*perm))) == NULL)
- {
- fclose(fp);
- log_error(LOG_LEVEL_FATAL,
- "can't load actions file '%s': out of memory!",
- csp->config->actions_file);
- return 1; /* never get here */
- }
- /* Save flags */
- copy_action (perm->action, cur_action);
+#define DEFINE_ACTION_BOOL(__name, __bit) \
+ if (!(mask & __bit)) \
+ { \
+ string_append(&result, "\n
-" __name); \
+ } \
+ else if (add & __bit) \
+ { \
+ string_append(&result, "\n
+" __name); \
+ }
- /* Save the URL pattern */
- if (create_url_spec(perm->url, buf))
- {
- 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);
- return 1; /* never get here */
- }
+#define DEFINE_ACTION_STRING(__name, __bit, __index) \
+ if (!(mask & __bit)) \
+ { \
+ string_append(&result, "\n
-" __name); \
+ } \
+ else if (add & __bit) \
+ { \
+ string_append(&result, "\n
+" __name "{"); \
+ if (NULL == result) \
+ { \
+ return NULL; \
+ } \
+ enc_str = html_encode(action->string[__index]);\
+ if (NULL == enc_str) \
+ { \
+ free(result); \
+ return NULL; \
+ } \
+ string_append(&result, enc_str); \
+ free(enc_str); \
+ string_append(&result, "}"); \
+ }
- /* add it to the list */
- last_perm->next = perm;
- last_perm = perm;
- }
- else if (mode == MODE_START_OF_FILE)
- {
- /* oops - please have a {} line as 1st line in file. */
- 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);
- return 1; /* never get here */
- }
- else
- {
- /* How did we get here? This is impossible! */
- fclose(fp);
- log_error(LOG_LEVEL_FATAL,
- "can't load actions file '%s': INTERNAL ERROR - mode = %d",
- csp->config->actions_file, mode);
- return 1; /* never get here */
- }
+#define DEFINE_ACTION_MULTI(__name, __index) \
+ if (action->multi_remove_all[__index]) \
+ { \
+ string_append(&result, "\n
-" __name); \
+ } \
+ else \
+ { \
+ lst = action->multi_remove[__index]->first; \
+ while (lst) \
+ { \
+ string_append(&result, "\n
-" __name "{");\
+ if (NULL == result) \
+ { \
+ return NULL; \
+ } \
+ enc_str = html_encode(lst->str); \
+ if (NULL == enc_str) \
+ { \
+ free(result); \
+ return NULL; \
+ } \
+ string_append(&result, enc_str); \
+ free(enc_str); \
+ string_append(&result, "}"); \
+ lst = lst->next; \
+ } \
+ } \
+ lst = action->multi_add[__index]->first; \
+ while (lst) \
+ { \
+ string_append(&result, "\n
+" __name "{"); \
+ if (NULL == result) \
+ { \
+ return NULL; \
+ } \
+ enc_str = html_encode(lst->str); \
+ if (NULL == enc_str) \
+ { \
+ free(result); \
+ return NULL; \
+ } \
+ string_append(&result, enc_str); \
+ free(enc_str); \
+ string_append(&result, "}"); \
+ lst = lst->next; \
}
- fclose(fp);
+#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
- free_action(cur_action);
+#include "actionlist.h"
- free_alias_list(alias_list);
+#undef DEFINE_ACTION_MULTI
+#undef DEFINE_ACTION_STRING
+#undef DEFINE_ACTION_BOOL
+#undef DEFINE_ACTION_ALIAS
- /* the old one is now obsolete */
- if (current_actions_file)
+ /* trim leading
*/
+ if (result && *result)
{
- current_actions_file->unloader = unload_actions_file;
+ char * s = result;
+ result = strdup(result + 5);
+ free(s);
}
- fs->next = files->next;
- files->next = fs;
- current_actions_file = fs;
+ return result;
+}
+#endif /* def FEATURE_CGI_EDIT_ACTIONS */
- if (csp)
- {
- csp->actions_list = fs;
+
+/*********************************************************************
+ *
+ * Function : current_actions_to_text
+ *
+ * Description : Converts a actionsfile entry to text.
+ *
+ * Parameters :
+ * 1 : action = Action
+ *
+ * Returns : A string. Caller must free it.
+ * NULL on out-of-memory error.
+ *
+ *********************************************************************/
+char * current_action_to_text(struct current_action_spec *action)
+{
+ unsigned long flags = action->flags;
+ char * result = strdup("");
+ struct list_entry * lst;
+
+#define DEFINE_ACTION_BOOL(__name, __bit) \
+ if (flags & __bit) \
+ { \
+ string_append(&result, " +" __name); \
+ } \
+ else \
+ { \
+ string_append(&result, " -" __name); \
}
- return(0);
+#define DEFINE_ACTION_STRING(__name, __bit, __index) \
+ if (flags & __bit) \
+ { \
+ string_append(&result, " +" __name "{"); \
+ string_append(&result, action->string[__index]); \
+ string_append(&result, "}"); \
+ } \
+ else \
+ { \
+ string_append(&result, " -" __name); \
+ }
+
+#define DEFINE_ACTION_MULTI(__name, __index) \
+ lst = action->multi[__index]->first; \
+ if (lst == NULL) \
+ { \
+ string_append(&result, " -" __name); \
+ } \
+ else \
+ { \
+ while (lst) \
+ { \
+ string_append(&result, " +" __name "{"); \
+ string_append(&result, lst->str); \
+ string_append(&result, "}"); \
+ lst = lst->next; \
+ } \
+ }
+
+#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
+#include "actionlist.h"
+
+#undef DEFINE_ACTION_MULTI
+#undef DEFINE_ACTION_STRING
+#undef DEFINE_ACTION_BOOL
+#undef DEFINE_ACTION_ALIAS
+
+ return result;
}