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