]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/index.c
NVALUES: fix a couple of value_find_ex() calls
[openldap] / servers / slapd / back-bdb / index.c
index bca4444eb4f14a7818875338d207efd590d3e906..1120054eb3f8b6a7c8f670fd4ccfa8cd43f8a6d1 100644 (file)
@@ -1,7 +1,7 @@
 /* index.c - routines for dealing with attribute indexes */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -36,14 +36,14 @@ static slap_mask_t index_mask(
                return mask;
        }
 
-       /* If there is a language tag, did we ever index the base
+       /* If there is a tagging option, did we ever index the base
         * type? If so, check for mask, otherwise it's not there.
         */
-       if( slap_ad_is_lang( desc ) && desc != desc->ad_type->sat_ad ) {
-               /* has language tag */
+       if( slap_ad_is_tagged( desc ) && desc != desc->ad_type->sat_ad ) {
+               /* has tagging option */
                bdb_attr_mask( be->be_private, desc->ad_type->sat_ad, &mask );
 
-               if (! ( mask & SLAP_INDEX_NOLANG ) ) {
+               if ( mask && ( mask ^ SLAP_INDEX_NOTAGS ) ) {
                        *atname = desc->ad_type->sat_cname;
                        *dbname = desc->ad_type->sat_cname.bv_val;
                        return mask;
@@ -57,19 +57,11 @@ static slap_mask_t index_mask(
 
                bdb_attr_mask( be->be_private, at->sat_ad, &mask );
 
-               if( mask & SLAP_INDEX_AUTO_SUBTYPES ) {
-                       *atname = desc->ad_type->sat_cname;
-                       *dbname = at->sat_cname.bv_val;
-                       return mask;
-               }
-
-               if( !( mask & SLAP_INDEX_NOSUBTYPES ) ) {
+               if ( mask && ( mask ^ SLAP_INDEX_NOSUBTYPES ) ) {
                        *atname = at->sat_cname;
                        *dbname = at->sat_cname.bv_val;
                        return mask;
                }
-
-               if( mask ) break;
        }
 
        return 0;
@@ -79,7 +71,6 @@ int bdb_index_is_indexed(
        Backend *be,
        AttributeDescription *desc )
 {
-       int rc;
        slap_mask_t mask;
        char *dbname;
        struct berval prefix;
@@ -90,7 +81,7 @@ int bdb_index_is_indexed(
                return LDAP_INAPPROPRIATE_MATCHING;
        }
 
-       return LDAP_SUCCESS;
+       return LDAP_SUCCESS;
 }
 
 int bdb_index_param(
@@ -121,6 +112,7 @@ int bdb_index_param(
        switch( ftype ) {
        case LDAP_FILTER_PRESENT:
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
+                       *prefixp = presence_key;
                        goto done;
                }
                break;
@@ -177,8 +169,8 @@ static int indexer(
        
        if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "index", LDAP_LEVEL_ERR,
-                       "bdb_index_read: Could not open DB %s\n", dbname));
+               LDAP_LOG( INDEX, ERR, 
+                       "bdb_index_read: Could not open DB %s\n", dbname, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "<= bdb_index_read NULL (could not open %s)\n",
@@ -270,24 +262,19 @@ static int index_at_values(
        Backend *be,
        DB_TXN *txn,
        AttributeType *type,
-       struct berval *lang,
+       struct berval *tags,
        BerVarray vals,
        ID id,
-       int op,
-       char ** dbnamep,
-       slap_mask_t *maskp )
+       int op )
 {
        int rc;
        slap_mask_t mask = 0;
-       slap_mask_t tmpmask = 0;
-       int lindex = 0;
 
        if( type->sat_sup ) {
                /* recurse */
                rc = index_at_values( be, txn,
-                       type->sat_sup, lang,
-                       vals, id, op,
-                       dbnamep, &tmpmask );
+                       type->sat_sup, tags,
+                       vals, id, op );
 
                if( rc ) return rc;
        }
@@ -298,13 +285,7 @@ static int index_at_values(
        }
 
        if( mask ) {
-               *dbnamep = type->sat_cname.bv_val;
-       } else if ( !( tmpmask & SLAP_INDEX_AUTO_SUBTYPES ) ) {
-               mask = tmpmask;
-       }
-
-       if( mask ) {
-               rc = indexer( be, txn, *dbnamep,
+               rc = indexer( be, txn, type->sat_cname.bv_val,
                        &type->sat_cname,
                        vals, id, op,
                        mask );
@@ -312,33 +293,22 @@ static int index_at_values(
                if( rc ) return rc;
        }
 
-       if( lang->bv_len ) {
-               char *dbname = NULL;
-               struct berval lname;
+       if( tags->bv_len ) {
                AttributeDescription *desc;
 
-               tmpmask = 0;
-               lname.bv_val = NULL;
+               mask = 0;
 
-               desc = ad_find_lang( type, lang );
+               desc = ad_find_tags( type, tags );
                if( desc ) {
-                       bdb_attr_mask( be->be_private, desc, &tmpmask );
-               }
-
-               if( tmpmask ) {
-                       dbname = desc->ad_cname.bv_val;
-                       lname = desc->ad_cname;
-                       mask = tmpmask;
+                       bdb_attr_mask( be->be_private, desc, &mask );
                }
 
-               if( dbname != NULL ) {
-                       rc = indexer( be, txn, dbname, &lname,
+               if( mask ) {
+                       rc = indexer( be, txn, desc->ad_cname.bv_val,
+                               &desc->ad_cname,
                                vals, id, op,
                                mask );
 
-                       if( !tmpmask ) {
-                               ch_free( lname.bv_val );
-                       }
                        if( rc ) {
                                return rc;
                        }
@@ -357,13 +327,10 @@ int bdb_index_values(
        int op )
 {
        int rc;
-       char *dbname = NULL;
-       slap_mask_t mask;
 
        rc = index_at_values( be, txn,
-               desc->ad_type, &desc->ad_lang,
-               vals, id, op,
-               &dbname, &mask );
+               desc->ad_type, &desc->ad_tags,
+               vals, id, op );
 
        return rc;
 }
@@ -379,10 +346,8 @@ bdb_index_entry(
        int rc;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-               "index_entry: %s (%s) %ld\n",
-               op == SLAP_INDEX_ADD_OP ? "add" : "del",
-               e->e_dn, (long) e->e_id ));
+       LDAP_LOG( INDEX, ENTRY, "index_entry: %s (%s) %ld\n",
+               op == SLAP_INDEX_ADD_OP ? "add" : "del", e->e_dn, (long) e->e_id );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> index_entry_%s( %ld, \"%s\" )\n",
                op == SLAP_INDEX_ADD_OP ? "add" : "del",
@@ -391,16 +356,22 @@ bdb_index_entry(
 
        /* add each attribute to the indexes */
        for ( ; ap != NULL; ap = ap->a_next ) {
-               rc = bdb_index_values( be, txn,
-                       ap->a_desc, ap->a_vals, e->e_id, op );
+#ifdef SLAP_NVALUES
+               rc = bdb_index_values( be, txn, ap->a_desc,
+                       ap->a_nvals ? ap->a_nvals : ap->a_vals,
+                       e->e_id, op );
+#else
+               rc = bdb_index_values( be, txn, ap->a_desc,
+                       ap->a_vals, e->e_id, op );
+#endif
 
                if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-                               "index_entry: success\n" ));
+                       LDAP_LOG( INDEX, ENTRY, 
+                               "index_entry: failure (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
-                               "<= index_entry_%s( %ld, \"%s\" ) success\n",
+                               "<= index_entry_%s( %ld, \"%s\" ) failure\n",
                                op == SLAP_INDEX_ADD_OP ? "add" : "del",
                                (long) e->e_id, e->e_dn );
 #endif
@@ -409,8 +380,7 @@ bdb_index_entry(
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-               "index_entry: success\n" ));
+       LDAP_LOG( INDEX, ENTRY, "index_entry: success\n", 0, 0, 0  );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= index_entry_%s( %ld, \"%s\" ) success\n",
                op == SLAP_INDEX_ADD_OP ? "add" : "del",