From: Howard Chu Date: Sat, 11 Aug 2007 04:19:53 +0000 (+0000) Subject: Remove tool_id2entry_get X-Git-Tag: OPENLDAP_REL_ENG_2_4_MP~241 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a87b4592a4a2eed4b13049b98a4ab01fc9aa59c8;p=openldap Remove tool_id2entry_get --- diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index a1699bb570..521dc26b47 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -723,7 +723,6 @@ bdb_back_initialize( 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; diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 00e21d506a..7d75164f94 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -641,7 +641,6 @@ bdb_trans_backoff( int num_retries ); #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) @@ -672,7 +671,6 @@ extern BI_tool_entry_get bdb_tool_entry_get; 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 ); diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index dd8f0235cf..f8cf1e138d 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -27,7 +27,8 @@ 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; @@ -88,7 +89,9 @@ int bdb_tool_entry_open( /* 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) { @@ -143,10 +146,6 @@ int bdb_tool_entry_close( 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; @@ -174,45 +173,22 @@ int bdb_tool_entry_close( 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 @@ -223,7 +199,7 @@ ID bdb_tool_entry_next( 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; } @@ -233,6 +209,7 @@ ID bdb_tool_entry_next( } BDB_DISK2ID( key.data, &id ); + previd = id; return id; } @@ -262,43 +239,36 @@ ID bdb_tool_dn2id_get( 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; diff --git a/servers/slapd/back-ldif/ldif.c b/servers/slapd/back-ldif/ldif.c index 03f50f5a2f..b6f943f92a 100644 --- a/servers/slapd/back-ldif/ldif.c +++ b/servers/slapd/back-ldif/ldif.c @@ -1308,7 +1308,6 @@ ldif_back_initialize( 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; diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 951a28631f..6d2cf71522 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -2027,7 +2027,6 @@ monitor_back_initialize( 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; diff --git a/servers/slapd/backglue.c b/servers/slapd/backglue.c index 129d4db4b0..78d0633cc2 100644 --- a/servers/slapd/backglue.c +++ b/servers/slapd/backglue.c @@ -863,7 +863,6 @@ glue_db_init( /*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; diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 793597cbcf..9106d198be 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1727,7 +1727,6 @@ struct BackendDB { #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 @@ -2080,7 +2079,6 @@ typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e, 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 )); @@ -2180,7 +2178,6 @@ struct BackendInfo { 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 diff --git a/servers/slapd/slapacl.c b/servers/slapd/slapacl.c index 99b5afa5d2..090b67e327 100644 --- a/servers/slapd/slapacl.c +++ b/servers/slapd/slapacl.c @@ -238,7 +238,7 @@ slapacl( int argc, char **argv ) 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; " @@ -264,7 +264,8 @@ slapacl( int argc, char **argv ) 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; @@ -384,7 +385,7 @@ destroy:; 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 ) { diff --git a/servers/slapd/slapadd.c b/servers/slapd/slapadd.c index 69f2a59b11..547bfebdd4 100644 --- a/servers/slapd/slapadd.c +++ b/servers/slapd/slapadd.c @@ -78,7 +78,7 @@ slapadd( int argc, char **argv ) !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", @@ -324,8 +324,8 @@ slapadd( int argc, char **argv ) 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 ) {