1 /* id2entry.c - routines to deal with the id2entry database */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
21 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
22 DB *db = bdb->bi_id2entry->bdi_db;
28 key.data = (char *) &e->e_id;
29 key.size = sizeof(ID);
31 rc = entry_encode( e, &bv );
32 if( rc != LDAP_SUCCESS ) {
39 rc = db->put( db, tid, &key, &data, flag );
50 return bdb_id2entry_put( be, tid, e, DB_NOOVERWRITE );
53 int bdb_id2entry_update(
58 return bdb_id2entry_put( be, tid, e, 0 );
67 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
68 DB *db = bdb->bi_id2entry->bdi_db;
76 key.data = (char *) &id;
77 key.size = sizeof(ID);
80 data.flags = DB_DBT_MALLOC;
83 rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags );
91 rc = entry_decode( &bv, e );
96 /* only free on error. On success, the entry was
104 int bdb_id2entry_delete(
109 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
110 DB *db = bdb->bi_id2entry->bdi_db;
115 key.data = (char *) &id;
116 key.size = sizeof(ID);
118 rc = db->del( db, tid, &key, 0 );
123 int bdb_entry_return(
127 /* Our entries are allocated in two blocks; the data comes from
128 * the db itself and the Entry structure and associated pointers
129 * are allocated in entry_decode. The db data pointer is saved
130 * in e_private. Since the Entry structure is allocated as a single
131 * block, e_attrs is always a fixed offset from e. The exception
132 * is when an entry has been modified, in which case we also need
135 if( (void *) e->e_attrs != (void *) (e+1)) {
136 attrs_free( e->e_attrs );
139 free( e->e_private );
146 int bdb_entry_release(
153 /* A tool will call this with NULL Connection and Operation
154 * pointers. We don't need to free the e_private in that case,
155 * because the tool is getting entries into a realloc'd
159 return bdb_entry_return( be, e );