]> git.sur5r.net Git - openldap/commitdiff
Remove tool_id2entry_get
authorHoward Chu <hyc@openldap.org>
Sat, 11 Aug 2007 04:19:53 +0000 (04:19 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 11 Aug 2007 04:19:53 +0000 (04:19 +0000)
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/proto-bdb.h
servers/slapd/back-bdb/tools.c
servers/slapd/back-ldif/ldif.c
servers/slapd/back-monitor/init.c
servers/slapd/backglue.c
servers/slapd/slap.h
servers/slapd/slapacl.c
servers/slapd/slapadd.c

index a1699bb57015cb9ac6ebead92010893e95d49da8..521dc26b472c7bf8752c42ef721d4f4da5f25e69 100644 (file)
@@ -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;
index 00e21d506aec2d18a964f40d1bd3a70b37e38242..7d75164f94477c77395f8d67e2c75f256e467881 100644 (file)
@@ -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 );
index dd8f0235cfa80aef911acb9f808c56f57c56a605..f8cf1e138dec0cd0b50300b97d7938e5061e3b61 100644 (file)
@@ -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;
index 03f50f5a2f7698d4ad87a3d9ac62f04cf1a760bf..b6f943f92aaa7a876d8377932756ee2a91dc1486 100644 (file)
@@ -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;
index 951a28631f7dc73a178533546779c725762ba606..6d2cf715227996feb52e03e44e899e30724461e7 100644 (file)
@@ -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;
index 129d4db4b06ae698e46db5aa89dc3a714bcb3e4b..78d0633cc2f82c2406173f3e20b4e598d4afbe74 100644 (file)
@@ -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;
index 793597cbcf1883adf0ed1312ad716e1e718a33eb..9106d198be3a7184d2a91176d535f6be45d602e3 100644 (file)
@@ -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
index 99b5afa5d2ba35c4039a77b52a7865587ba04064..090b67e327bd6a0c72f9f6001e18974721633c30 100644 (file)
@@ -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 ) {
index 69f2a59b116573722cd13fb6ea74632950bec237..547bfebdd41d575ff237754e3f34a6f8f1e395f6 100644 (file)
@@ -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 ) {