--------------------- PatchSet 1417 Date: 2001/01/29 13:35:42 Author: rbcollins Branch: rbcollins_filters Tag: (none) Log: dynmic multi instance configuration partially done. Gotta sleep though. This code will not compile and run Members: src/client_side.c:1.1.1.3.4.1.4.15.2.6->1.1.1.3.4.1.4.15.2.7 src/structs.h:1.1.1.3.4.1.4.12.2.5->1.1.1.3.4.1.4.12.2.6 src/typedefs.h:1.1.1.3.8.7.4.3->1.1.1.3.8.7.4.4 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.6 retrieving revision 1.1.1.3.4.1.4.15.2.7 diff -u -r1.1.1.3.4.1.4.15.2.6 -r1.1.1.3.4.1.4.15.2.7 --- squid/src/client_side.c 28 Jan 2001 20:54:59 -0000 1.1.1.3.4.1.4.15.2.6 +++ squid/src/client_side.c 29 Jan 2001 13:35:42 -0000 1.1.1.3.4.1.4.15.2.7 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.6 2001/01/28 20:54:59 rbcollins Exp $ + * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.7 2001/01/29 13:35:42 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1333,14 +1333,82 @@ } +typedef struct _onunloadcfg OnUnloadConfig; +typedef struct _onunloadstate OnUnloadState; +struct _onunloadstate { + OnUnloadConfig *config; + /* allow for searching across buffer breaks */ + /* not implemented just yet :] */ + char *pos; +}; +struct _onunloadcfg { + char *searchstring, *replace; +}; + +static REMOVEFILTER clientFilterOnUnload_Remove; +static ADDFILTER clientFilterOnUnload_Add; +static FILTERMKSTATE clientFilterOnUnload_MakeState; + +void +clientFilterFreeConfig(void *data) { + OnUnloadConfig *config=data; + xfree(config->searchstring); + config->searchstring=NULL; + xfree(config->replace); + config->replace=NULL; + xfree(config); +} + +void +clientFilterOnUnload_AddInstance(FILTER_instance *instance) { + instance->Add=clientFilterOnUnload_Add; + instance->MakeState=clientFilterOnUnload_MakeState; + instance->data=xmalloc(sizeof(OnUnloadConfig)); +} + +void +clientFilterOnUnload_RemInstance(FILTER_instance *instance) { + instance->Add=NULL; + instance->MakeState=NULL; + clientFilterFreeConfig(instance->data); + instance->data=NULL; +} + void -clientFilterOnUnload_Add(clientHttpRequest * http, HttpReply * rep) { +clientFilterOnUnload_Add(dlink_list *filters, void *filter_config) { FILTER_list *temp_filter; temp_filter=xmalloc(sizeof(FILTER_list)); temp_filter->filter=clientFilterOnUnload; - temp_filter->data=NULL; + temp_filter->Remove=clientFilterOnUnload_Remove; + temp_filter->data=filter_config; /* cbDataLock(http); ? */ - dlinkAddTail(temp_filter, &temp_filter->node, &http->repfilters); + dlinkAddTail(temp_filter, &temp_filter->node, filters); +} + +static void * +clientFilterOnUnload_MakeState(void * data) { + OnUnloadState *state; + OnUnloadConfig *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(OnUnloadState)); + state->config=xmalloc(sizeof(OnUnloadConfig)); + state->config->searchstring=xstrdup(config->searchstring); + state->config->replace=xstrdup(config->replace); + return state; +} + +void +clientFilterOnUnload_Remove(FILTER_list *filters, dlink_list *filter_list, void *data) { + OnUnloadState *state=data; + dlinkDelete(&filters->node, filter_list); + xfree(filters); + clientFilterFreeConfig(state->config); + state->config=NULL; + xfree(state); } /* @@ -1406,16 +1474,72 @@ { aclCheck_t *ch; int rv; + + /* setup an array of filter modules + * 1) Compiled into the squid code, a filter "urlfilter" is registered */ + FILTER_module modules[0]; + FILTER_instance instances[1]; + + modules[0].namestr="textreplace"; + modules[0].AddInstance=clientFilterOnUnload_AddInstance; + + /* now for each module, +#create an instance aka filter config +filter_add textreplace onunload*/ + instances[0].namestr="onunload"; + instances[0].module=modules[0]; + modules[0].AddInstance(&instances[0]); + +/*filter_add textreplace onclick*/ + instances[1].namestr="onclick"; + instances[1].module=modules[0]; + modules[0].AddInstance(&instances[1]); + +/* +# configure it +filter_config onunload search onunload +filter_config onunload replace nonsense +*/ + instances[0].parse("search onunload"); + instances[0].parse("replace nonsense"); + +/* +filter_config onclick search onclick +filter_config onclick replace non1234 +*/ + ch = aclChecklistCreate(Config.accessList.onunload, http->request, NULL); ch->reply = rep; rv = aclCheckFast(Config.accessList.onunload, ch); aclChecklistFree(ch); if (rv==1) { + OnUnloadConfig filtercfg; + filtercfg.searchstring="onunload"; + filtercfg.replace="nonsense"; debug(33,8)("\n\nAdding the filter OnUnload!!\n\n"); - clientFilterOnUnload_Add(http, rep); + /* hmm. what should the parameters be? the list and a config? + * that allows all four cases with one insertion routine. + * but perhaps the filter needs to know the direction? + * to allow for reconfigures, each filter will be given a copy of their + * config with room for whatever state data they need. + * Rather than require the filter to make the copy, + * we will get a callback that does that. + */ + clientFilterOnUnload_Add(&http->repfilters, clientFilterOnUnload_MakeState(&filtercfg)); + filtercfg.searchstring="onclick"; + filtercfg.replace="non1234"; + clientFilterOnUnload_Add(&http->repfilters, clientFilterOnUnload_MakeState(&filtercfg)); } } + +/* remove all the config details. This simulates what happens when a reconfigure occurs + * during a request's process */ + + /* for each instance */ + instances[1].module->RemInstance(&instances[1]); + instances[0].module->RemInstance(&instances[0]); + /* the following should happen: while (filter_list test) @@ -2071,8 +2195,11 @@ clientFilterOnUnload(const char *buf, size_t len, dlink_list *filter_list, FILTER_list *filters, unsigned int flags, void *data) { #define pattern "onunload.*\".*\"" FILTER_list *temp_filter; - char *chr, searchstring[]="onunload"; + OnUnloadState *state=data; + OnUnloadConfig *config=state->config; + char *chr, *searchstring=config->searchstring; const char *startpos,*pos; + size_t replacelen=strlen(config->replace); /* this looks for browser DOM handlers of the type onunload="..." and * removes them from the data passed to the client @@ -2124,9 +2251,9 @@ if (startpos-buf) temp_filter->filter(buf,startpos-buf,filter_list, temp_filter, flags, temp_filter->data); /* send the filter set of data */ - temp_filter->filter("nonsense",8,filter_list, temp_filter, flags, temp_filter->data); + temp_filter->filter(config->replace,replacelen,filter_list, temp_filter, flags, temp_filter->data); /* and the rest */ - temp_filter->filter(startpos+8,len-(startpos-buf)-8,filter_list, temp_filter, flags,temp_filter->data); + temp_filter->filter(startpos+replacelen,len-(startpos-buf)-replacelen,filter_list, temp_filter, flags,temp_filter->data); return; } if(tolower(*pos)!=tolower(*chr)) { @@ -2240,8 +2367,13 @@ while (link) { tmplink=link; link=link->next; - dlinkDelete(tmplink, &http->repfilters); - xfree(tmplink->data); + temp_filter=tmplink->data; + if (temp_filter->Remove) + temp_filter->Remove(temp_filter, &http->repfilters, temp_filter->data); + else { + dlinkDelete(tmplink, &http->repfilters); + xfree(tmplink->data); + } } } while (http->te_translations) { @@ -2292,8 +2424,13 @@ while (link) { tmplink=link; link=link->next; - dlinkDelete(tmplink, &http->repfilters); - xfree(tmplink->data); + temp_filter=tmplink->data; + if (temp_filter->Remove) + temp_filter->Remove(temp_filter, &http->repfilters, temp_filter->data); + else { + dlinkDelete(tmplink, &http->repfilters); + xfree(tmplink->data); + } } } while (http->te_translations) { 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.5 retrieving revision 1.1.1.3.4.1.4.12.2.6 diff -u -r1.1.1.3.4.1.4.12.2.5 -r1.1.1.3.4.1.4.12.2.6 --- squid/src/structs.h 28 Jan 2001 13:24:14 -0000 1.1.1.3.4.1.4.12.2.5 +++ squid/src/structs.h 29 Jan 2001 13:35:42 -0000 1.1.1.3.4.1.4.12.2.6 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.5 2001/01/28 13:24:14 rbcollins Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.6 2001/01/29 13:35:42 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -912,9 +912,24 @@ unsigned int only_if_cached:1; }; +struct _FILTER_instance { + char *namestr; + FILTER_module *module; + ADDFILTER *Add; + FILTERMKSTATE *MakeState; + void *data; +}; + +struct _FILTER_module { + char *namestr; + ADDFILTERINSTANCE *AddInstance; + REMFILTERINSTANCE *RemInstance; +}; + struct _FILTER_list { dlink_node node; DATAFILTER * filter; + REMOVEFILTER *Remove; void *data; }; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.1.1.3.8.7.4.3 retrieving revision 1.1.1.3.8.7.4.4 diff -u -r1.1.1.3.8.7.4.3 -r1.1.1.3.8.7.4.4 --- squid/src/typedefs.h 26 Jan 2001 13:18:33 -0000 1.1.1.3.8.7.4.3 +++ squid/src/typedefs.h 29 Jan 2001 13:35:42 -0000 1.1.1.3.8.7.4.4 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.1.1.3.8.7.4.3 2001/01/26 13:18:33 rbcollins Exp $ + * $Id: typedefs.h,v 1.1.1.3.8.7.4.4 2001/01/29 13:35:42 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -354,7 +354,13 @@ /* filters.c */ typedef struct _FILTER_list FILTER_list; +typedef struct _FILTER_module FILTER_module; +typedef struct _FILTER_instance FILTER_instance; /* buffer, data length, remaining filters pointer, flags, state data */ typedef void DATAFILTER(const char *, size_t , dlink_list *, FILTER_list *, unsigned int, void *); - +/* self, the list, the state */ +typedef void REMOVEFILTER(FILTER_list *, dlink_list *, void*); +typedef void *FILTERMKSTATE(void *); +typedef void ADDFILTER(dlink_list *, void *); +typedef void ADDFILTERINSTANCE(FILTER_instance *); #endif /* _TYPEDEFS_H_ */