httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r630323 - in /httpd/httpd/trunk/modules/ssl: ssl_engine_config.c ssl_private.h ssl_scache.c ssl_scache_dbm.c ssl_scache_dc.c ssl_scache_memcache.c ssl_scache_shmcb.c
Date Fri, 22 Feb 2008 21:09:42 GMT
Author: jorton
Date: Fri Feb 22 13:09:40 2008
New Revision: 630323

URL: http://svn.apache.org/viewvc?rev=630323&view=rev
Log:
Session cache interface redesign, Part 3: 

Move provider-private context out of SSLModConfigRec and into an
opaque context pointer.  Use real error propagation in the ->init
functions rather than ssl_die().

* modules/ssl/ssl_private.h (modssl_sesscache_provider): Take a
  context out-parameter from ->init, and return an apr_status_t.
  Add context pointer as first arg for the other function types.
  (SSLModConfigRec): Remove tSessionCacheData* fields; add
  sesscache_context field.

* modules/ssl/ssl_scache.c (ssl_scache_init): Move once-per-process
  invocation check back into here.  
  (ssl_scache_*): Adjust to use context pointer.

* modules/ssl/ssl_scache_shmcb.c, modules/ssl/ssl_scache_dc.c,
  modules/ssl/ssl_scache_dbm.c: Adjust all implementations to use
  opaque context pointer.

* modules/ssl/ssl_scache_memcache.c: Move memcache context into the
  context structure rather than using global state.

* modules/ssl/ssl_engine_config.c: Remove handling of
  pSessionCacheData* fields in SSLModConfigRec.

Modified:
    httpd/httpd/trunk/modules/ssl/ssl_engine_config.c
    httpd/httpd/trunk/modules/ssl/ssl_private.h
    httpd/httpd/trunk/modules/ssl/ssl_scache.c
    httpd/httpd/trunk/modules/ssl/ssl_scache_dbm.c
    httpd/httpd/trunk/modules/ssl/ssl_scache_dc.c
    httpd/httpd/trunk/modules/ssl/ssl_scache_memcache.c
    httpd/httpd/trunk/modules/ssl/ssl_scache_shmcb.c

Modified: httpd/httpd/trunk/modules/ssl/ssl_engine_config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_engine_config.c?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_engine_config.c (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_engine_config.c Fri Feb 22 13:09:40 2008
@@ -61,8 +61,6 @@
     mc->nSessionCacheMode      = SSL_SCMODE_UNSET;
     mc->szSessionCacheDataFile = NULL;
     mc->nSessionCacheDataSize  = 0;
-    mc->pSessionCacheDataMM    = NULL;
-    mc->pSessionCacheDataRMM   = NULL;
     mc->sesscache              = NULL;
     mc->nMutexMode             = SSL_MUTEXMODE_UNSET;
     mc->nMutexMech             = APR_LOCK_DEFAULT;
@@ -1001,7 +999,6 @@
                                 "SSLSessionCache: Invalid cache file path %s",
                                 colon+1);
         }
