* serialize access to the provider. */
#define AP_SOCACHE_FLAG_NOTMPSAFE (0x0001)
+/* A cache instance. */
+typedef struct ap_socache_instance_t ap_socache_instance_t;
+
typedef struct ap_socache_provider_t {
/* Canonical provider name: */
const char *name;
*
* The context pointer returned in *INSTANCE will be passed as the
* first argument to subsequent invocations. */
- const char *(*create)(void **instance, const char *arg,
+ const char *(*create)(ap_socache_instance_t **instance, const char *arg,
apr_pool_t *tmp, apr_pool_t *p);
/* Initialize the cache. Return APR error code. */
- apr_status_t (*init)(void *instance, /* hints, namespace */
+ apr_status_t (*init)(ap_socache_instance_t *instance, /* hints, namespace */
server_rec *s, apr_pool_t *pool);
/* Destroy a given cache context. */
- void (*destroy)(void *instance, server_rec *s);
+ void (*destroy)(ap_socache_instance_t *instance, server_rec *s);
/* Store an object in the cache with key ID of length IDLEN, with
* DATA of length DATALEN. The object expires at abolute time
* EXPIRY. */
- apr_status_t (*store)(void *instance, server_rec *s,
+ apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s,
const unsigned char *id, unsigned int idlen,
time_t expiry,
unsigned char *data, unsigned int datalen);
* placed in DEST, which has length on entry of *DESTLEN.
* *DESTLEN must be updated to equal the length of data written on
* exit. */
- apr_status_t (*retrieve)(void *instance, server_rec *s,
+ apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s,
const unsigned char *id, unsigned int idlen,
unsigned char *data, unsigned int *datalen,
apr_pool_t *pool);
/* Remove an object from the cache with key ID of length IDLEN.
* POOL may be used for temporary allocations. */
- void (*delete)(void *instance, server_rec *s,
+ void (*delete)(ap_socache_instance_t *instance, server_rec *s,
const unsigned char *id, unsigned int idlen,
apr_pool_t *pool);
/* Dump cache status for mod_status output. */
- void (*status)(void *instance, request_rec *r, int flags);
+ void (*status)(ap_socache_instance_t *instance, request_rec *r, int flags);
} ap_socache_provider_t;
/* Cache providers are registered using the ap_provider_* interface,
/* Use of the context structure must be thread-safe after the initial
* create/init; callers must hold the mutex. */
-struct context {
+struct ap_socache_instance_t {
const char *data_file;
/* Pool must only be used with the mutex held. */
apr_pool_t *pool;
#endif
#endif
+static void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s);
-
-static void socache_dbm_expire(struct context *ctx, server_rec *s);
-
-static void socache_dbm_remove(void *context, server_rec *s,
+static void socache_dbm_remove(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
apr_pool_t *p);
-static const char *socache_dbm_create(void **context, const char *arg,
+static const char *socache_dbm_create(ap_socache_instance_t **context,
+ const char *arg,
apr_pool_t *tmp, apr_pool_t *p)
{
- struct context *ctx;
+ ap_socache_instance_t *ctx;
*context = ctx = apr_pcalloc(p, sizeof *ctx);
return NULL;
}
-static apr_status_t socache_dbm_init(void *context, server_rec *s, apr_pool_t *p)
+static apr_status_t socache_dbm_init(ap_socache_instance_t *ctx,
+ server_rec *s, apr_pool_t *p)
{
- struct context *ctx = context;
apr_dbm_t *dbm;
apr_status_t rv;
return APR_SUCCESS;
}
-static void socache_dbm_kill(void *context, server_rec *s)
+static void socache_dbm_kill(ap_socache_instance_t *ctx, server_rec *s)
{
- struct context *ctx = context;
-
/* the correct way */
unlink(apr_pstrcat(ctx->pool, ctx->data_file, SSL_DBM_FILE_SUFFIX_DIR, NULL));
unlink(apr_pstrcat(ctx->pool, ctx->data_file, SSL_DBM_FILE_SUFFIX_PAG, NULL));
return;
}
-static apr_status_t socache_dbm_store(void *context, server_rec *s,
- const unsigned char *id, unsigned int idlen,
- time_t expiry,
- unsigned char *ucaData, unsigned int nData)
+static apr_status_t socache_dbm_store(
+ ap_socache_instance_t *ctx, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ time_t expiry, unsigned char *ucaData, unsigned int nData)
{
- struct context *ctx = context;
apr_dbm_t *dbm;
apr_datum_t dbmkey;
apr_datum_t dbmval;
return APR_SUCCESS;
}
-static apr_status_t socache_dbm_retrieve(void *context, server_rec *s,
- const unsigned char *id, unsigned int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *p)
+static apr_status_t socache_dbm_retrieve(
+ ap_socache_instance_t *ctx, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *p)
{
- struct context *ctx = context;
apr_dbm_t *dbm;
apr_datum_t dbmkey;
apr_datum_t dbmval;
return APR_SUCCESS;
}
-static void socache_dbm_remove(void *context, server_rec *s,
+static void socache_dbm_remove(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
apr_pool_t *p)
{
- struct context *ctx = context;
apr_dbm_t *dbm;
apr_datum_t dbmkey;
apr_status_t rv;
return;
}
-static void socache_dbm_expire(struct context *ctx, server_rec *s)
+static void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s)
{
apr_dbm_t *dbm;
apr_datum_t dbmkey;
nElements, nElements-nDeleted, nDeleted);
}
-static void socache_dbm_status(void *context, request_rec *r, int flags)
+static void socache_dbm_status(ap_socache_instance_t *ctx, request_rec *r,
+ int flags)
{
- struct context *ctx = context;
apr_dbm_t *dbm;
apr_datum_t dbmkey;
apr_datum_t dbmval;
#error "You must compile with a more recent version of the distcache-base package"
#endif
-struct context {
+struct ap_socache_instance_t {
/* Configured target server: */
const char *target;
/* distcache client context: */
DC_CTX *dc;
};
-static const char *socache_dc_create(void **context, const char *arg,
+static const char *socache_dc_create(ap_socache_instance_t **context,
+ const char *arg,
apr_pool_t *tmp, apr_pool_t *p)
{
- struct context *ctx;
+ struct ap_socache_instance_t *ctx;
ctx = *context = apr_palloc(p, sizeof *ctx);
return NULL;
}
-static apr_status_t socache_dc_init(void *context, server_rec *s, apr_pool_t *p)
+static apr_status_t socache_dc_init(ap_socache_instance_t *ctx, server_rec *s, apr_pool_t *p)
{
- struct context *ctx = ctx;
-
#if 0
/* If a "persistent connection" mode of operation is preferred, you *must*
* also use the PIDCHECK flag to ensure fork()'d processes don't interlace
return APR_SUCCESS;
}
-static void socache_dc_kill(void *context, server_rec *s)
+static void socache_dc_kill(ap_socache_instance_t *ctx, server_rec *s)
{
- struct context *ctx = context;
-
if (ctx && ctx->dc) {
DC_CTX_free(ctx->dc);
ctx->dc = NULL;
}
}
-static apr_status_t socache_dc_store(void *context, server_rec *s,
+static apr_status_t socache_dc_store(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
time_t timeout,
unsigned char *der, unsigned int der_len)
{
- struct context *ctx = context;
-
/* !@#$%^ - why do we deal with *absolute* time anyway??? */
timeout -= time(NULL);
/* Send the serialised session to the distributed cache context */
return APR_SUCCESS;
}
-static apr_status_t socache_dc_retrieve(void *context, server_rec *s,
+static apr_status_t socache_dc_retrieve(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
unsigned char *dest, unsigned int *destlen,
apr_pool_t *p)
{
unsigned int data_len;
- struct context *ctx = context;
/* Retrieve any corresponding session from the distributed cache context */
if (!DC_CTX_get_session(ctx->dc, id, idlen, dest, *destlen, &data_len)) {
return APR_SUCCESS;
}
-static void socache_dc_remove(void *context, server_rec *s,
+static void socache_dc_remove(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
apr_pool_t *p)
{
- struct context *ctx = context;
-
/* Remove any corresponding session from the distributed cache context */
if (!DC_CTX_remove_session(ctx->dc, id, idlen)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' MISS");
}
}
-static void socache_dc_status(void *context, request_rec *r, int flags)
+static void socache_dc_status(ap_socache_instance_t *ctx, request_rec *r, int flags)
{
- struct context *ctx = context;
-
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"distributed scache 'socache_dc_status'");
ap_rprintf(r, "cache type: <b>DC (Distributed Cache)</b>, "
#define MC_DEFAULT_SERVER_TTL 600
#endif
-struct context {
+struct ap_socache_instance_t {
const char *servers;
apr_memcache_t *mc;
};
-static const char *socache_mc_create(void **context, const char *arg,
+static const char *socache_mc_create(ap_socache_instance_t **context,
+ const char *arg,
apr_pool_t *tmp, apr_pool_t *p)
{
- struct context *ctx;
+ ap_socache_instance_t *ctx;
*context = ctx = apr_palloc(p, sizeof *ctx);
return NULL;
}
-static apr_status_t socache_mc_init(void *context, server_rec *s, apr_pool_t *p)
+static apr_status_t socache_mc_init(ap_socache_instance_t *ctx,
+ server_rec *s, apr_pool_t *p)
{
apr_status_t rv;
int thread_limit = 0;
char *cache_config;
char *split;
char *tok;
- struct context *ctx = context;
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
return APR_SUCCESS;
}
-static void socache_mc_kill(void *context, server_rec *s)
+static void socache_mc_kill(ap_socache_instance_t *context, server_rec *s)
{
/* noop. */
}
return str;
}
-static apr_status_t socache_mc_store(void *context, server_rec *s,
+static apr_status_t socache_mc_store(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
time_t timeout,
unsigned char *ucaData, unsigned int nData)
{
- struct context *ctx = context;
char buf[MC_KEY_LEN];
char *strkey = NULL;
apr_status_t rv;
return APR_SUCCESS;
}
-static apr_status_t socache_mc_retrieve(void *context, server_rec *s,
+static apr_status_t socache_mc_retrieve(ap_socache_instance_t *ctx,
+ server_rec *s,
const unsigned char *id, unsigned int idlen,
unsigned char *dest, unsigned int *destlen,
apr_pool_t *p)
{
- struct context *ctx = context;
apr_size_t der_len;
char buf[MC_KEY_LEN], *der;
char *strkey = NULL;
return APR_SUCCESS;
}
-static void socache_mc_remove(void *context, server_rec *s,
+static void socache_mc_remove(ap_socache_instance_t *ctx, server_rec *s,
const unsigned char *id, unsigned int idlen,
apr_pool_t *p)
{
- struct context *ctx = context;
char buf[MC_KEY_LEN];
char* strkey = NULL;
apr_status_t rv;
}
}
-static void socache_mc_status(void *context, request_rec *r, int flags)
+static void socache_mc_status(ap_socache_instance_t *ctx, request_rec *r, int flags)
{
/* SSLModConfigRec *mc = myModConfig(r->server); */
/* TODO: Make a mod_status handler. meh. */
unsigned char removed;
} SHMCBIndex;
-struct context {
+struct ap_socache_instance_t {
const char *data_file;
apr_size_t shm_size;
apr_shm_t *shm;
* subcache internals are deferred to shmcb_subcache_*** functions lower down
*/
-static const char *socache_shmcb_create(void **context, const char *arg,
+static const char *socache_shmcb_create(ap_socache_instance_t **context,
+ const char *arg,
apr_pool_t *tmp, apr_pool_t *p)
{
- struct context *ctx;
+ ap_socache_instance_t *ctx;
char *path, *cp, *cp2;
/* Allocate the context. */
return NULL;
}
-static apr_status_t socache_shmcb_init(void *context, server_rec *s, apr_pool_t *p)
+static apr_status_t socache_shmcb_init(ap_socache_instance_t *ctx,
+ server_rec *s, apr_pool_t *p)
{
void *shm_segment;
apr_size_t shm_segsize;
apr_status_t rv;
SHMCBHeader *header;
unsigned int num_subcache, num_idx, loop;
- struct context *ctx = context;
/* Create shared memory segment */
if (ctx->data_file == NULL) {
return APR_SUCCESS;
}
-static void socache_shmcb_kill(void *context, server_rec *s)
+static void socache_shmcb_kill(ap_socache_instance_t *ctx, server_rec *s)
{
- struct context *ctx = context;
-
if (ctx && ctx->shm) {
apr_shm_destroy(ctx->shm);
ctx->shm = NULL;
}
}
-static apr_status_t socache_shmcb_store(void *context, server_rec *s,
+static apr_status_t socache_shmcb_store(ap_socache_instance_t *ctx,
+ server_rec *s,
const unsigned char *id, unsigned int idlen,
time_t timeout,
unsigned char *encoded,
unsigned int len_encoded)
{
- struct context *ctx = context;
SHMCBHeader *header = ctx->header;
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
return APR_SUCCESS;
}
-static apr_status_t socache_shmcb_retrieve(void *context, server_rec *s,
- const unsigned char *id, unsigned int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *p)
+static apr_status_t socache_shmcb_retrieve(ap_socache_instance_t *ctx,
+ server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *p)
{
- struct context *ctx = context;
SHMCBHeader *header = ctx->header;
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
int rv;
return rv == 0 ? APR_SUCCESS : APR_EGENERAL;
}
-static void socache_shmcb_remove(void *context, server_rec *s,
- const unsigned char *id, unsigned int idlen,
- apr_pool_t *p)
+static void socache_shmcb_remove(ap_socache_instance_t *ctx, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ apr_pool_t *p)
{
- struct context *ctx = context;
SHMCBHeader *header = ctx->header;
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
"leaving socache_shmcb_remove successfully");
}
-static void socache_shmcb_status(void *context, request_rec *r, int flags)
+static void socache_shmcb_status(ap_socache_instance_t *ctx,
+ request_rec *r, int flags)
{
server_rec *s = r->server;
- struct context *ctx = context;
SHMCBHeader *header = ctx->header;
unsigned int loop, total = 0, cache_total = 0, non_empty_subcaches = 0;
time_t idx_expiry, min_expiry = 0, max_expiry = 0, average_expiry = 0;