]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/ldbmtest.c
Updated some items
[openldap] / servers / slapd / tools / ldbmtest.c
index 0868b97d0c7b9f5ede3db0ae0524bc56be28e3ef..f2e33a7610bdf1722c7c52ca931c04aa2e2f7990 100644 (file)
@@ -31,30 +31,9 @@ static void          free_and_close(struct dbcache *dbc, Datum key, Datum data);
 static void            edit_entry(char c, Datum *data);
 static void            get_keydata(FILE *fp, char c, Datum *key, Datum *data);
 
-struct dbcache *dbc;
-LDBM           dbp;
-char           *tailorfile;
-Backend                *be = NULL;
-int            ldap_debug;
-int            ldap_syslog;
-int            ldap_syslog_level;
-long           num_entries_sent;
-long           num_bytes_sent;
-int            active_threads;
-char           *default_referral;
-time_t         currenttime;
-pthread_t      listener_tid;
-pthread_mutex_t        num_sent_mutex;
-pthread_mutex_t        entry2str_mutex;
-pthread_mutex_t        active_threads_mutex;
-pthread_mutex_t        new_conn_mutex;
-pthread_mutex_t        currenttime_mutex;
-pthread_mutex_t        replog_mutex;
-pthread_mutex_t        ops_mutex;
-pthread_mutex_t        regex_mutex;
-#ifdef SLAPD_CRYPT
-pthread_mutex_t        crypt_mutex;
-#endif
+static struct dbcache *dbc;
+static LDBM           dbp;
+static Backend         *be = NULL;
 
 int
 main( int argc, char **argv )
@@ -63,18 +42,19 @@ main( int argc, char **argv )
        Datum           savekey, key, data, last;
        char            *fname;
        ID              id;
-       IDList          *idl;
+       ID_BLOCK                *idl;
        Backend         *tbe;
        int             i;
+       char            *tailorfile;
 
 #ifdef HAVE_BERKELEY_DB2
        DBC     *cursorp;
+#endif
 
        ldbm_datum_init( savekey );
        ldbm_datum_init( key );
        ldbm_datum_init( data );
        ldbm_datum_init( last );
-#endif
 
        tailorfile = SLAPD_DEFAULT_CONFIGFILE;
        while ( (i = getopt( argc, argv, "d:f:" )) != EOF ) {
@@ -100,8 +80,9 @@ main( int argc, char **argv )
         * initialize stuff and figure out which backend we're dealing with
         */
 
-       init();
-       read_config( tailorfile, &be, NULL );
+       slap_init(SLAP_TOOL_MODE, "ldbmtest");
+       read_config( tailorfile );
+       slap_startup(-1);
 
        while ( 1 ) {
                printf( "dbtest: " );
@@ -147,7 +128,7 @@ main( int argc, char **argv )
                        get_keydata( stdin, buf[1], &key, NULL );
                        if ( (idl = idl_fetch( be, dbc, key )) != NULL ) {
                                data.dptr = (char *) idl;
-                               data.dsize = (idl->b_nmax + 1) * sizeof(ID);
+                               data.dsize = (ID_BLOCK_NMAX(idl) + 1) * sizeof(ID);
                                print_entry( stdout, buf[1], &key, "key: ",
                                    &data, "data:\n" );
                        }
@@ -286,7 +267,7 @@ main( int argc, char **argv )
 
                        get_keydata( stdin, buf[1], &key, &data );
 
-                       idl = (IDList *) data.dptr;
+                       idl = (ID_BLOCK *) data.dptr;
                        for ( id = idl_firstid( idl ); id != NOID;
                            id = idl_nextid( idl, id ) ) {
                                if ( idl_insert_key( be, dbc, key, id )
@@ -309,7 +290,7 @@ main( int argc, char **argv )
                        } else {
                                buf[strlen( buf ) - 1] = '\0';
                        }
-                       (void) dn_normalize( buf );
+                       (void) dn_normalize_case( buf );
                        if ( (tbe = select_backend( buf )) == NULL ) {
                                fprintf( stderr, "unknown suffix \"%s\"\n",
                                    buf );
@@ -377,6 +358,9 @@ main( int argc, char **argv )
                }
        }
 
+       slap_shutdown(-1);
+       slap_destroy();
+
        return( 0 );
 }
 
@@ -410,7 +394,7 @@ get_idlist( FILE *fp, Datum *data )
 {
        char    buf[20];
        int     i, j, fd, tty;
-       IDList  *p;
+       ID_BLOCK        *p;
        int     psize, pmax;
        int     nmax, nids;
 
@@ -435,7 +419,7 @@ get_idlist( FILE *fp, Datum *data )
 
                if ( psize + sizeof(ID) > pmax ) {
                        pmax += BUFSIZ;
-                       p = (IDList *) myrealloc( (char *) p, pmax );
+                       p = (ID_BLOCK *) myrealloc( (char *) p, pmax );
                }
 
                if ( strncmp( buf, "nids=0", 6 ) == 0 ) {
@@ -443,7 +427,7 @@ get_idlist( FILE *fp, Datum *data )
                        continue;
                }
 
-               p->b_ids[i++] = atol( buf );
+               ID_BLOCK_ID(p,i++) = atol( buf );
                psize += sizeof(ID);
        }
        if ( nmax == 0 ) {
@@ -460,19 +444,19 @@ get_idlist( FILE *fp, Datum *data )
                }
        }
        if ( i > 0 ) {
-               p->b_nmax = nmax;
+               ID_BLOCK_NMAX(p) = nmax;
                if ( nids != 0 ) {
-                       p->b_nids = 0;
-                       p->b_ids[i] = NOID;
+                       ID_BLOCK_NIDS(p) = 0;
+                       ID_BLOCK_ID(p,i) = NOID;
                } else {
-                       p->b_nids = i;
+                       ID_BLOCK_NIDS(p) = i;
                }
 
-               qsort( (void *) p->b_ids, i, sizeof(ID), dnid_cmp );
+               qsort( (void *) &ID_BLOCK_ID(p, 0), i, sizeof(ID), dnid_cmp );
        }
 
        data->dptr = (char *) p;
