]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/attr.c
#unifdef -DSLAP_NVALUES_ON_DISK
[openldap] / servers / slapd / attr.c
index decf58228a5890b046d2341f8ec5397358f0a5d2..599b89193a6f78f93f93a75f6b94d6d4ea00923d 100644 (file)
 #include "ldap_pvt.h"
 #include "slap.h"
 
-#ifdef LDAP_DEBUG
-static void at_index_print( void ) 
-{
-}
-#endif
-
 void
 attr_free( Attribute *a )
 {
        ber_bvarray_free( a->a_vals );
 #ifdef SLAP_NVALUES
-       ber_bvarray_free( a->a_nvals );
+       if (a->a_nvals != a->a_vals) ber_bvarray_free( a->a_nvals );
 #endif
        free( a );
 }
@@ -72,7 +66,7 @@ Attribute *attr_dup( Attribute *a )
                tmp->a_vals[i].bv_val = NULL;
 
 #ifdef SLAP_NVALUES
-               if( a->a_nvals != NULL ) {
+               if( a->a_nvals != a->a_vals ) {
                        tmp->a_nvals = ch_malloc((i+1) * sizeof(struct berval));
                        for( i=0; a->a_nvals[i].bv_val != NULL; i++ ) {
                                ber_dupbv( &tmp->a_nvals[i], &a->a_nvals[i] );
@@ -81,7 +75,7 @@ Attribute *attr_dup( Attribute *a )
                        tmp->a_nvals[i].bv_val = NULL;
 
                } else {
-                       tmp->a_nvals = NULL;
+                       tmp->a_nvals = tmp->a_vals;
                }
 #endif
 
@@ -122,6 +116,10 @@ Attribute *attrs_dup( Attribute *a )
 /*
  * attr_merge - merge the given type and value with the list of
  * attributes in attrs.
+ *
+ * For SLAP_NVALUES: nvals must be NULL if the attribute has no
+ * normalizer. In this case, a->a_nvals will be set equal to a->a_vals.
+ *
  * returns     0       everything went ok
  *             -1      trouble
  */
@@ -160,6 +158,7 @@ attr_merge(
 
 #ifdef SLAP_NVALUES
        if( !rc && nvals ) rc = value_add( &(*a)->a_nvals, nvals );
+       else (*a)->a_nvals = (*a)->a_vals;
 #endif
 
        return rc;
@@ -171,7 +170,7 @@ attr_merge_one(
        AttributeDescription *desc,
        struct berval   *val
 #ifdef SLAP_NVALUES
-       , BerVarray     nval
+       , struct berval *nval
 #endif
 ) {
        int rc;
@@ -198,6 +197,7 @@ attr_merge_one(
 
 #ifdef SLAP_NVALUES
        if( !rc && nval ) rc = value_add_one( &(*a)->a_nvals, nval );
+       else (*a)->a_nvals = (*a)->a_vals;
 #endif
        return rc;
 }