]>
Commit | Line | Data |
---|---|---|
cd304fc2 | 1 | |
2 | /* | |
5f8252d2 | 3 | * $Id: Server.h,v 1.3 2007/04/06 04:50:05 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" |
56 | #include "ICAP/ICAPModXact.h" | |
cd304fc2 | 57 | |
58 | class ICAPAccessCheck; | |
59 | #endif | |
60 | ||
5f8252d2 | 61 | class ServerStateData: |
62 | #if ICAP_CLIENT | |
63 | public ICAPInitiator, | |
64 | public BodyProducer, | |
65 | #endif | |
66 | public BodyConsumer | |
cd304fc2 | 67 | { |
68 | ||
69 | public: | |
70 | ServerStateData(FwdState *); | |
71 | virtual ~ServerStateData(); | |
72 | ||
5f8252d2 | 73 | // returns primary or "request data connection" fd |
74 | virtual int dataDescriptor() const = 0; | |
75 | ||
76 | // BodyConsumer: consume request body or adapted response body. | |
77 | // The implementation just calls the corresponding HTTP or ICAP handle*() | |
78 | // method, depending on the pipe. | |
79 | virtual void noteMoreBodyDataAvailable(BodyPipe &); | |
80 | virtual void noteBodyProductionEnded(BodyPipe &); | |
81 | virtual void noteBodyProducerAborted(BodyPipe &); | |
82 | ||
83 | // read response data from the network | |
84 | virtual void maybeReadVirginBody() = 0; | |
85 | ||
86 | // abnormal transaction termination; reason is for debugging only | |
87 | virtual void abortTransaction(const char *reason) = 0; | |
88 | ||
cd304fc2 | 89 | #if ICAP_CLIENT |
cd304fc2 | 90 | virtual void icapAclCheckDone(ICAPServiceRep::Pointer) = 0; |
5f8252d2 | 91 | |
92 | // ICAPInitiator: start an ICAP transaction and receive adapted headers. | |
93 | virtual void noteIcapHeadersAdapted(); | |
94 | virtual void noteIcapHeadersAborted(); | |
95 | ||
96 | // BodyProducer: provide virgin response body to ICAP. | |
97 | virtual void noteMoreBodySpaceAvailable(BodyPipe &); | |
98 | virtual void noteBodyConsumerAborted(BodyPipe &); | |
cd304fc2 | 99 | #endif |
100 | ||
5f8252d2 | 101 | public: // should be protected |
102 | void serverComplete(); // call when no server communication is expected | |
103 | ||
104 | protected: | |
105 | // kids customize these | |
106 | virtual void haveParsedReplyHeaders(); // default does nothing | |
107 | virtual void completeForwarding(); // default calls fwd->complete() | |
108 | ||
109 | // BodyConsumer for HTTP: consume request body. | |
110 | void handleMoreRequestBodyAvailable(); | |
111 | void handleRequestBodyProductionEnded(); | |
112 | virtual void handleRequestBodyProducerAborted() = 0; | |
113 | ||
114 | // sending of the request body to the server | |
115 | void sendMoreRequestBody(); | |
116 | // has body; kids overwrite to increment I/O stats counters | |
117 | virtual void sentRequestBody(int fd, size_t size, comm_err_t errflag) = 0; | |
118 | virtual void doneSendingRequestBody() = 0; | |
119 | static IOCB sentRequestBodyWrapper; | |
120 | ||
121 | virtual void closeServer() = 0; // end communication with the server | |
122 | virtual bool doneWithServer() const = 0; // did we end communication? | |
123 | ||
124 | // Entry-dependent callbacks use this check to quit if the entry went bad | |
125 | bool abortOnBadEntry(const char *abortReason); | |
126 | ||
127 | #if ICAP_CLIENT | |
128 | bool startIcap(ICAPServiceRep::Pointer, HttpRequest *cause); | |
129 | void cleanIcap(); | |
130 | virtual bool doneWithIcap() const; // did we end ICAP communication? | |
131 | ||
132 | // BodyConsumer for ICAP: consume adapted response body. | |
133 | void handleMoreAdaptedBodyAvailable(); | |
134 | void handleAdaptedBodyProductionEnded(); | |
135 | void handleAdaptedBodyProducerAborted(); | |
136 | ||
137 | void handleIcapCompleted(); | |
138 | void handleIcapAborted(); | |
139 | #endif | |
140 | ||
141 | public: // should not be | |
cd304fc2 | 142 | StoreEntry *entry; |
143 | FwdState::Pointer fwd; | |
144 | HttpRequest *request; | |
145 | HttpReply *reply; | |
146 | ||
147 | protected: | |
5f8252d2 | 148 | BodyPipe::Pointer requestBodySource; // to consume request body |
149 | IOCB *requestSender; // set if we are expecting comm_write to call us back | |
150 | ||
cd304fc2 | 151 | #if ICAP_CLIENT |
5f8252d2 | 152 | BodyPipe::Pointer virginBodyDestination; // to provide virgin response body |
153 | ICAPModXact::Pointer adaptedHeadSource; // to get adapted response headers | |
154 | BodyPipe::Pointer adaptedBodySource; // to consume adated response body | |
cd304fc2 | 155 | |
cd304fc2 | 156 | bool icapAccessCheckPending; |
cd304fc2 | 157 | #endif |
158 | ||
5f8252d2 | 159 | private: |
160 | void quitIfAllDone(); // successful termination | |
161 | ||
cd304fc2 | 162 | }; |
163 | ||
164 | #endif /* SQUID_SERVER_H */ |