From 759638db2054a39560d8839e7af72165c6927637 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 31 May 2006 14:11:07 +0000 Subject: [PATCH] misc cleanup --- servers/slapd/back-meta/back-meta.h | 4 +--- servers/slapd/back-meta/candidates.c | 30 ++++++++++------------- servers/slapd/back-meta/conn.c | 11 +++------ servers/slapd/back-meta/search.c | 36 +++++++++++++--------------- 4 files changed, 32 insertions(+), 49 deletions(-) diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index c12067292f..0a33025a44 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -427,9 +427,7 @@ meta_back_conndn_dup( */ extern int meta_back_is_candidate( - struct berval *nsuffix, - int suffixscope, - BerVarray subtree_exclude, + metatarget_t *mt, struct berval *ndn, int scope ); diff --git a/servers/slapd/back-meta/candidates.c b/servers/slapd/back-meta/candidates.c index 27d3c2eaa1..f16a9d0eda 100644 --- a/servers/slapd/back-meta/candidates.c +++ b/servers/slapd/back-meta/candidates.c @@ -59,40 +59,38 @@ */ int meta_back_is_candidate( - struct berval *nsuffix, - int suffixscope, - BerVarray subtree_exclude, + metatarget_t *mt, struct berval *ndn, int scope ) { - if ( dnIsSuffix( ndn, nsuffix ) ) { - if ( subtree_exclude ) { + if ( dnIsSuffix( ndn, &mt->mt_nsuffix ) ) { + if ( mt->mt_subtree_exclude ) { int i; - for ( i = 0; !BER_BVISNULL( &subtree_exclude[ i ] ); i++ ) { - if ( dnIsSuffix( ndn, &subtree_exclude[ i ] ) ) { + for ( i = 0; !BER_BVISNULL( &mt->mt_subtree_exclude[ i ] ); i++ ) { + if ( dnIsSuffix( ndn, &mt->mt_subtree_exclude[ i ] ) ) { return META_NOT_CANDIDATE; } } } - switch ( suffixscope ) { + switch ( mt->mt_scope ) { case LDAP_SCOPE_SUBTREE: default: return META_CANDIDATE; case LDAP_SCOPE_SUBORDINATE: - if ( ndn->bv_len > nsuffix->bv_len ) { + if ( ndn->bv_len > mt->mt_nsuffix.bv_len ) { return META_CANDIDATE; } break; /* nearly useless; not allowed by config */ case LDAP_SCOPE_ONELEVEL: - if ( ndn->bv_len > nsuffix->bv_len ) { + if ( ndn->bv_len > mt->mt_nsuffix.bv_len ) { struct berval rdn = *ndn; - rdn.bv_len -= nsuffix->bv_len + rdn.bv_len -= mt->mt_nsuffix.bv_len + STRLENOF( "," ); if ( dnIsOneLevelRDN( &rdn ) ) { return META_CANDIDATE; @@ -102,7 +100,7 @@ meta_back_is_candidate( /* nearly useless; not allowed by config */ case LDAP_SCOPE_BASE: - if ( ndn->bv_len == nsuffix->bv_len ) { + if ( ndn->bv_len == mt->mt_nsuffix.bv_len ) { return META_CANDIDATE; } break; @@ -111,7 +109,7 @@ meta_back_is_candidate( return META_NOT_CANDIDATE; } - if ( scope == LDAP_SCOPE_SUBTREE && dnIsSuffix( nsuffix, ndn ) ) { + if ( scope == LDAP_SCOPE_SUBTREE && dnIsSuffix( &mt->mt_nsuffix, ndn ) ) { /* * suffix longer than dn, but common part matches */ @@ -139,11 +137,7 @@ meta_back_select_unique_candidate( for ( i = 0; i < mi->mi_ntargets; i++ ) { metatarget_t *mt = mi->mi_targets[ i ]; - if ( meta_back_is_candidate( &mt->mt_nsuffix, - mt->mt_scope, - mt->mt_subtree_exclude, - ndn, LDAP_SCOPE_BASE ) ) - { + if ( meta_back_is_candidate( mt, ndn, LDAP_SCOPE_BASE ) ) { if ( candidate == META_TARGET_NONE ) { candidate = i; diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index d1300d8f1c..01d8fad382 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -719,9 +719,7 @@ meta_back_get_candidate( * and a default target is defined, and it is * a candidate, try using it (FIXME: YMMV) */ if ( mi->mi_defaulttarget != META_DEFAULT_TARGET_NONE - && meta_back_is_candidate( &mi->mi_targets[ mi->mi_defaulttarget ]->mt_nsuffix, - mi->mi_targets[ mi->mi_defaulttarget ]->mt_scope, - mi->mi_targets[ mi->mi_defaulttarget ]->mt_subtree_exclude, + && meta_back_is_candidate( mi->mi_targets[ mi->mi_defaulttarget ], ndn, op->o_tag == LDAP_REQ_SEARCH ? op->ors_scope : LDAP_SCOPE_BASE ) ) { candidate = mi->mi_defaulttarget; @@ -1181,11 +1179,8 @@ retry_lock2:; metasingleconn_t *msc = &mc->mc_conns[ i ]; if ( i == cached - || meta_back_is_candidate( &mt->mt_nsuffix, - mt->mt_scope, - mt->mt_subtree_exclude, - &op->o_req_ndn, - LDAP_SCOPE_SUBTREE ) ) + || meta_back_is_candidate( mt, &op->o_req_ndn, + LDAP_SCOPE_SUBTREE ) ) { /* diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index 23925647ac..97d0ff58ef 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -235,11 +235,9 @@ meta_back_search_start( { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; metatarget_t *mt = mi->mi_targets[ candidate ]; - metaconn_t *mc = *mcp; - metasingleconn_t *msc = &mc->mc_conns[ candidate ]; + metasingleconn_t *msc = &(*mcp)->mc_conns[ candidate ]; struct berval realbase = op->o_req_dn; int realscope = op->ors_scope; - ber_len_t suffixlen = 0; struct berval mbase = BER_BVNULL; struct berval mfilter = BER_BVNULL; char **mapped_attrs = NULL; @@ -250,26 +248,10 @@ meta_back_search_start( Debug( LDAP_DEBUG_TRACE, "%s >>> meta_back_search_start[%d]\n", op->o_log_prefix, candidate, 0 ); - /* should we check return values? */ - if ( op->ors_deref != -1 ) { - assert( msc->msc_ld != NULL ); - (void)ldap_set_option( msc->msc_ld, LDAP_OPT_DEREF, - ( void * )&op->ors_deref ); - } - - if ( op->ors_tlimit != SLAP_NO_LIMIT ) { - tv.tv_sec = op->ors_tlimit > 0 ? op->ors_tlimit : 1; - tv.tv_usec = 0; - tvp = &tv; - } - - dc->target = mt; - /* * modifies the base according to the scope, if required */ - suffixlen = mt->mt_nsuffix.bv_len; - if ( suffixlen > op->o_req_ndn.bv_len ) { + if ( mt->mt_nsuffix.bv_len > op->o_req_ndn.bv_len ) { switch ( op->ors_scope ) { case LDAP_SCOPE_SUBTREE: /* @@ -341,6 +323,7 @@ meta_back_search_start( /* * Rewrite the search base, if required */ + dc->target = mt; dc->ctx = "searchBase"; switch ( ldap_back_dn_massage( dc, &realbase, &mbase ) ) { default: @@ -391,6 +374,19 @@ meta_back_search_start( goto done; } + /* should we check return values? */ + if ( op->ors_deref != -1 ) { + assert( msc->msc_ld != NULL ); + (void)ldap_set_option( msc->msc_ld, LDAP_OPT_DEREF, + ( void * )&op->ors_deref ); + } + + if ( op->ors_tlimit != SLAP_NO_LIMIT ) { + tv.tv_sec = op->ors_tlimit > 0 ? op->ors_tlimit : 1; + tv.tv_usec = 0; + tvp = &tv; + } + /* * Starts the search */ -- 2.39.5