---------------------
PatchSet 1482 
Date: 2001/02/03 14:23:20
Author: rbcollins
Branch: rbcollins_filters
Tag: (none) 
Log:
list instead of array for FILTER_instance config entries.

Members: 
	src/cache_cf.c:1.1.1.3.4.1.4.7.4.6->1.1.1.3.4.1.4.7.4.7 
	src/client_side.c:1.1.1.3.4.1.4.15.2.16->1.1.1.3.4.1.4.15.2.17 
	src/filters.c:1.1.2.4->1.1.2.5 
	src/protos.h:1.1.1.3.8.11.2.7->1.1.1.3.8.11.2.8 
	src/structs.h:1.1.1.3.4.1.4.12.2.12->1.1.1.3.4.1.4.12.2.13 
	src/modules/htmldemo/htmldemo.c:1.1.2.2->1.1.2.3 
	src/modules/spy/spy.c:1.1.2.1->1.1.2.2 
	src/modules/textreplace/textreplace.c:1.1.2.6->1.1.2.7 

Index: squid/src/cache_cf.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v
retrieving revision 1.1.1.3.4.1.4.7.4.6
retrieving revision 1.1.1.3.4.1.4.7.4.7
diff -u -r1.1.1.3.4.1.4.7.4.6 -r1.1.1.3.4.1.4.7.4.7
--- squid/src/cache_cf.c	31 Jan 2001 12:41:51 -0000	1.1.1.3.4.1.4.7.4.6
+++ squid/src/cache_cf.c	3 Feb 2001 14:23:20 -0000	1.1.1.3.4.1.4.7.4.7
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.c,v 1.1.1.3.4.1.4.7.4.6 2001/01/31 12:41:51 rbcollins Exp $
+ * $Id: cache_cf.c,v 1.1.1.3.4.1.4.7.4.7 2001/02/03 14:23:20 rbcollins Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -1054,6 +1054,8 @@
     else if (type==MOD_EXTERNAL)
 	rv = mod_external_install(node->namestr, node);
 #endif
+    else 
+	rv=0;
     if (rv)
         dlinkAddTail(node,&node->node,&cfg->modules);
     else {
@@ -1165,32 +1167,16 @@
 }
 
 
-/* allocate new instance during config. Changing address is ok here as long
- * as all instances are allocated before any filter configs are created */
-void
-allocate_new_filterinstance(filterConfig * cfg)
-{
-    if (cfg->instances == NULL) {
-        cfg->n_allocated = 4;
-        cfg->instances = xcalloc(cfg->n_allocated, sizeof(FILTER_instance));
-    }
-    if (cfg->n_allocated == cfg->n_configured) {
-        FILTER_instance *tmp;
-        cfg->n_allocated <<= 1;
-        tmp = xcalloc(cfg->n_allocated, sizeof(FILTER_instance));
-        xmemcpy(tmp, cfg->instances, cfg->n_configured * sizeof(FILTER_instance));
-        xfree(cfg->instances);
-        cfg->instances = tmp;
-    }
-}
+CBDATA_TYPE(FILTER_instance);
 
 static void
-parse_filter_add(filterConfig * cfg)
+parse_filter_add(FILTER_instance ** cfg)
 {
     char *name_str, *instance_str;
     FILTER_module   *module = NULL;
     FILTER_instance *instance = NULL;
-    int i;
+    if (!(*cfg))
+	CBDATA_INIT_TYPE(FILTER_instance);
 
     if ((name_str = strtok(NULL, w_space)) == NULL)
         self_destruct();
@@ -1202,17 +1188,20 @@
         debug(3, 0) ("Parsing Config File: Unknown filter '%s'.\n", name_str);
         return;
     }
