- *a = (Attribute *) ch_malloc( sizeof(Attribute) );
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
- (*a)->a_desc = ad_dup( desc );
-#else
- (*a)->a_type = attr_normalize( ch_strdup( type ) );
- (*a)->a_syntax = attr_syntax( type );
-#endif
- (*a)->a_vals = NULL;
- (*a)->a_next = NULL;
+ *a = attr_alloc( desc );
+ }
+
+ rc = value_add_one( &(*a)->a_vals, val );
+
+ if ( rc == LDAP_SUCCESS ) {
+ if ( nval ) {
+ rc = value_add_one( &(*a)->a_nvals, nval );
+ /* FIXME: what if rc != LDAP_SUCCESS ? */
+ } else {
+ (*a)->a_nvals = (*a)->a_vals;
+ }
+ }
+ return rc;
+}
+
+/*
+ * if a normalization function is defined for the equality matchingRule
+ * of desc, the value is normalized and stored in nval; otherwise nval
+ * is NULL
+ */
+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,
+ AttributeDescription *desc,
+ struct berval *val,
+ void *memctx )
+{
+ 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;