]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/filterindex.c
return structuralObjectClass errors
[openldap] / servers / slapd / back-bdb / filterindex.c
index 11ec7d16500426f235e632575caddec9ca2389ca..13bca595f77b093d424462a0da1652f2f1008ef4 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2004 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -21,6 +21,9 @@
 
 #include "back-bdb.h"
 #include "idl.h"
+#ifdef LDAP_COMP_MATCH
+#include <component.h>
+#endif
 
 static int presence_candidates(
        Operation *op,
@@ -74,6 +77,15 @@ comp_candidates (
        ID *ids,
        ID *tmp,
        ID *stack);
+
+static int
+ava_comp_candidates (
+               Operation *op,
+               AttributeAssertion *ava,
+               AttributeAliasing *aa,
+               ID *ids,
+               ID *tmp,
+               ID *stack);
 #endif
 
 int
@@ -85,6 +97,9 @@ bdb_filter_candidates(
        ID *stack )
 {
        int rc = 0;
+#ifdef LDAP_COMP_MATCH
+       AttributeAliasing *aa;
+#endif
        Debug( LDAP_DEBUG_FILTER, "=> bdb_filter_candidates\n", 0, 0, 0 );
 
        switch ( f->f_choice ) {
@@ -114,7 +129,15 @@ bdb_filter_candidates(
 
        case LDAP_FILTER_EQUALITY:
                Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
-               rc = equality_candidates( op, f->f_ava, ids, tmp );
+#ifdef LDAP_COMP_MATCH
+               if ( is_aliased_attribute && ( aa = is_aliased_attribute ( f->f_ava->aa_desc ) ) ) {
+                       rc = ava_comp_candidates ( op, f->f_ava, aa, ids, tmp, stack );
+               }
+               else
+#endif
+               {
+                       rc = equality_candidates( op, f->f_ava, ids, tmp );
+               }
                break;
 
        case LDAP_FILTER_APPROX:
@@ -131,7 +154,7 @@ bdb_filter_candidates(
                /* if no GE index, use pres */
                Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
                if( f->f_ava->aa_desc->ad_type->sat_ordering &&
-                       ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage && SLAP_MR_ORDERED_INDEX ) )
+                       ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
                        rc = inequality_candidates( op, f->f_ava, ids, tmp, LDAP_FILTER_GE );
                else
                        rc = presence_candidates( op, f->f_ava->aa_desc, ids );
@@ -141,7 +164,7 @@ bdb_filter_candidates(
                /* if no LE index, use pres */
                Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
                if( f->f_ava->aa_desc->ad_type->sat_ordering &&
-                       ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage && SLAP_MR_ORDERED_INDEX ) )
+                       ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
                        rc = inequality_candidates( op, f->f_ava, ids, tmp, LDAP_FILTER_LE );
                else
                        rc = presence_candidates( op, f->f_ava->aa_desc, ids );
@@ -201,7 +224,6 @@ comp_list_candidates(
        ID *tmp,
        ID *save )
 {
-       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        int rc = 0;
        ComponentFilter *f;
 
@@ -275,12 +297,20 @@ comp_equality_candidates (
         MatchingRule *mr = mra->ma_rule;
         Syntax *sat_syntax;
        ComponentReference* cr_list, *cr;
+       AttrInfo *ai;
 
         BDB_IDL_ALL( bdb, ids );
 
-       bdb_attr_comp_ref ( op->o_bd->be_private, mra->ma_desc, &cr_list );
-       if( !cr_list || !ca->ca_comp_ref )
+       if ( !ca->ca_comp_ref )
                return 0;
+
+       ai = bdb_attr_mask( op->o_bd->be_private, mra->ma_desc );
+       if( ai ) {
+               cr_list = ai->ai_cr;
+       }
+       else {
+               return 0;
+       }
        /* find a component reference to be indexed */
        sat_syntax = ca->ca_ma_rule->smr_syntax;
        for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
@@ -361,6 +391,29 @@ comp_equality_candidates (
         return( rc );
 }
 
+static int
+ava_comp_candidates (
+       Operation *op,
+       AttributeAssertion *ava,
+       AttributeAliasing *aa,
+       ID *ids,
+       ID *tmp,
+       ID *stack )
+{
+       MatchingRuleAssertion mra;
+       
+       mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
+       if ( !mra.ma_rule ) {
+               struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
+               BDB_IDL_ALL( bdb, ids );
+               return 0;
+       }
+       mra.ma_desc = aa->aa_aliased_ad;
+       mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
+       
+       return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
+}
+
 static int
 comp_candidates (
        Operation *op,
@@ -420,8 +473,12 @@ ext_candidates(
         * Currently Only Component Indexing for componentFilterMatch is supported
         * Indexing for an extensible filter is not supported yet
         */
-       if ( !mra->ma_cf )
+       if ( !mra->ma_cf ) {
+               struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
+               BDB_IDL_ALL( bdb, ids );
                return 0;
+       }
+
        return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
 }
 #endif
@@ -435,7 +492,6 @@ list_candidates(
        ID *tmp,
        ID *save )
 {
-       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        int rc = 0;
        Filter  *f;
 
@@ -922,7 +978,6 @@ inequality_candidates(
 {
        struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        DB      *db;
-       int i;
        int rc;
        slap_mask_t mask;
        struct berval prefix = {0, NULL};
@@ -1010,9 +1065,11 @@ inequality_candidates(
 
                bdb_idl_union( ids, tmp );
 
-               if( BDB_IDL_IS_ZERO( ids ) )
+               if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
+                       BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
+                       cursor->c_close( cursor );
                        break;
-               i++;
+               }
        }
        ber_bvarray_free_x( keys, op->o_tmpmemctx );