]> git.sur5r.net Git - openldap/commitdiff
Store IDs in BeigEndian format on disk
authorHoward Chu <hyc@openldap.org>
Sat, 6 Mar 2004 12:41:29 +0000 (12:41 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 6 Mar 2004 12:41:29 +0000 (12:41 +0000)
servers/slapd/back-bdb/dbcache.c
servers/slapd/back-bdb/id2entry.c
servers/slapd/back-bdb/init.c

index 23d964deaa3bd45446d27ffc150fdc4c4a1c3d86..3ce25895a74c4b94ad2e71cd22cccfb88a8d17fb 100644 (file)
@@ -118,7 +118,6 @@ bdb_db_cache(
        rc = db->bdi_db->set_h_hash( db->bdi_db, bdb_db_hash );
 #endif
        rc = db->bdi_db->set_flags( db->bdi_db, DB_DUP | DB_DUPSORT );
-       rc = db->bdi_db->set_dup_compare( db->bdi_db, bdb_bt_compare );
 
        file = ch_malloc( strlen( name ) + sizeof(BDB_SUFFIX) );
        sprintf( file, "%s" BDB_SUFFIX, name );
index fce1fcdc637266ec84f2a2a67ac290785be08328..13f958dd467e89d2d3074c9ac5c5772f847d1301 100644 (file)
@@ -32,7 +32,9 @@ static int bdb_id2entry_put(
        DB *db = bdb->bi_id2entry->bdi_db;
        DBT key, data;
        struct berval bv;
-       int rc;
+       char buf[sizeof(ID)];
+       ID tmp;
+       int i, rc;
 #ifdef BDB_HIER
        struct berval odn, ondn;
 
@@ -44,9 +46,16 @@ static int bdb_id2entry_put(
        e->e_nname = slap_empty_bv;
 #endif
        DBTzero( &key );
-       key.data = (char *) &e->e_id;
+       key.data = buf;
        key.size = sizeof(ID);
 
+       /* Set key in BigEndian order */
+       tmp = e->e_id;
+       for ( i=sizeof(ID)-1; i>=0; i-- ) {
+               buf[i] = tmp & 0xff;
+               tmp >>= 8;
+       }
+
        rc = entry_encode( e, &bv );
 #ifdef BDB_HIER
        e->e_name = odn; e->e_nname = ondn;
@@ -96,13 +105,20 @@ int bdb_id2entry(
        DB *db = bdb->bi_id2entry->bdi_db;
        DBT key, data;
        struct berval bv;
-       int rc = 0, ret = 0;
+       char buf[sizeof(ID)];
+       ID tmp;
+       int i, rc = 0, ret = 0;
 
        *e = NULL;
 
        DBTzero( &key );
-       key.data = (char *) &id;
+       key.data = buf;
        key.size = sizeof(ID);
+       tmp = id;
+       for ( i=sizeof(ID)-1; i>=0; i-- ) {
+               buf[i] = tmp & 0xff;
+               tmp >>= 8;
+       }
 
        DBTzero( &data );
        data.flags = DB_DBT_MALLOC;
@@ -138,11 +154,18 @@ int bdb_id2entry_delete(
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        DB *db = bdb->bi_id2entry->bdi_db;
        DBT key;
-       int rc;
+       char buf[sizeof(ID)];
+       ID tmp;
+       int i, rc;
 
        DBTzero( &key );
-       key.data = (char *) &e->e_id;
+       key.data = buf;
        key.size = sizeof(ID);
+       tmp = e->e_id;
+       for ( i=sizeof(ID)-1; i>=0; i-- ) {
+               buf[i] = tmp & 0xff;
+               tmp >>= 8;
+       }
 
        /* delete from database */
        rc = db->del( db, tid, &key, 0 );
index 7be4e2d954beba352ed08a94095aa72839b120e1..f037eaf6ee15e26af193aba65d43251f2a9495e4 100644 (file)
@@ -114,32 +114,6 @@ bdb_db_init( BackendDB *be )
        return 0;
 }
 
-int
-bdb_bt_compare(
-       DB *db, 
-       const DBT *usrkey,
-       const DBT *curkey
-)
-{
-       unsigned char *u, *c;
-       int i, x;
-
-       u = usrkey->data;
-       c = curkey->data;
-
-#ifdef WORDS_BIGENDIAN
-       for( i = 0; i < (int)sizeof(ID); i++)
-#else
-       for( i = sizeof(ID)-1; i >= 0; i--)
-#endif
-       {
-               x = u[i] - c[i];
-               if( x ) return x;
-       }
-
-       return 0;
-}
-
 static int
 bdb_db_open( BackendDB *be )
 {
@@ -372,8 +346,6 @@ bdb_db_open( BackendDB *be )
                }
 
                if( i == BDB_ID2ENTRY ) {
-                       rc = db->bdi_db->set_bt_compare( db->bdi_db,
-                               bdb_bt_compare );
                        rc = db->bdi_db->set_pagesize( db->bdi_db,
                                BDB_ID2ENTRY_PAGESIZE );
                        if ( slapMode & SLAP_TOOL_READMAIN ) {
@@ -385,8 +357,6 @@ bdb_db_open( BackendDB *be )
                        rc = db->bdi_db->set_flags( db->bdi_db, 
                                DB_DUP | DB_DUPSORT );
 #ifndef BDB_HIER
-                       rc = db->bdi_db->set_dup_compare( db->bdi_db,
-                               bdb_bt_compare );
                        if ( slapMode & SLAP_TOOL_READONLY ) {
                                flags |= DB_RDONLY;
                        } else {
@@ -395,8 +365,6 @@ bdb_db_open( BackendDB *be )
 #else
                        rc = db->bdi_db->set_dup_compare( db->bdi_db,
                                bdb_dup_compare );
-                       rc = db->bdi_db->set_bt_compare( db->bdi_db,
-                               bdb_bt_compare );
                        if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
                                flags |= DB_RDONLY;
                        } else {