Hi,

I sent few weeks ago a patch for util_ldap shm cache which is broken in apache 2.0
The problem are:


shm file is unique for all httpd
-> i created a directive to specify a filename - creating default if not.

shm is initialized in child init hook
-> i move this to post_init hook

shm, rmm pointer are global and defined in util_ldap_cache.c
-> i created st->util_ldap_shm and st->util_ldap_rmm which are per root server address


All allocation or free with rmm are using global address
-> i made them using st->util_ldap_shm and rmm

The first patch i sent was my debug code, this one is cleaned and working with me in worker and prefork mpm
I would like to know if there is a reason that util_ldap.h is in include/ and all util_ldap code is in modules/experimental


Regards,

Matthieu


? patch-util_ldap.diff
Index: include/util_ldap.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/include/util_ldap.h,v
retrieving revision 1.11
diff -u -r1.11 util_ldap.h
--- include/util_ldap.h 14 Feb 2003 16:04:00 -0000      1.11
+++ include/util_ldap.h 1 Jul 2003 12:48:16 -0000
@@ -65,6 +65,8 @@
 #include <apr_thread_rwlock.h>
 #include <apr_tables.h>
 #include <apr_time.h>
+#include <apr_shm.h>
+#include <apr_rmm.h>
 
 /* Apache header files */
 #include "ap_config.h"
@@ -140,6 +142,16 @@
     apr_thread_mutex_t *mutex;          /* mutex lock for the connection list */
 #endif
 
+/* LDAP shm */
+#if APR_HAS_SHARED_MEMORY
+    const char *shm_file;
+    apr_shm_t *util_ldap_shm;
+    apr_rmm_t *util_ldap_rmm;
+#endif
+
+    /* LDAP cache */      
+    void *ldap_cache;
+    
     apr_size_t cache_bytes;     /* Size (in bytes) of shared memory cache */
     long search_cache_ttl;      /* TTL for search cache */
     long search_cache_size;     /* Size (in entries) of search cache */
@@ -291,7 +303,7 @@
  *         apr_smmem_init() call. Regardless of the status, the cache
  *         will be set up at least for in-process or in-thread operation.
  */
-apr_status_t util_ldap_cache_init(apr_pool_t *pool, apr_size_t reqsize);
+apr_status_t util_ldap_cache_init(void *data);
 
 /**
  * Display formatted stats for cache
@@ -300,7 +312,7 @@
  *      various stats about the cache.
  * @deffunc char *util_ald_cache_display(apr_pool_t *pool)
  */
-char *util_ald_cache_display(apr_pool_t *pool);
+char *util_ald_cache_display(apr_pool_t *pool, void *ldap_cache);
 
 
 /* from apr_ldap_cache_mgr.c */
@@ -312,7 +324,7 @@
  *      various stats about the cache.
  * @deffunc char *util_ald_cache_display(apr_pool_t *pool)
  */
-char *util_ald_cache_display(apr_pool_t *pool);
+char *util_ald_cache_display(apr_pool_t *pool, void *ldap_cache);
 
 #endif /* APU_HAS_LDAP */
 #endif /* UTIL_LDAP_H */
Index: modules/experimental/util_ldap.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/experimental/util_ldap.c,v
retrieving revision 1.14
diff -u -r1.14 util_ldap.c
--- modules/experimental/util_ldap.c    4 Apr 2003 13:47:13 -0000       1.14
+++ modules/experimental/util_ldap.c    1 Jul 2003 12:48:17 -0000
@@ -141,6 +141,8 @@
  */
 int util_ldap_handler(request_rec *r)
 {
+    util_ldap_state_t *st = (util_ldap_state_t *)ap_get_module_config(
+                               r->server->module_config, &ldap_module);
 
     r->allowed |= (1 << M_GET);
     if (r->method_number != M_GET)
@@ -171,7 +173,7 @@
              "</tr>\n", r
             );
 
-    ap_rputs(util_ald_cache_display(r->pool), r);
+    ap_rputs(util_ald_cache_display(r->pool, st->ldap_cache), r);
 
     ap_rputs("</table>\n</p>\n", r);
 
@@ -517,7 +519,7 @@
     LDAP_CACHE_WRLOCK();
 
     curnode.url = url;
-    curl = util_ald_cache_fetch(util_ldap_cache, &curnode);
+    curl = util_ald_cache_fetch(st->ldap_cache, &curnode);
     if (curl == NULL) {
         curl = util_ald_create_caches(st, url);
     }
@@ -596,7 +598,7 @@
             LDAP_CACHE_RDLOCK();
             newnode.reqdn = (char *)reqdn;
             newnode.dn = (char *)dn;
