]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/filterindex.c
Fixes for NO_THREADS
[openldap] / servers / slapd / back-ldbm / filterindex.c
index 67d2454789012c744e30a5e2332e79f65d4418d0..c59145e296053538b536034e41210c794b75d965 100644 (file)
@@ -1,7 +1,7 @@
 /* filterindex.c - generate the list of candidate entries from a filter */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -39,7 +39,7 @@ filter_candidates(
        ID_BLOCK        *result;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY, "filter_candidates: enter\n"));
+       LDAP_LOG( FILTER, ENTRY, "filter_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> filter_candidates\n", 0, 0, 0 );
 #endif
@@ -49,8 +49,8 @@ filter_candidates(
        switch ( f->f_choice ) {
        case SLAPD_FILTER_DN_ONE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  DN ONE (%s)\n", f->f_dn ));
+               LDAP_LOG( FILTER, DETAIL1, 
+                          "filter_candidates:  DN ONE (%s)\n", f->f_dn, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 );
 #endif
@@ -65,8 +65,8 @@ filter_candidates(
 
        case SLAPD_FILTER_DN_SUBTREE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  DN SUBTREE (%s)\n", f->f_dn ));
+               LDAP_LOG( FILTER, DETAIL1, 
+                          "filter_candidates:  DN SUBTREE (%s)\n", f->f_dn, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 );
 #endif
@@ -81,8 +81,9 @@ filter_candidates(
 
        case LDAP_FILTER_PRESENT:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  Present (%s)\n", f->f_desc->ad_cname.bv_val ));
+               LDAP_LOG( FILTER, DETAIL1, 
+                       "filter_candidates:  Present (%s)\n", 
+                       f->f_desc->ad_cname.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
 #endif
@@ -92,10 +93,10 @@ filter_candidates(
 
        case LDAP_FILTER_EQUALITY:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
+               LDAP_LOG( FILTER, DETAIL1, 
                           "filter_candidates:  EQUALITY (%s),(%s)\n",
                           f->f_ava->aa_desc->ad_cname.bv_val,
-                          f->f_ava->aa_value->bv_val ));
+                          f->f_ava->aa_value.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
 #endif
@@ -105,10 +106,10 @@ filter_candidates(
 
        case LDAP_FILTER_APPROX:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
+               LDAP_LOG( FILTER, DETAIL1, 
                           "filter_candidates:  APPROX (%s), (%s)\n",
                           f->f_ava->aa_desc->ad_cname.bv_val,
-                          f->f_ava->aa_value->bv_val ));
+                          f->f_ava->aa_value.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
 #endif
@@ -118,8 +119,8 @@ filter_candidates(
 
        case LDAP_FILTER_SUBSTRINGS:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  SUBSTRINGS\n"));
+               LDAP_LOG( FILTER, DETAIL1,
+                          "filter_candidates:  SUBSTRINGS\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
 #endif
@@ -129,30 +130,27 @@ filter_candidates(
 
        case LDAP_FILTER_GE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  GE\n"));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  GE\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
 #endif
 
-               result = presence_candidates( be, f->f_desc );
+               result = presence_candidates( be, f->f_ava->aa_desc );
                break;
 
        case LDAP_FILTER_LE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  LE\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  LE\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
 #endif
 
-               result = presence_candidates( be, f->f_desc );
+               result = presence_candidates( be, f->f_ava->aa_desc );
                break;
 
        case LDAP_FILTER_AND:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  AND\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  AND\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
 #endif
@@ -162,8 +160,7 @@ filter_candidates(
 
        case LDAP_FILTER_OR:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  OR\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  OR\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
 #endif
@@ -173,8 +170,7 @@ filter_candidates(
 
        case LDAP_FILTER_NOT:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  NOT\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  NOT\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
 #endif
@@ -187,12 +183,23 @@ filter_candidates(
                 */
                result = idl_allids( be );
                break;
+       default:
+#ifdef NEW_LOGGING
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  UNKNOWN\n", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN\n", 0, 0, 0 );
+#endif
+               /* unknown filters must not return NULL, to allow
+                * extended filter processing to be done later.
+                */
+               result = idl_allids( be );
+               break;
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "filter_candidates: return %ld\n",
-                  result ? ID_BLOCK_NIDS(result) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+               "filter_candidates: return %ld\n", 
+               result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= filter_candidates %ld\n",
            result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
@@ -212,26 +219,27 @@ presence_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval *prefix;
+       struct berval prefix = {0};
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "presence_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "presence_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
 #endif
 
-
        idl = idl_allids( be );
 
+       if( desc == slap_schema.si_ad_objectClass ) {
+               return idl;
+       }
+
        rc = index_param( be, desc, LDAP_FILTER_PRESENT,
                &dbname, &mask, &prefix );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                          "presence_candidates: index_param returned %d\n",
-                          rc ));
+               LDAP_LOG( FILTER, INFO, 
+                          "presence_candidates: index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= presence_candidates: index_param returned=%d\n",
@@ -244,15 +252,13 @@ presence_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                          "presence_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, INFO, "presence_candidates: not indexed\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= presense_candidates: not indexed\n",
                        0, 0, 0 );
 #endif
 
-               ber_bvfree( prefix );
                return idl;
        }
 
@@ -260,29 +266,28 @@ presence_candidates(
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
+               LDAP_LOG( FILTER, INFO, 
                           "presence_candidates: db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+                          dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= presense_candidates db open failed (%s%s)\n",
                        dbname, LDBM_SUFFIX, 0 );
 #endif
 
-               ber_bvfree( prefix );
                return idl;
        }
 
-       if( prefix != NULL ) {
+       if( prefix.bv_val != NULL ) {
                idl_free( idl );
                idl = NULL;
 
-               rc = key_read( be, db, prefix, &idl );
+               rc = key_read( be, db, &prefix, &idl );
 
                if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "presence_candidates: key read failed (%d)\n", rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "presence_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= presense_candidates key read failed (%d)\n",
@@ -292,8 +297,7 @@ presence_candidates(
 
                } else if( idl == NULL ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                                  "presence_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, DETAIL1, "presence_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= presense_candidates NULL\n",
@@ -304,12 +308,11 @@ presence_candidates(
        }
 
        ldbm_cache_close( be, db );
-       ber_bvfree( prefix );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "presence_candidates:  return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+               "presence_candidates:  return %ld\n", 
+               idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -330,13 +333,12 @@ equality_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval *prefix;
-       struct berval **keys = NULL;
+       struct berval prefix = {0};
+       struct berval *keys = NULL;
        MatchingRule *mr;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "equality_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "equality_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> equality_candidates\n", 0, 0, 0 );
 #endif
@@ -349,8 +351,8 @@ equality_candidates(
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates:  index_param returned %d\n", rc ));
+               LDAP_LOG( FILTER, ERR, 
+                          "equality_candidates:  index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: index_param returned=%d\n",
@@ -363,26 +365,22 @@ equality_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, ERR, "equality_candidates: not indexed\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: not indexed\n",
                        0, 0, 0 );
 #endif
 
-               ber_bvfree( prefix );
                return idl;
        }
 
        mr = ava->aa_desc->ad_type->sat_equality;
        if( !mr ) {
-               ber_bvfree( prefix );
                return idl;
        }
 
        if( !mr->smr_filter ) {
-               ber_bvfree( prefix );
                return idl;
        }
 
@@ -391,17 +389,15 @@ equality_candidates(
                mask,
                ava->aa_desc->ad_type->sat_syntax,
                mr,
-               prefix,
-               ava->aa_value,
+               &prefix,
+               &ava->aa_value,
                &keys );
 
-       ber_bvfree( prefix );
-
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "equality_candidates: (%s%s) MR filter failed (%d\n",
-                          dbname, LDBM_SUFFIX, rc ));
+                          dbname, LDBM_SUFFIX, rc );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: (%s%s) MR filter failed (%d)\n",
@@ -413,9 +409,8 @@ equality_candidates(
 
        if( keys == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates: no keys (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+               LDAP_LOG( FILTER, ERR, 
+                  "equality_candidates: no keys (%s%s)\n", dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: no keys (%s%s)\n",
@@ -429,9 +424,8 @@ equality_candidates(
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates: db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+               LDAP_LOG( FILTER, ERR, "equality_candidates: db open failed (%s%s)\n",
+                       dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= equality_candidates db open failed (%s%s)\n",
@@ -441,18 +435,18 @@ equality_candidates(
                return idl;
        }
 
-       for ( i= 0; keys[i] != NULL; i++ ) {
+       for ( i= 0; keys[i].bv_val != NULL; i++ ) {
                ID_BLOCK *save;
                ID_BLOCK *tmp;
 
-               rc = key_read( be, db, keys[i], &tmp );
+               rc = key_read( be, db, &keys[i], &tmp );
 
                if( rc != LDAP_SUCCESS ) {
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "equality_candidates: key read failed (%d)\n", rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "equality_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= equality_candidates key read failed (%d)\n",
@@ -466,8 +460,7 @@ equality_candidates(
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "equality_candidates NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "equality_candidates NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= equality_candidates NULL\n",
@@ -485,15 +478,15 @@ equality_candidates(
                if( idl == NULL ) break;
        }
 
-       ber_bvecfree( keys );
+       ber_bvarray_free( keys );
 
        ldbm_cache_close( be, db );
 
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "equality_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+                  "equality_candidates: return %ld\n", 
+                  idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= equality_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -514,13 +507,12 @@ approx_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval *prefix;
-       struct berval **keys = NULL;
+       struct berval prefix = {0};
+       struct berval *keys = NULL;
        MatchingRule *mr;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "approx_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "approx_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> approx_candidates\n", 0, 0, 0 );
 #endif
@@ -533,8 +525,8 @@ approx_candidates(
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "approx_candidates: index_param returned %d\n", rc ));
+               LDAP_LOG( FILTER, ERR, 
+                          "approx_candidates: index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= approx_candidates: index_param returned=%d\n",
@@ -547,15 +539,13 @@ approx_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "approx_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, ERR, "approx_candidates: not indexed\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= approx_candidates: not indexed\n",
                        0, 0, 0 );
 #endif
 
-               ber_bvfree( prefix );
                return idl;
        }
 
@@ -566,12 +556,10 @@ approx_candidates(
        }
 
        if( !mr ) {
-               ber_bvfree( prefix );
                return idl;
        }
 
        if( !mr->smr_filter ) {
-               ber_bvfree( prefix );
                return idl;
        }
 
@@ -580,17 +568,15 @@ approx_candidates(
                mask,
                ava->aa_desc->ad_type->sat_syntax,
                mr,
-               prefix,
-               ava->aa_value,
+               &prefix,
+               &ava->aa_value,
                &keys );
 
-       ber_bvfree( prefix );
-
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "approx_candidates: (%s%s) MR filter failed (%d)\n",
-                          dbname, LDBM_SUFFIX, rc ));
+                          dbname, LDBM_SUFFIX, rc );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= approx_candidates: (%s%s) MR filter failed (%d)\n",
@@ -602,9 +588,9 @@ approx_candidates(
 
        if( keys == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
+               LDAP_LOG( FILTER, INFO, 
                           "approx_candidates: no keys (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+                          dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= approx_candidates: no keys (%s%s)\n",
@@ -618,9 +604,9 @@ approx_candidates(
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "approx_candidates db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+               LDAP_LOG( FILTER, ERR, 
+                       "approx_candidates db open failed (%s%s)\n", 
+                       dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= approx_candidates db open failed (%s%s)\n",
@@ -630,18 +616,18 @@ approx_candidates(
                return idl;
        }
 
-       for ( i= 0; keys[i] != NULL; i++ ) {
+       for ( i= 0; keys[i].bv_val != NULL; i++ ) {
                ID_BLOCK *save;
                ID_BLOCK *tmp;
 
-               rc = key_read( be, db, keys[i], &tmp );
+               rc = key_read( be, db, &keys[i], &tmp );
 
                if( rc != LDAP_SUCCESS ) {
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "approx_candidates: key read failed (%d)\n", rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "approx_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= approx_candidates key read failed (%d)\n",
                            rc, 0, 0 );
@@ -654,8 +640,7 @@ approx_candidates(
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "approx_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "approx_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= approx_candidates NULL\n",
                            0, 0, 0 );
@@ -672,14 +657,14 @@ approx_candidates(
                if( idl == NULL ) break;
        }
 
-       ber_bvecfree( keys );
+       ber_bvarray_free( keys );
 
        ldbm_cache_close( be, db );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "approx_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+               "approx_candidates: return %ld\n", 
+               idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= approx_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -699,8 +684,7 @@ list_candidates(
        Filter  *f;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "list_candidates: 0x%x\n", ftype ));
+       LDAP_LOG( FILTER, ENTRY, "list_candidates: 0x%x\n", ftype, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> list_candidates 0x%x\n", ftype, 0, 0 );
 #endif
@@ -711,8 +695,7 @@ list_candidates(
                if ( (tmp = filter_candidates( be, f )) == NULL &&
                    ftype == LDAP_FILTER_AND ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "list_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "list_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                               "<= list_candidates NULL\n", 0, 0, 0 );
@@ -737,9 +720,8 @@ list_candidates(
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "list_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, "list_candidates: return %ld\n",
+                  idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= list_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -760,13 +742,12 @@ substring_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval *prefix;
-       struct berval **keys = NULL;
+       struct berval prefix = {0};
+       struct berval *keys = NULL;
        MatchingRule *mr;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "substrings_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "substrings_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> substrings_candidates\n", 0, 0, 0 );
 #endif
@@ -779,8 +760,8 @@ substring_candidates(
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "substrings_candidates: index_param returned %d\n", rc ));
+               LDAP_LOG( FILTER, ERR, 
+                          "substrings_candidates: index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= substrings_candidates: index_param returned=%d\n",
@@ -793,27 +774,23 @@ substring_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "substrings_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, ERR, "substrings_candidates: not indexed\n", 0, 0, 0);
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= substrings_candidates: not indexed\n",
                        0, 0, 0 );
 #endif
 
-               ber_bvfree( prefix );
                return idl;
        }
 
        mr = sub->sa_desc->ad_type->sat_substr;
 
        if( !mr ) {
-               ber_bvfree( prefix );
                return idl;
        }
 
        if( !mr->smr_filter ) {
-               ber_bvfree( prefix );
                return idl;
        }
 
@@ -822,17 +799,15 @@ substring_candidates(
                mask,
                sub->sa_desc->ad_type->sat_syntax,
                mr,
-               prefix,
+               &prefix,
                sub,
                &keys );
 
-       ber_bvfree( prefix );
-
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "substrings_candidates: (%s%s) MR filter failed (%d)\n",
-                          dbname, LDBM_SUFFIX, rc ));
+                          dbname, LDBM_SUFFIX, rc );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= substrings_candidates: (%s%s) MR filter failed (%d)\n",
@@ -844,9 +819,9 @@ substring_candidates(
 
        if( keys == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "substrings_candidates: (0x%04lx) no keys (%s%s)\n",
-                          mask, dbname, LDBM_SUFFIX ));
+                          mask, dbname, LDBM_SUFFIX );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= substrings_candidates: (0x%04lx) no keys (%s%s)\n",
@@ -860,9 +835,9 @@ substring_candidates(
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "substrings_candidates: db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+                          dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= substrings_candidates db open failed (%s%s)\n",
@@ -872,19 +847,18 @@ substring_candidates(
                return idl;
        }
 
-       for ( i= 0; keys[i] != NULL; i++ ) {
+       for ( i= 0; keys[i].bv_val != NULL; i++ ) {
                ID_BLOCK *save;
                ID_BLOCK *tmp;
 
-               rc = key_read( be, db, keys[i], &tmp );
+               rc = key_read( be, db, &keys[i], &tmp );
 
                if( rc != LDAP_SUCCESS ) {
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "substrings_candidates: key read failed (%d)\n",
-                                  rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "substrings_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates key read failed (%d)\n",
                            rc, 0, 0 );
@@ -897,8 +871,7 @@ substring_candidates(
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "substrings_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "substrings_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates NULL\n",
                            0, 0, 0 );
@@ -915,14 +888,14 @@ substring_candidates(
                if( idl == NULL ) break;
        }
 
-       ber_bvecfree( keys );
+       ber_bvarray_free( keys );
 
        ldbm_cache_close( be, db );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
+       LDAP_LOG( FILTER, ENTRY, 
                   "substrings_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+                  idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );