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;
142 *out = ber_bvdup( in );
157 if ( ! (syntax & SYNTAX_CIS) ) {
161 if ( syntax & SYNTAX_DN ) {
162 (void) dn_normalize( s );
167 for ( d = s; *s; s++ ) {
168 if ( (syntax & SYNTAX_TEL) && (*s == ' ' || *s == '-') ) {
171 *d++ = TOUPPER( (unsigned char) *s );
177 #ifdef SLAPD_SCHEMA_NOT_COMPAT
181 AttributeDescription *ad,
183 struct berval *v1, /* (unnormalized) stored value */
184 struct berval *v2, /* (normalized) asserted value */
189 struct berval *nv1 = NULL;
191 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
192 rc = ad->ad_type->sat_syntax->ssyn_normalize(
193 ad->ad_type->sat_syntax, v1, &nv1 );
195 if( rc != LDAP_SUCCESS ) {
196 return LDAP_INAPPROPRIATE_MATCHING;
200 if( !mr->smr_match ) {
201 return LDAP_INAPPROPRIATE_MATCHING;
204 rc = (mr->smr_match)( match, usage,
205 ad->ad_type->sat_syntax,
207 nv1 != NULL ? nv1 : v1,
220 int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
225 if ( normalize & 1 ) {
226 v1 = ber_bvdup( v1 );
227 value_normalize( v1->bv_val, syntax );
229 if ( normalize & 2 ) {
230 v2 = ber_bvdup( v2 );
231 value_normalize( v2->bv_val, syntax );
236 case (SYNTAX_CIS | SYNTAX_TEL):
237 case (SYNTAX_CIS | SYNTAX_DN):
238 rc = strcasecmp( v1->bv_val, v2->bv_val );
242 rc = strcmp( v1->bv_val, v2->bv_val );
245 default: /* Unknown syntax */
247 rc = (v1->bv_len == v2->bv_len
248 ? memcmp( v1->bv_val, v2->bv_val, v1->bv_len )
249 : v1->bv_len > v2->bv_len ? 1 : -1);
253 if ( normalize & 1 ) {
256 if ( normalize & 2 ) {
264 #ifdef SLAPD_SCHEMA_NOT_COMPAT
266 AttributeDescription *ad,
268 struct berval **vals,
274 struct berval **vals,
282 for ( i = 0; vals[i] != NULL; i++ ) {
283 #ifdef SLAPD_SCHEMA_NOT_COMPAT
286 rc = value_match( &match, ad, mr, vals[i], val, text );
288 if( rc == LDAP_SUCCESS && match == 0 )
290 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 )
297 return LDAP_NO_SUCH_ATTRIBUTE;