-        mc->tSessionCacheDataTable = NULL;
         mc->nSessionCacheDataSize  = 1024*512; /* 512KB */
 
         if ((cp = strchr(mc->szSessionCacheDataFile, '('))) {

Modified: httpd/httpd/trunk/modules/ssl/ssl_private.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_private.h?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_private.h (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_private.h Fri Feb 22 13:09:40 2008
@@ -366,21 +366,31 @@
 
 /* Session cache provider vtable. */
 typedef struct {
-    void (*init)(server_rec *s, apr_pool_t *pool);
-    void (*destroy)(server_rec *s);
-    BOOL (*store)(server_rec *s, UCHAR *id, int idlen,
-                  time_t expiry, 
+    /* Initialize the cache.  Return APR error code.  The context
+     * pointer returned in *CONTEXT will be passed as the first
+     * argument to subsequent invocations. */
+    apr_status_t (*init)(server_rec *s, void **context, apr_pool_t *pool);
+    /* Destroy a given cache context. */    
+    void (*destroy)(void *context, server_rec *s);
+    /* Store an object in the cache. */
+    BOOL (*store)(void *context, server_rec *s, 
+                  UCHAR *id, int idlen, time_t expiry, 
                   unsigned char *data, unsigned int datalen);
     /* Retrieve cached data with key ID of length IDLEN,
      * returning TRUE on success or FALSE otherwise.  If
      * TRUE, the data must be placed in DEST, which has length
      * on entry of *DESTLEN.  *DESTLEN must be updated to 
      * equal the length of data written on exit. */
-    BOOL (*retrieve)(server_rec *s, const UCHAR *id, int idlen,
+    BOOL (*retrieve)(void *context, server_rec *s,
+                     const UCHAR *id, int idlen,
                      unsigned char *dest, unsigned int *destlen,
                      apr_pool_t *pool);
-    void (*delete)(server_rec *s, UCHAR *id, int idlen, apr_pool_t *pool);
-    void (*status)(request_rec *r, int flags, apr_pool_t *pool);
+    /* Remove an object from the cache. */
+    void (*delete)(void *context, server_rec *s,
+                   UCHAR *id, int idlen, apr_pool_t *pool);
+    /* Dump cache status for mod_status output. */
+    void (*status)(void *context, request_rec *r, 
+                   int flags, apr_pool_t *pool);
 } modssl_sesscache_provider;
 
 typedef struct {
@@ -390,12 +400,11 @@
     int             nSessionCacheMode;
     char           *szSessionCacheDataFile;
     int             nSessionCacheDataSize;
-    apr_shm_t      *pSessionCacheDataMM;
-    apr_rmm_t      *pSessionCacheDataRMM;
-    void           *tSessionCacheDataTable;
 
-    /* The configured provider: */
+    /* The configured provider, and associated private data
+     * structure. */
     const modssl_sesscache_provider *sesscache;
+    void *sesscache_context;
 
     ssl_mutexmode_t nMutexMode;
     apr_lockmech_e  nMutexMech;

Modified: httpd/httpd/trunk/modules/ssl/ssl_scache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_scache.c?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_scache.c (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_scache.c Fri Feb 22 13:09:40 2008
@@ -40,6 +40,20 @@
 void ssl_scache_init(server_rec *s, apr_pool_t *p)
 {
     SSLModConfigRec *mc = myModConfig(s);
+    apr_status_t rv;
+
+    /* ### push this up into scache_init??? */
+    {
+        void *data;
+        const char *userdata_key = "ssl_scache_init";
+
+        apr_pool_userdata_get(&data, userdata_key, s->process->pool);
+        if (!data) {
+            apr_pool_userdata_set((const void *)1, userdata_key,
+                                  apr_pool_cleanup_null, s->process->pool);
+            return;
+        }
+    }
 
     /*
      * Warn the user that he should use the session cache.
@@ -52,14 +66,20 @@
         return;
     }
 
-    mc->sesscache->init(s, p);
+    rv = mc->sesscache->init(s, &mc->sesscache_context, p);
+    if (rv) {
+        /* ABORT ABORT etc. */
+        ssl_die();
+    }
 }
 
 void ssl_scache_kill(server_rec *s)
 {
     SSLModConfigRec *mc = myModConfig(s);
-
-    mc->sesscache->destroy(s);
+    
+    if (mc->sesscache) {
+        mc->sesscache->destroy(mc->sesscache_context, s);
+    }
 }
 
 BOOL ssl_scache_store(server_rec *s, UCHAR *id, int idlen,
@@ -81,7 +101,8 @@
     ptr = encoded;
     len = i2d_SSL_SESSION(sess, &ptr);
 
-    return mc->sesscache->store(s, id, idlen, expiry, encoded, len);
+    return mc->sesscache->store(mc->sesscache_context, s, id, idlen, 
+                                expiry, encoded, len);
 }
 
 SSL_SESSION *ssl_scache_retrieve(server_rec *s, UCHAR *id, int idlen,
@@ -92,7 +113,8 @@
     unsigned int destlen = SSL_SESSION_MAX_DER;
     MODSSL_D2I_SSL_SESSION_CONST unsigned char *ptr;
     
-    if (mc->sesscache->retrieve(s, id, idlen, dest, &destlen, p) == FALSE) {
+    if (mc->sesscache->retrieve(mc->sesscache_context, s, id, idlen, 
+                                dest, &destlen, p) == FALSE) {
         return NULL;
     }
 
@@ -106,7 +128,7 @@
 {
     SSLModConfigRec *mc = myModConfig(s);
 
-    mc->sesscache->delete(s, id, idlen, p);
+    mc->sesscache->delete(mc->sesscache_context, s, id, idlen, p);
 
     return;
 }
@@ -130,7 +152,7 @@
     ap_rputs("</td></tr>\n", r);
     ap_rputs("<tr><td bgcolor=\"#ffffff\">\n", r);
 
-    mc->sesscache->status(r, flags, r->pool);
+    mc->sesscache->status(mc->sesscache_context, r, flags, r->pool);
 
     ap_rputs("</td></tr>\n", r);
     ap_rputs("</table>\n", r);

Modified: httpd/httpd/trunk/modules/ssl/ssl_scache_dbm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_scache_dbm.c?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_scache_dbm.c (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_scache_dbm.c Fri Feb 22 13:09:40 2008
@@ -26,12 +26,12 @@
 
 #include "ssl_private.h"
 
-static void ssl_scache_dbm_expire(server_rec *s);
+static void ssl_scache_dbm_expire(void *context, server_rec *s);
 
-static void ssl_scache_dbm_remove(server_rec *s, UCHAR *id, int idlen,
+static void ssl_scache_dbm_remove(void *context, server_rec *s, UCHAR *id, int idlen,
                                   apr_pool_t *p);
 
-static void ssl_scache_dbm_init(server_rec *s, apr_pool_t *p)
+static apr_status_t ssl_scache_dbm_init(server_rec *s, void **context, apr_pool_t *p)
 {
     SSLModConfigRec *mc = myModConfig(s);
     apr_dbm_t *dbm;
@@ -41,7 +41,7 @@
     if (mc->szSessionCacheDataFile == NULL) {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                      "SSLSessionCache required");
-        ssl_die();
+        return APR_EINVAL;
     }
 
     /* open it once to create it and to make sure it _can_ be created */
@@ -52,7 +52,7 @@
                      "Cannot create SSLSessionCache DBM file `%s'",
                      mc->szSessionCacheDataFile);
         ssl_mutex_off(s);
-        return;
+        return rv;
     }
     apr_dbm_close(dbm);
 
@@ -81,11 +81,12 @@
     }
 #endif
     ssl_mutex_off(s);
-    ssl_scache_dbm_expire(s);
-    return;
+    ssl_scache_dbm_expire(context, s);
+
+    return APR_SUCCESS;
 }
 
-static void ssl_scache_dbm_kill(server_rec *s)
+static void ssl_scache_dbm_kill(void *context, server_rec *s)
 {
     SSLModConfigRec *mc = myModConfig(s);
     apr_pool_t *p;
@@ -105,7 +106,7 @@
     return;
 }
 
-static BOOL ssl_scache_dbm_store(server_rec *s, UCHAR *id, int idlen,
+static BOOL ssl_scache_dbm_store(void *context, server_rec *s, UCHAR *id, int idlen,
                                  time_t expiry, 
                                  unsigned char *ucaData, unsigned int nData)
 {
@@ -183,12 +184,12 @@
     free(dbmval.dptr);
 
     /* allow the regular expiring to occur */
-    ssl_scache_dbm_expire(s);
+    ssl_scache_dbm_expire(context, s);
 
     return TRUE;
 }
 
-static BOOL ssl_scache_dbm_retrieve(server_rec *s, const UCHAR *id, int idlen,
+static BOOL ssl_scache_dbm_retrieve(void *context, server_rec *s, const UCHAR *id, int idlen,
                                     unsigned char *dest, unsigned int *destlen,
                                     apr_pool_t *p)
 {
@@ -202,7 +203,7 @@
     apr_status_t rc;
 
     /* allow the regular expiring to occur */
-    ssl_scache_dbm_expire(s);
+    ssl_scache_dbm_expire(context, s);
 
     /* create DBM key and values */
     dbmkey.dptr  = (char *)id;
@@ -251,14 +252,14 @@
     /* make sure the stuff is still not expired */
     now = time(NULL);
     if (expiry <= now) {
-        ssl_scache_dbm_remove(s, (UCHAR *)id, idlen, p);
+        ssl_scache_dbm_remove(context, s, (UCHAR *)id, idlen, p);
         return FALSE;
     }
 
     return TRUE;
 }
 
-static void ssl_scache_dbm_remove(server_rec *s, UCHAR *id, int idlen,
+static void ssl_scache_dbm_remove(void *context, server_rec *s, UCHAR *id, int idlen,
                                   apr_pool_t *p)
 {
     SSLModConfigRec *mc = myModConfig(s);
@@ -288,7 +289,7 @@
     return;
 }
 
-static void ssl_scache_dbm_expire(server_rec *s)
+static void ssl_scache_dbm_expire(void *context, server_rec *s)
 {
     SSLModConfigRec *mc = myModConfig(s);
     SSLSrvConfigRec *sc = mySrvConfig(s);
@@ -407,7 +408,8 @@
     return;
 }
 
-static void ssl_scache_dbm_status(request_rec *r, int flags, apr_pool_t *p)
+static void ssl_scache_dbm_status(void *context, request_rec *r, 
+                                  int flags, apr_pool_t *p)
 {
     SSLModConfigRec *mc = myModConfig(r->server);
     apr_dbm_t *dbm;

Modified: httpd/httpd/trunk/modules/ssl/ssl_scache_dc.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_scache_dc.c?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_scache_dc.c (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_scache_dc.c Fri Feb 22 13:09:40 2008
@@ -48,16 +48,22 @@
 **
 */
 
-static void ssl_scache_dc_init(server_rec *s, apr_pool_t *p)
+struct context {
+    DC_CTX *dc;
+};
+
+static apr_status_t ssl_scache_dc_init(server_rec *s, void **context, apr_pool_t *p)
 {
-    DC_CTX *ctx;
+    DC_CTX *dc;
     SSLModConfigRec *mc = myModConfig(s);
+    struct context *ctx;
+
     /*
      * Create a session context
      */
     if (mc->szSessionCacheDataFile == NULL) {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "SSLSessionCache required");
-        ssl_die();
+        return APR_EINVAL;
     }
 #if 0
     /* If a "persistent connection" mode of operation is preferred, you *must*
@@ -75,39 +81,41 @@
      * performance/stability danger of file-descriptor bloatage. */
 #define SESSION_CTX_FLAGS        0
 #endif
-    ctx = DC_CTX_new(mc->szSessionCacheDataFile, SESSION_CTX_FLAGS);
-    if (!ctx) {
+    dc = DC_CTX_new(mc->szSessionCacheDataFile, SESSION_CTX_FLAGS);
+    if (!dc) {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache failed to obtain context");
-        ssl_die();
+        return APR_EGENERAL;
     }
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "distributed scache context initialised");
     /*
      * Success ...
      */
-    mc->tSessionCacheDataTable = ctx;
-    return;
+    ctx = *context = apr_palloc(p, sizeof *ctx);
+    ctx->dc = dc;
+
+    return APR_SUCCESS;
 }
 
-static void ssl_scache_dc_kill(server_rec *s)
+static void ssl_scache_dc_kill(void *context, server_rec *s)
 {
-    SSLModConfigRec *mc = myModConfig(s);
+    struct context *ctx = context;
 
-    if (mc->tSessionCacheDataTable)
-        DC_CTX_free(mc->tSessionCacheDataTable);
-    mc->tSessionCacheDataTable = NULL;
+    if (ctx && ctx->dc) {
+        DC_CTX_free(ctx->dc);
+        ctx->dc = NULL;
+    }
 }
 
-static BOOL ssl_scache_dc_store(server_rec *s, UCHAR *id, int idlen,
+static BOOL ssl_scache_dc_store(void *context, server_rec *s, UCHAR *id, int idlen,
                                 time_t timeout,
                                 unsigned char *der, unsigned int der_len)
 {
-    SSLModConfigRec *mc = myModConfig(s);
-    DC_CTX *ctx = mc->tSessionCacheDataTable;
+    struct context *ctx = context;
 
     /* !@#$%^ - why do we deal with *absolute* time anyway??? */
     timeout -= time(NULL);
     /* Send the serialised session to the distributed cache context */
-    if (!DC_CTX_add_session(ctx, id, idlen, der, der_len,
+    if (!DC_CTX_add_session(ctx->dc, id, idlen, der, der_len,
                             (unsigned long)timeout * 1000)) {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'add_session' failed");
         return FALSE;
@@ -116,16 +124,16 @@
     return TRUE;
 }
 
-static BOOL ssl_scache_dc_retrieve(server_rec *s, const UCHAR *id, int idlen,
+static BOOL ssl_scache_dc_retrieve(void *context,
+                                   server_rec *s, const UCHAR *id, int idlen,
                                    unsigned char *dest, unsigned int *destlen,
                                    apr_pool_t *p)
 {
     unsigned int data_len;
-    SSLModConfigRec *mc = myModConfig(s);
-    DC_CTX *ctx = mc->tSessionCacheDataTable;
+    struct context *ctx = context;
 
     /* Retrieve any corresponding session from the distributed cache context */
-    if (!DC_CTX_get_session(ctx, id, idlen, dest, *destlen, &data_len)) {
+    if (!DC_CTX_get_session(ctx->dc, id, idlen, dest, *destlen, &data_len)) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'get_session' MISS");
         return FALSE;
     }
@@ -137,20 +145,20 @@
     return TRUE;
 }
 
-static void ssl_scache_dc_remove(server_rec *s, UCHAR *id, int idlen, apr_pool_t *p)
+static void ssl_scache_dc_remove(void *context, server_rec *s, 
+                                 UCHAR *id, int idlen, apr_pool_t *p)
 {
-    SSLModConfigRec *mc = myModConfig(s);
-    DC_CTX *ctx = mc->tSessionCacheDataTable;
+    struct context *ctx = context;
 
     /* Remove any corresponding session from the distributed cache context */
-    if (!DC_CTX_remove_session(ctx, 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");
     } else {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' HIT");
     }
 }
 
-static void ssl_scache_dc_status(request_rec *r, int flags, apr_pool_t *pool)
+static void ssl_scache_dc_status(void *context, request_rec *r, int flags, apr_pool_t *pool)
 {
     SSLModConfigRec *mc = myModConfig(r->server);
 

Modified: httpd/httpd/trunk/modules/ssl/ssl_scache_memcache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_scache_memcache.c?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_scache_memcache.c (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_scache_memcache.c Fri Feb 22 13:09:40 2008
@@ -44,8 +44,6 @@
 
 
 /* The underlying apr_memcache system is thread safe.. */
-static apr_memcache_t *memctxt;
-
 #define MC_TAG "mod_ssl:"
 #define MC_TAG_LEN \
     (sizeof(MC_TAG))
@@ -69,8 +67,11 @@
 #define MC_DEFAULT_SERVER_TTL 600
 #endif
 
+struct context {
+    apr_memcache_t *mc;
+};
 
-static void ssl_scache_mc_init(server_rec *s, apr_pool_t *p)
+static apr_status_t ssl_scache_mc_init(server_rec *s, void **context, apr_pool_t *p)
 {
     apr_status_t rv;
     int thread_limit = 0;
@@ -79,12 +80,13 @@
     char *split;
     char *tok;
     SSLModConfigRec *mc = myModConfig(s);
+    struct context *ctx = apr_palloc(p, sizeof *ctx);
 
     ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
 
     if (mc->szSessionCacheDataFile == NULL) {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "SSLSessionCache required");
-        ssl_die();
+        return APR_EINVAL;
     }
 
     /* Find all the servers in the first run to get a total count */
@@ -95,12 +97,12 @@
         split = apr_strtok(NULL,",", &tok);
     }
 
-    rv = apr_memcache_create(p, nservers, 0, &memctxt);
+    rv = apr_memcache_create(p, nservers, 0, &ctx->mc);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                      "SSLSessionCache: Failed to create Memcache Object of '%d' size.", 
                      nservers);
-        ssl_die();
+        return rv;
     }
 
     /* Now add each server to the memcache */
@@ -116,14 +118,14 @@
         if (rv != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                          "SSLSessionCache: Failed to Parse Server: '%s'", split);
-            ssl_die();
+            return rv;
         }
 
         if (host_str == NULL) {
             ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                          "SSLSessionCache: Failed to Parse Server, "
                          "no hostname specified: '%s'", split);
-            ssl_die();
+            return APR_EINVAL;
         }
 
         if (port == 0) {
@@ -141,26 +143,28 @@
             ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                          "SSLSessionCache: Failed to Create Server: %s:%d", 
                          host_str, port);
-            ssl_die();
+            return rv;
         }
 
-        rv = apr_memcache_add_server(memctxt, st);
+        rv = apr_memcache_add_server(ctx->mc, st);
         if (rv != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                          "SSLSessionCache: Failed to Add Server: %s:%d", 
                          host_str, port);
-            ssl_die();
+            return rv;
         }
 
         split = apr_strtok(NULL,",", &tok);
     }
 
-    return;
+    *context = ctx;
+
+    return APR_SUCCESS;
 }
 
-static void ssl_scache_mc_kill(server_rec *s)
+static void ssl_scache_mc_kill(void *context, server_rec *s)
 {
-
+    /* noop. */
 }
 
 static char *mc_session_id2sz(const unsigned char *id, int idlen,
@@ -181,10 +185,12 @@
     return str;
 }
 
-static BOOL ssl_scache_mc_store(server_rec *s, UCHAR *id, int idlen,
+static BOOL ssl_scache_mc_store(void *context, server_rec *s, 
+                                UCHAR *id, 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;
@@ -195,7 +201,7 @@
         return FALSE;
     }
 
-    rv = apr_memcache_set(memctxt, strkey, (char*)ucaData, nData, timeout, 0);
+    rv = apr_memcache_set(ctx->mc, strkey, (char*)ucaData, nData, timeout, 0);
 
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
@@ -207,13 +213,15 @@
     return TRUE;
 }
 
-static BOOL ssl_scache_mc_retrieve(server_rec *s, const UCHAR *id, int idlen,
+static BOOL ssl_scache_mc_retrieve(void *context, server_rec *s, 
+                                   const UCHAR *id, 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;
+    char *strkey = NULL;
     apr_status_t rv;
 
     strkey = mc_session_id2sz(id, idlen, buf, sizeof(buf));
@@ -227,7 +235,7 @@
     /* ### this could do with a subpool, but _getp looks like it will
      * eat memory like it's going out of fashion anyway. */
 
-    rv = apr_memcache_getp(memctxt, p, strkey,
+    rv = apr_memcache_getp(ctx->mc, p, strkey,
                            &der, &der_len, NULL);
     if (rv) {
         if (rv != APR_NOTFOUND) {
@@ -248,8 +256,9 @@
     return TRUE;
 }
 
-static void ssl_scache_mc_remove(server_rec *s, UCHAR *id, int idlen, apr_pool_t *p)
+static void ssl_scache_mc_remove(void *context, server_rec *s, UCHAR *id, int idlen, apr_pool_t
*p)
 {
+    struct context *ctx = context;
     char buf[MC_KEY_LEN];
     char* strkey = NULL;
     apr_status_t rv;
@@ -260,7 +269,7 @@
         return;
     }
 
-    rv = apr_memcache_delete(memctxt, strkey, 0);
+    rv = apr_memcache_delete(ctx->mc, strkey, 0);
 
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s,
@@ -270,7 +279,8 @@
     }
 }
 
-static void ssl_scache_mc_status(request_rec *r, int flags, apr_pool_t *pool)
+static void ssl_scache_mc_status(void *context, request_rec *r, 
+                                 int flags, apr_pool_t *pool)
 {
     /* SSLModConfigRec *mc = myModConfig(r->server); */
     /* TODO: Make a mod_status handler. meh. */

Modified: httpd/httpd/trunk/modules/ssl/ssl_scache_shmcb.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_scache_shmcb.c?rev=630323&r1=630322&r2=630323&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ssl/ssl_scache_shmcb.c (original)
+++ httpd/httpd/trunk/modules/ssl/ssl_scache_shmcb.c Fri Feb 22 13:09:40 2008
@@ -86,6 +86,10 @@
     unsigned char removed;
 } SHMCBIndex;
 
+struct context {
+    apr_shm_t *shm;
+    SHMCBHeader *header;
+};
 
 /* The SHM data segment is of fixed size and stores data as follows.
  *
@@ -203,8 +207,8 @@
 }
 
 /* A memcmp against a cyclic data buffer.  Compares SRC of length
- * SRC_LEN data which begins at offset DEST_OFFSET in cyclic buffer
- * DATA which is of size BUF_SIZE.  Got that?  Good. */
+ * SRC_LEN against the contents of cyclic buffer DATA (which is of
+ * size BUF_SIZE), starting at offset DEST_OFFSET. Got that?  Good. */
 static int shmcb_cyclic_memcmp(unsigned int buf_size, unsigned char *data,
                                unsigned int dest_offset, 
                                const unsigned char *src,
@@ -246,7 +250,8 @@
  * subcache internals are deferred to shmcb_subcache_*** functions lower down
  */
 
-static void ssl_scache_shmcb_init(server_rec *s, apr_pool_t *p)
+static apr_status_t ssl_scache_shmcb_init(server_rec *s, void **context,
+                                          apr_pool_t *p)
 {
     SSLModConfigRec *mc = myModConfig(s);
     void *shm_segment;
@@ -254,36 +259,30 @@
     apr_status_t rv;
     SHMCBHeader *header;
     unsigned int num_subcache, num_idx, loop;
+    struct context *ctx;
 
-    {
-        void *data;
-        const char *userdata_key = "ssl_scache_init";
-
-        apr_pool_userdata_get(&data, userdata_key, s->process->pool);
-        if (!data) {
-            apr_pool_userdata_set((const void *)1, userdata_key,
-                                  apr_pool_cleanup_null, s->process->pool);
-            return;
-        }
-    }
+    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+                 "POOL %p %p", mc->pPool, p);
+
+    /* Allocate the context. */
+    *context = ctx = apr_pcalloc(p, sizeof *ctx);
 
     /* Create shared memory segment */
     if (mc->szSessionCacheDataFile == NULL) {
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                      "SSLSessionCache required");
-        ssl_die();
+        return APR_EINVAL;
     }
 
     /* Use anonymous shm by default, fall back on name-based. */
-    rv = apr_shm_create(&(mc->pSessionCacheDataMM), 
-                        mc->nSessionCacheDataSize, 
+    rv = apr_shm_create(&ctx->shm, mc->nSessionCacheDataSize, 
                         NULL, mc->pPool);
     if (APR_STATUS_IS_ENOTIMPL(rv)) {
         /* For a name-based segment, remove it first in case of a
          * previous unclean shutdown. */
         apr_shm_remove(mc->szSessionCacheDataFile, mc->pPool);
 
-        rv = apr_shm_create(&(mc->pSessionCacheDataMM),
+        rv = apr_shm_create(&ctx->shm,
                             mc->nSessionCacheDataSize,
                             mc->szSessionCacheDataFile,
                             mc->pPool);
@@ -293,16 +292,16 @@
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                      "could not allocate shared memory for shmcb "
                      "session cache");
-        ssl_die();
+        return rv;
     }
 
-    shm_segment = apr_shm_baseaddr_get(mc->pSessionCacheDataMM);
-    shm_segsize = apr_shm_size_get(mc->pSessionCacheDataMM);
+    shm_segment = apr_shm_baseaddr_get(ctx->shm);
+    shm_segsize = apr_shm_size_get(ctx->shm);
     if (shm_segsize < (5 * sizeof(SHMCBHeader))) {
         /* the segment is ridiculously small, bail out */
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                      "shared memory segment too small");
-        ssl_die();
+        return APR_ENOSPC;
     }
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                  "shmcb_init allocated %" APR_SIZE_T_FMT
@@ -333,10 +332,10 @@
         /* we're still too small, bail out */
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                      "shared memory segment too small");
-        ssl_die();
+        return APR_ENOSPC;
     }
     /* OK, we're sorted */
-    header = shm_segment;
+    ctx->header = header = shm_segment;
     header->stat_stores = 0;
     header->stat_expiries = 0;
     header->stat_scrolled = 0;
@@ -379,28 +378,29 @@
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,
                  "Shared memory session cache initialised");
     /* Success ... */
-    mc->tSessionCacheDataTable = shm_segment;
+
+    return APR_SUCCESS;
 }
 
-static void ssl_scache_shmcb_kill(server_rec *s)
+static void ssl_scache_shmcb_kill(void *context, server_rec *s)
 {
-    SSLModConfigRec *mc = myModConfig(s);
+    struct context *ctx = context;
 
-    if (mc->pSessionCacheDataMM != NULL) {
-        apr_shm_destroy(mc->pSessionCacheDataMM);
-        mc->pSessionCacheDataMM = NULL;
+    if (ctx && ctx->shm) {
+        apr_shm_destroy(ctx->shm);
+        ctx->shm = NULL;
     }
-    return;
 }
 
-static BOOL ssl_scache_shmcb_store(server_rec *s, UCHAR *id, int idlen,
+static BOOL ssl_scache_shmcb_store(void *context, server_rec *s, 
+                                   UCHAR *id, int idlen,
                                    time_t timeout, 
                                    unsigned char *encoded,
                                    unsigned int len_encoded)
 {
-    SSLModConfigRec *mc = myModConfig(s);
     BOOL to_return = FALSE;
-    SHMCBHeader *header = mc->tSessionCacheDataTable;
+    struct context *ctx = context;
+    SHMCBHeader *header = ctx->header;
     SHMCBSubcache *subcache = SHMCB_MASK(header, id);
 
     ssl_mutex_on(s);
@@ -427,13 +427,13 @@
     return to_return;
 }
 
-static BOOL ssl_scache_shmcb_retrieve(server_rec *s, 
+static BOOL ssl_scache_shmcb_retrieve(void *context, server_rec *s, 
                                       const UCHAR *id, int idlen,
                                       unsigned char *dest, unsigned int *destlen,
                                       apr_pool_t *p)
 {
-    SSLModConfigRec *mc = myModConfig(s);
-    SHMCBHeader *header = mc->tSessionCacheDataTable;
+    struct context *ctx = context;
+    SHMCBHeader *header = ctx->header;
     SHMCBSubcache *subcache = SHMCB_MASK(header, id);
     BOOL rv;
 
@@ -457,10 +457,11 @@
     return rv;
 }
 
-static void ssl_scache_shmcb_remove(server_rec *s, UCHAR *id, int idlen, apr_pool_t *p)
+static void ssl_scache_shmcb_remove(void *context, server_rec *s, 
+                                    UCHAR *id, int idlen, apr_pool_t *p)
 {
-    SSLModConfigRec *mc = myModConfig(s);
-    SHMCBHeader *header = mc->tSessionCacheDataTable;
+    struct context *ctx = context;
+    SHMCBHeader *header = ctx->header;
     SHMCBSubcache *subcache = SHMCB_MASK(header, id);
 
     ssl_mutex_on(s);
@@ -482,12 +483,13 @@
     ssl_mutex_off(s);
 }
 
-static void ssl_scache_shmcb_status(request_rec *r, int flags, apr_pool_t *p)
+static void ssl_scache_shmcb_status(void *context, request_rec *r, 
+                                    int flags, apr_pool_t *p)
 {
     server_rec *s = r->server;
     SSLModConfigRec *mc = myModConfig(s);
-    void *shm_segment = apr_shm_baseaddr_get(mc->pSessionCacheDataMM);
-    SHMCBHeader *header = shm_segment;
+    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;
     time_t now = time(NULL);



Mime
View raw message