-            util_ald_cache_insert(curl->dn_compare_cache, &newnode);
+            util_ald_cache_insert(st, curl->dn_compare_cache, &newnode);
             LDAP_CACHE_UNLOCK();
         }
         ldc->reason = "DN Comparison TRUE (checked on server)";
@@ -637,7 +639,7 @@
     /* get cache entry (or create one) */
     LDAP_CACHE_WRLOCK();
     curnode.url = url;
-    curl = util_ald_cache_fetch(util_ldap_cache, &curnode);
+    curl = util_ald_cache_fetch(st->ldap_cache, &curnode);
     if (curl == NULL) {
         curl = util_ald_create_caches(st, url);
     }
@@ -659,7 +661,7 @@
             /* found it... */
             if (curtime - compare_nodep->lastcompare > st->compare_cache_ttl) {
                 /* ...but it is too old */
-                util_ald_cache_remove(curl->compare_cache, compare_nodep);
+                util_ald_cache_remove(st, curl->compare_cache, compare_nodep);
             }
             else {
                 /* ...and it is good */
@@ -714,7 +716,7 @@
             LDAP_CACHE_WRLOCK();
             the_compare_node.lastcompare = curtime;
             the_compare_node.result = result;
-            util_ald_cache_insert(curl->compare_cache, &the_compare_node);
+            util_ald_cache_insert(st, curl->compare_cache, &the_compare_node);
             LDAP_CACHE_UNLOCK();
         }
         if (LDAP_COMPARE_TRUE == result) {
@@ -760,7 +762,7 @@
     /* Get the cache node for this url */
     LDAP_CACHE_WRLOCK();
     curnode.url = url;
-    curl = (util_url_node_t *)util_ald_cache_fetch(util_ldap_cache, &curnode);
+    curl = (util_url_node_t *)util_ald_cache_fetch(st->ldap_cache, &curnode);
     if (curl == NULL) {
         curl = util_ald_create_caches(st, url);
     }
@@ -781,11 +783,11 @@
              */
             if ((curtime - search_nodep->lastbind) > st->search_cache_ttl) {
                 /* ...but entry is too old */
-                util_ald_cache_remove(curl->search_cache, search_nodep);
+                util_ald_cache_remove(st, curl->search_cache, search_nodep);
             }
             else if (strcmp(search_nodep->bindpw, bindpw) != 0) {
            /* ...but cached password doesn't match sent password */
-                util_ald_cache_remove(curl->search_cache, search_nodep);
+                util_ald_cache_remove(st, curl->search_cache, search_nodep);
             }
             else {
                 /* ...and entry is valid */
@@ -920,7 +922,7 @@
     the_search_node.lastbind = apr_time_now();
     the_search_node.vals = vals;
     if (curl) {
-        util_ald_cache_insert(curl->search_cache, &the_search_node);
+        util_ald_cache_insert(st, curl->search_cache, &the_search_node);
     }
     ldap_msgfree(res);
     LDAP_CACHE_UNLOCK();
@@ -1044,6 +1046,20 @@
     return(NULL);
 }
 
+static const char *util_ldap_set_shm_file(cmd_parms *cmd, void *dummy, const char 
*file)
+{
+    util_ldap_state_t *st = 
+        (util_ldap_state_t *)ap_get_module_config(cmd->server->module_config, 
+                                                 &ldap_module);
+
+    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, cmd->server, 
+                      "LDAP: Shm Session Cache file - %s", 
+                       file);
+
+    st->shm_file = apr_pstrdup(cmd->pool, file);
+
+    return(NULL);
+}
 
 const char *util_ldap_set_cert_type(cmd_parms *cmd, void *dummy, const char *Type)
 {
@@ -1091,22 +1107,6 @@
     return st;
 }
 
-static void util_ldap_init_module(apr_pool_t *pool, server_rec *s)
-{
-    util_ldap_state_t *st = 
-        (util_ldap_state_t *)ap_get_module_config(s->module_config, 
-                                                 &ldap_module);
-
-    apr_status_t result = util_ldap_cache_init(pool, st->cache_bytes);
-    char buf[MAX_STRING_LEN];
-
-    apr_strerror(result, buf, sizeof(buf));
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, result, s, 
-                      "[%d] ldap cache init: %s", 
-                      getpid(), buf);
-}
-
-
 static apr_status_t util_ldap_cleanup_module(void *data)
 {
     server_rec *s = data;
@@ -1128,11 +1128,15 @@
                                  apr_pool_t *ptemp, server_rec *s)
 {
     int rc = LDAP_SUCCESS;
-
+    
+    apr_status_t result;
+    char buf[MAX_STRING_LEN];
+    
     util_ldap_state_t *st = (util_ldap_state_t *)ap_get_module_config(
                                                 s->module_config, 
                                                 &ldap_module);
 
+
         /* log the LDAP SDK used 
         */
     #if APR_HAS_NETSCAPE_LDAPSDK 
@@ -1161,8 +1165,20 @@
 
     #endif /* APR_HAS_NETSCAPE_LDAPSDK */
 
+    /* initializing cache
+    */
+    if (!st->util_ldap_shm) {
+           result = util_ldap_cache_init(st);
+           ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, result, s, "LDAP: 
using file: %s for shm cache", st->shm_file);
+    
+           apr_strerror(result, buf, sizeof(buf));
+           ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, result, s, 
+                             "[%d] ldap cache init: %s", 
+                             getpid(), buf);
+    }
 
