1998-08-09 08:43:13 +08:00
|
|
|
/* id2entry.c - routines to deal with the id2entry index */
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
id2entry_add( Backend *be, Entry *e )
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
struct dbcache *db;
|
|
|
|
Datum key, data;
|
1998-08-19 08:10:02 +08:00
|
|
|
int len, rc, flags;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( key );
|
|
|
|
ldbm_datum_init( data );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %lu, \"%s\" )\n", e->e_id,
|
1998-08-09 08:43:13 +08:00
|
|
|
e->e_dn, 0 );
|
|
|
|
|
|
|
|
if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
|
|
|
|
== NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
|
|
|
|
LDBM_SUFFIX, 0, 0 );
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
key.dptr = (char *) &e->e_id;
|
|
|
|
key.dsize = sizeof(ID);
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &entry2str_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
data.dptr = entry2str( e, &len, 1 );
|
|
|
|
data.dsize = len + 1;
|
|
|
|
|
1998-08-19 08:10:02 +08:00
|
|
|
/* store it */
|
|
|
|
flags = LDBM_REPLACE;
|
1998-11-07 10:25:32 +08:00
|
|
|
if ( li->li_dbcachewsync ) flags |= LDBM_SYNC;
|
1998-08-19 08:10:02 +08:00
|
|
|
rc = ldbm_cache_store( db, key, data, flags );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
ldbm_cache_close( be, db );
|
|
|
|
(void) cache_add_entry_lock( &li->li_cache, e, 0 );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= id2entry_add %d\n", rc, 0, 0 );
|
1998-09-21 04:22:46 +08:00
|
|
|
|
|
|
|
/* XXX should entries be born locked, i.e. apply writer lock here? */
|
1998-08-09 08:43:13 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
id2entry_delete( Backend *be, Entry *e )
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
struct dbcache *db;
|
|
|
|
Datum key;
|
|
|
|
int rc;
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE, "=> id2entry_delete( %lu, \"%s\" )\n", e->e_id,
|
1998-09-21 04:22:46 +08:00
|
|
|
e->e_dn, 0 );
|
|
|
|
|
1998-11-05 13:03:12 +08:00
|
|
|
#ifdef LDAP_DEBUG
|
1999-02-05 02:00:50 +08:00
|
|
|
/* check for writer lock */
|
|
|
|
assert(ldap_pvt_thread_rdwr_writers(&e->e_rdwr) == 1);
|
1998-11-05 13:03:12 +08:00
|
|
|
#endif
|
1998-09-21 04:22:46 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( key );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
|
1998-09-21 04:22:46 +08:00
|
|
|
== NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
|
|
|
|
LDBM_SUFFIX, 0, 0 );
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( cache_delete_entry( &li->li_cache, e ) != 0 ) {
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
Debug(LDAP_DEBUG_ANY, "could not delete %lu (%s) from cache\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
e->e_id, e->e_dn, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
key.dptr = (char *) &e->e_id;
|
|
|
|
key.dsize = sizeof(ID);
|
|
|
|
|
|
|
|
rc = ldbm_cache_delete( db, key );
|
|
|
|
|
|
|
|
ldbm_cache_close( be, db );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= id2entry_delete %d\n", rc, 0, 0 );
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* XXX returns entry with reader/writer lock */
|
1998-08-09 08:43:13 +08:00
|
|
|
Entry *
|
1998-09-21 04:22:46 +08:00
|
|
|
id2entry( Backend *be, ID id, int rw )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
struct dbcache *db;
|
|
|
|
Datum key, data;
|
|
|
|
Entry *e;
|
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( key );
|
|
|
|
ldbm_datum_init( data );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> id2entry_%s( %ld )\n",
|
|
|
|
rw ? "w" : "r", id, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
if ( (e = cache_find_entry_id( &li->li_cache, id, rw )) != NULL ) {
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s 0x%lx (cache)\n",
|
|
|
|
rw ? "w" : "r", (unsigned long)e, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
|
1998-09-21 04:22:46 +08:00
|
|
|
== NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "Could not open id2entry%s\n",
|
|
|
|
LDBM_SUFFIX, 0, 0 );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
key.dptr = (char *) &id;
|
|
|
|
key.dsize = sizeof(ID);
|
|
|
|
|
|
|
|
data = ldbm_cache_fetch( db, key );
|
|
|
|
|
|
|
|
if ( data.dptr == NULL ) {
|
1998-09-21 04:22:46 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) not found\n",
|
|
|
|
rw ? "w" : "r", id, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
ldbm_cache_close( be, db );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
e = str2entry( data.dptr );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
ldbm_datum_free( db->dbc_db, data );
|
|
|
|
ldbm_cache_close( be, db );
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
if ( e == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (failed)\n",
|
|
|
|
rw ? "w" : "r", id, 0 );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* acquire required reader/writer lock */
|
|
|
|
if (entry_rdwr_lock(e, rw)) {
|
|
|
|
/* XXX set DELETE flag?? */
|
|
|
|
entry_free(e);
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
e->e_id = id;
|
|
|
|
(void) cache_add_entry_lock( &li->li_cache, e, 0 );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (disk)\n",
|
|
|
|
rw ? "w" : "r", id, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( e );
|
|
|
|
}
|
1998-09-21 04:22:46 +08:00
|
|
|
|
|
|
|
Entry *
|
|
|
|
id2entry_r( Backend *be, ID id )
|
|
|
|
{
|
|
|
|
return( id2entry( be, id, 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Entry *
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
id2entry_w( Backend *be, ID id )
|
1998-09-21 04:22:46 +08:00
|
|
|
{
|
|
|
|
return( id2entry( be, id, 1 ) );
|
|
|
|
}
|
|
|
|
|