1 /* value.c - routines for dealing with values */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
22 struct berval ***vals,
23 struct berval **addvals,
31 if ( *maxvals == 0 ) {
34 need = nvals + naddvals + 1;
35 while ( *maxvals < need ) {
37 *vals = (struct berval **) ch_realloc( (char *) *vals,
38 *maxvals * sizeof(struct berval *) );
41 for ( i = 0, j = 0; i < naddvals; i++, j++ ) {
42 if ( addvals[i]->bv_len > 0 ) {
43 (*vals)[nvals + j] = ber_bvdup( addvals[i] );
44 if( (*vals)[nvals + j] == NULL ) break;
47 (*vals)[nvals + j] = NULL;
54 struct berval ***vals,
55 struct berval **addvals
60 for ( nn = 0; addvals != NULL && addvals[nn] != NULL; nn++ )
63 if ( *vals == NULL ) {
64 *vals = (struct berval **) ch_malloc( (nn + 1)
65 * sizeof(struct berval *) );
68 for ( n = 0; (*vals)[n] != NULL; n++ )
70 *vals = (struct berval **) ch_realloc( (char *) *vals,
71 (n + nn + 1) * sizeof(struct berval *) );
74 for ( i = 0, j = 0; i < nn; i++ ) {
75 if ( addvals[i]->bv_len > 0 ) {
76 (*vals)[n + j] = ber_bvdup( addvals[i] );
77 if( (*vals)[n + j++] == NULL ) break;
80 (*vals)[n + j] = NULL;
93 if ( ! (syntax & SYNTAX_CIS) ) {
97 if ( syntax & SYNTAX_DN ) {
98 (void) dn_normalize_case( s );
103 for ( d = s; *s; s++ ) {
104 if ( (syntax & SYNTAX_TEL) && (*s == ' ' || *s == '-') ) {
107 *d++ = TOUPPER( (unsigned char) *s );
117 int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
122 if ( normalize & 1 ) {
123 v1 = ber_bvdup( v1 );
124 value_normalize( v1->bv_val, syntax );
126 if ( normalize & 2 ) {
127 v2 = ber_bvdup( v2 );
128 value_normalize( v2->bv_val, syntax );
133 case (SYNTAX_CIS | SYNTAX_TEL):
134 case (SYNTAX_CIS | SYNTAX_DN):
135 rc = strcasecmp( v1->bv_val, v2->bv_val );
139 rc = strcmp( v1->bv_val, v2->bv_val );
142 default: /* Unknown syntax */
144 rc = (v1->bv_len == v2->bv_len
145 ? memcmp( v1->bv_val, v2->bv_val, v1->bv_len )
146 : v1->bv_len > v2->bv_len ? 1 : -1);
150 if ( normalize & 1 ) {
153 if ( normalize & 2 ) {
162 struct berval **vals,
170 for ( i = 0; vals[i] != NULL; i++ ) {
171 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {