int rc, flags;
DBCache *db;
Datum key, data;
- struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+ char *buf, *ptr, *pdn;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
ldbm_datum_init( key );
key.dsize = strlen( dn ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
+ buf = ch_malloc( key.dsize );
+ key.dptr = buf;
+ buf[0] = DN_BASE_PREFIX;
+ ptr = buf + 1;
+ strcpy( ptr, dn );
ldbm_datum_init( data );
data.dptr = (char *) &id;
flags = LDBM_INSERT;
rc = ldbm_cache_store( db, key, data, flags );
- free( key.dptr );
+ if ( rc != -1 && !be_issuffix( be, ptr )) {
+ buf[0] = DN_SUBTREE_PREFIX;
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ rc = idl_insert_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ }
if ( rc != -1 ) {
- char *pdn = dn_parent( NULL, dn );
+ pdn = dn_parent( be, ptr );
if( pdn != NULL ) {
- ldbm_datum_init( key );
- key.dsize = strlen( pdn ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn );
+ pdn[-1] = DN_ONE_PREFIX;
+ key.dsize -= pdn - ptr;
+ key.dptr = pdn - 1;
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
rc = idl_insert_key( be, db, key, id );
- free( key.dptr );
- free( pdn );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
}
}
- if ( rc != -1 ) {
- char **subtree = dn_subtree( NULL, dn );
-
- if( subtree != NULL ) {
- int i;
- for( i=0; subtree[i] != NULL; i++ ) {
- ldbm_datum_init( key );
- key.dsize = strlen( subtree[i] ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s",
- DN_SUBTREE_PREFIX, subtree[i] );
+ while ( rc != -1 && pdn != NULL ) {
+ if ( be_issuffix( be, pdn ))
+ break;
- rc = idl_insert_key( be, db, key, id );
+ pdn[-1] = DN_SUBTREE_PREFIX;
- free( key.dptr );
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ rc = idl_insert_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
- if(rc == -1) break;
- }
-
- charray_free( subtree );
- }
+ if( rc != 0 ) break;
+ ptr = pdn;
+ pdn = dn_parent( be, pdn );
+ key.dsize -= pdn - ptr;
+ key.dptr = pdn - 1;
}
+ free( buf );
ldbm_cache_close( be, db );
#ifdef NEW_LOGGING
assert( idp );
/* first check the cache */
- if ( (*idp = cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) {
+ if ( (*idp = cache_find_entry_ndn2id( be, &li->li_cache, dn )) != NOID ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"dn2id: (%s)%ld in cache.\n", dn, *idp ));
return( 0 );
}
-ID_BLOCK *
+int
dn2idl(
Backend *be,
const char *dn,
- int prefix
+ int prefix,
+ ID_BLOCK **idlp
)
{
DBCache *db;
Datum key;
- ID_BLOCK *idl;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
Debug( LDAP_DEBUG_TRACE, "=> dn2idl( \"%c%s\" )\n", prefix, dn, 0 );
#endif
+ assert( idlp != NULL );
+ *idlp = NULL;
+
+ if ( prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn) ) {
+ *idlp = ch_malloc( sizeof(ID) );
+ **idlp = ID_BLOCK_ALLIDS_VALUE;
+ return 0;
+ }
if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
LDBM_SUFFIX, 0, 0 );
#endif
- return NULL;
+ return -1;
}
ldbm_datum_init( key );
key.dptr = ch_malloc( key.dsize );
sprintf( key.dptr, "%c%s", prefix, dn );
- idl = idl_fetch( be, db, key );
+ *idlp = idl_fetch( be, db, key );
ldbm_cache_close( be, db );
free( key.dptr );
- return( idl );
+ return( 0 );
}
DBCache *db;
Datum key;
int rc;
+ char *buf, *ptr, *pdn;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
return( -1 );
}
+ ldbm_datum_init( key );
+ key.dsize = strlen( dn ) + 2;
+ buf = ch_malloc( key.dsize );
+ key.dptr = buf;
+ buf[0] = DN_BASE_PREFIX;
+ ptr = buf + 1;
+ strcpy( ptr, dn );
- {
- char *pdn = dn_parent( NULL, dn );
+ rc = ldbm_cache_delete( db, key );
+
+ if( !be_issuffix( be, ptr )) {
+ buf[0] = DN_SUBTREE_PREFIX;
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ (void) idl_delete_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ }
- if( pdn != NULL ) {
- ldbm_datum_init( key );
- key.dsize = strlen( pdn ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn );
+ pdn = dn_parent( be, ptr );
- (void) idl_delete_key( be, db, key, id );
+ if( pdn != NULL ) {
+ pdn[-1] = DN_ONE_PREFIX;
+ key.dsize -= pdn - ptr;
+ key.dptr = pdn - 1;
- free( key.dptr );
- free( pdn );
- }
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ (void) idl_delete_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
}
- {
- char **subtree = dn_subtree( NULL, dn );
-
- if( subtree != NULL ) {
- int i;
- for( i=0; subtree[i] != NULL; i++ ) {
- ldbm_datum_init( key );
- key.dsize = strlen( subtree[i] ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s",
- DN_SUBTREE_PREFIX, subtree[i] );
+ while ( pdn != NULL ) {
+ if ( be_issuffix( be, pdn ))
+ break;
- (void) idl_delete_key( be, db, key, id );
+ pdn[-1] = DN_SUBTREE_PREFIX;
- free( key.dptr );
- }
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ (void) idl_delete_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
- charray_free( subtree );
- }
+ ptr = pdn;
+ pdn = dn_parent( be, pdn );
+ key.dsize -= pdn - ptr;
+ key.dptr = pdn - 1;
}
- ldbm_datum_init( key );
-
- key.dsize = strlen( dn ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
-
- rc = ldbm_cache_delete( db, key );
-
- free( key.dptr );
+ free( buf );
ldbm_cache_close( be, db );
if ( (e = dn2entry_r( be, pdn, matched )) != NULL ) {
*matched = e;
}
- free( pdn );
}
return NULL;