2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #define MAX(x,y) ((x)<=(y)?(y):(x))
27 #define MIN(x,y) ((x)<=(y)?(x):(y))
31 typedef struct _Chunk
{
35 } ChunkRec
, *ChunkPtr
;
39 typedef int (*RequestFunction
)(struct _Object
*, int, int, int,
40 struct _HTTPRequest
*, void*);
42 typedef struct _Object
{
45 RequestFunction request
;
46 void *request_closure
;
48 unsigned short key_size
;
52 struct _Atom
*message
;
60 unsigned short cache_control
;
63 struct _Atom
*headers
;
69 struct _Condition condition
;
70 struct _DiskCacheEntry
*disk_entry
;
71 struct _Object
*next
, *previous
;
72 } ObjectRec
, *ObjectPtr
;
74 typedef struct _CacheControl
{
80 } CacheControlRec
, *CacheControlPtr
;
82 extern int cacheIsShared
;
83 extern int mindlesslyCacheVary
;
85 extern CacheControlRec no_cache_control
;
86 extern int objectExpiryScheduled
;
87 extern int publicObjectCount
;
88 extern int privateObjectCount
;
91 extern const time_t time_t_max
;
93 extern int publicObjectLowMark
, objectHighMark
;
95 extern int log2ObjectHashTableSize
;
102 /* object is public */
103 #define OBJECT_PUBLIC 1
104 /* object hasn't got any headers yet */
105 #define OBJECT_INITIAL 2
106 /* a server connection is already taking care of the object */
107 #define OBJECT_INPROGRESS 4
108 /* the object has been superseded -- don't try to fetch it */
109 #define OBJECT_SUPERSEDED 8
110 /* the object is private and aditionally can only be used by its requestor */
111 #define OBJECT_LINEAR 16
112 /* the object is currently being validated */
113 #define OBJECT_VALIDATING 32
114 /* object has been aborted */
115 #define OBJECT_ABORTED 64
116 /* last object request was a failure */
117 #define OBJECT_FAILED 128
118 /* Object is a local file */
119 #define OBJECT_LOCAL 256
120 /* The object's data has been entirely written out to disk */
121 #define OBJECT_DISK_ENTRY_COMPLETE 512
122 /* The object is suspected to be dynamic -- don't PMM */
123 #define OBJECT_DYNAMIC 1024
124 /* Used for synchronisation between client and server. */
125 #define OBJECT_MUTATING 2048
127 /* object->cache_control and connection->cache_control */
129 /* Non-standard: like no-cache, but kept internally */
130 #define CACHE_NO_HIDDEN 1
134 #define CACHE_PUBLIC 4
136 #define CACHE_PRIVATE 8
138 #define CACHE_NO_STORE 16
140 #define CACHE_NO_TRANSFORM 32
141 /* must-revalidate */
142 #define CACHE_MUST_REVALIDATE 64
143 /* proxy-revalidate */
144 #define CACHE_PROXY_REVALIDATE 128
146 #define CACHE_ONLY_IF_CACHED 256
147 /* set if Vary header; treated as no-cache */
148 #define CACHE_VARY 512
149 /* set if Authorization header; treated specially */
150 #define CACHE_AUTHORIZATION 1024
152 #define CACHE_COOKIE 2048
156 void preinitObject(void);
157 void initObject(void);
158 ObjectPtr
findObject(int type
, void *key
, int key_size
);
159 ObjectPtr
makeObject(int type
, void *key
, int key_size
,
160 int public, int fromdisk
,
161 int (*request
)(ObjectPtr
, int, int, int,
162 struct _HTTPRequest
*, void*), void*);
163 void objectMetadataChanged(ObjectPtr object
, int dirty
);
164 ObjectPtr
retainObject(ObjectPtr
);
165 void releaseObject(ObjectPtr
);
166 int objectSetChunks(ObjectPtr object
, int numchunks
);
167 void lockChunk(ObjectPtr
, int);
168 void unlockChunk(ObjectPtr
, int);
169 void destroyObject(ObjectPtr object
);
170 void privatiseObject(ObjectPtr object
, int linear
);
171 void abortObject(ObjectPtr object
, int code
, struct _Atom
*message
);
172 void supersedeObject(ObjectPtr
);
173 void notifyObject(ObjectPtr
);
174 void releaseNotifyObject(ObjectPtr
);
175 ObjectPtr
objectPartial(ObjectPtr object
, int length
, struct _Atom
*headers
);
176 int objectHoleSize(ObjectPtr object
, int offset
);
177 int objectAddData(ObjectPtr object
, char *data
, int offset
, int len
);
178 void objectPrintf(ObjectPtr object
, int offset
, char *format
, ...)
179 ATTRIBUTE((format (printf
, 3, 4)));
180 int discardObjectsHandler(TimeEventHandlerPtr
);
181 void writeoutObjects(int);
182 int discardObjects(int all
, int force
);
183 int objectIsStale(ObjectPtr object
, CacheControlPtr cache_control
);
184 int objectMustRevalidate(ObjectPtr object
, CacheControlPtr cache_control
);