1 /* id2entry.c - routines to deal with the id2entry index */
5 #include <sys/socket.h>
9 extern struct dbcache *ldbm_cache_open();
10 extern Datum ldbm_cache_fetch();
11 extern char *dn_parent();
12 extern Entry *str2entry();
13 extern Entry *cache_find_entry_id();
14 extern char *entry2str();
15 extern pthread_mutex_t entry2str_mutex;
18 id2entry_add( Backend *be, Entry *e )
20 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
25 Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %d, \"%s\" )\n", e->e_id,
28 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
30 Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
35 key.dptr = (char *) &e->e_id;
36 key.dsize = sizeof(ID);
38 pthread_mutex_lock( &entry2str_mutex );
39 data.dptr = entry2str( e, &len, 1 );
42 /* store it - LDBM_SYNC ensures id2entry is always consistent */
43 rc = ldbm_cache_store( db, key, data, LDBM_REPLACE|LDBM_SYNC );
45 pthread_mutex_unlock( &entry2str_mutex );
47 ldbm_cache_close( be, db );
48 (void) cache_add_entry_lock( &li->li_cache, e, 0 );
50 Debug( LDAP_DEBUG_TRACE, "<= id2entry_add %d\n", rc, 0, 0 );
55 id2entry_delete( Backend *be, Entry *e )
57 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
62 Debug( LDAP_DEBUG_TRACE, "=> id2entry_delete( %d, \"%s\" )\n", e->e_id,
65 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
67 Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
72 if ( cache_delete_entry( &li->li_cache, e ) != 0 ) {
73 Debug( LDAP_DEBUG_ANY, "could not delete %d (%s) from cache\n",
74 e->e_id, e->e_dn, 0 );
77 key.dptr = (char *) &e->e_id;
78 key.dsize = sizeof(ID);
80 rc = ldbm_cache_delete( db, key );
82 ldbm_cache_close( be, db );
84 Debug( LDAP_DEBUG_TRACE, "<= id2entry_delete %d\n", rc, 0, 0 );
89 id2entry( Backend *be, ID id )
91 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
96 Debug( LDAP_DEBUG_TRACE, "=> id2entry( %ld )\n", id, 0, 0 );
98 if ( (e = cache_find_entry_id( &li->li_cache, id )) != NULL ) {
99 Debug( LDAP_DEBUG_TRACE, "<= id2entry 0x%x (cache)\n", e, 0,
104 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
106 Debug( LDAP_DEBUG_ANY, "Could not open id2entry%s\n",
111 key.dptr = (char *) &id;
112 key.dsize = sizeof(ID);
114 data = ldbm_cache_fetch( db, key );
116 if ( data.dptr == NULL ) {
117 Debug( LDAP_DEBUG_TRACE, "<= id2entry( %ld ) not found\n", id,
119 ldbm_cache_close( be, db );
123 if ( (e = str2entry( data.dptr )) != NULL ) {
125 (void) cache_add_entry_lock( &li->li_cache, e, 0 );
128 ldbm_datum_free( db->dbc_db, data );
129 ldbm_cache_close( be, db );
131 Debug( LDAP_DEBUG_TRACE, "<= id2entry( %ld ) 0x%x (disk)\n", id, e, 0 );