static int wt_id2entry_put( Operation *op, WT_SESSION *session, Entry *e, const char *config ) { struct berval bv; WT_CURSOR *cursor = NULL; WT_ITEM item; int rc; rc = entry_encode( e, &bv ); if(rc != LDAP_SUCCESS){ return -1; } item.size = bv.bv_len; item.data = bv.bv_val; rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL, config, &cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_put) ": open_cursor failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } cursor->set_key(cursor, e->e_id); cursor->set_value(cursor, e->e_ndn, &item); rc = cursor->insert(cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_put) ": insert failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } done: ch_free( bv.bv_val ); if(cursor){ cursor->close(cursor); } return rc; }
int bdb_id2entry_put( BackendDB *be, DB_TXN *tid, Entry *e, int flag ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_id2entry->bdi_db; DBT key, data; struct berval bv; int rc; #ifdef BDB_HIER struct berval odn, ondn; /* We only store rdns, and they go in the id2parent database. */ odn = e->e_name; ondn = e->e_nname; e->e_name = slap_empty_bv; e->e_nname = slap_empty_bv; #endif DBTzero( &key ); key.data = (char *) &e->e_id; key.size = sizeof(ID); rc = entry_encode( e, &bv ); #ifdef BDB_HIER e->e_name = odn; e->e_nname = ondn; #endif if( rc != LDAP_SUCCESS ) { return -1; } DBTzero( &data ); bv2DBT( &bv, &data ); rc = db->put( db, tid, &key, &data, flag ); free( bv.bv_val ); return rc; }