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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors