-
-#define DEFINE_ACTION_STRING(__name, __bit, __index) \
- if (!(mask & __bit)) \
- { \
- string_append(&result, "\n<br>-" __name); \
- } \
- else if (add & __bit) \
- { \
- string_append(&result, "\n<br>+" __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<br>-" __name); \
- } \
- else \
- { \
- lst = action->multi_remove[__index]->first; \
- while (lst) \
- { \
- string_append(&result, "\n<br>-" __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<br>+" __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 <br> */
- 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;
- }
-}