]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Store.h
Author: Alexey Veselovsky <alexey.veselovsky@eykontech.com>
[thirdparty/squid.git] / src / Store.h
1
2 /*
3 * $Id: Store.h,v 1.42 2008/01/20 08:54:28 amosjeffries 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_STORE_H
35 #define SQUID_STORE_H
36
37 #include "squid.h"
38
39 #include <ostream>
40
41 #include "StoreIOBuffer.h"
42 #include "Range.h"
43 #include "RefCount.h"
44 #include "CommRead.h"
45 #include "Packer.h"
46 #include "RemovalPolicy.h"
47
48 #if USE_SQUID_ESI
49 #include "ESIElement.h"
50 #endif
51
52 class StoreClient;
53
54 class MemObject;
55
56 class Store;
57
58 class StoreSearch;
59
60 class StoreEntry : public hash_link
61 {
62
63 public:
64 static DeferredRead::DeferrableRead DeferReader;
65 bool checkDeferRead(int fd) const;
66
67 virtual const char *getMD5Text() const;
68 StoreEntry();
69 StoreEntry(const char *url, const char *log_url);
70 virtual ~StoreEntry(){}
71
72 virtual HttpReply const *getReply() const;
73 virtual void write (StoreIOBuffer);
74 virtual _SQUID_INLINE_ bool isEmpty() const;
75 virtual bool isAccepting() const;
76 virtual size_t bytesWanted(Range<size_t> const) const;
77 virtual void complete();
78 virtual store_client_t storeClientType() const;
79 virtual char const *getSerialisedMetaData();
80 virtual void replaceHttpReply(HttpReply *);
81 virtual bool swapoutPossible();
82 virtual void trimMemory();
83 void abort();
84 void unlink();
85 void makePublic();
86 void makePrivate();
87 void setPublicKey();
88 void setPrivateKey();
89 void expireNow();
90 void releaseRequest();
91 void negativeCache();
92 void cacheNegatively(); /* argh, why both? */
93 void invokeHandlers();
94 void purgeMem();
95 void swapOut();
96 bool swapOutAble() const;
97 void swapOutFileClose();
98 const char *url() const;
99 int checkCachable();
100 int checkNegativeHit() const;
101 int locked() const;
102 int validToSend() const;
103 int keepInMemory() const;
104 void createMemObject(const char *, const char *);
105 void dump(int debug_lvl) const;
106 void hashDelete();
107 void hashInsert(const cache_key *);
108 void registerAbort(STABH * cb, void *);
109 void reset();
110 void setMemStatus(mem_status_t);
111 void timestampsSet();
112 void unregisterAbort();
113 void destroyMemObject();
114 int checkTooSmall();
115
116 void delayAwareRead(int fd, char *buf, int len, IOCB *handler, void *data);
117
118 void setNoDelay (bool const);
119 bool modifiedSince(HttpRequest * request) const;
120 /* what store does this entry belong too ? */
121 virtual RefCount<Store> store() const;
122
123 MemObject *mem_obj;
124 RemovalPolicyNode repl;
125 /* START OF ON-DISK STORE_META_STD TLV field */
126 time_t timestamp;
127 time_t lastref;
128 time_t expires;
129 time_t lastmod;
130 uint64_t swap_file_sz;
131 u_short refcount;
132 u_short flags;
133 /* END OF ON-DISK STORE_META_STD */
134
135 sfileno swap_filen:
136 25;
137
138 sdirno swap_dirn:
139 7;
140 u_short lock_count; /* Assume < 65536! */
141
142 mem_status_t mem_status:
143 3;
144
145 ping_status_t ping_status:
146 3;
147
148 store_status_t store_status:
149 3;
150
151 swap_status_t swap_status:
152 3;
153
154 public:
155 static size_t inUseCount();
156 static void getPublicByRequestMethod(StoreClient * aClient, HttpRequest * request, const HttpRequestMethod& method);
157 static void getPublicByRequest(StoreClient * aClient, HttpRequest * request);
158 static void getPublic(StoreClient * aClient, const char *uri, const HttpRequestMethod& method);
159
160 virtual bool isNull()
161 {
162 return false;
163 }
164
165 void *operator new(size_t byteCount);
166 void operator delete(void *address);
167 void setReleaseFlag();
168 #if USE_SQUID_ESI
169
170 ESIElement::Pointer cachedESITree;
171 #endif
172 /* append bytes to the buffer */
173 virtual void append(char const *, int len);
174 /* disable sending content to the clients */
175 virtual void buffer();
176 /* flush any buffered content */
177 virtual void flush();
178 /* reduce the memory lock count on the entry */
179 virtual int unlock();
180 /* increate the memory lock count on the entry */
181 virtual int64_t objectLen() const;
182 virtual int64_t contentLen() const;
183
184 virtual void lock()
185
186 ;
187 virtual void release();
188
189 private:
190 static MemAllocator *pool;
191
192 bool validLength() const;
193 };
194
195 class NullStoreEntry:public StoreEntry
196 {
197
198 public:
199 static NullStoreEntry *getInstance();
200 bool isNull()
201 {
202 return true;
203 }
204
205 const char *getMD5Text() const;
206 _SQUID_INLINE_ HttpReply const *getReply() const;
207 void write (StoreIOBuffer){}
208
209 bool isEmpty () const {return true;}
210
211 virtual size_t bytesWanted(Range<size_t> const aRange) const { assert (aRange.size());return aRange.end - 1;}
212
213 void operator delete(void *address);
214 void complete(){}
215
216 private:
217 store_client_t storeClientType() const{return STORE_MEM_CLIENT;}
218
219 char const *getSerialisedMetaData();
220 bool swapoutPossible() {return false;}
221
222 void trimMemory() {}
223
224
225 static NullStoreEntry _instance;
226 };
227
228 typedef void (*STOREGETCLIENT) (StoreEntry *, void *cbdata);
229
230
231 /* Abstract base class that will replace the whole store and swapdir interface. */
232
233 class Store : public RefCountable
234 {
235
236 public:
237 /* The root store */
238 static _SQUID_INLINE_ Store &Root();
239 static void Root(Store *);
240 static void Root(RefCount<Store>);
241 static void Stats(StoreEntry * output);
242 static void Maintain(void *unused);
243
244 virtual ~Store() {}
245
246 /* Handle pending callbacks - called by the event loop. */
247 virtual int callback() = 0;
248 /* create the resources needed for this store to operate */
249 virtual void create();
250 /* notify this store that its disk is full. TODO XXX move into a protected api call
251 * between store files and their stores, rather than a top level api call
252 */
253 virtual void diskFull();
254 /* Retrieve a store entry from the store */
255
256 virtual StoreEntry * get
257 (const cache_key *) = 0;
258
259 /* TODO: imeplement the async version */
260 virtual void get
261 (String const key , STOREGETCLIENT callback, void *cbdata) = 0;
262
263 /* prepare the store for use. The store need not be usable immediately,
264 * it should respond to readable() and writable() with true as soon
265 * as it can provide those services
266 */
267 virtual void init() = 0;
268
269 /* the maximum size the store will support in normal use. Inaccuracy is permitted,
270 * but may throw estimates for memory etc out of whack. */
271 virtual size_t maxSize() const = 0;
272
273 /* The minimum size the store will shrink to via normal housekeeping */
274 virtual size_t minSize() const = 0;
275
276 /* TODO: make these calls asynchronous */
277 virtual void stat(StoreEntry &) const = 0; /* output stats to the provided store entry */
278
279 virtual void sync(); /* Sync the store prior to shutdown */
280
281 /* remove a Store entry from the store */
282 virtual void unlink (StoreEntry &);
283
284 /* search in the store */
285 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
286
287 /* pulled up from SwapDir for migration.... probably do not belong here */
288 virtual void reference(StoreEntry &) = 0; /* Reference this object */
289
290 virtual void dereference(StoreEntry &) = 0; /* Unreference this object */
291
292 virtual void maintain() = 0; /* perform regular maintenance should be private and self registered ... */
293
294 /* These should really be private */
295 virtual void updateSize(int64_t size, int sign) = 0;
296
297 private:
298 static RefCount<Store> CurrentRoot;
299 };
300
301 typedef RefCount<Store> StorePointer;
302
303 SQUIDCEXTERN size_t storeEntryInUse();
304 SQUIDCEXTERN const char *storeEntryFlags(const StoreEntry *);
305 extern void storeEntryReplaceObject(StoreEntry *, HttpReply *);
306
307 SQUIDCEXTERN StoreEntry *storeGetPublic(const char *uri, const HttpRequestMethod& method);
308 SQUIDCEXTERN StoreEntry *storeGetPublicByRequest(HttpRequest * request);
309 SQUIDCEXTERN StoreEntry *storeGetPublicByRequestMethod(HttpRequest * request, const HttpRequestMethod& method);
310 SQUIDCEXTERN StoreEntry *storeCreateEntry(const char *, const char *, request_flags, const HttpRequestMethod&);
311 SQUIDCEXTERN void storeInit(void);
312 extern void storeRegisterWithCacheManager(CacheManager & manager);
313 SQUIDCEXTERN void storeConfigure(void);
314 SQUIDCEXTERN void storeFreeMemory(void);
315 SQUIDCEXTERN int expiresMoreThan(time_t, time_t);
316 #if STDC_HEADERS
317 SQUIDCEXTERN void
318 storeAppendPrintf(StoreEntry *, const char *,...) PRINTF_FORMAT_ARG2;
319 #else
320 SQUIDCEXTERN void storeAppendPrintf();
321 #endif
322 SQUIDCEXTERN void storeAppendVPrintf(StoreEntry *, const char *, va_list ap);
323 SQUIDCEXTERN int storeTooManyDiskFilesOpen(void);
324 SQUIDCEXTERN void storeHeapPositionUpdate(StoreEntry *, SwapDir *);
325 SQUIDCEXTERN void storeSwapFileNumberSet(StoreEntry * e, sfileno filn);
326 SQUIDCEXTERN void storeFsInit(void);
327 SQUIDCEXTERN void storeFsDone(void);
328 SQUIDCEXTERN void storeReplAdd(const char *, REMOVALPOLICYCREATE *);
329 extern FREE destroyStoreEntry;
330
331 /* should be a subclass of Packer perhaps ? */
332 SQUIDCEXTERN void packerToStoreInit(Packer * p, StoreEntry * e);
333
334 #ifdef _USE_INLINE_
335 #include "Store.cci"
336 #endif
337
338 #endif /* SQUID_STORE_H */