3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
32 #ifndef SQUID_SERVER_H
33 #define SQUID_SERVER_H
35 #include "base/AsyncJob.h"
37 #include "CommCalls.h"
39 #include "StoreIOBuffer.h"
41 #include "adaptation/forward.h"
42 #include "adaptation/Initiator.h"
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
55 \todo TODO: Rename to ServerStateDataInfoRecordHandler.
57 class ServerStateData
:
59 public Adaptation::Initiator
,
66 ServerStateData(FwdState
*);
67 virtual ~ServerStateData();
69 /// \return primary or "request data connection"
70 virtual const Comm::ConnectionPointer
& dataConnection() const = 0;
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.
75 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer
);
76 virtual void noteBodyProductionEnded(BodyPipe::Pointer
);
77 virtual void noteBodyProducerAborted(BodyPipe::Pointer
);
79 /// read response data from the network
80 virtual void maybeReadVirginBody() = 0;
82 /// abnormal transaction termination; reason is for debugging only
83 virtual void abortTransaction(const char *reason
) = 0;
85 /// a hack to reach HttpStateData::orignal_request
86 virtual HttpRequest
*originalRequest();
89 // Adaptation::Initiator API: start an ICAP transaction and receive adapted headers.
90 virtual void noteAdaptationAnswer(const Adaptation::Answer
&answer
);
91 virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group
);
93 // BodyProducer: provide virgin response body to ICAP.
94 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer
);
95 virtual void noteBodyConsumerAborted(BodyPipe::Pointer
);
97 virtual bool getMoreRequestBody(MemBuf
&buf
);
98 virtual void processReplyBody() = 0;
100 //AsyncJob virtual methods
101 virtual void swanSong();
102 virtual bool doneAll() const;
104 public: // should be protected
105 void serverComplete(); /**< call when no server communication is expected */
108 void serverComplete2(); /**< Continuation of serverComplete */
109 bool completed
; /**< serverComplete() has been called */
112 // kids customize these
113 virtual void haveParsedReplyHeaders(); /**< called when got final headers */
114 virtual void completeForwarding(); /**< default calls fwd->complete() */
116 // BodyConsumer for HTTP: consume request body.
117 bool startRequestBodyFlow();
118 void handleMoreRequestBodyAvailable();
119 void handleRequestBodyProductionEnded();
120 virtual void handleRequestBodyProducerAborted() = 0;
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(const CommIoCbParams
&io
) = 0;
126 virtual void doneSendingRequestBody() = 0;
128 virtual void closeServer() = 0; /**< end communication with the server */
129 virtual bool doneWithServer() const = 0; /**< did we end communication? */
131 /// Entry-dependent callbacks use this check to quit if the entry went bad
132 bool abortOnBadEntry(const char *abortReason
);
135 void startAdaptation(const Adaptation::ServiceGroupPointer
&group
, HttpRequest
*cause
);
136 void adaptVirginReplyBody(const char *buf
, ssize_t len
);
137 void cleanAdaptation();
138 virtual bool doneWithAdaptation() const; /**< did we end ICAP communication? */
140 // BodyConsumer for ICAP: consume adapted response body.
141 void handleMoreAdaptedBodyAvailable();
142 void handleAdaptedBodyProductionEnded();
143 void handleAdaptedBodyProducerAborted();
145 void handleAdaptedHeader(HttpMsg
*msg
);
146 void handleAdaptationCompleted();
147 void handleAdaptationBlocked(const Adaptation::Answer
&answer
);
148 void handleAdaptationAborted(bool bypassable
= false);
150 /// called by StoreEntry when it has more buffer space available
151 void resumeBodyStorage();
152 /// called when the entire adapted response body is consumed
153 void endAdaptedBodyConsumption();
157 const HttpReply
*virginReply() const;
158 HttpReply
*virginReply();
159 HttpReply
*setVirginReply(HttpReply
*r
);
161 HttpReply
*finalReply();
162 HttpReply
*setFinalReply(HttpReply
*r
);
164 // Kids use these to stuff data into the response instead of messing with the entry directly
165 void adaptOrFinalizeReply();
166 void addVirginReplyBody(const char *buf
, ssize_t len
);
167 void storeReplyBody(const char *buf
, ssize_t len
);
168 size_t replyBodySpace(const MemBuf
&readBuf
, const size_t minSpace
) const;
170 void adjustBodyBytesRead(const int64_t delta
);
172 // These should be private
173 int64_t currentOffset
; /**< Our current offset in the StoreEntry */
174 MemBuf
*responseBodyBuffer
; /**< Data temporarily buffered for ICAP */
176 public: // should not be
178 FwdState::Pointer fwd
;
179 HttpRequest
*request
;
182 BodyPipe::Pointer requestBodySource
; /**< to consume request body */
183 AsyncCall::Pointer requestSender
; /**< set if we are expecting Comm::Write to call us back */
186 BodyPipe::Pointer virginBodyDestination
; /**< to provide virgin response body */
187 CbcPointer
<Adaptation::Initiate
> adaptedHeadSource
; /**< to get adapted response headers */
188 BodyPipe::Pointer adaptedBodySource
; /**< to consume adated response body */
190 bool adaptationAccessCheckPending
;
191 bool startedAdaptation
;
193 bool receivedWholeRequestBody
; ///< handleRequestBodyProductionEnded called
196 void sendBodyIsTooLargeError();
197 void maybePurgeOthers();
199 HttpReply
*theVirginReply
; /**< reply received from the origin server */
200 HttpReply
*theFinalReply
; /**< adapted reply from ICAP or virgin reply */
203 #endif /* SQUID_SERVER_H */