5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
36 \defgroup StoreAPI Store API
41 #include "StoreIOBuffer.h"
46 #include "RemovalPolicy.h"
49 #include "esi/Element.h"
63 typedef unsigned int ping_status_t
;
68 class StoreEntry
: public hash_link
72 static DeferredRead::DeferrableRead DeferReader
;
73 bool checkDeferRead(int fd
) const;
75 virtual const char *getMD5Text() const;
77 StoreEntry(const char *url
, const char *log_url
);
78 virtual ~StoreEntry() {}
80 virtual HttpReply
const *getReply() const;
81 virtual void write (StoreIOBuffer
);
82 virtual _SQUID_INLINE_
bool isEmpty() const;
83 virtual bool isAccepting() const;
84 virtual size_t bytesWanted(Range
<size_t> const) const;
85 virtual void complete();
86 virtual store_client_t
storeClientType() const;
87 virtual char const *getSerialisedMetaData();
88 virtual void replaceHttpReply(HttpReply
*);
89 virtual bool swapoutPossible();
90 virtual void trimMemory();
98 void releaseRequest();
100 void cacheNegatively(); /** \todo argh, why both? */
101 void invokeHandlers();
104 bool swapOutAble() const;
105 void swapOutFileClose();
106 const char *url() const;
108 int checkNegativeHit() const;
110 int validToSend() const;
111 int keepInMemory() const;
112 void createMemObject(const char *, const char *);
113 void dump(int debug_lvl
) const;
115 void hashInsert(const cache_key
*);
116 void registerAbort(STABH
* cb
, void *);
118 void setMemStatus(mem_status_t
);
119 void timestampsSet();
120 void unregisterAbort();
121 void destroyMemObject();
124 void delayAwareRead(int fd
, char *buf
, int len
, AsyncCall::Pointer callback
);
126 void setNoDelay (bool const);
127 bool modifiedSince(HttpRequest
* request
) const;
129 /** What store does this entry belong too ? */
130 virtual RefCount
<Store
> store() const;
133 RemovalPolicyNode repl
;
134 /* START OF ON-DISK STORE_META_STD TLV field */
139 uint64_t swap_file_sz
;
142 /* END OF ON-DISK STORE_META_STD */
149 u_short lock_count
; /* Assume < 65536! */
151 mem_status_t mem_status
:
154 ping_status_t ping_status
:
157 store_status_t store_status
:
160 swap_status_t swap_status
:
164 static size_t inUseCount();
165 static void getPublicByRequestMethod(StoreClient
* aClient
, HttpRequest
* request
, const HttpRequestMethod
& method
);
166 static void getPublicByRequest(StoreClient
* aClient
, HttpRequest
* request
);
167 static void getPublic(StoreClient
* aClient
, const char *uri
, const HttpRequestMethod
& method
);
169 virtual bool isNull() {
173 void *operator new(size_t byteCount
);
174 void operator delete(void *address
);
175 void setReleaseFlag();
178 ESIElement::Pointer cachedESITree
;
180 /** append bytes to the buffer */
181 virtual void append(char const *, int len
);
182 /** disable sending content to the clients */
183 virtual void buffer();
184 /** flush any buffered content */
185 virtual void flush();
186 /** reduce the memory lock count on the entry */
187 virtual int unlock();
188 /** increate the memory lock count on the entry */
189 virtual int64_t objectLen() const;
190 virtual int64_t contentLen() const;
193 virtual void release();
196 static MemAllocator
*pool
;
198 bool validLength() const;
201 /// \ingroup StoreAPI
202 class NullStoreEntry
:public StoreEntry
206 static NullStoreEntry
*getInstance();
211 const char *getMD5Text() const;
212 _SQUID_INLINE_ HttpReply
const *getReply() const;
213 void write (StoreIOBuffer
) {}
215 bool isEmpty () const {return true;}
217 virtual size_t bytesWanted(Range
<size_t> const aRange
) const { assert (aRange
.size());return aRange
.end
- 1;}
219 void operator delete(void *address
);
223 store_client_t
storeClientType() const {return STORE_MEM_CLIENT
;}
225 char const *getSerialisedMetaData();
226 bool swapoutPossible() {return false;}
231 static NullStoreEntry _instance
;
234 /// \ingroup StoreAPI
235 typedef void (*STOREGETCLIENT
) (StoreEntry
*, void *cbdata
);
240 * Abstract base class that will replace the whole store and swapdir interface.
242 class Store
: public RefCountable
246 /** The root store */
247 static _SQUID_INLINE_ Store
&Root();
248 static void Root(Store
*);
249 static void Root(RefCount
<Store
>);
250 static void Stats(StoreEntry
* output
);
251 static void Maintain(void *unused
);
255 /** Handle pending callbacks - called by the event loop. */
256 virtual int callback() = 0;
258 /** create the resources needed for this store to operate */
259 virtual void create();
262 * Notify this store that its disk is full.
263 \todo XXX move into a protected api call between store files and their stores, rather than a top level api call
265 virtual void diskFull();
267 /** Retrieve a store entry from the store */
268 virtual StoreEntry
* get(const cache_key
*) = 0;
270 /** \todo imeplement the async version */
271 virtual void get(String
const key
, STOREGETCLIENT callback
, void *cbdata
) = 0;
273 /* prepare the store for use. The store need not be usable immediately,
274 * it should respond to readable() and writable() with true as soon
275 * as it can provide those services
277 virtual void init() = 0;
280 * The maximum size the store will support in normal use. Inaccuracy is permitted,
281 * but may throw estimates for memory etc out of whack.
283 virtual size_t maxSize() const = 0;
285 /** The minimum size the store will shrink to via normal housekeeping */
286 virtual size_t minSize() const = 0;
289 * Output stats to the provided store entry.
290 \todo make these calls asynchronous
292 virtual void stat(StoreEntry
&) const = 0;
294 /** Sync the store prior to shutdown */
297 /** remove a Store entry from the store */
298 virtual void unlink (StoreEntry
&);
300 /* search in the store */
301 virtual StoreSearch
*search(String
const url
, HttpRequest
*) = 0;
303 /* pulled up from SwapDir for migration.... probably do not belong here */
304 virtual void reference(StoreEntry
&) = 0; /* Reference this object */
306 virtual void dereference(StoreEntry
&) = 0; /* Unreference this object */
308 virtual void maintain() = 0; /* perform regular maintenance should be private and self registered ... */
310 /* These should really be private */
311 virtual void updateSize(int64_t size
, int sign
) = 0;
314 static RefCount
<Store
> CurrentRoot
;
317 /// \ingroup StoreAPI
318 typedef RefCount
<Store
> StorePointer
;
320 /// \ingroup StoreAPI
321 SQUIDCEXTERN
size_t storeEntryInUse();
323 /// \ingroup StoreAPI
324 SQUIDCEXTERN
const char *storeEntryFlags(const StoreEntry
*);
326 /// \ingroup StoreAPI
327 extern void storeEntryReplaceObject(StoreEntry
*, HttpReply
*);
329 /// \ingroup StoreAPI
330 SQUIDCEXTERN StoreEntry
*storeGetPublic(const char *uri
, const HttpRequestMethod
& method
);
332 /// \ingroup StoreAPI
333 SQUIDCEXTERN StoreEntry
*storeGetPublicByRequest(HttpRequest
* request
);
335 /// \ingroup StoreAPI
336 SQUIDCEXTERN StoreEntry
*storeGetPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
);
338 /// \ingroup StoreAPI
339 SQUIDCEXTERN StoreEntry
*storeCreateEntry(const char *, const char *, request_flags
, const HttpRequestMethod
&);
341 /// \ingroup StoreAPI
342 SQUIDCEXTERN
void storeInit(void);
344 /// \ingroup StoreAPI
345 SQUIDCEXTERN
void storeConfigure(void);
347 /// \ingroup StoreAPI
348 SQUIDCEXTERN
void storeFreeMemory(void);
350 /// \ingroup StoreAPI
351 SQUIDCEXTERN
int expiresMoreThan(time_t, time_t);
353 /// \ingroup StoreAPI
354 SQUIDCEXTERN
void storeAppendPrintf(StoreEntry
*, const char *,...) PRINTF_FORMAT_ARG2
;
356 /// \ingroup StoreAPI
357 SQUIDCEXTERN
void storeAppendVPrintf(StoreEntry
*, const char *, va_list ap
);
359 /// \ingroup StoreAPI
360 SQUIDCEXTERN
int storeTooManyDiskFilesOpen(void);
363 /// \ingroup StoreAPI
364 SQUIDCEXTERN
void storeHeapPositionUpdate(StoreEntry
*, SwapDir
*);
366 /// \ingroup StoreAPI
367 SQUIDCEXTERN
void storeSwapFileNumberSet(StoreEntry
* e
, sfileno filn
);
369 /// \ingroup StoreAPI
370 SQUIDCEXTERN
void storeFsInit(void);
372 /// \ingroup StoreAPI
373 SQUIDCEXTERN
void storeFsDone(void);
375 /// \ingroup StoreAPI
376 SQUIDCEXTERN
void storeReplAdd(const char *, REMOVALPOLICYCREATE
*);
378 /// \ingroup StoreAPI
379 extern FREE destroyStoreEntry
;
383 \todo should be a subclass of Packer perhaps ?
385 SQUIDCEXTERN
void packerToStoreInit(Packer
* p
, StoreEntry
* e
);
391 #endif /* SQUID_STORE_H */