]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/value.c
ITS#2895 store a copy in the entry cache
[openldap] / servers / slapd / value.c
index 0d70a7c611b2e538e0ac78d1cb073072528081e7..1c4379866dcc2a76c1a461416a5e27decceec305 100644 (file)
@@ -1,8 +1,28 @@
 /* value.c - routines for dealing with values */
 /* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
 /*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ * Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
  */
 
 #include "portable.h"
@@ -129,9 +149,12 @@ int asserted_value_validate_normalize(
        unsigned usage,
        struct berval *in,
        struct berval *out,
-       const char ** text )
+       const char ** text,
+       void *ctx )
 {
        int rc;
+       struct berval pval;
+       pval.bv_val = NULL;
 
        /* we expect the value to be in the assertion syntax */
        assert( !SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) );
@@ -146,7 +169,13 @@ int asserted_value_validate_normalize(
                return LDAP_INAPPROPRIATE_MATCHING;
        }
 
-       rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
+       if( mr->smr_syntax->ssyn_pretty ) {
+               rc = (mr->smr_syntax->ssyn_pretty)( mr->smr_syntax, in, &pval, ctx );
+               in = &pval;
+
+       } else {
+               rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
+       }
 
        if( rc != LDAP_SUCCESS ) {
                *text = "value does not conform to assertion syntax";
@@ -154,17 +183,23 @@ int asserted_value_validate_normalize(
        }
 
        if( mr->smr_normalize ) {
-               rc = (mr->smr_normalize)( usage,
+               rc = (mr->smr_normalize)(
+                       usage|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
                        ad ? ad->ad_type->sat_syntax : NULL,
-                       mr, in, out );
+                       mr, in, out, ctx );
+
+               if( pval.bv_val ) ber_memfree_x( pval.bv_val, ctx );
 
                if( rc != LDAP_SUCCESS ) {
                        *text = "unable to normalize value for matching";
                        return LDAP_INVALID_SYNTAX;
                }
 
+       } else if ( pval.bv_val != NULL ) {
+               *out = pval;
+
        } else {
-               ber_dupbv( out, in );
+               ber_dupbv_x( out, in, ctx );
        }
 
        return LDAP_SUCCESS;
@@ -191,7 +226,6 @@ value_match(
                return LDAP_INAPPROPRIATE_MATCHING;
        }
 
-
        rc = (mr->smr_match)( match, flags,
                ad->ad_type->sat_syntax,
                mr,
@@ -207,7 +241,8 @@ int value_find_ex(
        AttributeDescription *ad,
        unsigned flags,
        BerVarray vals,
-       struct berval *val )
+       struct berval *val,
+       void *ctx )
 {
        int     i;
        int rc;
@@ -224,9 +259,9 @@ int value_find_ex(
                mr->smr_normalize )
        {
                rc = (mr->smr_normalize)(
-                       flags & SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK,
+                       flags & (SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK|SLAP_MR_VALUE_OF_SYNTAX),
                        ad ? ad->ad_type->sat_syntax : NULL,
-                       mr, val, &nval );
+                       mr, val, &nval, ctx );
 
                if( rc != LDAP_SUCCESS ) {
                        return LDAP_INVALID_SYNTAX;
@@ -241,11 +276,11 @@ int value_find_ex(
                        &vals[i], nval.bv_val == NULL ? val : &nval, &text );
 
                if( rc == LDAP_SUCCESS && match == 0 ) {
-                       free( nval.bv_val );
-                       return LDAP_SUCCESS;
+                       sl_free( nval.bv_val, ctx );
+                       return rc;
                }
        }
 
-       free( nval.bv_val );
+       sl_free( nval.bv_val, ctx );
        return LDAP_NO_SUCH_ATTRIBUTE;
 }