mirror of
https://github.com/apache/httpd.git
synced 2025-08-08 15:02:10 +03:00
socache API tweaks based on chrisd's review:
* include/ap_socache.h (ap_socache_provider_t::store): Take a pool. (ap_socache_provider_t::retrieve): Guarantee APR_NOTFOUND for a "not found" result. (ap_socache_provider_t::remove): Return an apr_status_t. * modules/cache/mod_socache_dc.c, modules/cache/mod_socache_dbm.c, modules/cache/mod_socache_shmcb, modules/cache/mod_socache_memcache.c: Adjust accordingly. * modules/ssl/ssl_scache.c (ssl_scache_store): Pass pool to sesscache->store. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@726059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -116,11 +116,14 @@ typedef struct ap_socache_provider_t {
|
|||||||
* @param expiry Absolute time at which the object expires
|
* @param expiry Absolute time at which the object expires
|
||||||
* @param data Data to store; binary blob
|
* @param data Data to store; binary blob
|
||||||
* @param datalen Length of data blob
|
* @param datalen Length of data blob
|
||||||
|
* @param pool Pool for temporary allocations.
|
||||||
|
* @return APR status value.
|
||||||
*/
|
*/
|
||||||
apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s,
|
apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s,
|
||||||
const unsigned char *id, unsigned int idlen,
|
const unsigned char *id, unsigned int idlen,
|
||||||
time_t expiry,
|
time_t expiry,
|
||||||
unsigned char *data, unsigned int datalen);
|
unsigned char *data, unsigned int datalen,
|
||||||
|
apr_pool_t *pool);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a cached object.
|
* Retrieve a cached object.
|
||||||
@@ -132,6 +135,8 @@ typedef struct ap_socache_provider_t {
|
|||||||
* @param datalen On entry, length of data buffer; on exit, the
|
* @param datalen On entry, length of data buffer; on exit, the
|
||||||
* number of bytes written to the data buffer.
|
* number of bytes written to the data buffer.
|
||||||
* @param pool Pool for temporary allocations.
|
* @param pool Pool for temporary allocations.
|
||||||
|
* @return APR status value; APR_NOTFOUND if the object was not
|
||||||
|
* found
|
||||||
*/
|
*/
|
||||||
apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s,
|
apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s,
|
||||||
const unsigned char *id, unsigned int idlen,
|
const unsigned char *id, unsigned int idlen,
|
||||||
@@ -145,7 +150,7 @@ typedef struct ap_socache_provider_t {
|
|||||||
* @param idlen Length of id blob
|
* @param idlen Length of id blob
|
||||||
* @param pool Pool for temporary allocations.
|
* @param pool Pool for temporary allocations.
|
||||||
*/
|
*/
|
||||||
void (*remove)(ap_socache_instance_t *instance, server_rec *s,
|
apr_status_t (*remove)(ap_socache_instance_t *instance, server_rec *s,
|
||||||
const unsigned char *id, unsigned int idlen,
|
const unsigned char *id, unsigned int idlen,
|
||||||
apr_pool_t *pool);
|
apr_pool_t *pool);
|
||||||
|
|
||||||
|
25
modules/cache/mod_socache_dbm.c
vendored
25
modules/cache/mod_socache_dbm.c
vendored
@@ -71,9 +71,9 @@ struct ap_socache_instance_t {
|
|||||||
|
|
||||||
static void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s);
|
static void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s);
|
||||||
|
|
||||||
static void socache_dbm_remove(ap_socache_instance_t *ctx, server_rec *s,
|
static apr_status_t socache_dbm_remove(ap_socache_instance_t *ctx,
|
||||||
const unsigned char *id, unsigned int idlen,
|
server_rec *s, const unsigned char *id,
|
||||||
apr_pool_t *p);
|
unsigned int idlen, apr_pool_t *p);
|
||||||
|
|
||||||
static const char *socache_dbm_create(ap_socache_instance_t **context,
|
static const char *socache_dbm_create(ap_socache_instance_t **context,
|
||||||
const char *arg,
|
const char *arg,
|
||||||
@@ -176,10 +176,11 @@ static void socache_dbm_kill(ap_socache_instance_t *ctx, server_rec *s)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static apr_status_t socache_dbm_store(ap_socache_instance_t *ctx, server_rec *s,
|
static apr_status_t socache_dbm_store(ap_socache_instance_t *ctx,
|
||||||
const unsigned char *id, unsigned int idlen,
|
server_rec *s, const unsigned char *id,
|
||||||
time_t expiry, unsigned char *ucaData,
|
unsigned int idlen, time_t expiry,
|
||||||
unsigned int nData)
|
unsigned char *ucaData,
|
||||||
|
unsigned int nData, apr_pool_t *pool)
|
||||||
{
|
{
|
||||||
apr_dbm_t *dbm;
|
apr_dbm_t *dbm;
|
||||||
apr_datum_t dbmkey;
|
apr_datum_t dbmkey;
|
||||||
@@ -315,9 +316,9 @@ static apr_status_t socache_dbm_retrieve(ap_socache_instance_t *ctx, server_rec
|
|||||||
return APR_SUCCESS;
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_dbm_remove(ap_socache_instance_t *ctx, server_rec *s,
|
static apr_status_t socache_dbm_remove(ap_socache_instance_t *ctx,
|
||||||
const unsigned char *id, unsigned int idlen,
|
server_rec *s, const unsigned char *id,
|
||||||
apr_pool_t *p)
|
unsigned int idlen, apr_pool_t *p)
|
||||||
{
|
{
|
||||||
apr_dbm_t *dbm;
|
apr_dbm_t *dbm;
|
||||||
apr_datum_t dbmkey;
|
apr_datum_t dbmkey;
|
||||||
@@ -336,12 +337,12 @@ static void socache_dbm_remove(ap_socache_instance_t *ctx, server_rec *s,
|
|||||||
"Cannot open SSLSessionCache DBM file `%s' for writing "
|
"Cannot open SSLSessionCache DBM file `%s' for writing "
|
||||||
"(delete)",
|
"(delete)",
|
||||||
ctx->data_file);
|
ctx->data_file);
|
||||||
return;
|
return rv;
|
||||||
}
|
}
|
||||||
apr_dbm_delete(dbm, dbmkey);
|
apr_dbm_delete(dbm, dbmkey);
|
||||||
apr_dbm_close(dbm);
|
apr_dbm_close(dbm);
|
||||||
|
|
||||||
return;
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s)
|
static void socache_dbm_expire(ap_socache_instance_t *ctx, server_rec *s)
|
||||||
|
11
modules/cache/mod_socache_dc.c
vendored
11
modules/cache/mod_socache_dc.c
vendored
@@ -93,7 +93,8 @@ static void socache_dc_kill(ap_socache_instance_t *ctx, server_rec *s)
|
|||||||
static apr_status_t socache_dc_store(ap_socache_instance_t *ctx, 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,
|
const unsigned char *id, unsigned int idlen,
|
||||||
time_t timeout,
|
time_t timeout,
|
||||||
unsigned char *der, unsigned int der_len)
|
unsigned char *der, unsigned int der_len,
|
||||||
|
apr_pool_t *p)
|
||||||
{
|
{
|
||||||
/* !@#$%^ - why do we deal with *absolute* time anyway??? */
|
/* !@#$%^ - why do we deal with *absolute* time anyway??? */
|
||||||
timeout -= time(NULL);
|
timeout -= time(NULL);
|
||||||
@@ -128,15 +129,17 @@ static apr_status_t socache_dc_retrieve(ap_socache_instance_t *ctx, server_rec *
|
|||||||
return APR_SUCCESS;
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_dc_remove(ap_socache_instance_t *ctx, server_rec *s,
|
static apr_status_t socache_dc_remove(ap_socache_instance_t *ctx,
|
||||||
const unsigned char *id, unsigned int idlen,
|
server_rec *s, const unsigned char *id,
|
||||||
apr_pool_t *p)
|
unsigned int idlen, apr_pool_t *p)
|
||||||
{
|
{
|
||||||
/* Remove any corresponding session from the distributed cache context */
|
/* Remove any corresponding session from the distributed cache context */
|
||||||
if (!DC_CTX_remove_session(ctx->dc, id, idlen)) {
|
if (!DC_CTX_remove_session(ctx->dc, id, idlen)) {
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' MISS");
|
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' MISS");
|
||||||
|
return APR_NOTFOUND;
|
||||||
} else {
|
} else {
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' HIT");
|
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' HIT");
|
||||||
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
modules/cache/mod_socache_memcache.c
vendored
17
modules/cache/mod_socache_memcache.c
vendored
@@ -201,7 +201,8 @@ static int socache_mc_id2key(ap_socache_instance_t *ctx,
|
|||||||
static apr_status_t socache_mc_store(ap_socache_instance_t *ctx, 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,
|
const unsigned char *id, unsigned int idlen,
|
||||||
time_t timeout,
|
time_t timeout,
|
||||||
unsigned char *ucaData, unsigned int nData)
|
unsigned char *ucaData, unsigned int nData,
|
||||||
|
apr_pool_t *p)
|
||||||
{
|
{
|
||||||
char buf[MC_KEY_LEN];
|
char buf[MC_KEY_LEN];
|
||||||
apr_status_t rv;
|
apr_status_t rv;
|
||||||
@@ -222,8 +223,7 @@ static apr_status_t socache_mc_store(ap_socache_instance_t *ctx, server_rec *s,
|
|||||||
return APR_SUCCESS;
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static apr_status_t socache_mc_retrieve(ap_socache_instance_t *ctx,
|
static apr_status_t socache_mc_retrieve(ap_socache_instance_t *ctx, server_rec *s,
|
||||||
server_rec *s,
|
|
||||||
const unsigned char *id, unsigned int idlen,
|
const unsigned char *id, unsigned int idlen,
|
||||||
unsigned char *dest, unsigned int *destlen,
|
unsigned char *dest, unsigned int *destlen,
|
||||||
apr_pool_t *p)
|
apr_pool_t *p)
|
||||||
@@ -259,15 +259,15 @@ static apr_status_t socache_mc_retrieve(ap_socache_instance_t *ctx,
|
|||||||
return APR_SUCCESS;
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_mc_remove(ap_socache_instance_t *ctx, server_rec *s,
|
static apr_status_t socache_mc_remove(ap_socache_instance_t *ctx, server_rec *s,
|
||||||
const unsigned char *id, unsigned int idlen,
|
const unsigned char *id,
|
||||||
apr_pool_t *p)
|
unsigned int idlen, apr_pool_t *p)
|
||||||
{
|
{
|
||||||
char buf[MC_KEY_LEN];
|
char buf[MC_KEY_LEN];
|
||||||
apr_status_t rv;
|
apr_status_t rv;
|
||||||
|
|
||||||
if (socache_mc_id2key(ctx, id, idlen, buf, sizeof buf)) {
|
if (socache_mc_id2key(ctx, id, idlen, buf, sizeof buf)) {
|
||||||
return;
|
return APR_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = apr_memcache_delete(ctx->mc, buf, 0);
|
rv = apr_memcache_delete(ctx->mc, buf, 0);
|
||||||
@@ -276,8 +276,9 @@ static void socache_mc_remove(ap_socache_instance_t *ctx, server_rec *s,
|
|||||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s,
|
ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s,
|
||||||
"scache_mc: error deleting key '%s' ",
|
"scache_mc: error deleting key '%s' ",
|
||||||
buf);
|
buf);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_mc_status(ap_socache_instance_t *ctx, request_rec *r, int flags)
|
static void socache_mc_status(ap_socache_instance_t *ctx, request_rec *r, int flags)
|
||||||
|
26
modules/cache/mod_socache_shmcb.c
vendored
26
modules/cache/mod_socache_shmcb.c
vendored
@@ -447,11 +447,11 @@ static void socache_shmcb_kill(ap_socache_instance_t *ctx, server_rec *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static apr_status_t socache_shmcb_store(ap_socache_instance_t *ctx,
|
static apr_status_t socache_shmcb_store(ap_socache_instance_t *ctx,
|
||||||
server_rec *s,
|
server_rec *s, const unsigned char *id,
|
||||||
const unsigned char *id, unsigned int idlen,
|
unsigned int idlen, time_t timeout,
|
||||||
time_t timeout,
|
|
||||||
unsigned char *encoded,
|
unsigned char *encoded,
|
||||||
unsigned int len_encoded)
|
unsigned int len_encoded,
|
||||||
|
apr_pool_t *p)
|
||||||
{
|
{
|
||||||
SHMCBHeader *header = ctx->header;
|
SHMCBHeader *header = ctx->header;
|
||||||
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
|
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
|
||||||
@@ -503,12 +503,13 @@ static apr_status_t socache_shmcb_retrieve(ap_socache_instance_t *ctx,
|
|||||||
return rv == 0 ? APR_SUCCESS : APR_EGENERAL;
|
return rv == 0 ? APR_SUCCESS : APR_EGENERAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_shmcb_remove(ap_socache_instance_t *ctx, server_rec *s,
|
static apr_status_t socache_shmcb_remove(ap_socache_instance_t *ctx,
|
||||||
const unsigned char *id, unsigned int idlen,
|
server_rec *s, const unsigned char *id,
|
||||||
apr_pool_t *p)
|
unsigned int idlen, apr_pool_t *p)
|
||||||
{
|
{
|
||||||
SHMCBHeader *header = ctx->header;
|
SHMCBHeader *header = ctx->header;
|
||||||
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
|
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
|
||||||
|
apr_status_t rv;
|
||||||
|
|
||||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
||||||
"socache_shmcb_remove (0x%02x -> subcache %d)",
|
"socache_shmcb_remove (0x%02x -> subcache %d)",
|
||||||
@@ -516,14 +517,19 @@ static void socache_shmcb_remove(ap_socache_instance_t *ctx, server_rec *s,
|
|||||||
if (idlen < 4) {
|
if (idlen < 4) {
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "unusably short session_id provided "
|
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "unusably short session_id provided "
|
||||||
"(%u bytes)", idlen);
|
"(%u bytes)", idlen);
|
||||||
return;
|
return APR_EINVAL;
|
||||||
}
|
}
|
||||||
if (shmcb_subcache_remove(s, header, subcache, id, idlen))
|
if (shmcb_subcache_remove(s, header, subcache, id, idlen) == 0) {
|
||||||
header->stat_removes_hit++;
|
header->stat_removes_hit++;
|
||||||
else
|
rv = APR_SUCCESS;
|
||||||
|
} else {
|
||||||
header->stat_removes_miss++;
|
header->stat_removes_miss++;
|
||||||
|
rv = APR_NOTFOUND;
|
||||||
|
}
|
||||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
||||||
"leaving socache_shmcb_remove successfully");
|
"leaving socache_shmcb_remove successfully");
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socache_shmcb_status(ap_socache_instance_t *ctx,
|
static void socache_shmcb_status(ap_socache_instance_t *ctx,
|
||||||
|
@@ -114,7 +114,7 @@ BOOL ssl_scache_store(server_rec *s, UCHAR *id, int idlen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rv = mc->sesscache->store(mc->sesscache_context, s, id, idlen,
|
rv = mc->sesscache->store(mc->sesscache_context, s, id, idlen,
|
||||||
expiry, encoded, len);
|
expiry, encoded, len, p);
|
||||||
|
|
||||||
if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
|
if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
|
||||||
ssl_mutex_off(s);
|
ssl_mutex_off(s);
|
||||||
|
Reference in New Issue
Block a user