]>
Commit | Line | Data |
---|---|---|
6039b729 | 1 | /* |
ae7ff0b8 | 2 | * $Id: client_side.h,v 1.29 2008/02/11 22:25:22 rousskov Exp $ |
6039b729 | 3 | * |
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 | ||
33 | #ifndef SQUID_CLIENTSIDE_H | |
34 | #define SQUID_CLIENTSIDE_H | |
35 | ||
a553a5a3 | 36 | #include "comm.h" |
0655fa4d | 37 | #include "StoreIOBuffer.h" |
5f8252d2 | 38 | #include "BodyPipe.h" |
a2ac85d9 | 39 | #include "RefCount.h" |
0655fa4d | 40 | |
41 | class ConnStateData; | |
42 | ||
43 | class ClientHttpRequest; | |
44 | ||
45 | class clientStreamNode; | |
46 | ||
9554bbf2 | 47 | class AuthUserRequest; |
48 | ||
2512d159 | 49 | template <class T> |
50 | ||
51 | class Range; | |
52 | ||
0655fa4d | 53 | class ClientSocketContext : public RefCountable |
54 | { | |
55 | ||
56 | public: | |
57 | typedef RefCount<ClientSocketContext> Pointer; | |
58 | void *operator new(size_t); | |
59 | void operator delete(void *); | |
0655fa4d | 60 | ClientSocketContext(); |
61 | ~ClientSocketContext(); | |
62 | bool startOfOutput() const; | |
63 | void writeComplete(int fd, char *bufnotused, size_t size, comm_err_t errflag); | |
64 | void keepaliveNextRequest(); | |
65 | ClientHttpRequest *http; /* we own this */ | |
fedd1531 | 66 | HttpReply *reply; |
0655fa4d | 67 | char reqbuf[HTTP_REQBUF_SZ]; |
68 | Pointer next; | |
69 | ||
70 | struct | |
71 | { | |
72 | ||
081ef8a7 | 73 | unsigned deferred: 1; /* This is a pipelined request waiting for the current object to complete */ |
0655fa4d | 74 | |
081ef8a7 | 75 | unsigned parsed_ok: 1; /* Was this parsed correctly? */ |
0655fa4d | 76 | } |
77 | ||
78 | flags; | |
79 | bool mayUseConnection() const {return mayUseConnection_;} | |
80 | ||
81 | void mayUseConnection(bool aBool) | |
82 | { | |
83 | mayUseConnection_ = aBool; | |
84 | debug (33,3)("ClientSocketContext::mayUseConnection: This %p marked %d\n", | |
85 | this, aBool); | |
86 | } | |
87 | ||
7d9b0628 | 88 | class DeferredParams |
0655fa4d | 89 | { |
7d9b0628 | 90 | |
91 | public: | |
0655fa4d | 92 | clientStreamNode *node; |
93 | HttpReply *rep; | |
94 | StoreIOBuffer queuedBuffer; | |
7d9b0628 | 95 | }; |
0655fa4d | 96 | |
7d9b0628 | 97 | DeferredParams deferredparams; |
57d55dfa | 98 | int64_t writtenToSocket; |
0655fa4d | 99 | void pullData(); |
47f6e231 | 100 | int64_t getNextRangeOffset() const; |
0655fa4d | 101 | bool canPackMoreRanges() const; |
102 | clientStream_status_t socketState(); | |
103 | void sendBody(HttpReply * rep, StoreIOBuffer bodyData); | |
104 | void sendStartOfMessage(HttpReply * rep, StoreIOBuffer bodyData); | |
47f6e231 | 105 | size_t lengthToSend(Range<int64_t> const &available); |
0655fa4d | 106 | void noteSentBodyBytes(size_t); |
107 | void buildRangeHeader(HttpReply * rep); | |
108 | int fd() const; | |
109 | clientStreamNode * getTail() const; | |
110 | clientStreamNode * getClientReplyContext() const; | |
111 | void connIsFinished(); | |
a2ac85d9 | 112 | void removeFromConnectionList(RefCount<ConnStateData> conn); |
2324cda2 | 113 | void deferRecipientForLater(clientStreamNode * node, HttpReply * rep, StoreIOBuffer receivedData); |
0655fa4d | 114 | bool multipartRangeRequest() const; |
0655fa4d | 115 | void registerWithConn(); |
116 | ||
117 | private: | |
118 | CBDATA_CLASS(ClientSocketContext); | |
119 | void prepareReply(HttpReply * rep); | |
2512d159 | 120 | void packRange(StoreIOBuffer const &, MemBuf * mb); |
0655fa4d | 121 | void deRegisterWithConn(); |
55e44db9 | 122 | void doClose(); |
5f8252d2 | 123 | void initiateClose(const char *reason); |
0655fa4d | 124 | bool mayUseConnection_; /* This request may use the connection. Don't read anymore requests for now */ |
125 | bool connRegistered_; | |
126 | }; | |
127 | ||
0b86805b | 128 | /* A connection to a socket */ |
5f8252d2 | 129 | class ConnStateData : public BodyProducer, public RefCountable |
6039b729 | 130 | { |
131 | ||
132 | public: | |
a2ac85d9 | 133 | typedef RefCount<ConnStateData> Pointer; |
6039b729 | 134 | |
135 | ConnStateData(); | |
136 | ~ConnStateData(); | |
137 | ||
138 | void readSomeData(); | |
139 | int getAvailableBufferLength() const; | |
140 | bool areAllContextsForThisConnection() const; | |
141 | void freeAllContexts(); | |
142 | void readNextRequest(); | |
143 | void makeSpaceAvailable(); | |
0655fa4d | 144 | ClientSocketContext::Pointer getCurrentContext() const; |
145 | void addContextToQueue(ClientSocketContext * context); | |
146 | int getConcurrentRequestCount() const; | |
a2ac85d9 | 147 | void close(); |
148 | bool isOpen() const; | |
6039b729 | 149 | |
150 | int fd; | |
151 | ||
152 | struct In | |
153 | { | |
154 | In(); | |
155 | ~In(); | |
156 | char *addressToReadInto() const; | |
157 | char *buf; | |
158 | size_t notYetUsed; | |
159 | size_t allocatedSize; | |
0b86805b | 160 | } in; |
6039b729 | 161 | |
3e62bd58 | 162 | int64_t bodySizeLeft(); |
3b299123 | 163 | |
164 | /* | |
165 | * Is this connection based authentication? if so what type it | |
166 | * is. | |
167 | */ | |
168 | auth_type_t auth_type; | |
169 | /* | |
170 | * note this is ONLY connection based because NTLM is against HTTP spec. | |
171 | * the user details for connection based authentication | |
172 | */ | |
76f142cd | 173 | AuthUserRequest *auth_user_request; |
3b299123 | 174 | /* |
175 | * used by the owner of the connection, opaque otherwise | |
176 | * TODO: generalise the connection owner concept. | |
177 | */ | |
178 | ClientSocketContext::Pointer currentobject; | |
6039b729 | 179 | |
cc192b50 | 180 | IPAddress peer; |
6039b729 | 181 | |
cc192b50 | 182 | IPAddress me; |
6039b729 | 183 | |
cc192b50 | 184 | IPAddress log_addr; |
6039b729 | 185 | char rfc931[USER_IDENT_SZ]; |
186 | int nrequests; | |
187 | ||
188 | struct | |
189 | { | |
48962ba8 | 190 | bool readMoreRequests; |
6039b729 | 191 | } |
192 | ||
193 | flags; | |
194 | http_port_list *port; | |
195 | ||
196 | bool transparent() const; | |
197 | void transparent(bool const); | |
198 | bool reading() const; | |
199 | void reading(bool const); | |
5f8252d2 | 200 | |
55e44db9 | 201 | bool closing() const; |
5f8252d2 | 202 | void startClosing(const char *reason); |
6039b729 | 203 | |
3e62bd58 | 204 | BodyPipe::Pointer expectRequestBody(int64_t size); |
5f8252d2 | 205 | virtual void noteMoreBodySpaceAvailable(BodyPipe &); |
206 | virtual void noteBodyConsumerAborted(BodyPipe &); | |
207 | ||
208 | void handleReadData(char *buf, size_t size); | |
209 | void handleRequestBodyData(); | |
0b86805b | 210 | |
ae7ff0b8 | 211 | #if USE_SSL |
212 | bool switchToHttps(); | |
213 | bool switchedToHttps() const { return switchedToHttps_; } | |
214 | #else | |
215 | bool switchedToHttps() const { return false; } | |
216 | #endif | |
217 | ||
6039b729 | 218 | private: |
0b86805b | 219 | CBDATA_CLASS2(ConnStateData); |
6039b729 | 220 | bool transparent_; |
221 | bool reading_; | |
55e44db9 | 222 | bool closing_; |
ae7ff0b8 | 223 | bool switchedToHttps_; |
7ce98c67 | 224 | Pointer openReference; |
5f8252d2 | 225 | BodyPipe::Pointer bodyPipe; // set when we are reading request body |
6039b729 | 226 | }; |
227 | ||
55e44db9 | 228 | /* convenience class while splitting up body handling */ |
229 | /* temporary existence only - on stack use expected */ | |
230 | ||
de31d06f | 231 | void setLogUri(ClientHttpRequest * http, char const *uri); |
232 | ||
8596962e | 233 | const char *findTrailingHTTPVersion(const char *uriAndHTTPVersion, const char *end = NULL); |
234 | ||
6039b729 | 235 | #endif /* SQUID_CLIENTSIDE_H */ |