--------------------- PatchSet 93 Date: 2002/11/01 00:34:41 Author: rbcollins Branch: esi Tag: (none) Log: towards C++ for render() Members: src/ESI.cc:1.1.2.2->1.1.2.3 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/src/ESI.cc 31 Oct 2002 23:53:23 -0000 1.1.2.2 +++ squid3/src/ESI.cc 1 Nov 2002 00:34:41 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.2 2002/10/31 23:53:23 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.3 2002/11/01 00:34:41 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -186,14 +186,12 @@ static esiAddElement esiAddFail; static esiProcessSelf esiProcessComplete; -static esiRender esiLiteralRender; static esiProcessSelf esiLiteralProcess; static esiAddElement esiSequenceAdd; static esiRender esiSequenceRender; static esiProcessSelf esiSequenceProcess; -static esiRender esiIncludeRender; static esiProcessSelf esiIncludeProcess; struct esiInclude; static void esiIncludeSubRequestDone (esiInclude *, esiStreamContext *, int); @@ -225,9 +223,9 @@ } esiElementType_t; static esiElementType _esiComment = {esiRenderSelf,esiAddFail,esiProcessComplete}; -static esiElementType _esiLiteral = {esiLiteralRender,esiAddFail,esiLiteralProcess}; -static esiElementType _esiSequence = {esiSequenceRender,esiSequenceAdd,esiSequenceProcess}; -static esiElementType _esiInclude = {esiIncludeRender, esiAddFail, esiIncludeProcess}; +static esiElementType _esiLiteral = {esiRenderSelf,esiAddFail,esiLiteralProcess}; +static esiElementType _esiSequence = {esiRenderSelf,esiSequenceAdd,esiSequenceProcess}; +static esiElementType _esiInclude = {esiRenderSelf, esiAddFail, esiIncludeProcess}; static esiElementType _esiRemove = {esiRemoveRender, esiRemoveAdd, esiProcessComplete}; static esiElementType _esiTry = {esiTryRender, esiTryAdd, esiTryProcess}; /* esiAttempt, esiExcept, esiVar, esiWhen and esiOtherwise are 'Sequences' */ @@ -255,7 +253,12 @@ /* esiLiteral */ struct esiLiteral : public esiElement{ + void *operator new (size_t byteCount); + void operator delete (void *address); void deleteSelf(); + + esiLiteral(esiContext *, const XML_Char *s, int len); + void render(esiSegment *); /* optimise copies away later */ esiSegment *buffer; struct { @@ -292,6 +295,12 @@ /* esiInclude */ struct esiInclude : public esiElement{ + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); + + esiInclude(int attributes, const char **attr, esiContext *); + void render(esiSegment *); struct { int onerrorcontinue:1; /* on error return zero data */ int failed:1; /* Failed to process completely */ @@ -1714,6 +1723,22 @@ } /* esiLiteral */ +void * +esiLiteral::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiLiteral)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiLiteral, esiLiteralFree); + rv = (void *)cbdataAlloc (esiLiteral); + return rv; +} + +void +esiLiteral::operator delete (void *address) +{ + cbdataFree ((esiLiteral *)address); +} + void esiLiteral::deleteSelf() { @@ -1734,15 +1759,17 @@ esiElement * esiLiteralNew (esiContext *context, const XML_Char *s, int length) { - esiLiteral *rv; + return new esiLiteral(context, s, length); +} + +esiLiteral::esiLiteral(esiContext *context, const XML_Char *s, int length) +{ esiSegment *local; off_t start; - CBDATA_INIT_TYPE_FREECB(esiLiteral, esiLiteralFree); - rv = cbdataAlloc (esiLiteral); - rv->Vptr = &_esiLiteral; + Vptr = &_esiLiteral; assert (s); - rv->buffer = cbdataAlloc (esiSegment); - local = rv->buffer; + buffer = cbdataAlloc (esiSegment); + local = buffer; start = 0; while (length > 0) { off_t len = sizeof (local->buf) - local->len; @@ -1757,19 +1784,18 @@ local=local->next; } } - rv->varState = cbdataReference (context->varState); - return (esiElement *)rv; + varState = cbdataReference (context->varState); } void -esiLiteralRender (void *data, esiSegment *output) +esiLiteral::render (esiSegment *output) { + debug (86,9)("esiLiteral::render: Rending %p\n",this); /* append the entire chain */ - esiLiteral *thisNode = (esiLiteral *)data; esiSegment *myout = output; assert (myout->next == NULL); - myout->next = thisNode->buffer; - thisNode->buffer = NULL; + myout->next = buffer; + buffer = NULL; } esiProcessResult_t @@ -1955,6 +1981,28 @@ safe_free (thisNode->alturl); } +void * +esiInclude::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiInclude)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiInclude, esiIncludeFree); + rv = (void *)cbdataAlloc (esiInclude); + return rv; +} + +void +esiInclude::operator delete (void *address) +{ + cbdataFree ((esiInclude *)address); +} + +void +esiInclude::deleteSelf() +{ + delete this; +} + void esiIncludeStart (esiStreamContext *, char const *, esiVarState *); @@ -1982,35 +2030,37 @@ esiElement * esiIncludeNew (int attrcount, char const **attr, esiContext *context) { - esiInclude *rv; + return new esiInclude (attrcount, attr, context); +} + +esiInclude::esiInclude (int attrcount, char const **attr, esiContext *aContext) +{ int i; - assert (context); - CBDATA_INIT_TYPE_FREECB(esiInclude, esiIncludeFree); - rv = cbdataAlloc (esiInclude); - rv->Vptr = &_esiInclude; + assert (aContext); + Vptr = &_esiInclude; for (i = 0; attr[i] && i < attrcount; i += 2) { if (!strcmp(attr[i],"src")) { /* Start a request for thisNode url */ debug (86,5)("esiIncludeNew: Requesting source '%s'\n",attr[i+1]); /* TODO: don't assert on thisNode, ignore the duplicate */ - assert (rv->src == NULL); - rv->src = esiStreamContextNew (rv); - assert (rv->src != NULL); - rv->srcurl = xstrdup ( attr[i+1]); + assert (src == NULL); + src = esiStreamContextNew (this); + assert (src != NULL); + srcurl = xstrdup ( attr[i+1]); } else if (!strcmp(attr[i],"alt")) { /* Start a secondary request for thisNode url */ /* TODO: make a config parameter to wait on requesting alt's * for the src to fail */ debug (86,5)("esiIncludeNew: Requesting alternate '%s'\n",attr[i+1]); - assert (rv->alt == NULL); /* TODO: FIXME */ - rv->alt = esiStreamContextNew (rv); - assert (rv->alt != NULL); - rv->alturl = xstrdup (attr[i+1]); + assert (alt == NULL); /* TODO: FIXME */ + alt = esiStreamContextNew (this); + assert (alt != NULL); + alturl = xstrdup (attr[i+1]); } else if (!strcmp(attr[i],"onerror")) { if (!strcmp(attr[i+1], "continue")) { - rv->flags.onerrorcontinue = 1; + flags.onerrorcontinue = 1; } else { /* ignore mistyped attributes */ debug (86, 1)("invalid value for onerror='%s'\n", attr[i+1]); @@ -2020,40 +2070,38 @@ */ } } - rv->context = cbdataReference(context); - if (rv->src) { - esiIncludeStart (rv->src, rv->srcurl, context->varState); + context = cbdataReference(aContext); + if (src) { + esiIncludeStart (src, srcurl, context->varState); /* eaten by the request */ - rv->srcurl = NULL; - esiIncludeStart (rv->alt, rv->alturl, context->varState); + srcurl = NULL; + esiIncludeStart (alt, alturl, context->varState); /* eaten by the request */ - rv->alturl = NULL; + alturl = NULL; } else { - if (rv->alt) - cbdataFree (rv->alt); + if (alt) + cbdataFree (alt); debug (86,1)("esiIncludeNew: esi:include with no src attributes\n"); - rv->flags.failed = 1; + flags.failed = 1; } - return (esiElement *)rv; } void -esiIncludeRender (void *data, esiSegment *output) +esiInclude::render(esiSegment *output) { - esiInclude *thisNode = (esiInclude *)data; esiSegment *myout = NULL; - debug (86, 5)("esiIncludeRender: Rendering include %p\n", thisNode); - assert (thisNode->flags.finished || (thisNode->flags.failed && thisNode->flags.onerrorcontinue)); - if (thisNode->flags.failed && thisNode->flags.onerrorcontinue) { + debug (86, 5)("esiIncludeRender: Rendering include %p\n", this); + assert (flags.finished || (flags.failed && flags.onerrorcontinue)); + if (flags.failed && flags.onerrorcontinue) { return; } /* Render the content */ - if (thisNode->srccontent) { - myout = thisNode->srccontent; - thisNode->srccontent = NULL; - } else if (thisNode->altcontent) { - myout = thisNode->altcontent; - thisNode->altcontent = NULL; + if (srccontent) { + myout = srccontent; + srccontent = NULL; + } else if (altcontent) { + myout = altcontent; + altcontent = NULL; } else fatal ("esiIncludeRender called with no content, and no failure!\n"); assert (output->next == NULL);