--------------------- PatchSet 115 Date: 2002/11/01 21:37:55 Author: rbcollins Branch: esi Tag: (none) Log: introduce more methods Members: src/ESI.cc:1.1.2.23->1.1.2.24 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.23 retrieving revision 1.1.2.24 diff -u -r1.1.2.23 -r1.1.2.24 --- squid3/src/ESI.cc 1 Nov 2002 17:46:55 -0000 1.1.2.23 +++ squid3/src/ESI.cc 1 Nov 2002 21:37:55 -0000 1.1.2.24 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.23 2002/11/01 17:46:55 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.24 2002/11/01 21:37:55 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -434,6 +434,12 @@ } parserState; /* todo factor this off somewhere else; */ esiVarState *varState; esiElement *tree; + static void Free(void *); + + + void fail (clientStreamNode *thisNode, clientHttpRequest *http); +private: + void freeResources(); }; CBDATA_TYPE(esiContext); @@ -449,9 +455,7 @@ /* Local functions */ /* esiContext */ -static FREE esiContextFree; static esiContext *esiContextNew(HttpReply *, clientStreamNode *, clientHttpRequest *); -static void esiContextFreeResources (esiContext *); static size_t esiSend (clientStreamNode *thisNode, esiContext *,clientHttpRequest *http); static esiProcessResult_t esiProcess (esiContext *); /* esiStreamContext */ @@ -467,7 +471,6 @@ static CSCB esiBufferRecipient; static CSD esiBufferDetach; /* static void esiStartSub (void); */ -static void esiFail (clientStreamNode *thisNode, esiContext *context, clientHttpRequest *http); static esiKick_t esiKick (esiContext *context); static void esiAddStackElement (esiContext *context, esiElement *element); @@ -505,7 +508,7 @@ * and when we come here we have sent data to the client */ if (context->pos == 0) - esiFail (context->thisNode, context, context->http); + context->fail (context->thisNode, context->http); --context->flags.kicked; return ESI_KICK_FAILED; } @@ -898,21 +901,20 @@ } void -esiContextFree(void *data) +esiContext::Free(void *data) { esiContext *context = (esiContext *)data; - esiContextFreeResources (context); - /* Not freed by freeresources because esiFail needs it */ + context->freeResources (); + /* Not freed by freeresources because esi::fail needs it */ safe_free (context->errormessage); debug (86,3)("esiContextFree: Freed %p\n", context); - return; } esiContext * esiContextNew (HttpReply *rep, clientStreamNode *thisNode, clientHttpRequest *http) { esiContext *rv; - CBDATA_INIT_TYPE_FREECB(esiContext, esiContextFree); + CBDATA_INIT_TYPE_FREECB(esiContext, esiContext::Free); rv = cbdataAlloc(esiContext); assert (rep); rv->rep = rep; @@ -1424,20 +1426,20 @@ } void -esiContextFreeResources (esiContext *context) { - if (context->rep) { - httpReplyDestroy (context->rep); - context->rep = NULL; - } - if (context->tree) - cbdataFree (context->tree); - if (context->flags.parserinited) { - XML_ParserFree (context->parserState.p); - context->flags.parserinited = 0; - } - esiSegmentFreeList (&context->buffered); - esiSegmentFreeList (&context->outbound); - cbdataFree (context->varState); +esiContext::freeResources () { + if (rep) { + httpReplyDestroy (rep); + rep = NULL; + } + if (tree) + cbdataFree (tree); + if (flags.parserinited) { + XML_ParserFree (parserState.p); + flags.parserinited = 0; + } + esiSegmentFreeList (&buffered); + esiSegmentFreeList (&outbound); + cbdataFree (varState); /* don't touch incoming, it's a pointer into buffered anyway */ } @@ -1445,51 +1447,52 @@ /* This can ONLY be used before we have sent *any* data to the client */ -void esiFail (clientStreamNode *thisNode, esiContext *context, clientHttpRequest *http) +void +esiContext::fail (clientStreamNode *thisNode, clientHttpRequest *http) { ErrorState *err; size_t errorprogress; /* check preconditions */ - assert (context->pos == 0); + assert (pos == 0); /* cleanup current state */ - esiContextFreeResources (context); + freeResources (); /* Stop altering thisNode request */ - context->flags.oktosend = 1; - context->flags.finished = 1; + flags.oktosend = 1; + flags.finished = 1; /* don't honour range requests - for errors we sent it all */ - context->flags.error = 1; + flags.error = 1; /* create an error object */ - err = clientBuildError(context->errorpage, context->errorstatus, NULL, + err = clientBuildError(errorpage, errorstatus, NULL, http->conn ? &http->conn->peer.sin_addr : &no_addr, http->request); - err->err_msg = context->errormessage; - context->errormessage = NULL; - context->rep = errorBuildReply (err); - assert (context->rep->body.mb.size >= 0); - errorprogress = context->rep->body.mb.size; + err->err_msg = errormessage; + errormessage = NULL; + rep = errorBuildReply (err); + assert (rep->body.mb.size >= 0); + errorprogress = rep->body.mb.size; /* Tell esiSend where to start sending from */ - context->outbound_offset = 0; + outbound_offset = 0; /* copy the membuf from the reply to outbound */ - while (errorprogress < (size_t)context->rep->body.mb.size) + while (errorprogress < (size_t)rep->body.mb.size) { size_t amount; - if (!context->outbound) { - context->outboundtail = context->outbound = cbdataAlloc (esiSegment); + if (!outbound) { + outboundtail = outbound = cbdataAlloc (esiSegment); } else { /* add to tail */ - assert (context->outboundtail->next == NULL); - context->outboundtail->next = cbdataAlloc (esiSegment); - context->outboundtail = context->outboundtail->next; + assert (outboundtail->next == NULL); + outboundtail->next = cbdataAlloc (esiSegment); + outboundtail = outboundtail->next; } - amount = context->rep->body.mb.size - errorprogress; + amount = rep->body.mb.size - errorprogress; if (amount > HTTP_REQBUF_SZ) amount = HTTP_REQBUF_SZ; - xmemcpy (context->outboundtail->buf, context->rep->body.mb.buf + errorprogress, amount); - context->outboundtail->len = amount; + xmemcpy (outboundtail->buf, rep->body.mb.buf + errorprogress, amount); + outboundtail->len = amount; errorprogress += amount; } /* the esiCode now thinks that the error is the outbound, and all processing has finished. */ /* Send as much as we can */ - assert (esiSend (thisNode, context, http)); + assert (esiSend (thisNode, this, http)); /* don't cancel anything. The stream nodes will clean up after * themselves when the reply is freed - and we don't know what to * clean anyway.