3
* $Id: ESIAssign.cc,v 1.6.4.1 2008/02/10 10:43:09 serassio Exp $
5
* DEBUG: section 86 ESI processing
6
* AUTHOR: Robert Collins
8
* SQUID Web Proxy Cache http://www.squid-cache.org/
9
* ----------------------------------------------------------
11
* Squid is the result of efforts by numerous individuals from
12
* the Internet community; see the CONTRIBUTORS file for full
13
* details. Many organizations have provided support for Squid's
14
* development; see the SPONSORS file for full details. Squid is
15
* Copyrighted (C) 2001 by the Regents of the University of
16
* California; see the COPYRIGHT file for full details. Squid
17
* incorporates software developed and/or copyrighted by other
18
* sources; see the CREDITS file for full details.
20
* This program is free software; you can redistribute it and/or modify
21
* it under the terms of the GNU General Public License as published by
22
* the Free Software Foundation; either version 2 of the License, or
23
* (at your option) any later version.
25
* This program is distributed in the hope that it will be useful,
26
; but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
* GNU General Public License for more details.
30
* You should have received a copy of the GNU General Public License
31
* along with this program; if not, write to the Free Software
32
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38
/* MS Visual Studio Projects are monolithic, so we need the following
39
* #if to exclude the ESI code from compile process when not needed.
41
#if (USE_SQUID_ESI == 1)
43
#include "ESIAssign.h"
44
#include "ESIContext.h"
45
#include "ESISequence.h"
47
ESIAssign::~ESIAssign()
53
ESIAssign::ESIAssign (ESIAssign const &old) : parent (NULL), varState (NULL), name (old.name), value (old.value ? new ESIVariableExpression (*old.value): NULL), variable (NULL), unevaluatedVariable(old.unevaluatedVariable)
56
ESIAssign::ESIAssign (esiTreeParentPtr aParent, int attrcount, char const **attr, ESIContext *aContext) : parent (aParent), varState (NULL), name(), value (NULL), variable (NULL), unevaluatedVariable()
58
/* TODO: grab content IFF no value was specified */
61
for (int i = 0; i < attrcount && attr[i]; i += 2) {
62
if (!strcmp(attr[i],"name")) {
63
/* the variables name is ... */
64
debugs(86, 5, "ESIAssign::ESIAssign: Variable name '" << attr[i+1] << "'");
65
/* If there are duplicate name attributes, we simply use the
69
} else if (!strcmp(attr[i],"value")) {
70
/* short form assignment: */
71
debugs(86, 5, "ESIAssign::ESIAssign: Unevaluated variable '" << attr[i+1] << "'");
72
/* Again, if there are duplicate attributes, we use the last */
73
unevaluatedVariable = attr[i+1];
75
/* ignore mistyped attributes. TODO:? error on these for user feedback - config parameter needed
80
varState = cbdataReference(aContext->varState);
84
ESIAssign::evaluateVariable()
86
if (variable.getRaw())
87
variable->process (false);
91
if (unevaluatedVariable.size()) {
92
varState->feedData(unevaluatedVariable.buf(), unevaluatedVariable.size());
93
char const *result = varState->extractChar ();
95
/* Consider activating this, when we want to evaluate variables to a
98
// setTestResult(ESIExpression::Evaluate (expression));
100
value = new ESIVariableExpression (result);
107
ESIAssign::provideData (ESISegment::Pointer data, ESIElement * source)
109
assert (source == variable.getRaw());
110
char *result = data->listToChar();
111
unevaluatedVariable = result;
116
ESIAssign::process (int dovars)
124
return ESI_PROCESS_COMPLETE;
126
varState->addVariable (name.buf(), name.size(), value);
130
debugs(86, 5, "ESIAssign: Processed " << this);
132
return ESI_PROCESS_COMPLETE;
136
ESIAssign::render(ESISegment::Pointer)
140
ESIAssign::makeCacheable() const
142
ESIAssign *result = new ESIAssign (*this);
144
if (variable.getRaw())
145
result->variable = variable->makeCacheable();
151
ESIAssign::makeUsable(esiTreeParentPtr aParent, ESIVarState &aVarState) const
153
ESIAssign *result = new ESIAssign (*this);
154
result->parent = aParent;
155
result->varState = cbdataReference(&aVarState);
157
if (variable.getRaw())
158
result->variable = variable->makeUsable(result, aVarState);
167
cbdataReferenceDone (varState);
174
ESIAssign::addElement(ESIElement::Pointer anElement)
176
/* we have a value, drop the element on the floor */
178
if (unevaluatedVariable.size())
181
if (!variable.getRaw())
182
variable = new esiSequence (this, false);
184
return variable->addElement (anElement);
187
ESIVariableExpression::~ESIVariableExpression()
190
ESIVariableExpression::ESIVariableExpression (String const &aString) : expression (aString)
194
ESIVariableExpression::eval (ESIVarState &state, char const *subref, char const *defaultOnEmpty) const
196
/* XXX: Implement evaluation of the expression */
197
ESISegment::ListAppend (state.getOutput(), expression.buf(), expression.size());
200
#endif /* USE_SQUID_ESI == 1 */