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 #if defined(USHRT_MAX) && CHUNK_SIZE <= USHRT_MAX
32 typedef unsigned short chunk_size_t
;
34 typedef unsigned int chunk_size_t
;
37 typedef struct _Chunk
{
41 } ChunkRec
, *ChunkPtr
;
45 typedef int (*RequestFunction
)(struct _Object
*, int, int, int,
46 struct _HTTPRequest
*, void*);
48 typedef struct _Object
{
51 RequestFunction request
;
52 void *request_closure
;
54 unsigned short key_size
;
58 struct _Atom
*message
;
66 unsigned short cache_control
;
69 struct _Atom
*headers
;
75 struct _Condition condition
;
76 struct _DiskCacheEntry
*disk_entry
;
77 struct _Object
*next
, *previous
;
78 } ObjectRec
, *ObjectPtr
;
80 typedef struct _CacheControl
{
86 } CacheControlRec
, *CacheControlPtr
;
88 extern int cacheIsShared
;
89 extern int mindlesslyCacheVary
;
91 extern CacheControlRec no_cache_control
;
92 extern int objectExpiryScheduled
;
93 extern int publicObjectCount
;
94 extern int privateObjectCount
;
97 extern const time_t time_t_max
;
99 extern int publicObjectLowMark
, objectHighMark
;
101 extern int log2ObjectHashTableSize
;
104 #define OBJECT_HTTP 1
108 /* object is public */
109 #define OBJECT_PUBLIC 1
110 /* object hasn't got any headers yet */
111 #define OBJECT_INITIAL 2
112 /* a server connection is already taking care of the object */
113 #define OBJECT_INPROGRESS 4
114 /* the object has been superseded -- don't try to fetch it */
115 #define OBJECT_SUPERSEDED 8
116 /* the object is private and aditionally can only be used by its requestor */
117 #define OBJECT_LINEAR 16
118 /* the object is currently being validated */
119 #define OBJECT_VALIDATING 32
120 /* object has been aborted */
121 #define OBJECT_ABORTED 64
122 /* last object request was a failure */
123 #define OBJECT_FAILED 128
124 /* Object is a local file */
125 #define OBJECT_LOCAL 256
126 /* The object's data has been entirely written out to disk */
127 #define OBJECT_DISK_ENTRY_COMPLETE 512
128 /* The object is suspected to be dynamic -- don't PMM */
129 #define OBJECT_DYNAMIC 1024
130 /* Used for synchronisation between client and server. */
131 #define OBJECT_MUTATING 2048
133 /* object->cache_control and connection->cache_control */
135 /* Non-standard: like no-cache, but kept internally */
136 #define CACHE_NO_HIDDEN 1
140 #define CACHE_PUBLIC 4
142 #define CACHE_PRIVATE 8
144 #define CACHE_NO_STORE 16
146 #define CACHE_NO_TRANSFORM 32
147 /* must-revalidate */
148 #define CACHE_MUST_REVALIDATE 64
149 /* proxy-revalidate */
150 #define CACHE_PROXY_REVALIDATE 128
152 #define CACHE_ONLY_IF_CACHED 256
153 /* set if Vary header; treated as no-cache */
154 #define CACHE_VARY 512
155 /* set if Authorization header; treated specially */
156 #define CACHE_AUTHORIZATION 1024
158 #define CACHE_COOKIE 2048
162 void preinitObject(void);
163 void initObject(void);
164 ObjectPtr
findObject(int type
, const void *key
, int key_size
);
165 ObjectPtr
makeObject(int type
, const void *key
, int key_size
,
166 int public, int fromdisk
,
167 int (*request
)(ObjectPtr
, int, int, int,
168 struct _HTTPRequest
*, void*), void*);
169 void objectMetadataChanged(ObjectPtr object
, int dirty
);
170 ObjectPtr
retainObject(ObjectPtr
);
171 void releaseObject(ObjectPtr
);
172 int objectSetChunks(ObjectPtr object
, int numchunks
);
173 void lockChunk(ObjectPtr
, int);
174 void unlockChunk(ObjectPtr
, int);
175 void destroyObject(ObjectPtr object
);
176 void privatiseObject(ObjectPtr object
, int linear
);
177 void abortObject(ObjectPtr object
, int code
, struct _Atom
*message
);
178 void supersedeObject(ObjectPtr
);
179 void notifyObject(ObjectPtr
);
180 void releaseNotifyObject(ObjectPtr
);
181 ObjectPtr
objectPartial(ObjectPtr object
, int length
, struct _Atom
*headers
);
182 int objectHoleSize(ObjectPtr object
, int offset
)
184 int objectHasData(ObjectPtr object
, int from
, int to
)
186 int objectAddData(ObjectPtr object
, const char *data
, int offset
, int len
);
187 void objectPrintf(ObjectPtr object
, int offset
, const char *format
, ...)
188 ATTRIBUTE ((format (printf
, 3, 4)));
189 int discardObjectsHandler(TimeEventHandlerPtr
);
190 void writeoutObjects(int);
191 int discardObjects(int all
, int force
);
192 int objectIsStale(ObjectPtr object
, CacheControlPtr cache_control
)
194 int objectMustRevalidate(ObjectPtr object
, CacheControlPtr cache_control
)