/* index.c - routines for dealing with attribute indexes */
/* $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
*/
#include "slap.h"
#include "back-bdb.h"
+#include "lutil_hash.h"
+
+static char presence_keyval[LUTIL_HASH_BYTES] = {0,0,0,1};
+static struct berval presence_key = {LUTIL_HASH_BYTES, presence_keyval};
static slap_mask_t index_mask(
Backend *be,
AttributeDescription *desc,
char **dbname,
- char **atname )
+ struct berval *atname )
{
AttributeType *at;
slap_mask_t mask = 0;
- /* we do not support indexing of binary attributes */
- if( slap_ad_is_binary( desc ) ) return 0;
-
- bdb_attr_mask( be->be_private, desc->ad_cname->bv_val, &mask );
+ bdb_attr_mask( be->be_private, desc, &mask );
if( mask ) {
- *atname = desc->ad_cname->bv_val;
- *dbname = desc->ad_cname->bv_val;
+ *atname = desc->ad_cname;
+ *dbname = desc->ad_cname.bv_val;
return mask;
}
- if( slap_ad_is_lang( desc ) ) {
+ /* If there is a language tag, 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 */
- bdb_attr_mask( be->be_private, desc->ad_type->sat_cname, &mask );
+ bdb_attr_mask( be->be_private, desc->ad_type->sat_ad, &mask );
- if( mask & SLAP_INDEX_AUTO_LANG ) {
- *atname = desc->ad_cname->bv_val;
- *dbname = desc->ad_type->sat_cname;
- return mask;
- }
- if( mask & SLAP_INDEX_LANG ) {
+ if ( mask && ( mask ^ SLAP_INDEX_NOLANG ) ) {
*atname = desc->ad_type->sat_cname;
- *dbname = desc->ad_type->sat_cname;
+ *dbname = desc->ad_type->sat_cname.bv_val;
return mask;
}
}
/* see if supertype defined mask for its subtypes */
for( at = desc->ad_type; at != NULL ; at = at->sat_sup ) {
- bdb_attr_mask( be->be_private, at->sat_cname, &mask );
+ /* If no AD, we've never indexed this type */
+ if ( !at->sat_ad ) continue;
- if( mask & SLAP_INDEX_AUTO_SUBTYPES ) {
- *atname = desc->ad_type->sat_cname;
- *dbname = at->sat_cname;
- return mask;
- }
- if( mask & SLAP_INDEX_SUBTYPES ) {
+ bdb_attr_mask( be->be_private, at->sat_ad, &mask );
+
+ if ( mask && ( mask ^ SLAP_INDEX_NOSUBTYPES ) ) {
*atname = at->sat_cname;
- *dbname = at->sat_cname;
+ *dbname = at->sat_cname.bv_val;
return mask;
}
-
- if( mask ) break;
}
return 0;
}
+int bdb_index_is_indexed(
+ Backend *be,
+ AttributeDescription *desc )
+{
+ slap_mask_t mask;
+ char *dbname;
+ struct berval prefix;
+
+ mask = index_mask( be, desc, &dbname, &prefix );
+
+ if( mask == 0 ) {
+ return LDAP_INAPPROPRIATE_MATCHING;
+ }
+
+ return LDAP_SUCCESS;
+}
+
int bdb_index_param(
Backend *be,
AttributeDescription *desc,
int ftype,
- char **dbnamep,
+ DB **dbp,
slap_mask_t *maskp,
- struct berval **prefixp )
+ struct berval *prefixp )
{
+ int rc;
slap_mask_t mask;
+ DB *db;
char *dbname;
- char *atname;
- mask = index_mask( be, desc, &dbname, &atname );
+ mask = index_mask( be, desc, &dbname, prefixp );
if( mask == 0 ) {
return LDAP_INAPPROPRIATE_MATCHING;
}
- switch(ftype) {
+ rc = bdb_db_cache( be, dbname, &db );
+
+ if( rc != LDAP_SUCCESS ) {
+ return rc;
+ }
+
+ switch( ftype ) {
case LDAP_FILTER_PRESENT:
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
goto done;
return LDAP_INAPPROPRIATE_MATCHING;
done:
- *dbnamep = dbname;
- *prefixp = ber_bvstrdup( atname );
+ *dbp = db;
*maskp = mask;
return LDAP_SUCCESS;
}
Backend *be,
DB_TXN *txn,
char *dbname,
- char *atname,
- struct berval **vals,
+ struct berval *atname,
+ BerVarray vals,
ID id,
int op,
slap_mask_t mask )
const char *text;
DB *db;
AttributeDescription *ad = NULL;
- struct berval **keys;
- struct berval prefix;
+ struct berval *keys;
assert( mask );
return LDAP_OTHER;
}
- rc = slap_str2ad( atname, &ad, &text );
+ rc = slap_bv2ad( atname, &ad, &text );
if( rc != LDAP_SUCCESS ) return rc;
- prefix.bv_val = atname;
- prefix.bv_len = strlen( atname );
-
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
- rc = bdb_key_change( be, db, txn, &prefix, id, op );
+ rc = bdb_key_change( be, db, txn, &presence_key, id, op );
if( rc ) {
goto done;
}
mask,
ad->ad_type->sat_syntax,
ad->ad_type->sat_equality,
- &prefix, vals, &keys );
+ atname, vals, &keys );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i] != NULL; i++ ) {
- rc = bdb_key_change( be, db, txn, keys[i], id, op );
+ for( i=0; keys[i].bv_val != NULL; i++ ) {
+ rc = bdb_key_change( be, db, txn, &keys[i], id, op );
if( rc ) {
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
goto done;
}
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
}
rc = LDAP_SUCCESS;
}
mask,
ad->ad_type->sat_syntax,
ad->ad_type->sat_approx,
- &prefix, vals, &keys );
+ atname, vals, &keys );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i] != NULL; i++ ) {
- rc = bdb_key_change( be, db, txn, keys[i], id, op );
+ for( i=0; keys[i].bv_val != NULL; i++ ) {
+ rc = bdb_key_change( be, db, txn, &keys[i], id, op );
if( rc ) {
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
goto done;
}
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
}
rc = LDAP_SUCCESS;
mask,
ad->ad_type->sat_syntax,
ad->ad_type->sat_substr,
- &prefix, vals, &keys );
+ atname, vals, &keys );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i] != NULL; i++ ) {
- bdb_key_change( be, db, txn, keys[i], id, op );
+ for( i=0; keys[i].bv_val != NULL; i++ ) {
+ bdb_key_change( be, db, txn, &keys[i], id, op );
if( rc ) {
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
goto done;
}
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
}
rc = LDAP_SUCCESS;
}
done:
- ad_free( ad, 1 );
return rc;
}
Backend *be,
DB_TXN *txn,
AttributeType *type,
- const char *lang,
- struct berval **vals,
+ struct berval *lang,
+ BerVarray vals,
ID id,
- int op,
- char ** dbnamep,
- slap_mask_t *maskp )
+ int op )
{
int rc;
- slap_mask_t mask;
- slap_mask_t tmpmask = 0;
- int lindex = 0;
+ slap_mask_t mask = 0;
if( type->sat_sup ) {
/* recurse */
rc = index_at_values( be, txn,
type->sat_sup, lang,
- vals, id, op,
- dbnamep, &tmpmask );
+ vals, id, op );
if( rc ) return rc;
}
- bdb_attr_mask( be->be_private, type->sat_cname, &mask );
-
- if( mask ) {
- *dbnamep = type->sat_cname;
- } else if ( tmpmask & SLAP_INDEX_AUTO_SUBTYPES ) {
- mask = tmpmask;
+ /* If this type has no AD, we've never used it before */
+ if( type->sat_ad ) {
+ bdb_attr_mask( be->be_private, type->sat_ad, &mask );
}
if( mask ) {
- rc = indexer( be, txn, *dbnamep,
- type->sat_cname,
+ rc = indexer( be, txn, type->sat_cname.bv_val,
+ &type->sat_cname,
vals, id, op,
mask );
if( rc ) return rc;
}
- if( lang ) {
- char *dbname = NULL;
- size_t tlen = strlen( type->sat_cname );
- size_t llen = strlen( lang );
- char *lname = ch_malloc( tlen + llen + sizeof(";") );
+ if( lang->bv_len ) {
+ AttributeDescription *desc;
- sprintf( lname, "%s;%s", type->sat_cname, lang );
+ mask = 0;
- bdb_attr_mask( be->be_private, lname, &tmpmask );
-
- if( tmpmask ) {
- dbname = lname;
- } else if ( mask & SLAP_INDEX_AUTO_LANG ) {
- dbname = *dbnamep;
- tmpmask = mask;
+ desc = ad_find_lang( type, lang );
+ if( desc ) {
+ 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,
- tmpmask );
+ mask );
if( rc ) {
- ch_free( lname );
return rc;
}
}
-
- ch_free( lname );
}
return LDAP_SUCCESS;
Backend *be,
DB_TXN *txn,
AttributeDescription *desc,
- struct berval **vals,
+ BerVarray vals,
ID id,
int op )
{
int rc;
- char *dbname = NULL;
- slap_mask_t mask;
-
- if( slap_ad_is_binary( desc ) ) {
- /* binary attributes have no index capabilities */
- return LDAP_SUCCESS;
- }
rc = index_at_values( be, txn,
- desc->ad_type, desc->ad_lang,
- vals, id, op,
- &dbname, &mask );
+ desc->ad_type, &desc->ad_lang,
+ vals, id, op );
return rc;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
- "index_entry: %s (%s)%ld\n",
+ "index_entry: %s (%s) %ld\n",
op == SLAP_INDEX_ADD_OP ? "add" : "del",
- e->e_dn, e->e_id ));
+ 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",
- e->e_id, e->e_dn );
+ (long) e->e_id, e->e_dn );
#endif
/* add each attribute to the indexes */
if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
- "index_entry: success\n" ));
+ "index_entry: success\n" ));
#else
Debug( LDAP_DEBUG_TRACE,
"<= index_entry_%s( %ld, \"%s\" ) success\n",
op == SLAP_INDEX_ADD_OP ? "add" : "del",
- e->e_id, e->e_dn );
+ (long) e->e_id, e->e_dn );
#endif
return rc;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
- "index_entry: success\n" ));
+ "index_entry: success\n" ));
#else
Debug( LDAP_DEBUG_TRACE, "<= index_entry_%s( %ld, \"%s\" ) success\n",
op == SLAP_INDEX_ADD_OP ? "add" : "del",
- e->e_id, e->e_dn );
+ (long) e->e_id, e->e_dn );
#endif
return LDAP_SUCCESS;