mod_socache_dbm.c revision eab15974b1d8bbcb6d4f9ec75527b39ffded82aa
0797faae937515a5225a36db4a1ec79480d2555cjorton/* Licensed to the Apache Software Foundation (ASF) under one or more
0797faae937515a5225a36db4a1ec79480d2555cjorton * contributor license agreements. See the NOTICE file distributed with
0797faae937515a5225a36db4a1ec79480d2555cjorton * this work for additional information regarding copyright ownership.
0797faae937515a5225a36db4a1ec79480d2555cjorton * The ASF licenses this file to You under the Apache License, Version 2.0
0797faae937515a5225a36db4a1ec79480d2555cjorton * (the "License"); you may not use this file except in compliance with
0797faae937515a5225a36db4a1ec79480d2555cjorton * the License. You may obtain a copy of the License at
0797faae937515a5225a36db4a1ec79480d2555cjorton *
0797faae937515a5225a36db4a1ec79480d2555cjorton * http://www.apache.org/licenses/LICENSE-2.0
0797faae937515a5225a36db4a1ec79480d2555cjorton *
0797faae937515a5225a36db4a1ec79480d2555cjorton * Unless required by applicable law or agreed to in writing, software
0797faae937515a5225a36db4a1ec79480d2555cjorton * distributed under the License is distributed on an "AS IS" BASIS,
0797faae937515a5225a36db4a1ec79480d2555cjorton * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0797faae937515a5225a36db4a1ec79480d2555cjorton * See the License for the specific language governing permissions and
0797faae937515a5225a36db4a1ec79480d2555cjorton * limitations under the License.
0797faae937515a5225a36db4a1ec79480d2555cjorton */
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "httpd.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "http_log.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "http_request.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "http_protocol.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "http_config.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "mpm_common.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "apr.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "apr_strings.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "apr_time.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#define APR_WANT_STRFUNC
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "apr_want.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "apr_dbm.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton#if APR_HAVE_UNISTD_H
0797faae937515a5225a36db4a1ec79480d2555cjorton#include <unistd.h>
0797faae937515a5225a36db4a1ec79480d2555cjorton#endif
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton#include "ap_socache.h"
0797faae937515a5225a36db4a1ec79480d2555cjorton
dca6643570b2f028bc7af76329bd7e333bf7493cpquerna#if AP_NEED_SET_MUTEX_PERMS
dca6643570b2f028bc7af76329bd7e333bf7493cpquerna#include "unixd.h"
dca6643570b2f028bc7af76329bd7e333bf7493cpquerna#endif
dca6643570b2f028bc7af76329bd7e333bf7493cpquerna
0797faae937515a5225a36db4a1ec79480d2555cjorton/* Use of the context structure must be thread-safe after the initial
0797faae937515a5225a36db4a1ec79480d2555cjorton * create/init; callers must hold the mutex. */
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstruct ap_socache_instance_t {
0797faae937515a5225a36db4a1ec79480d2555cjorton const char *data_file;
0797faae937515a5225a36db4a1ec79480d2555cjorton /* Pool must only be used with the mutex held. */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_t *pool;
0797faae937515a5225a36db4a1ec79480d2555cjorton time_t last_expiry;
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton time_t expiry_interval;
0797faae937515a5225a36db4a1ec79480d2555cjorton};
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton/**
0797faae937515a5225a36db4a1ec79480d2555cjorton * Support for DBM library
0797faae937515a5225a36db4a1ec79480d2555cjorton */
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD )
0797faae937515a5225a36db4a1ec79480d2555cjorton
bf8ae84ccab0e10cacda6098f6a696577752c433wrowe/* Check for definition of DEFAULT_REL_RUNTIMEDIR */
bf8ae84ccab0e10cacda6098f6a696577752c433wrowe#ifndef DEFAULT_REL_RUNTIMEDIR
bf8ae84ccab0e10cacda6098f6a696577752c433wrowe#define DEFAULT_DBM_PREFIX "logs/socache-dbm-"
bf8ae84ccab0e10cacda6098f6a696577752c433wrowe#else
8c4aed3f92674325e17d8360ee2797beda3a1472jorton#define DEFAULT_DBM_PREFIX DEFAULT_REL_RUNTIMEDIR "/socache-dbm-"
bf8ae84ccab0e10cacda6098f6a696577752c433wrowe#endif
8c4aed3f92674325e17d8360ee2797beda3a1472jorton
0797faae937515a5225a36db4a1ec79480d2555cjorton/* ### this should use apr_dbm_usednames. */
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#if !defined(DBM_FILE_SUFFIX_DIR) && !defined(DBM_FILE_SUFFIX_PAG)
0797faae937515a5225a36db4a1ec79480d2555cjorton#if defined(DBM_SUFFIX)
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_SUFFIX_DIR DBM_SUFFIX
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_SUFFIX_PAG DBM_SUFFIX
0797faae937515a5225a36db4a1ec79480d2555cjorton#elif defined(__FreeBSD__) || (defined(DB_LOCK) && defined(DB_SHMEM))
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_SUFFIX_DIR ".db"
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_SUFFIX_PAG ".db"
0797faae937515a5225a36db4a1ec79480d2555cjorton#else
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_SUFFIX_DIR ".dir"
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton#define DBM_FILE_SUFFIX_PAG ".pag"
0797faae937515a5225a36db4a1ec79480d2555cjorton#endif
0797faae937515a5225a36db4a1ec79480d2555cjorton#endif
0797faae937515a5225a36db4a1ec79480d2555cjorton
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstatic void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s);
0797faae937515a5225a36db4a1ec79480d2555cjorton
501e60e433e1914c64f642114fbb4fb9be9e2ca9jortonstatic apr_status_t socache_dbm_remove(ap_socache_instance_t *ctx,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton server_rec *s, const unsigned char *id,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton unsigned int idlen, apr_pool_t *p);
0797faae937515a5225a36db4a1ec79480d2555cjorton
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstatic const char *socache_dbm_create(ap_socache_instance_t **context,
2685f3814b77577ef7b2523442dab1ca88df1e41jorton const char *arg,
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_t *tmp, apr_pool_t *p)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
2685f3814b77577ef7b2523442dab1ca88df1e41jorton ap_socache_instance_t *ctx;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton *context = ctx = apr_pcalloc(p, sizeof *ctx);
0797faae937515a5225a36db4a1ec79480d2555cjorton
8c4aed3f92674325e17d8360ee2797beda3a1472jorton if (arg && *arg) {
8c4aed3f92674325e17d8360ee2797beda3a1472jorton ctx->data_file = ap_server_root_relative(p, arg);
8c4aed3f92674325e17d8360ee2797beda3a1472jorton if (!ctx->data_file) {
8c4aed3f92674325e17d8360ee2797beda3a1472jorton return apr_psprintf(tmp, "Invalid cache file path %s", arg);
8c4aed3f92674325e17d8360ee2797beda3a1472jorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton }
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_create(&ctx->pool, p);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton return NULL;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstatic apr_status_t socache_dbm_init(ap_socache_instance_t *ctx,
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton const char *namespace,
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton const struct ap_socache_hints *hints,
2685f3814b77577ef7b2523442dab1ca88df1e41jorton server_rec *s, apr_pool_t *p)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_t *dbm;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_status_t rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* for the DBM we need the data file */
0797faae937515a5225a36db4a1ec79480d2555cjorton if (ctx->data_file == NULL) {
8c4aed3f92674325e17d8360ee2797beda3a1472jorton const char *path = apr_pstrcat(p, DEFAULT_DBM_PREFIX, namespace,
8c4aed3f92674325e17d8360ee2797beda3a1472jorton NULL);
8c4aed3f92674325e17d8360ee2797beda3a1472jorton
8c4aed3f92674325e17d8360ee2797beda3a1472jorton ctx->data_file = ap_server_root_relative(p, path);
8c4aed3f92674325e17d8360ee2797beda3a1472jorton
8c4aed3f92674325e17d8360ee2797beda3a1472jorton if (ctx->data_file == NULL) {
8c4aed3f92674325e17d8360ee2797beda3a1472jorton ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
8c4aed3f92674325e17d8360ee2797beda3a1472jorton "could not use default path '%s' for DBM socache",
8c4aed3f92674325e17d8360ee2797beda3a1472jorton path);
8c4aed3f92674325e17d8360ee2797beda3a1472jorton return APR_EINVAL;
8c4aed3f92674325e17d8360ee2797beda3a1472jorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* open it once to create it and to make sure it _can_ be created */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_clear(ctx->pool);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rv = apr_dbm_open(&dbm, ctx->data_file,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton APR_DBM_RWCREATE, DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot create socache DBM file `%s'",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton return rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton ctx->expiry_interval = (hints && hints->expiry_interval
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton ? hints->expiry_interval : 30);
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton
0b310e2cb91c7ca69a95637c05fae2fb124d7fcfpquerna#if AP_NEED_SET_MUTEX_PERMS
0797faae937515a5225a36db4a1ec79480d2555cjorton /*
0797faae937515a5225a36db4a1ec79480d2555cjorton * We have to make sure the Apache child processes have access to
0797faae937515a5225a36db4a1ec79480d2555cjorton * the DBM file. But because there are brain-dead platforms where we
0797faae937515a5225a36db4a1ec79480d2555cjorton * cannot exactly determine the suffixes we try all possibilities.
0797faae937515a5225a36db4a1ec79480d2555cjorton */
0797faae937515a5225a36db4a1ec79480d2555cjorton if (geteuid() == 0 /* is superuser */) {
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna chown(ctx->data_file, ap_unixd_config.user_id, -1 /* no gid change */);
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton if (chown(apr_pstrcat(p, ctx->data_file, DBM_FILE_SUFFIX_DIR, NULL),
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna ap_unixd_config.user_id, -1) == -1) {
0797faae937515a5225a36db4a1ec79480d2555cjorton if (chown(apr_pstrcat(p, ctx->data_file, ".db", NULL),
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna ap_unixd_config.user_id, -1) == -1)
0797faae937515a5225a36db4a1ec79480d2555cjorton chown(apr_pstrcat(p, ctx->data_file, ".dir", NULL),
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna ap_unixd_config.user_id, -1);
0797faae937515a5225a36db4a1ec79480d2555cjorton }
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton if (chown(apr_pstrcat(p, ctx->data_file, DBM_FILE_SUFFIX_PAG, NULL),
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna ap_unixd_config.user_id, -1) == -1) {
0797faae937515a5225a36db4a1ec79480d2555cjorton if (chown(apr_pstrcat(p, ctx->data_file, ".db", NULL),
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna ap_unixd_config.user_id, -1) == -1)
0797faae937515a5225a36db4a1ec79480d2555cjorton chown(apr_pstrcat(p, ctx->data_file, ".pag", NULL),
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna ap_unixd_config.user_id, -1);
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton#endif
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_expire(ctx, s);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_SUCCESS;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstatic void socache_dbm_kill(ap_socache_instance_t *ctx, server_rec *s)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton /* the correct way */
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton unlink(apr_pstrcat(ctx->pool, ctx->data_file, DBM_FILE_SUFFIX_DIR, NULL));
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton unlink(apr_pstrcat(ctx->pool, ctx->data_file, DBM_FILE_SUFFIX_PAG, NULL));
0797faae937515a5225a36db4a1ec79480d2555cjorton /* the additional ways to be sure */
0797faae937515a5225a36db4a1ec79480d2555cjorton unlink(apr_pstrcat(ctx->pool, ctx->data_file, ".dir", NULL));
0797faae937515a5225a36db4a1ec79480d2555cjorton unlink(apr_pstrcat(ctx->pool, ctx->data_file, ".pag", NULL));
0797faae937515a5225a36db4a1ec79480d2555cjorton unlink(apr_pstrcat(ctx->pool, ctx->data_file, ".db", NULL));
0797faae937515a5225a36db4a1ec79480d2555cjorton unlink(ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton return;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
501e60e433e1914c64f642114fbb4fb9be9e2ca9jortonstatic apr_status_t socache_dbm_store(ap_socache_instance_t *ctx,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton server_rec *s, const unsigned char *id,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton unsigned int idlen, time_t expiry,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton unsigned char *ucaData,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton unsigned int nData, apr_pool_t *pool)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_t *dbm;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmkey;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmval;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_status_t rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* be careful: do not try to store too much bytes in a DBM file! */
0797faae937515a5225a36db4a1ec79480d2555cjorton#ifdef PAIRMAX
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((idlen + nData) >= PAIRMAX) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
0797faae937515a5225a36db4a1ec79480d2555cjorton "data size too large for DBM session cache: %d >= %d",
0797faae937515a5225a36db4a1ec79480d2555cjorton (idlen + nData), PAIRMAX);
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_ENOSPC;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton#else
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((idlen + nData) >= 950 /* at least less than approx. 1KB */) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
0797faae937515a5225a36db4a1ec79480d2555cjorton "data size too large for DBM session cache: %d >= %d",
0797faae937515a5225a36db4a1ec79480d2555cjorton (idlen + nData), 950);
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_ENOSPC;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton#endif
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* create DBM key */
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmkey.dptr = (char *)id;
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmkey.dsize = idlen;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* create DBM value */
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmval.dsize = sizeof(time_t) + nData;
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmval.dptr = (char *)malloc(dbmval.dsize);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (dbmval.dptr == NULL) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
0797faae937515a5225a36db4a1ec79480d2555cjorton "malloc error creating DBM value");
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_ENOMEM;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton memcpy((char *)dbmval.dptr, &expiry, sizeof(time_t));
0797faae937515a5225a36db4a1ec79480d2555cjorton memcpy((char *)dbmval.dptr+sizeof(time_t), ucaData, nData);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* and store it to the DBM file */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_clear(ctx->pool);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rv = apr_dbm_open(&dbm, ctx->data_file,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton APR_DBM_RWCREATE, DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot open socache DBM file `%s' for writing "
0797faae937515a5225a36db4a1ec79480d2555cjorton "(store)",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton free(dbmval.dptr);
0797faae937515a5225a36db4a1ec79480d2555cjorton return rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rv = apr_dbm_store(dbm, dbmkey, dbmval)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot store socache object to DBM file `%s'",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton free(dbmval.dptr);
0797faae937515a5225a36db4a1ec79480d2555cjorton return rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* free temporary buffers */
0797faae937515a5225a36db4a1ec79480d2555cjorton free(dbmval.dptr);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* allow the regular expiring to occur */
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_expire(ctx, s);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_SUCCESS;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
072f7e449a76d28b580de6e89a1723713ab9adb1jortonstatic apr_status_t socache_dbm_retrieve(ap_socache_instance_t *ctx, server_rec *s,
072f7e449a76d28b580de6e89a1723713ab9adb1jorton const unsigned char *id, unsigned int idlen,
072f7e449a76d28b580de6e89a1723713ab9adb1jorton unsigned char *dest, unsigned int *destlen,
072f7e449a76d28b580de6e89a1723713ab9adb1jorton apr_pool_t *p)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_t *dbm;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmkey;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmval;
0797faae937515a5225a36db4a1ec79480d2555cjorton unsigned int nData;
0797faae937515a5225a36db4a1ec79480d2555cjorton time_t expiry;
0797faae937515a5225a36db4a1ec79480d2555cjorton time_t now;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_status_t rc;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* allow the regular expiring to occur */
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_expire(ctx, s);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* create DBM key and values */
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmkey.dptr = (char *)id;
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmkey.dsize = idlen;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* and fetch it from the DBM file
0797faae937515a5225a36db4a1ec79480d2555cjorton * XXX: Should we open the dbm against r->pool so the cleanup will
0797faae937515a5225a36db4a1ec79480d2555cjorton * do the apr_dbm_close? This would make the code a bit cleaner.
0797faae937515a5225a36db4a1ec79480d2555cjorton */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_clear(ctx->pool);
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rc = apr_dbm_open(&dbm, ctx->data_file, APR_DBM_RWCREATE,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rc, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot open socache DBM file `%s' for reading "
0797faae937515a5225a36db4a1ec79480d2555cjorton "(fetch)",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton return rc;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton rc = apr_dbm_fetch(dbm, dbmkey, &dbmval);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (rc != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton return rc;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton if (dbmval.dptr == NULL || dbmval.dsize <= sizeof(time_t)) {
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_EGENERAL;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* parse resulting data */
0797faae937515a5225a36db4a1ec79480d2555cjorton nData = dbmval.dsize-sizeof(time_t);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (nData > *destlen) {
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_ENOSPC;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton *destlen = nData;
0797faae937515a5225a36db4a1ec79480d2555cjorton memcpy(&expiry, dbmval.dptr, sizeof(time_t));
0797faae937515a5225a36db4a1ec79480d2555cjorton memcpy(dest, (char *)dbmval.dptr + sizeof(time_t), nData);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* make sure the stuff is still not expired */
0797faae937515a5225a36db4a1ec79480d2555cjorton now = time(NULL);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (expiry <= now) {
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_remove(ctx, s, id, idlen, p);
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_NOTFOUND;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton return APR_SUCCESS;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
501e60e433e1914c64f642114fbb4fb9be9e2ca9jortonstatic apr_status_t socache_dbm_remove(ap_socache_instance_t *ctx,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton server_rec *s, const unsigned char *id,
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton unsigned int idlen, apr_pool_t *p)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_t *dbm;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmkey;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_status_t rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* create DBM key and values */
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmkey.dptr = (char *)id;
0797faae937515a5225a36db4a1ec79480d2555cjorton dbmkey.dsize = idlen;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* and delete it from the DBM file */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_clear(ctx->pool);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rv = apr_dbm_open(&dbm, ctx->data_file, APR_DBM_RWCREATE,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot open socache DBM file `%s' for writing "
0797faae937515a5225a36db4a1ec79480d2555cjorton "(delete)",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton return rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_delete(dbm, dbmkey);
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton
501e60e433e1914c64f642114fbb4fb9be9e2ca9jorton return APR_SUCCESS;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstatic void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_t *dbm;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmkey;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmval;
0797faae937515a5225a36db4a1ec79480d2555cjorton time_t tExpiresAt;
0797faae937515a5225a36db4a1ec79480d2555cjorton int nElements = 0;
0797faae937515a5225a36db4a1ec79480d2555cjorton int nDeleted = 0;
0797faae937515a5225a36db4a1ec79480d2555cjorton int bDelete;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t *keylist;
0797faae937515a5225a36db4a1ec79480d2555cjorton int keyidx;
0797faae937515a5225a36db4a1ec79480d2555cjorton int i;
0797faae937515a5225a36db4a1ec79480d2555cjorton time_t tNow;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_status_t rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /*
0797faae937515a5225a36db4a1ec79480d2555cjorton * make sure the expiration for still not-accessed session
0797faae937515a5225a36db4a1ec79480d2555cjorton * cache entries is done only from time to time
0797faae937515a5225a36db4a1ec79480d2555cjorton */
0797faae937515a5225a36db4a1ec79480d2555cjorton tNow = time(NULL);
0797faae937515a5225a36db4a1ec79480d2555cjorton
fca945cb6bed035dcc6bbced5e327bbd4d8420abjorton if (tNow < ctx->last_expiry + ctx->expiry_interval) {
0797faae937515a5225a36db4a1ec79480d2555cjorton return;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->last_expiry = tNow;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /*
0797faae937515a5225a36db4a1ec79480d2555cjorton * Here we have to be very carefully: Not all DBM libraries are
0797faae937515a5225a36db4a1ec79480d2555cjorton * smart enough to allow one to iterate over the elements and at the
0797faae937515a5225a36db4a1ec79480d2555cjorton * same time delete expired ones. Some of them get totally crazy
0797faae937515a5225a36db4a1ec79480d2555cjorton * while others have no problems. So we have to do it the slower but
0797faae937515a5225a36db4a1ec79480d2555cjorton * more safe way: we first iterate over all elements and remember
0797faae937515a5225a36db4a1ec79480d2555cjorton * those which have to be expired. Then in a second pass we delete
0797faae937515a5225a36db4a1ec79480d2555cjorton * all those expired elements. Additionally we reopen the DBM file
0797faae937515a5225a36db4a1ec79480d2555cjorton * to be really safe in state.
0797faae937515a5225a36db4a1ec79480d2555cjorton */
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton#define KEYMAX 1024
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton for (;;) {
0797faae937515a5225a36db4a1ec79480d2555cjorton /* allocate the key array in a memory sub pool */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_clear(ctx->pool);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((keylist = apr_palloc(ctx->pool, sizeof(dbmkey)*KEYMAX)) == NULL) {
0797faae937515a5225a36db4a1ec79480d2555cjorton break;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* pass 1: scan DBM database */
0797faae937515a5225a36db4a1ec79480d2555cjorton keyidx = 0;
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rv = apr_dbm_open(&dbm, ctx->data_file, APR_DBM_RWCREATE,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot open socache DBM file `%s' for "
0797faae937515a5225a36db4a1ec79480d2555cjorton "scanning",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton break;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_firstkey(dbm, &dbmkey);
0797faae937515a5225a36db4a1ec79480d2555cjorton while (dbmkey.dptr != NULL) {
0797faae937515a5225a36db4a1ec79480d2555cjorton nElements++;
0797faae937515a5225a36db4a1ec79480d2555cjorton bDelete = FALSE;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_fetch(dbm, dbmkey, &dbmval);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (dbmval.dsize <= sizeof(time_t) || dbmval.dptr == NULL)
0797faae937515a5225a36db4a1ec79480d2555cjorton bDelete = TRUE;
0797faae937515a5225a36db4a1ec79480d2555cjorton else {
0797faae937515a5225a36db4a1ec79480d2555cjorton memcpy(&tExpiresAt, dbmval.dptr, sizeof(time_t));
0797faae937515a5225a36db4a1ec79480d2555cjorton if (tExpiresAt <= tNow)
0797faae937515a5225a36db4a1ec79480d2555cjorton bDelete = TRUE;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton if (bDelete) {
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((keylist[keyidx].dptr = apr_pmemdup(ctx->pool, dbmkey.dptr, dbmkey.dsize)) != NULL) {
0797faae937515a5225a36db4a1ec79480d2555cjorton keylist[keyidx].dsize = dbmkey.dsize;
0797faae937515a5225a36db4a1ec79480d2555cjorton keyidx++;
0797faae937515a5225a36db4a1ec79480d2555cjorton if (keyidx == KEYMAX)
0797faae937515a5225a36db4a1ec79480d2555cjorton break;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_nextkey(dbm, &dbmkey);
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton /* pass 2: delete expired elements */
0797faae937515a5225a36db4a1ec79480d2555cjorton if (apr_dbm_open(&dbm, ctx->data_file, APR_DBM_RWCREATE,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton DBM_FILE_MODE, ctx->pool) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot re-open socache DBM file `%s' for "
0797faae937515a5225a36db4a1ec79480d2555cjorton "expiring",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton break;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton for (i = 0; i < keyidx; i++) {
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_delete(dbm, keylist[i]);
0797faae937515a5225a36db4a1ec79480d2555cjorton nDeleted++;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton if (keyidx < KEYMAX)
0797faae937515a5225a36db4a1ec79480d2555cjorton break;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
0797faae937515a5225a36db4a1ec79480d2555cjorton "Inter-Process Session Cache (DBM) Expiry: "
0797faae937515a5225a36db4a1ec79480d2555cjorton "old: %d, new: %d, removed: %d",
0797faae937515a5225a36db4a1ec79480d2555cjorton nElements, nElements-nDeleted, nDeleted);
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
2685f3814b77577ef7b2523442dab1ca88df1e41jortonstatic void socache_dbm_status(ap_socache_instance_t *ctx, request_rec *r,
2685f3814b77577ef7b2523442dab1ca88df1e41jorton int flags)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_t *dbm;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmkey;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_datum_t dbmval;
0797faae937515a5225a36db4a1ec79480d2555cjorton int nElem;
0797faae937515a5225a36db4a1ec79480d2555cjorton int nSize;
0797faae937515a5225a36db4a1ec79480d2555cjorton int nAverage;
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_status_t rv;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton nElem = 0;
0797faae937515a5225a36db4a1ec79480d2555cjorton nSize = 0;
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_pool_clear(ctx->pool);
0797faae937515a5225a36db4a1ec79480d2555cjorton if ((rv = apr_dbm_open(&dbm, ctx->data_file, APR_DBM_RWCREATE,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton DBM_FILE_MODE, ctx->pool)) != APR_SUCCESS) {
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
eab15974b1d8bbcb6d4f9ec75527b39ffded82aajorton "Cannot open socache DBM file `%s' for status "
0797faae937515a5225a36db4a1ec79480d2555cjorton "retrival",
0797faae937515a5225a36db4a1ec79480d2555cjorton ctx->data_file);
0797faae937515a5225a36db4a1ec79480d2555cjorton return;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton /*
0797faae937515a5225a36db4a1ec79480d2555cjorton * XXX - Check the return value of apr_dbm_firstkey, apr_dbm_fetch - TBD
0797faae937515a5225a36db4a1ec79480d2555cjorton */
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_firstkey(dbm, &dbmkey);
0797faae937515a5225a36db4a1ec79480d2555cjorton for ( ; dbmkey.dptr != NULL; apr_dbm_nextkey(dbm, &dbmkey)) {
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_fetch(dbm, dbmkey, &dbmval);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (dbmval.dptr == NULL)
0797faae937515a5225a36db4a1ec79480d2555cjorton continue;
0797faae937515a5225a36db4a1ec79480d2555cjorton nElem += 1;
0797faae937515a5225a36db4a1ec79480d2555cjorton nSize += dbmval.dsize;
0797faae937515a5225a36db4a1ec79480d2555cjorton }
0797faae937515a5225a36db4a1ec79480d2555cjorton apr_dbm_close(dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton if (nSize > 0 && nElem > 0)
0797faae937515a5225a36db4a1ec79480d2555cjorton nAverage = nSize / nElem;
0797faae937515a5225a36db4a1ec79480d2555cjorton else
0797faae937515a5225a36db4a1ec79480d2555cjorton nAverage = 0;
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_rprintf(r, "cache type: <b>DBM</b>, maximum size: <b>unlimited</b><br>");
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_rprintf(r, "current sessions: <b>%d</b>, current size: <b>%d</b> bytes<br>", nElem, nSize);
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_rprintf(r, "average session size: <b>%d</b> bytes<br>", nAverage);
0797faae937515a5225a36db4a1ec79480d2555cjorton return;
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjortonstatic const ap_socache_provider_t socache_dbm = {
0797faae937515a5225a36db4a1ec79480d2555cjorton "dbm",
0797faae937515a5225a36db4a1ec79480d2555cjorton AP_SOCACHE_FLAG_NOTMPSAFE,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_create,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_init,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_kill,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_store,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_retrieve,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_remove,
0797faae937515a5225a36db4a1ec79480d2555cjorton socache_dbm_status
0797faae937515a5225a36db4a1ec79480d2555cjorton};
0797faae937515a5225a36db4a1ec79480d2555cjorton
0797faae937515a5225a36db4a1ec79480d2555cjortonstatic void register_hooks(apr_pool_t *p)
0797faae937515a5225a36db4a1ec79480d2555cjorton{
0797faae937515a5225a36db4a1ec79480d2555cjorton ap_register_provider(p, AP_SOCACHE_PROVIDER_GROUP, "dbm",
0797faae937515a5225a36db4a1ec79480d2555cjorton AP_SOCACHE_PROVIDER_VERSION,
0797faae937515a5225a36db4a1ec79480d2555cjorton &socache_dbm);
0797faae937515a5225a36db4a1ec79480d2555cjorton}
0797faae937515a5225a36db4a1ec79480d2555cjorton
6c61d6d39916f23d49386ce9e9148f2d52f730d5chrisdmodule AP_MODULE_DECLARE_DATA socache_dbm_module = {
0797faae937515a5225a36db4a1ec79480d2555cjorton STANDARD20_MODULE_STUFF,
0797faae937515a5225a36db4a1ec79480d2555cjorton NULL, NULL, NULL, NULL, NULL,
0797faae937515a5225a36db4a1ec79480d2555cjorton register_hooks
0797faae937515a5225a36db4a1ec79480d2555cjorton};