]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/matchedValues.c
filter_candidate tweaks, search_stack tweaks
[openldap] / servers / slapd / matchedValues.c
index 170977d0eeb46b61ee4b0f014d2a5b8a7bb70d1e..39cb6426bb8efd85440900b3ca94e4f9dd117524 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /* 
- * Copyright 1999-2002 The OpenLDAP Foundation.
+ * Copyright 1999-2003 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted only
 
 #include "slap.h"
 
-#include "../../libraries/liblber/lber-int.h"
-
-static int test_mra_vrFilter(
-       Backend         *be,
-       Connection      *conn,
+static int
+test_mra_vrFilter(
        Operation       *op,
        Attribute       *a,
        MatchingRuleAssertion *mra,
@@ -30,8 +27,6 @@ static int test_mra_vrFilter(
 
 static int
 test_substrings_vrFilter(
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
        ValuesReturnFilter *f,
@@ -40,8 +35,6 @@ test_substrings_vrFilter(
 
 static int
 test_presence_vrFilter(
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
        AttributeDescription *desc,
@@ -50,8 +43,6 @@ test_presence_vrFilter(
 
 static int
 test_ava_vrFilter(
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
        AttributeAssertion *ava,
@@ -62,14 +53,12 @@ test_ava_vrFilter(
 
 int
 filter_matched_values( 
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
        char            ***e_flags
 )
 {
-       ValuesReturnFilter *f;
+       ValuesReturnFilter *vrf;
        int             rc = LDAP_SUCCESS;
 
 #ifdef NEW_LOGGING
@@ -78,22 +67,22 @@ filter_matched_values(
        Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
 #endif
 
-       for ( f = op->vrFilter; f != NULL; f = f->f_next ) {
-               switch ( f->f_choice ) {
+       for ( vrf = op->vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
+               switch ( vrf->vrf_choice ) {
                case SLAPD_FILTER_COMPUTED:
 #ifdef NEW_LOGGING
                        LDAP_LOG( FILTER, DETAIL1, 
                                "test_vrFilter: COMPUTED %s (%d)\n",
-                               f->f_result == LDAP_COMPARE_FALSE ? "false" :
-                               f->f_result == LDAP_COMPARE_TRUE         ? "true"  :
-                               f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
-                               "error", f->f_result, 0 );
+                               vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
+                               vrf->vrf_result == LDAP_COMPARE_TRUE     ? "true"  :
+                               vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
+                               "error", vrf->vrf_result, 0 );
 #else
                        Debug( LDAP_DEBUG_FILTER, "     COMPUTED %s (%d)\n",
-                               f->f_result == LDAP_COMPARE_FALSE ? "false" :
-                               f->f_result == LDAP_COMPARE_TRUE ? "true" :
-                               f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
-                               f->f_result, 0 );
+                               vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
+                               vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
+                               vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
+                               vrf->vrf_result, 0 );
 #endif
                        /*This type of filter does not affect the result */
                        rc = LDAP_SUCCESS;
@@ -105,7 +94,7 @@ filter_matched_values(
 #else
                        Debug( LDAP_DEBUG_FILTER, "     EQUALITY\n", 0, 0, 0 );
 #endif
-                       rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
+                       rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
                                LDAP_FILTER_EQUALITY, e_flags );
                        if( rc == -1 ) {
                                return rc;
@@ -119,8 +108,8 @@ filter_matched_values(
                        Debug( LDAP_DEBUG_FILTER, "     SUBSTRINGS\n", 0, 0, 0 );
 #endif
 
-                       rc = test_substrings_vrFilter( be, conn, op, a,
-                               f, e_flags );
+                       rc = test_substrings_vrFilter( op, a,
+                               vrf, e_flags );
                        if( rc == -1 ) {
                                return rc;
                        }
@@ -132,15 +121,15 @@ filter_matched_values(
 #else
                        Debug( LDAP_DEBUG_FILTER, "     PRESENT\n", 0, 0, 0 );
 #endif
-                       rc = test_presence_vrFilter( be, conn, op, a,
-                               f->f_desc, e_flags );
+                       rc = test_presence_vrFilter( op, a,
+                               vrf->vrf_desc, e_flags );
                        if( rc == -1 ) {
                                return rc;
                        }
                        break;
 
                case LDAP_FILTER_GE:
-                       rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
+                       rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
                                LDAP_FILTER_GE, e_flags );
                        if( rc == -1 ) {
                                return rc;
@@ -148,7 +137,7 @@ filter_matched_values(
                        break;
 
                case LDAP_FILTER_LE:
-                       rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
+                       rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
                                LDAP_FILTER_LE, e_flags );
                        if( rc == -1 ) {
                                return rc;
@@ -161,8 +150,8 @@ filter_matched_values(
 #else
                        Debug( LDAP_DEBUG_FILTER, "     EXT\n", 0, 0, 0 );
 #endif
-                       rc = test_mra_vrFilter( be, conn, op, a,
-                               f->f_mra, e_flags );
+                       rc = test_mra_vrFilter( op, a,
+                               vrf->vrf_mra, e_flags );
                        if( rc == -1 ) {
                                return rc;
                        }
@@ -171,10 +160,10 @@ filter_matched_values(
                default:
 #ifdef NEW_LOGGING
                        LDAP_LOG( FILTER, INFO, 
-                               "test_vrFilter:  unknown filter type %lu\n", f->f_choice, 0, 0 );
+                               "test_vrFilter:  unknown filter type %lu\n", vrf->vrf_choice, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY, "        unknown filter type %lu\n",
-                               f->f_choice, 0, 0 );
+                               vrf->vrf_choice, 0, 0 );
 #endif
                        rc = LDAP_PROTOCOL_ERROR;
                } 
@@ -190,8 +179,6 @@ filter_matched_values(
 
 static int
 test_ava_vrFilter(
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
        AttributeAssertion *ava,
@@ -234,13 +221,14 @@ test_ava_vrFilter(
 
                }
 
-               for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ ) {
+               bv = a->a_nvals;
+               for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
                        int ret;
                        int rc;
                        const char *text;
 
-                       rc = value_match( &ret, a->a_desc, mr, 
-                               SLAP_MR_ASSERTION_SYNTAX_MATCH, bv, &ava->aa_value, &text );
+                       rc = value_match( &ret, a->a_desc, mr, 0,
+                               bv, &ava->aa_value, &text );
                        if( rc != LDAP_SUCCESS ) {
                                return rc;
                        }
@@ -272,8 +260,6 @@ test_ava_vrFilter(
 
 static int
 test_presence_vrFilter(
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
        AttributeDescription *desc,
@@ -298,11 +284,9 @@ test_presence_vrFilter(
 
 static int
 test_substrings_vrFilter(
-       Backend         *be,
-       Connection      *conn,
        Operation       *op,
        Attribute       *a,
-       ValuesReturnFilter *f,
+       ValuesReturnFilter *vrf,
        char            ***e_flags
 )
 {
@@ -312,7 +296,7 @@ test_substrings_vrFilter(
                MatchingRule *mr = a->a_desc->ad_type->sat_substr;
                struct berval *bv;
 
-               if ( !is_ad_subtype( a->a_desc, f->f_sub_desc ) ) {
+               if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
                        continue;
                }
 
@@ -320,14 +304,14 @@ test_substrings_vrFilter(
                        continue;
                }
 
-               for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
+               bv = a->a_nvals;
+               for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
                        int ret;
                        int rc;
                        const char *text;
 
-                       rc = value_match( &ret, a->a_desc, mr,
-                               SLAP_MR_ASSERTION_SYNTAX_MATCH,
-                               bv, f->f_sub, &text );
+                       rc = value_match( &ret, a->a_desc, mr, 0,
+                               bv, vrf->vrf_sub, &text );
 
                        if( rc != LDAP_SUCCESS ) {
                                return rc;
@@ -342,9 +326,8 @@ test_substrings_vrFilter(
        return LDAP_SUCCESS;
 }
 
-static int test_mra_vrFilter(
-       Backend         *be,
-       Connection      *conn,
+static int
+test_mra_vrFilter(
        Operation       *op,
        Attribute       *a,
        MatchingRuleAssertion *mra,
@@ -354,22 +337,39 @@ static int test_mra_vrFilter(
        int i, j;
 
        for ( i=0; a != NULL; a = a->a_next, i++ ) {
-               struct berval *bv;
-       
-               if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
-                       return( LDAP_SUCCESS );
+               struct berval *bv, value;
+
+               if ( mra->ma_desc ) {
+                       if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
+                               continue;
+                       }
+                       value = mra->ma_value;
+
+               } else {
+                       int rc;
+                       const char      *text = NULL;
+
+                       /* check if matching is appropriate */
+                       if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
+                               a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
+                               continue;
+                       }
+
+                       rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
+                               SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
+                               &mra->ma_value, &value, &text, op->o_tmpmemctx );
+
+                       if( rc != LDAP_SUCCESS ) continue;
                }
 
-               for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
+               bv = a->a_nvals;
+               for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
                        int ret;
                        int rc;
                        const char *text;
 
-                       rc = value_match( &ret, a->a_desc, mra->ma_rule,
-                               SLAP_MR_ASSERTION_SYNTAX_MATCH,
-                               bv, &mra->ma_value,
-                               &text );
-
+                       rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
+                               bv, &value, &text );
                        if( rc != LDAP_SUCCESS ) {
                                return rc;
                        }