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