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, 0 );
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 almost always contiguous blocks, so a single
140 * free() on the Entry pointer suffices. The exception is when
141 * an entry has been modified, in which case the attr list will
142 * have been alloc'd separately.
144 if( (void *) e->e_attrs < (void *) e
145 || (void *) e->e_attrs > e->e_private )
147 attrs_free(e->e_attrs);