]>
Commit | Line | Data |
---|---|---|
924f73bc | 1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
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. | |
26ac0430 | 24 | * |
924f73bc | 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. | |
26ac0430 | 29 | * |
924f73bc | 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 | ||
f7f3304a | 36 | #include "squid-old.h" |
3db19d36 | 37 | |
454e8283 | 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 | ||
f99c2cfe AR |
43 | #include "esi/Assign.h" |
44 | #include "esi/Context.h" | |
45 | #include "esi/Sequence.h" | |
924f73bc | 46 | |
924f73bc | 47 | ESIAssign::~ESIAssign() |
48 | { | |
49 | if (value) | |
50 | delete value; | |
51 | } | |
52 | ||
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) | |
54 | {} | |
55 | ||
56 | ESIAssign::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 | ||
83 | void | |
84 | ESIAssign::evaluateVariable() | |
85 | { | |
86 | if (variable.getRaw()) | |
87 | variable->process (false); | |
88 | ||
89 | variable = NULL; | |
90 | ||
91 | if (unevaluatedVariable.size()) { | |
bb790702 | 92 | varState->feedData(unevaluatedVariable.rawBuf(), 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 | ||
106 | void | |
107 | ESIAssign::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 | ||
115 | esiProcessResult_t | |
116 | ESIAssign::process (int dovars) | |
117 | { | |
118 | assert (varState); | |
119 | ||
120 | if (!value) | |
121 | evaluateVariable(); | |
122 | ||
123 | if (!value) | |
124 | return ESI_PROCESS_COMPLETE; | |
125 | ||
bb790702 | 126 | varState->addVariable (name.rawBuf(), 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 | ||
135 | void | |
136 | ESIAssign::render(ESISegment::Pointer) | |
137 | {} | |
138 | ||
139 | ESIAssign::Pointer | |
140 | ESIAssign::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 | ||
150 | ESIAssign::Pointer | |
151 | ESIAssign::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 | ||
163 | void | |
164 | ESIAssign::finish() | |
165 | { | |
166 | if (varState) | |
167 | cbdataReferenceDone (varState); | |
168 | ||
169 | if (parent.getRaw()) | |
170 | parent = NULL; | |
171 | } | |
172 | ||
173 | bool | |
174 | ESIAssign::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 | ||
187 | ESIVariableExpression::~ESIVariableExpression() | |
188 | {} | |
189 | ||
30abd221 | 190 | ESIVariableExpression::ESIVariableExpression (String const &aString) : expression (aString) |
924f73bc | 191 | {} |
192 | ||
193 | void | |
194 | ESIVariableExpression::eval (ESIVarState &state, char const *subref, char const *defaultOnEmpty) const | |
195 | { | |
196 | /* XXX: Implement evaluation of the expression */ | |
bb790702 | 197 | ESISegment::ListAppend (state.getOutput(), expression.rawBuf(), expression.size()); |
924f73bc | 198 | } |
454e8283 | 199 | |
200 | #endif /* USE_SQUID_ESI == 1 */ |