]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Context.h
merge from parent SslServerCertValidator r12337
[thirdparty/squid.git] / src / esi / Context.h
1 /*
2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
30 */
31
32 #ifndef SQUID_ESICONTEXT_H
33 #define SQUID_ESICONTEXT_H
34
35 #include "esi/Parser.h"
36 #include "esi/Element.h"
37 #include "clientStream.h"
38 #include "err_type.h"
39 #include "HttpStatusCode.h"
40
41 class ESIVarState;
42 class ClientHttpRequest;
43
44 /* ESIContext */
45
46 class ESIContext : public esiTreeParent, public ESIParserClient
47 {
48
49 public:
50 typedef RefCount<ESIContext> Pointer;
51 void *operator new (size_t byteCount);
52 void operator delete (void *address);
53 ESIContext() :
54 thisNode(NULL),
55 http(NULL),
56 errorpage(ERR_NONE),
57 errorstatus(HTTP_STATUS_NONE),
58 errormessage(NULL),
59 rep(NULL),
60 outbound_offset(0),
61 readpos(0),
62 pos(0),
63 varState(NULL),
64 cachedASTInUse(false),
65 reading_(true),
66 processing(false) {
67 memset(&flags, 0, sizeof(flags));
68 }
69
70 ~ESIContext();
71
72 enum esiKick_t {
73 ESI_KICK_FAILED,
74 ESI_KICK_PENDING,
75 ESI_KICK_SENT,
76 ESI_KICK_INPROGRESS
77 };
78
79 /* when esi processing completes */
80 void provideData(ESISegment::Pointer, ESIElement *source);
81 void fail (ESIElement *source, char const*anError = NULL);
82 void startRead();
83 void finishRead();
84 bool reading() const;
85 void setError();
86 void setErrorMessage(char const *);
87
88 void addStackElement (ESIElement::Pointer element);
89 void addLiteral (const char *s, int len);
90
91 void finishChildren ();
92
93 clientStreamNode *thisNode; /* our stream node */
94 /* the request we are processing. HMM: cbdataReferencing this will result
95 * in a circular reference, so we don't. Note: we are automatically freed
96 * when it is, so thats ok. */
97 ClientHttpRequest *http;
98
99 struct {
100 int passthrough:1;
101 int oktosend:1;
102 int finished:1;
103
104 /* an error has occured, send full body replies
105 * regardless. Note that we don't fail midstream
106 * because we buffer until we can not fail
107 */
108 int error:1;
109
110 int finishedtemplate:1; /* we've read the entire template */
111 int clientwantsdata:1; /* we need to satisfy a read request */
112 int kicked:1; /* note on reentering the kick routine */
113 int detached:1; /* our downstream has detached */
114 } flags;
115
116 err_type errorpage; /* if we error what page to use */
117 http_status errorstatus; /* if we error, what code to return */
118 char *errormessage; /* error to pass to error page */
119 HttpReply *rep; /* buffered until we pass data downstream */
120 ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */
121 ESISegment::Pointer incoming;
122 /* processed data we are waiting to send, or for
123 * potential errors to be resolved
124 */
125 ESISegment::Pointer outbound;
126 ESISegment::Pointer outboundtail; /* our write segment */
127 /* the offset to the next character to send -
128 * non zero if we haven't sent the entire segment
129 * for some reason
130 */
131 size_t outbound_offset;
132 int64_t readpos; /* the logical position we are reading from */
133 int64_t pos; /* the logical position of outbound_offset in the data stream */
134
135 class ParserState
136 {
137
138 public:
139 ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */
140 int stackdepth; /* self explanatory */
141 ESIParser::Pointer theParser;
142 ESIElement::Pointer top();
143 void init (ESIParserClient *);
144 bool inited() const;
145 ParserState();
146 void freeResources();
147 void popAll();
148 int parsing:1; /* libexpat is not reentrant on the same context */
149
150 private:
151 bool inited_;
152 }
153
154 parserState; /* todo factor this off somewhere else; */
155 ESIVarState *varState;
156 ESIElement::Pointer tree;
157
158 esiKick_t kick ();
159 RefCount<ESIContext> cbdataLocker;
160 bool failed() const {return flags.error != 0;}
161
162 bool cachedASTInUse;
163
164 private:
165 void fail ();
166 void freeResources();
167 void fixupOutboundTail();
168 void trimBlanks();
169 size_t send ();
170 bool reading_;
171 void appendOutboundData(ESISegment::Pointer theData);
172 esiProcessResult_t process ();
173 void parse();
174 void parseOneBuffer();
175 void updateCachedAST();
176 bool hasCachedAST() const;
177 void getCachedAST();
178 virtual void start(const char *el, const char **attr, size_t attrCount);
179 virtual void end(const char *el);
180 virtual void parserDefault (const char *s, int len);
181 virtual void parserComment (const char *s);
182 bool processing;
183
184 CBDATA_CLASS(ESIContext);
185 };
186
187 #endif /* SQUID_ESICONTEXT_H */