From ed6284991af4118546ae92200bebee38e1f3eda9 Mon Sep 17 00:00:00 2001 From: Bradley Nicholes Date: Tue, 11 Nov 2003 19:10:56 +0000 Subject: [PATCH] Updated the latest LDAP cache changes to support platforms that do not have 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 | 10 +++- modules/experimental/util_ldap_cache.c | 65 +++++++++++----------- modules/experimental/util_ldap_cache.h | 8 ++- modules/experimental/util_ldap_cache_mgr.c | 38 +++++++------ 4 files changed, 66 insertions(+), 55 deletions(-) diff --git a/modules/experimental/util_ldap.c b/modules/experimental/util_ldap.c index 9ab92c5623a..e588201b14c 100644 --- a/modules/experimental/util_ldap.c +++ b/modules/experimental/util_ldap.c @@ -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 */ diff --git a/modules/experimental/util_ldap_cache.c b/modules/experimental/util_ldap_cache.c index c172107d118..6fb2934bda8 100644 --- a/modules/experimental/util_ldap_cache.c +++ b/modules/experimental/util_ldap_cache.c @@ -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); } diff --git a/modules/experimental/util_ldap_cache.h b/modules/experimental/util_ldap_cache.h index 88e1224b2eb..e9c2937360f 100644 --- a/modules/experimental/util_ldap_cache.h +++ b/modules/experimental/util_ldap_cache.h @@ -68,8 +68,10 @@ * LDAP Cache Manager */ +#if APR_HAS_SHARED_MEMORY #include #include /* 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, ...); diff --git a/modules/experimental/util_ldap_cache_mgr.c b/modules/experimental/util_ldap_cache_mgr.c index 9cc281e3036..58e26551acd 100644 --- a/modules/experimental/util_ldap_cache_mgr.c +++ b/modules/experimental/util_ldap_cache_mgr.c @@ -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--; } -- 2.47.3