From: jongfoster Date: Fri, 1 Jun 2001 18:49:17 +0000 (+0000) Subject: Replaced "list_share" with "list" - the tiny memory gain was not X-Git-Tag: v_2_9_9~423 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=014e796377eafac5f1875e61282d48cb337dbdce Replaced "list_share" with "list" - the tiny memory gain was not worth the extra complexity. --- diff --git a/actions.c b/actions.c index 93884498..3fe17cb2 100644 --- a/actions.c +++ b/actions.c @@ -1,4 +1,4 @@ -const char actions_rcs[] = "$Id: actions.c,v 1.1 2001/05/31 21:16:46 jongfoster Exp $"; +const char actions_rcs[] = "$Id: actions.c,v 1.2 2001/05/31 21:40:00 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.c,v $ @@ -33,6 +33,9 @@ const char actions_rcs[] = "$Id: actions.c,v 1.1 2001/05/31 21:16:46 jongfoster * * Revisions : * $Log: actions.c,v $ + * Revision 1.2 2001/05/31 21:40:00 jongfoster + * Removing some commented out, obsolete blocks of code. + * * Revision 1.1 2001/05/31 21:16:46 jongfoster * Moved functions to process the action list into this new file. * @@ -627,7 +630,7 @@ char * current_action_to_text(struct current_action_spec *action) { unsigned flags = action->flags; char * result = strdup(""); - struct list_share * lst; + struct list * lst; #define DEFINE_ACTION_BOOL(__name, __bit) \ if (flags & __bit) \ @@ -743,13 +746,13 @@ void merge_current_action (struct current_action_spec *dest, if (src->multi_remove_all[i]) { /* Remove everything from dest */ - destroy_list_share(dest->multi[i]); - list_duplicate_share(dest->multi[i], src->multi_add[i]); + destroy_list(dest->multi[i]); + list_duplicate(dest->multi[i], src->multi_add[i]); } else { - list_remove_list_share(dest->multi[i], src->multi_remove[i]); - list_append_list_unique_share(dest->multi[i], src->multi_add[i]); + list_remove_list(dest->multi[i], src->multi_remove[i]); + list_append_list_unique(dest->multi[i], src->multi_add[i]); } } } @@ -773,7 +776,7 @@ void free_current_action (struct current_action_spec *src) for (i = 0; i < ACTION_MULTI_COUNT; i++) { - destroy_list_share(src->multi[i]); + destroy_list(src->multi[i]); } memset(src, '\0', sizeof(*src)); diff --git a/jcc.c b/jcc.c index 05c30fab..b114d257 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.14 2001/05/29 20:14:01 joergs Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.15 2001/05/31 21:24:47 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,12 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.14 2001/05/29 20:14:01 joergs Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.15 2001/05/31 21:24:47 jongfoster + * Changed "permission" to "action" throughout. + * Removed DEFAULT_USER_AGENT - it must now be specified manually. + * Moved vanilla wafer check into chat(), since we must now + * decide whether or not to add it based on the URL. + * * Revision 1.14 2001/05/29 20:14:01 joergs * AmigaOS bugfix: PCRS needs a lot of stack, stacksize for child threads * increased. @@ -463,7 +469,7 @@ static void chat(struct client_state *csp) && (csp->action->multi[ACTION_MULTI_WAFER]->next == NULL) && ((csp->action->flags & ACTION_VANILLA_WAFER) != 0)) { - enlist_share(csp->action->multi[ACTION_MULTI_WAFER], VANILLA_WAFER); + enlist(csp->action->multi[ACTION_MULTI_WAFER], VANILLA_WAFER); } #endif /* def JAR_FILES */ diff --git a/list.c b/list.c index a44c0e9d..8b1d594f 100644 --- a/list.c +++ b/list.c @@ -1,4 +1,4 @@ -const char list_rcs[] = "$Id: list.c,v NOT CHECKED IN $"; +const char list_rcs[] = "$Id: list.c,v 1.1 2001/05/31 21:11:53 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/list.c,v $ @@ -34,6 +34,21 @@ const char list_rcs[] = "$Id: list.c,v NOT CHECKED IN $"; * * Revisions : * $Log: list.c,v $ + * Revision 1.1 2001/05/31 21:11:53 jongfoster + * - Moved linked list support to new "list.c" file. + * Structure definitions are still in project.h, + * function prototypes are now in "list.h". + * - Added support for "struct list_share", which is identical + * to "struct list" except it saves memory by not duplicating + * the strings. Obviously, this only works if there is some + * other way of managing the memory used by the strings. + * (These list_share lists are used for lists which last + * for only 1 request, and where all the list entries are + * just coming directly from entries in the actionsfile.) + * Note that you still need to destroy list_share lists + * properly to free the nodes - it's only the strings + * which are shared. + * * *********************************************************************/ @@ -336,7 +351,8 @@ void list_duplicate(struct list *dest, const struct list *src) * * Function : list_append_list_unique * - * Description : Append a string list to another list + * Description : Append a string list to another list. + * Duplicate items are not added. * * Parameters : * 1 : dest = pointer to destination for merge. Caller allocs. @@ -356,248 +372,8 @@ void list_append_list_unique(struct list *dest, const struct list *src) } } - -/********************************************************************* - * - * Function : destroy_list_share - * - * Description : Destroy a string list (opposite of enlist) - * - * Parameters : - * 1 : h = pointer to list 'dummy' header - * - * Returns : N/A - * - *********************************************************************/ -void destroy_list_share(struct list_share *h) -{ - struct list_share *p, *n; - - for (p = h->next; p ; p = n) - { - n = p->next; - free(p); - } - - memset(h, '\0', sizeof(*h)); - -} - - -/********************************************************************* - * - * Function : enlist_share - * - * Description : Append a string into a specified string list. - * - * Parameters : - * 1 : header = pointer to list 'dummy' header - * 2 : str = string to add to the list (maybe NULL) - * - * Returns : N/A - * - *********************************************************************/ -void enlist_share(struct list_share *header, const char *str) -{ - struct list_share *cur = (struct list_share *)malloc(sizeof(*cur)); - struct list_share *last; - - if (cur) - { - cur->str = (str ? strdup(str) : NULL); - cur->next = NULL; - - last = header->last; - if (last == NULL) - { - last = header; - } - - last->next = cur; - header->last = cur; - } - -} - - -/********************************************************************* - * - * Function : enlist_unique_share - * - * Description : Append a string into a specified string list, - * if & only if it's not there already. - * - * Parameters : - * 1 : header = pointer to list 'dummy' header - * 2 : str = string to add to the list (maybe NULL) - * - * Returns : N/A - * - *********************************************************************/ -void enlist_unique_share(struct list_share *header, const char *str) -{ - struct list_share *last; - struct list_share *cur = header->next; - - while (cur != NULL) - { - if ((cur->str != NULL) && (0 == strcmp(str, cur->str))) - { - /* Already there */ - return; - } - cur = cur->next; - } - - cur = (struct list_share *)malloc(sizeof(*cur)); - - if (cur != NULL) - { - cur->str = str; - cur->next = NULL; - - last = header->last; - if (last == NULL) - { - last = header; - } - last->next = cur; - header->last = cur; - } -} - - -/********************************************************************* - * - * Function : list_append_list_unique_share - * - * Description : Append a string list to another list - * - * Parameters : - * 1 : dest = pointer to destination for merge. Caller allocs. - * 2 : src = pointer to source for merge. - * - * Returns : N/A - * - *********************************************************************/ -void list_append_list_unique_share(struct list_share *dest, const struct list *src) -{ - struct list * cur = src->next; - - while (cur) - { - enlist_unique_share(dest, cur->str); - cur = cur->next; - } -} - - -/********************************************************************* - * - * Function : list_remove_item_share - * - * Description : Remove a string from a specified string list. - * - * Parameters : - * 1 : header = pointer to list 'dummy' header - * 2 : str = string to remove from the list - * - * Returns : Number of times it was removed. - * - *********************************************************************/ -int list_remove_item_share(struct list_share *header, const char *str) -{ - struct list_share *prev = header; - struct list_share *cur = prev->next; - int count = 0; - - while (cur != NULL) - { - if ((cur->str != NULL) && (0 == strcmp(str, cur->str))) - { - count++; - - prev->next = cur->next; - free(cur); - } - else - { - prev = cur; - } - cur = prev->next; - } - - header->last = prev; - - return count; -} - - -/********************************************************************* - * - * Function : list_remove_list_share - * - * Description : Remove all strings in one list from another list. - * This is currently a brute-force algorithm - * (it compares every pair of strings). - * - * Parameters : - * 1 : dest = list to change - * 2 : src = list of strings to remove - * - * Returns : Total number of strings removed. - * - *********************************************************************/ -int list_remove_list_share(struct list_share *dest, const struct list *src) -{ - struct list *cur = src->next; - int count = 0; - - while (cur != NULL) - { - if (cur->str != NULL) - { - count += list_remove_item_share(dest, cur->str); - } - cur = cur->next; - } - - return count; -} - - -/********************************************************************* - * - * Function : list_duplicate_share - * - * Description : Duplicate a string list - * - * Parameters : - * 1 : dest = pointer to destination for copy. Caller allocs. - * 2 : src = pointer to source for copy. - * - * Returns : N/A - * - *********************************************************************/ -void list_duplicate_share(struct list_share *dest, const struct list *src) -{ - struct list * cur_src = src->next; - struct list_share * cur_dest = dest; - - memset(dest, '\0', sizeof(*dest)); - - while (cur_src) - { - cur_dest = cur_dest->next = (struct list_share *)zalloc(sizeof(*cur_dest)); - if (cur_dest == NULL) - { - return; - } - cur_dest->str = cur_src->str; - cur_src = cur_src->next; - } - - dest->last = cur_dest; - -} - +/* + Local Variables: + tab-width: 3 + end: +*/ diff --git a/list.h b/list.h index 5a6ea13a..15b61cf6 100644 --- a/list.h +++ b/list.h @@ -1,9 +1,9 @@ #ifndef _LIST_H #define _LIST_H -#define LIST_H_VERSION "$Id: list.h,v NOT CHECKED IN YET $" +#define LIST_H_VERSION "$Id: list.h,v 1.1 2001/05/31 21:11:53 jongfoster Exp $" /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/list.c,v $ + * File : $Source: /cvsroot/ijbswa/current/list.h,v $ * * Purpose : Declares functions to handle lists. * Functions declared include: @@ -35,7 +35,22 @@ * Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Revisions : - * $Log: list.c,v $ + * $Log: list.h,v $ + * Revision 1.1 2001/05/31 21:11:53 jongfoster + * - Moved linked list support to new "list.c" file. + * Structure definitions are still in project.h, + * function prototypes are now in "list.h". + * - Added support for "struct list_share", which is identical + * to "struct list" except it saves memory by not duplicating + * the strings. Obviously, this only works if there is some + * other way of managing the memory used by the strings. + * (These list_share lists are used for lists which last + * for only 1 request, and where all the list entries are + * just coming directly from entries in the actionsfile.) + * Note that you still need to destroy list_share lists + * properly to free the nodes - it's only the strings + * which are shared. + * * *********************************************************************/ @@ -47,25 +62,20 @@ extern "C" { #endif -extern void enlist(struct list *h, const char *s); -extern void destroy_list(struct list *h); +extern void enlist(struct list *h, const char *s); +extern void enlist_unique(struct list *header, const char *str); + +extern void destroy_list(struct list *h); + extern char *list_to_text(struct list *h); -void enlist_unique(struct list *header, const char *str); +extern int list_remove_item(struct list *header, const char *str); +extern int list_remove_list(struct list *header, const struct list *to_remove); -int list_remove_item(struct list *header, const char *str); -int list_remove_list(struct list *header, const struct list *to_remove); +extern void list_append_list_unique(struct list *dest, const struct list *src); -void list_duplicate(struct list *dest, const struct list *src); -void list_append_list_unique(struct list *dest, const struct list *src); +extern void list_duplicate(struct list *dest, const struct list *src); -void destroy_list_share(struct list_share *h); -void enlist_share(struct list_share *header, const char *str); -void enlist_unique_share(struct list_share *header, const char *str); -int list_remove_item_share(struct list_share *header, const char *str); -int list_remove_list_share(struct list_share *dest, const struct list *src); -void list_duplicate_share(struct list_share *dest, const struct list *src); -void list_append_list_unique_share(struct list_share *dest, const struct list *src); /* Revision control strings from this header and associated .c file */ extern const char list_rcs[]; diff --git a/parsers.c b/parsers.c index 359f6c5c..14e92ac5 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.12 2001/05/31 17:33:13 oes Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.13 2001/05/31 21:30:33 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -41,6 +41,11 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.12 2001/05/31 17:33:13 oes Exp $" * * Revisions : * $Log: parsers.c,v $ + * Revision 1.13 2001/05/31 21:30:33 jongfoster + * Removed list code - it's now in list.[ch] + * Renamed "permission" to "action", and changed many features + * to use the actions file rather than the global config. + * * Revision 1.12 2001/05/31 17:33:13 oes * * CRLF -> LF @@ -1102,7 +1107,6 @@ char *client_accept(const struct parsers *v, char *s, struct client_state *csp) void client_cookie_adder(struct client_state *csp) { struct list *lst; - struct list_share *lsts; char *tmp = NULL; char *e; @@ -1115,14 +1119,14 @@ void client_cookie_adder(struct client_state *csp) tmp = strsav(tmp, lst->str); } - for (lsts = csp->action->multi[ACTION_MULTI_WAFER]->next; lsts ; lsts = lsts->next) + for (lst = csp->action->multi[ACTION_MULTI_WAFER]->next; lst ; lst = lst->next) { if (tmp) { tmp = strsav(tmp, "; "); } - if ((e = cookie_encode(lsts->str))) + if ((e = cookie_encode(lst->str))) { tmp = strsav(tmp, e); freez(e); @@ -1158,12 +1162,12 @@ void client_cookie_adder(struct client_state *csp) *********************************************************************/ void client_xtra_adder(struct client_state *csp) { - struct list_share *l = csp->action->multi[ACTION_MULTI_ADD_HEADER]; + struct list *lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]; - for (l = l->next; l ; l = l->next) + for (lst = lst->next; lst ; lst = lst->next) { - log_error(LOG_LEVEL_HEADER, "addh: %s", l->str); - enlist(csp->headers, l->str); + log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str); + enlist(csp->headers, lst->str); } } diff --git a/project.h b/project.h index f9f277cf..acb08496 100644 --- a/project.h +++ b/project.h @@ -1,6 +1,6 @@ #ifndef _PROJECT_H #define _PROJECT_H -#define PROJECT_H_VERSION "$Id: project.h,v 1.10 2001/05/31 21:33:53 jongfoster Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.11 2001/06/01 10:32:47 oes Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -36,6 +36,9 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.11 2001/06/01 10:32:47 oes + * Added constants for anchoring selection bitmap + * * Revision 1.10 2001/05/31 21:33:53 jongfoster * Changes for new actions file, replacing permissionsfile * and parts of the config file. Also added support for @@ -259,15 +262,6 @@ struct list /* FIXME: Why not separate entries and header? */ }; -/* Generic linked list of strings */ -struct list_share /* FIXME: Why not separate entries and header? */ -{ - const char * str; /* valid in an entry */ - struct list_share *last; /* valid in header */ - struct list_share *next; -}; - - /* A URL pattern */ struct url_spec { @@ -341,7 +335,7 @@ struct current_action_spec char * string[ACTION_STRING_COUNT]; /* Strings to add */ - struct list_share multi[ACTION_MULTI_COUNT][1]; + struct list multi[ACTION_MULTI_COUNT][1]; }; struct action_spec