]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ESIAssign.cc
Windows port: fix Visual Studio build problems when ESI, Delay Pools and SSL support...
[thirdparty/squid.git] / src / ESIAssign.cc
CommitLineData
924f73bc 1
2/*
454e8283 3 * $Id: ESIAssign.cc,v 1.7 2008/01/20 19:46:35 serassio Exp $
924f73bc 4 *
5 * DEBUG: section 86 ESI processing
6 * AUTHOR: Robert Collins
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
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.
19 *
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.
24 *
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.
29 *
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.
33 *
34 */
35
36#include "squid.h"
454e8283 37#
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.
40 */
41#if (USE_SQUID_ESI == 1)
42
43include "ESIAssign.h"
924f73bc 44#include "ESIContext.h"
45#include "ESISequence.h"
46
924f73bc 47ESIAssign::~ESIAssign()
48{
49 if (value)
50 delete value;
51}
52
53ESIAssign::ESIAssign (ESIAssign const &old) : parent (NULL), varState (NULL), name (old.name), value (old.value ? new ESIVariableExpression (*old.value): NULL), variable (NULL), unevaluatedVariable(old.unevaluatedVariable)
54{}
55
56ESIAssign::ESIAssign (esiTreeParentPtr aParent, int attrcount, char const **attr, ESIContext *aContext) : parent (aParent), varState (NULL), name(), value (NULL), variable (NULL), unevaluatedVariable()
57{
58 /* TODO: grab content IFF no value was specified */
59 assert (aContext);
60
61 for (int i = 0; i < attrcount && attr[i]; i += 2) {
62 if (!strcmp(attr[i],"name")) {
63 /* the variables name is ... */
bf8fe701 64 debugs(86, 5, "ESIAssign::ESIAssign: Variable name '" << attr[i+1] << "'");
924f73bc 65 /* If there are duplicate name attributes, we simply use the
66 * last one
67 */
68 name = attr[i+1];
69 } else if (!strcmp(attr[i],"value")) {
70 /* short form assignment: */
bf8fe701 71 debugs(86, 5, "ESIAssign::ESIAssign: Unevaluated variable '" << attr[i+1] << "'");
924f73bc 72 /* Again, if there are duplicate attributes, we use the last */
73 unevaluatedVariable = attr[i+1];
74 } else {
75 /* ignore mistyped attributes. TODO:? error on these for user feedback - config parameter needed
76 */
77 }
78 }
79
80 varState = cbdataReference(aContext->varState);
81}
82
83void
84ESIAssign::evaluateVariable()
85{
86 if (variable.getRaw())
87 variable->process (false);
88
89 variable = NULL;
90
91 if (unevaluatedVariable.size()) {
30abd221 92 varState->feedData(unevaluatedVariable.buf(), unevaluatedVariable.size());
924f73bc 93 char const *result = varState->extractChar ();
94
95 /* Consider activating this, when we want to evaluate variables to a
96 * value
97 */
98 // setTestResult(ESIExpression::Evaluate (expression));
99
100 value = new ESIVariableExpression (result);
101
102 safe_free (result);
103 }
104}
105
106void
107ESIAssign::provideData (ESISegment::Pointer data, ESIElement * source)
108{
109 assert (source == variable.getRaw());
110 char *result = data->listToChar();
111 unevaluatedVariable = result;
112 safe_free (result);
113}
114
115esiProcessResult_t
116ESIAssign::process (int dovars)
117{
118 assert (varState);
119
120 if (!value)
121 evaluateVariable();
122
123 if (!value)
124 return ESI_PROCESS_COMPLETE;
125
30abd221 126 varState->addVariable (name.buf(), name.size(), value);
924f73bc 127
128 value = NULL;
129
bf8fe701 130 debugs(86, 5, "ESIAssign: Processed " << this);
924f73bc 131
132 return ESI_PROCESS_COMPLETE;
133}
134
135void
136ESIAssign::render(ESISegment::Pointer)
137{}
138
139ESIAssign::Pointer
140ESIAssign::makeCacheable() const
141{
142 ESIAssign *result = new ESIAssign (*this);
143
144 if (variable.getRaw())
145 result->variable = variable->makeCacheable();
146
147 return result;
148}
149
150ESIAssign::Pointer
151ESIAssign::makeUsable(esiTreeParentPtr aParent, ESIVarState &aVarState) const
152{
153 ESIAssign *result = new ESIAssign (*this);
154 result->parent = aParent;
155 result->varState = cbdataReference(&aVarState);
156
157 if (variable.getRaw())
158 result->variable = variable->makeUsable(result, aVarState);
159
160 return result;
161}
162
163void
164ESIAssign::finish()
165{
166 if (varState)
167 cbdataReferenceDone (varState);
168
169 if (parent.getRaw())
170 parent = NULL;
171}
172
173bool
174ESIAssign::addElement(ESIElement::Pointer anElement)
175{
176 /* we have a value, drop the element on the floor */
177
178 if (unevaluatedVariable.size())
179 return true;
180
181 if (!variable.getRaw())
182 variable = new esiSequence (this, false);
183
184 return variable->addElement (anElement);
185}
186
187ESIVariableExpression::~ESIVariableExpression()
188{}
189
30abd221 190ESIVariableExpression::ESIVariableExpression (String const &aString) : expression (aString)
924f73bc 191{}
192
193void
194ESIVariableExpression::eval (ESIVarState &state, char const *subref, char const *defaultOnEmpty) const
195{
196 /* XXX: Implement evaluation of the expression */
30abd221 197 ESISegment::ListAppend (state.getOutput(), expression.buf(), expression.size());
924f73bc 198}
454e8283 199
200#endif /* USE_SQUID_ESI == 1 */