]> git.ipfire.org Git - thirdparty/squid.git/blame - src/esi/Context.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / esi / Context.h
CommitLineData
43ae1d95 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
43ae1d95 3 *
bbc27441
AJ
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.
43ae1d95 7 */
8
9#ifndef SQUID_ESICONTEXT_H
10#define SQUID_ESICONTEXT_H
11
0655fa4d 12#include "clientStream.h"
582c2af2 13#include "err_type.h"
602d9612
A
14#include "esi/Element.h"
15#include "esi/Parser.h"
f522f9b5 16#include "http/forward.h"
955394ce 17#include "http/StatusCode.h"
43ae1d95 18
924f73bc 19class ESIVarState;
43ae1d95 20class ClientHttpRequest;
21
43ae1d95 22/* ESIContext */
23
24class ESIContext : public esiTreeParent, public ESIParserClient
25{
5c2f68b7 26 CBDATA_CLASS(ESIContext);
43ae1d95 27
28public:
0655fa4d 29 typedef RefCount<ESIContext> Pointer;
a5488e5d 30 ESIContext() :
f53969cc
SM
31 thisNode(NULL),
32 http(NULL),
33 errorpage(ERR_NONE),
34 errorstatus(Http::scNone),
35 errormessage(NULL),
36 rep(NULL),
37 outbound_offset(0),
38 readpos(0),
39 pos(0),
40 varState(NULL),
41 cachedASTInUse(false),
42 reading_(true),
43 processing(false) {
a5488e5d
AJ
44 memset(&flags, 0, sizeof(flags));
45 }
43ae1d95 46
47 ~ESIContext();
48
49 enum esiKick_t {
50 ESI_KICK_FAILED,
51 ESI_KICK_PENDING,
52 ESI_KICK_SENT,
53 ESI_KICK_INPROGRESS
54 };
55
56 /* when esi processing completes */
57 void provideData(ESISegment::Pointer, ESIElement *source);
924f73bc 58 void fail (ESIElement *source, char const*anError = NULL);
43ae1d95 59 void startRead();
60 void finishRead();
61 bool reading() const;
62 void setError();
924f73bc 63 void setErrorMessage(char const *);
43ae1d95 64
65 void addStackElement (ESIElement::Pointer element);
66 void addLiteral (const char *s, int len);
67
68 void finishChildren ();
69
70 clientStreamNode *thisNode; /* our stream node */
71 /* the request we are processing. HMM: cbdataReferencing this will result
72 * in a circular reference, so we don't. Note: we are automatically freed
73 * when it is, so thats ok. */
74 ClientHttpRequest *http;
75
26ac0430 76 struct {
3d0ac046
HN
77 int passthrough:1;
78 int oktosend:1;
79 int finished:1;
43ae1d95 80
61beade2 81 /* an error has occurred, send full body replies
43ae1d95 82 * regardless. Note that we don't fail midstream
83 * because we buffer until we can not fail
84 */
3d0ac046 85 int error:1;
43ae1d95 86
3d0ac046
HN
87 int finishedtemplate:1; /* we've read the entire template */
88 int clientwantsdata:1; /* we need to satisfy a read request */
89 int kicked:1; /* note on reentering the kick routine */
90 int detached:1; /* our downstream has detached */
91 } flags;
43ae1d95 92
43ae1d95 93 err_type errorpage; /* if we error what page to use */
955394ce 94 Http::StatusCode errorstatus; /* if we error, what code to return */
43ae1d95 95 char *errormessage; /* error to pass to error page */
f522f9b5 96 HttpReplyPointer rep; /* buffered until we pass data downstream */
43ae1d95 97 ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */
98 ESISegment::Pointer incoming;
99 /* processed data we are waiting to send, or for
26ac0430 100 * potential errors to be resolved
43ae1d95 101 */
102 ESISegment::Pointer outbound;
103 ESISegment::Pointer outboundtail; /* our write segment */
104 /* the offset to the next character to send -
26ac0430
AJ
105 * non zero if we haven't sent the entire segment
106 * for some reason
43ae1d95 107 */
108 size_t outbound_offset;
e4d72ba2 109 int64_t readpos; /* the logical position we are reading from */
110 int64_t pos; /* the logical position of outbound_offset in the data stream */
43ae1d95 111
112 class ParserState
113 {
114
115 public:
116 ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */
117 int stackdepth; /* self explanatory */
118 ESIParser::Pointer theParser;
119 ESIElement::Pointer top();
120 void init (ESIParserClient *);
121 bool inited() const;
122 ParserState();
123 void freeResources();
124 void popAll();
3d0ac046 125 int parsing:1; /* libexpat is not reentrant on the same context */
43ae1d95 126
127 private:
128 bool inited_;
129 }
130
131 parserState; /* todo factor this off somewhere else; */
924f73bc 132 ESIVarState *varState;
43ae1d95 133 ESIElement::Pointer tree;
134
135 esiKick_t kick ();
136 RefCount<ESIContext> cbdataLocker;
137 bool failed() const {return flags.error != 0;}
138
139 bool cachedASTInUse;
140
141private:
43ae1d95 142 void fail ();
143 void freeResources();
144 void fixupOutboundTail();
145 void trimBlanks();
146 size_t send ();
147 bool reading_;
148 void appendOutboundData(ESISegment::Pointer theData);
149 esiProcessResult_t process ();
150 void parse();
151 void parseOneBuffer();
152 void updateCachedAST();
153 bool hasCachedAST() const;
154 void getCachedAST();
155 virtual void start(const char *el, const char **attr, size_t attrCount);
156 virtual void end(const char *el);
157 virtual void parserDefault (const char *s, int len);
158 virtual void parserComment (const char *s);
159 bool processing;
160};
161
162#endif /* SQUID_ESICONTEXT_H */
f53969cc 163