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] );
46 (*vals)[nvals + j] = NULL;
53 struct berval ***vals,
54 struct berval **addvals
59 for ( nn = 0; addvals != NULL && addvals[nn] != NULL; nn++ )
62 if ( *vals == NULL ) {
63 *vals = (struct berval **) ch_malloc( (nn + 1)
64 * sizeof(struct berval *) );
67 for ( n = 0; (*vals)[n] != NULL; n++ )
69 *vals = (struct berval **) ch_realloc( (char *) *vals,
70 (n + nn + 1) * sizeof(struct berval *) );
73 for ( i = 0, j = 0; i < nn; i++ ) {
74 if ( addvals[i]->bv_len > 0 ) {
75 (*vals)[n + j++] = ber_bvdup( addvals[i] );
78 (*vals)[n + j] = NULL;
91 if ( ! (syntax & SYNTAX_CIS) ) {
95 if ( syntax & SYNTAX_DN ) {
96 (void) dn_normalize_case( s );
101 for ( d = s; *s; s++ ) {
102 if ( (syntax & SYNTAX_TEL) && (*s == ' ' || *s == '-') ) {
105 *d++ = TOUPPER( (unsigned char) *s );
115 int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
120 if ( normalize & 1 ) {
121 v1 = ber_bvdup( v1 );
122 value_normalize( v1->bv_val, syntax );
124 if ( normalize & 2 ) {
125 v2 = ber_bvdup( v2 );
126 value_normalize( v2->bv_val, syntax );
131 case (SYNTAX_CIS | SYNTAX_TEL):
132 case (SYNTAX_CIS | SYNTAX_DN):
133 rc = strcasecmp( v1->bv_val, v2->bv_val );
137 rc = strcmp( v1->bv_val, v2->bv_val );
141 rc = (v1->bv_len == v2->bv_len
142 ? memcmp( v1->bv_val, v2->bv_val, v1->bv_len )
143 : v1->bv_len > v2->bv_len ? 1 : -1);
147 if ( normalize & 1 ) {
150 if ( normalize & 2 ) {
159 struct berval **vals,
167 for ( i = 0; vals[i] != NULL; i++ ) {
168 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {