]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/matchedValues.c
Merge remote branch 'origin/mdb.master'
[openldap] / servers / slapd / matchedValues.c
index c025d1866ac9e114a913d12be12c424b4e07ba62..e2dd2b09db1216310bddb1d9883601f679f698af 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2004 The OpenLDAP Foundation.
+ * Copyright 1999-2012 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -171,38 +171,37 @@ test_ava_vrFilter(
                if( mr == NULL ) continue;
 
                bv = a->a_nvals;
-               for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
-                       int ret;
-                       int rc;
+               for ( j=0; !BER_BVISNULL( bv ); bv++, j++ ) {
+                       int rc, match;
                        const char *text;
 
-                       rc = value_match( &ret, a->a_desc, mr, 0,
+                       rc = value_match( &match, a->a_desc, mr, 0,
                                bv, &ava->aa_value, &text );
                        if( rc != LDAP_SUCCESS ) return rc;
 
                        switch ( type ) {
                        case LDAP_FILTER_EQUALITY:
                        case LDAP_FILTER_APPROX:
-                               if ( ret == 0 ) {
+                               if ( match == 0 ) {
                                        (*e_flags)[i][j] = 1;
                                }
                                break;
        
                        case LDAP_FILTER_GE:
-                               if ( ret >= 0 ) {
+                               if ( match >= 0 ) {
                                        (*e_flags)[i][j] = 1;
                                }
                                break;
        
                        case LDAP_FILTER_LE:
-                               if ( ret <= 0 ) {
+                               if ( match <= 0 ) {
                                        (*e_flags)[i][j] = 1;
                                }
                                break;
                        }
                }
        }
-       return( LDAP_SUCCESS );
+       return LDAP_SUCCESS;
 }
 
 static int
@@ -219,7 +218,7 @@ test_presence_vrFilter(
 
                if ( !is_ad_subtype( a->a_desc, desc ) ) continue;
 
-               for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
+               for ( bv = a->a_vals, j = 0; !BER_BVISNULL( bv ); bv++, j++ );
                memset( (*e_flags)[i], 1, j);
        }
 
@@ -246,19 +245,16 @@ test_substrings_vrFilter(
                if( mr == NULL ) continue;
 
                bv = a->a_nvals;
-               for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
-                       int ret;
-                       int rc;
+               for ( j = 0; !BER_BVISNULL( bv ); bv++, j++ ) {
+                       int rc, match;
                        const char *text;
 
-                       rc = value_match( &ret, a->a_desc, mr, 0,
+                       rc = value_match( &match, a->a_desc, mr, 0,
                                bv, vrf->vrf_sub, &text );
 
-                       if( rc != LDAP_SUCCESS ) {
-                               return rc;
-                       }
+                       if( rc != LDAP_SUCCESS ) return rc;
 
-                       if ( ret == 0 ) {
+                       if ( match == 0 ) {
                                (*e_flags)[i][j] = 1;
                        }
                }
@@ -274,10 +270,11 @@ test_mra_vrFilter(
        MatchingRuleAssertion *mra,
        char            ***e_flags )
 {
-       int i, j;
+       int     i, j;
 
-       for ( i=0; a != NULL; a = a->a_next, i++ ) {
-               struct berval *bv, assertedValue;
+       for ( i = 0; a != NULL; a = a->a_next, i++ ) {
+               struct berval   *bv, assertedValue;
+               int             normalize_attribute = 0;
 
                if ( mra->ma_desc ) {
                        if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
@@ -298,26 +295,49 @@ test_mra_vrFilter(
                                SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
                                &mra->ma_value, &assertedValue, &text, op->o_tmpmemctx );
 
-                       if( rc != LDAP_SUCCESS ) continue;
+                       if ( rc != LDAP_SUCCESS ) continue;
                }
 
                /* check match */
-               if (mra->ma_rule == a->a_desc->ad_type->sat_equality) {
+               if ( mra->ma_rule == a->a_desc->ad_type->sat_equality ) {
                        bv = a->a_nvals;
+
                } else {
                        bv = a->a_vals;
+                       normalize_attribute = 1;
                }
                                        
-               for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
-                       int ret;
-                       int rc;
-                       const char *text;
+               for ( j = 0; !BER_BVISNULL( bv ); bv++, j++ ) {
+                       int             rc, match;
+                       const char      *text;
+                       struct berval   nbv = BER_BVNULL;
+
+                       if ( normalize_attribute && mra->ma_rule->smr_normalize ) {
+                               /* see comment in filterentry.c */
+                               if ( mra->ma_rule->smr_normalize(
+                                               SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                                               mra->ma_rule->smr_syntax,
+                                               mra->ma_rule,
+                                               bv, &nbv, op->o_tmpmemctx ) != LDAP_SUCCESS )
+                               {
+                                       /* FIXME: stop processing? */
+                                       continue;
+                               }
 
-                       rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
-                               bv, &assertedValue, &text );
-                       if( rc != LDAP_SUCCESS ) return rc;
+                       } else {
+                               nbv = *bv;
+                       }
+
+                       rc = value_match( &match, a->a_desc, mra->ma_rule, 0,
+                               &nbv, &assertedValue, &text );
+
+                       if ( nbv.bv_val != bv->bv_val ) {
+                               op->o_tmpfree( nbv.bv_val, op->o_tmpmemctx );
+                       }
+
+                       if ( rc != LDAP_SUCCESS ) return rc;
 
-                       if ( ret == 0 ) {
+                       if ( match == 0 ) {
                                (*e_flags)[i][j] = 1;
                        }
                }