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;
135 struct berval *nv2 = NULL;
138 if( !mr->smr_match ) {
139 return LDAP_INAPPROPRIATE_MATCHING;
142 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
143 rc = ad->ad_type->sat_syntax->ssyn_normalize(
144 ad->ad_type->sat_syntax, v1, &nv1 );
146 if( rc != LDAP_SUCCESS ) {
147 return LDAP_INAPPROPRIATE_MATCHING;
151 if ( !(flags & SLAP_MR_VALUE_IS_IN_MR_SYNTAX) &&
153 rc = (mr->smr_convert)(v2,&nv2);
154 if ( rc != LDAP_SUCCESS ) {
155 return LDAP_INVALID_SYNTAX;
159 rc = (mr->smr_match)( match, flags,
160 ad->ad_type->sat_syntax,
162 nv1 != NULL ? nv1 : v1,
163 nv2 != NULL ? nv2 : v2 );
172 AttributeDescription *ad,
173 struct berval **vals,
178 struct berval *nval = NULL;
179 MatchingRule *mr = ad->ad_type->sat_equality;
181 if( mr == NULL || !mr->smr_match ) {
182 return LDAP_INAPPROPRIATE_MATCHING;
185 if( mr->smr_syntax->ssyn_normalize ) {
186 rc = mr->smr_syntax->ssyn_normalize(
187 mr->smr_syntax, val, &nval );
189 if( rc != LDAP_SUCCESS ) {
190 return LDAP_INAPPROPRIATE_MATCHING;
194 for ( i = 0; vals[i] != NULL; i++ ) {
198 rc = value_match( &match, ad, mr, 0,
199 vals[i], nval == NULL ? val : nval, &text );
201 if( rc == LDAP_SUCCESS && match == 0 ) {
208 return LDAP_NO_SUCH_ATTRIBUTE;