*/
#if (USE_SQUID_ESI == 1)
-#include "esi/Esi.h"
-#include "clientStream.h"
#include "client_side_request.h"
+#include "client_side.h"
+#include "clientStream.h"
+#include "comm/Connection.h"
#include "errorpage.h"
-#include "esi/Segment.h"
-#include "esi/Element.h"
+#include "esi/Assign.h"
+#include "esi/Attempt.h"
#include "esi/Context.h"
+#include "esi/Element.h"
+#include "esi/Esi.h"
+#include "esi/Except.h"
+#include "esi/Expression.h"
+#include "esi/Segment.h"
+#include "esi/VarState.h"
#include "HttpHdrSc.h"
#include "HttpHdrScTarget.h"
#include "HttpReply.h"
-#include "esi/Attempt.h"
-#include "esi/Except.h"
-#include "client_side.h"
-#include "esi/VarState.h"
-#include "esi/Assign.h"
-#include "esi/Expression.h"
#include "HttpRequest.h"
-#include "MemBuf.h"
#include "ip/Address.h"
+#include "MemBuf.h"
+#include "profiler/Profiler.h"
+#include "protos.h"
/* quick reference on behaviour here.
* The ESI specification 1.0 requires the ESI processor to be able to
typedef ESIContext::esiKick_t esiKick_t;
-
/* some core operators */
/* esiComment */
static FREE esiRemoveFree;
static ESIElement * esiRemoveNew(void);
-
/* esiTry */
struct esiTry : public ESIElement {
return reading_;
}
-
ESIStreamContext::ESIStreamContext() : finished(false), include (NULL), localbuffer (new ESISegment), buffer (NULL)
{}
/* ESIContext */
static ESIContext *ESIContextNew(HttpReply *, clientStreamNode *, ClientHttpRequest *);
-
void *
ESIContext::operator new(size_t byteCount)
{
return;
}
-
if (context->flags.oktosend && context->flags.finished) {
StoreIOBuffer tempBuffer;
assert (!context->outbound.getRaw());
assert (len != 0 || rep != NULL);
if (len) {
- xmemcpy (next->readBuffer.data, &outbound->buf[outbound_offset], len);
+ memcpy(next->readBuffer.data, &outbound->buf[outbound_offset], len);
if (len + outbound_offset == outbound->len) {
ESISegment::Pointer temp = outbound->next;
if (len == 0)
len = 1; /* tell the caller we sent something (because we sent headers */
-
cbdataReferenceDone (templock);
debugs (86,5,"ESIContext::send: this=" << this << " sent " << len);
&context->incoming->buf[context->incoming->len] <<
" because our buffer was not used");
- xmemcpy (&context->incoming->buf[context->incoming->len], receivedData.data, len);
+ memcpy(&context->incoming->buf[context->incoming->len], receivedData.data, len);
context->incoming->len += len;
if (context->incoming->len == HTTP_REQBUF_SZ) {
if (len != receivedData.length) {
/* capture the remnants */
- xmemcpy (context->incoming->buf, &receivedData.data[len], receivedData.length - len);
+ memcpy(context->incoming->buf, &receivedData.data[len], receivedData.length - len);
context->incoming->len = receivedData.length - len;
}
debugs(86, 5, "ESIContext::addStackElement: About to add ESI Node " << element.getRaw());
if (!parserState.top()->addElement(element)) {
- debugs(86, 1, "ESIContext::addStackElement: failed to add esi node, probable error in ESI template");
+ debugs(86, DBG_IMPORTANT, "ESIContext::addStackElement: failed to add esi node, probable error in ESI template");
flags.error = 1;
} else {
/* added ok, push onto the stack */
- parserState.stack[parserState.stackdepth++] = element;
+ parserState.stack[parserState.stackdepth] = element;
+ ++parserState.stackdepth;
}
}
position = localbuf + strlen (localbuf);
for (i = 0; i < specifiedattcount && attr[i]; i += 2) {
- *position++ = ' ';
+ *position = ' ';
+ ++position;
/* TODO: handle thisNode gracefully */
assert (xstrncpy (position, attr[i], sizeof(localbuf) + (position - localbuf)));
position += strlen (position);
- *position++ = '=';
- *position++ = '\"';
+ *position = '=';
+ ++position;
+ *position = '\"';
+ ++position;
const char *chPtr = attr[i + 1];
char ch;
while ((ch = *chPtr++) != '\0') {
assert( xstrncpy(position, """, sizeof(localbuf) + (position-localbuf)) );
position += 6;
} else {
- *(position++) = ch;
+ *position = ch;
+ ++position;
}
}
position += strlen (position);
- *position++ = '\"';
+ *position = '\"';
+ ++position;
}
- *position++ = '>';
+ *position = '>';
+ ++position;
*position = '\0';
addLiteral (localbuf, position - localbuf);
localbuf[1] = '/';
assert (xstrncpy (&localbuf[2], el, sizeof(localbuf) - 3));
position = localbuf + strlen (localbuf);
- *position++ = '>';
+ *position = '>';
+ ++position;
*position = '\0';
addLiteral (localbuf, position - localbuf);
break;
if (!tempParser->parse("<div>", 5,0) ||
!tempParser->parse(s + 3, strlen(s) - 3, 0) ||
!tempParser->parse("</div>",6,1)) {
- debugs(86, 0, "ESIContext::parserComment: Parsing fragment '" << s + 3 << "' failed.");
+ debugs(86, DBG_CRITICAL, "ESIContext::parserComment: Parsing fragment '" << s + 3 << "' failed.");
setError();
char tempstr[1024];
snprintf(tempstr, 1023, "ESIContext::parserComment: Parse error at line %ld:\n%s\n",
tempParser->lineNumber(),
tempParser->errorString());
- debugs(86, 0, "" << tempstr << "");
+ debugs(86, DBG_CRITICAL, "" << tempstr << "");
setErrorMessage(tempstr);
}
len = strlen (s);
if (len > sizeof (localbuf) - 9) {
- debugs(86, 0, "ESIContext::parserComment: Truncating long comment");
+ debugs(86, DBG_CRITICAL, "ESIContext::parserComment: Truncating long comment");
len = sizeof (localbuf) - 9;
}
ESIElement::Pointer element (new esiLiteral (this, s, len));
if (!parserState.top()->addElement(element)) {
- debugs(86, 1, "ESIContext::addLiteral: failed to add esi node, probable error in ESI template");
+ debugs(86, DBG_IMPORTANT, "ESIContext::addLiteral: failed to add esi node, probable error in ESI template");
flags.error = 1;
}
}
snprintf (tempstr, 1023, "esiProcess: Parse error at line %ld:\n%s\n",
parserState.theParser->lineNumber(),
parserState.theParser->errorString());
- debugs(86, 0, "" << tempstr << "");
+ debugs(86, DBG_CRITICAL, "" << tempstr << "");
setErrorMessage(tempstr);
if (!parserState.stackdepth) {
debugs(86, 5, "empty parser stack, inserting the top level node");
assert (tree.getRaw());
- parserState.stack[parserState.stackdepth++] = tree;
+ parserState.stack[parserState.stackdepth] = tree;
+ ++parserState.stackdepth;
}
if (rep && !parserState.inited())
break;
case ESI_PROCESS_FAILED:
- debugs(86, 0, "esiProcess: tree Processed FAILED");
+ debugs(86, DBG_CRITICAL, "esiProcess: tree Processed FAILED");
setError();
setErrorMessage("esiProcess: ESI template Processing failed.");
extern ErrorState *clientBuildError (err_type, http_status, char const *, Ip::Address &, HttpRequest *);
-
/* This can ONLY be used before we have sent *any* data to the client */
void
ESIContext::fail ()
/* don't honour range requests - for errors we send it all */
flags.error = 1;
/* create an error object */
- ErrorState * err = clientBuildError(errorpage, errorstatus, NULL, http->getConn()->peer, http->request);
+ // XXX: with the in-direction on remote IP. does the http->getConn()->clientConnection exist?
+ ErrorState * err = clientBuildError(errorpage, errorstatus, NULL, http->getConn()->clientConnection->remote, http->request);
err->err_msg = errormessage;
errormessage = NULL;
rep = err->BuildHttpReply();
- assert (rep->body.mb->contentSize() >= 0);
- size_t errorprogress = rep->body.mb->contentSize();
+ assert (rep->body.hasContent());
+ size_t errorprogress = rep->body.contentSize();
/* Tell esiSend where to start sending from */
outbound_offset = 0;
/* copy the membuf from the reply to outbound */
- while (errorprogress < (size_t)rep->body.mb->contentSize()) {
+ while (errorprogress < (size_t)rep->body.contentSize()) {
appendOutboundData(new ESISegment);
- errorprogress += outboundtail->append(rep->body.mb->content() + errorprogress, rep->body.mb->contentSize() - errorprogress);
+ errorprogress += outboundtail->append(rep->body.content() + errorprogress, rep->body.contentSize() - errorprogress);
}
/* the esiCode now thinks that the error is the outbound,
if (dynamic_cast<esiAttempt*>(element.getRaw())) {
if (attempt.getRaw()) {
- debugs(86, 1, "esiTryAdd: Failed for " << this << " - try allready has an attempt node (section 3.4)");
+ debugs(86, DBG_IMPORTANT, "esiTryAdd: Failed for " << this << " - try allready has an attempt node (section 3.4)");
return false;
}
if (dynamic_cast<esiExcept*>(element.getRaw())) {
if (except.getRaw()) {
- debugs(86, 1, "esiTryAdd: Failed for " << this << " - try already has an except node (section 3.4)");
+ debugs(86, DBG_IMPORTANT, "esiTryAdd: Failed for " << this << " - try already has an except node (section 3.4)");
return false;
}
return true;
}
- debugs(86, 1, "esiTryAdd: Failed to add element " << element.getRaw() << " to try " << this << ", incorrect element type (see section 3.4)");
+ debugs(86, DBG_IMPORTANT, "esiTryAdd: Failed to add element " << element.getRaw() << " to try " << this << ", incorrect element type (see section 3.4)");
return false;
}
assert (this);
if (!attempt.getRaw()) {
- debugs(86, 0, "esiTryProcess: Try has no attempt element - ESI template is invalid (section 3.4)");
+ debugs(86, DBG_CRITICAL, "esiTryProcess: Try has no attempt element - ESI template is invalid (section 3.4)");
return ESI_PROCESS_FAILED;
}
if (!except.getRaw()) {
- debugs(86, 0, "esiTryProcess: Try has no except element - ESI template is invalid (section 3.4)");
+ debugs(86, DBG_CRITICAL, "esiTryProcess: Try has no except element - ESI template is invalid (section 3.4)");
return ESI_PROCESS_FAILED;
}
/* Some elements require specific parents */
if (!(dynamic_cast<esiWhen*>(element.getRaw()) || dynamic_cast<esiOtherwise*>(element.getRaw()))) {
- debugs(86, 0, "esiChooseAdd: invalid child node for esi:choose (section 3.3)");
+ debugs(86, DBG_CRITICAL, "esiChooseAdd: invalid child node for esi:choose (section 3.3)");
return false;
}
if (dynamic_cast<esiOtherwise*>(element.getRaw())) {
if (otherwise.getRaw()) {
- debugs(86, 0, "esiChooseAdd: only one otherwise node allowed for esi:choose (section 3.3)");
+ debugs(86, DBG_CRITICAL, "esiChooseAdd: only one otherwise node allowed for esi:choose (section 3.3)");
return false;
}
parent->provideData (data, this);
}
-
esiChoose::esiChoose(esiChoose const &old) : chosenelement(-1), otherwise (NULL), parent (NULL)
{
for (size_t counter = 0; counter < old.elements.size(); ++counter) {
if (!count)
return;
- xmemmove (elements, &elements[count], (elementcount - count) * sizeof (ESIElement::Pointer));
+ memmove(elements, &elements[count], (elementcount - count) * sizeof (ESIElement::Pointer));
elementcount -= count;
}
/* ignore mistyped attributes.
* TODO:? error on these for user feedback - config parameter needed
*/
- debugs(86, 1, "Found misttyped attribute on ESI When clause");
+ debugs(86, DBG_IMPORTANT, "Found misttyped attribute on ESI When clause");
}
}
{
int rv = 0;
- if (rep->header.has(HDR_SURROGATE_CONTROL)) {
- HttpHdrScTarget *sctusable = httpHdrScGetMergedTarget (rep->surrogate_control,
- Config.Accel.surrogate_id);
+ if (rep->surrogate_control) {
+ HttpHdrScTarget *sctusable =
+ rep->surrogate_control->getMergedTarget(Config.Accel.surrogate_id);
- if (!sctusable || sctusable->content.size() == 0)
+ if (!sctusable || !sctusable->hasContent())
/* Nothing generic or targeted at us, or no
* content processing requested
*/
return 0;
- if (sctusable->content.pos("ESI/1.0") != NULL)
+ if (sctusable->content().pos("ESI/1.0") != NULL)
rv = 1;
- httpHdrScTargetDestroy (sctusable);
+ delete sctusable;
}
return rv;