#ifdef APU_HAS_LDAP
+#if APR_HAS_SHARED_MEMORY
#define MODLDAP_SHMEM_CACHE "/tmp/mod_ldap_cache"
-
+#endif
/* ------------------------------------------------------------------ */
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;
{
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);
}
/* ------------------------------------------------------------------ */
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) {
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;
}
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;
}
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);
}
/* ------------------------------------------------------------------ */
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;
}
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);
}
/* ------------------------------------------------------------------ */
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;
}
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);
}
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)
#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 */
#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;
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;
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;
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;
}
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)
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++;
q->next = p->next;
}
(*cache->free)(cache, p->payload);
- util_ald_free(cache->rmm_addr, p);
+ util_ald_free(cache, p);
cache->numentries--;
}