From 0291e294c5ded6c6f747657f37c00c446ddaef39 Mon Sep 17 00:00:00 2001 From: Sang Seok Lim Date: Thu, 13 Jan 2005 09:48:52 +0000 Subject: [PATCH] Handling multi-valued attributes in Component Matching --- servers/slapd/filterentry.c | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/servers/slapd/filterentry.c b/servers/slapd/filterentry.c index b09209b5e9..19d46e0359 100644 --- a/servers/slapd/filterentry.c +++ b/servers/slapd/filterentry.c @@ -154,6 +154,9 @@ static int test_mra_filter( Attribute *a; void *memctx; BER_MEMFREE_FN *memfree; +#ifdef LDAP_COMP_MATCH + int i, num_attr_vals; +#endif if ( op == NULL ) { memctx = NULL; @@ -198,15 +201,23 @@ static int test_mra_filter( if( mra->ma_cf && mra->ma_rule->smr_usage & SLAP_MR_COMPONENT ) { - int ret; - int rc; - const char *text; - rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, - (struct berval *)a,(void*) mra , &text ); - if ( rc != LDAP_SUCCESS ) return rc; - if ( ret == 0 ) return LDAP_COMPARE_TRUE; - else return LDAP_COMPARE_FALSE; + num_attr_vals = 0; + if ( !a->a_comp_data ) { + for ( ; a->a_vals[num_attr_vals].bv_val != NULL; num_attr_vals++ ); + if ( num_attr_vals <= 0 )/* no attribute value */ + return LDAP_INAPPROPRIATE_MATCHING; + num_attr_vals++; + + /* following malloced will be freed by comp_tree_free () */ + a->a_comp_data = malloc( sizeof( ComponentData ) + sizeof( ComponentSyntaxInfo* )*num_attr_vals ); + + if ( !a->a_comp_data ) + return LDAP_NO_MEMORY; + a->a_comp_data->cd_tree = (ComponentSyntaxInfo**)((char*)a->a_comp_data + sizeof(ComponentData)); + a->a_comp_data->cd_tree[ num_attr_vals - 1] = (ComponentSyntaxInfo*)NULL; + a->a_comp_data->cd_mem_op = nibble_mem_allocator ( 1024*16, 1024 ); + } } #endif @@ -218,14 +229,31 @@ static int test_mra_filter( } else { bv = a->a_vals; } - +#ifdef LDAP_COMP_MATCH + i = 0; +#endif for ( ; bv->bv_val != NULL; bv++ ) { int ret; int rc; const char *text; - rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, - bv, &mra->ma_value, &text ); +#ifdef LDAP_COMP_MATCH + if( mra->ma_cf && + mra->ma_rule->smr_usage & SLAP_MR_COMPONENT ) { + /* Check if decoded component trees are already linked */ + if ( num_attr_vals ) + a->a_comp_data->cd_tree[i] = attr_converter (a, a->a_desc->ad_type->sat_syntax, bv); + /* decoding error */ + if ( !a->a_comp_data->cd_tree[i] ) + return LDAP_OPERATIONS_ERROR; + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, + (struct berval*)a->a_comp_data->cd_tree[i++], (void*)mra, &text ); + } else +#endif + { + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, + bv, &mra->ma_value, &text ); + } if( rc != LDAP_SUCCESS ) return rc; if ( ret == 0 ) return LDAP_COMPARE_TRUE; -- 2.39.5