]> git.sur5r.net Git - openldap/commitdiff
wrap validate/pretty/normalize for ordered values (only #ifdef LDAP_DEVEL)
authorPierangelo Masarati <ando@openldap.org>
Thu, 11 Aug 2005 23:35:15 +0000 (23:35 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 11 Aug 2005 23:35:15 +0000 (23:35 +0000)
servers/slapd/entry.c
servers/slapd/modify.c
servers/slapd/proto-slap.h
servers/slapd/slap.h
servers/slapd/value.c

index 9441de24e6317c7b18a2425ceab42870e89bac20..6c1d45b1c41759cb244da642224be9205570bc53 100644 (file)
@@ -268,15 +268,24 @@ str2entry2( char *s, int checkvals )
                        slap_syntax_transform_func *pretty =
                                ad->ad_type->sat_syntax->ssyn_pretty;
 
-                       if( pretty ) {
+                       if ( pretty ) {
+#ifdef SLAP_ORDERED_PRETTYNORM
+                               rc = ordered_value_pretty( ad,
+                                       &vals[i], &pval, NULL );
+#else /* ! SLAP_ORDERED_PRETTYNORM */
                                rc = pretty( ad->ad_type->sat_syntax,
                                        &vals[i], &pval, NULL );
+#endif /* ! SLAP_ORDERED_PRETTYNORM */
 
-                       } else if( validate ) {
+                       } else if ( validate ) {
                                /*
                                 * validate value per syntax
                                 */
+#ifdef SLAP_ORDERED_PRETTYNORM
+                               rc = ordered_value_validate( ad, &vals[i] );
+#else /* ! SLAP_ORDERED_PRETTYNORM */
                                rc = validate( ad->ad_type->sat_syntax, &vals[i] );
+#endif /* ! SLAP_ORDERED_PRETTYNORM */
 
                        } else {
                                Debug( LDAP_DEBUG_ANY,
@@ -303,16 +312,24 @@ str2entry2( char *s, int checkvals )
                        }
                }
 
-               if( ad->ad_type->sat_equality &&
+               if ( ad->ad_type->sat_equality &&
                        ad->ad_type->sat_equality->smr_normalize )
                {
+#ifdef SLAP_ORDERED_PRETTYNORM
+                       rc = ordered_value_normalize(
+                               SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                               ad,
+                               ad->ad_type->sat_equality,
+                               &vals[i], &nvals[i], NULL );
+#else /* ! SLAP_ORDERED_PRETTYNORM */
                        rc = ad->ad_type->sat_equality->smr_normalize(
                                SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
                                ad->ad_type->sat_syntax,
                                ad->ad_type->sat_equality,
                                &vals[i], &nvals[i], NULL );
+#endif /* ! SLAP_ORDERED_PRETTYNORM */
 
-                       if( rc ) {
+                       if ( rc ) {
                                Debug( LDAP_DEBUG_ANY,
                                        "<= str2entry NULL (smr_normalize %d)\n", rc, 0, 0 );
                                goto fail;
index 4025e40b37a4d8742ed943e0b03f981483600e2a..56d6c0bf4aaa23b1ae63ef334851ba9b0bc32a56 100644 (file)
@@ -668,14 +668,25 @@ int slap_mods_check(
                         * check that each value is valid per syntax
                         *      and pretty if appropriate
                         */
-                       for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
+                       for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
                                struct berval pval;
-                               if( pretty ) {
+
+                               if ( pretty ) {
+#ifdef SLAP_ORDERED_PRETTYNORM
+                                       rc = ordered_value_pretty( ad,
+                                               &ml->sml_values[nvals], &pval, ctx );
+#else /* ! SLAP_ORDERED_PRETTYNORM */
                                        rc = pretty( ad->ad_type->sat_syntax,
                                                &ml->sml_values[nvals], &pval, ctx );
+#endif /* ! SLAP_ORDERED_PRETTYNORM */
                                } else {
+#ifdef SLAP_ORDERED_PRETTYNORM
+                                       rc = ordered_value_validate( ad,
+                                               &ml->sml_values[nvals] );
+#else /* ! SLAP_ORDERED_PRETTYNORM */
                                        rc = validate( ad->ad_type->sat_syntax,
                                                &ml->sml_values[nvals] );
+#endif /* ! SLAP_ORDERED_PRETTYNORM */
                                }
 
                                if( rc != 0 ) {
@@ -720,13 +731,21 @@ int slap_mods_check(
                                ml->sml_nvalues = ber_memalloc_x(
                                        (nvals+1)*sizeof(struct berval), ctx );
 
-                               for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
+                               for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
+#ifdef SLAP_ORDERED_PRETTYNORM
+                                       rc = ordered_value_normalize(
+                                               SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                                               ad,
+                                               ad->ad_type->sat_equality,
+                                               &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
+#else /* ! SLAP_ORDERED_PRETTYNORM */
                                        rc = ad->ad_type->sat_equality->smr_normalize(
                                                SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
                                                ad->ad_type->sat_syntax,
                                                ad->ad_type->sat_equality,
                                                &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
-                                       if( rc ) {
+#endif /* ! SLAP_ORDERED_PRETTYNORM */
+                                       if ( rc ) {
                                                Debug( LDAP_DEBUG_ANY,
                                                        "<= str2entry NULL (ssyn_normalize %d)\n",
                                                        rc, 0, 0 );
@@ -738,8 +757,7 @@ int slap_mods_check(
                                        }
                                }
 
-                               ml->sml_nvalues[nvals].bv_val = NULL;
-                               ml->sml_nvalues[nvals].bv_len = 0;
+                               BER_BVZERO( &ml->sml_nvalues[nvals] );
                        }
 
                        /* check for duplicates, but ignore Deletes.
index 5ad9092de766b5f8545a5c4989df91913ed1b5a9..4542c968861030839a3db8446e9a274fdb75a691 100644 (file)
@@ -1513,6 +1513,24 @@ LDAP_SLAPD_F (int) ordered_value_add LDAP_P((
        BerVarray vals,
        BerVarray nvals ));
 
+LDAP_SLAPD_F (int) ordered_value_validate LDAP_P((
+       AttributeDescription *ad,
+       struct berval *in ));
+
+LDAP_SLAPD_F (int) ordered_value_pretty LDAP_P((
+       AttributeDescription *ad,
+       struct berval *val,
+       struct berval *out,
+       void *ctx ));
+
+LDAP_SLAPD_F (int) ordered_value_normalize LDAP_P((
+       slap_mask_t usage,
+       AttributeDescription *ad,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized,
+       void *ctx ));
+
 LDAP_SLAPD_F (int) ordered_value_match LDAP_P((
        int *match,
        AttributeDescription *ad,
index 7d97375c36aa1e999a182aadd055c61e12ea2380..81a01025d72a1c2b7135e281e596db3611e0a470 100644 (file)
@@ -71,6 +71,8 @@ LDAP_BEGIN_DECL
 #define SLAP_CONTROL_X_TREE_DELETE LDAP_CONTROL_X_TREE_DELETE
 #define SLAPD_CONF_UNKNOWN_BAILOUT
 
+#define SLAP_ORDERED_PRETTYNORM
+
 #ifdef ENABLE_REWRITE
 #define SLAP_AUTH_REWRITE      1 /* use librewrite for sasl-regexp */
 #endif
index aab6b34bc85fb6ae347efc0d2fcce92c70332347..898715ed4c744c3505f1b050679c73fb338f6710 100644 (file)
@@ -396,6 +396,166 @@ ordered_value_sort( Attribute *a, int do_renumber )
        return 0;
 }
 
+/*
+ * wrapper for validate function
+ * uses the validate function of the syntax after removing
+ * the index, if allowed an present
+ */
+int
+ordered_value_validate(
+       AttributeDescription *ad,
+       struct berval *in )
+{
+       struct berval   bv = *in;
+
+       assert( ad->ad_type->sat_syntax != NULL );
+       assert( ad->ad_type->sat_syntax->ssyn_validate != NULL );
+
+       if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
+
+               /* Skip past the assertion index */
+               if ( bv.bv_val[0] == '{' ) {
+                       char    *ptr;
+
+                       ptr = strchr( bv.bv_val, '}' );
+                       if ( ptr == NULL ) {
+                               return LDAP_INVALID_SYNTAX;
+                       }
+                       ptr++;
+                       bv.bv_len -= ptr - bv.bv_val;
+                       bv.bv_val = ptr;
+                       in = &bv;
+               }
+       }
+
+       return ad->ad_type->sat_syntax->ssyn_validate( ad->ad_type->sat_syntax, in );
+}
+
+/*
+ * wrapper for pretty function
+ * uses the pretty function of the syntax after removing
+ * the index, if allowed and present; in case, it's prepended
+ * to the pretty value
+ */
+int
+ordered_value_pretty(
+       AttributeDescription *ad,
+       struct berval *val,
+       struct berval *out,
+       void *ctx )
+{
+       struct berval   bv = *val,
+                       idx = BER_BVNULL;
+       int             rc;
+
+       assert( ad->ad_type->sat_syntax != NULL );
+       assert( ad->ad_type->sat_syntax->ssyn_pretty != NULL );
+       assert( val != NULL );
+       assert( out != NULL );
+
+       if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
+
+               /* Skip past the assertion index */
+               if ( bv.bv_val[0] == '{' ) {
+                       char    *ptr;
+
+                       ptr = strchr( bv.bv_val, '}' );
+                       if ( ptr == NULL ) {
+                               return LDAP_INVALID_SYNTAX;
+                       }
+                       ptr++;
+
+                       idx = bv;
+                       idx.bv_len = ptr - bv.bv_val;
+
+                       bv.bv_len -= idx.bv_len;
+                       bv.bv_val = ptr;
+
+                       val = &bv;
+               }
+       }
+
+       rc = ad->ad_type->sat_syntax->ssyn_pretty( ad->ad_type->sat_syntax, val, out, ctx );
+
+       if ( rc == LDAP_SUCCESS && !BER_BVISNULL( &idx ) ) {
+               bv = *out;
+
+               out->bv_len = idx.bv_len + bv.bv_len;
+               out->bv_val = ber_memalloc_x( out->bv_len + 1, ctx );
+               
+               AC_MEMCPY( out->bv_val, idx.bv_val, idx.bv_len );
+               AC_MEMCPY( &out->bv_val[ idx.bv_len ], bv.bv_val, bv.bv_len + 1 );
+
+               ber_memfree_x( bv.bv_val, ctx );
+       }
+
+       return rc;
+}
+
+/*
+ * wrapper for normalize function
+ * uses the normalize function of the attribute description equality rule
+ * after removing the index, if allowed and present; in case, it's
+ * prepended to the value
+ */
+int
+ordered_value_normalize(
+       slap_mask_t usage,
+       AttributeDescription *ad,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized,
+       void *ctx )
+{
+       struct berval   bv = *val,
+                       idx = BER_BVNULL;
+       int             rc;
+
+       assert( ad->ad_type->sat_equality != NULL );
+       assert( ad->ad_type->sat_equality->smr_normalize != NULL );
+       assert( val != NULL );
+       assert( normalized != NULL );
+
+       if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
+
+               /* Skip past the assertion index */
+               if ( bv.bv_val[0] == '{' ) {
+                       char    *ptr;
+
+                       ptr = strchr( bv.bv_val, '}' );
+                       if ( ptr == NULL ) {
+                               return LDAP_INVALID_SYNTAX;
+                       }
+                       ptr++;
+
+                       idx = bv;
+                       idx.bv_len = ptr - bv.bv_val;
+
+                       bv.bv_len -= idx.bv_len;
+                       bv.bv_val = ptr;
+
+                       val = &bv;
+               }
+       }
+
+       rc = ad->ad_type->sat_equality->smr_normalize( usage,
+               ad->ad_type->sat_syntax, mr, val, normalized, ctx );
+
+       if ( rc == LDAP_SUCCESS && !BER_BVISNULL( &idx ) ) {
+               bv = *normalized;
+
+               normalized->bv_len = idx.bv_len + bv.bv_len;
+               normalized->bv_val = ber_memalloc_x( normalized->bv_len + 1, ctx );
+               
+               AC_MEMCPY( normalized->bv_val, idx.bv_val, idx.bv_len );
+               AC_MEMCPY( &normalized->bv_val[ idx.bv_len ], bv.bv_val, bv.bv_len + 1 );
+
+               ber_memfree_x( bv.bv_val, ctx );
+       }
+
+       return rc;
+}
+
 /* A wrapper for value match, handles Equality matches for attributes
  * with ordered values.
  */