X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldbm%2Ffilterindex.c;h=e7d17af8f3daf3d55eb3ab55a533a212596e63ec;hb=1586a68219cf85e9caaafcf2259c9bc249358077;hp=21a9d6ef7c44e0bd60aad7ae7ced7ea2db761f94;hpb=4bb44991757226b80fd321f194b2d6fe8a1a533d;p=openldap
diff --git a/servers/slapd/back-ldbm/filterindex.c b/servers/slapd/back-ldbm/filterindex.c
index 21a9d6ef7c..e7d17af8f3 100644
--- a/servers/slapd/back-ldbm/filterindex.c
+++ b/servers/slapd/back-ldbm/filterindex.c
@@ -1,4 +1,18 @@
/* filterindex.c - generate the list of candidate entries from a filter */
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
+ */
#include "portable.h"
@@ -10,344 +24,907 @@
#include "slap.h"
#include "back-ldbm.h"
-static IDList *ava_candidates( Backend *be, Ava *ava, int type );
-static IDList *presence_candidates( Backend *be, char *type );
-static IDList *approx_candidates( Backend *be, Ava *ava );
-static IDList *list_candidates( Backend *be, Filter *flist, int ftype );
-static IDList *substring_candidates( Backend *be, Filter *f );
-static IDList *substring_comp_candidates( Backend *be, char *type, char *val, int prepost );
-
-/*
- * test_filter - test a filter against a single entry.
- * returns 0 filter matched
- * -1 filter did not match
- * >0 an ldap error code
- */
-
-IDList *
+static ID_BLOCK *presence_candidates(
+ Operation *op,
+ AttributeDescription *desc );
+static ID_BLOCK *equality_candidates(
+ Operation *op, AttributeAssertion *ava );
+static ID_BLOCK *approx_candidates(
+ Operation *op, AttributeAssertion *ava );
+static ID_BLOCK *substring_candidates(
+ Operation *op,
+ SubstringsAssertion *sub );
+static ID_BLOCK *list_candidates(
+ Operation *op,
+ Filter *flist,
+ int ftype );
+
+ID_BLOCK *
filter_candidates(
- Backend *be,
+ Operation *op,
Filter *f
)
{
- IDList *result, *tmp1, *tmp2;
+ ID_BLOCK *result;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "filter_candidates: enter\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_TRACE, "=> filter_candidates\n", 0, 0, 0 );
+#endif
+
result = NULL;
switch ( f->f_choice ) {
+ case SLAPD_FILTER_COMPUTED:
+ switch( f->f_result ) {
+ case SLAPD_COMPARE_UNDEFINED:
+ /* This technically is not the same as FALSE, but it
+ * certainly will produce no matches.
+ */
+ /* FALLTHRU */
+ case LDAP_COMPARE_FALSE:
+ result = NULL;
+ break;
+ case LDAP_COMPARE_TRUE:
+ result = idl_allids( op->o_bd );
+ break;
+ }
+ break;
+
+ case SLAPD_FILTER_DN_ONE:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1,
+ "filter_candidates: DN ONE (%s)\n", f->f_dn, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 );
+#endif
+
+ /* an error is treated as an empty list */
+ if ( dn2idl( op->o_bd, f->f_dn, DN_ONE_PREFIX, &result ) != 0
+ && result != NULL ) {
+ idl_free( result );
+ result = NULL;
+ }
+ break;
+
+ case SLAPD_FILTER_DN_SUBTREE:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1,
+ "filter_candidates: DN SUBTREE (%s)\n", f->f_dn, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 );
+#endif
+
+ /* an error is treated as an empty list */
+ if ( dn2idl( op->o_bd, f->f_dn, DN_SUBTREE_PREFIX, &result ) != 0
+ && result != NULL ) {
+ idl_free( result );
+ result = NULL;
+ }
+ break;
+
+ case LDAP_FILTER_PRESENT:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1,
+ "filter_candidates: Present (%s)\n",
+ f->f_desc->ad_cname.bv_val, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
+#endif
+
+ result = presence_candidates( op, f->f_desc );
+ break;
+
case LDAP_FILTER_EQUALITY:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1,
+ "filter_candidates: EQUALITY (%s),(%s)\n",
+ f->f_ava->aa_desc->ad_cname.bv_val,
+ f->f_ava->aa_value.bv_val, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
- result = ava_candidates( be, &f->f_ava, LDAP_FILTER_EQUALITY );
+#endif
+
+ result = equality_candidates( op, f->f_ava );
+ break;
+
+ case LDAP_FILTER_APPROX:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1,
+ "filter_candidates: APPROX (%s), (%s)\n",
+ f->f_ava->aa_desc->ad_cname.bv_val,
+ f->f_ava->aa_value.bv_val, 0 );
+#else
+ Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
+#endif
+
+ result = approx_candidates( op, f->f_ava );
break;
case LDAP_FILTER_SUBSTRINGS:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1,
+ "filter_candidates: SUBSTRINGS\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
- result = substring_candidates( be, f );
+#endif
+
+ result = substring_candidates( op, f->f_sub );
break;
case LDAP_FILTER_GE:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "filter_candidates: GE\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
- result = ava_candidates( be, &f->f_ava, LDAP_FILTER_GE );
+#endif
+
+ result = presence_candidates( op, f->f_ava->aa_desc );
break;
case LDAP_FILTER_LE:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "filter_candidates: LE\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
- result = ava_candidates( be, &f->f_ava, LDAP_FILTER_LE );
- break;
-
- case LDAP_FILTER_PRESENT:
- Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
- result = presence_candidates( be, f->f_type );
- break;
+#endif
- case LDAP_FILTER_APPROX:
- Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
- result = approx_candidates( be, &f->f_ava );
+ result = presence_candidates( op, f->f_ava->aa_desc );
break;
case LDAP_FILTER_AND:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "filter_candidates: AND\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
- result = list_candidates( be, f->f_and, LDAP_FILTER_AND );
+#endif
+
+ result = list_candidates( op, f->f_and, LDAP_FILTER_AND );
break;
case LDAP_FILTER_OR:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "filter_candidates: OR\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
- result = list_candidates( be, f->f_or, LDAP_FILTER_OR );
+#endif
+
+ result = list_candidates( op, f->f_or, LDAP_FILTER_OR );
break;
case LDAP_FILTER_NOT:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "filter_candidates: NOT\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
- tmp1 = idl_allids( be );
- tmp2 = filter_candidates( be, f->f_not );
- result = idl_notin( be, tmp1, tmp2 );
- idl_free( tmp2 );
- idl_free( tmp1 );
+#endif
+
+ /*
+ * As candidates lists may contain entries which do
+ * not match the assertion, negation of the inner candidate
+ * list could result in matching entries be excluded from
+ * the returned candidate list.
+ */
+ result = idl_allids( op->o_bd );
+ break;
+ default:
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "filter_candidates: UNKNOWN\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN\n", 0, 0, 0 );
+#endif
+ /* unknown filters must not return NULL, to allow
+ * extended filter processing to be done later.
+ */
+ result = idl_allids( op->o_bd );
break;
}
- Debug( LDAP_DEBUG_TRACE, "<= filter_candidates %lu\n",
- result ? result->b_nids : 0, 0, 0 );
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY,
+ "filter_candidates: return %ld\n",
+ result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= filter_candidates %ld\n",
+ result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
+#endif
+
return( result );
}
-static IDList *
-ava_candidates(
- Backend *be,
- Ava *ava,
- int type
+static ID_BLOCK *
+presence_candidates(
+ Operation *op,
+ AttributeDescription *desc
)
{
- IDList *idl;
+ ID_BLOCK *idl;
+ DBCache *db;
+ int rc;
+ char *dbname;
+ slap_mask_t mask;
+ struct berval prefix = {0, NULL};
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "presence_candidates: enter\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
+#endif
- Debug( LDAP_DEBUG_TRACE, "=> ava_candidates 0x%x\n", type, 0, 0 );
+ idl = idl_allids( op->o_bd );
- switch ( type ) {
- case LDAP_FILTER_EQUALITY:
- idl = index_read( be, ava->ava_type, INDEX_EQUALITY,
- ava->ava_value.bv_val );
- break;
+ if( desc == slap_schema.si_ad_objectClass ) {
+ return idl;
+ }
- case LDAP_FILTER_GE:
- idl = idl_allids( be );
- break;
+ rc = index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
+ &dbname, &mask, &prefix );
- case LDAP_FILTER_LE:
- idl = idl_allids( be );
- break;
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO,
+ "presence_candidates: index_param returned %d\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= presence_candidates: index_param returned=%d\n",
+ rc, 0, 0 );
+#endif
+
+ return idl;
+ }
+
+ if( dbname == NULL ) {
+ /* not indexed */
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO, "presence_candidates: not indexed\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= presense_candidates: not indexed\n",
+ 0, 0, 0 );
+#endif
+
+ return idl;
+ }
+
+ db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+
+ if ( db == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO,
+ "presence_candidates: db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "<= presense_candidates db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#endif
+
+ return idl;
+ }
+
+ if( prefix.bv_val != NULL ) {
+ idl_free( idl );
+ idl = NULL;
+
+ rc = key_read( op->o_bd, db, &prefix, &idl );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "presence_candidates: key read failed (%d)\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= presense_candidates key read failed (%d)\n",
+ rc, 0, 0 );
+#endif
+
+
+ } else if( idl == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, DETAIL1, "presence_candidates: NULL\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= presense_candidates NULL\n",
+ 0, 0, 0 );
+#endif
+
+ }
}
- Debug( LDAP_DEBUG_TRACE, "<= ava_candidates %lu\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ ldbm_cache_close( op->o_bd, db );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY,
+ "presence_candidates: return %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#endif
+
return( idl );
}
-static IDList *
-presence_candidates(
- Backend *be,
- char *type
+static ID_BLOCK *
+equality_candidates(
+ Operation *op,
+ AttributeAssertion *ava
)
{
- IDList *idl;
+ ID_BLOCK *idl;
+ DBCache *db;
+ int i;
+ int rc;
+ char *dbname;
+ slap_mask_t mask;
+ struct berval prefix = {0, NULL};
+ struct berval *keys = NULL;
+ MatchingRule *mr;
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "equality_candidates: enter\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "=> equality_candidates\n", 0, 0, 0 );
+#endif
+
+
+ idl = idl_allids( op->o_bd );
+
+ rc = index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
+ &dbname, &mask, &prefix );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "equality_candidates: index_param returned %d\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= equality_candidates: index_param returned=%d\n",
+ rc, 0, 0 );
+#endif
+
+ return idl;
+ }
- Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
+ if( dbname == NULL ) {
+ /* not indexed */
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR, "equality_candidates: not indexed\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= equality_candidates: not indexed\n",
+ 0, 0, 0 );
+#endif
+
+ return idl;
+ }
+
+ mr = ava->aa_desc->ad_type->sat_equality;
+ if( !mr ) {
+ return idl;
+ }
- idl = index_read( be, type, 0, "*" );
+ if( !mr->smr_filter ) {
+ return idl;
+ }
+
+ rc = (mr->smr_filter)(
+ LDAP_FILTER_EQUALITY,
+ mask,
+ ava->aa_desc->ad_type->sat_syntax,
+ mr,
+ &prefix,
+ &ava->aa_value,
+ &keys, op->o_tmpmemctx );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "equality_candidates: (%s%s) MR filter failed (%d\n",
+ dbname, LDBM_SUFFIX, rc );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= equality_candidates: (%s%s) MR filter failed (%d)\n",
+ dbname, LDBM_SUFFIX, rc );
+#endif
+
+ return idl;
+ }
+
+ if( keys == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "equality_candidates: no keys (%s%s)\n", dbname, LDBM_SUFFIX, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= equality_candidates: no keys (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#endif
+
+ return idl;
+ }
+
+ db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+
+ if ( db == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR, "equality_candidates: db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "<= equality_candidates db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#endif
+
+ return idl;
+ }
+
+ for ( i= 0; keys[i].bv_val != NULL; i++ ) {
+ ID_BLOCK *save;
+ ID_BLOCK *tmp;
+
+ rc = key_read( op->o_bd, db, &keys[i], &tmp );
+
+ if( rc != LDAP_SUCCESS ) {
+ idl_free( idl );
+ idl = NULL;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "equality_candidates: key read failed (%d)\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= equality_candidates key read failed (%d)\n",
+ rc, 0, 0 );
+#endif
+
+ break;
+ }
+
+ if( tmp == NULL ) {
+ idl_free( idl );
+ idl = NULL;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO, "equality_candidates NULL\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= equality_candidates NULL\n",
+ 0, 0, 0 );
+#endif
+
+ break;
+ }
+
+ save = idl;
+ idl = idl_intersection( op->o_bd, idl, tmp );
+ idl_free( save );
+ idl_free( tmp );
+
+ if( idl == NULL ) break;
+ }
+
+ ber_bvarray_free_x( keys, op->o_tmpmemctx );
+
+ ldbm_cache_close( op->o_bd, db );
+
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY,
+ "equality_candidates: return %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= equality_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#endif
- Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %lu\n",
- idl ? idl->b_nids : 0, 0, 0 );
return( idl );
}
-static IDList *
+static ID_BLOCK *
approx_candidates(
- Backend *be,
- Ava *ava
+ Operation *op,
+ AttributeAssertion *ava
)
{
- char *w, *c;
- IDList *idl, *tmp;
-
+ ID_BLOCK *idl;
+ DBCache *db;
+ int i;
+ int rc;
+ char *dbname;
+ slap_mask_t mask;
+ struct berval prefix = {0, NULL};
+ struct berval *keys = NULL;
+ MatchingRule *mr;
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "approx_candidates: enter\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_TRACE, "=> approx_candidates\n", 0, 0, 0 );
+#endif
- idl = NULL;
- for ( w = first_word( ava->ava_value.bv_val ); w != NULL;
- w = next_word( w ) ) {
- c = phonetic( w );
- if ( (tmp = index_read( be, ava->ava_type, INDEX_APPROX, c ))
- == NULL ) {
- free( c );
+
+ idl = idl_allids( op->o_bd );
+
+ rc = index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
+ &dbname, &mask, &prefix );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "approx_candidates: index_param returned %d\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= approx_candidates: index_param returned=%d\n",
+ rc, 0, 0 );
+#endif
+
+ return idl;
+ }
+
+ if( dbname == NULL ) {
+ /* not indexed */
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR, "approx_candidates: not indexed\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "<= approx_candidates: not indexed\n",
+ 0, 0, 0 );
+#endif
+
+ return idl;
+ }
+
+ mr = ava->aa_desc->ad_type->sat_approx;
+ if( !mr ) {
+ /* no approx matching rule, try equality matching rule */
+ mr = ava->aa_desc->ad_type->sat_equality;
+ }
+
+ if( !mr ) {
+ return idl;
+ }
+
+ if( !mr->smr_filter ) {
+ return idl;
+ }
+
+ rc = (mr->smr_filter)(
+ LDAP_FILTER_APPROX,
+ mask,
+ ava->aa_desc->ad_type->sat_syntax,
+ mr,
+ &prefix,
+ &ava->aa_value,
+ &keys, op->o_tmpmemctx );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "approx_candidates: (%s%s) MR filter failed (%d)\n",
+ dbname, LDBM_SUFFIX, rc );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= approx_candidates: (%s%s) MR filter failed (%d)\n",
+ dbname, LDBM_SUFFIX, rc );
+#endif
+
+ return idl;
+ }
+
+ if( keys == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO,
+ "approx_candidates: no keys (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= approx_candidates: no keys (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#endif
+
+ return idl;
+ }
+
+ db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+
+ if ( db == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "approx_candidates db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "<= approx_candidates db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#endif
+
+ return idl;
+ }
+
+ for ( i= 0; keys[i].bv_val != NULL; i++ ) {
+ ID_BLOCK *save;
+ ID_BLOCK *tmp;
+
+ rc = key_read( op->o_bd, db, &keys[i], &tmp );
+
+ if( rc != LDAP_SUCCESS ) {
idl_free( idl );
+ idl = NULL;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "approx_candidates: key read failed (%d)\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= approx_candidates key read failed (%d)\n",
+ rc, 0, 0 );
+#endif
+
+ break;
+ }
+
+ if( tmp == NULL ) {
+ idl_free( idl );
+ idl = NULL;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO, "approx_candidates: NULL\n", 0, 0, 0 );
+#else
Debug( LDAP_DEBUG_TRACE, "<= approx_candidates NULL\n",
0, 0, 0 );
- return( NULL );
- }
- free( c );
+#endif
- if ( idl == NULL ) {
- idl = tmp;
- } else {
- idl = idl_intersection( be, idl, tmp );
+ break;
}
+
+ save = idl;
+ idl = idl_intersection( op->o_bd, idl, tmp );
+ idl_free( save );
+ idl_free( tmp );
+
+ if( idl == NULL ) break;
}
- Debug( LDAP_DEBUG_TRACE, "<= approx_candidates %lu\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ ber_bvarray_free_x( keys, op->o_tmpmemctx );
+
+ ldbm_cache_close( op->o_bd, db );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY,
+ "approx_candidates: return %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= approx_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#endif
+
return( idl );
}
-static IDList *
+static ID_BLOCK *
list_candidates(
- Backend *be,
+ Operation *op,
Filter *flist,
int ftype
)
{
- IDList *idl, *tmp, *tmp2;
+ ID_BLOCK *idl, *tmp, *tmp2;
Filter *f;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "list_candidates: 0x%x\n", ftype, 0, 0 );
+#else
Debug( LDAP_DEBUG_TRACE, "=> list_candidates 0x%x\n", ftype, 0, 0 );
+#endif
+
idl = NULL;
for ( f = flist; f != NULL; f = f->f_next ) {
- if ( (tmp = filter_candidates( be, f )) == NULL &&
+ if ( (tmp = filter_candidates( op, f )) == NULL &&
ftype == LDAP_FILTER_AND ) {
- Debug( LDAP_DEBUG_TRACE,
- "<= list_candidates NULL\n", 0, 0, 0 );
- idl_free( idl );
- return( NULL );
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO, "list_candidates: NULL\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= list_candidates NULL\n", 0, 0, 0 );
+#endif
+
+ idl_free( idl );
+ return( NULL );
}
tmp2 = idl;
if ( idl == NULL ) {
idl = tmp;
} else if ( ftype == LDAP_FILTER_AND ) {
- idl = idl_intersection( be, idl, tmp );
+ idl = idl_intersection( op->o_bd, idl, tmp );
idl_free( tmp );
idl_free( tmp2 );
} else {
- idl = idl_union( be, idl, tmp );
+ idl = idl_union( op->o_bd, idl, tmp );
idl_free( tmp );
idl_free( tmp2 );
}
}
- Debug( LDAP_DEBUG_TRACE, "<= list_candidates %lu\n",
- idl ? idl->b_nids : 0, 0, 0 );
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "list_candidates: return %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= list_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#endif
+
return( idl );
}
-static IDList *
+static ID_BLOCK *
substring_candidates(
- Backend *be,
- Filter *f
+ Operation *op,
+ SubstringsAssertion *sub
)
{
- int i;
- IDList *idl, *tmp, *tmp2;
+ ID_BLOCK *idl;
+ DBCache *db;
+ int i;
+ int rc;
+ char *dbname;
+ slap_mask_t mask;
+ struct berval prefix = {0, NULL};
+ struct berval *keys = NULL;
+ MatchingRule *mr;
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY, "substrings_candidates: enter\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "=> substrings_candidates\n", 0, 0, 0 );
+#endif
+
+
+ idl = idl_allids( op->o_bd );
+
+ rc = index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
+ &dbname, &mask, &prefix );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "substrings_candidates: index_param returned %d\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= substrings_candidates: index_param returned=%d\n",
+ rc, 0, 0 );
+#endif
+
+ return idl;
+ }
- Debug( LDAP_DEBUG_TRACE, "=> substring_candidates\n", 0, 0, 0 );
+ if( dbname == NULL ) {
+ /* not indexed */
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR, "substrings_candidates: not indexed\n", 0, 0, 0);
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "<= substrings_candidates: not indexed\n",
+ 0, 0, 0 );
+#endif
+
+ return idl;
+ }
- idl = NULL;
+ mr = sub->sa_desc->ad_type->sat_substr;
- /* initial */
- if ( f->f_sub_initial != NULL ) {
- if ( (int) strlen( f->f_sub_initial ) < SUBLEN - 1 ) {
- idl = idl_allids( be );
- } else if ( (idl = substring_comp_candidates( be, f->f_sub_type,
- f->f_sub_initial, '^' )) == NULL ) {
- return( NULL );
- }
+ if( !mr ) {
+ return idl;
}
- /* final */
- if ( f->f_sub_final != NULL ) {
- if ( (int) strlen( f->f_sub_final ) < SUBLEN - 1 ) {
- tmp = idl_allids( be );
- } else if ( (tmp = substring_comp_candidates( be, f->f_sub_type,
- f->f_sub_final, '$' )) == NULL ) {
- idl_free( idl );
- return( NULL );
- }
+ if( !mr->smr_filter ) {
+ return idl;
+ }
- if ( idl == NULL ) {
- idl = tmp;
- } else {
- tmp2 = idl;
- idl = idl_intersection( be, idl, tmp );
- idl_free( tmp );
- idl_free( tmp2 );
- }
+ rc = (mr->smr_filter)(
+ LDAP_FILTER_SUBSTRINGS,
+ mask,
+ sub->sa_desc->ad_type->sat_syntax,
+ mr,
+ &prefix,
+ sub,
+ &keys, op->o_tmpmemctx );
+
+ if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "substrings_candidates: (%s%s) MR filter failed (%d)\n",
+ dbname, LDBM_SUFFIX, rc );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= substrings_candidates: (%s%s) MR filter failed (%d)\n",
+ dbname, LDBM_SUFFIX, rc );
+#endif
+
+ return idl;
}
- for ( i = 0; f->f_sub_any != NULL && f->f_sub_any[i] != NULL; i++ ) {
- if ( (int) strlen( f->f_sub_any[i] ) < SUBLEN ) {
- tmp = idl_allids( be );
- } else if ( (tmp = substring_comp_candidates( be, f->f_sub_type,
- f->f_sub_any[i], 0 )) == NULL ) {
- idl_free( idl );
- return( NULL );
- }
+ if( keys == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "substrings_candidates: (0x%04lx) no keys (%s%s)\n",
+ mask, dbname, LDBM_SUFFIX );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= substrings_candidates: (0x%04lx) no keys (%s%s)\n",
+ mask, dbname, LDBM_SUFFIX );
+#endif
+
+ return idl;
+ }
- if ( idl == NULL ) {
- idl = tmp;
- } else {
- tmp2 = idl;
- idl = idl_intersection( be, idl, tmp );
- idl_free( tmp );
- idl_free( tmp2 );
- }
+ db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+
+ if ( db == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "substrings_candidates: db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "<= substrings_candidates db open failed (%s%s)\n",
+ dbname, LDBM_SUFFIX, 0 );
+#endif
+
+ return idl;
}
- Debug( LDAP_DEBUG_TRACE, "<= substring_candidates %lu\n",
- idl ? idl->b_nids : 0, 0, 0 );
- return( idl );
-}
+ for ( i= 0; keys[i].bv_val != NULL; i++ ) {
+ ID_BLOCK *save;
+ ID_BLOCK *tmp;
-static IDList *
-substring_comp_candidates(
- Backend *be,
- char *type,
- char *val,
- int prepost
-)
-{
- int i, len;
- IDList *idl, *tmp, *tmp2;
- char *p;
- char buf[SUBLEN + 1];
+ rc = key_read( op->o_bd, db, &keys[i], &tmp );
- Debug( LDAP_DEBUG_TRACE, "=> substring_comp_candidates\n", 0, 0, 0 );
+ if( rc != LDAP_SUCCESS ) {
+ idl_free( idl );
+ idl = NULL;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ERR,
+ "substrings_candidates: key read failed (%d)\n", rc, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates key read failed (%d)\n",
+ rc, 0, 0 );
+#endif
+
+ break;
+ }
- len = strlen( val );
- idl = NULL;
+ if( tmp == NULL ) {
+ idl_free( idl );
+ idl = NULL;
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, INFO, "substrings_candidates: NULL\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates NULL\n",
+ 0, 0, 0 );
+#endif
- /* prepend ^ for initial substring */
- if ( prepost == '^' ) {
- buf[0] = '^';
- for ( i = 0; i < SUBLEN - 1; i++ ) {
- buf[i + 1] = val[i];
+ break;
}
- buf[SUBLEN] = '\0';
- if ( (idl = index_read( be, type, INDEX_SUB, buf )) == NULL ) {
- return( NULL );
- }
- } else if ( prepost == '$' ) {
- p = val + len - SUBLEN + 1;
- for ( i = 0; i < SUBLEN - 1; i++ ) {
- buf[i] = p[i];
- }
- buf[SUBLEN - 1] = '$';
- buf[SUBLEN] = '\0';
+ save = idl;
+ idl = idl_intersection( op->o_bd, idl, tmp );
+ idl_free( save );
+ idl_free( tmp );
- if ( (idl = index_read( be, type, INDEX_SUB, buf )) == NULL ) {
- return( NULL );
- }
+ if( idl == NULL ) break;
}
- for ( p = val; p < (val + len - SUBLEN + 1); p++ ) {
- for ( i = 0; i < SUBLEN; i++ ) {
- buf[i] = p[i];
- }
- buf[SUBLEN] = '\0';
+ ber_bvarray_free_x( keys, op->o_tmpmemctx );
- if ( (tmp = index_read( be, type, INDEX_SUB, buf )) == NULL ) {
- idl_free( idl );
- return( NULL );
- }
+ ldbm_cache_close( op->o_bd, db );
- if ( idl == NULL ) {
- idl = tmp;
- } else {
- tmp2 = idl;
- idl = idl_intersection( be, idl, tmp );
- idl_free( tmp );
- idl_free( tmp2 );
- }
- }
+#ifdef NEW_LOGGING
+ LDAP_LOG( FILTER, ENTRY,
+ "substrings_candidates: return %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+#endif
- Debug( LDAP_DEBUG_TRACE, "<= substring_comp_candidates %lu\n",
- idl ? idl->b_nids : 0, 0, 0 );
return( idl );
}