]>
Commit | Line | Data |
---|---|---|
cd304fc2 | 1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
cd304fc2 | 4 | * |
5 | * AUTHOR: Duane Wessels | |
6 | * | |
7 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
8 | * ---------------------------------------------------------- | |
9 | * | |
10 | * Squid is the result of efforts by numerous individuals from | |
11 | * the Internet community; see the CONTRIBUTORS file for full | |
12 | * details. Many organizations have provided support for Squid's | |
13 | * development; see the SPONSORS file for full details. Squid is | |
14 | * Copyrighted (C) 2001 by the Regents of the University of | |
15 | * California; see the COPYRIGHT file for full details. Squid | |
16 | * incorporates software developed and/or copyrighted by other | |
17 | * sources; see the CREDITS file for full details. | |
18 | * | |
19 | * This program is free software; you can redistribute it and/or modify | |
20 | * it under the terms of the GNU General Public License as published by | |
21 | * the Free Software Foundation; either version 2 of the License, or | |
22 | * (at your option) any later version. | |
9e008dda | 23 | * |
cd304fc2 | 24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 | * GNU General Public License for more details. | |
9e008dda | 28 | * |
cd304fc2 | 29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program; if not, write to the Free Software | |
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
32 | * | |
33 | */ | |
cd304fc2 | 34 | #ifndef SQUID_SERVER_H |
35 | #define SQUID_SERVER_H | |
36 | ||
37 | #include "StoreIOBuffer.h" | |
38 | #include "forward.h" | |
5f8252d2 | 39 | #include "BodyPipe.h" |
dc56a9b1 | 40 | #include "ICAP/AsyncJob.h" |
41 | #include "CommCalls.h" | |
cd304fc2 | 42 | |
a83c6ed6 AR |
43 | #if USE_ADAPTATION |
44 | #include "adaptation/forward.h" | |
45 | #include "adaptation/Initiator.h" | |
cd304fc2 | 46 | #endif |
47 | ||
e0459b28 AJ |
48 | /** |
49 | * ServerStateData is a common base for server-side classes such as | |
50 | * HttpStateData and FtpStateData. All such classes must be able to | |
51 | * consume request bodies from the client-side or ICAP producer, adapt | |
52 | * virgin responses using ICAP, and provide the client-side consumer with | |
53 | * responses. | |
54 | * | |
55 | \todo TODO: Rename to ServerStateDataInfoRecordHandler. | |
56 | */ | |
5f8252d2 | 57 | class ServerStateData: |
a83c6ed6 | 58 | #if USE_ADAPTATION |
9e008dda AJ |
59 | public Adaptation::Initiator, |
60 | public BodyProducer, | |
5f8252d2 | 61 | #endif |
9e008dda | 62 | public BodyConsumer |
cd304fc2 | 63 | { |
64 | ||
65 | public: | |
66 | ServerStateData(FwdState *); | |
67 | virtual ~ServerStateData(); | |
68 | ||
e0459b28 | 69 | /// \return primary or "request data connection" fd |
9e008dda | 70 | virtual int dataDescriptor() const = 0; |
5f8252d2 | 71 | |
72 | // BodyConsumer: consume request body or adapted response body. | |
73 | // The implementation just calls the corresponding HTTP or ICAP handle*() | |
74 | // method, depending on the pipe. | |
dc56a9b1 | 75 | virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer); |
76 | virtual void noteBodyProductionEnded(BodyPipe::Pointer); | |
77 | virtual void noteBodyProducerAborted(BodyPipe::Pointer); | |
5f8252d2 | 78 | |
e0459b28 | 79 | /// read response data from the network |
5f8252d2 | 80 | virtual void maybeReadVirginBody() = 0; |
81 | ||
e0459b28 | 82 | /// abnormal transaction termination; reason is for debugging only |
5f8252d2 | 83 | virtual void abortTransaction(const char *reason) = 0; |
84 | ||
e0459b28 | 85 | /// a hack to reach HttpStateData::orignal_request |
7c4e4e7f | 86 | virtual HttpRequest *originalRequest(); |
5f8252d2 | 87 | |
a83c6ed6 AR |
88 | #if USE_ADAPTATION |
89 | void adaptationAclCheckDone(Adaptation::ServicePointer service); | |
90 | static void adaptationAclCheckDoneWrapper(Adaptation::ServicePointer service, void *data); | |
7dc79973 | 91 | |
5f8252d2 | 92 | // ICAPInitiator: start an ICAP transaction and receive adapted headers. |
a83c6ed6 AR |
93 | virtual void noteAdaptationAnswer(HttpMsg *message); |
94 | virtual void noteAdaptationQueryAbort(bool final); | |
5f8252d2 | 95 | |
96 | // BodyProducer: provide virgin response body to ICAP. | |
dc56a9b1 | 97 | virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer ); |
98 | virtual void noteBodyConsumerAborted(BodyPipe::Pointer ); | |
cd304fc2 | 99 | #endif |
7c4e4e7f | 100 | virtual void processReplyBody() = 0; |
cd304fc2 | 101 | |
dc56a9b1 | 102 | //AsyncJob virtual methods |
49918309 | 103 | virtual void swanSong(); |
9e008dda AJ |
104 | virtual bool doneAll() const { |
105 | return | |
a83c6ed6 | 106 | #if USE_ADAPTATION |
9e008dda AJ |
107 | Adaptation::Initiator::doneAll() && |
108 | BodyProducer::doneAll() && | |
dc56a9b1 | 109 | #endif |
9e008dda AJ |
110 | BodyConsumer::doneAll() && false; |
111 | } | |
dc56a9b1 | 112 | |
5f8252d2 | 113 | public: // should be protected |
e0459b28 | 114 | void serverComplete(); /**< call when no server communication is expected */ |
5f8252d2 | 115 | |
7dc79973 | 116 | private: |
e0459b28 AJ |
117 | void serverComplete2(); /**< Continuation of serverComplete */ |
118 | bool completed; /**< serverComplete() has been called */ | |
7dc79973 | 119 | |
5f8252d2 | 120 | protected: |
121 | // kids customize these | |
c1520b67 | 122 | virtual void haveParsedReplyHeaders(); /**< called when got final headers */ |
e0459b28 | 123 | virtual void completeForwarding(); /**< default calls fwd->complete() */ |
5f8252d2 | 124 | |
125 | // BodyConsumer for HTTP: consume request body. | |
123ec4de | 126 | bool startRequestBodyFlow(); |
5f8252d2 | 127 | void handleMoreRequestBodyAvailable(); |
128 | void handleRequestBodyProductionEnded(); | |
129 | virtual void handleRequestBodyProducerAborted() = 0; | |
130 | ||
131 | // sending of the request body to the server | |
132 | void sendMoreRequestBody(); | |
133 | // has body; kids overwrite to increment I/O stats counters | |
dc56a9b1 | 134 | virtual void sentRequestBody(const CommIoCbParams &io) = 0; |
5f8252d2 | 135 | virtual void doneSendingRequestBody() = 0; |
5f8252d2 | 136 | |
e0459b28 AJ |
137 | virtual void closeServer() = 0; /**< end communication with the server */ |
138 | virtual bool doneWithServer() const = 0; /**< did we end communication? */ | |
5f8252d2 | 139 | |
e0459b28 | 140 | /// Entry-dependent callbacks use this check to quit if the entry went bad |
5f8252d2 | 141 | bool abortOnBadEntry(const char *abortReason); |
142 | ||
a83c6ed6 AR |
143 | #if USE_ADAPTATION |
144 | bool startAdaptation(Adaptation::ServicePointer service, HttpRequest *cause); | |
bc81cb2b | 145 | void adaptVirginReplyBody(const char *buf, ssize_t len); |
a83c6ed6 | 146 | void cleanAdaptation(); |
e0459b28 | 147 | virtual bool doneWithAdaptation() const; /**< did we end ICAP communication? */ |
5f8252d2 | 148 | |
149 | // BodyConsumer for ICAP: consume adapted response body. | |
150 | void handleMoreAdaptedBodyAvailable(); | |
151 | void handleAdaptedBodyProductionEnded(); | |
152 | void handleAdaptedBodyProducerAborted(); | |
153 | ||
a83c6ed6 AR |
154 | void handleAdaptationCompleted(); |
155 | void handleAdaptationAborted(bool bypassable = false); | |
5f8252d2 | 156 | #endif |
157 | ||
7dc79973 | 158 | protected: |
585ab260 | 159 | const HttpReply *virginReply() const; |
160 | HttpReply *virginReply(); | |
161 | HttpReply *setVirginReply(HttpReply *r); | |
162 | ||
163 | HttpReply *finalReply(); | |
164 | HttpReply *setFinalReply(HttpReply *r); | |
165 | ||
7dc79973 | 166 | // Kids use these to stuff data into the response instead of messing with the entry directly |
585ab260 | 167 | void adaptOrFinalizeReply(); |
bc81cb2b | 168 | void addVirginReplyBody(const char *buf, ssize_t len); |
169 | void storeReplyBody(const char *buf, ssize_t len); | |
7dc79973 | 170 | size_t replyBodySpace(size_t space = 4096 * 10); |
171 | ||
172 | // These should be private | |
e0459b28 AJ |
173 | int64_t currentOffset; /**< Our current offset in the StoreEntry */ |
174 | MemBuf *responseBodyBuffer; /**< Data temporarily buffered for ICAP */ | |
7dc79973 | 175 | |
5f8252d2 | 176 | public: // should not be |
cd304fc2 | 177 | StoreEntry *entry; |
178 | FwdState::Pointer fwd; | |
179 | HttpRequest *request; | |
cd304fc2 | 180 | |
181 | protected: | |
e0459b28 AJ |
182 | BodyPipe::Pointer requestBodySource; /**< to consume request body */ |
183 | AsyncCall::Pointer requestSender; /**< set if we are expecting comm_write to call us back */ | |
5f8252d2 | 184 | |
a83c6ed6 | 185 | #if USE_ADAPTATION |
e0459b28 AJ |
186 | BodyPipe::Pointer virginBodyDestination; /**< to provide virgin response body */ |
187 | Adaptation::Initiate *adaptedHeadSource; /**< to get adapted response headers */ | |
188 | BodyPipe::Pointer adaptedBodySource; /**< to consume adated response body */ | |
cd304fc2 | 189 | |
a83c6ed6 AR |
190 | bool adaptationAccessCheckPending; |
191 | bool startedAdaptation; | |
cd304fc2 | 192 | #endif |
193 | ||
5f8252d2 | 194 | private: |
e0459b28 | 195 | void quitIfAllDone(); /**< successful termination */ |
47416555 | 196 | void sendBodyIsTooLargeError(); |
c1520b67 | 197 | void maybePurgeOthers(); |
585ab260 | 198 | |
e0459b28 AJ |
199 | HttpReply *theVirginReply; /**< reply received from the origin server */ |
200 | HttpReply *theFinalReply; /**< adapted reply from ICAP or virgin reply */ | |
cd304fc2 | 201 | }; |
202 | ||
203 | #endif /* SQUID_SERVER_H */ |