From 2f113e3507f764f4406587c7117fce304b42df4f Mon Sep 17 00:00:00 2001 From: oes Date: Fri, 29 Jun 2001 13:30:22 +0000 Subject: [PATCH] - Added Convenience function enlist_unique_header(), which takes the Header name and value as separate arguments and thus saves the pain of sprintf()ing and determining the Header name length to enlist_unique - Improved comments - Removed logentry from cancelled commit --- list.c | 124 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/list.c b/list.c index bc5476b9..0104a95e 100644 --- a/list.c +++ b/list.c @@ -1,4 +1,4 @@ -const char list_rcs[] = "$Id: list.c,v 1.3 2001/06/03 11:03:48 oes Exp $"; +const char list_rcs[] = "$Id: list.c,v 1.3 2001/06/03 19:12:24 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/list.c,v $ @@ -34,59 +34,8 @@ const char list_rcs[] = "$Id: list.c,v 1.3 2001/06/03 11:03:48 oes Exp $"; * * Revisions : * $Log: list.c,v $ - * Revision 1.3 2001/06/03 11:03:48 oes - * Makefile/in - * - * introduced cgi.c - * - * actions.c: - * - * adapted to new enlist_unique arg format - * - * conf loadcfg.c - * - * introduced confdir option - * - * filters.c filtrers.h - * - * extracted-CGI relevant stuff - * - * jbsockets.c - * - * filled comment - * - * jcc.c - * - * support for new cgi mechansim - * - * list.c list.h - * - * functions for new list type: "map" - * extended enlist_unique - * - * miscutil.c .h - * introduced bindup() - * - * parsers.c parsers.h - * - * deleted const struct interceptors - * - * pcrs.c - * added FIXME - * - * project.h - * - * added struct map - * added struct http_response - * changes struct interceptors to struct cgi_dispatcher - * moved HTML stuff to cgi.h - * - * re_filterfile: - * - * changed - * - * showargs.c - * NO TIME LEFT + * Revision 1.3 2001/06/03 19:12:24 oes + * functions for new struct map, extended enlist_unique * * Revision 1.2 2001/06/01 18:49:17 jongfoster * Replaced "list_share" with "list" - the tiny memory gain was not @@ -251,6 +200,64 @@ void enlist_unique(struct list *header, const char *str, int n) } +/********************************************************************* + * + * Function : enlist_unique_header + * + * Description : Make a HTTP header from the two strings name and value, + * and append the result into a specified string list, + * if & only if there isn't already a header with that name. + * + * Parameters : + * 1 : header = pointer to list 'dummy' header + * 2 : first = first string to add to the list (maybe NULL) + * 3 : second = number of chars to use for uniqueness test + * + * Returns : N/A + * + *********************************************************************/ +void enlist_unique_header(struct list *header, const char *name, const char *value) +{ + struct list *last; + struct list *cur = header->next; + int length; + char *dummy; + + if (name == NULL || value == NULL) return; + + dummy = strdup(name); + dummy = strsav(dummy, ": "); + length = strlen(dummy); + + while (cur != NULL) + { + if ((cur->str != NULL) && + (0 == strncmp(dummy, cur->str, length))) + { + /* Already there */ + return; + } + cur = cur->next; + } + + cur = (struct list *)malloc(sizeof(*cur)); + + if (cur != NULL) + { + cur->str = strsav(dummy, value); + cur->next = NULL; + + last = header->last; + if (last == NULL) + { + last = header; + } + last->next = cur; + header->last = cur; + } +} + + /********************************************************************* * * Function : destroy_list @@ -476,13 +483,16 @@ void list_append_list_unique(struct list *dest, const struct list *src) * Description : Add a mapping from given name to given value to a * given map. * + * Note: Since all strings will be free()d in free_map() + * later, use the copy flags for constants or + * strings that will be independantly free()d. + * * Parameters : * 1 : map = map to add to * 2 : name = name to add - * 3 : nc = flag set if name is string constant, and - * must be strdup()d, so it can later be free()d (FIXME!) + * 3 : nc = flag set if a copy of name should be used * 4 : value = value to add - * 5 : vc = flag set if value is string constant + * 5 : vc = flag set if a copy of value should be used * * Returns : pointer to extended map, or NULL if failiure * -- 2.39.2