]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Server.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / Server.h
1
2 /*
3 * AUTHOR: Duane Wessels
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.
21 *
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.
26 *
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 */
32 #ifndef SQUID_SERVER_H
33 #define SQUID_SERVER_H
34
35 #include "base/AsyncJob.h"
36 #include "BodyPipe.h"
37 #include "CommCalls.h"
38 #include "FwdState.h"
39 #include "StoreIOBuffer.h"
40 #if USE_ADAPTATION
41 #include "adaptation/forward.h"
42 #include "adaptation/Initiator.h"
43 #endif
44
45 class HttpMsg;
46 class HttpReply;
47
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 */
57 class ServerStateData:
58 #if USE_ADAPTATION
59 public Adaptation::Initiator,
60 public BodyProducer,
61 #endif
62 public BodyConsumer
63 {
64
65 public:
66 ServerStateData(FwdState *);
67 virtual ~ServerStateData();
68
69 /// \return primary or "request data connection"
70 virtual const Comm::ConnectionPointer & dataConnection() const = 0;
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.
75 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer);
76 virtual void noteBodyProductionEnded(BodyPipe::Pointer);
77 virtual void noteBodyProducerAborted(BodyPipe::Pointer);
78
79 /// read response data from the network
80 virtual void maybeReadVirginBody() = 0;
81
82 /// abnormal transaction termination; reason is for debugging only
83 virtual void abortTransaction(const char *reason) = 0;
84
85 /// a hack to reach HttpStateData::orignal_request
86 virtual HttpRequest *originalRequest();
87
88 #if USE_ADAPTATION
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);
92
93 // BodyProducer: provide virgin response body to ICAP.
94 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer );
95 virtual void noteBodyConsumerAborted(BodyPipe::Pointer );
96 #endif
97 virtual bool getMoreRequestBody(MemBuf &buf);
98 virtual void processReplyBody() = 0;
99
100 //AsyncJob virtual methods
101 virtual void swanSong();
102 virtual bool doneAll() const;
103
104 public: // should be protected
105 void serverComplete(); /**< call when no server communication is expected */
106
107 private:
108 void serverComplete2(); /**< Continuation of serverComplete */
109 bool completed; /**< serverComplete() has been called */
110
111 protected:
112 // kids customize these
113 virtual void haveParsedReplyHeaders(); /**< called when got final headers */
114 virtual void completeForwarding(); /**< default calls fwd->complete() */
115
116 // BodyConsumer for HTTP: consume request body.
117 bool startRequestBodyFlow();
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(const CommIoCbParams &io) = 0;
126 virtual void doneSendingRequestBody() = 0;
127
128 virtual void closeServer() = 0; /**< end communication with the server */
129 virtual bool doneWithServer() const = 0; /**< did we end communication? */
130
131 /// Entry-dependent callbacks use this check to quit if the entry went bad
132 bool abortOnBadEntry(const char *abortReason);
133
134 #if USE_ADAPTATION
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? */
139
140 // BodyConsumer for ICAP: consume adapted response body.
141 void handleMoreAdaptedBodyAvailable();
142 void handleAdaptedBodyProductionEnded();
143 void handleAdaptedBodyProducerAborted();
144
145 void handleAdaptedHeader(HttpMsg *msg);
146 void handleAdaptationCompleted();
147 void handleAdaptationBlocked(const Adaptation::Answer &answer);
148 void handleAdaptationAborted(bool bypassable = false);
149
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();
154 #endif
155
156 protected:
157 const HttpReply *virginReply() const;
158 HttpReply *virginReply();
159 HttpReply *setVirginReply(HttpReply *r);
160
161 HttpReply *finalReply();
162 HttpReply *setFinalReply(HttpReply *r);
163
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;
169
170 void adjustBodyBytesRead(const int64_t delta);
171
172 // These should be private
173 int64_t currentOffset; /**< Our current offset in the StoreEntry */
174 MemBuf *responseBodyBuffer; /**< Data temporarily buffered for ICAP */
175
176 public: // should not be
177 StoreEntry *entry;
178 FwdState::Pointer fwd;
179 HttpRequest *request;
180
181 protected:
182 BodyPipe::Pointer requestBodySource; /**< to consume request body */
183 AsyncCall::Pointer requestSender; /**< set if we are expecting Comm::Write to call us back */
184
185 #if USE_ADAPTATION
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 */
189
190 bool adaptationAccessCheckPending;
191 bool startedAdaptation;
192 #endif
193 bool receivedWholeRequestBody; ///< handleRequestBodyProductionEnded called
194
195 private:
196 void sendBodyIsTooLargeError();
197 void maybePurgeOthers();
198
199 HttpReply *theVirginReply; /**< reply received from the origin server */
200 HttpReply *theFinalReply; /**< adapted reply from ICAP or virgin reply */
201 };
202
203 #endif /* SQUID_SERVER_H */