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;
54 #ifndef SLAPD_SCHEMA_NOT_COMPAT
57 struct berval ***vals,
58 struct berval **addvals,
66 if ( *maxvals == 0 ) {
69 need = nvals + naddvals + 1;
70 while ( *maxvals < need ) {
72 *vals = (struct berval **) ch_realloc( (char *) *vals,
73 *maxvals * sizeof(struct berval *) );
76 for ( i = 0, j = 0; i < naddvals; i++ ) {
77 if ( addvals[i]->bv_len > 0 ) {
78 (*vals)[nvals + j] = ber_bvdup( addvals[i] );
79 if( (*vals)[nvals + j] != NULL ) j++;
82 (*vals)[nvals + j] = NULL;
88 #ifdef SLAPD_SCHEMA_NOT_COMPAT
91 AttributeDescription *ad,
100 switch( usage & SLAP_MR_TYPE_MASK ) {
102 case SLAP_MR_EQUALITY:
103 mr = ad->ad_type->sat_equality;
105 case SLAP_MR_ORDERING:
106 mr = ad->ad_type->sat_ordering;
109 mr = ad->ad_type->sat_substr;
114 *text = "internal error";
119 *text = "inappropriate matching request";
120 return LDAP_INAPPROPRIATE_MATCHING;
123 /* we only support equality matching of binary attributes */
124 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
125 *text = "inappropriate binary matching";
126 return LDAP_INAPPROPRIATE_MATCHING;
129 if( mr->smr_normalize ) {
130 rc = (mr->smr_normalize)( usage,
131 ad->ad_type->sat_syntax,
134 if( rc != LDAP_SUCCESS ) {
135 *text = "unable to normalize value";
136 return LDAP_INVALID_SYNTAX;
139 } else if ( mr->smr_syntax->ssyn_normalize ) {
140 rc = (mr->smr_syntax->ssyn_normalize)(
141 ad->ad_type->sat_syntax,
144 if( rc != LDAP_SUCCESS ) {
145 *text = "unable to normalize value";
146 return LDAP_INVALID_SYNTAX;
150 *out = ber_bvdup( in );
165 if ( ! (syntax & SYNTAX_CIS) ) {
169 if ( syntax & SYNTAX_DN ) {
170 (void) dn_normalize( s );
175 for ( d = s; *s; s++ ) {
176 if ( (syntax & SYNTAX_TEL) && (*s == ' ' || *s == '-') ) {
179 *d++ = TOUPPER( (unsigned char) *s );
185 #ifdef SLAPD_SCHEMA_NOT_COMPAT
189 AttributeDescription *ad,
191 struct berval *v1, /* stored value */
192 void *v2, /* assertion */
197 struct berval *nv1 = NULL;
199 if( !mr->smr_match ) {
200 return LDAP_INAPPROPRIATE_MATCHING;
203 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
204 rc = ad->ad_type->sat_syntax->ssyn_normalize(
205 ad->ad_type->sat_syntax, v1, &nv1 );
207 if( rc != LDAP_SUCCESS ) {
208 return LDAP_INAPPROPRIATE_MATCHING;
212 rc = (mr->smr_match)( match, usage,
213 ad->ad_type->sat_syntax,
215 nv1 != NULL ? nv1 : v1,
228 int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
233 if ( normalize & 1 ) {
234 v1 = ber_bvdup( v1 );
235 value_normalize( v1->bv_val, syntax );
237 if ( normalize & 2 ) {
238 v2 = ber_bvdup( v2 );
239 value_normalize( v2->bv_val, syntax );
244 case (SYNTAX_CIS | SYNTAX_TEL):
245 case (SYNTAX_CIS | SYNTAX_DN):
246 rc = strcasecmp( v1->bv_val, v2->bv_val );
250 rc = strcmp( v1->bv_val, v2->bv_val );
253 default: /* Unknown syntax */
255 rc = (v1->bv_len == v2->bv_len
256 ? memcmp( v1->bv_val, v2->bv_val, v1->bv_len )
257 : v1->bv_len > v2->bv_len ? 1 : -1);
261 if ( normalize & 1 ) {
264 if ( normalize & 2 ) {
272 #ifdef SLAPD_SCHEMA_NOT_COMPAT
274 AttributeDescription *ad,
275 struct berval **vals,
280 struct berval **vals,
287 #ifdef SLAPD_SCHEMA_NOT_COMPAT
289 struct berval *nval = NULL;
290 MatchingRule *mr = ad->ad_type->sat_equality;
292 if( mr == NULL || !mr->smr_match ) {
293 return LDAP_INAPPROPRIATE_MATCHING;
296 if( mr->smr_syntax->ssyn_normalize ) {
297 rc = mr->smr_syntax->ssyn_normalize(
298 mr->smr_syntax, val, &nval );
300 if( rc != LDAP_SUCCESS ) {
301 return LDAP_INAPPROPRIATE_MATCHING;
306 for ( i = 0; vals[i] != NULL; i++ ) {
307 #ifdef SLAPD_SCHEMA_NOT_COMPAT
311 rc = value_match( &match, ad, mr, vals[i],
312 nval == NULL ? val : nval, &text );
314 if( rc == LDAP_SUCCESS && match == 0 )
316 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 )
323 return LDAP_NO_SUCH_ATTRIBUTE;