Fix MIME types in local server.
[polipo.git] / object.h
blobd029605c39b0468f2eaa686004b074acbfd2360b
1 /*
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
20 THE SOFTWARE.
23 #undef MAX
24 #undef MIN
26 #define MAX(x,y) ((x)<=(y)?(y):(x))
27 #define MIN(x,y) ((x)<=(y)?(x):(y))
29 struct _HTTPRequest;
31 typedef struct _Chunk {
32 int locked;
33 int size;
34 char *data;
35 } ChunkRec, *ChunkPtr;
37 struct _Object;
39 typedef int (*RequestFunction)(struct _Object *, int, int, int,
40 struct _HTTPRequest*, void*);
42 typedef struct _Object {
43 short refcount;
44 unsigned char type;
45 RequestFunction request;
46 void *request_closure;
47 void *key;
48 unsigned short key_size;
49 unsigned short flags;
50 unsigned short code;
51 void *abort_data;
52 struct _Atom *message;
53 int length;
54 time_t date;
55 time_t age;
56 time_t expires;
57 time_t last_modified;
58 time_t atime;
59 char *etag;
60 unsigned short cache_control;
61 int max_age;
62 int s_maxage;
63 struct _Atom *headers;
64 struct _Atom *via;
65 int size;
66 int numchunks;
67 ChunkPtr chunks;
68 void *requestor;
69 struct _Condition condition;
70 struct _DiskCacheEntry *disk_entry;
71 struct _Object *next, *previous;
72 } ObjectRec, *ObjectPtr;
74 typedef struct _CacheControl {
75 int flags;
76 int max_age;
77 int s_maxage;
78 int min_fresh;
79 int max_stale;
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;
89 extern int idleTime;
91 extern const time_t time_t_max;
93 extern int publicObjectLowMark, objectHighMark;
95 extern int log2ObjectHashTableSize;
97 /* object->type */
98 #define OBJECT_HTTP 1
99 #define OBJECT_DNS 2
101 /* object->flags */
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 */
128 /* RFC 2616 14.9 */
129 /* Non-standard: like no-cache, but kept internally */
130 #define CACHE_NO_HIDDEN 1
131 /* no-cache */
132 #define CACHE_NO 2
133 /* public */
134 #define CACHE_PUBLIC 4
135 /* private */
136 #define CACHE_PRIVATE 8
137 /* no-store */
138 #define CACHE_NO_STORE 16
139 /* no-transform */
140 #define CACHE_NO_TRANSFORM 32
141 /* must-revalidate */
142 #define CACHE_MUST_REVALIDATE 64
143 /* proxy-revalidate */
144 #define CACHE_PROXY_REVALIDATE 128
145 /* only-if-cached */
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
151 /* set if cookie */
152 #define CACHE_COOKIE 2048
154 struct _HTTPRequest;
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);