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