From 369ee86107f26d9085f32be8c164f2378a674af4 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 9 Dec 2001 03:09:18 +0000 Subject: [PATCH] Cleaned up search, use dn_issuffixbv --- servers/slapd/backglue.c | 74 +++++++++++----------------------------- 1 file changed, 20 insertions(+), 54 deletions(-) diff --git a/servers/slapd/backglue.c b/servers/slapd/backglue.c index 1bf44af818..2e465df9ee 100644 --- a/servers/slapd/backglue.c +++ b/servers/slapd/backglue.c @@ -54,10 +54,14 @@ glue_back_select ( ) { glueinfo *gi = (glueinfo *) be->be_private; + struct berval bv; int i; + bv.bv_len = strlen(dn); + bv.bv_val = dn; + for (i = 0; be->be_nsuffix[i]; i++) { - if (dn_issuffix (dn, be->be_nsuffix[i]->bv_val)) + if (dn_issuffixbv (&bv, be->be_nsuffix[i])) return gi->n[i].be; } return NULL; @@ -236,7 +240,6 @@ glue_back_response ( j = gs->nrefs; if (!j) { new = ch_malloc ((i+1)*sizeof(struct berval *)); - gs->nrefs = i; } else { new = ch_realloc(gs->refs, (j+i+1)*sizeof(struct berval *)); @@ -291,6 +294,7 @@ glue_back_search ( int i, rc, t2limit = 0, s2limit = 0; long stoptime = 0; glue_state gs = {0}; + struct berval bv; if (tlimit) @@ -312,15 +316,18 @@ glue_back_search ( return rc; case LDAP_SCOPE_ONELEVEL: + case LDAP_SCOPE_SUBTREE: op->o_glue = &gs; op->o_sresult = glue_back_sresult; op->o_response = glue_back_response; + bv.bv_len = strlen(ndn); + bv.bv_val = ndn; /* * Execute in reverse order, most general first */ for (i = gi->nodes-1; i >= 0; i--) { - if (!gi->n[i].be->be_search) + if (!gi->n[i].be || !gi->n[i].be->be_search) continue; if (tlimit) { t2limit = stoptime - slap_get_time (); @@ -342,69 +349,28 @@ glue_back_search ( rc = 0; goto done; } - if (!strcmp (gi->n[i].pdn, ndn)) { - be = gi->n[i].be; + be = gi->n[i].be; + if (scope == LDAP_SCOPE_ONELEVEL && + !strcmp (gi->n[i].pdn, ndn)) { rc = be->be_search (be, conn, op, b0->be_suffix[i], - b0->be_nsuffix[i]->bv_val, + b0->be_nsuffix[i]->bv_val, LDAP_SCOPE_BASE, deref, s2limit, t2limit, filter, filterstr, attrs, attrsonly); - } else if (dn_issuffix (ndn, b0->be_nsuffix[i]->bv_val)) { - be = gi->n[i].be; + } else if (scope == LDAP_SCOPE_SUBTREE && + dn_issuffixbv (b0->be_nsuffix[i], &bv)) { rc = be->be_search (be, conn, op, - dn, ndn, scope, deref, + b0->be_suffix[i], + b0->be_nsuffix[i]->bv_val, + scope, deref, s2limit, t2limit, filter, filterstr, attrs, attrsonly); - } - } - break; - - case LDAP_SCOPE_SUBTREE: - op->o_glue = &gs; - op->o_sresult = glue_back_sresult; - op->o_response = glue_back_response; - - /* - * Execute in reverse order, most general first - */ - for (i = gi->nodes-1; i >= 0; i--) { - if (!gi->n[i].be->be_search) - continue; - if (tlimit) { - t2limit = stoptime - slap_get_time (); - if (t2limit <= 0) - break; - } - if (slimit) { - s2limit = slimit - gs.nentries; - if (s2limit <= 0) - break; - } - /* - * check for abandon - */ - ldap_pvt_thread_mutex_lock (&op->o_abandonmutex); - rc = op->o_abandon; - ldap_pvt_thread_mutex_unlock (&op->o_abandonmutex); - if (rc) { - rc = 0; - goto done; - } - if (dn_issuffix (ndn, b0->be_nsuffix[i]->bv_val)) { - be = gi->n[i].be; + } else if (dn_issuffix (&bv, b0->be_nsuffix[i])) { rc = be->be_search (be, conn, op, dn, ndn, scope, deref, s2limit, t2limit, filter, filterstr, attrs, attrsonly); - } else if (dn_issuffix (b0->be_nsuffix[i]->bv_val, ndn)) { - be = gi->n[i].be; - rc = be->be_search (be, conn, op, - b0->be_suffix[i], - b0->be_nsuffix[i]->bv_val, - scope, deref, - s2limit, t2limit, filter, filterstr, - attrs, attrsonly); } } break; -- 2.39.5