/* 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
*/
static void cont_id( Datum *cont, ID id )
{
- int i;
+ unsigned int i;
for( i=1; i <= sizeof(id); i++) {
((unsigned char *)cont->dptr)[i] = (unsigned char)(id & 0xFF);
{
if ( idl == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_free: called with NULL pointer\n" ));
#else
Debug( LDAP_DEBUG_TRACE,
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 );
Datum data;
ID_BLOCK *idl;
ID_BLOCK **tmp;
- int i, nids;
+ int nids;
+ unsigned i;
idl = idl_fetch_one( be, db, key );
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 );
}
if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_fetch: idl_fetch_one returned NULL\n" ));
#else
Debug( LDAP_DEBUG_ANY,
#endif
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_ENTRY,
+ LDAP_LOG(( "idl", LDAP_LEVEL_ENTRY,
"idl_fetch: %ld ids (%ld max)\n",
ID_BLOCK_NIDS(idl), ID_BLOCK_NMAXN(idl) ));
#else
/* delete old key block */
if ( (rc = ldbm_cache_delete( db, bkey )) != 0 ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_change_first: ldbm_cache_delete returned %d\n", rc ));
#else
Debug( LDAP_DEBUG_ANY,
if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_change_first: idl_store returned %d\n", rc ));
#else
Debug( LDAP_DEBUG_ANY,
ID_BLOCK_ID(h, pos) = ID_BLOCK_ID(b, 0);
if ( (rc = idl_store( be, db, hkey, h )) != 0 ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_change_first: idl_store returned %s\n", rc ));
#else
Debug( LDAP_DEBUG_ANY,
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);
if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_ERR,
+ LDAP_LOG(( "idl", LDAP_LEVEL_ERR,
"idl_insert_key: nonexistent continuation block\n" ));
#else
Debug( LDAP_DEBUG_ANY, "idl_insert_key: nonexistent continuation block\n",
case 0: /* id inserted ok */
if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_ERR,
+ LDAP_LOG(( "idl", LDAP_LEVEL_ERR,
"ids_insert_key: idl_store returned %d\n", rc ));
#else
Debug( LDAP_DEBUG_ANY,
/* 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 );
cont_id( &k2, ID_BLOCK_ID(idl, i) );
if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_ERR,
+ LDAP_LOG(( "idl", LDAP_LEVEL_ERR,
"idl_insert_key: idl_fetch_one returned NULL\n"));
#else
Debug( LDAP_DEBUG_ANY,
*/
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
*/
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,
+ LDAP_LOG(( "idl", LDAP_LEVEL_ERR,
"idl_insert_key: idl_store returned %d\n", rc ));
#else
Debug( LDAP_DEBUG_ANY,
}
- free( k3.dptr );
-
id = id2;
/* This new id will necessarily be inserted
* as the first id of the next block by the
*/
if ( rc == 2 ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_insert_key: id %ld is already in next block\n",
id ));
#else
#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) );
(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 */
/* 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);
if ( (tmp = idl_fetch_one( be, db, data )) == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
+ LDAP_LOG(( "idl", LDAP_LEVEL_INFO,
"idl_delete_key: idl_fetch_one returned NULL\n" ));
#else
Debug( LDAP_DEBUG_ANY,
if ( ID_BLOCK_ALLIDS( b ) ) {
return( idl_dup( a ) );
}
+ if ( ID_BLOCK_NIDS(a) == 0 || ID_BLOCK_NIDS(b) == 0 ) {
+ return( NULL );
+ }
n = idl_dup( idl_min( a, b ) );
idl_check(b);
#endif
- for ( ni = 0, ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
- for ( ;
- bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
- bi++ )
- {
- ; /* NULL */
- }
-
- if ( bi == ID_BLOCK_NIDS(b) ) {
- break;
- }
-
+ for ( ni = 0, ai = 0, bi = 0; ; ) {
if ( ID_BLOCK_ID(b, bi) == ID_BLOCK_ID(a, ai) ) {
ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
+ ai++;
+ bi++;
+ if ( ai >= ID_BLOCK_NIDS(a) || bi >= ID_BLOCK_NIDS(b) )
+ break;
+ } else if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) {
+ ai++;
+ if ( ai >= ID_BLOCK_NIDS(a) )
+ break;
+ } else {
+ bi++;
+ if ( bi >= ID_BLOCK_NIDS(b) )
+ break;
}
}