Re-introduce hdb dup_compare function, default compares too much

This commit is contained in:
Howard Chu 2007-12-06 15:58:47 +00:00
parent f06fdb2821
commit e237f4cc43
3 changed files with 33 additions and 0 deletions

View File

@ -451,6 +451,31 @@ typedef struct diskNode {
unsigned char entryID[sizeof(ID)]; /* variable placement */
} diskNode;
/* Sort function for the sorted duplicate data items of a dn2id key.
* Sorts based on normalized RDN, in length order.
*/
int
hdb_dup_compare(
DB *db,
const DBT *usrkey,
const DBT *curkey
)
{
diskNode *un, *cn;
int rc, ul, cl;
un = (diskNode *)usrkey->data;
cn = (diskNode *)curkey->data;
/* data is not aligned, cannot compare directly */
ul = un->nrdnlen[0] << 8 | un->nrdnlen[1];
cl = cn->nrdnlen[0] << 8 | cn->nrdnlen[1];
rc = ul - cl;
if( rc ) return rc;
return strcmp( un->nrdn, cn->nrdn );
}
/* This function constructs a full DN for a given entry.
*/
int hdb_fix_dn(

View File

@ -412,6 +412,8 @@ shm_retry:
flags |= DB_CREATE;
}
#else
rc = db->bdi_db->set_dup_compare( db->bdi_db,
bdb_dup_compare );
if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
flags |= DB_RDONLY;
} else {

View File

@ -129,6 +129,7 @@ int bdb_dn2idl(
#ifdef BDB_HIER
#define bdb_dn2id_parent BDB_SYMBOL(dn2id_parent)
#define bdb_dup_compare BDB_SYMBOL(dup_compare)
#define bdb_fix_dn BDB_SYMBOL(fix_dn)
int bdb_dn2id_parent(
@ -137,6 +138,11 @@ int bdb_dn2id_parent(
EntryInfo *ei,
ID *idp );
int bdb_dup_compare(
DB *db,
const DBT *usrkey,
const DBT *curkey );
int bdb_fix_dn( Entry *e, int checkit );
#endif