]> git.ipfire.org Git - thirdparty/squid.git/blob - src/client_side.h
Summary: Final MSVC fixups.
[thirdparty/squid.git] / src / client_side.h
1
2 /*
3 * $Id: client_side.h,v 1.8 2003/08/10 11:00:42 robertc Exp $
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
37 #include "StoreIOBuffer.h"
38 #include "RefCount.h"
39
40 class ConnStateData;
41
42 class ClientHttpRequest;
43
44 class clientStreamNode;
45
46 template <class T>
47
48 class Range;
49
50 class ClientSocketContext : public RefCountable
51 {
52
53 public:
54 typedef RefCount<ClientSocketContext> Pointer;
55 void *operator new(size_t);
56 void operator delete(void *);
57 ClientSocketContext();
58 ~ClientSocketContext();
59 bool startOfOutput() const;
60 void writeComplete(int fd, char *bufnotused, size_t size, comm_err_t errflag);
61 void keepaliveNextRequest();
62 ClientHttpRequest *http; /* we own this */
63 char reqbuf[HTTP_REQBUF_SZ];
64 Pointer next;
65
66 struct
67 {
68
69 int deferred:
70 1; /* This is a pipelined request waiting for the current object to complete */
71
72 int parsed_ok:
73 1; /* Was this parsed correctly? */
74 }
75
76 flags;
77 bool mayUseConnection() const {return mayUseConnection_;}
78
79 void mayUseConnection(bool aBool)
80 {
81 mayUseConnection_ = aBool;
82 debug (33,3)("ClientSocketContext::mayUseConnection: This %p marked %d\n",
83 this, aBool);
84 }
85
86 class DeferredParams
87 {
88
89 public:
90 clientStreamNode *node;
91 HttpReply *rep;
92 StoreIOBuffer queuedBuffer;
93 };
94
95 DeferredParams deferredparams;
96 off_t writtenToSocket;
97 void pullData();
98 off_t getNextRangeOffset() const;
99 bool canPackMoreRanges() const;
100 clientStream_status_t socketState();
101 void sendBody(HttpReply * rep, StoreIOBuffer bodyData);
102 void sendStartOfMessage(HttpReply * rep, StoreIOBuffer bodyData);
103 size_t lengthToSend(Range<size_t> const &available);
104 void noteSentBodyBytes(size_t);
105 void buildRangeHeader(HttpReply * rep);
106 int fd() const;
107 clientStreamNode * getTail() const;
108 clientStreamNode * getClientReplyContext() const;
109 void connIsFinished();
110 void removeFromConnectionList(RefCount<ConnStateData> conn);
111 void deferRecipientForLater(clientStreamNode * node, HttpReply * rep, StoreIOBuffer recievedData);
112 bool multipartRangeRequest() const;
113 void registerWithConn();
114
115 private:
116 CBDATA_CLASS(ClientSocketContext);
117 void prepareReply(HttpReply * rep);
118 void packRange(StoreIOBuffer const &, MemBuf * mb);
119 void deRegisterWithConn();
120 bool mayUseConnection_; /* This request may use the connection. Don't read anymore requests for now */
121 bool connRegistered_;
122 };
123
124 class ConnStateData : public RefCountable
125 {
126
127 public:
128 typedef RefCount<ConnStateData> Pointer;
129 void * operator new (size_t);
130 void operator delete (void *);
131
132 ConnStateData();
133 ~ConnStateData();
134
135 void readSomeData();
136 int getAvailableBufferLength() const;
137 bool areAllContextsForThisConnection() const;
138 void freeAllContexts();
139 void readNextRequest();
140 void makeSpaceAvailable();
141 ClientSocketContext::Pointer getCurrentContext() const;
142 void addContextToQueue(ClientSocketContext * context);
143 int getConcurrentRequestCount() const;
144 void close();
145 bool isOpen() const;
146
147 int fd;
148
149 struct In
150 {
151 In();
152 ~In();
153 char *addressToReadInto() const;
154 char *buf;
155 size_t notYetUsed;
156 size_t allocatedSize;
157 }
158
159 in;
160
161 struct
162 {
163 size_t size_left; /* How much body left to process */
164 HttpRequest *request; /* Parameters passed to clientReadBody */
165 char *buf;
166 size_t bufsize;
167 CBCB *callback;
168 void *cbdata;
169 }
170
171 body;
172 auth_type_t auth_type; /* Is this connection based authentication? if so what type it is. */
173 /* note this is ONLY connection based because NTLM is against HTTP spec */
174 /* the user details for connection based authentication */
175 auth_user_request_t *auth_user_request;
176 /* TODO: generalise the connection owner concept */
177 ClientSocketContext::Pointer currentobject; /* used by the owner of the connection. Opaque otherwise */
178
179 struct sockaddr_in peer;
180
181 struct sockaddr_in me;
182
183 struct in_addr log_addr;
184 char rfc931[USER_IDENT_SZ];
185 int nrequests;
186
187 struct
188 {
189
190 int readMoreRequests:
191 1;
192 }
193
194 flags;
195 http_port_list *port;
196
197 bool transparent() const;
198 void transparent(bool const);
199 bool reading() const;
200 void reading(bool const);
201
202 private:
203 CBDATA_CLASS(ConnStateData);
204 bool transparent_;
205 bool reading_;
206 Pointer openReference;
207 };
208
209 #endif /* SQUID_CLIENTSIDE_H */