]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Context.h
merge from SslServerCertValidator r12332
[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():reading_(true) {}
54
55 ~ESIContext();
56
57 enum esiKick_t {
58 ESI_KICK_FAILED,
59 ESI_KICK_PENDING,
60 ESI_KICK_SENT,
61 ESI_KICK_INPROGRESS
62 };
63
64 /* when esi processing completes */
65 void provideData(ESISegment::Pointer, ESIElement *source);
66 void fail (ESIElement *source, char const*anError = NULL);
67 void startRead();
68 void finishRead();
69 bool reading() const;
70 void setError();
71 void setErrorMessage(char const *);
72
73 void addStackElement (ESIElement::Pointer element);
74 void addLiteral (const char *s, int len);
75
76 void finishChildren ();
77
78 clientStreamNode *thisNode; /* our stream node */
79 /* the request we are processing. HMM: cbdataReferencing this will result
80 * in a circular reference, so we don't. Note: we are automatically freed
81 * when it is, so thats ok. */
82 ClientHttpRequest *http;
83
84 struct {
85 int passthrough:1;
86 int oktosend:1;
87 int finished:1;
88
89 /* an error has occured, send full body replies
90 * regardless. Note that we don't fail midstream
91 * because we buffer until we can not fail
92 */
93 int error:1;
94
95 int finishedtemplate:1; /* we've read the entire template */
96 int clientwantsdata:1; /* we need to satisfy a read request */
97 int kicked:1; /* note on reentering the kick routine */
98 int detached:1; /* our downstream has detached */
99 } flags;
100
101 err_type errorpage; /* if we error what page to use */
102 http_status errorstatus; /* if we error, what code to return */
103 char *errormessage; /* error to pass to error page */
104 HttpReply *rep; /* buffered until we pass data downstream */
105 ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */
106 ESISegment::Pointer incoming;
107 /* processed data we are waiting to send, or for
108 * potential errors to be resolved
109 */
110 ESISegment::Pointer outbound;
111 ESISegment::Pointer outboundtail; /* our write segment */
112 /* the offset to the next character to send -
113 * non zero if we haven't sent the entire segment
114 * for some reason
115 */
116 size_t outbound_offset;
117 int64_t readpos; /* the logical position we are reading from */
118 int64_t pos; /* the logical position of outbound_offset in the data stream */
119
120 class ParserState
121 {
122
123 public:
124 ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */
125 int stackdepth; /* self explanatory */
126 ESIParser::Pointer theParser;
127 ESIElement::Pointer top();
128 void init (ESIParserClient *);
129 bool inited() const;
130 ParserState();
131 void freeResources();
132 void popAll();
133 int parsing:1; /* libexpat is not reentrant on the same context */
134
135 private:
136 bool inited_;
137 }
138
139 parserState; /* todo factor this off somewhere else; */
140 ESIVarState *varState;
141 ESIElement::Pointer tree;
142
143 esiKick_t kick ();
144 RefCount<ESIContext> cbdataLocker;
145 bool failed() const {return flags.error != 0;}
146
147 bool cachedASTInUse;
148
149 private:
150 void fail ();
151 void freeResources();
152 void fixupOutboundTail();
153 void trimBlanks();
154 size_t send ();
155 bool reading_;
156 void appendOutboundData(ESISegment::Pointer theData);
157 esiProcessResult_t process ();
158 void parse();
159 void parseOneBuffer();
160 void updateCachedAST();
161 bool hasCachedAST() const;
162 void getCachedAST();
163 virtual void start(const char *el, const char **attr, size_t attrCount);
164 virtual void end(const char *el);
165 virtual void parserDefault (const char *s, int len);
166 virtual void parserComment (const char *s);
167 bool processing;
168
169 CBDATA_CLASS(ESIContext);
170 };
171
172 #endif /* SQUID_ESICONTEXT_H */