]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/idl.c
Fix -USLAPD_RLOOKUPS
[openldap] / servers / slapd / back-ldbm / idl.c
index 9560e1a9e8c7e4d3fc3a9b57b0680d231f43b19c..e89e7dbf84ed6a1d3400e222f5deace50ec410e3 100644 (file)
@@ -7,7 +7,7 @@
 #include <ac/string.h>
 #include <ac/socket.h>
 
-#include "ldapconfig.h"
+#include "ldap_defaults.h"
 #include "slap.h"
 #include "back-ldbm.h"
 
@@ -15,7 +15,7 @@ static ID_BLOCK* idl_dup( ID_BLOCK *idl );
 
 /* Allocate an ID_BLOCK with room for nids ids */
 ID_BLOCK *
-idl_alloc( int nids )
+idl_alloc( unsigned int nids )
 {
        ID_BLOCK        *new;
 
@@ -61,7 +61,7 @@ idl_free( ID_BLOCK *idl )
 static ID_BLOCK *
 idl_fetch_one(
     Backend            *be,
-    struct dbcache     *db,
+    DBCache    *db,
     Datum              key
 )
 {
@@ -97,7 +97,7 @@ idl_fetch_one(
 ID_BLOCK *
 idl_fetch(
     Backend            *be,
-    struct dbcache     *db,
+    DBCache    *db,
     Datum              key
 )
 {
@@ -107,26 +107,19 @@ idl_fetch(
        char    *kstr;
        int     i, nids;
 
-       ldbm_datum_init( data );
-
-       /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch\n", 0, 0, 0 ); */
-
-       data = ldbm_cache_fetch( db, key );
+       idl = idl_fetch_one( be, db, key );
 
-       if ( data.dptr == NULL ) {
-               return( NULL );
+       if ( idl == NULL ) {
+               return NULL;
        }
 
-       idl = idl_dup( (ID_BLOCK *) data.dptr );
-       ldbm_datum_free( db->dbc_db, data);
-
        if ( ID_BLOCK_ALLIDS(idl) ) {
                /* all ids block */
                /* make sure we have the current value of highest id */
                idl_free( idl );
                idl = idl_allids( be );
 
-               return idl;
+               return( idl );
        }
 
        if ( ! ID_BLOCK_INDIRECT( idl ) ) {
@@ -188,7 +181,7 @@ idl_fetch(
        }
        free( (char *) tmp );
 
-       Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %lu ids (%lu max)\n",
+       Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %ld ids (%ld max)\n",
               ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
        return( idl );
 }
@@ -198,7 +191,7 @@ idl_fetch(
 static int
 idl_store(
     Backend            *be,
-    struct dbcache     *db,
+    DBCache    *db,
     Datum              key, 
     ID_BLOCK           *idl
 )
@@ -284,7 +277,7 @@ idl_split_block(
 static int
 idl_change_first(
     Backend            *be,
-    struct dbcache     *db,
+    DBCache    *db,
     Datum              hkey,           /* header block key     */
     ID_BLOCK           *h,             /* header block         */
     int                        pos,            /* pos in h to update   */
@@ -328,7 +321,7 @@ idl_change_first(
 int
 idl_insert_key(
     Backend            *be,
-    struct dbcache     *db,
+    DBCache    *db,
     Datum              key,
     ID                 id
 )
@@ -378,9 +371,7 @@ idl_insert_key(
                                idl_free( idl );
                                idl = idl_allids( be );
                                rc = idl_store( be, db, key, idl );
-                               idl_free( idl );
-
-                               return( rc );
+                               break;
                        }
 
                        idl_split_block( idl, id, &tmp, &tmp2 );
@@ -449,6 +440,7 @@ idl_insert_key(
                Debug( LDAP_DEBUG_ANY, "nonexistent continuation block (%s)\n",
                    k2.dptr, 0, 0 );
                free( kstr );
+               idl_free( idl );
                return( -1 );
        }
 
@@ -507,7 +499,7 @@ idl_insert_key(
                        case 0:         /* id inserted */
                                if ( rc == 2 ) {
                                        Debug( LDAP_DEBUG_ANY,
-                                           "id %lu already in next block\n",
+                                           "id %ld already in next block\n",
                                            id, 0, 0 );
                                }
                                free( kstr );
@@ -517,10 +509,9 @@ idl_insert_key(
                                return( 0 );
 
                        case 3:         /* split the original block */
-                               idl_free( tmp2 );
                                break;
                        }
-
+                       idl_free( tmp2 );
                }
 
                /*
@@ -622,7 +613,7 @@ idl_insert_key(
  *             3       id not inserted, block must be split
  */
 int
-idl_insert( ID_BLOCK **idl, ID id, int maxids )
+idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
 {
        unsigned int    i, j;
 
@@ -671,7 +662,7 @@ idl_insert( ID_BLOCK **idl, ID id, int maxids )
 int
 idl_delete_key (
        Backend         *be,
-       struct dbcache  *db,
+       DBCache  *db,
        Datum           key,
        ID              id
 )
@@ -710,10 +701,12 @@ idl_delete_key (
                                        idl_store( be, db, key, idl );
                                }
 
+                               idl_free( idl );
                                return 0;
                        }
                        /*  We didn't find the ID.  Hmmm... */
                }
+               idl_free( idl );
                return -1;
        }
        
@@ -766,12 +759,16 @@ idl_delete_key (
                                        else
                                                idl_store( be, db, key, idl );
                                }
+                               idl_free( tmp );
                                free( kstr );
+                               idl_free( idl );
                                return 0;
                        }
                }
+               idl_free( tmp );
        }
        free( kstr );
+       idl_free( idl );
        return -1;
 }