Context.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 #ifndef SQUID_ESICONTEXT_H
10 #define SQUID_ESICONTEXT_H
11 
12 #include "clientStream.h"
13 #include "error/forward.h"
14 #include "esi/Element.h"
15 #include "esi/Esi.h"
16 #include "esi/Parser.h"
17 #include "http/forward.h"
18 #include "http/StatusCode.h"
19 
20 class ESIVarState;
21 class ClientHttpRequest;
22 
23 /* ESIContext */
24 
26 {
28 
29 public:
32  thisNode(NULL),
33  http(NULL),
37  rep(NULL),
38  outbound_offset(0),
39  readpos(0),
40  pos(0),
41  varState(NULL),
43  reading_(true),
44  processing(false) {
45  memset(&flags, 0, sizeof(flags));
46  }
47 
48  ~ESIContext();
49 
50  enum esiKick_t {
55  };
56 
57  /* when esi processing completes */
59  void fail (ESIElement *source, char const*anError = NULL);
60  void startRead();
61  void finishRead();
62  bool reading() const;
63  void setError();
64  void setErrorMessage(char const *);
65 
66  void addStackElement (ESIElement::Pointer element);
67  void addLiteral (const char *s, int len);
68 
69  void finishChildren ();
70 
71  clientStreamNode *thisNode; /* our stream node */
72  /* the request we are processing. HMM: cbdataReferencing this will result
73  * in a circular reference, so we don't. Note: we are automatically freed
74  * when it is, so that's ok. */
76 
77  struct {
78  int passthrough:1;
79  int oktosend:1;
80  int finished:1;
81 
82  /* an error has occurred, send full body replies
83  * regardless. Note that we don't fail midstream
84  * because we buffer until we can not fail
85  */
86  int error:1;
87 
88  int finishedtemplate:1; /* we've read the entire template */
89  int clientwantsdata:1; /* we need to satisfy a read request */
90  int kicked:1; /* note on reentering the kick routine */
91  int detached:1; /* our downstream has detached */
92  } flags;
93 
94  err_type errorpage; /* if we error what page to use */
95  Http::StatusCode errorstatus; /* if we error, what code to return */
96  char *errormessage; /* error to pass to error page */
97  HttpReplyPointer rep; /* buffered until we pass data downstream */
98  ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */
100  /* processed data we are waiting to send, or for
101  * potential errors to be resolved
102  */
104  ESISegment::Pointer outboundtail; /* our write segment */
105  /* the offset to the next character to send -
106  * non zero if we haven't sent the entire segment
107  * for some reason
108  */
110  int64_t readpos; /* the logical position we are reading from */
111  int64_t pos; /* the logical position of outbound_offset in the data stream */
112 
114  {
115 
116  public:
117  ESIElement::Pointer stack[ESI_STACK_DEPTH_LIMIT]; /* a stack of esi elements that are open */
118  int stackdepth; /* self explanatory */
121  void init (ESIParserClient *);
122  bool inited() const;
123  ParserState();
124  void freeResources();
125  void popAll();
126  int parsing:1; /* libexpat is not reentrant on the same context */
127 
128  private:
129  bool inited_;
130  }
131  parserState; // TODO: refactor this to somewhere else
132 
135 
136  esiKick_t kick ();
138  bool failed() const {return flags.error != 0;}
139 
141 
142 private:
143  void fail ();
144  void freeResources();
145  void fixupOutboundTail();
146  void trimBlanks();
147  size_t send ();
148  bool reading_;
151  void parse();
152  void parseOneBuffer();
153  void updateCachedAST();
154  bool hasCachedAST() const;
155  void getCachedAST();
156  virtual void start(const char *el, const char **attr, size_t attrCount);
157  virtual void end(const char *el);
158  virtual void parserDefault (const char *s, int len);
159  virtual void parserComment (const char *s);
161 };
162 
163 #endif /* SQUID_ESICONTEXT_H */
164 
esiKick_t kick()
Definition: Esi.cc:302
int oktosend
Definition: Context.h:79
void freeResources()
Definition: Esi.cc:1395
@ ESI_KICK_INPROGRESS
Definition: Context.h:54
int64_t pos
Definition: Context.h:111
void fail()
Definition: Esi.cc:1420
ESIElement::Pointer tree
Definition: Context.h:134
void trimBlanks()
Definition: Esi.cc:520
ESISegment::Pointer incoming
Definition: Context.h:99
ESISegment::Pointer buffered
Definition: Context.h:98
int finished
Definition: Context.h:80
@ scNone
Definition: StatusCode.h:21
int passthrough
Definition: Context.h:78
int finishedtemplate
Definition: Context.h:88
ClientHttpRequest * http
Definition: Context.h:75
void appendOutboundData(ESISegment::Pointer theData)
Definition: Esi.cc:255
int error
Definition: Context.h:86
ESIElement::Pointer top()
Definition: Esi.cc:905
Http::StatusCode errorstatus
Definition: Context.h:95
@ ERR_NONE
Definition: forward.h:15
StatusCode
Definition: StatusCode.h:20
err_type
Definition: forward.h:14
Definition: forward.h:22
virtual void end(const char *el)
Definition: Esi.cc:1074
ESISegment::Pointer outbound
Definition: Context.h:103
@ ESI_KICK_FAILED
Definition: Context.h:51
CBDATA_CLASS(ESIContext)
ESIContext()
Definition: Context.h:31
void parseOneBuffer()
Definition: Esi.cc:1203
HttpReplyPointer rep
Definition: Context.h:97
esiProcessResult_t process()
Definition: Esi.cc:1283
struct ESIContext::@60 flags
#define NULL
Definition: types.h:166
char * errormessage
Definition: Context.h:96
virtual void parserDefault(const char *s, int len)
Definition: Esi.cc:1127
virtual void parserComment(const char *s)
Definition: Esi.cc:1137
bool inited() const
Definition: Esi.cc:917
RefCount< ESIContext > Pointer
Definition: Context.h:30
#define true
Definition: GnuRegex.c:234
bool cachedASTInUse
Definition: Context.h:140
void finishChildren()
Definition: Esi.cc:626
#define ESI_STACK_DEPTH_LIMIT
Definition: Esi.h:16
@ ESI_KICK_SENT
Definition: Context.h:53
int detached
Definition: Context.h:91
void addLiteral(const char *s, int len)
Definition: Esi.cc:1183
class ESIContext::ParserState parserState
bool failed() const
Definition: Context.h:138
void init(ESIParserClient *)
Definition: Esi.cc:1196
~ESIContext()
Definition: Esi.cc:814
void finishRead()
Definition: Esi.cc:228
void parse()
Definition: Esi.cc:1235
ESIVarState * varState
Definition: Context.h:133
int kicked
Definition: Context.h:90
void fixupOutboundTail()
Definition: Esi.cc:293
esiProcessResult_t
Definition: Element.h:18
void startRead()
Definition: Esi.cc:222
size_t send()
Definition: Esi.cc:538
int64_t readpos
Definition: Context.h:110
virtual void start(const char *el, const char **attr, size_t attrCount)
Definition: Esi.cc:946
size_t outbound_offset
Definition: Context.h:109
void updateCachedAST()
Definition: Context.cc:24
RefCount< ESIContext > cbdataLocker
Definition: Context.h:137
bool reading_
Definition: Context.h:148
void provideData(ESISegment::Pointer, ESIElement *source)
Definition: Esi.cc:270
clientStreamNode * thisNode
Definition: Context.h:71
@ ESI_KICK_PENDING
Definition: Context.h:52
ESIParser::Pointer theParser
Definition: Context.h:119
bool hasCachedAST() const
Definition: Context.cc:52
ESISegment::Pointer outboundtail
Definition: Context.h:104
void setError()
Definition: Esi.cc:247
void getCachedAST()
Definition: Context.cc:69
int clientwantsdata
Definition: Context.h:89
void addStackElement(ESIElement::Pointer element)
Definition: Esi.cc:923
void setErrorMessage(char const *)
Definition: Context.cc:86
static StatHist s
#define false
Definition: GnuRegex.c:233
err_type errorpage
Definition: Context.h:94
bool reading() const
Definition: Esi.cc:234
ESIElement::Pointer stack[ESI_STACK_DEPTH_LIMIT]
Definition: Context.h:117
bool processing
Definition: Context.h:160

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors