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
42 /// \todo protect the 'ostream' file includes via configure file tests as per squid conventions.
45 #include "StoreIOBuffer.h"
50 #include "RemovalPolicy.h"
53 #include "ESIElement.h"
62 typedef unsigned int ping_status_t
;
67 class StoreEntry
: public hash_link
71 static DeferredRead::DeferrableRead DeferReader
;
72 bool checkDeferRead(int fd
) const;
74 virtual const char *getMD5Text() const;
76 StoreEntry(const char *url
, const char *log_url
);
77 virtual ~StoreEntry() {}
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();
97 void releaseRequest();
99 void cacheNegatively(); /** \todo argh, why both? */
100 void invokeHandlers();
103 bool swapOutAble() const;
104 void swapOutFileClose();
105 const char *url() const;
107 int checkNegativeHit() const;
109 int validToSend() const;
110 int keepInMemory() const;
111 void createMemObject(const char *, const char *);
112 void dump(int debug_lvl
) const;
114 void hashInsert(const cache_key
*);
115 void registerAbort(STABH
* cb
, void *);
117 void setMemStatus(mem_status_t
);
118 void timestampsSet();
119 void unregisterAbort();
120 void destroyMemObject();
123 void delayAwareRead(int fd
, char *buf
, int len
, AsyncCall::Pointer callback
);
125 void setNoDelay (bool const);
126 bool modifiedSince(HttpRequest
* request
) const;
128 /** What store does this entry belong too ? */
129 virtual RefCount
<Store
> store() const;
132 RemovalPolicyNode repl
;
133 /* START OF ON-DISK STORE_META_STD TLV field */
138 uint64_t swap_file_sz
;
141 /* END OF ON-DISK STORE_META_STD */
148 u_short lock_count
; /* Assume < 65536! */
150 mem_status_t mem_status
:
153 ping_status_t ping_status
:
156 store_status_t store_status
:
159 swap_status_t swap_status
:
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
);
168 virtual bool isNull() {
172 void *operator new(size_t byteCount
);
173 void operator delete(void *address
);
174 void setReleaseFlag();
177 ESIElement::Pointer cachedESITree
;
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;
192 virtual void release();
195 static MemAllocator
*pool
;
197 bool validLength() const;
200 /// \ingroup StoreAPI
201 class NullStoreEntry
:public StoreEntry
205 static NullStoreEntry
*getInstance();
210 const char *getMD5Text() const;
211 _SQUID_INLINE_ HttpReply
const *getReply() const;
212 void write (StoreIOBuffer
) {}
214 bool isEmpty () const {return true;}
216 virtual size_t bytesWanted(Range
<size_t> const aRange
) const { assert (aRange
.size());return aRange
.end
- 1;}
218 void operator delete(void *address
);
222 store_client_t
storeClientType() const {return STORE_MEM_CLIENT
;}
224 char const *getSerialisedMetaData();
225 bool swapoutPossible() {return false;}
230 static NullStoreEntry _instance
;
233 /// \ingroup StoreAPI
234 typedef void (*STOREGETCLIENT
) (StoreEntry
*, void *cbdata
);
239 * Abstract base class that will replace the whole store and swapdir interface.
241 class Store
: public RefCountable
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
);
254 /** Handle pending callbacks - called by the event loop. */
255 virtual int callback() = 0;
257 /** create the resources needed for this store to operate */
258 virtual void create();
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
264 virtual void diskFull();
266 /** Retrieve a store entry from the store */
267 virtual StoreEntry
* get
268 (const cache_key
*) = 0;
270 /** \todo imeplement the async version */
272 (String
const key
, STOREGETCLIENT callback
, void *cbdata
) = 0;
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
278 virtual void init() = 0;
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.
284 virtual size_t maxSize() const = 0;
286 /** The minimum size the store will shrink to via normal housekeeping */
287 virtual size_t minSize() const = 0;
290 * Output stats to the provided store entry.
291 \todo make these calls asynchronous
293 virtual void stat(StoreEntry
&) const = 0;
295 /** Sync the store prior to shutdown */
298 /** remove a Store entry from the store */
299 virtual void unlink (StoreEntry
&);
301 /* search in the store */
302 virtual StoreSearch
*search(String
const url
, HttpRequest
*) = 0;
304 /* pulled up from SwapDir for migration.... probably do not belong here */
305 virtual void reference(StoreEntry
&) = 0; /* Reference this object */
307 virtual void dereference(StoreEntry
&) = 0; /* Unreference this object */
309 virtual void maintain() = 0; /* perform regular maintenance should be private and self registered ... */
311 /* These should really be private */
312 virtual void updateSize(int64_t size
, int sign
) = 0;
315 static RefCount
<Store
> CurrentRoot
;
318 /// \ingroup StoreAPI
319 typedef RefCount
<Store
> StorePointer
;
321 /// \ingroup StoreAPI
322 SQUIDCEXTERN
size_t storeEntryInUse();
324 /// \ingroup StoreAPI
325 SQUIDCEXTERN
const char *storeEntryFlags(const StoreEntry
*);
327 /// \ingroup StoreAPI
328 extern void storeEntryReplaceObject(StoreEntry
*, HttpReply
*);
330 /// \ingroup StoreAPI
331 SQUIDCEXTERN StoreEntry
*storeGetPublic(const char *uri
, const HttpRequestMethod
& method
);
333 /// \ingroup StoreAPI
334 SQUIDCEXTERN StoreEntry
*storeGetPublicByRequest(HttpRequest
* request
);
336 /// \ingroup StoreAPI
337 SQUIDCEXTERN StoreEntry
*storeGetPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
);
339 /// \ingroup StoreAPI
340 SQUIDCEXTERN StoreEntry
*storeCreateEntry(const char *, const char *, request_flags
, const HttpRequestMethod
&);
342 /// \ingroup StoreAPI
343 SQUIDCEXTERN
void storeInit(void);
345 /// \ingroup StoreAPI
346 SQUIDCEXTERN
void storeConfigure(void);
348 /// \ingroup StoreAPI
349 SQUIDCEXTERN
void storeFreeMemory(void);
351 /// \ingroup StoreAPI
352 SQUIDCEXTERN
int expiresMoreThan(time_t, time_t);
354 /// \ingroup StoreAPI
355 SQUIDCEXTERN
void storeAppendPrintf(StoreEntry
*, const char *,...) PRINTF_FORMAT_ARG2
;
357 /// \ingroup StoreAPI
358 SQUIDCEXTERN
void storeAppendVPrintf(StoreEntry
*, const char *, va_list ap
);
360 /// \ingroup StoreAPI
361 SQUIDCEXTERN
int storeTooManyDiskFilesOpen(void);
364 /// \ingroup StoreAPI
365 SQUIDCEXTERN
void storeHeapPositionUpdate(StoreEntry
*, SwapDir
*);
367 /// \ingroup StoreAPI
368 SQUIDCEXTERN
void storeSwapFileNumberSet(StoreEntry
* e
, sfileno filn
);
370 /// \ingroup StoreAPI
371 SQUIDCEXTERN
void storeFsInit(void);
373 /// \ingroup StoreAPI
374 SQUIDCEXTERN
void storeFsDone(void);
376 /// \ingroup StoreAPI
377 SQUIDCEXTERN
void storeReplAdd(const char *, REMOVALPOLICYCREATE
*);
379 /// \ingroup StoreAPI
380 extern FREE destroyStoreEntry
;
384 \todo should be a subclass of Packer perhaps ?
386 SQUIDCEXTERN
void packerToStoreInit(Packer
* p
, StoreEntry
* e
);
392 #endif /* SQUID_STORE_H */