Abort dynamic objects in httpServerAbort.
[polipo.git] / object.h
blobb0277852a94d451c708abf012b9b1b3f6800facd
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 #if defined(USHRT_MAX) && CHUNK_SIZE <= USHRT_MAX
32 typedef unsigned short chunk_size_t;
33 #else
34 typedef unsigned int chunk_size_t;
35 #endif
37 typedef struct _Chunk {
38 short int locked;
39 chunk_size_t size;
40 char *data;
41 } ChunkRec, *ChunkPtr;
43 struct _Object;
45 typedef int (*RequestFunction)(struct _Object *, int, int, int,
46 struct _HTTPRequest*, void*);
48 typedef struct _Object {
49 short refcount;
50 unsigned char type;
51 RequestFunction request;
52 void *request_closure;
53 char *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;
80 typedef struct _CacheControl {
81 int flags;
82 int max_age;
83 int s_maxage;
84 int min_fresh;
85 int max_stale;
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;
95 extern int idleTime;
97 extern const time_t time_t_max;
99 extern int publicObjectLowMark, objectHighMark;
101 extern int log2ObjectHashTableSize;
103 /* object->type */
104 #define OBJECT_HTTP 1
105 #define OBJECT_DNS 2
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
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
162 struct _HTTPRequest;
164 void preinitObject(void);
165 void initObject(void);
166 ObjectPtr findObject(int type, const void *key, int key_size);
167 ObjectPtr 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*);
171 void objectMetadataChanged(ObjectPtr object, int dirty);
172 ObjectPtr retainObject(ObjectPtr);
173 void releaseObject(ObjectPtr);
174 int objectSetChunks(ObjectPtr object, int numchunks);
175 void lockChunk(ObjectPtr, int);
176 void unlockChunk(ObjectPtr, int);
177 void destroyObject(ObjectPtr object);
178 void privatiseObject(ObjectPtr object, int linear);
179 void abortObject(ObjectPtr object, int code, struct _Atom *message);
180 void supersedeObject(ObjectPtr);
181 void notifyObject(ObjectPtr);
182 void releaseNotifyObject(ObjectPtr);
183 ObjectPtr objectPartial(ObjectPtr object, int length, struct _Atom *headers);
184 int objectHoleSize(ObjectPtr object, int offset)
185 ATTRIBUTE ((pure));
186 int objectHasData(ObjectPtr object, int from, int to)
187 ATTRIBUTE ((pure));
188 int objectAddData(ObjectPtr object, const char *data, int offset, int len);
189 void objectPrintf(ObjectPtr object, int offset, const char *format, ...)
190 ATTRIBUTE ((format (printf, 3, 4)));
191 int discardObjectsHandler(TimeEventHandlerPtr);
192 void writeoutObjects(int);
193 int discardObjects(int all, int force);
194 int objectIsStale(ObjectPtr object, CacheControlPtr cache_control)
195 ATTRIBUTE ((pure));
196 int objectMustRevalidate(ObjectPtr object, CacheControlPtr cache_control)
197 ATTRIBUTE ((pure));