]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/ldbmtest.c
Use a cursor to step through ID_BLOCKS.
[openldap] / servers / slapd / tools / ldbmtest.c
index 0e7cf5e64c539f03227fb8c3bbe47c4b8f9114cf..fb058df05bdcf2be67e8707604b0e74cbbab4d9b 100644 (file)
@@ -1,3 +1,7 @@
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 #include "portable.h"
 
 #include <stdio.h>
 #include <io.h>
 #endif
 
-#include "ldapconfig.h"
+#include "ldap_defaults.h"
 #include "../slap.h"
 #include "../back-ldbm/back-ldbm.h"
 
-static struct dbcache  *openchoice(char c, int mode, int verbose, char **fname);
+static DBCache *openchoice(char c, int mode, int verbose, char **fname);
 static void            print_entry(FILE *fp, char c, Datum *key, char *klabel, Datum *data, char *dlabel);
-static void            free_and_close(struct dbcache *dbc, Datum key, Datum data);
+static void            free_and_close(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);
 
-static struct dbcache *dbc;
+static DBCache *dbc;
 static LDBM           dbp;
 static Backend         *be = NULL;
 
@@ -47,7 +51,7 @@ main( int argc, char **argv )
        char            buf[256];
        Datum           savekey, key, data, last;
        char            *fname;
-       ID              id;
+       ID              id, cursor;
        ID_BLOCK                *idl;
        Backend         *tbe;
        int             i;
@@ -77,8 +81,7 @@ main( int argc, char **argv )
                        fprintf( stderr,
                            "usage: %s [-d level] [-f slapdconfigfile]\n",
                            argv[0] );
-                       exit( -1 );
-                       break;
+                       exit( EXIT_FAILURE );
                }
        }
 
@@ -205,6 +208,7 @@ main( int argc, char **argv )
                        free_and_close( dbc, key, data );
                        break;
 
+#ifndef HAVE_WINSOCK
                case 'e':       /* edit an entry */
                        if ( (dbc = openchoice( buf[1], LDBM_WRITER, 1, NULL ))
                            == NULL ) {
@@ -243,6 +247,7 @@ main( int argc, char **argv )
 
                        free_and_close( dbc, key, data );
                        break;
+#endif
 
                case 'a':       /* add an entry */
                        if ( (dbc = openchoice( buf[1], LDBM_WRITER, 1, NULL ))
@@ -274,8 +279,8 @@ main( int argc, char **argv )
                        get_keydata( stdin, buf[1], &key, &data );
 
                        idl = (ID_BLOCK *) data.dptr;
-                       for ( id = idl_firstid( idl ); id != NOID;
-                           id = idl_nextid( idl, id ) ) {
+                       for ( id = idl_firstid( idl, &cursor ); id != NOID;
+                           id = idl_nextid( idl, &cursor ) ) {
                                if ( idl_insert_key( be, dbc, key, id )
                                    != 0 ) {
                                        fprintf( stderr,
@@ -292,7 +297,7 @@ main( int argc, char **argv )
                        printf( "suffix: " );
                        fflush( stdout );
                        if ( fgets( buf, sizeof(buf), stdin ) == NULL ) {
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        } else {
                                buf[strlen( buf ) - 1] = '\0';
                        }
@@ -367,11 +372,11 @@ main( int argc, char **argv )
        slap_shutdown(-1);
        slap_destroy();
 
-       return( 0 );
+       return( EXIT_SUCCESS );
 }
 
 static void
-free_and_close( struct dbcache *dbc, Datum key, Datum data )
+free_and_close( DBCache *dbc, Datum key, Datum data )
 {
        ldbm_cache_really_close( be, dbc );
        if ( key.dptr != NULL )
@@ -499,6 +504,7 @@ get_entry( FILE *fp, Datum *data )
        data->dsize = psize + 1;
 }
 
+#ifndef HAVE_WINSOCK
 static void
 edit_entry( char c, Datum *data )
 {
@@ -535,11 +541,11 @@ edit_entry( char c, Datum *data )
                char    *editor;
 
                if ( (editor = getenv( "EDITOR" )) == NULL ) {
-                       editor = DEFAULT_EDITOR;
+                       editor = LDAP_EDITOR;
                }
                execl( editor, editor, tmpname, NULL );
                perror( "execl" );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        }
 
        fclose( fp );
@@ -565,22 +571,23 @@ edit_entry( char c, Datum *data )
        fclose( fp );
        unlink( tmpname );
 }
+#endif
 
-static struct dbcache *
+static DBCache *
 openfile( char *name, int namesiz, int mode, int verbose, char c )
 {
-       struct dbcache  *dbc;
+       DBCache *dbc;
 
        if ( name == NULL || *name == '\0' ) {
                if ( c == 'f' ) {
                        printf( "  file: " );
                        if ( fgets( name, namesiz, stdin ) == NULL )
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        name[strlen( name ) - 1] = '\0';
                } else {
                        printf( "  attr: " );
                        if ( fgets( name, namesiz, stdin ) == NULL )
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        name[strlen( name ) - 1] = '\0';
                }
        }
@@ -595,7 +602,7 @@ openfile( char *name, int namesiz, int mode, int verbose, char c )
        return( dbc );
 }
 
-static struct dbcache *
+static DBCache *
 openchoice( char c, int mode, int verbose, char **fname )
 {
        static char     name[MAXPATHLEN];
@@ -740,7 +747,7 @@ get_keydata( FILE *fp, char c, Datum *key, Datum *data )
                        if ( tty )
                                printf( "  dn: " );
                        if ( fgets( kbuf, sizeof(kbuf), fp ) == NULL ) {
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        }
                        kbuf[strlen( kbuf ) - 1] = '\0';
                        key->dptr = strdup( kbuf );
@@ -751,7 +758,7 @@ get_keydata( FILE *fp, char c, Datum *key, Datum *data )
                        if ( tty )
                                printf( "  dnid: " );
                        if ( fgets( dbuf, sizeof(dbuf), fp ) == NULL ) {
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        }
                        n = atol( dbuf );
                        data->dptr = (char *) malloc( sizeof(n) );
@@ -765,7 +772,7 @@ get_keydata( FILE *fp, char c, Datum *key, Datum *data )
                        if ( tty )
                                printf( "  dnid: " );
                        if ( fgets( kbuf, sizeof(kbuf), fp ) == NULL ) {
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        }
                        n = atol( kbuf );
                        key->dptr = (char *) malloc( sizeof(n) );
@@ -784,7 +791,7 @@ get_keydata( FILE *fp, char c, Datum *key, Datum *data )
                        if ( tty )
                                printf( "  key: " );
                        if ( fgets( kbuf, sizeof(kbuf), fp ) == NULL ) {
-                               exit( 0 );
+                               exit( EXIT_SUCCESS );
                        }
                        kbuf[strlen( kbuf ) - 1] = '\0';
                        key->dptr = strdup( kbuf );