-
+    /* register cleanup
+    */
     apr_pool_cleanup_register(p, s, util_ldap_cleanup_module,
                               util_ldap_cleanup_module); 
 
@@ -1325,13 +1341,16 @@
                  "    DER_FILE      - file in binary DER format "
                  "    BASE64_FILE   - file in Base64 format "
                  "    CERT7_DB_PATH - Netscape certificate database file "),
+
+    AP_INIT_TAKE1("LDAPShmCacheFile", util_ldap_set_shm_file, NULL, RSRC_CONF,
+                 "Set the file used by shared memory for LDAP cache"),
+
     {NULL}
 };
 
 static void util_ldap_register_hooks(apr_pool_t *p)
 {
     ap_hook_post_config(util_ldap_post_config,NULL,NULL,APR_HOOK_MIDDLE);
-    ap_hook_child_init(util_ldap_init_module, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_handler(util_ldap_handler, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
Index: modules/experimental/util_ldap_cache.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/experimental/util_ldap_cache.c,v
retrieving revision 1.8
diff -u -r1.8 util_ldap_cache.c
--- modules/experimental/util_ldap_cache.c      21 Jan 2003 10:53:09 -0000      1.8
+++ modules/experimental/util_ldap_cache.c      1 Jul 2003 12:48:17 -0000
@@ -66,9 +66,6 @@
 
 #ifdef APU_HAS_LDAP
 
-#define MODLDAP_SHMEM_CACHE "/tmp/mod_ldap_cache"
-
-
 /* ------------------------------------------------------------------ */
 
 unsigned long util_ldap_url_node_hash(void *n)
@@ -85,14 +82,14 @@
     return(strcmp(na->url, nb->url) == 0);
 }
 
-void *util_ldap_url_node_copy(void *c)
+void *util_ldap_url_node_copy(util_ldap_state_t *st, void *c)
 {
     util_url_node_t *n = (util_url_node_t *)c;
-    util_url_node_t *node = (util_url_node_t 
*)util_ald_alloc(sizeof(util_url_node_t));
+    util_url_node_t *node = (util_url_node_t *)util_ald_alloc(st, 
sizeof(util_url_node_t));
 
     if (node) {
-        if (!(node->url = util_ald_strdup(n->url))) {
-            util_ald_free(node->url);
+        if (!(node->url = util_ald_strdup(st, n->url))) {
+            util_ald_free(st, node->url);
             return NULL;
         }
         node->search_cache = n->search_cache;
@@ -105,15 +102,15 @@
     }
 }
 
-void util_ldap_url_node_free(void *n)
+void util_ldap_url_node_free(util_ldap_state_t *st, void *n)
 {
     util_url_node_t *node = (util_url_node_t *)n;
 
-    util_ald_free(node->url);
-    util_ald_destroy_cache(node->search_cache);
-    util_ald_destroy_cache(node->compare_cache);
-    util_ald_destroy_cache(node->dn_compare_cache);
-    util_ald_free(node);
+    util_ald_free(st, node->url);
+    util_ald_destroy_cache(st, node->search_cache);
+    util_ald_destroy_cache(st, node->compare_cache);
+    util_ald_destroy_cache(st, node->dn_compare_cache);
+    util_ald_free(st, node);
 }
 
 /* ------------------------------------------------------------------ */
@@ -131,10 +128,10 @@
                  ((util_search_node_t *)b)->username) == 0);
 }
 
-void *util_ldap_search_node_copy(void *c)
+void *util_ldap_search_node_copy(util_ldap_state_t *st, void *c)
 {
     util_search_node_t *node = (util_search_node_t *)c;
-    util_search_node_t *newnode = util_ald_alloc(sizeof(util_search_node_t));
+    util_search_node_t *newnode = util_ald_alloc(st, sizeof(util_search_node_t));
 
     /* safety check */
     if (newnode) {
@@ -144,13 +141,13 @@
             int k = 0;
             int i = 0;
             while (node->vals[k++]);
-            if (!(newnode->vals = util_ald_alloc(sizeof(char *) * (k+1)))) {
-                util_ldap_search_node_free(newnode);
+            if (!(newnode->vals = util_ald_alloc(st, sizeof(char *) * (k+1)))) {
+                util_ldap_search_node_free(st, newnode);
                 return NULL;
             }
             while (node->vals[i]) {
-                if (!(newnode->vals[i] = util_ald_strdup(node->vals[i]))) {
-                    util_ldap_search_node_free(newnode);
+                if (!(newnode->vals[i] = util_ald_strdup(st, node->vals[i]))) {
+                    util_ldap_search_node_free(st, newnode);
                     return NULL;
                 }
                 i++;
@@ -159,10 +156,10 @@
         else {
             newnode->vals = NULL;
         }
-        if (!(newnode->username = util_ald_strdup(node->username)) ||
-            !(newnode->dn = util_ald_strdup(node->dn)) ||
-            !(newnode->bindpw = util_ald_strdup(node->bindpw)) ) {
-            util_ldap_search_node_free(newnode);
+        if (!(newnode->username = util_ald_strdup(st, node->username)) ||
+            !(newnode->dn = util_ald_strdup(st, node->dn)) ||
+            !(newnode->bindpw = util_ald_strdup(st, node->bindpw)) ) {
+            util_ldap_search_node_free(st, newnode);
             return NULL;
         }
         newnode->lastbind = node->lastbind;
@@ -171,20 +168,20 @@
     return (void *)newnode;
 }
 
-void util_ldap_search_node_free(void *n)
+void util_ldap_search_node_free(util_ldap_state_t *st, void *n)
 {
     int i = 0;
     util_search_node_t *node = (util_search_node_t *)n;
     if (node->vals) {
         while (node->vals[i]) {
-            util_ald_free(node->vals[i++]);
+            util_ald_free(st, node->vals[i++]);
         }
-        util_ald_free(node->vals);
+        util_ald_free(st, node->vals);
     }
-    util_ald_free(node->username);
-    util_ald_free(node->dn);
-    util_ald_free(node->bindpw);
-    util_ald_free(node);
+    util_ald_free(st, node->username);
+    util_ald_free(st, node->dn);
+    util_ald_free(st, node->bindpw);
+    util_ald_free(st, node);
 }
 
 /* ------------------------------------------------------------------ */
@@ -204,16 +201,16 @@
            strcmp(na->value, nb->value) == 0);
 }
 
-void *util_ldap_compare_node_copy(void *c)
+void *util_ldap_compare_node_copy(util_ldap_state_t *st, void *c)
 {
     util_compare_node_t *n = (util_compare_node_t *)c;
-    util_compare_node_t *node = (util_compare_node_t 
*)util_ald_alloc(sizeof(util_compare_node_t));
+    util_compare_node_t *node = (util_compare_node_t *)util_ald_alloc(st, 
sizeof(util_compare_node_t));
 
     if (node) {
-        if (!(node->dn = util_ald_strdup(n->dn)) ||
-            !(node->attrib = util_ald_strdup(n->attrib)) ||
-            !(node->value = util_ald_strdup(n->value))) {
-            util_ldap_compare_node_free(node);
+        if (!(node->dn = util_ald_strdup(st, n->dn)) ||
+            !(node->attrib = util_ald_strdup(st, n->attrib)) ||
+            !(node->value = util_ald_strdup(st, n->value))) {
+            util_ldap_compare_node_free(st, node);
             return NULL;
         }
         node->lastcompare = n->lastcompare;
@@ -225,13 +222,13 @@
     }
 }
 
-void util_ldap_compare_node_free(void *n)
+void util_ldap_compare_node_free(util_ldap_state_t *st, void *n)
 {
     util_compare_node_t *node = (util_compare_node_t *)n;
-    util_ald_free(node->dn);
-    util_ald_free(node->attrib);
-    util_ald_free(node->value);
-    util_ald_free(node);
+    util_ald_free(st, node->dn);
+    util_ald_free(st, node->attrib);
+    util_ald_free(st, node->value);
+    util_ald_free(st, node);
 }
 
 /* ------------------------------------------------------------------ */
@@ -247,14 +244,14 @@
                   ((util_dn_compare_node_t *)b)->reqdn) == 0);
 }
 
-void *util_ldap_dn_compare_node_copy(void *c)
+void *util_ldap_dn_compare_node_copy(util_ldap_state_t *st, void *c)
 {
     util_dn_compare_node_t *n = (util_dn_compare_node_t *)c;
-    util_dn_compare_node_t *node = (util_dn_compare_node_t 
*)util_ald_alloc(sizeof(util_dn_compare_node_t));
+    util_dn_compare_node_t *node = (util_dn_compare_node_t *)util_ald_alloc(st, 
sizeof(util_dn_compare_node_t));
     if (node) {
-        if (!(node->reqdn = util_ald_strdup(n->reqdn)) ||
-            !(node->dn = util_ald_strdup(n->dn))) {
-            util_ldap_dn_compare_node_free(node);
+        if (!(node->reqdn = util_ald_strdup(st, n->reqdn)) ||
+            !(node->dn = util_ald_strdup(st, n->dn))) {
+            util_ldap_dn_compare_node_free(st, node);
             return NULL;
         }
         return node;
@@ -264,12 +261,12 @@
     }
 }
 
-void util_ldap_dn_compare_node_free(void *n)
+void util_ldap_dn_compare_node_free(util_ldap_state_t *st, void *n)
 {
     util_dn_compare_node_t *node = (util_dn_compare_node_t *)n;
-    util_ald_free(node->reqdn);
-    util_ald_free(node->dn);
-    util_ald_free(node);
+    util_ald_free(st, node->reqdn);
+    util_ald_free(st, node->dn);
+    util_ald_free(st, node);
 }
 
 
@@ -279,46 +276,65 @@
 
 apr_status_t util_ldap_cache_module_kill(void *data)
 {
+    util_ldap_state_t *st = (util_ldap_state_t *) data;
+
+    if (!st) {
+       return -1;
+    }    
+
 #if APR_HAS_SHARED_MEMORY
-    if (util_ldap_shm != NULL) {
-        apr_status_t result = apr_shm_destroy(util_ldap_shm);
-        util_ldap_shm = NULL;
+    if (st->util_ldap_shm != NULL) {
+        apr_status_t result = apr_shm_destroy(st->util_ldap_shm);
+        st->util_ldap_shm = NULL;
+        
+        /* Remove cache file */
+        unlink(st->shm_file);
         return result;
     }
 #endif
-    util_ald_destroy_cache(util_ldap_cache);
+    util_ald_destroy_cache(st, st->ldap_cache);
     return APR_SUCCESS;
 }
 
-apr_status_t util_ldap_cache_init(apr_pool_t *pool, apr_size_t reqsize)
+apr_status_t util_ldap_cache_init(void *data)
 {
+    util_ldap_state_t *st = (util_ldap_state_t *) data;
+
+    if (!st) {
+       return -1;
+    }
+
 #if APR_HAS_SHARED_MEMORY
     apr_status_t result;
+    char *filename = NULL;
+    
+    /* if no cache file specified - create default */
+    if (!st->shm_file) {
+           filename = (char *)apr_psprintf(st->pool, "logs/ldap_cache");
+    }      
+    
+    filename = st->shm_file;       
+    st->shm_file = ap_server_root_relative(st->pool, filename);
+
+    result = apr_shm_create(&(st->util_ldap_shm), st->cache_bytes, st->shm_file, 
st->pool);
 
-    result = apr_shm_create(&util_ldap_shm, reqsize, MODLDAP_SHMEM_CACHE, pool);
-    if (result == EEXIST) {
-        /*
-         * The cache could have already been created (i.e. we may be a child 
process).  See
-         * if we can attach to the existing shared memory
-         */
-        result = apr_shm_attach(&util_ldap_shm, MODLDAP_SHMEM_CACHE, pool);
-    } 
     if (result != APR_SUCCESS) {
         return result;
     }
 
     /* This will create a rmm "handler" to get into the shared memory area */
-    apr_rmm_init(&util_ldap_rmm, NULL,
-                       (void *)apr_shm_baseaddr_get(util_ldap_shm), reqsize, pool);
+    apr_rmm_init(&(st->util_ldap_rmm), NULL,
+                       (void *)apr_shm_baseaddr_get(st->util_ldap_shm), 
st->cache_bytes, st->pool);
 #endif
 
-    apr_pool_cleanup_register(pool, NULL, util_ldap_cache_module_kill, 
apr_pool_cleanup_null);
+    apr_pool_cleanup_register(st->pool, NULL, util_ldap_cache_module_kill, 
apr_pool_cleanup_null);
 
-    util_ldap_cache = util_ald_create_cache(50,
-                                    util_ldap_url_node_hash,
-                                    util_ldap_url_node_compare,
-                                    util_ldap_url_node_copy,
-                                    util_ldap_url_node_free);
+    st->ldap_cache = (util_ald_cache_t *) util_ald_create_cache(st,
+                                            50,
+                                            util_ldap_url_node_hash,
+                                            util_ldap_url_node_compare,
+                                            util_ldap_url_node_copy,
+                                            util_ldap_url_node_free);
     return APR_SUCCESS;
 }
 
Index: modules/experimental/util_ldap_cache.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/experimental/util_ldap_cache.h,v
retrieving revision 1.6
diff -u -r1.6 util_ldap_cache.h
--- modules/experimental/util_ldap_cache.h      21 Jan 2003 10:53:09 -0000      1.6
+++ modules/experimental/util_ldap_cache.h      1 Jul 2003 12:48:18 -0000
@@ -1,3 +1,4 @@
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -85,8 +86,8 @@
     apr_time_t marktime;       /* Time that the cache became 3/4 full */
     unsigned long (*hash)(void *);  /* Func to hash the payload */
     int (*compare)(void *, void *); /* Func to compare two payloads */
-    void * (*copy)(void *);    /* Func to alloc mem and copy payload to new mem */
-    void (*free)(void *);      /* Func to free mem used by the payload */
+    void * (*copy)(util_ldap_state_t *, void *);       /* Func to alloc mem and copy 
payload to new mem */
+    void (*free)(util_ldap_state_t *, void *); /* Func to free mem used by the 
payload */
     util_cache_node_t **nodes;
 
     unsigned long numpurges;   /* No. of times the cache has been purged */
@@ -102,12 +103,6 @@
     unsigned long removes;     /* Number of removes */
 } util_ald_cache_t;
 
-#if APR_HAS_SHARED_MEMORY
-apr_shm_t *util_ldap_shm;
-apr_rmm_t *util_ldap_rmm;
-#endif
-util_ald_cache_t *util_ldap_cache;
-
 #if APR_HAS_THREADS
 apr_thread_rwlock_t *util_ldap_cache_lock;
 #define LDAP_CACHE_LOCK_CREATE(p) \
@@ -192,39 +187,40 @@
 /* util_ldap_cache.c */
 unsigned long util_ldap_url_node_hash(void *n);
 int util_ldap_url_node_compare(void *a, void *b);
-void *util_ldap_url_node_copy(void *c);
-void util_ldap_url_node_free(void *n);
+void *util_ldap_url_node_copy(util_ldap_state_t *st, void *c);
+void util_ldap_url_node_free(util_ldap_state_t *st, void *n);
 unsigned long util_ldap_search_node_hash(void *n);
 int util_ldap_search_node_compare(void *a, void *b);
-void *util_ldap_search_node_copy(void *c);
-void util_ldap_search_node_free(void *n);
+void *util_ldap_search_node_copy(util_ldap_state_t *st, void *c);
+void util_ldap_search_node_free(util_ldap_state_t *st, void *n);
 unsigned long util_ldap_compare_node_hash(void *n);
 int util_ldap_compare_node_compare(void *a, void *b);
-void *util_ldap_compare_node_copy(void *c);
-void util_ldap_compare_node_free(void *n);
+void *util_ldap_compare_node_copy(util_ldap_state_t *st, void *c);
+void util_ldap_compare_node_free(util_ldap_state_t *st, void *n);
 unsigned long util_ldap_dn_compare_node_hash(void *n);
 int util_ldap_dn_compare_node_compare(void *a, void *b);
-void *util_ldap_dn_compare_node_copy(void *c);
-void util_ldap_dn_compare_node_free(void *n);
+void *util_ldap_dn_compare_node_copy(util_ldap_state_t *st, void *c);
+void util_ldap_dn_compare_node_free(util_ldap_state_t *st, void *n);
 
 
 /* util_ldap_cache_mgr.c */
 
-void util_ald_free(const void *ptr);
-void *util_ald_alloc(unsigned long size);
-const char *util_ald_strdup(const char *s);
+void util_ald_free(util_ldap_state_t *st, const void *ptr);
+void *util_ald_alloc(util_ldap_state_t *st, unsigned long size);
+const char *util_ald_strdup(util_ldap_state_t *st, const char *s);
 unsigned long util_ald_hash_string(int nstr, ...);
-void util_ald_cache_purge(util_ald_cache_t *cache);
+void util_ald_cache_purge(util_ldap_state_t *st);
 util_url_node_t *util_ald_create_caches(util_ldap_state_t *s, const char *url);
-util_ald_cache_t *util_ald_create_cache(unsigned long maxentries,
+util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
+                               unsigned long maxentries,
                                 unsigned long (*hashfunc)(void *), 
                                 int (*comparefunc)(void *, void *),
-                                void * (*copyfunc)(void *),
-                                void (*freefunc)(void *));
-void util_ald_destroy_cache(util_ald_cache_t *cache);
+                                void * (*copyfunc)(util_ldap_state_t *, void *),
+                                void (*freefunc)(util_ldap_state_t *, void *));
+void util_ald_destroy_cache(util_ldap_state_t *st, util_ald_cache_t *cache);
 void *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload);
