]> git.ipfire.org Git - thirdparty/squid.git/blob - src/client_side_reply.h
Merged from trunk 13172.
[thirdparty/squid.git] / src / client_side_reply.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 *
28 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
29 */
30
31 #ifndef SQUID_CLIENTSIDEREPLY_H
32 #define SQUID_CLIENTSIDEREPLY_H
33
34 #include "client_side_request.h"
35 #include "ip/forward.h"
36 #include "RequestFlags.h"
37 #include "StoreClient.h"
38
39 class ErrorState;
40
41 /* XXX make static method */
42
43 class clientReplyContext : public RefCountable, public StoreClient
44 {
45
46 public:
47 static STCB CacheHit;
48 static STCB HandleIMSReply;
49 static STCB SendMoreData;
50
51 clientReplyContext(ClientHttpRequest *);
52 ~clientReplyContext();
53
54 void saveState();
55 void restoreState();
56 void purgeRequest ();
57 void purgeRequestFindObjectToPurge();
58 void purgeDoMissPurge();
59 void purgeFoundGet(StoreEntry *newEntry);
60 void purgeFoundHead(StoreEntry *newEntry);
61 void purgeFoundObject(StoreEntry *entry);
62 void sendClientUpstreamResponse();
63 void purgeDoPurgeGet(StoreEntry *entry);
64 void purgeDoPurgeHead(StoreEntry *entry);
65 void doGetMoreData();
66 void identifyStoreObject();
67 void identifyFoundObject(StoreEntry *entry);
68 int storeOKTransferDone() const;
69 int storeNotOKTransferDone() const;
70 /// replaces current response store entry with the given one
71 void setReplyToStoreEntry(StoreEntry *e);
72 /// builds error using clientBuildError() and calls setReplyToError() below
73 void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod&, char const *, Ip::Address &, HttpRequest *, const char *,
74 #if USE_AUTH
75 Auth::UserRequest::Pointer);
76 #else
77 void * unused);
78 #endif
79 /// creates a store entry for the reply and appends err to it
80 void setReplyToError(const HttpRequestMethod& method, ErrorState *err);
81 void createStoreEntry(const HttpRequestMethod& m, RequestFlags flags);
82 void removeStoreReference(store_client ** scp, StoreEntry ** ep);
83 void removeClientStoreReference(store_client **scp, ClientHttpRequest *http);
84 void startError(ErrorState * err);
85 void processExpired();
86 clientStream_status_t replyStatus();
87 void processMiss();
88 void traceReply(clientStreamNode * node);
89 const char *storeId() const { return (http->store_id.size() > 0 ? http->store_id.termedBuf() : http->uri); }
90
91 Http::StatusCode purgeStatus;
92
93 /* state variable - replace with class to handle storeentries at some point */
94 int lookingforstore;
95 virtual void created (StoreEntry *newEntry);
96
97 ClientHttpRequest *http;
98 int headers_sz;
99 store_client *sc; /* The store_client we're using */
100 StoreIOBuffer tempBuffer; /* For use in validating requests via IMS */
101 int old_reqsize; /* ... again, for the buffer */
102 size_t reqsize;
103 size_t reqofs;
104 char tempbuf[HTTP_REQBUF_SZ]; /* a temporary buffer if we need working storage */
105 #if USE_CACHE_DIGESTS
106
107 const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */
108 #endif
109
110 struct {
111
112 unsigned storelogiccomplete:1;
113
114 unsigned complete:1; /* we have read all we can from upstream */
115 bool headersSent;
116 } flags;
117 clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */
118
119 private:
120 clientStreamNode *getNextNode() const;
121 void makeThisHead();
122 bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const ;
123 void sendStreamError(StoreIOBuffer const &result);
124 void pushStreamData(StoreIOBuffer const &result, char *source);
125 clientStreamNode * next() const;
126 StoreIOBuffer holdingBuffer;
127 HttpReply *reply;
128 void processReplyAccess();
129 static ACLCB ProcessReplyAccessResult;
130 void processReplyAccessResult(const allow_t &accessAllowed);
131 void cloneReply();
132 void buildReplyHeader ();
133 bool alwaysAllowResponse(Http::StatusCode sline) const;
134 int checkTransferDone();
135 void processOnlyIfCachedMiss();
136 void processConditional(StoreIOBuffer &result);
137 void cacheHit(StoreIOBuffer result);
138 void handleIMSReply(StoreIOBuffer result);
139 void sendMoreData(StoreIOBuffer result);
140 void triggerInitialStoreRead();
141 void sendClientOldEntry();
142 void purgeAllCached();
143 void forgetHit();
144
145 void sendBodyTooLargeError();
146 void sendPreconditionFailedError();
147 void sendNotModified();
148 void sendNotModifiedOrPreconditionFailedError();
149
150 StoreEntry *old_entry;
151 store_client *old_sc; /* ... for entry to be validated */
152 bool deleting;
153
154 CBDATA_CLASS2(clientReplyContext);
155 };
156
157 #endif /* SQUID_CLIENTSIDEREPLY_H */