From 5ad8efbb473f14d52a16e11862559ae5133c7469 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 3 Jul 2001 11:23:18 +0000 Subject: [PATCH] Used API signature from back-bdb; compiles and passes make test --- servers/slapd/back-ldbm/add.c | 9 ++-- servers/slapd/back-ldbm/dn2id.c | 52 +++++++++++------------ servers/slapd/back-ldbm/modrdn.c | 3 +- servers/slapd/back-ldbm/proto-back-ldbm.h | 2 +- servers/slapd/back-ldbm/tools.c | 11 ++--- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index 65fa8748a9..5ff80d36b1 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -28,7 +28,8 @@ ldbm_back_add( char *pdn; Entry *p = NULL; int rootlock = 0; - int rc, rc_id; + int rc; + ID id = NOID; const char *text = NULL; AttributeDescription *children = slap_schema.si_ad_children; char textbuf[SLAP_TEXT_BUFLEN]; @@ -45,11 +46,11 @@ ldbm_back_add( /* nobody else can add until we lock our parent */ ldap_pvt_thread_mutex_lock(&li->li_add_mutex); - if ( ( dn2id( be, e->e_ndn, &rc_id ) ) != NOID || rc_id ) { - /* if (rc_id) something bad happened to ldbm cache */ + if ( ( rc = dn2id( be, e->e_ndn, &id ) ) || id != NOID ) { + /* if (rc) something bad happened to ldbm cache */ ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); send_ldap_result( conn, op, - rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS, + rc ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS, NULL, NULL, NULL, NULL ); return( -1 ); } diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 0dc80f0710..088bc45bb0 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -113,20 +113,17 @@ dn2id_add( return( rc ); } -ID +int dn2id( Backend *be, const char *dn, - int *rc + ID *idp ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; DBCache *db; - ID id; Datum key, data; - *rc = 0; - #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, "dn2id: (%s)\n", dn )); @@ -134,18 +131,19 @@ dn2id( Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 ); #endif + assert( idp ); /* first check the cache */ - if ( (id = cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) { + if ( (*idp = cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) { #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, - "dn2id: (%s)%ld in cache.\n", dn, id )); + "dn2id: (%s)%ld in cache.\n", dn, *idp )); #else - Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld (in cache)\n", id, + Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld (in cache)\n", *idp, 0, 0 ); #endif - return( id ); + return( 0 ); } if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) @@ -161,8 +159,8 @@ dn2id( * return code !0 if ldbm cache open failed; * callers should handle this */ - *rc = -1; - return( NOID ); + *idp = NOID; + return( -1 ); } ldbm_datum_init( key ); @@ -185,23 +183,24 @@ dn2id( Debug( LDAP_DEBUG_TRACE, "<= dn2id NOID\n", 0, 0, 0 ); #endif - return( NOID ); + *idp = NOID; + return( 0 ); } - AC_MEMCPY( (char *) &id, data.dptr, sizeof(ID) ); + AC_MEMCPY( (char *) idp, data.dptr, sizeof(ID) ); - assert( id != NOID ); + assert( *idp != NOID ); ldbm_datum_free( db->dbc_db, data ); #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, - "dn2id: %ld\n", id )); + "dn2id: %ld\n", *idp )); #else - Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld\n", id, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld\n", *idp, 0, 0 ); #endif - return( id ); + return( 0 ); } ID_BLOCK * @@ -363,7 +362,6 @@ dn2entry_rw( ID id; Entry *e = NULL; char *pdn; - int rc_id = 0; #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, @@ -380,13 +378,16 @@ dn2entry_rw( *matched = NULL; } - if ( (id = dn2id( be, dn, &rc_id )) != NOID && - (e = id2entry_rw( be, id, rw )) != NULL ) - { - return( e ); - } + if ( dn2id( be, dn, &id ) ) { + /* something bad happened to ldbm cache */ + return( NULL ); + + } else if ( id != NOID ) { + /* try to return the entry */ + if ((e = id2entry_rw( be, id, rw )) != NULL ) { + return( e ); + } - if ( id != NOID ) { #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ERR, "dn2entry_rw: no entry for valid id (%ld), dn (%s)\n", @@ -399,9 +400,6 @@ dn2entry_rw( /* must have been deleted from underneath us */ /* treat as if NOID was found */ - } else if ( rc_id ) { - /* something bad happened to ldbm cache */ - return NULL; } /* caller doesn't care about match */ diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 01661991e0..ed804339ad 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -52,6 +52,7 @@ ldbm_back_modrdn( Entry *matched; int rootlock = 0; int rc = -1, rc_id = 0; + ID id = NOID; const char *text = NULL; char textbuf[SLAP_TEXT_BUFLEN]; size_t textlen = sizeof textbuf; @@ -380,7 +381,7 @@ ldbm_back_modrdn( } ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); - if (dn2id ( be, new_ndn, &rc_id ) != NOID || rc_id ) { + if ( ( rc_id = dn2id ( be, new_ndn, &id ) ) || id != NOID ) { /* if (rc_id) something bad happened to ldbm cache */ send_ldap_result( conn, op, rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS, diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index ccefe6d583..350120a3b0 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -77,7 +77,7 @@ void *ldbm_cache_sync_daemon LDAP_P(( void *)); */ int dn2id_add LDAP_P(( Backend *be, const char *dn, ID id )); -ID dn2id LDAP_P(( Backend *be, const char *dn, int *rc )); +int dn2id LDAP_P(( Backend *be, const char *dn, ID *idp )); ID_BLOCK *dn2idl LDAP_P(( Backend *be, const char *dn, int prefix )); int dn2id_delete LDAP_P(( Backend *be, const char *dn, ID id )); diff --git a/servers/slapd/back-ldbm/tools.c b/servers/slapd/back-ldbm/tools.c index 6bbbfc6166..94d0dc6387 100644 --- a/servers/slapd/back-ldbm/tools.c +++ b/servers/slapd/back-ldbm/tools.c @@ -156,7 +156,7 @@ ID ldbm_tool_entry_put( { struct ldbminfo *li = (struct ldbminfo *) be->be_private; Datum key, data; - int rc, len, rc_id; + int rc, len; ID id; assert( slapMode & SLAP_TOOL_MODE ); @@ -176,7 +176,11 @@ ID ldbm_tool_entry_put( e->e_id, e->e_dn, 0 ); #endif - id = dn2id( be, e->e_ndn, &rc_id ); + if ( dn2id( be, e->e_ndn, &id ) ) { + /* something bad happened to ldbm cache */ + return NOID; + } + if( id != NOID ) { #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, @@ -188,9 +192,6 @@ ID ldbm_tool_entry_put( e->e_ndn, id, 0 ); #endif return NOID; - } else if ( rc_id ) { - /* something bad happened to ldbm cache */ - return NOID; } rc = index_entry_add( be, e, e->e_attrs ); -- 2.39.5