--------------------- PatchSet 437 Date: 2002/12/20 19:31:54 Author: rbcollins Branch: esi Tag: (none) Log: esiProcess -> method Members: src/ESI.cc:1.1.2.52->1.1.2.53 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.52 retrieving revision 1.1.2.53 diff -u -r1.1.2.52 -r1.1.2.53 --- squid3/src/ESI.cc 20 Dec 2002 12:02:36 -0000 1.1.2.52 +++ squid3/src/ESI.cc 20 Dec 2002 19:31:54 -0000 1.1.2.53 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.52 2002/12/20 12:02:36 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.53 2002/12/20 19:31:54 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -418,7 +418,8 @@ }; /* esiContext */ -struct esiContext : public esiTreeParent { +class esiContext : public esiTreeParent { +public: void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf() const; @@ -432,6 +433,8 @@ void finishRead(); bool reading() const; void setError(); + + esiProcessResult_t process (); void addStackElement (ESIElement::Pointer element); void addLiteral (const XML_Char *s, int len); @@ -519,7 +522,6 @@ /* Local functions */ /* esiContext */ static esiContext *esiContextNew(HttpReply *, clientStreamNode *, clientHttpRequest *); -static esiProcessResult_t esiProcess (esiContext *); /* esiStreamContext */ static FREE esiStreamContextFree; static esiStreamContext *esiStreamContextNew (esiIncludePtr); @@ -624,7 +626,7 @@ /* Something has occured. Process any remaining nodes */ if (!flags.finished) /* Process some of our data */ - switch (esiProcess (this)) { + switch (process ()) { case ESI_PROCESS_COMPLETE: debug (86,5)("esiKick: esiProcess OK\n");break; case ESI_PROCESS_PENDING_WONTFAIL: @@ -1360,7 +1362,7 @@ } esiProcessResult_t -esiProcess (esiContext *context) +esiContext::process () { /* parsing: * read through buffered, skipping plain text, and skipping any @@ -1368,70 +1370,70 @@ * when it's found, hand an esiLiteral of the preceeding data to our current * context */ - if (context->flags.parsing) { + if (flags.parsing) { /* in middle of parsing - finish here */ return ESI_PROCESS_PENDING_MAYFAIL; } - assert (context->flags.finished == 0); + assert (flags.finished == 0); - if (!context->parserState.stackdepth) { + if (!parserState.stackdepth) { debug (86,5)("empty parser stack, inserting the top level node\n"); - assert (context->tree.getRaw()); - context->parserState.stack[context->parserState.stackdepth++] = context->tree; + assert (tree.getRaw()); + parserState.stack[parserState.stackdepth++] = tree; } - if (context->rep && !context->flags.parserinited) + if (rep && !flags.parserinited) { /* TODO: grab the document encoding from the headers */ - context->parserState.p = XML_ParserCreateNS(NULL,'|'); - XML_SetUserData (context->parserState.p, context); - XML_SetElementHandler(context->parserState.p, start, end); - XML_SetDefaultHandler(context->parserState.p, esiExpatDefault); - XML_SetCommentHandler(context->parserState.p, esiExpatComment); - XML_UseParserAsHandlerArg(context->parserState.p); - context->flags.parserinited = 1; + parserState.p = XML_ParserCreateNS(NULL,'|'); + XML_SetUserData (parserState.p, this); + XML_SetElementHandler(parserState.p, start, end); + XML_SetDefaultHandler(parserState.p, esiExpatDefault); + XML_SetCommentHandler(parserState.p, esiExpatComment); + XML_UseParserAsHandlerArg(parserState.p); + flags.parserinited = 1; } /* we have data */ - if (context->buffered) { - context->flags.parsing = 1; + if (buffered) { + flags.parsing = 1; /* we don't keep any data around */ PROF_start(esiParsing); - while (context->buffered) { + while (buffered) { ESISegment *temp; - if (context->buffered->len) { - if (! XML_Parse(context->parserState.p, context->buffered->buf, context->buffered->len, context->flags.finishedtemplate)) { + if (buffered->len) { + if (! XML_Parse(parserState.p, buffered->buf, buffered->len, flags.finishedtemplate)) { char tempstr[1024]; - context->setError(); + setError(); snprintf (tempstr, 1023, "esiProcess: Parse error at line %d:\n%s\n", - XML_GetCurrentLineNumber(context->parserState.p), - XML_ErrorString(XML_GetErrorCode(context->parserState.p))); + XML_GetCurrentLineNumber(parserState.p), + XML_ErrorString(XML_GetErrorCode(parserState.p))); debug (86,0)("%s", tempstr); - if (!context->errormessage) - context->errormessage = xstrdup (tempstr); + if (!errormessage) + errormessage = xstrdup (tempstr); PROF_stop(esiParsing); return ESI_PROCESS_FAILED; } - if (context->flags.error) { - context->setError(); + if (flags.error) { + setError(); PROF_stop(esiParsing); return ESI_PROCESS_FAILED; } } - temp = context->buffered; - context->buffered = temp->next; + temp = buffered; + buffered = temp->next; cbdataFree (temp); } PROF_stop(esiParsing); /* Tel the read code to allocate a new buffer */ - context->incoming = NULL; - context->flags.parsing = 0; + incoming = NULL; + flags.parsing = 0; } /* ok, we've done all we can with the data. What can we process now? @@ -1439,7 +1441,7 @@ { esiProcessResult_t status; PROF_start(esiProcessing); - status = context->tree->process(0); + status = tree->process(0); switch (status) { case ESI_PROCESS_COMPLETE: debug (86,5)("esiProcess: tree Processed OK\n"); @@ -1452,31 +1454,31 @@ break; case ESI_PROCESS_FAILED: debug (86,0)("esiProcess: tree Processed FAILED\n"); - context->setError(); - if (!context->errormessage) - context->errormessage = xstrdup("esiProcess: ESI template Processing failed."); + setError(); + if (!errormessage) + errormessage = xstrdup("esiProcess: ESI template Processing failed."); PROF_stop(esiProcessing); return ESI_PROCESS_FAILED; break; } - if (status != ESI_PROCESS_PENDING_MAYFAIL && context->flags.finishedtemplate){ + if (status != ESI_PROCESS_PENDING_MAYFAIL && flags.finishedtemplate){ /* We've read the entire template, and no nodes will * return failure */ debug (86,5)("esiProcess, request will succeed\n"); - context->flags.oktosend = 1; + flags.oktosend = 1; } - if (status == ESI_PROCESS_COMPLETE && context->flags.finishedtemplate) { + if (status == ESI_PROCESS_COMPLETE && flags.finishedtemplate) { /* we've finished all processing. Render and send. */ debug (86,5)("esiProcess, processing complete\n"); - context->flags.finished = 1; + flags.finished = 1; } - if (!context->flags.finishedtemplate && !context->incoming) { - context->incoming = context->buffered = new ESISegment; + if (!flags.finishedtemplate && !incoming) { + incoming = buffered = new ESISegment; } PROF_stop(esiProcessing); return status; /* because we have no callbacks */