Assign.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 86 ESI processing */
10
11#include "squid.h"
12
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.
15 */
16#if (USE_SQUID_ESI == 1)
17
18#include "esi/Assign.h"
19#include "esi/Context.h"
20#include "esi/Sequence.h"
21#include "HttpReply.h"
22
24{
25 if (value)
26 delete value;
27}
28
29ESIAssign::ESIAssign (ESIAssign const &old) : parent (nullptr), varState (nullptr), name (old.name), value (old.value ? new ESIVariableExpression (*old.value): nullptr), variable (nullptr), unevaluatedVariable(old.unevaluatedVariable)
30{}
31
32ESIAssign::ESIAssign (esiTreeParentPtr aParent, int attrcount, char const **attr, ESIContext *aContext) : parent (aParent), varState (nullptr), name(), value (nullptr), variable (nullptr), unevaluatedVariable()
33{
34 /* TODO: grab content IFF no value was specified */
35 assert (aContext);
36
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
42 * last one
43 */
44 name = attr[i+1];
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];
50 } else {
51 /* ignore mistyped attributes. TODO:? error on these for user feedback - config parameter needed
52 */
53 }
54 }
55
57}
58
59void
61{
62 if (variable.getRaw())
63 variable->process (false);
64
65 variable = nullptr;
66
69 char const *result = varState->extractChar ();
70
71 /* Consider activating this, when we want to evaluate variables to a
72 * value
73 */
74 // setTestResult(ESIExpression::Evaluate (expression));
75
76 value = new ESIVariableExpression (result);
77
78 safe_free (result);
79 }
80}
81
82void
84{
85 assert (source == variable.getRaw());
86 char *result = data->listToChar();
87 unevaluatedVariable = result;
88 safe_free (result);
89}
90
93{
95
96 if (!value)
98
99 if (!value)
101
103
104 value = nullptr;
105
106 debugs(86, 5, "ESIAssign: Processed " << this);
107
109}
110
111void
113{}
114
117{
118 ESIAssign *result = new ESIAssign (*this);
119
120 if (variable.getRaw())
121 result->variable = variable->makeCacheable();
122
123 return result;
124}
125
128{
129 ESIAssign *result = new ESIAssign (*this);
130 result->parent = aParent;
131 result->varState = cbdataReference(&aVarState);
132
133 if (variable.getRaw())
134 result->variable = variable->makeUsable(result, aVarState);
135
136 return result;
137}
138
139void
141{
142 if (varState)
144
145 if (parent.getRaw())
146 parent = nullptr;
147}
148
149bool
151{
152 /* we have a value, drop the element on the floor */
153
155 return true;
156
157 if (!variable.getRaw())
158 variable = new esiSequence (this, false);
159
160 return variable->addElement (anElement);
161}
162
164{}
165
166ESIVariableExpression::ESIVariableExpression (String const &aString) : expression (aString)
167{}
168
169void
170ESIVariableExpression::eval (ESIVarState &state, char const *, char const *) const
171{
172 /* XXX: Implement evaluation of the expression */
174}
175
176#endif /* USE_SQUID_ESI == 1 */
177
esiProcessResult_t
Definition: Element.h:18
@ ESI_PROCESS_COMPLETE
Definition: Element.h:19
#define assert(EX)
Definition: assert.h:19
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
#define cbdataReference(var)
Definition: cbdata.h:341
ESIVarState * varState
Definition: Assign.h:52
void finish()
Definition: Assign.cc:140
esiTreeParentPtr parent
Definition: Assign.h:51
esiProcessResult_t process(int dovars)
Definition: Assign.cc:92
void render(ESISegment::Pointer)
Definition: Assign.cc:112
void provideData(ESISegment::Pointer data, ESIElement *source)
Definition: Assign.cc:83
ESIElement::Pointer variable
Definition: Assign.h:55
Pointer makeUsable(esiTreeParentPtr, ESIVarState &) const
Definition: Assign.cc:127
ESIVariableExpression * value
Definition: Assign.h:54
String unevaluatedVariable
Definition: Assign.h:56
ESIAssign(esiTreeParentPtr, int, const char **, ESIContext *)
Definition: Assign.cc:32
String name
Definition: Assign.h:53
~ESIAssign()
Definition: Assign.cc:23
void evaluateVariable()
Definition: Assign.cc:60
bool addElement(ESIElement::Pointer)
Definition: Assign.cc:150
Pointer makeCacheable() const
Definition: Assign.cc:116
ESIVarState * varState
Definition: Context.h:133
virtual Pointer makeCacheable() const =0
virtual Pointer makeUsable(esiTreeParentPtr, ESIVarState &) const =0
static void ListAppend(Pointer &, char const *, size_t)
Definition: Segment.cc:120
char * listToChar() const
Definition: Segment.cc:81
char * extractChar()
Definition: VarState.cc:117
ESISegment::Pointer & getOutput()
Definition: VarState.cc:76
void addVariable(char const *, size_t, Variable *)
Definition: VarState.cc:282
void feedData(const char *buf, size_t len)
Definition: VarState.cc:99
virtual void eval(ESIVarState &state, char const *, char const *) const
Definition: Assign.cc:170
ESIVariableExpression(String const &value)
Definition: Assign.cc:166
C * getRaw() const
Definition: RefCount.h:80
char const * rawBuf() const
Definition: SquidString.h:86
size_type size() const
Definition: SquidString.h:73
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
struct variable variable
Definition: snmp_vars.h:121
#define safe_free(x)
Definition: xalloc.h:73

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors