]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/idl.c
Add search no-op support.
[openldap] / servers / slapd / back-ldbm / idl.c
index beae715f0faa2b87208ef50890abae9043394ce3..e5f369a4b123f2156fd358100e09cdb3d7a6829c 100644 (file)
@@ -1,7 +1,7 @@
 /* idl.c - ldap id list handling routines */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -138,7 +138,13 @@ idl_fetch_one(
                return NULL;
        }
 
-       idl = idl_dup((ID_BLOCK *) data.dptr);
+       idl = (ID_BLOCK *) data.dptr;
+       if ( ID_BLOCK_ALLIDS(idl) ) {
+               /* make sure we have the current value of highest id */
+               idl = idl_allids( be );
+       } else {
+               idl = idl_dup((ID_BLOCK *) data.dptr);
+       }
 
        ldbm_datum_free( db->dbc_db, data );
 
@@ -165,7 +171,8 @@ idl_fetch(
        Datum   data;
        ID_BLOCK        *idl;
        ID_BLOCK        **tmp;
-       int     i, nids;
+       int     nids;
+       unsigned i;
 
        idl = idl_fetch_one( be, db, key );
 
@@ -175,10 +182,6 @@ idl_fetch(
 
        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 );
        }
 
@@ -279,7 +282,6 @@ idl_store(
 {
        int     rc, flags;
        Datum   data;
-       struct ldbminfo *li = (struct ldbminfo *) be->be_private;
 
 #ifdef LDBM_DEBUG_IDL
        idl_check(idl);
@@ -292,14 +294,14 @@ idl_store(
        data.dptr = (char *) idl;
        data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAXN(idl)) * sizeof(ID);
        
+       flags = LDBM_REPLACE;
+       rc = ldbm_cache_store( db, key, data, flags );
+
 #ifdef LDBM_DEBUG
        Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
                rc, 0, 0, 0, 0 );
 #endif
 
-       flags = LDBM_REPLACE;
-       rc = ldbm_cache_store( db, key, data, flags );
-
        /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
        return( rc );
 }
@@ -458,7 +460,7 @@ idl_insert_key(
     ID                 id
 )
 {
-       int     i, j, first, rc;
+       int     i, j, first, rc = 0;
        ID_BLOCK        *idl, *tmp, *tmp2, *tmp3;
        Datum   k2;
 
@@ -502,14 +504,15 @@ idl_insert_key(
                        idl_free( idl );
 
                        /* create the header indirect block */
-                       idl = idl_alloc( 3 );
 #ifndef USE_INDIRECT_NIDS
+                       idl = idl_alloc( 3 );
                        ID_BLOCK_NMAX(idl) = 3;
                        ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
                        ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
                        ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
                        ID_BLOCK_ID(idl, 2) = NOID;
 #else
+                       idl = idl_alloc( 2 );
                        ID_BLOCK_NMAX(idl) = 2 | ID_BLOCK_INDIRECT_VALUE;
                        ID_BLOCK_NIDS(idl) = 2;
                        ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
@@ -622,7 +625,7 @@ idl_insert_key(
                /* is there a next block? */
                if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
 #else
-               if ( !first && (i + 1) < ID_BLOCK_NIDS(idl) ) {
+               if ( !first && (unsigned long)(i + 1) < ID_BLOCK_NIDS(idl) ) {
 #endif
                        /* read it in */
                        cont_alloc( &k2, &key );
@@ -649,9 +652,6 @@ idl_insert_key(
                         */
                        if (id < ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1)) {
                            ID id2 = ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1);
-                           Datum k3;
-
-                           ldbm_datum_init( k3 );
 
                            --ID_BLOCK_NIDS(tmp);
                            /* This must succeed since we just popped one
@@ -659,10 +659,7 @@ idl_insert_key(
                             */
                            rc = idl_insert( &tmp, id, db->dbc_maxids );
 
-                               k3.dptr = ch_malloc(k2.dsize);
-                               k3.dsize = k2.dsize;
-                               AC_MEMCPY(k3.dptr, k2.dptr, k3.dsize);
-                           if ( (rc = idl_store( be, db, k3, tmp )) != 0 ) {
+                           if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "cache", LDAP_LEVEL_ERR,
                                               "idl_insert_key: idl_store returned %d\n", rc ));
@@ -673,8 +670,6 @@ idl_insert_key(
 
                            }
 
-                               free( k3.dptr );
-
                            id = id2;
                            /* This new id will necessarily be inserted
                             * as the first id of the next block by the
@@ -751,7 +746,7 @@ split:
 #ifndef USE_INDIRECT_NIDS
                        for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
 #else
-                       for ( j = 0; j < ID_BLOCK_NIDS(idl); j++ ) {
+                       for ( j = 0; (unsigned long) j < ID_BLOCK_NIDS(idl); j++ ) {
 #endif
                                cont_id( &k2, ID_BLOCK_ID(idl, j) );
 
@@ -798,7 +793,7 @@ split:
                        (char *) &ID_BLOCK_ID(tmp, i + 2),
                        (char *) &ID_BLOCK_ID(idl, i + 1),
                        (ID_BLOCK_NIDS(idl) - i - 1) * sizeof(ID) );
-               ID_BLOCK_NIDS(idl)++;
+               ID_BLOCK_NIDS(tmp) = ID_BLOCK_NIDS(idl) + 1;
 #endif
 
                /* store the header block */
@@ -936,12 +931,11 @@ idl_delete_key (
        /* We have to go through an indirect block and find the ID
           in the list of IDL's
           */
+       cont_alloc( &data, &key );
 #ifndef USE_INDIRECT_NIDS
        for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
                ;       /* NULL */
 
-       cont_alloc( &data, &key );
-
        for ( j = 0; j<nids; j++ ) 
 #else
        nids = ID_BLOCK_NIDS(idl);