1 /* value.c - routines for dealing with values */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
23 struct berval ***vals,
24 struct berval **addvals
29 for ( nn = 0; addvals != NULL && addvals[nn] != NULL; nn++ )
32 if ( *vals == NULL ) {
33 *vals = (struct berval **) ch_malloc( (nn + 1)
34 * sizeof(struct berval *) );
37 for ( n = 0; (*vals)[n] != NULL; n++ )
39 *vals = (struct berval **) ch_realloc( (char *) *vals,
40 (n + nn + 1) * sizeof(struct berval *) );
43 for ( i = 0, j = 0; i < nn; i++ ) {
44 if ( addvals[i]->bv_len > 0 ) {
45 (*vals)[n + j] = ber_bvdup( addvals[i] );
46 if( (*vals)[n + j++] == NULL ) break;
49 (*vals)[n + j] = NULL;
57 AttributeDescription *ad,
66 switch( usage & SLAP_MR_TYPE_MASK ) {
68 case SLAP_MR_EQUALITY:
69 mr = ad->ad_type->sat_equality;
71 case SLAP_MR_ORDERING:
72 mr = ad->ad_type->sat_ordering;
75 mr = ad->ad_type->sat_substr;
80 *text = "internal error";
85 *text = "inappropriate matching request";
86 return LDAP_INAPPROPRIATE_MATCHING;
89 /* we only support equality matching of binary attributes */
90 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
91 *text = "inappropriate binary matching";
92 return LDAP_INAPPROPRIATE_MATCHING;
95 if( mr->smr_normalize ) {
96 rc = (mr->smr_normalize)( usage,
97 ad->ad_type->sat_syntax,
100 if( rc != LDAP_SUCCESS ) {
101 *text = "unable to normalize value";
102 return LDAP_INVALID_SYNTAX;
105 } else if ( mr->smr_syntax->ssyn_normalize ) {
106 rc = (mr->smr_syntax->ssyn_normalize)(
107 ad->ad_type->sat_syntax,
110 if( rc != LDAP_SUCCESS ) {
111 *text = "unable to normalize value";
112 return LDAP_INVALID_SYNTAX;
116 *out = ber_bvdup( in );
126 AttributeDescription *ad,
129 struct berval *v1, /* stored value */
130 void *v2, /* assertion */
134 struct berval *nv1 = NULL;
136 if( !mr->smr_match ) {
137 return LDAP_INAPPROPRIATE_MATCHING;
140 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
141 rc = ad->ad_type->sat_syntax->ssyn_normalize(
142 ad->ad_type->sat_syntax, v1, &nv1 );
144 if( rc != LDAP_SUCCESS ) {
145 return LDAP_INAPPROPRIATE_MATCHING;
149 rc = (mr->smr_match)( match, flags,
150 ad->ad_type->sat_syntax,
152 nv1 != NULL ? nv1 : v1,
161 AttributeDescription *ad,
162 struct berval **vals,
167 struct berval *nval = NULL;
168 MatchingRule *mr = ad->ad_type->sat_equality;
170 if( mr == NULL || !mr->smr_match ) {
171 return LDAP_INAPPROPRIATE_MATCHING;
174 if( mr->smr_syntax->ssyn_normalize ) {
175 rc = mr->smr_syntax->ssyn_normalize(
176 mr->smr_syntax, val, &nval );
178 if( rc != LDAP_SUCCESS ) {
179 return LDAP_INAPPROPRIATE_MATCHING;
183 for ( i = 0; vals[i] != NULL; i++ ) {
187 rc = value_match( &match, ad, mr, 0,
188 vals[i], nval == NULL ? val : nval, &text );
190 if( rc == LDAP_SUCCESS && match == 0 ) {
197 return LDAP_NO_SUCH_ATTRIBUTE;