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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
59 struct berval ***vals,
60 struct berval **addvals,
68 if ( *maxvals == 0 ) {
71 need = nvals + naddvals + 1;
72 while ( *maxvals < need ) {
74 *vals = (struct berval **) ch_realloc( (char *) *vals,
75 *maxvals * sizeof(struct berval *) );
78 for ( i = 0, j = 0; i < naddvals; i++ ) {
79 if ( addvals[i]->bv_len > 0 ) {
80 (*vals)[nvals + j] = ber_bvdup( addvals[i] );
81 if( (*vals)[nvals + j] != NULL ) j++;
84 (*vals)[nvals + j] = NULL;
90 #ifdef SLAPD_SCHEMA_NOT_COMPAT
93 AttributeDescription *ad,
102 switch( usage & SLAP_MR_TYPE_MASK ) {
104 case SLAP_MR_EQUALITY:
105 mr = ad->ad_type->sat_equality;
107 case SLAP_MR_ORDERING:
108 mr = ad->ad_type->sat_ordering;
111 mr = ad->ad_type->sat_substr;
116 *text = "internal error";
121 *text = "inappropriate matching request";
122 return LDAP_INAPPROPRIATE_MATCHING;
125 /* we only support equality matching of binary attributes */
126 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
127 *text = "inappropriate binary matching";
128 return LDAP_INAPPROPRIATE_MATCHING;
131 if( mr->smr_normalize ) {
132 rc = (mr->smr_normalize)( usage,
133 ad->ad_type->sat_syntax,
136 if( rc != LDAP_SUCCESS ) {
137 *text = "unable to normalize value";
138 return LDAP_INVALID_SYNTAX;
141 } else if ( mr->smr_syntax->ssyn_normalize ) {
142 rc = (mr->smr_syntax->ssyn_normalize)(
143 ad->ad_type->sat_syntax,
146 if( rc != LDAP_SUCCESS ) {
147 *text = "unable to normalize value";
148 return LDAP_INVALID_SYNTAX;
152 *out = ber_bvdup( in );
167 if ( ! (syntax & SYNTAX_CIS) ) {
171 if ( syntax & SYNTAX_DN ) {
172 (void) dn_normalize( s );
177 for ( d = s; *s; s++ ) {
178 if ( (syntax & SYNTAX_TEL) && (*s == ' ' || *s == '-') ) {
181 *d++ = TOUPPER( (unsigned char) *s );
187 #ifdef SLAPD_SCHEMA_NOT_COMPAT
191 AttributeDescription *ad,
193 struct berval *v1, /* stored value */
194 void *v2, /* assertion */
199 struct berval *nv1 = NULL;
201 if( !mr->smr_match ) {
202 return LDAP_INAPPROPRIATE_MATCHING;
205 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
206 rc = ad->ad_type->sat_syntax->ssyn_normalize(
207 ad->ad_type->sat_syntax, v1, &nv1 );
209 if( rc != LDAP_SUCCESS ) {
210 return LDAP_INAPPROPRIATE_MATCHING;
214 rc = (mr->smr_match)( match, usage,
215 ad->ad_type->sat_syntax,
217 nv1 != NULL ? nv1 : v1,
230 int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
235 if ( normalize & 1 ) {
236 v1 = ber_bvdup( v1 );
237 value_normalize( v1->bv_val, syntax );
239 if ( normalize & 2 ) {
240 v2 = ber_bvdup( v2 );
241 value_normalize( v2->bv_val, syntax );
246 case (SYNTAX_CIS | SYNTAX_TEL):
247 case (SYNTAX_CIS | SYNTAX_DN):
248 rc = strcasecmp( v1->bv_val, v2->bv_val );
252 rc = strcmp( v1->bv_val, v2->bv_val );
255 default: /* Unknown syntax */
257 rc = (v1->bv_len == v2->bv_len
258 ? memcmp( v1->bv_val, v2->bv_val, v1->bv_len )
259 : v1->bv_len > v2->bv_len ? 1 : -1);
263 if ( normalize & 1 ) {
266 if ( normalize & 2 ) {
274 #ifdef SLAPD_SCHEMA_NOT_COMPAT
276 AttributeDescription *ad,
277 struct berval **vals,
282 struct berval **vals,
289 #ifdef SLAPD_SCHEMA_NOT_COMPAT
291 struct berval *nval = NULL;
292 MatchingRule *mr = ad->ad_type->sat_equality;
294 if( mr == NULL || !mr->smr_match ) {
295 return LDAP_INAPPROPRIATE_MATCHING;
298 if( mr->smr_syntax->ssyn_normalize ) {
299 rc = mr->smr_syntax->ssyn_normalize(
300 mr->smr_syntax, val, &nval );
302 if( rc != LDAP_SUCCESS ) {
303 return LDAP_INAPPROPRIATE_MATCHING;
308 for ( i = 0; vals[i] != NULL; i++ ) {
309 #ifdef SLAPD_SCHEMA_NOT_COMPAT
313 rc = value_match( &match, ad, mr, vals[i],
314 nval == NULL ? val : nval, &text );
316 if( rc == LDAP_SUCCESS && match == 0 )
318 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 )
325 return LDAP_NO_SUCH_ATTRIBUTE;