1 | /* |
---|
2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
---|
3 | * |
---|
4 | * Squid software is distributed under GPLv2+ license and includes |
---|
5 | * contributions from numerous individuals and organizations. |
---|
6 | * Please see the COPYING and CONTRIBUTORS files for details. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef SQUID_CLIENTSIDEREPLY_H |
---|
10 | #define SQUID_CLIENTSIDEREPLY_H |
---|
11 | |
---|
12 | #include "acl/forward.h" |
---|
13 | #include "client_side_request.h" |
---|
14 | #include "ip/forward.h" |
---|
15 | #include "RequestFlags.h" |
---|
16 | #include "StoreClient.h" |
---|
17 | |
---|
18 | class ErrorState; |
---|
19 | |
---|
20 | /* XXX make static method */ |
---|
21 | |
---|
22 | class clientReplyContext : public RefCountable, public StoreClient |
---|
23 | { |
---|
24 | |
---|
25 | public: |
---|
26 | static STCB CacheHit; |
---|
27 | static STCB HandleIMSReply; |
---|
28 | static STCB SendMoreData; |
---|
29 | |
---|
30 | clientReplyContext(ClientHttpRequest *); |
---|
31 | ~clientReplyContext(); |
---|
32 | |
---|
33 | void saveState(); |
---|
34 | void restoreState(); |
---|
35 | void purgeRequest (); |
---|
36 | void purgeRequestFindObjectToPurge(); |
---|
37 | void purgeDoMissPurge(); |
---|
38 | void purgeFoundGet(StoreEntry *newEntry); |
---|
39 | void purgeFoundHead(StoreEntry *newEntry); |
---|
40 | void purgeFoundObject(StoreEntry *entry); |
---|
41 | void sendClientUpstreamResponse(); |
---|
42 | void purgeDoPurgeGet(StoreEntry *entry); |
---|
43 | void purgeDoPurgeHead(StoreEntry *entry); |
---|
44 | void doGetMoreData(); |
---|
45 | void identifyStoreObject(); |
---|
46 | void identifyFoundObject(StoreEntry *entry); |
---|
47 | int storeOKTransferDone() const; |
---|
48 | int storeNotOKTransferDone() const; |
---|
49 | /// replaces current response store entry with the given one |
---|
50 | void setReplyToStoreEntry(StoreEntry *e, const char *reason); |
---|
51 | /// builds error using clientBuildError() and calls setReplyToError() below |
---|
52 | void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod&, char const *, Ip::Address &, HttpRequest *, const char *, |
---|
53 | #if USE_AUTH |
---|
54 | Auth::UserRequest::Pointer); |
---|
55 | #else |
---|
56 | void * unused); |
---|
57 | #endif |
---|
58 | /// creates a store entry for the reply and appends err to it |
---|
59 | void setReplyToError(const HttpRequestMethod& method, ErrorState *err); |
---|
60 | /// creates a store entry for the reply and appends error reply to it |
---|
61 | void setReplyToReply(HttpReply *reply); |
---|
62 | void createStoreEntry(const HttpRequestMethod& m, RequestFlags flags); |
---|
63 | void removeStoreReference(store_client ** scp, StoreEntry ** ep); |
---|
64 | void removeClientStoreReference(store_client **scp, ClientHttpRequest *http); |
---|
65 | void startError(ErrorState * err); |
---|
66 | void processExpired(); |
---|
67 | clientStream_status_t replyStatus(); |
---|
68 | void processMiss(); |
---|
69 | void traceReply(clientStreamNode * node); |
---|
70 | const char *storeId() const { return (http->store_id.size() > 0 ? http->store_id.termedBuf() : http->uri); } |
---|
71 | |
---|
72 | Http::StatusCode purgeStatus; |
---|
73 | |
---|
74 | /* state variable - replace with class to handle storeentries at some point */ |
---|
75 | int lookingforstore; |
---|
76 | virtual void created (StoreEntry *newEntry); |
---|
77 | |
---|
78 | ClientHttpRequest *http; |
---|
79 | int headers_sz; |
---|
80 | store_client *sc; /* The store_client we're using */ |
---|
81 | StoreIOBuffer tempBuffer; /* For use in validating requests via IMS */ |
---|
82 | int old_reqsize; /* ... again, for the buffer */ |
---|
83 | size_t reqsize; |
---|
84 | size_t reqofs; |
---|
85 | char tempbuf[HTTP_REQBUF_SZ]; /* a temporary buffer if we need working storage */ |
---|
86 | #if USE_CACHE_DIGESTS |
---|
87 | |
---|
88 | const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */ |
---|
89 | #endif |
---|
90 | |
---|
91 | struct { |
---|
92 | |
---|
93 | unsigned storelogiccomplete:1; |
---|
94 | |
---|
95 | unsigned complete:1; /* we have read all we can from upstream */ |
---|
96 | bool headersSent; |
---|
97 | } flags; |
---|
98 | clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */ |
---|
99 | |
---|
100 | private: |
---|
101 | clientStreamNode *getNextNode() const; |
---|
102 | void makeThisHead(); |
---|
103 | bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const ; |
---|
104 | void sendStreamError(StoreIOBuffer const &result); |
---|
105 | void pushStreamData(StoreIOBuffer const &result, char *source); |
---|
106 | clientStreamNode * next() const; |
---|
107 | StoreIOBuffer holdingBuffer; |
---|
108 | HttpReply *reply; |
---|
109 | void processReplyAccess(); |
---|
110 | static ACLCB ProcessReplyAccessResult; |
---|
111 | void processReplyAccessResult(const allow_t &accessAllowed); |
---|
112 | void cloneReply(); |
---|
113 | void buildReplyHeader (); |
---|
114 | bool alwaysAllowResponse(Http::StatusCode sline) const; |
---|
115 | int checkTransferDone(); |
---|
116 | void processOnlyIfCachedMiss(); |
---|
117 | void processConditional(StoreIOBuffer &result); |
---|
118 | void cacheHit(StoreIOBuffer result); |
---|
119 | void handleIMSReply(StoreIOBuffer result); |
---|
120 | void sendMoreData(StoreIOBuffer result); |
---|
121 | void triggerInitialStoreRead(); |
---|
122 | void sendClientOldEntry(); |
---|
123 | void purgeAllCached(); |
---|
124 | void forgetHit(); |
---|
125 | bool blockedHit() const; |
---|
126 | |
---|
127 | void sendBodyTooLargeError(); |
---|
128 | void sendPreconditionFailedError(); |
---|
129 | void sendNotModified(); |
---|
130 | void sendNotModifiedOrPreconditionFailedError(); |
---|
131 | |
---|
132 | StoreEntry *old_entry; |
---|
133 | store_client *old_sc; /* ... for entry to be validated */ |
---|
134 | bool deleting; |
---|
135 | |
---|
136 | CBDATA_CLASS2(clientReplyContext); |
---|
137 | }; |
---|
138 | |
---|
139 | #endif /* SQUID_CLIENTSIDEREPLY_H */ |
---|
140 | |
---|