-    for (i = 0; i < cfg->n_configured; i++) {
-        if (strcasecmp(cfg->instances[i].namestr, instance_str)==0) {
+    instance=* cfg;
+    while (instance) {
+        if (strcasecmp(instance->namestr, instance_str)==0) {
             debug(3,0) ("Parsing Config File: Attempt to add two filters with the same instance name '%s'.\n", instance_str);
             return;
         }
+	instance=instance->next;
     }
 
     if (instance == NULL) {
-        allocate_new_filterinstance(cfg);
-        instance = cfg->instances + cfg->n_configured;
-        cfg->n_configured++;
+        instance = CBDATA_ALLOC(FILTER_instance, NULL);
+	memset(instance, 0 ,sizeof(FILTER_instance));
+	instance->next=*cfg;
+	*cfg=instance;
         instance->namestr=xstrdup(instance_str);
         instance->module=module;
 	cbdataLock(module);
@@ -1221,20 +1210,17 @@
 }
 
 static void
-free_filter_add(filterConfig * cfg)
+free_filter_add(FILTER_instance ** cfg)
 {
     FILTER_instance *instance;
-    int i;
-    for (i = 0; i < cfg->n_configured; i++) {
-        instance = cfg->instances + i;
+    while (*cfg) {
+        instance = *cfg;
+	*cfg=instance->next;
         instance->module->RemInstance(instance);
 	cbdataUnlock(instance->module);
         safe_free(instance->namestr);
+	cbdataFree(instance);
     }
-    safe_free(cfg->instances);
-    cfg->instances = NULL;
-    cfg->n_allocated = 0;
-    cfg->n_configured = 0;
 }
 
 
@@ -1242,7 +1228,7 @@
 #define free_filter_config free_filter_add
 
 static void
-parse_filter_config(filterConfig * cfg)
+parse_filter_config(FILTER_instance * * cfg)
 {
 
     char *param_str, *instance_str;
@@ -1262,7 +1248,7 @@
 }
 
 static void
-dump_filter_add(StoreEntry * entry, const char *name, filterConfig cfg)
+dump_filter_add(StoreEntry * entry, const char *name, FILTER_instance *cfg)
 {
 #if 0
     authScheme *scheme;
@@ -1275,7 +1261,7 @@
 }
 
 static void
-dump_filter_config(StoreEntry * entry, const char *name, filterConfig cfg)
+dump_filter_config(StoreEntry * entry, const char *name, FILTER_instance *cfg)
 {
 #if 0
     authScheme *scheme;
Index: squid/src/client_side.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v
retrieving revision 1.1.1.3.4.1.4.15.2.16
retrieving revision 1.1.1.3.4.1.4.15.2.17
diff -u -r1.1.1.3.4.1.4.15.2.16 -r1.1.1.3.4.1.4.15.2.17
--- squid/src/client_side.c	1 Feb 2001 13:59:50 -0000	1.1.1.3.4.1.4.15.2.16
+++ squid/src/client_side.c	3 Feb 2001 14:23:20 -0000	1.1.1.3.4.1.4.15.2.17
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.16 2001/02/01 13:59:50 rbcollins Exp $
+ * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.17 2001/02/03 14:23:20 rbcollins Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -2525,7 +2525,7 @@
 #endif
 #if 0
 	/* we're finished, but the filters haven't been given a termination case */
-        if (http->repfilters.head != NULL && size>0) {
+        if (http->repfilters.head != NULL && size>0 && !http->flags.done_copying) {
             FILTER_list *temp_filter;
             temp_filter=http->repfilters.head->data;
             temp_filter->filter(NULL, 0, &http->repfilters, temp_filter, FILTER_EOF, temp_filter->data);	
Index: squid/src/filters.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/Attic/filters.c,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- squid/src/filters.c	31 Jan 2001 21:07:43 -0000	1.1.2.4
+++ squid/src/filters.c	3 Feb 2001 14:23:20 -0000	1.1.2.5
@@ -1,6 +1,6 @@
 
 /*
- * $Id: filters.c,v 1.1.2.4 2001/01/31 21:07:43 rbcollins Exp $
+ * $Id: filters.c,v 1.1.2.5 2001/02/03 14:23:20 rbcollins Exp $
  *
  * DEBUG: section 83    Content Processing Filters
  * AUTHOR: Robert Collins
@@ -42,7 +42,6 @@
 
 void filterModuleUnlink(void *);
 
-/* TODO: make these linked lists so we can remove cleanly */
 /* filter framework */
 void
 filterRegisterModule(const char *namestr, ADDFILTERINSTANCE *add,
@@ -82,6 +81,8 @@
 	temp=filter;
 	filter=filter->next;
 	if (strcmp(temp->namestr, namestr) == 0) {
+	    if (temp==filter_list)
+		filter_list=filter;
 	    cbdataFree(temp);
 	    filter=NULL;
 	}
@@ -117,14 +118,13 @@
 }
 
 FILTER_instance *
-filterInstanceByName(const char *namestr, filterConfig *cfg) {
-    FILTER_instance *instance;
-    int i = 0;
-    for (i = 0; i < cfg->n_configured; i++) {
-        instance = cfg->instances + i;
+filterInstanceByName(const char *namestr, FILTER_instance **cfg) {
+    FILTER_instance *instance=*cfg;
+    while (instance) {
         if (strncasecmp(namestr, instance->namestr, strlen(instance->namestr)) == 0) {
             return instance;
         }
+	instance=instance->next;
     }
     return NULL;
 }
Index: squid/src/protos.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/protos.h,v
retrieving revision 1.1.1.3.8.11.2.7
retrieving revision 1.1.1.3.8.11.2.8
diff -u -r1.1.1.3.8.11.2.7 -r1.1.1.3.8.11.2.8
--- squid/src/protos.h	1 Feb 2001 13:37:48 -0000	1.1.1.3.8.11.2.7
+++ squid/src/protos.h	3 Feb 2001 14:23:20 -0000	1.1.1.3.8.11.2.8
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.1.1.3.8.11.2.7 2001/02/01 13:37:48 rbcollins Exp $
+ * $Id: protos.h,v 1.1.1.3.8.11.2.8 2001/02/03 14:23:20 rbcollins Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -1309,6 +1309,6 @@
 
 /* filters.c */
 extern FILTER_module *filterByName(const char *namestr);
-extern FILTER_instance *filterInstanceByName(const char *namestr, filterConfig *cfg);
+extern FILTER_instance *filterInstanceByName(const char *namestr, FILTER_instance **);
 extern void filterRegisterModule(const char *, ADDFILTERINSTANCE *, REMFILTERINSTANCE *);
 extern void filterDeregisterModule(const char *);
Index: squid/src/structs.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/structs.h,v
retrieving revision 1.1.1.3.4.1.4.12.2.12
retrieving revision 1.1.1.3.4.1.4.12.2.13
diff -u -r1.1.1.3.4.1.4.12.2.12 -r1.1.1.3.4.1.4.12.2.13
--- squid/src/structs.h	1 Feb 2001 13:37:48 -0000	1.1.1.3.4.1.4.12.2.12
+++ squid/src/structs.h	3 Feb 2001 14:23:20 -0000	1.1.1.3.4.1.4.12.2.13
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.12 2001/02/01 13:37:48 rbcollins Exp $
+ * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.13 2001/02/03 14:23:20 rbcollins Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -303,13 +303,8 @@
     dlink_list modules;
 };
 
-struct _filterConfig {
-    FILTER_instance *instances;
-    int n_allocated;
-    int n_configured;
-};
-
 struct _FILTER_instance {
+    FILTER_instance *next;
     char *namestr;
     FILTER_module *module;
     ADDFILTER *Add;
@@ -613,7 +608,7 @@
     filterAccessConfig response_filters;
     filterAccessConfig client_request_filters;
     filterAccessConfig server_request_filters;
-    filterConfig filters;
+    FILTER_instance *filters;
     struct _authConfig {
 	authScheme *schemes;
 	int n_allocated;
Index: squid/src/modules/htmldemo/htmldemo.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/modules/htmldemo/Attic/htmldemo.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- squid/src/modules/htmldemo/htmldemo.c	3 Feb 2001 00:45:12 -0000	1.1.2.2
+++ squid/src/modules/htmldemo/htmldemo.c	3 Feb 2001 14:23:21 -0000	1.1.2.3
@@ -39,74 +39,78 @@
  type 1 : the filter removes HTML tags Isize decreases
  */
 
-/* The tester filter */
-typedef struct _tester_cfg TesterConfig;
-typedef struct _tester_state TesterState;
-struct _tester_state {
-    TesterConfig *config;
+/* The htmldemo filter */
+typedef struct _htmldemo_cfg HtmlDemoConfig;
+typedef struct _htmldemo_state HtmlDemoState;
+struct _htmldemo_state {
+    HtmlDemoConfig *config;
     char *buf;
     int buf_len,buf_max_len;
     int in_tag;
 };
-struct _tester_cfg {
+struct _htmldemo_cfg {
     int type;
 };
 
 
-static REMOVEFILTER  clientFilterTester_Remove;
-static ADDFILTER     clientFilterTester_Add;
-static FILTERMKSTATE clientFilterTester_MakeState;
-static FILTERPARSE   clientFilterTester_Parse;
-static DATAFILTER clientFilterTester;
+static REMOVEFILTER  htmldemo_Remove;
+static ADDFILTER     HtmlDemo_Add;
+static FILTERMKSTATE HtmlDemo_MakeState;
+static FILTERPARSE   HtmlDemo_Parse;
+static DATAFILTER HtmlDemo_Filter;
 
 static void
-clientFilterFreeConfig(void *data) {
-    TesterConfig *config=data;
+HtmlDemoFreeConfig(void *data) {
+    HtmlDemoConfig *config=data;
 
     xfree(config);
 }
 
 static void
-clientFilterTester_AddInstance(FILTER_instance *instance) {
-    TesterConfig *config;
-    instance->Add=clientFilterTester_Add;
-    instance->MakeState=clientFilterTester_MakeState;
-    instance->Parse    =clientFilterTester_Parse;
-    instance->data=xmalloc(sizeof(TesterConfig));
+clientFilterHtmlDemo_AddInstance(FILTER_instance *instance) {
+    HtmlDemoConfig *config;
+    instance->Add=HtmlDemo_Add;
+    instance->MakeState=HtmlDemo_MakeState;
+    instance->Parse    =HtmlDemo_Parse;
+    instance->data=xmalloc(sizeof(HtmlDemoConfig));
     /* Set defaults, if sensible defaults exist */
     config=instance->data;
+    /* lock the instance */
+    cbdataLock(instance);
 }
 
 static void
-clientFilterTester_RemInstance(FILTER_instance *instance) {
+clientFilterHtmlDemo_RemInstance(FILTER_instance *instance) {
     instance->Add=NULL;
     instance->MakeState=NULL;
-    clientFilterFreeConfig(instance->data);
+    HtmlDemoFreeConfig(instance->data);
     instance->data=NULL;
+    /* unlock the instance */
+    cbdataUnlock(instance);
 }
 
 static void
-clientFilterTester_Add(dlink_list *filters, void *filter_config) {
+HtmlDemo_Add(dlink_list *filters, void *filter_config) {
     FILTER_list *temp_filter;
     temp_filter=xmalloc(sizeof(FILTER_list));
-    temp_filter->filter=clientFilterTester;
-    temp_filter->Remove=clientFilterTester_Remove;
+    temp_filter->filter=HtmlDemo_Filter;
+    temp_filter->Remove=htmldemo_Remove;
     temp_filter->data=filter_config;
     /* cbDataLock(http); ? */
     dlinkAddTail(temp_filter, &temp_filter->node, filters);
 }
 
 static void *
-clientFilterTester_MakeState(void * data) {
-    TesterState *state;
-    TesterConfig *config=data;
+HtmlDemo_MakeState(void * data) {
+    HtmlDemoState *state;
+    HtmlDemoConfig *config=data;
     if (!config)
         return NULL;
     /* it's up to the filter writer wether to refcount the config,
      * or copy it. For now, to save learning cbdata, I copy it
      */
-    state=xmalloc(sizeof(TesterState));
-    state->config=xmalloc(sizeof(TesterConfig));
+    state=xmalloc(sizeof(HtmlDemoState));
+    state->config=xmalloc(sizeof(HtmlDemoConfig));
     state->config->type=config->type;
     state->buf=NULL;
     state->buf_len=state->buf_max_len=0;
@@ -114,23 +118,22 @@
 }
 
 static void
-clientFilterTester_Remove(FILTER_list *filters, dlink_list *filter_list, void *data) {
-    TesterState *state=data;
+htmldemo_Remove(FILTER_list *filters, dlink_list *filter_list, void *data) {
+    HtmlDemoState *state=data;
     dlinkDelete(&filters->node, filter_list);
     xfree(filters);
-    clientFilterFreeConfig(state->config);
+    HtmlDemoFreeConfig(state->config);
     state->config=NULL;
-    xfree(state);
+    safe_free(state->buf);
+    safe_free(state);
 }
 
 static void
-clientFilterTester_Parse(void *data, const char *namestr, char *param_str) {
-    TesterConfig *config=data;
-    char *z;
+HtmlDemo_Parse(void *data, const char *namestr, char *param_str) {
+    HtmlDemoConfig *config=data;
 
     if (strcasecmp(param_str, "type") == 0) {
-        parse_eol(&z);
-        config->type=atoi(z);
+        parse_int(&config->type);
     } /*else if (strcasecmp(param_str, "search") == 0) {
         parse_eol(&config->searchstring);
     } */else {
@@ -138,7 +141,7 @@
     }
 }
 
-void TesterWrite(TesterState *s,char *c,int l)
+void HtmlDemoWrite(HtmlDemoState *s,const char *c,int l)
 {
     if (s->buf_max_len<=s->buf_max_len+l)
     {
@@ -154,8 +157,8 @@
 mod_install_htmldemo (const char *namestr)
 {
   /* Register as a potential client_side reply filter */
-  filterRegisterModule (namestr, clientFilterTester_AddInstance,
-                        clientFilterTester_RemInstance);
+  filterRegisterModule (namestr, clientFilterHtmlDemo_AddInstance,
+                        clientFilterHtmlDemo_RemInstance);
   debug(1,1)("******* registering=[%p]\n",namestr);
 }
 
@@ -167,14 +170,14 @@
 }
 
 static void
-clientFilterTester(const char *buf, size_t len, dlink_list *filter_list,
+HtmlDemo_Filter(const char *buf, size_t len, dlink_list *filter_list,
                        FILTER_list *filters, unsigned int flags, void *data) {
     FILTER_list *temp_filter;
-    TesterState *state=data;
-    TesterConfig *config=state->config;
+    HtmlDemoState *state=data;
+    HtmlDemoConfig *config=state->config;
 
     temp_filter=filters->node.next->data;
-    debug(1,1)("******* clientFilterTester (%p,%d,%d)\n",buf,len,flags);
+    debug(1,1)("******* clientFilterHtmlDemo (%p,%d,%d)\n",buf,len,flags);
 
     if (flags & FILTER_HTTP_HEADER)
     {
@@ -197,14 +200,14 @@
 
             if (config->type==0)
             {
-                TesterWrite(state,buf+i,1);
+                HtmlDemoWrite(state,buf+i,1);
                 if (!state->in_tag)
-                    TesterWrite(state," ",1);
+                    HtmlDemoWrite(state," ",1);
             }
             else
             {
                 if (!state->in_tag)
-                    TesterWrite(state,buf+i,1);
+                    HtmlDemoWrite(state,buf+i,1);
             };
 
             if (buf[i]=='>')
@@ -213,11 +216,12 @@
 
         temp_filter->filter(state->buf,state->buf_len,filter_list,
                             temp_filter, flags, temp_filter->data);
-        /*TesterWrite(state,"",1);
+        /*HtmlDemoWrite(state,"",1);
         debug(1,1)("[%s]\n",state->buf);*/
     };
     if (flags & FILTER_EOF)
     {
-        xfree(state->buf);
+        safe_free(state->buf);
+	state->buf=NULL;
     };
 }
Index: squid/src/modules/spy/spy.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/modules/spy/Attic/spy.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- squid/src/modules/spy/spy.c	31 Jan 2001 21:07:43 -0000	1.1.2.1
+++ squid/src/modules/spy/spy.c	3 Feb 2001 14:23:21 -0000	1.1.2.2
@@ -1,6 +1,6 @@
 
 /*
- * $Id: spy.c,v 1.1.2.1 2001/01/31 21:07:43 rbcollins Exp $
+ * $Id: spy.c,v 1.1.2.2 2001/02/03 14:23:21 rbcollins Exp $
  *
  * DEBUG: section 83    Content Processing Filters
  * AUTHOR: Robert Collins
@@ -59,6 +59,8 @@
   instance->Parse = SpyFilter_Parse;
   instance->data = NULL;
   /* Set defaults, if sensible defaults exist */
+  /* lock the instance */
+  cbdataLock(instance);
 }
 
 static void
@@ -67,6 +69,7 @@
   instance->Add = NULL;
   instance->MakeState = NULL;
   instance->data = NULL;
+  cbdataUnlock(instance);
 }
 
 static void
Index: squid/src/modules/textreplace/textreplace.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/modules/textreplace/Attic/textreplace.c,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- squid/src/modules/textreplace/textreplace.c	1 Feb 2001 23:13:14 -0000	1.1.2.6
+++ squid/src/modules/textreplace/textreplace.c	3 Feb 2001 14:23:21 -0000	1.1.2.7
@@ -1,6 +1,6 @@
 
 /*
- * $Id: textreplace.c,v 1.1.2.6 2001/02/01 23:13:14 rbcollins Exp $
+ * $Id: textreplace.c,v 1.1.2.7 2001/02/03 14:23:21 rbcollins Exp $
  *
  * DEBUG: section 83    Content Processing Filters
  * AUTHOR: Robert Collins
@@ -84,6 +84,8 @@
   config = instance->data;
   config->searchstring = NULL;
   config->replace = NULL;
+  /* lock the instance to it is availble to us later */
+  cbdataUnlock(instance);
 }
 
 static void
@@ -93,6 +95,7 @@
   instance->MakeState = NULL;
   clientFilterFreeConfig (instance->data);
   instance->data = NULL;
+  cbdataUnlock(instance);
 }
 
 static void
