]> git.sur5r.net Git - openldap/commitdiff
Add basic infrastructure for pretty routines
authorKurt Zeilenga <kurt@openldap.org>
Wed, 5 Dec 2001 21:36:59 +0000 (21:36 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 5 Dec 2001 21:36:59 +0000 (21:36 +0000)
A pretty routine may rewrite the representation of a value but
must not alter the value itself.

servers/slapd/entry.c
servers/slapd/modify.c
servers/slapd/schema_init.c

index c4d49baec1288a90ae7b440050033e4b3b385189..ccb773a5a775e8d5d35ee0f4d0100ab489ab95d0 100644 (file)
@@ -176,10 +176,23 @@ str2entry( char *s )
                }
 
                if( slapMode & SLAP_TOOL_MODE ) {
+                       struct berval *pval;
                        slap_syntax_validate_func *validate =
                                ad->ad_type->sat_syntax->ssyn_validate;
+                       slap_syntax_transform_func *pretty =
+                               ad->ad_type->sat_syntax->ssyn_pretty;
 
-                       if( !validate ) {
+                       if( pretty ) {
+                               rc = pretty( ad->ad_type->sat_syntax,
+                                       &value, &pval );
+
+                       } else if( validate ) {
+                               /*
+                                * validate value per syntax
+                                */
+                               rc = validate( ad->ad_type->sat_syntax, &value );
+
+                       } else {
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
                                           "str2entry: no validator for syntax %s\n", 
@@ -195,11 +208,6 @@ str2entry( char *s )
                                return NULL;
                        }
 
-                       /*
-                        * validate value per syntax
-                        */
-                       rc = validate( ad->ad_type->sat_syntax, &value );
-
                        if( rc != 0 ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
@@ -215,6 +223,12 @@ str2entry( char *s )
                                free( type );
                                return NULL;
                        }
+
+                       if( pretty ) {
+                               free( value.bv_val );
+                               value = *pval;
+                               free( pval );
+                       }
                }
 
                rc = attr_merge( e, ad, vals );
index b63fd72234786f1c18072e80edb9c045cc8a2415..313c13460255790c796c77f228dfb0769efc9b26 100644 (file)
@@ -490,8 +490,10 @@ int slap_modlist2mods(
                        ber_len_t nvals;
                        slap_syntax_validate_func *validate =
                                ad->ad_type->sat_syntax->ssyn_validate;
-
-                       if( !validate ) {
+                       slap_syntax_transform_func *pretty =
+                               ad->ad_type->sat_syntax->ssyn_pretty;
+                       if( !pretty && !validate ) {
                                slap_mods_free( mod );
                                *text = "no validator for syntax";
                                snprintf( textbuf, textlen,
@@ -504,9 +506,17 @@ int slap_modlist2mods(
 
                        /*
                         * check that each value is valid per syntax
+                        *      and pretty if appropriate
                         */
                        for( nvals = 0; ml->ml_bvalues[nvals]; nvals++ ) {
-                               rc = validate( ad->ad_type->sat_syntax, ml->ml_bvalues[nvals] );
+                               struct berval *pval;
+                               if( pretty ) {
+                                       rc = pretty( ad->ad_type->sat_syntax,
+                                               ml->ml_bvalues[nvals], &pval );
+                               } else {
+                                       rc = validate( ad->ad_type->sat_syntax,
+                                               ml->ml_bvalues[nvals] );
+                               }
 
                                if( rc != 0 ) {
                                        slap_mods_free( mod );
@@ -516,6 +526,12 @@ int slap_modlist2mods(
                                        *text = textbuf;
                                        return LDAP_INVALID_SYNTAX;
                                }
+
+                               if( pretty ) {
+                                       ber_memfree( ml->ml_bvalues[nvals]->bv_val );
+                                       *ml->ml_bvalues[nvals] = *pval;
+                                       free( pval );
+                               }
                        }
 
                        /*
index 0b0c58162331b2ee73ca5b2f4a48392b454d8d9b..62e871b1c4f1839ce0bae172dc51cfcc6735648c 100644 (file)
@@ -436,7 +436,7 @@ int
 dnPretty(
        Syntax *syntax,
        struct berval *val,
-       struct berval **normalized)
+       struct berval **pretty)
 {
        struct berval *out = NULL;
 
@@ -479,7 +479,7 @@ dnPretty(
                out = ber_bvdup( val );
        }
 
-       *normalized = out;
+       *pretty = out;
 
        return( LDAP_SUCCESS );
 }