bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
bi->bi_tool_sync = 0;
bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
- bi->bi_tool_id2entry_get = bdb_tool_id2entry_get;
bi->bi_tool_entry_modify = bdb_tool_entry_modify;
bi->bi_connection_init = 0;
#define bdb_tool_entry_put BDB_SYMBOL(tool_entry_put)
#define bdb_tool_entry_reindex BDB_SYMBOL(tool_entry_reindex)
#define bdb_tool_dn2id_get BDB_SYMBOL(tool_dn2id_get)
-#define bdb_tool_id2entry_get BDB_SYMBOL(tool_id2entry_get)
#define bdb_tool_entry_modify BDB_SYMBOL(tool_entry_modify)
#define bdb_tool_idl_add BDB_SYMBOL(tool_idl_add)
extern BI_tool_entry_put bdb_tool_entry_put;
extern BI_tool_entry_reindex bdb_tool_entry_reindex;
extern BI_tool_dn2id_get bdb_tool_dn2id_get;
-extern BI_tool_id2entry_get bdb_tool_id2entry_get;
extern BI_tool_entry_modify bdb_tool_entry_modify;
int bdb_tool_idl_add( BackendDB *be, DB *db, DB_TXN *txn, DBT *key, ID id );
static DBC *cursor = NULL;
static DBT key, data;
static EntryHeader eh;
-static int eoff;
+static ID nid, previd = NOID;
+static char ehbuf[16];
typedef struct dn_id {
ID id;
/* initialize key and data thangs */
DBTzero( &key );
DBTzero( &data );
- key.flags = DB_DBT_REALLOC;
+ key.flags = DB_DBT_USERMEM;
+ key.data = &nid;
+ key.size = key.ulen = sizeof( nid );
data.flags = DB_DBT_USERMEM;
if (cursor == NULL) {
ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
}
- if( key.data ) {
- ch_free( key.data );
- key.data = NULL;
- }
if( eh.bv.bv_val ) {
ch_free( eh.bv.bv_val );
eh.bv.bv_val = NULL;
return 0;
}
-static int
-bdb_tool_entry_set(
- BackendDB *be, int flag )
-{
- struct bdb_info *bdb = (struct bdb_info *) be->be_private;
- int rc;
- char buf[16], *dptr;
-
- /* Get the header */
- data.ulen = data.dlen = sizeof( buf );
- data.data = buf;
- data.flags |= DB_DBT_PARTIAL;
- rc = cursor->c_get( cursor, &key, &data, flag );
- if ( rc )
- return rc;
-
- dptr = eh.bv.bv_val;
- eh.bv.bv_val = buf;
- eh.bv.bv_len = data.size;
- rc = entry_header( &eh );
- eoff = eh.data - eh.bv.bv_val;
- eh.bv.bv_val = dptr;
-
- return rc;
-}
-
ID bdb_tool_entry_next(
BackendDB *be )
{
int rc;
ID id;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
- char buf[16], *dptr;
assert( be != NULL );
assert( slapMode & SLAP_TOOL_MODE );
assert( bdb != NULL );
- rc = bdb_tool_entry_set( be, DB_NEXT );
+ /* Get the header */
+ data.ulen = data.dlen = sizeof( ehbuf );
+ data.data = ehbuf;
+ data.flags |= DB_DBT_PARTIAL;
+ rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
if( rc ) {
/* If we're doing linear indexing and there are more attrs to
bdb_attr_info_free( bdb->bi_attrs[0] );
bdb->bi_attrs[0] = bdb->bi_attrs[index_nattrs];
index_nattrs--;
- rc = bdb_tool_entry_set( be, DB_FIRST );
+ rc = cursor->c_get( cursor, &key, &data, DB_FIRST );
if ( rc ) {
return NOID;
}
}
BDB_DISK2ID( key.data, &id );
+ previd = id;
return id;
}
return ei->bei_id;
}
-int bdb_tool_id2entry_get(
- Backend *be,
- ID id,
- Entry **e
-)
-{
- int rc;
- ID nid;
-
- BDB_ID2DISK( id, &nid );
- key.ulen = key.size = sizeof(ID);
- key.flags = DB_DBT_USERMEM;
- key.data = &nid;
-
- rc = bdb_tool_entry_set( be, DB_SET );
- if ( rc == 0 )
- *e = bdb_tool_entry_get( be, id );
- if ( *e )
- rc = 0;
- else
- rc = LDAP_OTHER;
-
- key.data = NULL;
-
- return rc;
-}
-
Entry* bdb_tool_entry_get( BackendDB *be, ID id )
{
- int rc;
Entry *e = NULL;
+ char *dptr;
+ int rc, eoff;
assert( be != NULL );
assert( slapMode & SLAP_TOOL_MODE );
+ if ( id != previd ) {
+ data.ulen = data.dlen = sizeof( ehbuf );
+ data.data = ehbuf;
+ data.flags |= DB_DBT_PARTIAL;
+
+ BDB_ID2DISK( id, &nid );
+ rc = cursor->c_get( cursor, &key, &data, DB_SET );
+ if ( rc ) goto done;
+ }
+
+ /* Get the header */
+ dptr = eh.bv.bv_val;
+ eh.bv.bv_val = ehbuf;
+ eh.bv.bv_len = data.size;
+ rc = entry_header( &eh );
+ eoff = eh.data - eh.bv.bv_val;
+ eh.bv.bv_val = dptr;
+ if ( rc ) goto done;
+
/* Get the size */
- data.flags ^= DB_DBT_PARTIAL;
+ data.flags &= ~DB_DBT_PARTIAL;
data.ulen = 0;
rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
if ( rc != DB_BUFFER_SMALL ) goto done;
bi->bi_tool_sync = 0;
bi->bi_tool_dn2id_get = 0;
- bi->bi_tool_id2entry_get = 0;
bi->bi_tool_entry_modify = 0;
bi->bi_cf_ocs = ldifocs;
bi->bi_tool_entry_reindex = 0;
bi->bi_tool_sync = 0;
bi->bi_tool_dn2id_get = 0;
- bi->bi_tool_id2entry_get = 0;
bi->bi_tool_entry_modify = 0;
bi->bi_connection_init = 0;
/*FIXME : need to add support */
oi->oi_bi.bi_tool_dn2id_get = 0;
- oi->oi_bi.bi_tool_id2entry_get = 0;
oi->oi_bi.bi_tool_entry_modify = 0;
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_INSTANCE;
#define be_entry_put bd_info->bi_tool_entry_put
#define be_sync bd_info->bi_tool_sync
#define be_dn2id_get bd_info->bi_tool_dn2id_get
-#define be_id2entry_get bd_info->bi_tool_id2entry_get
#define be_entry_modify bd_info->bi_tool_entry_modify
#endif
typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id, AttributeDescription **adv ));
typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
typedef ID (BI_tool_dn2id_get) LDAP_P(( BackendDB *be, struct berval *dn ));
-typedef int (BI_tool_id2entry_get) LDAP_P(( BackendDB *be, ID id, Entry **e ));
typedef ID (BI_tool_entry_modify) LDAP_P(( BackendDB *be, Entry *e,
struct berval *text ));
BI_tool_entry_reindex *bi_tool_entry_reindex;
BI_tool_sync *bi_tool_sync;
BI_tool_dn2id_get *bi_tool_dn2id_get;
- BI_tool_id2entry_get *bi_tool_id2entry_get;
BI_tool_entry_modify *bi_tool_entry_modify;
#define SLAP_INDEX_ADD_OP 0x0001
if ( !be->be_entry_open ||
!be->be_entry_close ||
!be->be_dn2id_get ||
- !be->be_id2entry_get )
+ !be->be_entry_get )
{
fprintf( stderr, "%s: target database "
"doesn't support necessary operations; "
rc = 1;
goto destroy;
}
- if ( be->be_id2entry_get( be, id, &ep ) != 0 ) {
+ ep = be->be_entry_get( be, id );
+ if ( ep == NULL ) {
fprintf( stderr, "%s: unable to fetch entry \"%s\" (%lu)\n",
progname, e.e_nname.bv_val, id );
rc = 1;
ber_memfree( e.e_nname.bv_val );
}
if ( !dryrun && be ) {
- if ( ep != &e ) {
+ if ( ep && ep != &e ) {
be_entry_release_r( op, ep );
}
if ( doclose ) {
!be->be_entry_put ||
(update_ctxcsn &&
(!be->be_dn2id_get ||
- !be->be_id2entry_get ||
+ !be->be_entry_get ||
!be->be_entry_modify)) )
{
fprintf( stderr, "%s: database doesn't support necessary operations.\n",
fprintf( stderr, "%s: context entry is missing\n", progname );
rc = EXIT_FAILURE;
} else {
- ret = be->be_id2entry_get( be, ctxcsn_id, &ctxcsn_e );
- if ( ret == LDAP_SUCCESS ) {
+ ctxcsn_e = be->be_entry_get( be, ctxcsn_id );
+ if ( ctxcsn_e != NULL ) {
attr = attr_find( ctxcsn_e->e_attrs,
slap_schema.si_ad_contextCSN );
if ( attr ) {