]>
Commit | Line | Data |
---|---|---|
cd304fc2 | 1 | |
2 | /* | |
585ab260 | 3 | * $Id: Server.h,v 1.9 2007/08/09 23:30:52 rousskov Exp $ |
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. | |
23 | * | |
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. | |
28 | * | |
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 | */ | |
34 | ||
35 | /* | |
5f8252d2 | 36 | * ServerStateData is a common base for server-side classes such as |
37 | * HttpStateData and FtpStateData. All such classes must be able to | |
38 | * consume request bodies from the client-side or ICAP producer, adapt | |
39 | * virgin responses using ICAP, and provide the client-side consumer with | |
40 | * responses. | |
41 | * | |
42 | * TODO: Rename to ServerStateDataInfoRecordHandler. | |
cd304fc2 | 43 | */ |
44 | ||
5f8252d2 | 45 | |
cd304fc2 | 46 | #ifndef SQUID_SERVER_H |
47 | #define SQUID_SERVER_H | |
48 | ||
49 | #include "StoreIOBuffer.h" | |
50 | #include "forward.h" | |
5f8252d2 | 51 | #include "BodyPipe.h" |
cd304fc2 | 52 | |
53 | #if ICAP_CLIENT | |
54 | #include "ICAP/ICAPServiceRep.h" | |
5f8252d2 | 55 | #include "ICAP/ICAPInitiator.h" |
cd304fc2 | 56 | |
57 | class ICAPAccessCheck; | |
58 | #endif | |
59 | ||
5f8252d2 | 60 | class ServerStateData: |
61 | #if ICAP_CLIENT | |
62 | public ICAPInitiator, | |
63 | public BodyProducer, | |
64 | #endif | |
65 | public BodyConsumer | |
cd304fc2 | 66 | { |
67 | ||
68 | public: | |
69 | ServerStateData(FwdState *); | |
70 | virtual ~ServerStateData(); | |
71 | ||
5f8252d2 | 72 | // returns primary or "request data connection" fd |
73 | virtual int dataDescriptor() const = 0; | |
74 | ||
75 | // BodyConsumer: consume request body or adapted response body. | |
76 | // The implementation just calls the corresponding HTTP or ICAP handle*() | |
77 | // method, depending on the pipe. | |
78 | virtual void noteMoreBodyDataAvailable(BodyPipe &); | |
79 | virtual void noteBodyProductionEnded(BodyPipe &); | |
80 | virtual void noteBodyProducerAborted(BodyPipe &); | |
81 | ||
82 | // read response data from the network | |
83 | virtual void maybeReadVirginBody() = 0; | |
84 | ||
85 | // abnormal transaction termination; reason is for debugging only | |
86 | virtual void abortTransaction(const char *reason) = 0; | |
87 | ||
7c4e4e7f | 88 | // a hack to reach HttpStateData::orignal_request |
89 | virtual HttpRequest *originalRequest(); | |
5f8252d2 | 90 | |
7dc79973 | 91 | #if ICAP_CLIENT |
92 | void icapAclCheckDone(ICAPServiceRep::Pointer); | |
93 | static void icapAclCheckDoneWrapper(ICAPServiceRep::Pointer service, void *data); | |
94 | ||
5f8252d2 | 95 | // ICAPInitiator: start an ICAP transaction and receive adapted headers. |
9d4d7c5e | 96 | virtual void noteIcapAnswer(HttpMsg *message); |
97 | virtual void noteIcapQueryAbort(bool final); | |
5f8252d2 | 98 | |
99 | // BodyProducer: provide virgin response body to ICAP. | |
100 | virtual void noteMoreBodySpaceAvailable(BodyPipe &); | |
101 | virtual void noteBodyConsumerAborted(BodyPipe &); | |
cd304fc2 | 102 | #endif |
7c4e4e7f | 103 | virtual void processReplyBody() = 0; |
cd304fc2 | 104 | |
5f8252d2 | 105 | public: // should be protected |
106 | void serverComplete(); // call when no server communication is expected | |
107 | ||
7dc79973 | 108 | private: |
109 | void serverComplete2(); // Continuation of serverComplete | |
110 | bool completed; // serverComplete() has been called | |
111 | ||
5f8252d2 | 112 | protected: |
113 | // kids customize these | |
114 | virtual void haveParsedReplyHeaders(); // default does nothing | |
115 | virtual void completeForwarding(); // default calls fwd->complete() | |
116 | ||
117 | // BodyConsumer for HTTP: consume request body. | |
118 | void handleMoreRequestBodyAvailable(); | |
119 | void handleRequestBodyProductionEnded(); | |
120 | virtual void handleRequestBodyProducerAborted() = 0; | |
121 | ||
122 | // sending of the request body to the server | |
123 | void sendMoreRequestBody(); | |
124 | // has body; kids overwrite to increment I/O stats counters | |
125 | virtual void sentRequestBody(int fd, size_t size, comm_err_t errflag) = 0; | |
126 | virtual void doneSendingRequestBody() = 0; | |
127 | static IOCB sentRequestBodyWrapper; | |
128 | ||
129 | virtual void closeServer() = 0; // end communication with the server | |
130 | virtual bool doneWithServer() const = 0; // did we end communication? | |
131 | ||
132 | // Entry-dependent callbacks use this check to quit if the entry went bad | |
133 | bool abortOnBadEntry(const char *abortReason); | |
134 | ||
135 | #if ICAP_CLIENT | |
136 | bool startIcap(ICAPServiceRep::Pointer, HttpRequest *cause); | |
bc81cb2b | 137 | void adaptVirginReplyBody(const char *buf, ssize_t len); |
5f8252d2 | 138 | void cleanIcap(); |
139 | virtual bool doneWithIcap() const; // did we end ICAP communication? | |
140 | ||
141 | // BodyConsumer for ICAP: consume adapted response body. | |
142 | void handleMoreAdaptedBodyAvailable(); | |
143 | void handleAdaptedBodyProductionEnded(); | |
144 | void handleAdaptedBodyProducerAborted(); | |
145 | ||
146 | void handleIcapCompleted(); | |
9d4d7c5e | 147 | void handleIcapAborted(bool bypassable = false); |
5f8252d2 | 148 | #endif |
149 | ||
7dc79973 | 150 | protected: |
585ab260 | 151 | const HttpReply *virginReply() const; |
152 | HttpReply *virginReply(); | |
153 | HttpReply *setVirginReply(HttpReply *r); | |
154 | ||
155 | HttpReply *finalReply(); | |
156 | HttpReply *setFinalReply(HttpReply *r); | |
157 | ||
7dc79973 | 158 | // Kids use these to stuff data into the response instead of messing with the entry directly |
585ab260 | 159 | void adaptOrFinalizeReply(); |
bc81cb2b | 160 | void addVirginReplyBody(const char *buf, ssize_t len); |
161 | void storeReplyBody(const char *buf, ssize_t len); | |
7dc79973 | 162 | size_t replyBodySpace(size_t space = 4096 * 10); |
163 | ||
164 | // These should be private | |
165 | off_t currentOffset; // Our current offset in the StoreEntry | |
166 | MemBuf *responseBodyBuffer; // Data temporarily buffered for ICAP | |
167 | ||
5f8252d2 | 168 | public: // should not be |
cd304fc2 | 169 | StoreEntry *entry; |
170 | FwdState::Pointer fwd; | |
171 | HttpRequest *request; | |
cd304fc2 | 172 | |
173 | protected: | |
5f8252d2 | 174 | BodyPipe::Pointer requestBodySource; // to consume request body |
175 | IOCB *requestSender; // set if we are expecting comm_write to call us back | |
176 | ||
cd304fc2 | 177 | #if ICAP_CLIENT |
5f8252d2 | 178 | BodyPipe::Pointer virginBodyDestination; // to provide virgin response body |
9d4d7c5e | 179 | ICAPInitiate *adaptedHeadSource; // to get adapted response headers |
5f8252d2 | 180 | BodyPipe::Pointer adaptedBodySource; // to consume adated response body |
cd304fc2 | 181 | |
cd304fc2 | 182 | bool icapAccessCheckPending; |
bc81cb2b | 183 | bool startedIcap; |
cd304fc2 | 184 | #endif |
185 | ||
5f8252d2 | 186 | private: |
187 | void quitIfAllDone(); // successful termination | |
585ab260 | 188 | |
189 | HttpReply *theVirginReply; // reply received from the origin server | |
190 | HttpReply *theFinalReply; // adapted reply from ICAP or virgin reply | |
cd304fc2 | 191 | }; |
192 | ||
193 | #endif /* SQUID_SERVER_H */ |