]> git.sur5r.net Git - openldap/commitdiff
Additional indexer normalization (need to check all Indexers)
authorKurt Zeilenga <kurt@openldap.org>
Tue, 25 Feb 2003 19:21:18 +0000 (19:21 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 25 Feb 2003 19:21:18 +0000 (19:21 +0000)
servers/slapd/schema_init.c

index c7f4aadbf09755f60cf7b3d278d823822d33c88d..53cdb6a6f2bc9a20c8221cefdfcc662aa12d3b9c 100644 (file)
@@ -1390,11 +1390,11 @@ static int caseExactIgnoreSubstringsIndexer(
        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];
@@ -1414,10 +1414,39 @@ static int caseExactIgnoreSubstringsIndexer(
        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;
 
@@ -1455,7 +1484,8 @@ static int caseExactIgnoreSubstringsIndexer(
        if( nkeys == 0 ) {
                /* no keys to generate */
                *keysp = NULL;
-               ber_bvarray_free( nvalues );
+               ber_bvarray_free( tvalues );
+               ch_free( nvalues );
                return LDAP_SUCCESS;
        }
 
@@ -1556,7 +1586,8 @@ static int caseExactIgnoreSubstringsIndexer(
                *keysp = NULL;
        }
 
-       ber_bvarray_free( nvalues );
+       ber_bvarray_free( tvalues );
+       ch_free( nvalues );
 
        return LDAP_SUCCESS;
 }