ap_socache.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file ap_socache.h
  18. * @brief Small object cache provider interface.
  19. *
  20. * @defgroup AP_SOCACHE ap_socache
  21. * @ingroup APACHE_MODS
  22. * @{
  23. */
  24. #ifndef AP_SOCACHE_H
  25. #define AP_SOCACHE_H
  26. #include "httpd.h"
  27. #include "ap_provider.h"
  28. #include "apr_pools.h"
  29. #include "apr_time.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** If this flag is set, the store/retrieve/remove/status interfaces
  34. * of the provider are NOT safe to be called concurrently from
  35. * multiple processes or threads, and an external global mutex must be
  36. * used to serialize access to the provider.
  37. */
  38. /* XXX: Even if store/retrieve/remove is atomic, isn't it useful to note
  39. * independently that status and iterate may or may not be?
  40. */
  41. #define AP_SOCACHE_FLAG_NOTMPSAFE (0x0001)
  42. /** A cache instance. */
  43. typedef struct ap_socache_instance_t ap_socache_instance_t;
  44. /** Hints which may be passed to the init function; providers may
  45. * ignore some or all of these hints. */
  46. struct ap_socache_hints {
  47. /** Approximate average length of IDs: */
  48. apr_size_t avg_id_len;
  49. /** Approximate average size of objects: */
  50. apr_size_t avg_obj_size;
  51. /** Suggested interval between expiry cleanup runs; */
  52. apr_interval_time_t expiry_interval;
  53. };
  54. /**
  55. * Iterator callback prototype for the ap_socache_provider_t->iterate() method
  56. * @param instance The cache instance
  57. * @param s Associated server context (for logging)
  58. * @param userctx User defined pointer passed from the iterator call
  59. * @param id Unique ID for the object (binary blob)
  60. * with a trailing null char for convenience
  61. * @param idlen Length of id blob
  62. * @param data Output buffer to place retrieved data (binary blob)
  63. * with a trailing null char for convenience
  64. * @param datalen Length of data buffer
  65. * @param pool Pool for temporary allocations
  66. * @return APR status value; return APR_SUCCESS or the iteration will halt;
  67. * this value is returned to the ap_socache_provider_t->iterate() caller
  68. */
  69. typedef apr_status_t (ap_socache_iterator_t)(ap_socache_instance_t *instance,
  70. server_rec *s,
  71. void *userctx,
  72. const unsigned char *id,
  73. unsigned int idlen,
  74. const unsigned char *data,
  75. unsigned int datalen,
  76. apr_pool_t *pool);
  77. /** A socache provider structure. socache providers are registered
  78. * with the ap_provider.h interface using the AP_SOCACHE_PROVIDER_*
  79. * constants. */
  80. typedef struct ap_socache_provider_t {
  81. /** Canonical provider name. */
  82. const char *name;
  83. /** Bitmask of AP_SOCACHE_FLAG_* flags. */
  84. unsigned int flags;
  85. /**
  86. * Create a session cache based on the given configuration string.
  87. * The instance pointer returned in the instance parameter will be
  88. * passed as the first argument to subsequent invocations.
  89. *
  90. * @param instance Output parameter to which instance object is written.
  91. * @param arg User-specified configuration string. May be NULL to
  92. * force use of defaults.
  93. * @param tmp Pool to be used for any temporary allocations
  94. * @param p Pool to be use for any allocations lasting as long as
  95. * the created instance
  96. * @return NULL on success, or an error string on failure.
  97. */
  98. const char *(*create)(ap_socache_instance_t **instance, const char *arg,
  99. apr_pool_t *tmp, apr_pool_t *p);
  100. /**
  101. * Initialize the cache. The cname must be of maximum length 16
  102. * characters, and uniquely identifies the consumer of the cache
  103. * within the server; using the module name is recommended, e.g.
  104. * "mod_ssl-sess". This string may be used within a filesystem
  105. * path so use of only alphanumeric [a-z0-9_-] characters is
  106. * recommended. If hints is non-NULL, it gives a set of hints for
  107. * the provider. Returns APR error code.
  108. *
  109. * @param instance The cache instance
  110. * @param cname A unique string identifying the consumer of this API
  111. * @param hints Optional hints argument describing expected cache use
  112. * @param s Server structure to which the cache is associated
  113. * @param pool Pool for long-lived allocations
  114. * @return APR status value indicating success.
  115. */
  116. apr_status_t (*init)(ap_socache_instance_t *instance, const char *cname,
  117. const struct ap_socache_hints *hints,
  118. server_rec *s, apr_pool_t *pool);
  119. /**
  120. * Destroy a given cache instance object.
  121. * @param instance The cache instance to destroy.
  122. * @param s Associated server structure (for logging purposes)
  123. */
  124. void (*destroy)(ap_socache_instance_t *instance, server_rec *s);
  125. /**
  126. * Store an object in a cache instance.
  127. * @param instance The cache instance
  128. * @param s Associated server structure (for logging purposes)
  129. * @param id Unique ID for the object; binary blob
  130. * @param idlen Length of id blob
  131. * @param expiry Absolute time at which the object expires
  132. * @param data Data to store; binary blob
  133. * @param datalen Length of data blob
  134. * @param pool Pool for temporary allocations.
  135. * @return APR status value.
  136. */
  137. apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s,
  138. const unsigned char *id, unsigned int idlen,
  139. apr_time_t expiry,
  140. unsigned char *data, unsigned int datalen,
  141. apr_pool_t *pool);
  142. /**
  143. * Retrieve a cached object.
  144. *
  145. * @param instance The cache instance
  146. * @param s Associated server structure (for logging purposes)
  147. * @param id Unique ID for the object; binary blob
  148. * @param idlen Length of id blob
  149. * @param data Output buffer to place retrievd data (binary blob)
  150. * @param datalen On entry, length of data buffer; on exit, the
  151. * number of bytes written to the data buffer.
  152. * @param pool Pool for temporary allocations.
  153. * @return APR status value; APR_NOTFOUND if the object was not
  154. * found
  155. */
  156. apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s,
  157. const unsigned char *id, unsigned int idlen,
  158. unsigned char *data, unsigned int *datalen,
  159. apr_pool_t *pool);
  160. /**
  161. * Remove an object from the cache
  162. *
  163. * @param instance The cache instance
  164. * @param s Associated server structure (for logging purposes)
  165. * @param id Unique ID for the object; binary blob
  166. * @param idlen Length of id blob
  167. * @param pool Pool for temporary allocations.
  168. */
  169. apr_status_t (*remove)(ap_socache_instance_t *instance, server_rec *s,
  170. const unsigned char *id, unsigned int idlen,
  171. apr_pool_t *pool);
  172. /**
  173. * Dump the status of a cache instance for mod_status. Will use
  174. * the ap_r* interfaces to produce appropriate status output.
  175. * XXX: ap_r* are deprecated, bad dogfood
  176. *
  177. * @param instance The cache instance
  178. * @param r The request structure
  179. * @param flags The AP_STATUS_* constants used (see mod_status.h)
  180. */
  181. void (*status)(ap_socache_instance_t *instance, request_rec *r, int flags);
  182. /**
  183. * Dump all cached objects through an iterator callback.
  184. * @param instance The cache instance
  185. * @param s Associated server context (for processing and logging)
  186. * @param userctx User defined pointer passed through to the iterator
  187. * @param iterator The user provided callback function which will receive
  188. * individual calls for each unexpired id/data pair
  189. * @param pool Pool for temporary allocations.
  190. * @return APR status value; APR_NOTFOUND if the object was not
  191. * found
  192. */
  193. apr_status_t (*iterate)(ap_socache_instance_t *instance, server_rec *s,
  194. void *userctx, ap_socache_iterator_t *iterator,
  195. apr_pool_t *pool);
  196. } ap_socache_provider_t;
  197. /** The provider group used to register socache providers. */
  198. #define AP_SOCACHE_PROVIDER_GROUP "socache"
  199. /** The provider version used to register socache providers. */
  200. #define AP_SOCACHE_PROVIDER_VERSION "0"
  201. /** Default provider name. */
  202. #define AP_SOCACHE_DEFAULT_PROVIDER "default"
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* AP_SOCACHE_H */
  207. /** @} */