1 /* value.c - routines for dealing with values */
4 * Copyright 1998-1999 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,
32 if ( *maxvals == 0 ) {
35 need = nvals + naddvals + 1;
36 while ( *maxvals < need ) {
38 *vals = (struct berval **) ch_realloc( (char *) *vals,
39 *maxvals * sizeof(struct berval *) );
42 for ( i = 0, j = 0; i < naddvals; i++ ) {
43 if ( addvals[i]->bv_len > 0 ) {
44 (*vals)[nvals + j] = ber_bvdup( addvals[i] );
45 if( (*vals)[nvals + j] != NULL ) j++;
48 (*vals)[nvals + j] = NULL;
55 struct berval ***vals,
56 struct berval **addvals
61 for ( nn = 0; addvals != NULL && addvals[nn] != NULL; nn++ )
64 if ( *vals == NULL ) {
65 *vals = (struct berval **) ch_malloc( (nn + 1)
66 * sizeof(struct berval *) );
69 for ( n = 0; (*vals)[n] != NULL; n++ )
71 *vals = (struct berval **) ch_realloc( (char *) *vals,
72 (n + nn + 1) * sizeof(struct berval *) );
75 for ( i = 0, j = 0; i < nn; i++ ) {
76 if ( addvals[i]->bv_len > 0 ) {
77 (*vals)[n + j] = ber_bvdup( addvals[i] );
78 if( (*vals)[n + j++] == NULL ) break;
81 (*vals)[n + j] = NULL;
86 #ifdef SLAPD_SCHEMA_NOT_COMPAT
87 /* not yet implemented */
97 if ( ! (syntax & SYNTAX_CIS) ) {
101 if ( syntax & SYNTAX_DN ) {
102 (void) dn_normalize( s );
107 for ( d = s; *s; s++ ) {
108 if ( (syntax & SYNTAX_TEL) && (*s == ' ' || *s == '-') ) {
111 *d++ = TOUPPER( (unsigned char) *s );
121 int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
126 if ( normalize & 1 ) {
127 v1 = ber_bvdup( v1 );
128 value_normalize( v1->bv_val, syntax );
130 if ( normalize & 2 ) {
131 v2 = ber_bvdup( v2 );
132 value_normalize( v2->bv_val, syntax );
137 case (SYNTAX_CIS | SYNTAX_TEL):
138 case (SYNTAX_CIS | SYNTAX_DN):
139 rc = strcasecmp( v1->bv_val, v2->bv_val );
143 rc = strcmp( v1->bv_val, v2->bv_val );
146 default: /* Unknown syntax */
148 rc = (v1->bv_len == v2->bv_len
149 ? memcmp( v1->bv_val, v2->bv_val, v1->bv_len )
150 : v1->bv_len > v2->bv_len ? 1 : -1);
154 if ( normalize & 1 ) {
157 if ( normalize & 2 ) {
166 struct berval **vals,
174 for ( i = 0; vals[i] != NULL; i++ ) {
175 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {