Assign.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
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)
30 {}
31 
32 ESIAssign::ESIAssign (esiTreeParentPtr aParent, int attrcount, char const **attr, ESIContext *aContext) : parent (aParent), varState (NULL), name(), value (NULL), variable (NULL), 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 
56  varState = cbdataReference(aContext->varState);
57 }
58 
59 void
61 {
62  if (variable.getRaw())
63  variable->process (false);
64 
65  variable = NULL;
66 
67  if (unevaluatedVariable.size()) {
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 
82 void
84 {
85  assert (source == variable.getRaw());
86  char *result = data->listToChar();
87  unevaluatedVariable = result;
88  safe_free (result);
89 }
90 
92 ESIAssign::process (int dovars)
93 {
94  assert (varState);
95 
96  if (!value)
98 
99  if (!value)
100  return ESI_PROCESS_COMPLETE;
101 
103 
104  value = NULL;
105 
106  debugs(86, 5, "ESIAssign: Processed " << this);
107 
108  return ESI_PROCESS_COMPLETE;
109 }
110 
111 void
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 
139 void
141 {
142  if (varState)
144 
145  if (parent.getRaw())
146  parent = NULL;
147 }
148 
149 bool
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 
166 ESIVariableExpression::ESIVariableExpression (String const &aString) : expression (aString)
167 {}
168 
169 void
170 ESIVariableExpression::eval (ESIVarState &state, char const *subref, char const *defaultOnEmpty) const
171 {
172  /* XXX: Implement evaluation of the expression */
174 }
175 
176 #endif /* USE_SQUID_ESI == 1 */
177 
virtual Pointer makeUsable(esiTreeParentPtr, ESIVarState &) const =0
static void ListAppend(Pointer &, char const *, size_t)
Definition: Segment.cc:120
struct variable variable
Definition: snmp_vars.h:121
#define assert(EX)
Definition: assert.h:17
void provideData(ESISegment::Pointer data, ESIElement *source)
Definition: Assign.cc:83
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
char * listToChar() const
Definition: Segment.cc:81
void render(ESISegment::Pointer)
Definition: Assign.cc:112
int i
Definition: membanger.c:49
virtual Pointer makeCacheable() const =0
#define safe_free(x)
Definition: xalloc.h:73
Pointer makeUsable(esiTreeParentPtr, ESIVarState &) const
Definition: Assign.cc:127
String name
Definition: Assign.h:53
esiProcessResult_t
Definition: Element.h:16
ESIVarState * varState
Definition: Assign.h:52
char * extractChar()
Definition: VarState.cc:117
size_type size() const
Definition: SquidString.h:71
void addVariable(char const *, size_t, Variable *)
Definition: VarState.cc:282
Pointer makeCacheable() const
Definition: Assign.cc:116
ESIElement::Pointer variable
Definition: Assign.h:55
esiTreeParentPtr parent
Definition: Assign.h:51
esiProcessResult_t process(int dovars)
Definition: Assign.cc:92
void const char HLPCB void * data
Definition: stub_helper.cc:16
virtual void eval(ESIVarState &state, char const *, char const *) const
Definition: Assign.cc:170
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
#define cbdataReference(var)
Definition: cbdata.h:341
char const * rawBuf() const
Definition: SquidString.h:84
void finish()
Definition: Assign.cc:140
String unevaluatedVariable
Definition: Assign.h:56
void feedData(const char *buf, size_t len)
Definition: VarState.cc:99
bool addElement(ESIElement::Pointer)
Definition: Sequence.cc:146
void evaluateVariable()
Definition: Assign.cc:60
ESISegment::Pointer & getOutput()
Definition: VarState.cc:76
ESIAssign(esiTreeParentPtr, int, const char **, ESIContext *)
Definition: Assign.cc:32
~ESIAssign()
Definition: Assign.cc:23
ESIVariableExpression(String const &value)
Definition: Assign.cc:166
ESIVariableExpression * value
Definition: Assign.h:54
bool addElement(ESIElement::Pointer)
Definition: Assign.cc:150
ESIVarState * varState
Definition: Context.h:132
C * getRaw() const
Definition: RefCount.h:74
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors