]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Assign.cc
47c12a6144b1d7b74d39b8d30754d8e5e4a248a4
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 86 ESI processing */
13 /* MS Visual Studio Projects are monolithic, so we need the following
14 * #if to exclude the ESI code from compile process when not needed.
16 #if (USE_SQUID_ESI == 1)
18 #include "esi/Assign.h"
19 #include "esi/Context.h"
20 #include "esi/Sequence.h"
21 #include "HttpReply.h"
23 ESIAssign::~ESIAssign()
29 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
)
32 ESIAssign::ESIAssign (esiTreeParentPtr aParent
, int attrcount
, char const **attr
, ESIContext
*aContext
) : parent (aParent
), varState (NULL
), name(), value (NULL
), variable (NULL
), unevaluatedVariable()
34 /* TODO: grab content IFF no value was specified */
37 for (int i
= 0; i
< attrcount
&& attr
[i
]; i
+= 2) {
38 if (!strcmp(attr
[i
],"name")) {
39 /* the variables name is ... */
40 debugs(86, 5, "ESIAssign::ESIAssign: Variable name '" << attr
[i
+1] << "'");
41 /* If there are duplicate name attributes, we simply use the
45 } else if (!strcmp(attr
[i
],"value")) {
46 /* short form assignment: */
47 debugs(86, 5, "ESIAssign::ESIAssign: Unevaluated variable '" << attr
[i
+1] << "'");
48 /* Again, if there are duplicate attributes, we use the last */
49 unevaluatedVariable
= attr
[i
+1];
51 /* ignore mistyped attributes. TODO:? error on these for user feedback - config parameter needed
56 varState
= cbdataReference(aContext
->varState
);
60 ESIAssign::evaluateVariable()
62 if (variable
.getRaw())
63 variable
->process (false);
67 if (unevaluatedVariable
.size()) {
68 varState
->feedData(unevaluatedVariable
.rawBuf(), unevaluatedVariable
.size());
69 char const *result
= varState
->extractChar ();
71 /* Consider activating this, when we want to evaluate variables to a
74 // setTestResult(ESIExpression::Evaluate (expression));
76 value
= new ESIVariableExpression (result
);
83 ESIAssign::provideData (ESISegment::Pointer data
, ESIElement
* source
)
85 assert (source
== variable
.getRaw());
86 char *result
= data
->listToChar();
87 unevaluatedVariable
= result
;
92 ESIAssign::process (int dovars
)
100 return ESI_PROCESS_COMPLETE
;
102 varState
->addVariable (name
.rawBuf(), name
.size(), value
);
106 debugs(86, 5, "ESIAssign: Processed " << this);
108 return ESI_PROCESS_COMPLETE
;
112 ESIAssign::render(ESISegment::Pointer
)
116 ESIAssign::makeCacheable() const
118 ESIAssign
*result
= new ESIAssign (*this);
120 if (variable
.getRaw())
121 result
->variable
= variable
->makeCacheable();
127 ESIAssign::makeUsable(esiTreeParentPtr aParent
, ESIVarState
&aVarState
) const
129 ESIAssign
*result
= new ESIAssign (*this);
130 result
->parent
= aParent
;
131 result
->varState
= cbdataReference(&aVarState
);
133 if (variable
.getRaw())
134 result
->variable
= variable
->makeUsable(result
, aVarState
);
143 cbdataReferenceDone (varState
);
150 ESIAssign::addElement(ESIElement::Pointer anElement
)
152 /* we have a value, drop the element on the floor */
154 if (unevaluatedVariable
.size())
157 if (!variable
.getRaw())
158 variable
= new esiSequence (this, false);
160 return variable
->addElement (anElement
);
163 ESIVariableExpression::~ESIVariableExpression()
166 ESIVariableExpression::ESIVariableExpression (String
const &aString
) : expression (aString
)
170 ESIVariableExpression::eval (ESIVarState
&state
, char const *subref
, char const *defaultOnEmpty
) const
172 /* XXX: Implement evaluation of the expression */
173 ESISegment::ListAppend (state
.getOutput(), expression
.rawBuf(), expression
.size());
176 #endif /* USE_SQUID_ESI == 1 */