BerVarray values,
BerVarray *keysp )
{
- unsigned casefold;
- ber_len_t i, nkeys;
+ unsigned casefold, wasspace;
+ ber_len_t i, j, nkeys;
size_t slen, mlen;
BerVarray keys;
- BerVarray nvalues;
+ BerVarray tvalues, nvalues;
HASH_CONTEXT HASHcontext;
unsigned char HASHdigest[HASH_BYTES];
casefold = ( mr != caseExactSubstringsMatchingRule )
? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
+ tvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
+
for( i=0; values[i].bv_val != NULL; i++ ) {
- UTF8bvnormalize( &values[i], &nvalues[i], casefold );
+ UTF8bvnormalize( &values[i], &tvalues[i], casefold );
+
+ /* collapse spaces (in place) */
+ nvalues[i].bv_len = 0;
+ nvalues[i].bv_val = tvalues[i].bv_val;
+
+ wasspace=1;
+ for( j=0; j<tvalues[i].bv_len; j++) {
+ if ( ASCII_SPACE( tvalues[i].bv_val[j] )) {
+ if( wasspace++ == 0 ) {
+ nvalues[i].bv_val[nvalues[i].bv_len++] =
+ tvalues[i].bv_val[j];
+ }
+ } else {
+ wasspace = 0;
+ nvalues[i].bv_val[nvalues[i].bv_len++] = tvalues[i].bv_val[j];
+ }
+ }
+
+ if( nvalues[i].bv_len == 0 ) {
+ nvalues[i].bv_val = " ";
+ nvalues[i].bv_len = sizeof(" ")-1;
+ } else {
+ if( wasspace ) --nvalues[i].bv_len;
+ nvalues[i].bv_val[nvalues[i].bv_len] = '\0';
+ }
}
+
+ tvalues[i].bv_val = NULL;
nvalues[i].bv_val = NULL;
values = nvalues;
if( nkeys == 0 ) {
/* no keys to generate */
*keysp = NULL;
- ber_bvarray_free( nvalues );
+ ber_bvarray_free( tvalues );
+ ch_free( nvalues );
return LDAP_SUCCESS;
}
*keysp = NULL;
}
- ber_bvarray_free( nvalues );
+ ber_bvarray_free( tvalues );
+ ch_free( nvalues );
return LDAP_SUCCESS;
}