--------------------- PatchSet 1485 Date: 2001/02/04 12:47:34 Author: rbcollins Branch: rbcollins_filters Tag: (none) Log: moved more filter support code to filters.c Members: src/cache_cf.c:1.1.1.3.4.1.4.7.4.7->1.1.1.3.4.1.4.7.4.8 src/client_side.c:1.1.1.3.4.1.4.15.2.17->1.1.1.3.4.1.4.15.2.18 src/filters.c:1.1.2.5->1.1.2.6 src/protos.h:1.1.1.3.8.11.2.8->1.1.1.3.8.11.2.9 src/structs.h:1.1.1.3.4.1.4.12.2.13->1.1.1.3.4.1.4.12.2.14 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.7 retrieving revision 1.1.1.3.4.1.4.7.4.8 diff -u -r1.1.1.3.4.1.4.7.4.7 -r1.1.1.3.4.1.4.7.4.8 --- squid/src/cache_cf.c 3 Feb 2001 14:23:20 -0000 1.1.1.3.4.1.4.7.4.7 +++ squid/src/cache_cf.c 4 Feb 2001 12:47:34 -0000 1.1.1.3.4.1.4.7.4.8 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.1.1.3.4.1.4.7.4.7 2001/02/03 14:23:20 rbcollins Exp $ + * $Id: cache_cf.c,v 1.1.1.3.4.1.4.7.4.8 2001/02/04 12:47:34 rbcollins Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1086,34 +1086,16 @@ dump_mod_install(StoreEntry * entry, const char *name, modConfig cfg){ } - - -/* allocate new filteraccess record. Caveats with changing address apply as per - * new_filterinstance */ -void -allocate_new_filteraccess(filterAccessConfig * cfg) -{ - if (cfg->filters == NULL) { - cfg->n_allocated = 4; - cfg->filters = xcalloc(cfg->n_allocated, sizeof(filterAccess)); - } - if (cfg->n_allocated == cfg->n_configured) { - filterAccess *tmp; - cfg->n_allocated <<= 1; - tmp = xcalloc(cfg->n_allocated, sizeof(filterAccess)); - xmemcpy(tmp, cfg->filters, cfg->n_configured * sizeof(filterAccess)); - xfree(cfg->filters); - cfg->filters = tmp; - } -} +CBDATA_TYPE(filterAccess); static void -parse_filter_access(filterAccessConfig * cfg) +parse_filter_access(filterAccess * * cfg) { char *instance_str; - filterAccess *filter = NULL; + filterAccess *filter = NULL, *tail = NULL; FILTER_instance *instance = NULL; - int i; + if (!(*cfg)) + CBDATA_INIT_TYPE(filterAccess); if ((instance_str = strtok(NULL, w_space)) == NULL) self_destruct(); @@ -1122,39 +1104,43 @@ debug(3, 0) ("Parsing Config File: Unknown filter instance '%s'\n", instance_str); return; } - for (i = 0; i < cfg->n_configured; i++) { - if (cfg->filters[i].instance==instance) { - /* new line for existing access list */ - filter= cfg->filters+i; - } + + filter =*cfg; + while (filter && !(filter->instance==instance)) { + tail=filter; + filter=filter->next; } if (filter == NULL) { - allocate_new_filteraccess(cfg); - filter = cfg->filters + cfg->n_configured; - cfg->n_configured++; - filter->instance=instance; + filter = CBDATA_ALLOC(filterAccess, NULL); + memset(filter, 0, sizeof(filterAccess)); + filter->next=NULL; + if (tail) + tail->next=filter; + else + /* first entry */ + *cfg=filter; + filter->instance=instance; + cbdataLock(instance); } parse_acl_access(&filter->apply); } static void -free_filter_access(filterAccessConfig * cfg) +free_filter_access(filterAccess ** cfg) { filterAccess *filter; - int i; - for (i = 0; i < cfg->n_configured; i++) { - filter = cfg->filters + i; + while (*cfg) { + filter=*cfg; + *cfg=filter->next; free_acl_access(&filter->apply); + cbdataUnlock(filter->instance); + cbdataFree(filter); } - safe_free(cfg->filters); - cfg->filters = NULL; - cfg->n_allocated = 0; - cfg->n_configured = 0; } static void -dump_filter_access(StoreEntry * entry, const char *name, filterAccessConfig cfg) +dump_filter_access(StoreEntry * entry, const char *name, filterAccess * 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.17 retrieving revision 1.1.1.3.4.1.4.15.2.18 diff -u -r1.1.1.3.4.1.4.15.2.17 -r1.1.1.3.4.1.4.15.2.18 --- squid/src/client_side.c 3 Feb 2001 14:23:20 -0000 1.1.1.3.4.1.4.15.2.17 +++ squid/src/client_side.c 4 Feb 2001 12:47:34 -0000 1.1.1.3.4.1.4.15.2.18 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.17 2001/02/03 14:23:20 rbcollins Exp $ + * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.18 2001/02/04 12:47:34 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1280,7 +1280,6 @@ #endif -static DATAFILTER clientDoTEReply; static DATAFILTER clientWriteReplyHeaders; static DATAFILTER clientDoCommWriteMemBuf; @@ -1290,7 +1289,6 @@ int y, may_apply_tes; const char *s_ct; String s_ce; - FILTER_list *temp_filter; /* begin list of modules here */ may_apply_tes = 0; @@ -1321,50 +1319,6 @@ } te_build_encode_xlate_list(&http->request->header, hdr, filter_list, http->request->http_ver, &http->request->flags); -#if 0 - /* add the filter to the request chain */ - if (http->request->flags.te_encoding) { - /* handle TE */ - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=clientDoTEReply; - temp_filter->Remove=NULL; - temp_filter->data=http; - /* cbDataLock(http); ? */ - dlinkAddTail(temp_filter, &temp_filter->node, &http->repfilters); - } -#endif -} - -/* iterate through the configured filters, applying their access tests and adding - * if appropriate */ -static void -clientBuildReplyAddFilters(filterAccessConfig * cfg, dlink_list *filter_list, - clientHttpRequest * http, HttpReply *rep) { - aclCheck_t *ch; - int rv; - filterAccess *filter; - FILTER_instance *instance; - int i = 0; - for (i = 0; i < cfg->n_configured; i++) { - filter = cfg->filters +i; - instance = filter->instance; - ch = aclChecklistCreate(filter->apply, http->request, NULL); - ch->reply = rep; - rv = aclCheckFast(filter->apply, ch); - aclChecklistFree(ch); - if (rv==1) { - debug(33,8)("\n\nAdding the filter instance %s\n\n", instance->namestr); - /* 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. - */ - instance->Add(filter_list, instance->MakeState(instance->data)); - } - } } /* @@ -1428,7 +1382,7 @@ stringClean(&strConnection); } - clientBuildReplyAddFilters(&Config.reply_filters, &http->repfilters, http, rep); + filterBuildChain(Config.reply_filters, &http->repfilters, http, rep); /* Handle Ranges */ if (request->range) @@ -2074,8 +2028,7 @@ int fd = conn->fd; HttpReply *rep = NULL; const char *body_buf = buf; - char *te_body_buf; - int body_size = size, te_body_size; + int body_size = size; unsigned int filter_flags=0; MemBuf mb; ssize_t check_size = 0; Index: squid/src/filters.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/filters.c,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/src/filters.c 3 Feb 2001 14:23:20 -0000 1.1.2.5 +++ squid/src/filters.c 4 Feb 2001 12:47:34 -0000 1.1.2.6 @@ -1,6 +1,6 @@ /* - * $Id: filters.c,v 1.1.2.5 2001/02/03 14:23:20 rbcollins Exp $ + * $Id: filters.c,v 1.1.2.6 2001/02/04 12:47:34 rbcollins Exp $ * * DEBUG: section 83 Content Processing Filters * AUTHOR: Robert Collins @@ -128,3 +128,38 @@ } return NULL; } + +/* Apply a filterAccess list to a request/resonse/reply and build the filter chain + * from that. http,rep and further parameters are optional, as long as one is + * present + * TODO: allow a filter to abort a request before any data is processed by a return code + * here. + */ +void +filterBuildChain(filterAccess *head, dlink_list *filter_list, clientHttpRequest * http, HttpReply *rep) { + aclCheck_t *ch; + int rv; + filterAccess *filter; + FILTER_instance *instance; + filter=head; + while (filter) { + instance = filter->instance; + ch = aclChecklistCreate(filter->apply, http->request, NULL); + ch->reply = rep; + rv = aclCheckFast(filter->apply, ch); + aclChecklistFree(ch); + if (rv==1) { + debug(33,8)("\n\nAdding the filter instance %s\n\n", instance->namestr); + /* 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. + */ + instance->Add(filter_list, instance->MakeState(instance->data)); + } + } +} + Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.1.1.3.8.11.2.8 retrieving revision 1.1.1.3.8.11.2.9 diff -u -r1.1.1.3.8.11.2.8 -r1.1.1.3.8.11.2.9 --- squid/src/protos.h 3 Feb 2001 14:23:20 -0000 1.1.1.3.8.11.2.8 +++ squid/src/protos.h 4 Feb 2001 12:47:34 -0000 1.1.1.3.8.11.2.9 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.8.11.2.8 2001/02/03 14:23:20 rbcollins Exp $ + * $Id: protos.h,v 1.1.1.3.8.11.2.9 2001/02/04 12:47:34 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1312,3 +1312,4 @@ extern FILTER_instance *filterInstanceByName(const char *namestr, FILTER_instance **); extern void filterRegisterModule(const char *, ADDFILTERINSTANCE *, REMFILTERINSTANCE *); extern void filterDeregisterModule(const char *); +extern void filterBuildChain(filterAccess *, dlink_list *, clientHttpRequest * , HttpReply *); 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.13 retrieving revision 1.1.1.3.4.1.4.12.2.14 diff -u -r1.1.1.3.4.1.4.12.2.13 -r1.1.1.3.4.1.4.12.2.14 --- squid/src/structs.h 3 Feb 2001 14:23:20 -0000 1.1.1.3.4.1.4.12.2.13 +++ squid/src/structs.h 4 Feb 2001 12:47:34 -0000 1.1.1.3.4.1.4.12.2.14 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.13 2001/02/03 14:23:20 rbcollins Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.14 2001/02/04 12:47:34 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -328,16 +328,11 @@ }; struct _filterAccess { + filterAccess * next; FILTER_instance *instance; acl_access *apply; }; -struct _filterAccessConfig { - filterAccess *filters; - int n_allocated; - int n_configured; -}; - #if DELAY_POOLS struct _delaySpec { int restore_bps; @@ -604,10 +599,10 @@ acl_access *reply; } accessList; acl_deny_info_list *denyInfoList; - filterAccessConfig reply_filters; - filterAccessConfig response_filters; - filterAccessConfig client_request_filters; - filterAccessConfig server_request_filters; + filterAccess *reply_filters; + filterAccess *response_filters; + filterAccess *client_request_filters; + filterAccess *server_request_filters; FILTER_instance *filters; struct _authConfig { authScheme *schemes;