--------------------- PatchSet 1559 Date: 2001/02/12 13:31:24 Author: rbcollins Branch: rbcollins_filters Tag: (none) Log: store side changes to inform store clients of current store status allowing all-in-one close and writes from server side. Also offset added to the STCB, allowing for store clients to confirm they get what they asked for Members: src/asn.c:1.1.1.3.8.5.4.1->1.1.1.3.8.5.4.2 src/client_side.c:1.1.1.3.4.1.4.15.2.26->1.1.1.3.4.1.4.15.2.27 src/filters.c:1.1.2.9->1.1.2.10 src/http.c:1.1.1.3.4.1.4.12.2.12->1.1.1.3.4.1.4.12.2.13 src/protos.h:1.1.1.3.8.11.2.12->1.1.1.3.8.11.2.13 src/store.c:1.1.1.3.8.7.4.2->1.1.1.3.8.7.4.3 src/store_client.c:1.1.1.3.4.1.4.7.4.1->1.1.1.3.4.1.4.7.4.2 src/store_swapin.c:1.1.1.3.8.5.4.1->1.1.1.3.8.5.4.2 src/tools.c:1.1.1.3.8.8.2.1->1.1.1.3.8.8.2.2 src/transfer-encoding.c:1.1.2.1.2.6->1.1.2.1.2.7 src/typedefs.h:1.1.1.3.8.7.4.13->1.1.1.3.8.7.4.14 src/urn.c:1.1.1.3.8.4.4.1->1.1.1.3.8.4.4.2 src/modules/htmldemo/htmldemo.c:1.1.2.6->1.1.2.7 src/modules/spy/spy.c:1.1.2.6->1.1.2.7 src/modules/textreplace/textreplace.c:1.1.2.11->1.1.2.12 Index: squid/src/asn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/asn.c,v retrieving revision 1.1.1.3.8.5.4.1 retrieving revision 1.1.1.3.8.5.4.2 diff -u -r1.1.1.3.8.5.4.1 -r1.1.1.3.8.5.4.2 --- squid/src/asn.c 5 Feb 2001 13:37:10 -0000 1.1.1.3.8.5.4.1 +++ squid/src/asn.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.5.4.2 @@ -1,6 +1,6 @@ /* - * $Id: asn.c,v 1.1.1.3.8.5.4.1 2001/02/05 13:37:10 rbcollins Exp $ + * $Id: asn.c,v 1.1.1.3.8.5.4.2 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis @@ -219,7 +219,7 @@ } static void -asHandleReply(void *data, char *buf, ssize_t size) +asHandleReply(void *data, char *buf, ssize_t size, size_t offset, unsigned int flags) { ASState *asState = data; StoreEntry *e = asState->entry; 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.26 retrieving revision 1.1.1.3.4.1.4.15.2.27 diff -u -r1.1.1.3.4.1.4.15.2.26 -r1.1.1.3.4.1.4.15.2.27 --- squid/src/client_side.c 8 Feb 2001 08:18:22 -0000 1.1.1.3.4.1.4.15.2.26 +++ squid/src/client_side.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.4.1.4.15.2.27 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.26 2001/02/08 08:18:22 rbcollins Exp $ + * $Id: client_side.c,v 1.1.1.3.4.1.4.15.2.27 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -449,7 +449,7 @@ static void -clientHandleIMSReply(void *data, char *buf, ssize_t size) +clientHandleIMSReply(void *data, char *buf, ssize_t size, size_t offset, unsigned int flags) { clientHttpRequest *http = data; StoreEntry *entry = http->entry; @@ -515,6 +515,7 @@ * www.thegist.com (Netscape/1.13) returns a content-length for * 304's which seems to be the length of the 304 HEADERS!!! and * not the body they refer to. */ + /* RBC: Note that 304's are NOT ALLOWED a BODY. */ httpReplyUpdateOnNotModified(oldentry->mem_obj->reply, mem->reply); storeTimestampsSet(oldentry); storeUnregister(http->sc, entry, http); @@ -551,7 +552,7 @@ clientSendMoreData, http); } else { - clientSendMoreData(data, buf, size); + clientSendMoreData(data, buf, size, offset, flags); } } @@ -775,13 +776,7 @@ } if (http->acl_checklist) aclChecklistFree(http->acl_checklist); -#if 0 - while (http->te_translations) { - TE_list *tf = http->te_translations; - http->te_translations = http->te_translations->next; - xfree (tf); - } -#endif + filterCleanChain(&http->repfilters); if (request) checkFailureRatio(request->err_type, http->al.hier.code); safe_free(http->uri); @@ -1193,7 +1188,6 @@ } else { const int spec_count = http->request->range->specs.count; int actual_clen = -1; - FILTER_list *temp_filter; debug(33, 3) ("clientBuildRangeHeader: range spec count: %d virgin clen: %d\n", spec_count, rep->content_length); @@ -1234,11 +1228,7 @@ httpStatusLineSet(&rep->sline, rep->sline.version, HTTP_PARTIAL_CONTENT, NULL); /* add the ranges filter to the list */ - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=clientDoRangeReply; - temp_filter->data=http; - /* cbDataLock(http); ? */ - dlinkAddTail(temp_filter, &temp_filter->node, &http->repfilters); + filterChainAddTail(&http->repfilters,clientDoRangeReply, NULL,http); } } @@ -1332,15 +1322,9 @@ HttpHeader *hdr = &rep->header; int is_hit = isTcpHit(http->log_type); request_t *request = http->request; - FILTER_list *temp_filter; /* add the header check & forward filter */ - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=clientWriteReplyHeaders; - temp_filter->Remove=NULL; - temp_filter->data=http; - /* cbDataLock(http); ? */ - dlinkAdd(temp_filter, &temp_filter->node, &http->repfilters); + filterChainAdd(&http->repfilters,clientWriteReplyHeaders,NULL,http); #if DONT_FILTER_THESE @@ -1465,7 +1449,6 @@ clientBuildReply(clientHttpRequest * http, const char *buf, size_t size) { HttpReply *rep = httpReplyCreate(); - FILTER_list *temp_filter; /* why are we parsing this again ? */ /* we should be given a oldreply with the upstream headers already parsed, * connection header processed, etc etc */ @@ -1476,12 +1459,7 @@ /* build reply header & install filters */ clientBuildReplyHeader(http, rep); /* add the terminating filter */ - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=clientDoCommWriteMemBuf; - temp_filter->Remove=NULL; - temp_filter->data=http; - /* cbDataLock(http); ? */ - dlinkAddTail(temp_filter, &temp_filter->node, &http->repfilters); + filterChainAddTail(&http->repfilters,clientDoCommWriteMemBuf,NULL,http); } else { /* parsing failure, get rid of the invalid reply */ httpReplyDestroy(rep); @@ -1503,7 +1481,7 @@ * clientProcessMiss. */ static void -clientCacheHit(void *data, char *buf, ssize_t size) +clientCacheHit(void *data, char *buf, ssize_t size, size_t offset, unsigned int flags) { clientHttpRequest *http = data; StoreEntry *e = http->entry; @@ -1560,7 +1538,7 @@ assert(http->log_type == LOG_TCP_HIT); if (checkNegativeHit(e)) { http->log_type = LOG_TCP_NEGATIVE_HIT; - clientSendMoreData(data, buf, size); + clientSendMoreData(data, buf, size, offset, flags); } else if (r->method == METHOD_HEAD) { /* * RFC 2068 seems to indicate there is no "conditional HEAD" @@ -1569,7 +1547,7 @@ */ if (e->mem_status == IN_MEMORY) http->log_type = LOG_TCP_MEM_HIT; - clientSendMoreData(data, buf, size); + clientSendMoreData(data, buf, size, offset, flags); } else if (refreshCheckHTTP(e, r) && !http->flags.internal) { debug(33, 5) ("clientCacheHit: in refreshCheck() block\n"); /* @@ -1625,7 +1603,7 @@ clientProcessMiss(http); } else if (modifiedSince(e, http->request)) { http->log_type = LOG_TCP_IMS_HIT; - clientSendMoreData(data, buf, size); + clientSendMoreData(data, buf, size, offset, flags); } else { time_t timestamp = e->timestamp; MemBuf mb = httpPacked304Reply(e->mem_obj->reply); @@ -1654,7 +1632,7 @@ http->log_type = LOG_TCP_MEM_HIT; else if (Config.onoff.offline) http->log_type = LOG_TCP_OFFLINE_HIT; - clientSendMoreData(data, buf, size); + clientSendMoreData(data, buf, size, offset, flags); } } @@ -1968,7 +1946,7 @@ * such, calls filter init routines, and then calls the filters. */ static void -clientSendMoreData(void *data, char *buf, ssize_t size) +clientSendMoreData(void *data, char *buf, ssize_t size, size_t offset, unsigned int flags) { clientHttpRequest *http = data; StoreEntry *entry = http->entry; @@ -2022,7 +2000,7 @@ if (http->repfilters.head != NULL) { FILTER_list *temp_filter; temp_filter=http->repfilters.head->data; - temp_filter->filter(NULL, 0, 0, &http->repfilters, temp_filter, filter_flags | FILTER_EOF, temp_filter->data); + temp_filter->filter(NULL, 0, http->out.offset, &http->repfilters, temp_filter, filter_flags | FILTER_EOF, temp_filter->data); } else clientWriteComplete(fd, NULL, 0, COMM_OK, http); memFree(buf, MEM_CLIENT_SOCK_BUF); @@ -2048,29 +2026,7 @@ * so the error doesn't get handled twice! */ ErrorState *err; - { - /* remove any installed filters */ - dlink_node *link,*tmplink; - link=http->repfilters.head; - while (link) { - tmplink=link; - link=link->next; - 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); - } - } - } -#if 0 - while (http->te_translations) { - TE_list *tf = http->te_translations; - http->te_translations = http->te_translations->next; - xfree (tf); - } -#endif + filterCleanChain(&http->repfilters); err = errorCon(ERR_TOO_BIG, HTTP_FORBIDDEN); err->request = requestLink(http->request); storeUnregister(http->sc, http->entry, http); @@ -2109,26 +2065,10 @@ * coincidentally, is the most common acl for reply access lists */ ErrorState *err; - /* the following two list removals deal - * wuth resetting the dynamically attached code modules + /* reset the dynamically attached code modules * so the error doesn't get handled twice! */ - { - /* remove any installed filters */ - dlink_node *link,*tmplink; - link=http->repfilters.head; - while (link) { - tmplink=link; - link=link->next; - 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); - } - } - } + filterCleanChain(&http->repfilters); debug(33,8)("********* DENYING ACCESSS ************\n"); assert(http->repfilters.head==NULL); err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN); @@ -2249,7 +2189,7 @@ filter_flags |= FILTER_EOF; assert(http->repfilters.head != NULL); temp_filter=http->repfilters.head->data; - temp_filter->filter(body_buf, body_size, 0, &http->repfilters, temp_filter, filter_flags, temp_filter->data); + temp_filter->filter(body_buf, body_size, http->out.offset-body_size, &http->repfilters, temp_filter, filter_flags, temp_filter->data); #if 0 http->out.offset+=body_size; #endif @@ -2446,9 +2386,6 @@ } else { /* More data will be coming from primary server; register with * storage manager. */ -#if 0 - http->oldte_rv = 0x00; -#endif if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) debug(33, 0) ("clientWriteComplete 2: ENTRY_ABORTED\n"); storeClientCopy(http->sc, entry, Index: squid/src/filters.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/filters.c,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- squid/src/filters.c 5 Feb 2001 12:10:13 -0000 1.1.2.9 +++ squid/src/filters.c 12 Feb 2001 13:31:24 -0000 1.1.2.10 @@ -1,6 +1,6 @@ /* - * $Id: filters.c,v 1.1.2.9 2001/02/05 12:10:13 rbcollins Exp $ + * $Id: filters.c,v 1.1.2.10 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 83 Content Processing Filters * AUTHOR: Robert Collins @@ -166,3 +166,50 @@ filter=filter->next; } } + +/* clean up a filter chain, ready for reuse */ +void +filterCleanChain(dlink_list *filter_list) { + /* remove any installed filters */ + dlink_node *link,*tmplink; + FILTER_list *temp_filter; + link=filter_list->head; + while (link) { + tmplink=link; + link=link->next; + temp_filter=tmplink->data; + if (temp_filter->Remove) + temp_filter->Remove(temp_filter, filter_list, temp_filter->data); + else { + dlinkDelete(tmplink, filter_list); + xfree(tmplink->data); + } + } +} + +/* Add a filter to a filter chain. */ +void +filterChainAdd(dlink_list *filter_list, DATAFILTER *filter, REMOVEFILTER *Remove, void *data) { + FILTER_list *temp_filter; + /* add the header check & forward filter */ + temp_filter=xmalloc(sizeof(FILTER_list)); + temp_filter->filter=filter; + temp_filter->Remove=Remove; + /* if this is to be locked, the caller does that */ + temp_filter->data=data; + dlinkAdd(temp_filter, &temp_filter->node, filter_list); +} + + +/* Add a filter to a filter chain at the end of the chain */ +void +filterChainAddTail(dlink_list *filter_list, DATAFILTER *filter, REMOVEFILTER *Remove, void *data) { + FILTER_list *temp_filter; + /* add the header check & forward filter */ + temp_filter=xmalloc(sizeof(FILTER_list)); + temp_filter->filter=filter; + temp_filter->Remove=Remove; + /* if this is to be locked, the caller does that */ + temp_filter->data=data; + dlinkAddTail(temp_filter, &temp_filter->node, filter_list); +} Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,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/http.c 8 Feb 2001 08:18:22 -0000 1.1.1.3.4.1.4.12.2.12 +++ squid/src/http.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.4.1.4.12.2.13 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.1.1.3.4.1.4.12.2.12 2001/02/08 08:18:22 rbcollins Exp $ + * $Id: http.c,v 1.1.1.3.4.1.4.12.2.13 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -64,7 +64,7 @@ #endif if (httpState == NULL) return; - /* TODO free the filter chain here */ + filterCleanChain(&httpState->filters); storeUnlockObject(httpState->entry); if (httpState->reply_hdr) { memFree(httpState->reply_hdr, MEM_8K_BUF); @@ -565,6 +565,7 @@ httpState->eof = 1; comm_close(fd); #if 0 + /* this isn;t needed anymore because its just a special case of filter response */ } else if (len == 0) { unsigned int rvflags=0; /* TODO: this is broken: if this was a persistent connection, EOF can mean @@ -667,22 +668,14 @@ http_status s = entry->mem_obj->reply->sline.status; te_build_decode_xlate_list(&entry->mem_obj->reply->header, &httpState->filters); /* test for EOF condition (has to happen after content decoding! */ - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=httpPconnTransferDone; - temp_filter->data=httpState; - /* cbDataLock(httpState); ? */ - dlinkAddTail(temp_filter, &temp_filter->node, &httpState->filters); + filterChainAddTail(&httpState->filters,httpPconnTransferDone,NULL,httpState); /* apply user configured filters */ filterBuildChain(Config.response_filters, &httpState->filters, NULL, entry->mem_obj->reply , request); /* Send the data to the store manager */ - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=httpDoAppend; - temp_filter->data=httpState; - /* cbDataLock(httpState); ? */ - dlinkAddTail(temp_filter, &temp_filter->node, &httpState->filters); + filterChainAddTail(&httpState->filters,httpDoAppend,NULL,httpState); #if WIP_FWD_LOG fwdStatus(httpState->fwd, s); #endif Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.1.1.3.8.11.2.12 retrieving revision 1.1.1.3.8.11.2.13 diff -u -r1.1.1.3.8.11.2.12 -r1.1.1.3.8.11.2.13 --- squid/src/protos.h 8 Feb 2001 08:18:22 -0000 1.1.1.3.8.11.2.12 +++ squid/src/protos.h 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.11.2.13 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.8.11.2.12 2001/02/08 08:18:22 rbcollins Exp $ + * $Id: protos.h,v 1.1.1.3.8.11.2.13 2001/02/12 13:31:24 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1033,6 +1033,7 @@ extern store_client *storeClientListAdd(StoreEntry * e, void *data); extern void storeClientCopy(store_client *, StoreEntry *, off_t, off_t, size_t, char *, STCB *, void *); extern int storeClientCopyPending(store_client *, StoreEntry * e, void *data); +extern void storeClientCopyHeaders(store_client *, StoreEntry *, STHCB *, void *); extern int storeUnregister(store_client * sc, StoreEntry * e, void *data); extern off_t storeLowestMemReaderOffset(const StoreEntry * entry); extern void InvokeHandlers(StoreEntry * e); @@ -1130,6 +1131,7 @@ extern void dlinkDelete(dlink_node * m, dlink_list * list); extern void dlinkNodeDelete(dlink_node * m); extern dlink_node *dlinkNodeNew(); +extern void dlinkJoinHeadTail(dlink_list *, dlink_list *); extern void kb_incr(kb_t *, size_t); extern double gb_to_double(const gb_t *); @@ -1315,3 +1317,6 @@ extern void filterRegisterModule(const char *, ADDFILTERINSTANCE *, REMFILTERINSTANCE *); extern void filterDeregisterModule(const char *); extern void filterBuildChain(filterAccess *, dlink_list *, clientHttpRequest * , HttpReply *, request_t *); +extern void filterCleanChain(dlink_list *); +extern void filterChainAdd(dlink_list *, DATAFILTER *, REMOVEFILTER *, void *); +extern void filterChainAddTail(dlink_list *, DATAFILTER *, REMOVEFILTER *, void *); Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.1.1.3.8.7.4.2 retrieving revision 1.1.1.3.8.7.4.3 diff -u -r1.1.1.3.8.7.4.2 -r1.1.1.3.8.7.4.3 --- squid/src/store.c 8 Feb 2001 08:18:22 -0000 1.1.1.3.8.7.4.2 +++ squid/src/store.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.7.4.3 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.1.1.3.8.7.4.2 2001/02/08 08:18:22 rbcollins Exp $ + * $Id: store.c,v 1.1.1.3.8.7.4.3 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -447,6 +447,7 @@ } /* Append incoming data from a primary server to an entry. */ +/* TODO: write position field */ void storeAppend(StoreEntry * e, const char *buf, int len, unsigned int flags) { @@ -1231,6 +1232,7 @@ httpReplyDestroy(mem->reply); mem->reply = httpReplyCreate(); e->expires = e->lastmod = e->timestamp = -1; + e->store_status = STORE_PENDING; } /* Index: squid/src/store_client.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_client.c,v retrieving revision 1.1.1.3.4.1.4.7.4.1 retrieving revision 1.1.1.3.4.1.4.7.4.2 diff -u -r1.1.1.3.4.1.4.7.4.1 -r1.1.1.3.4.1.4.7.4.2 --- squid/src/store_client.c 5 Feb 2001 13:37:34 -0000 1.1.1.3.4.1.4.7.4.1 +++ squid/src/store_client.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.4.1.4.7.4.2 @@ -1,6 +1,6 @@ /* - * $Id: store_client.c,v 1.1.1.3.4.1.4.7.4.1 2001/02/05 13:37:34 rbcollins Exp $ + * $Id: store_client.c,v 1.1.1.3.4.1.4.7.4.2 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 20 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -157,11 +157,14 @@ { STCB *callback = sc->callback; char *buf = sc->copy_buf; + unsigned int flags; assert(sc->callback); sc->callback = NULL; sc->copy_buf = NULL; + /* TODO: test for abort and EOF and set in flags here */ + flags = 0; if (cbdataValid(sc->callback_data)) - callback(sc->callback_data, buf, sz); + callback(sc->callback_data, buf, sz, sc->copy_offset, flags); } static void Index: squid/src/store_swapin.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_swapin.c,v retrieving revision 1.1.1.3.8.5.4.1 retrieving revision 1.1.1.3.8.5.4.2 diff -u -r1.1.1.3.8.5.4.1 -r1.1.1.3.8.5.4.2 --- squid/src/store_swapin.c 5 Feb 2001 13:37:34 -0000 1.1.1.3.8.5.4.1 +++ squid/src/store_swapin.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.5.4.2 @@ -1,6 +1,6 @@ /* - * $Id: store_swapin.c,v 1.1.1.3.8.5.4.1 2001/02/05 13:37:34 rbcollins Exp $ + * $Id: store_swapin.c,v 1.1.1.3.8.5.4.2 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 20 Storage Manager Swapin Functions * AUTHOR: Duane Wessels @@ -78,7 +78,7 @@ if ((callback = sc->callback)) { assert(errflag <= 0); sc->callback = NULL; - callback(sc->callback_data, sc->copy_buf, errflag); + callback(sc->callback_data, sc->copy_buf, errflag, -1, FILTER_ABORT); } statCounter.swap.ins++; } Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.1.1.3.8.8.2.1 retrieving revision 1.1.1.3.8.8.2.2 diff -u -r1.1.1.3.8.8.2.1 -r1.1.1.3.8.8.2.2 --- squid/src/tools.c 5 Feb 2001 13:37:34 -0000 1.1.1.3.8.8.2.1 +++ squid/src/tools.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.8.2.2 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.1.1.3.8.8.2.1 2001/02/05 13:37:34 rbcollins Exp $ + * $Id: tools.c,v 1.1.1.3.8.8.2.2 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -823,6 +823,18 @@ } void +dlinkJoinHeadTail(dlink_list *from, dlink_list *to) { + dlink_node *temp_node, *temp_node2; + temp_node=from->head; + while (temp_node) { + temp_node2=temp_node->next; + dlinkDelete(temp_node,from); + dlinkAddTail(temp_node->data,temp_node,to); + temp_node=temp_node2; + } +} + +void kb_incr(kb_t * k, size_t v) { k->bytes += v; Index: squid/src/transfer-encoding.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/transfer-encoding.c,v retrieving revision 1.1.2.1.2.6 retrieving revision 1.1.2.1.2.7 diff -u -r1.1.2.1.2.6 -r1.1.2.1.2.7 --- squid/src/transfer-encoding.c 8 Feb 2001 08:18:22 -0000 1.1.2.1.2.6 +++ squid/src/transfer-encoding.c 12 Feb 2001 13:31:24 -0000 1.1.2.1.2.7 @@ -115,9 +115,11 @@ FILTER_list *temp_filter; /* are we going to have more that 17 characters in the hex length? unlikely*/ LOCAL_ARRAY(char, tempbuf,20); + dochunk_state *state=data; unsigned int rvflags=0; + size_t templen; - debug (82,8)("dochunked: Beginning\n"); + debug (82,8)("dochunked: Beginning len %d off %d flags %d\n",len,offset,flags); temp_filter=filters->node.next->data; if (flags & FILTER_HTTP_HEADER) { /* skip the header packet - we don't care about it */ @@ -125,19 +127,22 @@ return temp_filter->filter(buf,len, offset,filter_list, temp_filter, flags, temp_filter->data); } - if (buf) { snprintf (tempbuf,sizeof(tempbuf)-1,"%X\r\n", len); /* TODO: test for strlen(tempbuf)filter(tempbuf, strlen(tempbuf), offset,filter_list, temp_filter, flags & !FILTER_EOF, temp_filter->data); + debug(82, 8) ("dochunked: creating chunk of %d, offset %d\n", len,offset); + rvflags |= temp_filter->filter(tempbuf, templen=strlen(tempbuf), state->write_offset,filter_list, temp_filter, flags & !FILTER_EOF, temp_filter->data); + state->write_offset+=templen; if (rvflags & FILTER_ABORT) return rvflags; - rvflags |= temp_filter->filter(buf,len, offset,filter_list, temp_filter, flags & !FILTER_EOF, temp_filter->data); + rvflags |= temp_filter->filter(buf,len, state->write_offset,filter_list, temp_filter, flags & !FILTER_EOF, temp_filter->data); + state->read_offset+=len; + state->write_offset+=len; if (rvflags & FILTER_ABORT) return rvflags; - rvflags |= temp_filter->filter("\r\n",2, offset,filter_list ,temp_filter, flags & !FILTER_EOF, temp_filter->data); + rvflags |= temp_filter->filter("\r\n",2, state->write_offset,filter_list ,temp_filter, flags & !FILTER_EOF, temp_filter->data); + state->write_offset+=2; if (rvflags & FILTER_ABORT) return rvflags; } @@ -145,8 +150,9 @@ if ((flags & FILTER_EOF) || !buf) { /* write terminating 0 */ debug(82, 8) ("dochunked: creating termination chunk\n"); - rvflags |= temp_filter->filter("0\r\n\r\n",5, offset,filter_list, temp_filter, flags | FILTER_EOF, temp_filter->data); + rvflags |= temp_filter->filter("0\r\n\r\n",5, state->write_offset,filter_list, temp_filter, flags | FILTER_EOF, temp_filter->data); rvflags |= FILTER_EOF; + state->write_offset+=5; } debug(82,8)("dochunked: FINISHED\n"); return rvflags; @@ -351,27 +357,6 @@ } void -new_xlat (dlink_list *filter_list, int beg_or_end, - DATAFILTER *codec, REMOVEFILTER *Remove, - void *data) -{ - FILTER_list *temp_filter; - - temp_filter=xmalloc(sizeof(FILTER_list)); - temp_filter->filter=codec; - temp_filter->Remove=Remove; - temp_filter->data=data; - - if (beg_or_end == 0) - /* beginning */ - dlinkAdd(temp_filter, &temp_filter->node, filter_list); - else - /* end */ - dlinkAddTail(temp_filter, &temp_filter->node, filter_list); - return; -} - -void te_build_decode_xlate_list(HttpHeader * hdr, dlink_list *filter_list) { String s_transfer_encoding; @@ -379,7 +364,6 @@ const char *item; int y; dlink_list temp_list; - dlink_node *temp_node,*temp_node2; chunked_t *state; temp_list.head=NULL; temp_list.tail=NULL; @@ -401,7 +385,7 @@ state->state=1; state->read_offset=0; state->write_offset=0; - new_xlat(&temp_list, 0, undochunked, undochunked_remove, state); + filterChainAdd(&temp_list,undochunked,undochunked_remove,state); } @@ -410,13 +394,7 @@ } /* we've handles the incoming transfer encoding types */ /* transfer the filters from our temporary list to the request/reply list */ - temp_node=temp_list.head; - while (temp_node) { - temp_node2=temp_node->next; - dlinkDelete(temp_node,&temp_list); - dlinkAddTail(temp_node->data,temp_node,filter_list); - temp_node=temp_node2; - } + dlinkJoinHeadTail(&temp_list, filter_list); /* now we remove tansfer-encoding from the connection header */ /* handle Connection header */ if (httpHeaderHas(hdr, HDR_CONNECTION)) { @@ -450,7 +428,6 @@ { String s_te; dlink_list temp_list; - dlink_node *temp_node,*temp_node2; dochunk_state *state; temp_list.head=NULL; @@ -483,7 +460,7 @@ state=xmalloc(sizeof(dochunk_state)); state->read_offset=0; state->write_offset=0; - new_xlat(&temp_list, 1, dochunked, dochunked_remove, state); + filterChainAddTail(&temp_list,dochunked,dochunked_remove,state); strcat(vlb, "chunked"); httpHeaderPutStr(hdr, HDR_TRANSFER_ENCODING, vlb); httpHeaderDelById(hdr, HDR_CONTENT_LENGTH); @@ -500,11 +477,5 @@ /* add transfer-encoding to the connection header */ /* transfer the filters from our temporary list to the request/reply list */ - temp_node=temp_list.head; - while (temp_node) { - temp_node2=temp_node->next; - dlinkDelete(temp_node,&temp_list); - dlinkAddTail(temp_node->data,temp_node,filter_list); - temp_node=temp_node2; - } + dlinkJoinHeadTail(&temp_list, filter_list); } Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.1.1.3.8.7.4.13 retrieving revision 1.1.1.3.8.7.4.14 diff -u -r1.1.1.3.8.7.4.13 -r1.1.1.3.8.7.4.14 --- squid/src/typedefs.h 8 Feb 2001 08:18:22 -0000 1.1.1.3.8.7.4.13 +++ squid/src/typedefs.h 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.7.4.14 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.1.1.3.8.7.4.13 2001/02/08 08:18:22 rbcollins Exp $ + * $Id: typedefs.h,v 1.1.1.3.8.7.4.14 2001/02/12 13:31:24 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -236,7 +236,8 @@ typedef void SIH(storeIOState *, void *); /* swap in */ typedef int QS(const void *, const void *); /* qsort */ -typedef void STCB(void *, char *, ssize_t); /* store callback */ +typedef void STCB(void *, char *, ssize_t, size_t, unsigned int); /* store callback */ +typedef void STHCB(void *); typedef void STABH(void *); typedef void ERCB(int fd, void *, size_t); typedef void OBJH(StoreEntry *); Index: squid/src/urn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/urn.c,v retrieving revision 1.1.1.3.8.4.4.1 retrieving revision 1.1.1.3.8.4.4.2 diff -u -r1.1.1.3.8.4.4.1 -r1.1.1.3.8.4.4.2 --- squid/src/urn.c 5 Feb 2001 13:37:34 -0000 1.1.1.3.8.4.4.1 +++ squid/src/urn.c 12 Feb 2001 13:31:24 -0000 1.1.1.3.8.4.4.2 @@ -1,6 +1,6 @@ /* - * $Id: urn.c,v 1.1.1.3.8.4.4.1 2001/02/05 13:37:34 rbcollins Exp $ + * $Id: urn.c,v 1.1.1.3.8.4.4.2 2001/02/12 13:31:24 rbcollins Exp $ * * DEBUG: section 52 URN Parsing * AUTHOR: Kostas Anagnostakis @@ -171,7 +171,7 @@ } static void -urnHandleReply(void *data, char *buf, ssize_t size) +urnHandleReply(void *data, char *buf, ssize_t size, size_t offset, unsigned int flags) { UrnState *urnState = data; StoreEntry *e = urnState->entry; 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.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid/src/modules/htmldemo/htmldemo.c 8 Feb 2001 08:18:23 -0000 1.1.2.6 +++ squid/src/modules/htmldemo/htmldemo.c 12 Feb 2001 13:31:25 -0000 1.1.2.7 @@ -91,6 +91,8 @@ static void HtmlDemo_Add(dlink_list *filters, void *filter_config) { + filterChainAddTail(filters,HtmlDemo_Filter,htmldemo_Remove,filter_config); +#if 0 FILTER_list *temp_filter; temp_filter=xmalloc(sizeof(FILTER_list)); temp_filter->filter=HtmlDemo_Filter; @@ -98,6 +100,7 @@ temp_filter->data=filter_config; /* cbDataLock(http); ? */ dlinkAddTail(temp_filter, &temp_filter->node, filters); +#endif } static void * 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.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid/src/modules/spy/spy.c 8 Feb 2001 08:18:23 -0000 1.1.2.6 +++ squid/src/modules/spy/spy.c 12 Feb 2001 13:31:25 -0000 1.1.2.7 @@ -1,6 +1,6 @@ /* - * $Id: spy.c,v 1.1.2.6 2001/02/08 08:18:23 rbcollins Exp $ + * $Id: spy.c,v 1.1.2.7 2001/02/12 13:31:25 rbcollins Exp $ * * DEBUG: section 83 Content Processing Filters * AUTHOR: Robert Collins @@ -71,6 +71,8 @@ static void SpyFilter_Add (dlink_list * filters, void *filter_config) { + filterChainAddTail(filters,SpyFilter,SpyFilter_Remove,filter_config); +#if 0 FILTER_list *temp_filter; temp_filter = xmalloc (sizeof (FILTER_list)); temp_filter->filter = SpyFilter; @@ -78,6 +80,7 @@ temp_filter->data = filter_config; /* cbDataLock(http); ? */ dlinkAddTail (temp_filter, &temp_filter->node, filters); +#endif } 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.11 retrieving revision 1.1.2.12 diff -u -r1.1.2.11 -r1.1.2.12 --- squid/src/modules/textreplace/textreplace.c 8 Feb 2001 08:18:23 -0000 1.1.2.11 +++ squid/src/modules/textreplace/textreplace.c 12 Feb 2001 13:31:25 -0000 1.1.2.12 @@ -1,6 +1,6 @@ /* - * $Id: textreplace.c,v 1.1.2.11 2001/02/08 08:18:23 rbcollins Exp $ + * $Id: textreplace.c,v 1.1.2.12 2001/02/12 13:31:25 rbcollins Exp $ * * DEBUG: section 83 Content Processing Filters * AUTHOR: Robert Collins @@ -44,7 +44,7 @@ /* allow for searching across buffer breaks */ /* not implemented just yet :] */ char *pos; - size_t seen; + size_t read_offset,write_offset; }; struct _onunloadcfg { @@ -101,13 +101,7 @@ static void clientFilterOnUnload_Add (dlink_list * filters, void *filter_config) { - FILTER_list *temp_filter; - temp_filter = xmalloc (sizeof (FILTER_list)); - temp_filter->filter = clientFilterOnUnload; - temp_filter->Remove = clientFilterOnUnload_Remove; - temp_filter->data = filter_config; - /* cbDataLock(http); ? */ - dlinkAddTail (temp_filter, &temp_filter->node, filters); + filterChainAddTail(filters,clientFilterOnUnload,clientFilterOnUnload_Remove,filter_config); } static void * @@ -124,7 +118,8 @@ state->config = xmalloc (sizeof (OnUnloadConfig)); state->config->searchstring = xstrdup (config->searchstring); state->config->replace = xstrdup (config->replace); - state->seen = 0; + state->read_offset = 0; + state->write_offset = 0; return state; } @@ -176,7 +171,6 @@ filterDeregisterModule(namestr); } - char * strnchr (const char *str, char chr, size_t len) { @@ -191,14 +185,8 @@ return NULL; } -#if 0 -static void -clientFilterOnUnload (const char *buf, size_t len, dlink_list * filter_list, - FILTER_list * filters, unsigned int flags, void *data) -#endif DATAFILTER_FILTER(clientFilterOnUnload) { -#define pattern "onunload.*\".*\"" FILTER_list *temp_filter; OnUnloadState *state = data; OnUnloadConfig *config = state->config; @@ -208,22 +196,22 @@ strlen (config->searchstring); unsigned int rvflags=0; - /* this looks for browser DOM handlers of the type onunload="..." and - * removes them from the data passed to the client + /* this looks for string patterns within a buffer and replaces them with another + * arbitrary pattern * caveats and problems: * 1. theres probably a set of library functions for matching patterns at arbitrary * places in a datastream (ie handles buffer edge issues, optimum search patterns * and the like. Well this is a proof of concept filter - live with it :-] * 2. Some code may not quote the handler properly. I haven't tried to build * a full blown parser here - see 1. - * - * 3. I'm making use of the properties of the fixed search string to simplify - * the search. IT IS NOT GENERAL PURPOSE + * repeating partial matches and sub matches are not supported. This is a monotonic + * search. */ temp_filter = filters->node.next->data; - state->seen += len; - if (state->seen == len) + debug(33,8)("textreplacefilter: len %d off %d flags %d expected offset %d\n", + len,offset,flags,state->read_offset); + if (flags & FILTER_HTTP_HEADER) { /* skip the header packet - we don't care about it */ debug (33, 8) ("clientFilterOnUnload: skipping header block\n"); @@ -231,15 +219,24 @@ temp_filter->data); } + if (flags & FILTER_ABORT) { + debug (33, 8) ("clientFilterOnUnload: abort\n"); + rvflags = temp_filter->filter (NULL, 0, state->write_offset, filter_list, + temp_filter, flags, temp_filter->data); + return rvflags; + } + if (!buf) { - /* called with no buffer - legacy EOF indicator */ - debug (33, 8) ("clientFilterOnUnload: EOF via empty block\n"); - rvflags = temp_filter->filter (NULL, 0, offset, filter_list, temp_filter, flags, - temp_filter->data); - if (rvflags & FILTER_ABORT) + /* we don't buffer our output, so on a empty EOF, just pass it on dude */ + rvflags = temp_filter->filter (NULL, 0, offset, filter_list, + temp_filter, flags, temp_filter->data); return rvflags; } + + if (offset !=state->read_offset) + debug(33,8)("textreplace NON Contiguous data recievied. **************\n"); + state->read_offset+=len; startpos=buf; chr = searchstring; pos = 0; @@ -256,21 +253,25 @@ } if (pos - buf >= len) { /* end of data */ - return temp_filter->filter (lastmatch, len - (lastmatch - buf), - offset, filter_list, temp_filter, flags, - temp_filter->data); + rvflags |= temp_filter->filter (lastmatch, len - (lastmatch - buf), + state->write_offset, filter_list, + temp_filter, flags, temp_filter->data); + state->write_offset += len - (lastmatch - buf); + return rvflags; } if (*chr == '\0') { /* end of search string - we've got a match */ /* send the first set of data */ if (startpos - lastmatch) temp_filter->filter (lastmatch, startpos - lastmatch, - offset, filter_list, temp_filter, flags & !FILTER_EOF, - temp_filter->data); + state->write_offset, filter_list, temp_filter, + flags & !FILTER_EOF, temp_filter->data); + state->write_offset+=startpos - lastmatch; /* send the filter set of data */ temp_filter->filter (config->replace, replacelen, - offset, filter_list, temp_filter, flags & !FILTER_EOF, - temp_filter->data); + state->write_offset, filter_list, temp_filter, + flags & !FILTER_EOF, temp_filter->data); + state->write_offset+=replacelen; lastmatch = startpos + searchlen; /* update the pointers */ startpos = pos; @@ -298,6 +299,8 @@ } if (len- (lastmatch-buf)) /* found nothing */ - return temp_filter->filter(lastmatch,len - (lastmatch-buf) , offset, filter_list, temp_filter, flags, temp_filter->data); + rvflags |= temp_filter->filter(lastmatch,len - (lastmatch-buf) , + state->write_offset, filter_list, temp_filter, flags, temp_filter->data); + state->write_offset+=len - (lastmatch-buf); return rvflags; }