Context.h
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#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
20class ESIVarState;
22
23/* ESIContext */
24
26{
28
29public:
32 thisNode(nullptr),
33 http(nullptr),
36 errormessage(nullptr),
37 rep(nullptr),
39 readpos(0),
40 pos(0),
41 varState(nullptr),
45 memset(&flags, 0, sizeof(flags));
46 }
47
49
50 enum esiKick_t {
55 };
56
57 /* when esi processing completes */
59 void fail (ESIElement *source, char const*anError = nullptr);
60 void startRead();
61 void finishRead();
62 bool reading() const;
63 void setError();
64 void setErrorMessage(char const *);
65
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 {
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 */
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:
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
142private:
143 void fail ();
144 void freeResources();
145 void fixupOutboundTail();
146 void trimBlanks();
147 size_t send ();
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
esiProcessResult_t
Definition: Element.h:18
#define ESI_STACK_DEPTH_LIMIT
Definition: Esi.h:16
#define true
Definition: GnuRegex.c:241
#define false
Definition: GnuRegex.c:240
ESIElement::Pointer top()
Definition: Esi.cc:904
ESIParser::Pointer theParser
Definition: Context.h:119
ESIElement::Pointer stack[ESI_STACK_DEPTH_LIMIT]
Definition: Context.h:117
bool inited() const
Definition: Esi.cc:916
void init(ESIParserClient *)
Definition: Esi.cc:1195
ClientHttpRequest * http
Definition: Context.h:75
clientStreamNode * thisNode
Definition: Context.h:71
ESIVarState * varState
Definition: Context.h:133
int kicked
Definition: Context.h:90
int passthrough
Definition: Context.h:78
ESISegment::Pointer buffered
Definition: Context.h:98
err_type errorpage
Definition: Context.h:94
int finishedtemplate
Definition: Context.h:88
CBDATA_CLASS(ESIContext)
int detached
Definition: Context.h:91
void fixupOutboundTail()
Definition: Esi.cc:292
bool processing
Definition: Context.h:160
void getCachedAST()
Definition: Context.cc:69
void parseOneBuffer()
Definition: Esi.cc:1202
void setErrorMessage(char const *)
Definition: Context.cc:86
char * errormessage
Definition: Context.h:96
~ESIContext()
Definition: Esi.cc:813
void provideData(ESISegment::Pointer, ESIElement *source)
Definition: Esi.cc:269
int oktosend
Definition: Context.h:79
ESISegment::Pointer outboundtail
Definition: Context.h:104
bool reading() const
Definition: Esi.cc:233
esiKick_t kick()
Definition: Esi.cc:301
bool hasCachedAST() const
Definition: Context.cc:52
class ESIContext::ParserState parserState
int clientwantsdata
Definition: Context.h:89
void appendOutboundData(ESISegment::Pointer theData)
Definition: Esi.cc:254
@ ESI_KICK_FAILED
Definition: Context.h:51
@ ESI_KICK_PENDING
Definition: Context.h:52
@ ESI_KICK_INPROGRESS
Definition: Context.h:54
@ ESI_KICK_SENT
Definition: Context.h:53
void freeResources()
Definition: Esi.cc:1385
void updateCachedAST()
Definition: Context.cc:24
HttpReplyPointer rep
Definition: Context.h:97
void finishRead()
Definition: Esi.cc:227
void trimBlanks()
Definition: Esi.cc:519
ESISegment::Pointer incoming
Definition: Context.h:99
void setError()
Definition: Esi.cc:246
void addStackElement(ESIElement::Pointer element)
Definition: Esi.cc:922
bool failed() const
Definition: Context.h:138
struct ESIContext::@63 flags
void parse()
Definition: Esi.cc:1234
bool reading_
Definition: Context.h:148
void fail()
Definition: Esi.cc:1410
esiProcessResult_t process()
Definition: Esi.cc:1278
int error
Definition: Context.h:86
int finished
Definition: Context.h:80
Http::StatusCode errorstatus
Definition: Context.h:95
virtual void parserDefault(const char *s, int len)
Definition: Esi.cc:1126
void finishChildren()
Definition: Esi.cc:625
ESIElement::Pointer tree
Definition: Context.h:134
ESIContext()
Definition: Context.h:31
ESISegment::Pointer outbound
Definition: Context.h:103
bool cachedASTInUse
Definition: Context.h:140
RefCount< ESIContext > Pointer
Definition: Context.h:30
void addLiteral(const char *s, int len)
Definition: Esi.cc:1182
RefCount< ESIContext > cbdataLocker
Definition: Context.h:137
size_t outbound_offset
Definition: Context.h:109
virtual void end(const char *el)
Definition: Esi.cc:1073
size_t send()
Definition: Esi.cc:537
int64_t readpos
Definition: Context.h:110
virtual void start(const char *el, const char **attr, size_t attrCount)
Definition: Esi.cc:945
void startRead()
Definition: Esi.cc:221
int64_t pos
Definition: Context.h:111
virtual void parserComment(const char *s)
Definition: Esi.cc:1136
err_type
Definition: forward.h:14
@ ERR_NONE
Definition: forward.h:15
Definition: forward.h:22
StatusCode
Definition: StatusCode.h:20
@ scNone
Definition: StatusCode.h:21

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors