]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Updated the latest LDAP cache changes to support platforms that do not have
authorBradley Nicholes <bnicholes@apache.org>
Tue, 11 Nov 2003 19:10:56 +0000 (19:10 +0000)
committerBradley Nicholes <bnicholes@apache.org>
Tue, 11 Nov 2003 19:10:56 +0000 (19:10 +0000)
shared memory.  All shared memory patches must respect the
APR_HAS_SHARED_MEMORY #define.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101750 13f79535-47bb-0310-9956-ffa450edef68

modules/experimental/util_ldap.c
modules/experimental/util_ldap_cache.c
modules/experimental/util_ldap_cache.h
modules/experimental/util_ldap_cache_mgr.c

index 9ab92c5623ad01851993601693985c6f87213d39..e588201b14c3872e126c50230509f27b15b76f35 100644 (file)
@@ -1134,19 +1134,22 @@ static int util_ldap_post_config(apr_pool_t *p, apr_pool_t *plog,
     apr_status_t result;
     char buf[MAX_STRING_LEN];
 
-    server_rec *s_vhost;
-    util_ldap_state_t *st_vhost;
-    
     util_ldap_state_t *st =
         (util_ldap_state_t *)ap_get_module_config(s->module_config, &ldap_module);
 
+#if APR_HAS_SHARED_MEMORY
+    server_rec *s_vhost;
+    util_ldap_state_t *st_vhost;
+    
     /* initializing cache if file is here and we already don't have shm addr*/
     if (st->cache_file && !st->cache_shm) {
+#endif
         result = util_ldap_cache_init(p, st);
         apr_strerror(result, buf, sizeof(buf));
         ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, result, s,
                      "LDAP cache init: %s", buf);
 
+#if APR_HAS_SHARED_MEMORY
         /* merge config in all vhost */
         s_vhost = s->next;
         while (s_vhost) {
@@ -1164,6 +1167,7 @@ static int util_ldap_post_config(apr_pool_t *p, apr_pool_t *plog,
     else {
         ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0 , s, "LDAP cache: Unable to init Shared Cache: no file");
     }
+#endif
     
     /* log the LDAP SDK used 
      */
index c172107d11877526fb000d8cfb0046d23215e9df..6fb2934bda80d230c15c08e48a8b907886c7cdbd 100644 (file)
@@ -66,8 +66,9 @@
 
 #ifdef APU_HAS_LDAP
 
+#if APR_HAS_SHARED_MEMORY
 #define MODLDAP_SHMEM_CACHE "/tmp/mod_ldap_cache"
-
+#endif
 
 /* ------------------------------------------------------------------ */
 
@@ -88,11 +89,11 @@ int util_ldap_url_node_compare(void *a, void *b)
 void *util_ldap_url_node_copy(util_ald_cache_t *cache, void *c)
 {
     util_url_node_t *n = (util_url_node_t *)c;
-    util_url_node_t *node = (util_url_node_t *)util_ald_alloc(cache->rmm_addr, sizeof(util_url_node_t));
+    util_url_node_t *node = (util_url_node_t *)util_ald_alloc(cache, sizeof(util_url_node_t));
 
     if (node) {
-        if (!(node->url = util_ald_strdup(cache->rmm_addr, n->url))) {
-            util_ald_free(cache->rmm_addr, node->url);
+        if (!(node->url = util_ald_strdup(cache, n->url))) {
+            util_ald_free(cache, node->url);
             return NULL;
         }
         node->search_cache = n->search_cache;
@@ -109,11 +110,11 @@ void util_ldap_url_node_free(util_ald_cache_t *cache, void *n)
 {
     util_url_node_t *node = (util_url_node_t *)n;
 
-    util_ald_free(cache->rmm_addr, node->url);
+    util_ald_free(cache, 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(cache->rmm_addr, node);
+    util_ald_free(cache, node);
 }
 
 /* ------------------------------------------------------------------ */
@@ -134,7 +135,7 @@ int util_ldap_search_node_compare(void *a, void *b)
 void *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c)
 {
     util_search_node_t *node = (util_search_node_t *)c;
-    util_search_node_t *newnode = util_ald_alloc(cache->rmm_addr, sizeof(util_search_node_t));
+    util_search_node_t *newnode = util_ald_alloc(cache, sizeof(util_search_node_t));
 
     /* safety check */
     if (newnode) {
@@ -144,12 +145,12 @@ void *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c)
             int k = 0;
             int i = 0;
             while (node->vals[k++]);
-            if (!(newnode->vals = util_ald_alloc(cache->rmm_addr, sizeof(char *) * (k+1)))) {
+            if (!(newnode->vals = util_ald_alloc(cache, sizeof(char *) * (k+1)))) {
                 util_ldap_search_node_free(cache, newnode);
                 return NULL;
             }
             while (node->vals[i]) {
-                if (!(newnode->vals[i] = util_ald_strdup(cache->rmm_addr, node->vals[i]))) {
+                if (!(newnode->vals[i] = util_ald_strdup(cache, node->vals[i]))) {
                     util_ldap_search_node_free(cache, newnode);
                     return NULL;
                 }
@@ -159,9 +160,9 @@ void *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c)
         else {
             newnode->vals = NULL;
         }
-        if (!(newnode->username = util_ald_strdup(cache->rmm_addr, node->username)) ||
-            !(newnode->dn = util_ald_strdup(cache->rmm_addr, node->dn)) ||
-            !(newnode->bindpw = util_ald_strdup(cache->rmm_addr, node->bindpw)) ) {
+        if (!(newnode->username = util_ald_strdup(cache, node->username)) ||
+            !(newnode->dn = util_ald_strdup(cache, node->dn)) ||
+            !(newnode->bindpw = util_ald_strdup(cache, node->bindpw)) ) {
             util_ldap_search_node_free(cache, newnode);
             return NULL;
         }
@@ -177,14 +178,14 @@ void util_ldap_search_node_free(util_ald_cache_t *cache, void *n)
     util_search_node_t *node = (util_search_node_t *)n;
     if (node->vals) {
         while (node->vals[i]) {
-            util_ald_free(cache->rmm_addr, node->vals[i++]);
+            util_ald_free(cache, node->vals[i++]);
         }
-        util_ald_free(cache->rmm_addr, node->vals);
+        util_ald_free(cache, node->vals);
     }
-    util_ald_free(cache->rmm_addr, node->username);
-    util_ald_free(cache->rmm_addr, node->dn);
-    util_ald_free(cache->rmm_addr, node->bindpw);
-    util_ald_free(cache->rmm_addr, node);
+    util_ald_free(cache, node->username);
+    util_ald_free(cache, node->dn);
+    util_ald_free(cache, node->bindpw);
+    util_ald_free(cache, node);
 }
 
 /* ------------------------------------------------------------------ */
@@ -207,12 +208,12 @@ int util_ldap_compare_node_compare(void *a, void *b)
 void *util_ldap_compare_node_copy(util_ald_cache_t *cache, void *c)
 {
     util_compare_node_t *n = (util_compare_node_t *)c;
-    util_compare_node_t *node = (util_compare_node_t *)util_ald_alloc(cache->rmm_addr, sizeof(util_compare_node_t));
+    util_compare_node_t *node = (util_compare_node_t *)util_ald_alloc(cache, sizeof(util_compare_node_t));
 
     if (node) {
-        if (!(node->dn = util_ald_strdup(cache->rmm_addr, n->dn)) ||
-            !(node->attrib = util_ald_strdup(cache->rmm_addr, n->attrib)) ||
-            !(node->value = util_ald_strdup(cache->rmm_addr, n->value))) {
+        if (!(node->dn = util_ald_strdup(cache, n->dn)) ||
+            !(node->attrib = util_ald_strdup(cache, n->attrib)) ||
+            !(node->value = util_ald_strdup(cache, n->value))) {
             util_ldap_compare_node_free(cache, node);
             return NULL;
         }
@@ -228,10 +229,10 @@ void *util_ldap_compare_node_copy(util_ald_cache_t *cache, void *c)
 void util_ldap_compare_node_free(util_ald_cache_t *cache, void *n)
 {
     util_compare_node_t *node = (util_compare_node_t *)n;
-    util_ald_free(cache->rmm_addr, node->dn);
-    util_ald_free(cache->rmm_addr, node->attrib);
-    util_ald_free(cache->rmm_addr, node->value);
-    util_ald_free(cache->rmm_addr, node);
+    util_ald_free(cache, node->dn);
+    util_ald_free(cache, node->attrib);
+    util_ald_free(cache, node->value);
+    util_ald_free(cache, node);
 }
 
 /* ------------------------------------------------------------------ */
@@ -250,10 +251,10 @@ int util_ldap_dn_compare_node_compare(void *a, void *b)
 void *util_ldap_dn_compare_node_copy(util_ald_cache_t *cache, 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(cache->rmm_addr, sizeof(util_dn_compare_node_t));
+    util_dn_compare_node_t *node = (util_dn_compare_node_t *)util_ald_alloc(cache, sizeof(util_dn_compare_node_t));
     if (node) {
-        if (!(node->reqdn = util_ald_strdup(cache->rmm_addr, n->reqdn)) ||
-            !(node->dn = util_ald_strdup(cache->rmm_addr, n->dn))) {
+        if (!(node->reqdn = util_ald_strdup(cache, n->reqdn)) ||
+            !(node->dn = util_ald_strdup(cache, n->dn))) {
             util_ldap_dn_compare_node_free(cache, node);
             return NULL;
         }
@@ -267,9 +268,9 @@ void *util_ldap_dn_compare_node_copy(util_ald_cache_t *cache, void *c)
 void util_ldap_dn_compare_node_free(util_ald_cache_t *cache, void *n)
 {
     util_dn_compare_node_t *node = (util_dn_compare_node_t *)n;
-    util_ald_free(cache->rmm_addr, node->reqdn);
-    util_ald_free(cache->rmm_addr, node->dn);
-    util_ald_free(cache->rmm_addr, node);
+    util_ald_free(cache, node->reqdn);
+    util_ald_free(cache, node->dn);
+    util_ald_free(cache, node);
 }
 
 
index 88e1224b2eb2d4873c1abd2452aee6a1b2790cfc..e9c2937360f137f7ad1c2bff1723be6383c3c0a2 100644 (file)
  * LDAP Cache Manager
  */
 
+#if APR_HAS_SHARED_MEMORY
 #include <apr_shm.h>
 #include <apr_rmm.h> /* EDD */
+#endif
 
 typedef struct util_cache_node_t {
     void *payload;             /* Pointer to the payload */
@@ -212,9 +214,9 @@ void util_ldap_dn_compare_node_free(util_ald_cache_t *cache, void *n);
 /* util_ldap_cache_mgr.c */
 
 /* Cache alloc and free function, dealing or not with shm */
-void util_ald_free(apr_rmm_t *rmm_addr, const void *ptr);
-void *util_ald_alloc(apr_rmm_t *rmm_addr, unsigned long size);
-const char *util_ald_strdup(apr_rmm_t *rmm_addr, const char *s);
+void util_ald_free(util_ald_cache_t *cache, const void *ptr);
+void *util_ald_alloc(util_ald_cache_t *cache, unsigned long size);
+const char *util_ald_strdup(util_ald_cache_t *cache, const char *s);
 
 /* Cache managing function */
 unsigned long util_ald_hash_string(int nstr, ...);
index 9cc281e30366f38896ff9bcea4dc0f65fc8886af..58e26551acdaaee89ecb306ce96186dd38132ba2 100644 (file)
@@ -112,13 +112,13 @@ static const unsigned long primes[] =
   0
 };
 
-void util_ald_free(apr_rmm_t *rmm_addr, const void *ptr)
+void util_ald_free(util_ald_cache_t *cache, const void *ptr)
 {
 #if APR_HAS_SHARED_MEMORY
-    if (rmm_addr) {
+    if (cache->rmm_addr) {
         if (ptr)
             /* Free in shared memory */
-            apr_rmm_free(rmm_addr, apr_rmm_offset_get(rmm_addr, (void *)ptr));
+            apr_rmm_free(cache->rmm_addr, apr_rmm_offset_get(cache->rmm_addr, (void *)ptr));
     }
     else {
         if (ptr)
@@ -131,14 +131,14 @@ void util_ald_free(apr_rmm_t *rmm_addr, const void *ptr)
 #endif
 }
 
-void *util_ald_alloc(apr_rmm_t *rmm_addr, unsigned long size)
+void *util_ald_alloc(util_ald_cache_t *cache, unsigned long size)
 {
     if (0 == size)
         return NULL;
 #if APR_HAS_SHARED_MEMORY
-    if (rmm_addr) {
+    if (cache->rmm_addr) {
         /* allocate from shared memory */
-        return (void *)apr_rmm_addr_get(rmm_addr, apr_rmm_calloc(rmm_addr, size));
+        return (void *)apr_rmm_addr_get(cache->rmm_addr, apr_rmm_calloc(cache->rmm_addr, size));
     }
     else {
         /* Cache shm is not used */
@@ -149,12 +149,12 @@ void *util_ald_alloc(apr_rmm_t *rmm_addr, unsigned long size)
 #endif
 }
 
-const char *util_ald_strdup(apr_rmm_t *rmm_addr, const char *s)
+const char *util_ald_strdup(util_ald_cache_t *cache, const char *s)
 {
 #if APR_HAS_SHARED_MEMORY
-    if (rmm_addr) {
+    if (cache->rmm_addr) {
         /* allocate from shared memory */
-        char *buf = (char *)apr_rmm_addr_get(rmm_addr, apr_rmm_calloc(rmm_addr, strlen(s)+1));
+        char *buf = (char *)apr_rmm_addr_get(cache->rmm_addr, apr_rmm_calloc(cache->rmm_addr, strlen(s)+1));
         if (buf) {
             strcpy(buf, s);
             return buf;
@@ -226,7 +226,7 @@ void util_ald_cache_purge(util_ald_cache_t *cache)
             if (p->add_time < cache->marktime) {
                q = p->next;
                (*cache->free)(cache, p->payload);
-               util_ald_free(cache->rmm_addr, p);
+               util_ald_free(cache, p);
                cache->numentries--;
                cache->npurged++;
                p = q;
@@ -300,7 +300,11 @@ util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
     if (st->search_cache_size <= 0)
         return NULL;
 
+#if APR_HAS_SHARED_MEMORY
     cache = (util_ald_cache_t *)util_ald_alloc(st->cache_rmm, sizeof(util_ald_cache_t));
+#else
+    cache = (util_ald_cache_t *)util_ald_alloc(NULL, sizeof(util_ald_cache_t));
+#endif
     if (!cache)
         return NULL;
 
@@ -311,9 +315,9 @@ util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
         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->rmm_addr, cache->size * sizeof(util_cache_node_t *));
+    cache->nodes = (util_cache_node_t **)util_ald_alloc(cache, cache->size * sizeof(util_cache_node_t *));
     if (!cache->nodes) {
-        util_ald_free(cache->rmm_addr, cache);
+        util_ald_free(cache, cache);
         return NULL;
     }
 
@@ -354,12 +358,12 @@ void util_ald_destroy_cache(util_ald_cache_t *cache)
         while (p != NULL) {
             q = p->next;
            (*cache->free)(cache, p->payload);
-           util_ald_free(cache->rmm_addr, p);
+           util_ald_free(cache, p);
            p = q;
         }
     }
-    util_ald_free(cache->rmm_addr, cache->nodes);
-    util_ald_free(cache->rmm_addr, cache);
+    util_ald_free(cache, cache->nodes);
+    util_ald_free(cache, cache);
 }
 
 void *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload)
@@ -398,7 +402,7 @@ void util_ald_cache_insert(util_ald_cache_t *cache, void *payload)
     if (cache == NULL || payload == NULL)
         return;
 
-    if ((node = (util_cache_node_t *)util_ald_alloc(cache->rmm_addr, sizeof(util_cache_node_t))) == NULL)
+    if ((node = (util_cache_node_t *)util_ald_alloc(cache, sizeof(util_cache_node_t))) == NULL)
         return;
 
     cache->inserts++;
@@ -442,7 +446,7 @@ void util_ald_cache_remove(util_ald_cache_t *cache, void *payload)
         q->next = p->next;
     }
     (*cache->free)(cache, p->payload);
-    util_ald_free(cache->rmm_addr, p);
+    util_ald_free(cache, p);
     cache->numentries--;
 }