object.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. Copyright (c) 2003-2006 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #undef MAX
  20. #undef MIN
  21. #define MAX(x,y) ((x)<=(y)?(y):(x))
  22. #define MIN(x,y) ((x)<=(y)?(x):(y))
  23. struct _HTTPRequest;
  24. #if defined(USHRT_MAX) && CHUNK_SIZE <= USHRT_MAX
  25. typedef unsigned short chunk_size_t;
  26. #else
  27. typedef unsigned int chunk_size_t;
  28. #endif
  29. typedef struct _Chunk {
  30. short int locked;
  31. chunk_size_t size;
  32. char *data;
  33. } ChunkRec, *ChunkPtr;
  34. struct _Object;
  35. typedef int (*RequestFunction)(struct _Object *, int, int, int,
  36. struct _HTTPRequest*, void*);
  37. typedef struct _Object {
  38. short refcount;
  39. unsigned char type;
  40. RequestFunction request;
  41. void *request_closure;
  42. char *key;
  43. unsigned short key_size;
  44. unsigned short flags;
  45. unsigned short code;
  46. void *abort_data;
  47. struct _Atom *message;
  48. int length;
  49. time_t date;
  50. time_t age;
  51. time_t expires;
  52. time_t last_modified;
  53. time_t atime;
  54. char *etag;
  55. unsigned short cache_control;
  56. int max_age;
  57. int s_maxage;
  58. struct _Atom *headers;
  59. struct _Atom *via;
  60. int size;
  61. int numchunks;
  62. ChunkPtr chunks;
  63. void *requestor;
  64. struct _Condition condition;
  65. struct _DiskCacheEntry *disk_entry;
  66. struct _Object *next, *previous;
  67. } ObjectRec, *ObjectPtr;
  68. typedef struct _CacheControl {
  69. int flags;
  70. int max_age;
  71. int s_maxage;
  72. int min_fresh;
  73. int max_stale;
  74. } CacheControlRec, *CacheControlPtr;
  75. extern int cacheIsShared;
  76. extern int mindlesslyCacheVary;
  77. extern CacheControlRec no_cache_control;
  78. extern int objectExpiryScheduled;
  79. extern int publicObjectCount;
  80. extern int privateObjectCount;
  81. extern int idleTime;
  82. extern const time_t time_t_max;
  83. extern int publicObjectLowMark, objectHighMark;
  84. extern int log2ObjectHashTableSize;
  85. /* object->type */
  86. #define OBJECT_HTTP 1
  87. #define OBJECT_DNS 2
  88. /* object->flags */
  89. /* object is public */
  90. #define OBJECT_PUBLIC 1
  91. /* object hasn't got any headers yet */
  92. #define OBJECT_INITIAL 2
  93. /* a server connection is already taking care of the object */
  94. #define OBJECT_INPROGRESS 4
  95. /* the object has been superseded -- don't try to fetch it */
  96. #define OBJECT_SUPERSEDED 8
  97. /* the object is private and aditionally can only be used by its requestor */
  98. #define OBJECT_LINEAR 16
  99. /* the object is currently being validated */
  100. #define OBJECT_VALIDATING 32
  101. /* object has been aborted */
  102. #define OBJECT_ABORTED 64
  103. /* last object request was a failure */
  104. #define OBJECT_FAILED 128
  105. /* Object is a local file */
  106. #define OBJECT_LOCAL 256
  107. /* The object's data has been entirely written out to disk */
  108. #define OBJECT_DISK_ENTRY_COMPLETE 512
  109. /* The object is suspected to be dynamic -- don't PMM */
  110. #define OBJECT_DYNAMIC 1024
  111. /* Used for synchronisation between client and server. */
  112. #define OBJECT_MUTATING 2048
  113. /* object->cache_control and connection->cache_control */
  114. /* RFC 2616 14.9 */
  115. /* Non-standard: like no-cache, but kept internally */
  116. #define CACHE_NO_HIDDEN 1
  117. /* no-cache */
  118. #define CACHE_NO 2
  119. /* public */
  120. #define CACHE_PUBLIC 4
  121. /* private */
  122. #define CACHE_PRIVATE 8
  123. /* no-store */
  124. #define CACHE_NO_STORE 16
  125. /* no-transform */
  126. #define CACHE_NO_TRANSFORM 32
  127. /* must-revalidate */
  128. #define CACHE_MUST_REVALIDATE 64
  129. /* proxy-revalidate */
  130. #define CACHE_PROXY_REVALIDATE 128
  131. /* only-if-cached */
  132. #define CACHE_ONLY_IF_CACHED 256
  133. /* set if Vary header; treated as no-cache */
  134. #define CACHE_VARY 512
  135. /* set if Authorization header; treated specially */
  136. #define CACHE_AUTHORIZATION 1024
  137. /* set if cookie */
  138. #define CACHE_COOKIE 2048
  139. /* set if this object should never be combined with another resource */
  140. #define CACHE_MISMATCH 4096
  141. struct _HTTPRequest;
  142. void preinitObject(void);
  143. void initObject(void);
  144. ObjectPtr findObject(int type, const void *key, int key_size);
  145. ObjectPtr makeObject(int type, const void *key, int key_size,
  146. int public, int fromdisk,
  147. int (*request)(ObjectPtr, int, int, int,
  148. struct _HTTPRequest*, void*), void*);
  149. void objectMetadataChanged(ObjectPtr object, int dirty);
  150. ObjectPtr retainObject(ObjectPtr);
  151. void releaseObject(ObjectPtr);
  152. int objectSetChunks(ObjectPtr object, int numchunks);
  153. void lockChunk(ObjectPtr, int);
  154. void unlockChunk(ObjectPtr, int);
  155. void destroyObject(ObjectPtr object);
  156. void privatiseObject(ObjectPtr object, int linear);
  157. void abortObject(ObjectPtr object, int code, struct _Atom *message);
  158. void supersedeObject(ObjectPtr);
  159. void notifyObject(ObjectPtr);
  160. void releaseNotifyObject(ObjectPtr);
  161. ObjectPtr objectPartial(ObjectPtr object, int length, struct _Atom *headers);
  162. int objectHoleSize(ObjectPtr object, int offset)
  163. ATTRIBUTE ((pure));
  164. int objectHasData(ObjectPtr object, int from, int to)
  165. ATTRIBUTE ((pure));
  166. int objectAddData(ObjectPtr object, const char *data, int offset, int len);
  167. void objectPrintf(ObjectPtr object, int offset, const char *format, ...)
  168. ATTRIBUTE ((format (printf, 3, 4)));
  169. int discardObjectsHandler(TimeEventHandlerPtr);
  170. void writeoutObjects(int);
  171. int discardObjects(int all, int force);
  172. int objectIsStale(ObjectPtr object, CacheControlPtr cache_control)
  173. ATTRIBUTE ((pure));
  174. int objectMustRevalidate(ObjectPtr object, CacheControlPtr cache_control)
  175. ATTRIBUTE ((pure));