--------------------- PatchSet 439 Date: 2002/12/20 19:52:26 Author: rbcollins Branch: esi Tag: (none) Log: extract some methods Members: src/ESI.cc:1.1.2.54->1.1.2.55 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.54 retrieving revision 1.1.2.55 diff -u -r1.1.2.54 -r1.1.2.55 --- squid3/src/ESI.cc 20 Dec 2002 19:42:23 -0000 1.1.2.54 +++ squid3/src/ESI.cc 20 Dec 2002 19:52:26 -0000 1.1.2.55 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.54 2002/12/20 19:42:23 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.55 2002/12/20 19:52:26 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -449,7 +449,6 @@ * because we buffer until we can not fail */ int finishedtemplate:1; /* we've read the entire template */ - int parserinited:1; int clientwantsdata:1; /* we need to satisfy a read request */ int kicked:1; /* note on reentering the kick routine */ int parsing:1; /* libexpat is not reentrant on the same context */ @@ -471,11 +470,18 @@ */ off_t readpos; /* the logical position we are reading from */ off_t pos; /* the logical position of outbound_offset in the data stream */ - struct _parserState{ + class ParserState{ + public: ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */ int stackdepth; /* self explanatory */ XML_Parser p; /* our parser */ ESIElement::Pointer top(); + void init (void *); + bool inited() const; + ParserState(); + void freeResources(); + private: + bool inited_; } parserState; /* todo factor this off somewhere else; */ esiVarState *varState; ESIElement::Pointer tree; @@ -1137,11 +1143,21 @@ } ESIElement::Pointer -esiContext::_parserState::top() +esiContext::ParserState::top() { return stack[stackdepth-1]; } +esiContext::ParserState::ParserState() : inited_ (false) +{ +} + +bool +esiContext::ParserState::inited() const +{ + return inited_; +} + void esiContext::addStackElement (ESIElement::Pointer element) { @@ -1362,6 +1378,19 @@ } void +esiContext::ParserState::init(void *userData) +{ + /* TODO: grab the document encoding from the headers */ + p = XML_ParserCreateNS(NULL,'|'); + XML_SetUserData (p, userData); + XML_SetElementHandler(p, start, end); + XML_SetDefaultHandler(p, esiExpatDefault); + XML_SetCommentHandler(p, esiExpatComment); + XML_UseParserAsHandlerArg(p); + inited_ = true; +} + +void esiContext::parse() { if (!parserState.stackdepth) { @@ -1370,16 +1399,8 @@ parserState.stack[parserState.stackdepth++] = tree; } - if (rep && !flags.parserinited) { - /* TODO: grab the document encoding from the headers */ - 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; - } + if (rep && !parserState.inited()) + parserState.init(this); /* we have data */ if (buffered) { @@ -1496,6 +1517,13 @@ } void +esiContext::ParserState::freeResources() +{ + XML_ParserFree (p); + inited_ = false; +} + +void esiContext::freeResources () { debug (86,5)("esiContext::freeResources: Freeing for this=%p\n",this); if (rep) { @@ -1503,9 +1531,8 @@ rep = NULL; } tree = NULL; - if (flags.parserinited) { - XML_ParserFree (parserState.p); - flags.parserinited = 0; + if (parserState.inited()) { + parserState.freeResources(); } ESISegmentFreeList (&buffered); ESISegmentFreeList (&outbound);