2001-10-05 06:29:34 +08:00
|
|
|
/* index.c - routines for dealing with attribute indexes */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2001-10-05 06:29:34 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-bdb.h"
|
2001-10-06 04:12:16 +08:00
|
|
|
#include "idl.h"
|
2001-10-05 06:29:34 +08:00
|
|
|
|
|
|
|
/* read a key */
|
|
|
|
int
|
|
|
|
bdb_key_read(
|
2001-11-27 11:41:03 +08:00
|
|
|
Backend *be,
|
2001-10-05 06:29:34 +08:00
|
|
|
DB *db,
|
|
|
|
DB_TXN *txn,
|
2001-11-27 11:41:03 +08:00
|
|
|
struct berval *k,
|
2001-10-05 09:19:58 +08:00
|
|
|
ID *ids
|
2001-10-05 06:29:34 +08:00
|
|
|
)
|
|
|
|
{
|
2001-10-06 04:12:16 +08:00
|
|
|
int rc;
|
|
|
|
DBT key;
|
2001-10-05 06:29:34 +08:00
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ENTRY, "key_read: enter\n", 0, 0, 0 );
|
2001-10-05 06:29:34 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
|
2001-10-06 04:12:16 +08:00
|
|
|
DBTzero( &key );
|
2001-10-06 01:00:21 +08:00
|
|
|
bv2DBT(k,&key);
|
2002-04-25 13:16:15 +08:00
|
|
|
key.ulen = key.size;
|
|
|
|
key.flags = DB_DBT_USERMEM;
|
2001-10-05 06:29:34 +08:00
|
|
|
|
2001-10-06 04:12:16 +08:00
|
|
|
rc = bdb_idl_fetch_key( be, db, txn, &key, ids );
|
2001-10-05 06:29:34 +08:00
|
|
|
|
2001-10-05 09:19:58 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2001-10-05 06:29:34 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ERR, "bdb_key_read: failed (%d)\n", rc, 0, 0 );
|
2001-10-05 06:29:34 +08:00
|
|
|
#else
|
2001-10-05 09:19:58 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read: failed (%d)\n",
|
|
|
|
rc, 0, 0 );
|
2001-10-05 06:29:34 +08:00
|
|
|
#endif
|
2001-10-05 09:19:58 +08:00
|
|
|
} else {
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, DETAIL1,
|
|
|
|
"bdb_key_read: %ld candidates\n", (long)BDB_IDL_N(ids), 0, 0);
|
2001-10-05 09:19:58 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read %ld candidates\n",
|
2001-11-27 11:41:03 +08:00
|
|
|
(long) BDB_IDL_N(ids), 0, 0 );
|
2001-10-05 09:19:58 +08:00
|
|
|
#endif
|
|
|
|
}
|
2001-10-05 06:29:34 +08:00
|
|
|
|
2001-10-05 09:19:58 +08:00
|
|
|
return rc;
|
2001-10-05 06:29:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add or remove stuff from index files */
|
|
|
|
int
|
|
|
|
bdb_key_change(
|
2001-11-27 11:41:03 +08:00
|
|
|
Backend *be,
|
|
|
|
DB *db,
|
2001-10-05 06:29:34 +08:00
|
|
|
DB_TXN *txn,
|
2001-11-27 11:41:03 +08:00
|
|
|
struct berval *k,
|
|
|
|
ID id,
|
|
|
|
int op
|
2001-10-05 06:29:34 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
DBT key;
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ENTRY, "key_change: %s ID %lx\n",
|
|
|
|
op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long) id, 0 );
|
2001-10-05 06:29:34 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
|
|
|
|
op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DBTzero( &key );
|
2001-10-06 01:00:21 +08:00
|
|
|
bv2DBT(k,&key);
|
2002-04-25 13:16:15 +08:00
|
|
|
key.ulen = key.size;
|
|
|
|
key.flags = DB_DBT_USERMEM;
|
2001-10-05 06:29:34 +08:00
|
|
|
|
|
|
|
if (op == SLAP_INDEX_ADD_OP) {
|
2001-11-27 11:41:03 +08:00
|
|
|
/* Add values */
|
|
|
|
rc = bdb_idl_insert_key( be, db, txn, &key, id );
|
2002-08-30 18:41:46 +08:00
|
|
|
if ( rc == DB_KEYEXIST ) rc = 0;
|
2001-10-05 06:29:34 +08:00
|
|
|
} else {
|
2001-11-27 11:41:03 +08:00
|
|
|
/* Delete values */
|
|
|
|
rc = bdb_idl_delete_key( be, db, txn, &key, id );
|
2002-08-30 18:41:46 +08:00
|
|
|
if ( rc == DB_NOTFOUND ) rc = 0;
|
2001-10-05 06:29:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, RESULTS, "key_change: return %d\n", rc, 0, 0 );
|
2001-10-05 06:29:34 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|