-void util_ald_cache_insert(util_ald_cache_t *cache, void *payload);
-void util_ald_cache_remove(util_ald_cache_t *cache, void *payload);
+void util_ald_cache_insert(util_ldap_state_t *st, util_ald_cache_t *cache, void 
*payload);
+void util_ald_cache_remove(util_ldap_state_t *st, util_ald_cache_t *cache, void 
*payload);
 char *util_ald_cache_display_stats(apr_pool_t *p, util_ald_cache_t *cache,
                                  char *name);
 
Index: modules/experimental/util_ldap_cache_mgr.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/experimental/util_ldap_cache_mgr.c,v
retrieving revision 1.5
diff -u -r1.5 util_ldap_cache_mgr.c
--- modules/experimental/util_ldap_cache_mgr.c  21 Jan 2003 10:53:09 -0000      1.5
+++ modules/experimental/util_ldap_cache_mgr.c  1 Jul 2003 12:48:18 -0000
@@ -112,12 +112,12 @@
   0
 };
 
-void util_ald_free(const void *ptr)
+void util_ald_free(util_ldap_state_t *st, const void *ptr)
 {
 #if APR_HAS_SHARED_MEMORY
-    if (util_ldap_shm) {
+    if (st->util_ldap_shm) {
         if (ptr)
-            apr_rmm_free(util_ldap_rmm, apr_rmm_offset_get(util_ldap_rmm, (void 
*)ptr));
+            apr_rmm_free(st->util_ldap_rmm, apr_rmm_offset_get(st->util_ldap_rmm, 
(void *)ptr));
     } else {
         if (ptr)
             free((void *)ptr);
@@ -128,13 +128,13 @@
 #endif
 }
 
-void *util_ald_alloc(unsigned long size)
+void *util_ald_alloc(util_ldap_state_t *st, unsigned long size)
 {
     if (0 == size)
         return NULL;
 #if APR_HAS_SHARED_MEMORY
-    if (util_ldap_shm) {
-        return (void *)apr_rmm_addr_get(util_ldap_rmm, apr_rmm_calloc(util_ldap_rmm, 
size));
+    if (st->util_ldap_shm) {
+        return (void *)apr_rmm_addr_get(st->util_ldap_rmm, 
apr_rmm_calloc(st->util_ldap_rmm, size));
     } else {
         return (void *)calloc(sizeof(char), size);
     }
@@ -143,11 +143,11 @@
 #endif
 }
 
-const char *util_ald_strdup(const char *s)
+const char *util_ald_strdup(util_ldap_state_t *st, const char *s)
 {
 #if APR_HAS_SHARED_MEMORY
-    if (util_ldap_shm) {
-        char *buf = (char *)apr_rmm_addr_get(util_ldap_rmm, 
apr_rmm_calloc(util_ldap_rmm, strlen(s)+1));
+    if (st->util_ldap_shm) {
+        char *buf = (char *)apr_rmm_addr_get(st->util_ldap_rmm, 
apr_rmm_calloc(st->util_ldap_rmm, strlen(s)+1));
         if (buf) {
             strcpy(buf, s);
             return buf;
@@ -199,8 +199,9 @@
   that were added before that time. It's pretty simplistic, but time to
   purge is only O(n), which is more important.
 */
-void util_ald_cache_purge(util_ald_cache_t *cache)
+void util_ald_cache_purge(util_ldap_state_t *st)
 {
+    util_ald_cache_t *cache = (util_ald_cache_t *)st->ldap_cache;
     unsigned long i;
     util_cache_node_t *p, *q;
     apr_time_t t;
@@ -217,8 +218,8 @@
         while (p != NULL) {
             if (p->add_time < cache->marktime) {
                q = p->next;
-               (*cache->free)(p->payload);
-               util_ald_free(p);
+               (*cache->free)(st, p->payload);
+               util_ald_free(st, p);
                cache->numentries--;
                cache->npurged++;
                p = q;
@@ -247,17 +248,20 @@
     util_ald_cache_t *dn_compare_cache;
 
     /* create the three caches */
-    search_cache = util_ald_create_cache(st->search_cache_size,
+    search_cache = util_ald_create_cache(st,
+                                         st->search_cache_size,
                                          util_ldap_search_node_hash,
                                          util_ldap_search_node_compare,
                                          util_ldap_search_node_copy,
                                          util_ldap_search_node_free);
-    compare_cache = util_ald_create_cache(st->compare_cache_size,
+    compare_cache = util_ald_create_cache(st,
+                                          st->compare_cache_size,
                                           util_ldap_compare_node_hash,
                                           util_ldap_compare_node_compare,
                                           util_ldap_compare_node_copy,
                                           util_ldap_compare_node_free);
-    dn_compare_cache = util_ald_create_cache(st->compare_cache_size,
+    dn_compare_cache = util_ald_create_cache(st,
+                                             st->compare_cache_size,
                                              util_ldap_dn_compare_node_hash,
                                              util_ldap_dn_compare_node_compare,
                                              util_ldap_dn_compare_node_copy,
@@ -272,19 +276,21 @@
         curl->compare_cache = compare_cache;
         curl->dn_compare_cache = dn_compare_cache;
 
-        util_ald_cache_insert(util_ldap_cache, curl);
-
+        util_ald_cache_insert(st, st->ldap_cache, curl);
+       return curl;
     }
 
-    return curl;
+    /* cache is not valid */
+    return NULL;
 }
 
 
-util_ald_cache_t *util_ald_create_cache(unsigned long maxentries,
+util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
+                               unsigned long maxentries,
                                 unsigned long (*hashfunc)(void *), 
                                 int (*comparefunc)(void *, void *),
-                                void * (*copyfunc)(void *),
-                                void (*freefunc)(void *))
+                                void * (*copyfunc)(util_ldap_state_t *, void *),
+                                void (*freefunc)(util_ldap_state_t *, void *))
 {
     util_ald_cache_t *cache;
     unsigned long i;
@@ -292,7 +298,7 @@
     if (maxentries <= 0)
         return NULL;
 
-    cache = (util_ald_cache_t *)util_ald_alloc(sizeof(util_ald_cache_t));
+    cache = (util_ald_cache_t *)util_ald_alloc(st, sizeof(util_ald_cache_t));
     if (!cache)
         return NULL;
 
@@ -303,9 +309,9 @@
         for (i = 0; primes[i] && primes[i] < cache->size; ++i) ;
             cache->size = primes[i]? primes[i] : primes[i-1];
 
-    cache->nodes = (util_cache_node_t **)util_ald_alloc(cache->size * 
sizeof(util_cache_node_t *));
+    cache->nodes = (util_cache_node_t **)util_ald_alloc(st, cache->size * 
sizeof(util_cache_node_t *));
     if (!cache->nodes) {
-        util_ald_free(cache);
+        util_ald_free(st, cache);
         return NULL;
     }
 
@@ -332,7 +338,7 @@
     return cache;
 }
 
-void util_ald_destroy_cache(util_ald_cache_t *cache)
+void util_ald_destroy_cache(util_ldap_state_t *st, util_ald_cache_t *cache)
 {
     unsigned long i;
     util_cache_node_t *p, *q;
@@ -345,13 +351,13 @@
         q = NULL;
         while (p != NULL) {
             q = p->next;
-           (*cache->free)(p->payload);
-           util_ald_free(p);
+           (*cache->free)(st, p->payload);
+           util_ald_free(st, p);
            p = q;
         }
     }
-    util_ald_free(cache->nodes);
-    util_ald_free(cache);
+    util_ald_free(st, cache->nodes);
+    util_ald_free(st, cache);
 }
 
 void *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload)
@@ -382,7 +388,7 @@
  * Insert an item into the cache. 
  * *** Does not catch duplicates!!! ***
  */
-void util_ald_cache_insert(util_ald_cache_t *cache, void *payload)
+void util_ald_cache_insert(util_ldap_state_t *st, util_ald_cache_t *cache, void 
*payload)
 {
     int hashval;
     util_cache_node_t *node;
@@ -392,18 +398,18 @@
 
     cache->inserts++;
     hashval = (*cache->hash)(payload) % cache->size;
-    node = (util_cache_node_t *)util_ald_alloc(sizeof(util_cache_node_t));
+    node = (util_cache_node_t *)util_ald_alloc(st, sizeof(util_cache_node_t));
     node->add_time = apr_time_now();
-    node->payload = (*cache->copy)(payload);
+    node->payload = (*cache->copy)(st, payload);
     node->next = cache->nodes[hashval];
     cache->nodes[hashval] = node;
     if (++cache->numentries == cache->fullmark) 
         cache->marktime=apr_time_now();
     if (cache->numentries >= cache->maxentries)
-        util_ald_cache_purge(cache);
+        util_ald_cache_purge(st);
 }
 
-void util_ald_cache_remove(util_ald_cache_t *cache, void *payload)
+void util_ald_cache_remove(util_ldap_state_t *st, util_ald_cache_t *cache, void 
*payload)
 {
     int hashval;
     util_cache_node_t *p, *q;
@@ -431,8 +437,8 @@
         /* We found the node and it's not the first in the list */
         q->next = p->next;
     }
-    (*cache->free)(p->payload);
-    util_ald_free(p);
+    (*cache->free)(st, p->payload);
+    util_ald_free(st, p);
     cache->numentries--;
 }
 
@@ -499,8 +505,9 @@
     return buf;
 }
 
-char *util_ald_cache_display(apr_pool_t *pool)
+char *util_ald_cache_display(apr_pool_t *pool, void *data)
 {
+    util_ald_cache_t *util_ldap_cache = (util_ald_cache_t *) data;
     unsigned long i;
     char *buf, *t1, *t2, *t3;
 

Reply via email to