]>
Commit | Line | Data |
---|---|---|
6039b729 | 1 | |
2 | /* | |
47f6e231 | 3 | * $Id: client_side.h,v 1.23 2007/08/13 17:20:51 hno Exp $ |
6039b729 | 4 | * |
5 | * | |
6 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
7 | * ---------------------------------------------------------- | |
8 | * | |
9 | * Squid is the result of efforts by numerous individuals from | |
10 | * the Internet community; see the CONTRIBUTORS file for full | |
11 | * details. Many organizations have provided support for Squid's | |
12 | * development; see the SPONSORS file for full details. Squid is | |
13 | * Copyrighted (C) 2001 by the Regents of the University of | |
14 | * California; see the COPYRIGHT file for full details. Squid | |
15 | * incorporates software developed and/or copyrighted by other | |
16 | * sources; see the CREDITS file for full details. | |
17 | * | |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
20 | * the Free Software Foundation; either version 2 of the License, or | |
21 | * (at your option) any later version. | |
22 | * | |
23 | * This program is distributed in the hope that it will be useful, | |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | * GNU General Public License for more details. | |
27 | * | |
28 | * You should have received a copy of the GNU General Public License | |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
31 | * | |
32 | */ | |
33 | ||
34 | #ifndef SQUID_CLIENTSIDE_H | |
35 | #define SQUID_CLIENTSIDE_H | |
36 | ||
a553a5a3 | 37 | #include "comm.h" |
0655fa4d | 38 | #include "StoreIOBuffer.h" |
5f8252d2 | 39 | #include "BodyPipe.h" |
a2ac85d9 | 40 | #include "RefCount.h" |
0655fa4d | 41 | |
42 | class ConnStateData; | |
43 | ||
44 | class ClientHttpRequest; | |
45 | ||
46 | class clientStreamNode; | |
47 | ||
9554bbf2 | 48 | class AuthUserRequest; |
49 | ||
2512d159 | 50 | template <class T> |
51 | ||
52 | class Range; | |
53 | ||
0655fa4d | 54 | class ClientSocketContext : public RefCountable |
55 | { | |
56 | ||
57 | public: | |
58 | typedef RefCount<ClientSocketContext> Pointer; | |
59 | void *operator new(size_t); | |
60 | void operator delete(void *); | |
0655fa4d | 61 | ClientSocketContext(); |
62 | ~ClientSocketContext(); | |
63 | bool startOfOutput() const; | |
64 | void writeComplete(int fd, char *bufnotused, size_t size, comm_err_t errflag); | |
65 | void keepaliveNextRequest(); | |
66 | ClientHttpRequest *http; /* we own this */ | |
fedd1531 | 67 | HttpReply *reply; |
0655fa4d | 68 | char reqbuf[HTTP_REQBUF_SZ]; |
69 | Pointer next; | |
70 | ||
71 | struct | |
72 | { | |
73 | ||
081ef8a7 | 74 | unsigned deferred: 1; /* This is a pipelined request waiting for the current object to complete */ |
0655fa4d | 75 | |
081ef8a7 | 76 | unsigned parsed_ok: 1; /* Was this parsed correctly? */ |
0655fa4d | 77 | } |
78 | ||
79 | flags; | |
80 | bool mayUseConnection() const {return mayUseConnection_;} | |
81 | ||
82 | void mayUseConnection(bool aBool) | |
83 | { | |
84 | mayUseConnection_ = aBool; | |
85 | debug (33,3)("ClientSocketContext::mayUseConnection: This %p marked %d\n", | |
86 | this, aBool); | |
87 | } | |
88 | ||
7d9b0628 | 89 | class DeferredParams |
0655fa4d | 90 | { |
7d9b0628 | 91 | |
92 | public: | |
0655fa4d | 93 | clientStreamNode *node; |
94 | HttpReply *rep; | |
95 | StoreIOBuffer queuedBuffer; | |
7d9b0628 | 96 | }; |
0655fa4d | 97 | |
7d9b0628 | 98 | DeferredParams deferredparams; |
0655fa4d | 99 | off_t writtenToSocket; |
100 | void pullData(); | |
47f6e231 | 101 | int64_t getNextRangeOffset() const; |
0655fa4d | 102 | bool canPackMoreRanges() const; |
103 | clientStream_status_t socketState(); | |
104 | void sendBody(HttpReply * rep, StoreIOBuffer bodyData); | |
105 | void sendStartOfMessage(HttpReply * rep, StoreIOBuffer bodyData); | |
47f6e231 | 106 | size_t lengthToSend(Range<int64_t> const &available); |
0655fa4d | 107 | void noteSentBodyBytes(size_t); |
108 | void buildRangeHeader(HttpReply * rep); | |
109 | int fd() const; | |
110 | clientStreamNode * getTail() const; | |
111 | clientStreamNode * getClientReplyContext() const; | |
112 | void connIsFinished(); | |
a2ac85d9 | 113 | void removeFromConnectionList(RefCount<ConnStateData> conn); |
0655fa4d | 114 | void deferRecipientForLater(clientStreamNode * node, HttpReply * rep, StoreIOBuffer recievedData); |
115 | bool multipartRangeRequest() const; | |
0655fa4d | 116 | void registerWithConn(); |
117 | ||
118 | private: | |
119 | CBDATA_CLASS(ClientSocketContext); | |
120 | void prepareReply(HttpReply * rep); | |
2512d159 | 121 | void packRange(StoreIOBuffer const &, MemBuf * mb); |
0655fa4d | 122 | void deRegisterWithConn(); |
55e44db9 | 123 | void doClose(); |
5f8252d2 | 124 | void initiateClose(const char *reason); |
0655fa4d | 125 | bool mayUseConnection_; /* This request may use the connection. Don't read anymore requests for now */ |
126 | bool connRegistered_; | |
127 | }; | |
128 | ||
0b86805b | 129 | |
130 | /* A connection to a socket */ | |
5f8252d2 | 131 | class ConnStateData : public BodyProducer, public RefCountable |
6039b729 | 132 | { |
133 | ||
134 | public: | |
a2ac85d9 | 135 | typedef RefCount<ConnStateData> Pointer; |
6039b729 | 136 | |
137 | ConnStateData(); | |
138 | ~ConnStateData(); | |
139 | ||
140 | void readSomeData(); | |
141 | int getAvailableBufferLength() const; | |
142 | bool areAllContextsForThisConnection() const; | |
143 | void freeAllContexts(); | |
144 | void readNextRequest(); | |
145 | void makeSpaceAvailable(); | |
0655fa4d | 146 | ClientSocketContext::Pointer getCurrentContext() const; |
147 | void addContextToQueue(ClientSocketContext * context); | |
148 | int getConcurrentRequestCount() const; | |
a2ac85d9 | 149 | void close(); |
150 | bool isOpen() const; | |
6039b729 | 151 | |
152 | int fd; | |
153 | ||
154 | struct In | |
155 | { | |
156 | In(); | |
157 | ~In(); | |
158 | char *addressToReadInto() const; | |
159 | char *buf; | |
160 | size_t notYetUsed; | |
161 | size_t allocatedSize; | |
0b86805b | 162 | } in; |
6039b729 | 163 | |
3b299123 | 164 | ssize_t bodySizeLeft(); |
165 | ||
166 | /* | |
167 | * Is this connection based authentication? if so what type it | |
168 | * is. | |
169 | */ | |
170 | auth_type_t auth_type; | |
171 | /* | |
172 | * note this is ONLY connection based because NTLM is against HTTP spec. | |
173 | * the user details for connection based authentication | |
174 | */ | |
76f142cd | 175 | AuthUserRequest *auth_user_request; |
3b299123 | 176 | /* |
177 | * used by the owner of the connection, opaque otherwise | |
178 | * TODO: generalise the connection owner concept. | |
179 | */ | |
180 | ClientSocketContext::Pointer currentobject; | |
6039b729 | 181 | |
182 | struct sockaddr_in peer; | |
183 | ||
184 | struct sockaddr_in me; | |
185 | ||
ddfcbc22 | 186 | struct IN_ADDR log_addr; |
6039b729 | 187 | char rfc931[USER_IDENT_SZ]; |
188 | int nrequests; | |
189 | ||
190 | struct | |
191 | { | |
48962ba8 | 192 | bool readMoreRequests; |
6039b729 | 193 | } |
194 | ||
195 | flags; | |
196 | http_port_list *port; | |
197 | ||
198 | bool transparent() const; | |
199 | void transparent(bool const); | |
200 | bool reading() const; | |
201 | void reading(bool const); | |
5f8252d2 | 202 | |
55e44db9 | 203 | bool closing() const; |
5f8252d2 | 204 | void startClosing(const char *reason); |
6039b729 | 205 | |
5f8252d2 | 206 | BodyPipe::Pointer expectRequestBody(size_t size); |
207 | virtual void noteMoreBodySpaceAvailable(BodyPipe &); | |
208 | virtual void noteBodyConsumerAborted(BodyPipe &); | |
209 | ||
210 | void handleReadData(char *buf, size_t size); | |
211 | void handleRequestBodyData(); | |
0b86805b | 212 | |
6039b729 | 213 | private: |
0b86805b | 214 | CBDATA_CLASS2(ConnStateData); |
6039b729 | 215 | bool transparent_; |
216 | bool reading_; | |
55e44db9 | 217 | bool closing_; |
7ce98c67 | 218 | Pointer openReference; |
5f8252d2 | 219 | BodyPipe::Pointer bodyPipe; // set when we are reading request body |
6039b729 | 220 | }; |
221 | ||
55e44db9 | 222 | /* convenience class while splitting up body handling */ |
223 | /* temporary existence only - on stack use expected */ | |
224 | ||
de31d06f | 225 | void setLogUri(ClientHttpRequest * http, char const *uri); |
226 | ||
8596962e | 227 | const char *findTrailingHTTPVersion(const char *uriAndHTTPVersion, const char *end = NULL); |
228 | ||
6039b729 | 229 | #endif /* SQUID_CLIENTSIDE_H */ |