-const char actions_rcs[] = "$Id: actions.c,v 1.40 2007/05/21 10:26:50 fabiankeil Exp $";
+const char actions_rcs[] = "$Id: actions.c,v 1.45 2008/03/24 11:21:02 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/actions.c,v $
* Purpose : Declares functions to work with actions files
* Functions declared include: FIXME
*
- * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge
+ * Copyright : Written by and Copyright (C) 2001-2008 the SourceForge
* Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
*
* Revisions :
* $Log: actions.c,v $
+ * Revision 1.45 2008/03/24 11:21:02 fabiankeil
+ * Share the action settings for multiple patterns in the same
+ * section so we waste less memory for gigantic block lists
+ * (and load them slightly faster). Reported by Franz Schwartau.
+ *
+ * Revision 1.44 2008/03/04 18:30:34 fabiankeil
+ * Remove the treat-forbidden-connects-like-blocks action. We now
+ * use the "blocked" page for forbidden CONNECT requests by default.
+ *
+ * Revision 1.43 2008/03/01 14:00:43 fabiankeil
+ * Let the block action take the reason for the block
+ * as argument and show it on the "blocked" page.
+ *
+ * Revision 1.42 2008/02/09 15:15:38 fabiankeil
+ * List active and inactive actions in the show-url-info's
+ * "Final results" section separately. Patch submitted by Lee
+ * in #1830056, modified to list active actions first.
+ *
+ * Revision 1.41 2008/01/28 20:17:40 fabiankeil
+ * - Mark some parameters as immutable.
+ * - Hide update_action_bits_for_all_tags() while it's unused.
+ *
* Revision 1.40 2007/05/21 10:26:50 fabiankeil
* - Use strlcpy() instead of strcpy().
* - Provide a reason why loading the actions
return err;
}
+/*********************************************************************
+ *
+ * Function : free_action_spec
+ *
+ * Description : Frees an action_spec and the memory used by it.
+ *
+ * Parameters :
+ * 1 : src = Source to free.
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void free_action_spec(struct action_spec *src)
+{
+ free_action(src);
+ freez(src);
+}
+
/*********************************************************************
*
return JB_ERR_OK;
}
+/*********************************************************************
+ *
+ * Function : action_used_to_valid_
+ *
+ * Description : Checks if unrecognized actions were valid in earlier
+ * releases.
+ *
+ * Parameters :
+ * 1 : action = The string containing the action to check.
+ *
+ * Returns : True if yes, otherwise false.
+ *
+ *********************************************************************/
+static int action_used_to_be_valid(const char *action)
+{
+ return (0 == strcmpic(action, "treat-forbidden-connects-like-blocks")
+ || 0 == strcmpic(action, "kill-popups"));
+}
/*********************************************************************
*
if ((value == NULL) || (*value == '\0'))
{
- return JB_ERR_PARSE;
+ if (0 != strcmpic(action->name, "block"))
+ {
+ /*
+ * XXX: Temporary backwards compatibility hack.
+ */
+ static int complaint_shown = 0;
+ value = "No reason specified.";
+ if (!complaint_shown)
+ {
+ log_error(LOG_LEVEL_ERROR, "At least one block "
+ "without reason found. This may become a fatal "
+ "error in future versions.");
+ complaint_shown = 1;
+ }
+ }
+ else
+ {
+ return JB_ERR_PARSE;
+ }
}
/* FIXME: should validate option string here */
freez (cur_action->string[action->index]);
/* Found it */
merge_actions(cur_action, alias->action);
}
+ else if ((2 < strlen(option)) && action_used_to_be_valid(option+1))
+ {
+ log_error(LOG_LEVEL_ERROR, "Action '%s' is no longer valid "
+ "in this Privoxy release. Ignored.", option+1);
+ }
else
{
/* Bad action name */
{
next = cur->next;
free_url_spec(cur->url);
- free_action(cur->action);
+ if ((next == NULL) || (next->action != cur->action))
+ {
+ /*
+ * As the action settings might be shared,
+ * we can only free them if the current
+ * url pattern is the last one, or if the
+ * next one is using different settings.
+ */
+ free_action_spec(cur->action);
+ }
freez(cur);
cur = next;
}
-
}
{
if (!cur_action_used)
{
- free_action(cur_action);
- free(cur_action);
+ free_action_spec(cur_action);
}
cur_action = NULL;
}
return 1; /* never get here */
}
- /* Save flags */
- copy_action (perm->action, cur_action);
+ perm->action = cur_action;
+ cur_action_used = 1;
/* Save the URL pattern */
if (create_url_spec(perm->url, buf))
fclose(fp);
- free_action(cur_action);
- freez(cur_action);
-
+ if (!cur_action_used)
+ {
+ free_action_spec(cur_action);
+ }
free_alias_list(alias_list);
/* the old one is now obsolete */
const struct current_action_spec *action)
{
unsigned long flags = action->flags;
- char * result = strdup("");
struct list_entry * lst;
+ char *result = strdup("");
+ char *active = strdup("");
+ char *inactive = strdup("");
#define DEFINE_ACTION_BOOL(__name, __bit) \
if (flags & __bit) \
{ \
- string_append(&result, "\n<br>+"); \
- string_join(&result, add_help_link(__name, csp->config)); \
+ string_append(&active, "\n<br>+"); \
+ string_join(&active, add_help_link(__name, csp->config)); \
} \
else \
{ \
- string_append(&result, "\n<br>-"); \
- string_join(&result, add_help_link(__name, csp->config)); \
+ string_append(&inactive, "\n<br>-"); \
+ string_join(&inactive, add_help_link(__name, csp->config)); \
}
#define DEFINE_ACTION_STRING(__name, __bit, __index) \
if (flags & __bit) \
{ \
- string_append(&result, "\n<br>+"); \
- string_join(&result, add_help_link(__name, csp->config)); \
- string_append(&result, "{"); \
- string_join(&result, html_encode(action->string[__index])); \
- string_append(&result, "}"); \
+ string_append(&active, "\n<br>+"); \
+ string_join(&active, add_help_link(__name, csp->config)); \
+ string_append(&active, "{"); \
+ string_join(&active, html_encode(action->string[__index])); \
+ string_append(&active, "}"); \
} \
else \
{ \
- string_append(&result, "\n<br>-"); \
- string_join(&result, add_help_link(__name, csp->config)); \
+ string_append(&inactive, "\n<br>-"); \
+ string_join(&inactive, add_help_link(__name, csp->config)); \
}
#define DEFINE_ACTION_MULTI(__name, __index) \
lst = action->multi[__index]->first; \
if (lst == NULL) \
{ \
- string_append(&result, "\n<br>-"); \
- string_join(&result, add_help_link(__name, csp->config)); \
+ string_append(&inactive, "\n<br>-"); \
+ string_join(&inactive, add_help_link(__name, csp->config)); \
} \
else \
{ \
while (lst) \
{ \
- string_append(&result, "\n<br>+"); \
- string_join(&result, add_help_link(__name, csp->config)); \
- string_append(&result, "{"); \
- string_join(&result, html_encode(lst->str)); \
- string_append(&result, "}"); \
+ string_append(&active, "\n<br>+"); \
+ string_join(&active, add_help_link(__name, csp->config)); \
+ string_append(&active, "{"); \
+ string_join(&active, html_encode(lst->str)); \
+ string_append(&active, "}"); \
lst = lst->next; \
} \
}
#undef DEFINE_ACTION_BOOL
#undef DEFINE_ACTION_ALIAS
+ if (active != NULL)
+ {
+ string_append(&result, active);
+ freez(active);
+ }
+ string_append(&result, "\n<br>");
+ if (inactive != NULL)
+ {
+ string_append(&result, inactive);
+ freez(inactive);
+ }
return result;
}