]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Store.h
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / Store.h
1 /*
2 * $Id$
3 *
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32 #ifndef SQUID_STORE_H
33 #define SQUID_STORE_H
34
35 /**
36 \defgroup StoreAPI Store API
37 \ingroup FileSystems
38 */
39
40 #include "squid.h"
41
42 /// \todo protect the 'ostream' file includes via configure file tests as per squid conventions.
43 #include <ostream>
44
45 #include "StoreIOBuffer.h"
46 #include "Range.h"
47 #include "RefCount.h"
48 #include "CommRead.h"
49 #include "Packer.h"
50 #include "RemovalPolicy.h"
51
52 #if USE_SQUID_ESI
53 #include "ESIElement.h"
54 #endif
55
56 class AsyncCall;
57 class StoreClient;
58 class MemObject;
59 class Store;
60 class StoreSearch;
61
62 typedef unsigned int ping_status_t;
63
64 /**
65 \ingroup StoreAPI
66 */
67 class StoreEntry : public hash_link
68 {
69
70 public:
71 static DeferredRead::DeferrableRead DeferReader;
72 bool checkDeferRead(int fd) const;
73
74 virtual const char *getMD5Text() const;
75 StoreEntry();
76 StoreEntry(const char *url, const char *log_url);
77 virtual ~StoreEntry() {}
78
79 virtual HttpReply const *getReply() const;
80 virtual void write (StoreIOBuffer);
81 virtual _SQUID_INLINE_ bool isEmpty() const;
82 virtual bool isAccepting() const;
83 virtual size_t bytesWanted(Range<size_t> const) const;
84 virtual void complete();
85 virtual store_client_t storeClientType() const;
86 virtual char const *getSerialisedMetaData();
87 virtual void replaceHttpReply(HttpReply *);
88 virtual bool swapoutPossible();
89 virtual void trimMemory();
90 void abort();
91 void unlink();
92 void makePublic();
93 void makePrivate();
94 void setPublicKey();
95 void setPrivateKey();
96 void expireNow();
97 void releaseRequest();
98 void negativeCache();
99 void cacheNegatively(); /** \todo argh, why both? */
100 void invokeHandlers();
101 void purgeMem();
102 void swapOut();
103 bool swapOutAble() const;
104 void swapOutFileClose();
105 const char *url() const;
106 int checkCachable();
107 int checkNegativeHit() const;
108 int locked() const;
109 int validToSend() const;
110 int keepInMemory() const;
111 void createMemObject(const char *, const char *);
112 void dump(int debug_lvl) const;
113 void hashDelete();
114 void hashInsert(const cache_key *);
115 void registerAbort(STABH * cb, void *);
116 void reset();
117 void setMemStatus(mem_status_t);
118 void timestampsSet();
119 void unregisterAbort();
120 void destroyMemObject();
121 int checkTooSmall();
122
123 void delayAwareRead(int fd, char *buf, int len, AsyncCall::Pointer callback);
124
125 void setNoDelay (bool const);
126 bool modifiedSince(HttpRequest * request) const;
127
128 /** What store does this entry belong too ? */
129 virtual RefCount<Store> store() const;
130
131 MemObject *mem_obj;
132 RemovalPolicyNode repl;
133 /* START OF ON-DISK STORE_META_STD TLV field */
134 time_t timestamp;
135 time_t lastref;
136 time_t expires;
137 time_t lastmod;
138 uint64_t swap_file_sz;
139 u_short refcount;
140 u_short flags;
141 /* END OF ON-DISK STORE_META_STD */
142
143 sfileno swap_filen:
144 25;
145
146 sdirno swap_dirn:
147 7;
148 u_short lock_count; /* Assume < 65536! */
149
150 mem_status_t mem_status:
151 3;
152
153 ping_status_t ping_status:
154 3;
155
156 store_status_t store_status:
157 3;
158
159 swap_status_t swap_status:
160 3;
161
162 public:
163 static size_t inUseCount();
164 static void getPublicByRequestMethod(StoreClient * aClient, HttpRequest * request, const HttpRequestMethod& method);
165 static void getPublicByRequest(StoreClient * aClient, HttpRequest * request);
166 static void getPublic(StoreClient * aClient, const char *uri, const HttpRequestMethod& method);
167
168 virtual bool isNull() {
169 return false;
170 };
171
172 void *operator new(size_t byteCount);
173 void operator delete(void *address);
174 void setReleaseFlag();
175 #if USE_SQUID_ESI
176
177 ESIElement::Pointer cachedESITree;
178 #endif
179 /** append bytes to the buffer */
180 virtual void append(char const *, int len);
181 /** disable sending content to the clients */
182 virtual void buffer();
183 /** flush any buffered content */
184 virtual void flush();
185 /** reduce the memory lock count on the entry */
186 virtual int unlock();
187 /** increate the memory lock count on the entry */
188 virtual int64_t objectLen() const;
189 virtual int64_t contentLen() const;
190
191 virtual void lock();
192 virtual void release();
193
194 private:
195 static MemAllocator *pool;
196
197 bool validLength() const;
198 };
199
200 /// \ingroup StoreAPI
201 class NullStoreEntry:public StoreEntry
202 {
203
204 public:
205 static NullStoreEntry *getInstance();
206 bool isNull() {
207 return true;
208 }
209
210 const char *getMD5Text() const;
211 _SQUID_INLINE_ HttpReply const *getReply() const;
212 void write (StoreIOBuffer) {}
213
214 bool isEmpty () const {return true;}
215
216 virtual size_t bytesWanted(Range<size_t> const aRange) const { assert (aRange.size());return aRange.end - 1;}
217
218 void operator delete(void *address);
219 void complete() {}
220
221 private:
222 store_client_t storeClientType() const {return STORE_MEM_CLIENT;}
223
224 char const *getSerialisedMetaData();
225 bool swapoutPossible() {return false;}
226
227 void trimMemory() {}
228
229
230 static NullStoreEntry _instance;
231 };
232
233 /// \ingroup StoreAPI
234 typedef void (*STOREGETCLIENT) (StoreEntry *, void *cbdata);
235
236
237 /**
238 \ingroup StoreAPI
239 * Abstract base class that will replace the whole store and swapdir interface.
240 */
241 class Store : public RefCountable
242 {
243
244 public:
245 /** The root store */
246 static _SQUID_INLINE_ Store &Root();
247 static void Root(Store *);
248 static void Root(RefCount<Store>);
249 static void Stats(StoreEntry * output);
250 static void Maintain(void *unused);
251
252 virtual ~Store() {}
253
254 /** Handle pending callbacks - called by the event loop. */
255 virtual int callback() = 0;
256
257 /** create the resources needed for this store to operate */
258 virtual void create();
259
260 /**
261 * Notify this store that its disk is full.
262 \todo XXX move into a protected api call between store files and their stores, rather than a top level api call
263 */
264 virtual void diskFull();
265
266 /** Retrieve a store entry from the store */
267 virtual StoreEntry * get
268 (const cache_key *) = 0;
269
270 /** \todo imeplement the async version */
271 virtual void get
272 (String const key , STOREGETCLIENT callback, void *cbdata) = 0;
273
274 /* prepare the store for use. The store need not be usable immediately,
275 * it should respond to readable() and writable() with true as soon
276 * as it can provide those services
277 */
278 virtual void init() = 0;
279
280 /**
281 * The maximum size the store will support in normal use. Inaccuracy is permitted,
282 * but may throw estimates for memory etc out of whack.
283 */
284 virtual size_t maxSize() const = 0;
285
286 /** The minimum size the store will shrink to via normal housekeeping */
287 virtual size_t minSize() const = 0;
288
289 /**
290 * Output stats to the provided store entry.
291 \todo make these calls asynchronous
292 */
293 virtual void stat(StoreEntry &) const = 0;
294
295 /** Sync the store prior to shutdown */
296 virtual void sync();
297
298 /** remove a Store entry from the store */
299 virtual void unlink (StoreEntry &);
300
301 /* search in the store */
302 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
303
304 /* pulled up from SwapDir for migration.... probably do not belong here */
305 virtual void reference(StoreEntry &) = 0; /* Reference this object */
306
307 virtual void dereference(StoreEntry &) = 0; /* Unreference this object */
308
309 virtual void maintain() = 0; /* perform regular maintenance should be private and self registered ... */
310
311 /* These should really be private */
312 virtual void updateSize(int64_t size, int sign) = 0;
313
314 private:
315 static RefCount<Store> CurrentRoot;
316 };
317
318 /// \ingroup StoreAPI
319 typedef RefCount<Store> StorePointer;
320
321 /// \ingroup StoreAPI
322 SQUIDCEXTERN size_t storeEntryInUse();
323
324 /// \ingroup StoreAPI
325 SQUIDCEXTERN const char *storeEntryFlags(const StoreEntry *);
326
327 /// \ingroup StoreAPI
328 extern void storeEntryReplaceObject(StoreEntry *, HttpReply *);
329
330 /// \ingroup StoreAPI
331 SQUIDCEXTERN StoreEntry *storeGetPublic(const char *uri, const HttpRequestMethod& method);
332
333 /// \ingroup StoreAPI
334 SQUIDCEXTERN StoreEntry *storeGetPublicByRequest(HttpRequest * request);
335
336 /// \ingroup StoreAPI
337 SQUIDCEXTERN StoreEntry *storeGetPublicByRequestMethod(HttpRequest * request, const HttpRequestMethod& method);
338
339 /// \ingroup StoreAPI
340 SQUIDCEXTERN StoreEntry *storeCreateEntry(const char *, const char *, request_flags, const HttpRequestMethod&);
341
342 /// \ingroup StoreAPI
343 SQUIDCEXTERN void storeInit(void);
344
345 /// \ingroup StoreAPI
346 SQUIDCEXTERN void storeConfigure(void);
347
348 /// \ingroup StoreAPI
349 SQUIDCEXTERN void storeFreeMemory(void);
350
351 /// \ingroup StoreAPI
352 SQUIDCEXTERN int expiresMoreThan(time_t, time_t);
353
354 #if STDC_HEADERS
355 /// \ingroup StoreAPI
356 SQUIDCEXTERN void storeAppendPrintf(StoreEntry *, const char *,...) PRINTF_FORMAT_ARG2;
357 #else
358 /// \ingroup StoreAPI
359 SQUIDCEXTERN void storeAppendPrintf();
360 #endif
361
362 /// \ingroup StoreAPI
363 SQUIDCEXTERN void storeAppendVPrintf(StoreEntry *, const char *, va_list ap);
364
365 /// \ingroup StoreAPI
366 SQUIDCEXTERN int storeTooManyDiskFilesOpen(void);
367
368 class SwapDir;
369 /// \ingroup StoreAPI
370 SQUIDCEXTERN void storeHeapPositionUpdate(StoreEntry *, SwapDir *);
371
372 /// \ingroup StoreAPI
373 SQUIDCEXTERN void storeSwapFileNumberSet(StoreEntry * e, sfileno filn);
374
375 /// \ingroup StoreAPI
376 SQUIDCEXTERN void storeFsInit(void);
377
378 /// \ingroup StoreAPI
379 SQUIDCEXTERN void storeFsDone(void);
380
381 /// \ingroup StoreAPI
382 SQUIDCEXTERN void storeReplAdd(const char *, REMOVALPOLICYCREATE *);
383
384 /// \ingroup StoreAPI
385 extern FREE destroyStoreEntry;
386
387 /**
388 \ingroup StoreAPI
389 \todo should be a subclass of Packer perhaps ?
390 */
391 SQUIDCEXTERN void packerToStoreInit(Packer * p, StoreEntry * e);
392
393 #ifdef _USE_INLINE_
394 #include "Store.cci"
395 #endif
396
397 #endif /* SQUID_STORE_H */