]> git.ipfire.org Git - thirdparty/squid.git/blob - src/client_side_reply.h
Add custom Store ID code support
[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 "base/RefCount.h"
35 #include "client_side_request.h"
36 #include "clientStream.h"
37 #include "HttpHeader.h"
38 #include "RequestFlags.h"
39 #include "StoreClient.h"
40
41 class ErrorState;
42 #include "ip/forward.h"
43
44 /* XXX make static method */
45
46 class clientReplyContext : public RefCountable, public StoreClient
47 {
48
49 public:
50 void *operator new (size_t byteCount);
51 void operator delete (void *address);
52 static STCB CacheHit;
53 static STCB HandleIMSReply;
54 static STCB SendMoreData;
55
56 clientReplyContext(ClientHttpRequest *);
57 ~clientReplyContext();
58
59 void saveState();
60 void restoreState();
61 void purgeRequest ();
62 void purgeRequestFindObjectToPurge();
63 void purgeDoMissPurge();
64 void purgeFoundGet(StoreEntry *newEntry);
65 void purgeFoundHead(StoreEntry *newEntry);
66 void purgeFoundObject(StoreEntry *entry);
67 void sendClientUpstreamResponse();
68 void purgeDoPurgeGet(StoreEntry *entry);
69 void purgeDoPurgeHead(StoreEntry *entry);
70 void doGetMoreData();
71 void identifyStoreObject();
72 void identifyFoundObject(StoreEntry *entry);
73 int storeOKTransferDone() const;
74 int storeNotOKTransferDone() const;
75 /// replaces current response store entry with the given one
76 void setReplyToStoreEntry(StoreEntry *e);
77 /// builds error using clientBuildError() and calls setReplyToError() below
78 void setReplyToError(err_type, http_status, const HttpRequestMethod&, char const *, Ip::Address &, HttpRequest *, const char *,
79 #if USE_AUTH
80 Auth::UserRequest::Pointer);
81 #else
82 void * unused);
83 #endif
84 /// creates a store entry for the reply and appends err to it
85 void setReplyToError(const HttpRequestMethod& method, ErrorState *err);
86 void createStoreEntry(const HttpRequestMethod& m, RequestFlags flags);
87 void removeStoreReference(store_client ** scp, StoreEntry ** ep);
88 void removeClientStoreReference(store_client **scp, ClientHttpRequest *http);
89 void startError(ErrorState * err);
90 void processExpired();
91 clientStream_status_t replyStatus();
92 void processMiss();
93 void traceReply(clientStreamNode * node);
94 const char *storeId() const { return (http->store_id.size() > 0 ? http->store_id.termedBuf() : http->uri); }
95
96 http_status purgeStatus;
97
98 /* state variable - replace with class to handle storeentries at some point */
99 int lookingforstore;
100 virtual void created (StoreEntry *newEntry);
101
102 ClientHttpRequest *http;
103 int headers_sz;
104 store_client *sc; /* The store_client we're using */
105 StoreIOBuffer tempBuffer; /* For use in validating requests via IMS */
106 int old_reqsize; /* ... again, for the buffer */
107 size_t reqsize;
108 size_t reqofs;
109 char tempbuf[HTTP_REQBUF_SZ]; /* a temporary buffer if we need working storage */
110 #if USE_CACHE_DIGESTS
111
112 const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */
113 #endif
114
115 struct {
116
117 unsigned storelogiccomplete:1;
118
119 unsigned complete:1; /* we have read all we can from upstream */
120 bool headersSent;
121 } flags;
122 clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */
123
124 private:
125 clientStreamNode *getNextNode() const;
126 void makeThisHead();
127 bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const ;
128 void sendStreamError(StoreIOBuffer const &result);
129 void pushStreamData(StoreIOBuffer const &result, char *source);
130 clientStreamNode * next() const;
131 StoreIOBuffer holdingBuffer;
132 HttpReply *reply;
133 void processReplyAccess();
134 static ACLCB ProcessReplyAccessResult;
135 void processReplyAccessResult(const allow_t &accessAllowed);
136 void cloneReply();
137 void buildReplyHeader ();
138 bool alwaysAllowResponse(http_status sline) const;
139 int checkTransferDone();
140 void processOnlyIfCachedMiss();
141 void processConditional(StoreIOBuffer &result);
142 void cacheHit(StoreIOBuffer result);
143 void handleIMSReply(StoreIOBuffer result);
144 void sendMoreData(StoreIOBuffer result);
145 void triggerInitialStoreRead();
146 void sendClientOldEntry();
147 void purgeAllCached();
148
149 void sendBodyTooLargeError();
150 void sendPreconditionFailedError();
151 void sendNotModified();
152 void sendNotModifiedOrPreconditionFailedError();
153
154 StoreEntry *old_entry;
155 store_client *old_sc; /* ... for entry to be validated */
156 bool deleting;
157
158 CBDATA_CLASS(clientReplyContext);
159 };
160
161 #endif /* SQUID_CLIENTSIDEREPLY_H */