From 43b16581609b6494322f28075e841c20d0f6d2fb Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 8 Apr 2003 23:27:22 +0000 Subject: [PATCH] normalize while merging values --- servers/slapd/attr.c | 71 +++++++++++++++++++++++++++++++++++--- servers/slapd/proto-slap.h | 6 ++++ 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index ee283b6cef..a2a009aeff 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -122,8 +122,8 @@ int attr_merge( Entry *e, AttributeDescription *desc, - BerVarray vals - , BerVarray nvals + BerVarray vals, + BerVarray nvals ) { int rc; @@ -152,12 +152,49 @@ attr_merge( return rc; } +int +attr_merge_normalize( + Entry *e, + AttributeDescription *desc, + BerVarray vals +) { + BerVarray nvals = NULL; + int rc; + + if ( desc->ad_type->sat_equality->smr_normalize ) { + int i; + + for ( i = 0; vals[i].bv_val; i++); + + nvals = ch_calloc( sizeof(struct berval), i + 1 ); + for ( i = 0; vals[i].bv_val; i++ ) { + rc = (*desc->ad_type->sat_equality->smr_normalize)( + 0, + desc->ad_type->sat_syntax, + desc->ad_type->sat_equality, + &vals[i], &nvals[i] ); + + if ( rc != LDAP_SUCCESS ) { + nvals[i+1].bv_val = NULL; + goto error_return; + } + } + nvals[i].bv_val = NULL; + } + + rc = attr_merge( e, desc, vals, nvals ); + +error_return:; + ber_bvarray_free( nvals ); + return rc; +} + int attr_merge_one( Entry *e, AttributeDescription *desc, - struct berval *val - , struct berval *nval + struct berval *val, + struct berval *nval ) { int rc; Attribute **a; @@ -184,6 +221,32 @@ attr_merge_one( return rc; } +int +attr_merge_normalize_one( + Entry *e, + AttributeDescription *desc, + struct berval *val +) { + struct berval nval; + int rc; + + if ( desc->ad_type->sat_equality->smr_normalize ) { + rc = (*desc->ad_type->sat_equality->smr_normalize)( + 0, + desc->ad_type->sat_syntax, + desc->ad_type->sat_equality, + val, &nval ); + + if ( rc != LDAP_SUCCESS ) { + return rc; + } + } + + rc = attr_merge_one( e, desc, val, &nval ); + ch_free( nval.bv_val ); + return rc; +} + /* * attrs_find - find attribute(s) by AttributeDescription * returns next attribute which is subtype of provided description. diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index f743486104..4844df4fdc 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -146,6 +146,12 @@ LDAP_SLAPD_F (int) attr_merge_one LDAP_P(( Entry *e, AttributeDescription *desc, struct berval *val, struct berval *nval )); +LDAP_SLAPD_F (int) attr_merge_normalize LDAP_P(( Entry *e, + AttributeDescription *desc, + BerVarray vals )); +LDAP_SLAPD_F (int) attr_merge_normalize_one LDAP_P(( Entry *e, + AttributeDescription *desc, + struct berval *val )); LDAP_SLAPD_F (Attribute *) attrs_find LDAP_P(( Attribute *a, AttributeDescription *desc )); LDAP_SLAPD_F (Attribute *) attr_find LDAP_P(( -- 2.39.5