/* filterindex.c - generate the list of candidate entries from a filter */
/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
Filter *f
)
{
- ID_BLOCK *result, *tmp1, *tmp2;
+ ID_BLOCK *result;
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY, "filter_candidates: enter\n"));
case LDAP_FILTER_PRESENT:
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
- "filter_candidates: Present (%s)\n", f->f_desc->ad_cname->bv_val ));
+ "filter_candidates: Present (%s)\n", f->f_desc->ad_cname.bv_val ));
#else
Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
#endif
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
"filter_candidates: EQUALITY (%s),(%s)\n",
- f->f_ava->aa_desc->ad_cname->bv_val,
- f->f_ava->aa_value->bv_val ));
+ f->f_ava->aa_desc->ad_cname.bv_val,
+ f->f_ava->aa_value.bv_val ));
#else
Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
#endif
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
"filter_candidates: APPROX (%s), (%s)\n",
- f->f_ava->aa_desc->ad_cname->bv_val,
- f->f_ava->aa_value->bv_val ));
+ f->f_ava->aa_desc->ad_cname.bv_val,
+ f->f_ava->aa_value.bv_val ));
#else
Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
#endif
Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
#endif
- result = idl_allids( be );
+ result = presence_candidates( be, f->f_ava->aa_desc );
break;
case LDAP_FILTER_LE:
Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
#endif
- result = idl_allids( be );
+ result = presence_candidates( be, f->f_ava->aa_desc );
break;
case LDAP_FILTER_AND:
Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
#endif
- tmp1 = idl_allids( be );
- tmp2 = filter_candidates( be, f->f_not );
- result = idl_notin( be, tmp1, tmp2 );
- idl_free( tmp2 );
- idl_free( tmp1 );
+ /*
+ * 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( be );
+ break;
+ default:
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
+ "filter_candidates: UNKNOWN\n" ));
+#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( be );
break;
}
int rc;
char *dbname;
slap_mask_t mask;
- struct berval *prefix;
+ struct berval prefix = {0};
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
#endif
-
idl = idl_allids( be );
+ if( desc == slap_schema.si_ad_objectClass ) {
+ return idl;
+ }
+
rc = index_param( be, desc, LDAP_FILTER_PRESENT,
&dbname, &mask, &prefix );
0, 0, 0 );
#endif
- ber_bvfree( prefix );
return idl;
}
- db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_READER );
+ db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
if ( db == NULL ) {
#ifdef NEW_LOGGING
dbname, LDBM_SUFFIX, 0 );
#endif
- ber_bvfree( prefix );
return idl;
}
- if( prefix != NULL ) {
+ if( prefix.bv_val != NULL ) {
idl_free( idl );
idl = NULL;
- rc = key_read( be, db, prefix, &idl );
+ rc = key_read( be, db, &prefix, &idl );
if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
}
ldbm_cache_close( be, db );
- ber_bvfree( prefix );
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
int rc;
char *dbname;
slap_mask_t mask;
- struct berval *prefix;
- struct berval **keys = NULL;
+ struct berval prefix = {0};
+ struct berval *keys = NULL;
MatchingRule *mr;
#ifdef NEW_LOGGING
0, 0, 0 );
#endif
- ber_bvfree( prefix );
return idl;
}
mr = ava->aa_desc->ad_type->sat_equality;
if( !mr ) {
- ber_bvfree( prefix );
return idl;
}
if( !mr->smr_filter ) {
- ber_bvfree( prefix );
return idl;
}
mask,
ava->aa_desc->ad_type->sat_syntax,
mr,
- prefix,
- ava->aa_value,
+ &prefix,
+ &ava->aa_value,
&keys );
- ber_bvfree( prefix );
-
if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
return idl;
}
- db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_READER );
+ db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
if ( db == NULL ) {
#ifdef NEW_LOGGING
return idl;
}
- for ( i= 0; keys[i] != NULL; i++ ) {
+ for ( i= 0; keys[i].bv_val != NULL; i++ ) {
ID_BLOCK *save;
ID_BLOCK *tmp;
- rc = key_read( be, db, keys[i], &tmp );
+ rc = key_read( be, db, &keys[i], &tmp );
if( rc != LDAP_SUCCESS ) {
idl_free( idl );
if( idl == NULL ) break;
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
ldbm_cache_close( be, db );
int rc;
char *dbname;
slap_mask_t mask;
- struct berval *prefix;
- struct berval **keys = NULL;
+ struct berval prefix = {0};
+ struct berval *keys = NULL;
MatchingRule *mr;
#ifdef NEW_LOGGING
0, 0, 0 );
#endif
- ber_bvfree( prefix );
return idl;
}
}
if( !mr ) {
- ber_bvfree( prefix );
return idl;
}
if( !mr->smr_filter ) {
- ber_bvfree( prefix );
return idl;
}
mask,
ava->aa_desc->ad_type->sat_syntax,
mr,
- prefix,
- ava->aa_value,
+ &prefix,
+ &ava->aa_value,
&keys );
- ber_bvfree( prefix );
-
if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
return idl;
}
- db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_READER );
+ db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
if ( db == NULL ) {
#ifdef NEW_LOGGING
return idl;
}
- for ( i= 0; keys[i] != NULL; i++ ) {
+ for ( i= 0; keys[i].bv_val != NULL; i++ ) {
ID_BLOCK *save;
ID_BLOCK *tmp;
- rc = key_read( be, db, keys[i], &tmp );
+ rc = key_read( be, db, &keys[i], &tmp );
if( rc != LDAP_SUCCESS ) {
idl_free( idl );
if( idl == NULL ) break;
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
ldbm_cache_close( be, db );
int rc;
char *dbname;
slap_mask_t mask;
- struct berval *prefix;
- struct berval **keys = NULL;
+ struct berval prefix = {0};
+ struct berval *keys = NULL;
MatchingRule *mr;
#ifdef NEW_LOGGING
0, 0, 0 );
#endif
- ber_bvfree( prefix );
return idl;
}
mr = sub->sa_desc->ad_type->sat_substr;
if( !mr ) {
- ber_bvfree( prefix );
return idl;
}
if( !mr->smr_filter ) {
- ber_bvfree( prefix );
return idl;
}
mask,
sub->sa_desc->ad_type->sat_syntax,
mr,
- prefix,
+ &prefix,
sub,
&keys );
- ber_bvfree( prefix );
-
if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
return idl;
}
- db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_READER );
+ db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
if ( db == NULL ) {
#ifdef NEW_LOGGING
return idl;
}
- for ( i= 0; keys[i] != NULL; i++ ) {
+ for ( i= 0; keys[i].bv_val != NULL; i++ ) {
ID_BLOCK *save;
ID_BLOCK *tmp;
- rc = key_read( be, db, keys[i], &tmp );
+ rc = key_read( be, db, &keys[i], &tmp );
if( rc != LDAP_SUCCESS ) {
idl_free( idl );
if( idl == NULL ) break;
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
ldbm_cache_close( be, db );