/* 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
*/
/* has language tag */
attr_mask( be->be_private, desc->ad_type->sat_ad, &mask );
- if( mask & SLAP_INDEX_AUTO_LANG ) {
- *atname = desc->ad_cname;
- *dbname = desc->ad_type->sat_cname.bv_val;
- 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.bv_val;
return mask;
}
/* see if supertype defined mask for its subtypes */
- for( at = desc->ad_type; at != NULL ; at = at->sat_sup ) {
+ for( at = desc->ad_type->sat_sup; at != NULL ; at = at->sat_sup ) {
/* If no AD, we've never indexed this type */
if (!at->sat_ad)
continue;
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_SUBTYPES ) {
+ if( mask && ( mask ^ SLAP_INDEX_NOSUBTYPES ) ) {
*atname = at->sat_cname;
*dbname = at->sat_cname.bv_val;
return mask;
}
-
- if( mask ) break;
}
return 0;
}
+int 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 index_param(
Backend *be,
AttributeDescription *desc,
return LDAP_INAPPROPRIATE_MATCHING;
}
- switch(ftype) {
+ switch( ftype ) {
case LDAP_FILTER_PRESENT:
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
goto done;
Backend *be,
char *dbname,
struct berval *atname,
- struct berval **vals,
+ BerVarray vals,
ID id,
int op,
slap_mask_t mask )
const char *text;
DBCache *db;
AttributeDescription *ad = NULL;
- struct berval **keys;
+ struct berval *keys;
assert( mask );
if ( db == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "index", LDAP_LEVEL_ERR,
- "index_read: Could not open db %s%s\n",
- dbname, LDBM_SUFFIX ));
+ LDAP_LOG( INDEX, ERR,
+ "index_read: Could not open db %s%s\n", dbname, LDBM_SUFFIX, 0 );
#else
Debug( LDAP_DEBUG_ANY,
"<= index_read NULL (could not open %s%s)\n",
atname, vals, &keys );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i] != NULL; i++ ) {
- key_change( be, db, keys[i], id, op );
+ for( i=0; keys[i].bv_val != NULL; i++ ) {
+ key_change( be, db, &keys[i], id, op );
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
}
}
atname, vals, &keys );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i] != NULL; i++ ) {
- key_change( be, db, keys[i], id, op );
+ for( i=0; keys[i].bv_val != NULL; i++ ) {
+ key_change( be, db, &keys[i], id, op );
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
}
}
atname, vals, &keys );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i] != NULL; i++ ) {
- key_change( be, db, keys[i], id, op );
+ for( i=0; keys[i].bv_val != NULL; i++ ) {
+ key_change( be, db, &keys[i], id, op );
}
- ber_bvecfree( keys );
+ ber_bvarray_free( keys );
}
}
Backend *be,
AttributeType *type,
struct berval *lang,
- struct berval **vals,
+ BerVarray vals,
ID id,
- int op,
- char ** dbnamep,
- slap_mask_t *maskp )
+ int op )
{
slap_mask_t mask = 0;
- slap_mask_t tmpmask = 0;
if( type->sat_sup ) {
/* recurse */
(void) index_at_values( be,
type->sat_sup, lang,
- vals, id, op,
- dbnamep, &tmpmask );
+ vals, id, op );
}
/* If this type has no AD, we've never used it before */
- if (type->sat_ad)
+ if( type->sat_ad ) {
attr_mask( be->be_private, type->sat_ad, &mask );
-
- if( mask ) {
- *dbnamep = type->sat_cname.bv_val;
- } else if ( tmpmask & SLAP_INDEX_AUTO_SUBTYPES ) {
- mask = tmpmask;
}
if( mask ) {
- indexer( be, *dbnamep,
+ indexer( be, type->sat_cname.bv_val,
&type->sat_cname,
vals, id, op,
mask );
}
if( lang->bv_len ) {
- char *dbname = NULL;
- struct berval lname;
AttributeDescription *desc;
- tmpmask = 0;
- lname.bv_val = NULL;
+ mask = 0;
desc = ad_find_lang(type, lang);
- if (desc)
- attr_mask( be->be_private, desc, &tmpmask );
-
- if( tmpmask ) {
- dbname = desc->ad_cname.bv_val;
- lname = desc->ad_cname;
- mask = tmpmask;
- } else if ( mask & SLAP_INDEX_AUTO_LANG ) {
- dbname = *dbnamep;
- lname.bv_len = type->sat_cname.bv_len+lang->bv_len + 1;
- lname.bv_val = ch_malloc( lname.bv_len + 1 );
-
- strcpy(lname.bv_val, type->sat_cname.bv_val);
- lname.bv_val[type->sat_cname.bv_len] = ';';
- strcpy(lname.bv_val+type->sat_cname.bv_len+1,
- lang->bv_val);
+ if( desc ) {
+ attr_mask( be->be_private, desc, &mask );
}
- if( dbname != NULL ) {
- indexer( be, dbname, &lname,
+ if( mask ) {
+ indexer( be, desc->ad_cname.bv_val, &desc->ad_cname,
vals, id, op,
mask );
- if (!tmpmask)
- ch_free( lname.bv_val );
}
}
int index_values(
Backend *be,
AttributeDescription *desc,
- struct berval **vals,
+ BerVarray vals,
ID id,
int op )
{
- char *dbname = NULL;
- slap_mask_t mask;
-
(void) index_at_values( be,
desc->ad_type, &desc->ad_lang,
- vals, id, op,
- &dbname, &mask );
+ vals, id, op );
return LDAP_SUCCESS;
}
-
int
index_entry(
Backend *be,
int op,
- Entry *e,
- Attribute *ap
-)
+ Entry *e,
+ Attribute *ap )
{
#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, e->e_id ));
+ LDAP_LOG( INDEX, ENTRY,
+ "index_entry: %s (%s)%ld\n", op == SLAP_INDEX_ADD_OP ? "add" : "del",
+ e->e_dn, 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 );
#endif
-
/* add each attribute to the indexes */
for ( ; ap != NULL; ap = ap->a_next ) {
index_values( be, ap->a_desc, ap->a_vals, e->e_id, op );
}
#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",
e->e_id, e->e_dn );
#endif
-
return LDAP_SUCCESS;
}