-       data->dsize = (nmax + 2) * sizeof(ID);
+       data->dsize = (nmax + ID_BLOCK_IDS_OFFSET) * sizeof(ID);
 }
 
 static void
@@ -557,7 +541,7 @@ edit_entry( char c, Datum *data )
 #ifdef HAVE_WAITPID
        if ( waitpid( (pid_t) -1, NULL, WAIT_FLAGS ) < 0 ) {
 #else
-       if ( wait3( &status, WAIT_FLAGS, 0 ) < 0 ) {
+       if ( wait4( (pid_t) -1, &status, WAIT_FLAGS, 0 ) < 0 ) {
 #endif
                perror( "wait" );
                return;
@@ -650,7 +634,7 @@ print_entry(
 )
 {
        ID      id;
-       IDList  *idl;
+       ID_BLOCK        *idl;
        int     i;
        char    msg[2];
 
@@ -680,7 +664,7 @@ print_entry(
        case 'e':       /* id2entry - key is dnid, data is entry */
                if ( key != NULL ) {
                        SAFEMEMCPY( (char *) &id, key->dptr, sizeof(ID) );
-                       fprintf( fp, "%s %lu\n", klabel, id );
+                       fprintf( fp, "%s %ld\n", klabel, id );
                }
                if ( data != NULL ) {
                        if ( dlabel ) {
@@ -697,22 +681,22 @@ print_entry(
                        fprintf( fp, "%s%s (len %d)\n", klabel, key->dptr,
                            key->dsize );
                if ( data != NULL ) {
-                       idl = (IDList *) data->dptr;
+                       idl = (ID_BLOCK *) data->dptr;
 
                        if ( dlabel )
                                fprintf( fp, "%s\tnmax=%ld\n\tncur=%ld\n", dlabel,
-                                   idl->b_nmax, idl->b_nids );
+                                   ID_BLOCK_NMAX(idl), ID_BLOCK_NIDS(idl) );
 
-                       if ( INDIRECT_BLOCK( idl ) ) {
-                               for ( i = 0; idl->b_ids[i] != NOID; i++ ) {
-                                       fprintf( fp, "\t%ld\n", idl->b_ids[i] );
+                       if ( ID_BLOCK_INDIRECT( idl ) ) {
+                               for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
+                                       fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl, i) );
                                }
-                       } else if ( ALLIDS( idl ) ) {
+                       } else if ( ID_BLOCK_ALLIDS( idl ) ) {
                                fprintf( fp, "\tALLIDS (1..%ld)\n",
-                                   idl->b_nids - 1 );
+                                   ID_BLOCK_NIDS(idl) - 1 );
                        } else {
-                               for ( i = 0; i < idl->b_nids; i++ ) {
-                                       fprintf( fp, "\t%ld\n", idl->b_ids[i] );
+                               for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) {
+                                       fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl,i) );
                                }
                        }
                }