]> git.ipfire.org Git - thirdparty/squid.git/blob - src/clients/Client.h
C++11: Remove GnuRegex and all -lregex related code
[thirdparty/squid.git] / src / clients / Client.h
1 /*
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_SRC_CLIENTS_CLIENT_H
10 #define SQUID_SRC_CLIENTS_CLIENT_H
11
12 #include "base/AsyncJob.h"
13 #include "BodyPipe.h"
14 #include "CommCalls.h"
15 #include "FwdState.h"
16 #include "StoreIOBuffer.h"
17 #if USE_ADAPTATION
18 #include "adaptation/forward.h"
19 #include "adaptation/Initiator.h"
20 #endif
21
22 class HttpMsg;
23 class HttpReply;
24
25 /**
26 * Client is a common base for classes such as HttpStateData and FtpStateData.
27 * All such classes must be able to consume request bodies from a BodyPipe
28 * or ICAP producer, adapt virgin responses using ICAP, and provide a
29 * consumer with responses.
30 */
31 class Client:
32 #if USE_ADAPTATION
33 public Adaptation::Initiator,
34 public BodyProducer,
35 #endif
36 public BodyConsumer
37 {
38
39 public:
40 Client(FwdState *);
41 virtual ~Client();
42
43 /// \return primary or "request data connection"
44 virtual const Comm::ConnectionPointer & dataConnection() const = 0;
45
46 // BodyConsumer: consume request body or adapted response body.
47 // The implementation just calls the corresponding HTTP or ICAP handle*()
48 // method, depending on the pipe.
49 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer);
50 virtual void noteBodyProductionEnded(BodyPipe::Pointer);
51 virtual void noteBodyProducerAborted(BodyPipe::Pointer);
52
53 /// read response data from the network
54 virtual void maybeReadVirginBody() = 0;
55
56 /// abnormal transaction termination; reason is for debugging only
57 virtual void abortAll(const char *reason) = 0;
58
59 /// abnormal data transfer termination
60 /// \retval true the transaction will be terminated (abortAll called)
61 /// \reval false the transaction will survive
62 virtual bool abortOnData(const char *reason);
63
64 /// a hack to reach HttpStateData::orignal_request
65 virtual HttpRequest *originalRequest();
66
67 #if USE_ADAPTATION
68 // Adaptation::Initiator API: start an ICAP transaction and receive adapted headers.
69 virtual void noteAdaptationAnswer(const Adaptation::Answer &answer);
70 virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group);
71
72 // BodyProducer: provide virgin response body to ICAP.
73 virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer );
74 virtual void noteBodyConsumerAborted(BodyPipe::Pointer );
75 #endif
76 virtual bool getMoreRequestBody(MemBuf &buf);
77 virtual void processReplyBody() = 0;
78
79 //AsyncJob virtual methods
80 virtual void swanSong();
81 virtual bool doneAll() const;
82
83 public: // should be protected
84 void serverComplete(); /**< call when no server communication is expected */
85
86 private:
87 void serverComplete2(); /**< Continuation of serverComplete */
88 bool completed; /**< serverComplete() has been called */
89
90 protected:
91 // kids customize these
92 virtual void haveParsedReplyHeaders(); /**< called when got final headers */
93 virtual void completeForwarding(); /**< default calls fwd->complete() */
94
95 // BodyConsumer for HTTP: consume request body.
96 bool startRequestBodyFlow();
97 void handleMoreRequestBodyAvailable();
98 void handleRequestBodyProductionEnded();
99 virtual void handleRequestBodyProducerAborted() = 0;
100
101 // sending of the request body to the server
102 void sendMoreRequestBody();
103 // has body; kids overwrite to increment I/O stats counters
104 virtual void sentRequestBody(const CommIoCbParams &io) = 0;
105 virtual void doneSendingRequestBody() = 0;
106
107 /// Use this to end communication with the server. The call cancels our
108 /// closure handler and tells FwdState to forget about the connection.
109 virtual void closeServer() = 0;
110 virtual bool doneWithServer() const = 0; /**< did we end communication? */
111 /// whether we may receive more virgin response body bytes
112 virtual bool mayReadVirginReplyBody() const = 0;
113
114 /// Entry-dependent callbacks use this check to quit if the entry went bad
115 bool abortOnBadEntry(const char *abortReason);
116
117 bool blockCaching();
118
119 #if USE_ADAPTATION
120 void startAdaptation(const Adaptation::ServiceGroupPointer &group, HttpRequest *cause);
121 void adaptVirginReplyBody(const char *buf, ssize_t len);
122 void cleanAdaptation();
123 virtual bool doneWithAdaptation() const; /**< did we end ICAP communication? */
124
125 // BodyConsumer for ICAP: consume adapted response body.
126 void handleMoreAdaptedBodyAvailable();
127 void handleAdaptedBodyProductionEnded();
128 void handleAdaptedBodyProducerAborted();
129
130 void handleAdaptedHeader(HttpMsg *msg);
131 void handleAdaptationCompleted();
132 void handleAdaptationBlocked(const Adaptation::Answer &answer);
133 void handleAdaptationAborted(bool bypassable = false);
134 bool handledEarlyAdaptationAbort();
135
136 /// called by StoreEntry when it has more buffer space available
137 void resumeBodyStorage();
138 /// called when the entire adapted response body is consumed
139 void endAdaptedBodyConsumption();
140 #endif
141
142 protected:
143 const HttpReply *virginReply() const;
144 HttpReply *virginReply();
145 HttpReply *setVirginReply(HttpReply *r);
146
147 HttpReply *finalReply();
148 HttpReply *setFinalReply(HttpReply *r);
149
150 // Kids use these to stuff data into the response instead of messing with the entry directly
151 void adaptOrFinalizeReply();
152 void addVirginReplyBody(const char *buf, ssize_t len);
153 void storeReplyBody(const char *buf, ssize_t len);
154 /// \deprecated use SBuf I/O API and calcBufferSpaceToReserve() instead
155 size_t replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const;
156 /// determine how much space the buffer needs to reserve
157 size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const;
158
159 void adjustBodyBytesRead(const int64_t delta);
160
161 // These should be private
162 int64_t currentOffset; /**< Our current offset in the StoreEntry */
163 MemBuf *responseBodyBuffer; /**< Data temporarily buffered for ICAP */
164
165 public: // should not be
166 StoreEntry *entry;
167 FwdState::Pointer fwd;
168 HttpRequest *request;
169
170 protected:
171 BodyPipe::Pointer requestBodySource; /**< to consume request body */
172 AsyncCall::Pointer requestSender; /**< set if we are expecting Comm::Write to call us back */
173
174 #if USE_ADAPTATION
175 BodyPipe::Pointer virginBodyDestination; /**< to provide virgin response body */
176 CbcPointer<Adaptation::Initiate> adaptedHeadSource; /**< to get adapted response headers */
177 BodyPipe::Pointer adaptedBodySource; /**< to consume adated response body */
178
179 bool adaptationAccessCheckPending;
180 bool startedAdaptation;
181 #endif
182 bool receivedWholeRequestBody; ///< handleRequestBodyProductionEnded called
183
184 /// whether we should not be talking to FwdState; XXX: clear fwd instead
185 /// points to a string literal which is used only for debugging
186 const char *doneWithFwd;
187
188 private:
189 void sendBodyIsTooLargeError();
190 void maybePurgeOthers();
191
192 HttpReply *theVirginReply; /**< reply received from the origin server */
193 HttpReply *theFinalReply; /**< adapted reply from ICAP or virgin reply */
194 };
195
196 #endif /* SQUID_SRC_CLIENTS_CLIENT_H */
197