You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by bn...@apache.org on 2003/11/11 20:10:56 UTC

cvs commit: httpd-2.0/modules/experimental util_ldap_cache_mgr.c util_ldap_cache.h util_ldap_cache.c util_ldap.c

bnicholes    2003/11/11 11:10:56

  Modified:    modules/experimental util_ldap_cache_mgr.c util_ldap_cache.h
                        util_ldap_cache.c util_ldap.c
  Log:
  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.
  
  Revision  Changes    Path
  1.8       +21 -17    httpd-2.0/modules/experimental/util_ldap_cache_mgr.c
  
  Index: util_ldap_cache_mgr.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap_cache_mgr.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- util_ldap_cache_mgr.c	7 Nov 2003 10:49:35 -0000	1.7
  +++ util_ldap_cache_mgr.c	11 Nov 2003 19:10:56 -0000	1.8
  @@ -112,13 +112,13 @@
     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 @@
   #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 @@
   #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 @@
               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 @@
       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 @@
           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 @@
           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 @@
       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 @@
           q->next = p->next;
       }
       (*cache->free)(cache, p->payload);
  -    util_ald_free(cache->rmm_addr, p);
  +    util_ald_free(cache, p);
       cache->numentries--;
   }
   
  
  
  
  1.8       +5 -3      httpd-2.0/modules/experimental/util_ldap_cache.h
  
  Index: util_ldap_cache.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap_cache.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- util_ldap_cache.h	6 Nov 2003 20:45:56 -0000	1.7
  +++ util_ldap_cache.h	11 Nov 2003 19:10:56 -0000	1.8
  @@ -68,8 +68,10 @@
    * 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 @@
   /* 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, ...);
  
  
  
  1.10      +33 -32    httpd-2.0/modules/experimental/util_ldap_cache.c
  
  Index: util_ldap_cache.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap_cache.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- util_ldap_cache.c	6 Nov 2003 20:45:56 -0000	1.9
  +++ util_ldap_cache.c	11 Nov 2003 19:10:56 -0000	1.10
  @@ -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 @@
   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 @@
   {
       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 @@
   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 @@
               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 @@
           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 @@
       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 @@
   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_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 @@
   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_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);
   }
   
   
  
  
  
  1.16      +7 -3      httpd-2.0/modules/experimental/util_ldap.c
  
  Index: util_ldap.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- util_ldap.c	6 Nov 2003 20:45:56 -0000	1.15
  +++ util_ldap.c	11 Nov 2003 19:10:56 -0000	1.16
  @@ -1134,19 +1134,22 @@
       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 @@
       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 
        */