]> git.ipfire.org Git - thirdparty/squid.git/blame_incremental - src/Server.h
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / Server.h
... / ...
CommitLineData
1
2/*
3 * $Id$
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#ifndef SQUID_SERVER_H
35#define SQUID_SERVER_H
36
37#include "StoreIOBuffer.h"
38#include "forward.h"
39#include "BodyPipe.h"
40#include "ICAP/AsyncJob.h"
41#include "CommCalls.h"
42
43#if USE_ADAPTATION
44#include "adaptation/forward.h"
45#include "adaptation/Initiator.h"
46#endif
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 */
57class ServerStateData:
58#if USE_ADAPTATION
59 public Adaptation::Initiator,
60 public BodyProducer,
61#endif
62 public BodyConsumer
63{
64
65public:
66 ServerStateData(FwdState *);
67 virtual ~ServerStateData();
68
69 /// \return primary or "request data connection" fd
70 virtual int dataDescriptor() 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 void adaptationAclCheckDone(Adaptation::ServicePointer service);
90 static void adaptationAclCheckDoneWrapper(Adaptation::ServicePointer service, void *data);
91
92 // ICAPInitiator: start an ICAP transaction and receive adapted headers.
93 virtual void noteAdaptationAnswer(HttpMsg *message);
94 virtual void noteAdaptationQueryAbort(bool final);
95
96 // BodyProducer: provide virgin response body to ICAP.
97 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer );
98 virtual void noteBodyConsumerAborted(BodyPipe::Pointer );
99#endif
100 virtual void processReplyBody() = 0;
101
102//AsyncJob virtual methods
103 virtual void swanSong();
104 virtual bool doneAll() const {
105 return
106#if USE_ADAPTATION
107 Adaptation::Initiator::doneAll() &&
108 BodyProducer::doneAll() &&
109#endif
110 BodyConsumer::doneAll() && false;
111 }
112
113public: // should be protected
114 void serverComplete(); /**< call when no server communication is expected */
115
116private:
117 void serverComplete2(); /**< Continuation of serverComplete */
118 bool completed; /**< serverComplete() has been called */
119
120protected:
121 // kids customize these
122 virtual void haveParsedReplyHeaders(); /**< called when got final headers */
123 virtual void completeForwarding(); /**< default calls fwd->complete() */
124
125 // BodyConsumer for HTTP: consume request body.
126 bool startRequestBodyFlow();
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
134 virtual void sentRequestBody(const CommIoCbParams &io) = 0;
135 virtual void doneSendingRequestBody() = 0;
136
137 virtual void closeServer() = 0; /**< end communication with the server */
138 virtual bool doneWithServer() const = 0; /**< did we end communication? */
139
140 /// Entry-dependent callbacks use this check to quit if the entry went bad
141 bool abortOnBadEntry(const char *abortReason);
142
143#if USE_ADAPTATION
144 bool startAdaptation(Adaptation::ServicePointer service, HttpRequest *cause);
145 void adaptVirginReplyBody(const char *buf, ssize_t len);
146 void cleanAdaptation();
147 virtual bool doneWithAdaptation() const; /**< did we end ICAP communication? */
148
149 // BodyConsumer for ICAP: consume adapted response body.
150 void handleMoreAdaptedBodyAvailable();
151 void handleAdaptedBodyProductionEnded();
152 void handleAdaptedBodyProducerAborted();
153
154 void handleAdaptationCompleted();
155 void handleAdaptationAborted(bool bypassable = false);
156#endif
157
158protected:
159 const HttpReply *virginReply() const;
160 HttpReply *virginReply();
161 HttpReply *setVirginReply(HttpReply *r);
162
163 HttpReply *finalReply();
164 HttpReply *setFinalReply(HttpReply *r);
165
166 // Kids use these to stuff data into the response instead of messing with the entry directly
167 void adaptOrFinalizeReply();
168 void addVirginReplyBody(const char *buf, ssize_t len);
169 void storeReplyBody(const char *buf, ssize_t len);
170 size_t replyBodySpace(size_t space = 4096 * 10);
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
176public: // should not be
177 StoreEntry *entry;
178 FwdState::Pointer fwd;
179 HttpRequest *request;
180
181protected:
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 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
194private:
195 void quitIfAllDone(); /**< successful termination */
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 */