root / trunk / src / dot / proxy / object.h

Revision 7618, 6.1 kB (checked in by BradNeuberg, 22 months ago)

Local and remote SVN repositories somehow became out of sync and corrupted -- re-adding these in

Line 
1/*
2Copyright (c) 2003-2006 by Juliusz Chroboczek
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22
23#undef MAX
24#undef MIN
25
26#define MAX(x,y) ((x)<=(y)?(y):(x))
27#define MIN(x,y) ((x)<=(y)?(x):(y))
28
29struct _HTTPRequest;
30
31#if defined(USHRT_MAX) && CHUNK_SIZE <= USHRT_MAX
32typedef unsigned short chunk_size_t;
33#else
34typedef unsigned int chunk_size_t;
35#endif
36
37typedef struct _Chunk {
38    short int locked;
39    chunk_size_t size;
40    char *data;
41} ChunkRec, *ChunkPtr;
42
43struct _Object;
44
45typedef int (*RequestFunction)(struct _Object *, int, int, int,
46                               struct _HTTPRequest*, void*);
47
48typedef struct _Object {
49    short refcount;
50    unsigned char type;
51    RequestFunction request;
52    void *request_closure;
53    void *key;
54    unsigned short key_size;
55    unsigned short flags;
56    unsigned short code;
57    void *abort_data;
58    struct _Atom *message;
59    int length;
60    time_t date;
61    time_t age;
62    time_t expires;
63    time_t last_modified;
64    time_t atime;
65    char *etag;
66    unsigned short cache_control;
67    int max_age;
68    int s_maxage;
69    struct _Atom *headers;
70    struct _Atom *via;
71    int size;
72    int numchunks;
73    ChunkPtr chunks;
74    void *requestor;
75    struct _Condition condition;
76    struct _DiskCacheEntry *disk_entry;
77    struct _Object *next, *previous;
78} ObjectRec, *ObjectPtr;
79
80typedef struct _CacheControl {
81    int flags;
82    int max_age;
83    int s_maxage;
84    int min_fresh;
85    int max_stale;
86} CacheControlRec, *CacheControlPtr;
87
88extern int cacheIsShared;
89extern int mindlesslyCacheVary;
90
91extern CacheControlRec no_cache_control;
92extern int objectExpiryScheduled;
93extern int publicObjectCount;
94extern int privateObjectCount;
95extern int idleTime;
96
97extern const time_t time_t_max;
98
99extern int publicObjectLowMark, objectHighMark;
100
101extern int log2ObjectHashTableSize;
102
103/* object->type */
104#define OBJECT_HTTP 1
105#define OBJECT_DNS 2
106
107/* object->flags */
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
132
133/* object->cache_control and connection->cache_control */
134/* RFC 2616 14.9 */
135/* Non-standard: like no-cache, but kept internally */
136#define CACHE_NO_HIDDEN 1
137/* no-cache */
138#define CACHE_NO 2
139/* public */
140#define CACHE_PUBLIC 4
141/* private */
142#define CACHE_PRIVATE 8
143/* no-store */
144#define CACHE_NO_STORE 16
145/* no-transform */
146#define CACHE_NO_TRANSFORM 32
147/* must-revalidate */
148#define CACHE_MUST_REVALIDATE 64
149/* proxy-revalidate */
150#define CACHE_PROXY_REVALIDATE 128
151/* only-if-cached */
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
157/* set if cookie */
158#define CACHE_COOKIE 2048
159/* set if this object should never be combined with another resource */
160#define CACHE_MISMATCH 4096
161
162struct _HTTPRequest;
163
164void preinitObject(void);
165void initObject(void);
166ObjectPtr findObject(int type, const void *key, int key_size);
167ObjectPtr makeObject(int type, const void *key, int key_size,
168                     int public, int fromdisk,
169                     int (*request)(ObjectPtr, int, int, int,
170                                    struct _HTTPRequest*, void*), void*);
171void objectMetadataChanged(ObjectPtr object, int dirty);
172ObjectPtr retainObject(ObjectPtr);
173void releaseObject(ObjectPtr);
174int objectSetChunks(ObjectPtr object, int numchunks);
175void lockChunk(ObjectPtr, int);
176void unlockChunk(ObjectPtr, int);
177void destroyObject(ObjectPtr object);
178void privatiseObject(ObjectPtr object, int linear);
179void abortObject(ObjectPtr object, int code, struct _Atom *message);
180void supersedeObject(ObjectPtr);
181void notifyObject(ObjectPtr);
182void releaseNotifyObject(ObjectPtr);
183ObjectPtr objectPartial(ObjectPtr object, int length, struct _Atom *headers);
184int objectHoleSize(ObjectPtr object, int offset)
185    ATTRIBUTE ((pure));
186int objectHasData(ObjectPtr object, int from, int to)
187    ATTRIBUTE ((pure));
188int objectAddData(ObjectPtr object, const char *data, int offset, int len);
189void objectPrintf(ObjectPtr object, int offset, const char *format, ...)
190     ATTRIBUTE ((format (printf, 3, 4)));
191int discardObjectsHandler(TimeEventHandlerPtr);
192void writeoutObjects(int);
193int discardObjects(int all, int force);
194int objectIsStale(ObjectPtr object, CacheControlPtr cache_control)
195    ATTRIBUTE ((pure));
196int objectMustRevalidate(ObjectPtr object, CacheControlPtr cache_control)
197    ATTRIBUTE ((pure));
Note: See TracBrowser for help on using the browser.