]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/cache.c
Change overlapping `strcpy( x, y )' to `SAFEMEMCPY( x, y, strlen( y ) + 1 )'
[openldap] / servers / slapd / back-ldbm / cache.c
index 4e0b06157648226e051b6eaaaab527f53ac71b64..01a92295df87d35dbafa2f37994085d77804c814 100644 (file)
@@ -1,14 +1,18 @@
 /* cache.c - routines to maintain an in-core cache of entries */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+int strcasecmp( const char *, const char *);
+
+#include <ac/socket.h>
 #include "slap.h"
+
 #include "back-ldbm.h"
 
-static int     cache_delete_entry_internal();
+static int     cache_delete_entry_internal(struct cache *cache, Entry *e);
 #ifdef LDAP_DEBUG
-static void    lru_print();
+static void    lru_print(struct cache *cache);
 #endif
 
 /*
@@ -132,10 +136,11 @@ cache_add_entry_lock(
        /* set cache mutex */
        pthread_mutex_lock( &cache->c_mutex );
 
-       if ( avl_insert( &cache->c_dntree, e, cache_entrydn_cmp, avl_dup_error )
-           != 0 ) {
+       if ( avl_insert( &cache->c_dntree, (caddr_t) e,
+               cache_entrydn_cmp, avl_dup_error ) != 0 )
+       {
                Debug( LDAP_DEBUG_TRACE,
-                       "====> cache_add_entry lock: entry %20s id %d already in dn cache\n",
+                       "====> cache_add_entry lock: entry %20s id %lu already in dn cache\n",
                    e->e_dn, e->e_id, 0 );
 
                /* free cache mutex */
@@ -144,15 +149,17 @@ cache_add_entry_lock(
        }
 
        /* id tree */
-       if ( avl_insert( &cache->c_idtree, e, cache_entryid_cmp, avl_dup_error )
-           != 0 ) {
+       if ( avl_insert( &cache->c_idtree, (caddr_t) e,
+               cache_entryid_cmp, avl_dup_error ) != 0 )
+       {
                Debug( LDAP_DEBUG_ANY,
-                       "====> entry %20s id %d already in id cache\n",
+                       "====> entry %20s id %lu already in id cache\n",
                    e->e_dn, e->e_id, 0 );
 
                /* delete from dn tree inserted above */
-               if ( avl_delete( &cache->c_dntree, e, cache_entrydn_cmp )
-                   == NULL ) {
+               if ( avl_delete( &cache->c_dntree, (caddr_t) e,
+                       cache_entrydn_cmp ) == NULL )
+               {
                        Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
                            0, 0, 0 );
                }
@@ -192,7 +199,9 @@ cache_add_entry_lock(
                        e = cache->c_lrutail;
 
                        /* XXX check for writer lock - should also check no readers pending */
-                       assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#ifdef LDAP_DEBUG
+                       assert(!pthread_rdwr_rwchk_np(&e->e_rdwr));
+#endif
 
                        /* delete from cache and lru q */
                        rc = cache_delete_entry_internal( cache, e );
@@ -226,9 +235,9 @@ cache_find_entry_dn2id(
 
        e.e_dn = dn;
 
-       if ( (ep = (Entry *) avl_find( cache->c_dntree, &e, cache_entrydn_cmp ))
-               != NULL ) {
-
+       if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
+               cache_entrydn_cmp )) != NULL )
+       {
                Debug(LDAP_DEBUG_TRACE, "====> cache_find_entry_dn2id: found dn: %s\n",
                        dn, 0, 0);
 
@@ -307,9 +316,9 @@ cache_find_entry_id(
 
        e.e_id = id;
 
-       if ( (ep = (Entry *) avl_find( cache->c_idtree, &e, cache_entryid_cmp ))
-               != NULL ) {
-
+       if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
+               cache_entryid_cmp )) != NULL )
+       {
                Debug(LDAP_DEBUG_TRACE,
                        "====> cache_find_entry_dn2id: found id: %ld rw: %d\n",
                        id, rw, 0);
@@ -388,7 +397,9 @@ cache_delete_entry(
        Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry:\n", 0, 0, 0 );
 
        /* XXX check for writer lock - should also check no readers pending */
+#ifdef LDAP_DEBUG
        assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#endif
 
        /* set cache mutex */
        pthread_mutex_lock( &cache->c_mutex );
@@ -406,14 +417,24 @@ cache_delete_entry_internal(
     Entry              *e
 )
 {
+       int rc = 0;     /* return code */
+
        /* dn tree */
-       if ( avl_delete( &cache->c_dntree, e, cache_entrydn_cmp ) == NULL ) {
-               return( -1 );
+       if ( avl_delete( &cache->c_dntree, (caddr_t) e, cache_entrydn_cmp )
+               == NULL )
+       {
+               rc = -1;
        }
 
        /* id tree */
-       if ( avl_delete( &cache->c_idtree, e, cache_entryid_cmp ) == NULL ) {
-               return( -1 );
+       if ( avl_delete( &cache->c_idtree, (caddr_t) e, cache_entryid_cmp )
+               == NULL )
+       {
+               rc = -1;
+       }
+
+       if (rc != 0) {
+               return rc;
        }
 
        /* lru */
@@ -437,12 +458,12 @@ lru_print( struct cache *cache )
 
        fprintf( stderr, "LRU queue (head to tail):\n" );
        for ( e = cache->c_lruhead; e != NULL; e = e->e_lrunext ) {
-               fprintf( stderr, "\tdn %20s id %d refcnt %d\n", e->e_dn,
+               fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn,
                    e->e_id, e->e_refcnt );
        }
        fprintf( stderr, "LRU queue (tail to head):\n" );
        for ( e = cache->c_lrutail; e != NULL; e = e->e_lruprev ) {
-               fprintf( stderr, "\tdn %20s id %d refcnt %d\n", e->e_dn,
+               fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn,
                    e->e_id, e->e_refcnt );
        }
 }