#include "slap.h"
#include "back-bdb.h"
-#ifdef BDB_INDEX
-
static slap_mask_t index_mask(
Backend *be,
AttributeDescription *desc,
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->ad_cname.bv_val, &mask );
if( mask ) {
- *atname = desc->ad_cname->bv_val;
- *dbname = desc->ad_cname->bv_val;
+ *atname = desc->ad_cname.bv_val;
+ *dbname = desc->ad_cname.bv_val;
return mask;
}
bdb_attr_mask( be->be_private, desc->ad_type->sat_cname, &mask );
if( mask & SLAP_INDEX_AUTO_LANG ) {
- *atname = desc->ad_cname->bv_val;
+ *atname = desc->ad_cname.bv_val;
*dbname = desc->ad_type->sat_cname;
return mask;
}
Backend *be,
AttributeDescription *desc,
int ftype,
- char **dbnamep,
+ DB **dbp,
slap_mask_t *maskp,
struct berval **prefixp )
{
+ int rc;
slap_mask_t mask;
+ DB *db;
char *dbname;
char *atname;
return LDAP_INAPPROPRIATE_MATCHING;
}
+ 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 ) ) {
return LDAP_INAPPROPRIATE_MATCHING;
done:
- *dbnamep = dbname;
+ *dbp = db;
*prefixp = ber_bvstrdup( atname );
*maskp = mask;
return LDAP_SUCCESS;
assert( mask );
- rc = slap_str2ad( atname, &ad, &text );
-
- if( rc != LDAP_SUCCESS ) return rc;
-
- prefix.bv_val = atname;
- prefix.bv_len = strlen( atname );
-
rc = bdb_db_cache( be, dbname, &db );
if ( rc != LDAP_SUCCESS ) {
"<= bdb_index_read NULL (could not open %s)\n",
dbname, 0, 0 );
#endif
-
- ad_free( ad, 1 );
return LDAP_OTHER;
}
+ rc = slap_str2ad( 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 );
+ if( rc ) {
+ goto done;
+ }
}
if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) {
if( rc == LDAP_SUCCESS && keys != NULL ) {
for( i=0; keys[i] != NULL; i++ ) {
rc = bdb_key_change( be, db, txn, keys[i], id, op );
+ if( rc ) {
+ ber_bvecfree( keys );
+ goto done;
+ }
}
ber_bvecfree( keys );
}
+ rc = LDAP_SUCCESS;
}
if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
if( rc == LDAP_SUCCESS && keys != NULL ) {
for( i=0; keys[i] != NULL; i++ ) {
rc = bdb_key_change( be, db, txn, keys[i], id, op );
+ if( rc ) {
+ ber_bvecfree( keys );
+ goto done;
+ }
}
ber_bvecfree( keys );
}
+
+ rc = LDAP_SUCCESS;
}
if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) ) {
if( rc == LDAP_SUCCESS && keys != NULL ) {
for( i=0; keys[i] != NULL; i++ ) {
bdb_key_change( be, db, txn, keys[i], id, op );
+ if( rc ) {
+ ber_bvecfree( keys );
+ goto done;
+ }
}
ber_bvecfree( keys );
}
+
+ rc = LDAP_SUCCESS;
}
- ad_free( ad, 1 );
- return LDAP_SUCCESS;
+done:
+ return rc;
}
static int index_at_values(
Backend *be,
DB_TXN *txn,
AttributeType *type,
- const char *lang,
+ struct berval *lang,
struct berval **vals,
ID id,
int op,
type->sat_sup, lang,
vals, id, op,
dbnamep, &tmpmask );
+
+ if( rc ) return rc;
}
bdb_attr_mask( be->be_private, type->sat_cname, &mask );
type->sat_cname,
vals, id, op,
mask );
+
+ if( rc ) return rc;
}
- if( lang ) {
+ if( lang->bv_len ) {
char *dbname = NULL;
size_t tlen = strlen( type->sat_cname );
- size_t llen = strlen( lang );
+ size_t llen = lang->bv_len;
char *lname = ch_malloc( tlen + llen + sizeof(";") );
- sprintf( lname, "%s;%s", type->sat_cname, lang );
+ sprintf( lname, "%s;%s", type->sat_cname, lang->bv_val );
bdb_attr_mask( be->be_private, lname, &tmpmask );
rc = indexer( be, txn, dbname, lname,
vals, id, op,
tmpmask );
+
+ if( rc ) {
+ ch_free( lname );
+ return rc;
+ }
}
ch_free( lname );
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,
+ desc->ad_type, &desc->ad_lang,
vals, id, op,
&dbname, &mask );
#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 */
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;
}
-
-#endif