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>
20 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
21 DB *db = bdb->bi_id2entry->bdi_db;
27 key.data = (char *) &e->e_id;
28 key.size = sizeof(ID);
30 rc = entry_encode( e, &bv );
31 if( rc != LDAP_SUCCESS ) {
38 rc = db->put( db, tid, &key, &data, DB_NOOVERWRITE );
44 int bdb_id2entry_update(
49 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
50 DB *db = bdb->bi_id2entry->bdi_db;
56 key.data = (char *) &e->e_id;
57 key.size = sizeof(ID);
59 rc = entry_encode( e, &bv );
60 if( rc != LDAP_SUCCESS ) {
67 rc = db->put( db, tid, &key, &data, 0 );
79 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
80 DB *db = bdb->bi_id2entry->bdi_db;
88 key.data = (char *) &id;
89 key.size = sizeof(ID);
92 data.flags = DB_DBT_MALLOC;
95 rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags );
101 DBT2bv( &data, &bv );
103 rc = entry_decode( &bv, e );
108 /* only free on error. On success, the entry was
111 ch_free( data.data );
116 int bdb_id2entry_delete(
121 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
122 DB *db = bdb->bi_id2entry->bdi_db;
127 key.data = (char *) &id;
128 key.size = sizeof(ID);
130 rc = db->del( db, tid, &key, 0 );
135 int bdb_entry_return(
139 /* Our entries are allocated in two blocks; the data comes from
140 * the db itself and the Entry structure and associated pointers
141 * are allocated in entry_decode. The db data pointer is saved
142 * in e_private. Since the Entry structure is allocated as a single
143 * block, e_attrs is always a fixed offset from e. The exception
144 * is when an entry has been modified, in which case we also need
147 if( (void *) e->e_attrs != (void *) (e+1)) {
148 attrs_free( e->e_attrs );
151 free( e->e_private );
158 int bdb_entry_release(
165 /* A tool will call this with NULL Connection and Operation
166 * pointers. We don't need to free the e_private in that case,
167 * because the tool is getting entries into a realloc'd
171 return bdb_entry_return( be, e );