]> git.sur5r.net Git - openldap/commitdiff
add attr_normalize*() helper (please holler if I missed any obvious alternative)
authorPierangelo Masarati <ando@openldap.org>
Wed, 6 Sep 2006 09:06:50 +0000 (09:06 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 6 Sep 2006 09:06:50 +0000 (09:06 +0000)
servers/slapd/attr.c
servers/slapd/proto-slap.h

index 78784736b2d54ba628d5428697182ba26aff7dee..22481eb6c38d117330d48654e9f92f5005f87d23 100644 (file)
@@ -307,16 +307,61 @@ attr_merge(
        return rc;
 }
 
+int
+attr_normalize(
+       AttributeDescription    *desc,
+       BerVarray               vals,
+       BerVarray               *nvalsp,
+       void                    *memctx )
+{
+       int             rc = LDAP_SUCCESS;
+       BerVarray       nvals = NULL;
+
+       *nvalsp = NULL;
+
+       if ( desc->ad_type->sat_equality &&
+               desc->ad_type->sat_equality->smr_normalize )
+       {
+               int     i;
+               
+               for ( i = 0; !BER_BVISNULL( &vals[i] ); i++ );
+
+               nvals = slap_sl_calloc( sizeof(struct berval), i + 1, memctx );
+               for ( i = 0; !BER_BVISNULL( &vals[i] ); i++ ) {
+                       rc = desc->ad_type->sat_equality->smr_normalize(
+                                       SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                                       desc->ad_type->sat_syntax,
+                                       desc->ad_type->sat_equality,
+                                       &vals[i], &nvals[i], memctx );
+
+                       if ( rc != LDAP_SUCCESS ) {
+                               BER_BVZERO( &nvals[i + 1] );
+                               break;
+                       }
+               }
+               BER_BVZERO( &nvals[i] );
+               *nvalsp = nvals;
+       }
+
+error_return:;
+       if ( rc != LDAP_SUCCESS && nvals != NULL ) {
+               ber_bvarray_free_x( nvals, memctx );
+       }
+
+       return rc;
+}
+
 int
 attr_merge_normalize(
-       Entry           *e,
-       AttributeDescription *desc,
-       BerVarray       vals,
-       void     *memctx )
+       Entry                   *e,
+       AttributeDescription    *desc,
+       BerVarray               vals,
+       void                    *memctx )
 {
        BerVarray       nvals = NULL;
        int             rc;
 
+#if 0
        if ( desc->ad_type->sat_equality &&
                desc->ad_type->sat_equality->smr_normalize )
        {
@@ -339,13 +384,20 @@ attr_merge_normalize(
                }
                BER_BVZERO( &nvals[i] );
        }
+#endif
 
-       rc = attr_merge( e, desc, vals, nvals );
+       rc = attr_normalize( desc, vals, &nvals, memctx );
+       if ( rc == LDAP_SUCCESS ) {
+               rc = attr_merge( e, desc, vals, nvals );
+       }
 
+#if 0
 error_return:;
+#endif 
        if ( nvals != NULL ) {
                ber_bvarray_free_x( nvals, memctx );
        }
+
        return rc;
 }
 
@@ -382,6 +434,34 @@ attr_merge_one(
        return rc;
 }
 
+int
+attr_normalize_one(
+       AttributeDescription *desc,
+       struct berval   *val,
+       struct berval   *nval,
+       void            *memctx )
+{
+       int             rc = LDAP_SUCCESS;
+
+       BER_BVZERO( nval );
+
+       if ( desc->ad_type->sat_equality &&
+               desc->ad_type->sat_equality->smr_normalize )
+       {
+               rc = desc->ad_type->sat_equality->smr_normalize(
+                               SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                               desc->ad_type->sat_syntax,
+                               desc->ad_type->sat_equality,
+                               val, nval, memctx );
+
+               if ( rc != LDAP_SUCCESS ) {
+                       return rc;
+               }
+       }
+
+       return rc;
+}
+
 int
 attr_merge_normalize_one(
        Entry           *e,
@@ -389,14 +469,20 @@ attr_merge_normalize_one(
        struct berval   *val,
        void            *memctx )
 {
-       struct berval   nval;
+       struct berval   nval = BER_BVNULL;
        struct berval   *nvalp = NULL;
        int             rc;
 
+       rc = attr_normalize_one( desc, val, &nval, memctx );
+       if ( rc == LDAP_SUCCESS && !BER_BVISNULL( &nval ) ) {
+               nvalp = &nval;
+       }
+
+#if 0
        if ( desc->ad_type->sat_equality &&
                desc->ad_type->sat_equality->smr_normalize )
        {
-               rc = (*desc->ad_type->sat_equality->smr_normalize)(
+               rc = desc->ad_type->sat_equality->smr_normalize)
                                SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
                                desc->ad_type->sat_syntax,
                                desc->ad_type->sat_equality,
@@ -407,6 +493,7 @@ attr_merge_normalize_one(
                }
                nvalp = &nval;
        }
+#endif
 
        rc = attr_merge_one( e, desc, val, nvalp );
        if ( nvalp != NULL ) {
index dac07b4075a215b0ac8bea4a43a2834e86682ffc..4ca9f1dd2a9db8f898443c151eca8eb26d369971 100644 (file)
@@ -258,6 +258,10 @@ LDAP_SLAPD_F (int) attr_merge_one LDAP_P(( Entry *e,
        AttributeDescription *desc,
        struct berval *val,
        struct berval *nval ));
+LDAP_SLAPD_F (int) attr_normalize LDAP_P(( AttributeDescription *desc,
+       BerVarray vals, BerVarray *nvalsp, void *memctx ));
+LDAP_SLAPD_F (int) attr_normalize_one LDAP_P(( AttributeDescription *desc,
+       struct berval *val, struct berval *nval, void *memctx ));
 LDAP_SLAPD_F (int) attr_merge_normalize LDAP_P(( Entry *e,
        AttributeDescription *desc,
        BerVarray vals, void *memctx ));