#include "portable.h"
#include <stdio.h>
-#include <ac/string.h>
#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
+#include <limits.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/ctype.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+#include <ac/wait.h>
+
#include <sys/resource.h>
-#include <sys/wait.h>
#include <sys/param.h>
#include <sys/stat.h>
-#include <limits.h>
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
#include "ldapconfig.h"
#include "../slap.h"
#define EDITOR "/usr/ucb/vi"
-extern IDList *idl_fetch();
-extern Backend *select_backend();
-extern struct dbcache *ldbm_cache_open();
-
-static struct dbcache *openchoice();
-static void print_entry();
-static void free_and_close();
-static void edit_entry();
-static void get_keydata();
-
-struct dbcache *dbc;
-LDBM dbp;
-char *tailorfile;
-Backend *be = NULL;
-int ldap_debug;
-int ldap_syslog;
-int ldap_syslog_level;
-int global_schemacheck;
-int num_entries_sent;
-int num_bytes_sent;
-int active_threads;
-char *default_referral;
-struct objclass *global_oc;
-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;
-
-main( argc, argv )
- int argc;
- char **argv;
+static struct 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 edit_entry(char c, Datum *data);
+static void get_keydata(FILE *fp, char c, Datum *key, Datum *data);
+
+static struct dbcache *dbc;
+static LDBM dbp;
+static Backend *be = NULL;
+
+int
+main( int argc, char **argv )
{
char buf[256];
Datum savekey, key, data, last;
char *fname;
ID id;
- IDList *idl;
+ ID_BLOCK *idl;
Backend *tbe;
int i;
- extern char *optarg;
+ char *tailorfile;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
DBC *cursorp;
#endif
+ ldbm_datum_init( savekey );
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
+ ldbm_datum_init( last );
+
tailorfile = SLAPD_DEFAULT_CONFIGFILE;
while ( (i = getopt( argc, argv, "d:f:" )) != EOF ) {
switch ( i ) {
* 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: " );
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" );
}
}
savekey.dptr = NULL;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
for ( key = ldbm_firstkey( dbc->dbc_db, &cursorp );
key.dptr != NULL;
key = ldbm_nextkey( dbc->dbc_db, key, cursorp ) )
"key: ", NULL, NULL );
}
- ldbm_datum_free( dbc->dbc_db, data );
+ if ( data.dptr != NULL ) {
+ ldbm_datum_free( dbc->dbc_db, data );
+ }
}
if ( savekey.dptr != NULL )
ldbm_datum_free( dbc->dbc_db, savekey );
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 )
!= 0 ) {
fprintf( stderr,
- "idl_insert_key (%s) %d failed\n",
+ "idl_insert_key (%s) %ld failed\n",
key.dptr, id );
continue;
}
} 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 );
last.dptr = NULL;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
for ( key = ldbm_firstkey( dbp, &cursorp );
key.dptr != NULL;
key = ldbm_nextkey( dbp, last, cursorp ) )
}
}
+ slap_shutdown(-1);
+ slap_destroy();
+
return( 0 );
}
static void
-free_and_close( dbc, key, data )
- struct dbcache *dbc;
- Datum key;
- Datum data;
+free_and_close( struct dbcache *dbc, Datum key, Datum data )
{
ldbm_cache_really_close( be, dbc );
if ( key.dptr != NULL )
}
static int
-dnid_cmp( a, b )
- long *a;
- long *b;
+dnid_cmp( const void *a, const void *b )
{
- return( *a - *b );
+ return( *(const long int *)a - *(const long int *)b );
}
static char *
-myrealloc( p, size )
- char *p;
- int size;
+myrealloc( char *p, int size )
{
if ( p == NULL )
return( (char *) malloc( size ) );
}
static void
-get_idlist( fp, data )
- FILE *fp;
- Datum *data;
+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;
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 ) {
continue;
}
- p->b_ids[i++] = atol( buf );
+ ID_BLOCK_ID(p,i++) = atol( buf );
psize += sizeof(ID);
}
if ( nmax == 0 ) {
}
}
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), (void *) 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
-get_entry( fp, data )
- FILE *fp;
- Datum *data;
+get_entry( FILE *fp, Datum *data )
{
char buf[BUFSIZ];
char *p;
}
static void
-edit_entry( c, data )
- char c;
- Datum *data;
+edit_entry( char c, Datum *data )
{
int fd, pid;
char tmpname[20];
FILE *fp;
+#ifndef HAVE_WAITPID
WAITSTATUSTYPE status;
+#endif
strcpy( tmpname, "/tmp/dbtestXXXXXX" );
-#ifdef ultrix
+#ifndef HAVE_MKSTEMP
if ( (fd = open( mktemp( tmpname ), O_RDWR, 0600 )) == -1 ) {
perror( tmpname );
return;
fclose( fp );
-#ifdef USE_WAITPID
- if ( waitpid( (pid_t) -1, 0, WAIT_FLAGS ) < 0 ) {
+#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;
perror( tmpname );
return;
}
- ldbm_datum_free( NULL, *data );
+ if ( data->dptr != NULL ) {
+ ldbm_datum_free( NULL, *data );
+ }
get_keydata( fp, c, NULL, data );
fclose( fp );
unlink( tmpname );
}
static struct dbcache *
-openfile( name, namesiz, mode, verbose, c )
- char *name;
- int namesiz;
- int mode;
- int verbose;
- char c;
+openfile( char *name, int namesiz, int mode, int verbose, char c )
{
struct dbcache *dbc;
}
static struct dbcache *
-openchoice( c, mode, verbose, fname )
- char c;
- int mode;
- int verbose;
- char **fname;
+openchoice( char c, int mode, int verbose, char **fname )
{
static char name[MAXPATHLEN];
}
static void
-print_entry( fp, c, key, klabel, data, dlabel )
- FILE *fp;
- char c;
- Datum *key;
- char *klabel;
- Datum *data;
- char *dlabel;
+print_entry(
+ FILE *fp,
+ char c,
+ Datum *key,
+ char *klabel,
+ Datum *data,
+ char *dlabel
+)
{
ID id;
- IDList *idl;
+ ID_BLOCK *idl;
int i;
char msg[2];
key->dsize );
if ( data != NULL ) {
SAFEMEMCPY( (char *) &id, data->dptr, sizeof(ID) );
- fprintf( fp, "%s%d\n", dlabel ? dlabel : "", id );
+ fprintf( fp, "%s%ld\n", dlabel ? dlabel : "", id );
}
break;
case 'e': /* id2entry - key is dnid, data is entry */
if ( key != NULL ) {
SAFEMEMCPY( (char *) &id, key->dptr, sizeof(ID) );
- fprintf( fp, "%s %d\n", klabel, id );
+ fprintf( fp, "%s %ld\n", klabel, id );
}
if ( data != NULL ) {
if ( dlabel ) {
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=%d\n\tncur=%d\n", dlabel,
- idl->b_nmax, idl->b_nids );
+ fprintf( fp, "%s\tnmax=%ld\n\tncur=%ld\n", dlabel,
+ ID_BLOCK_NMAX(idl), ID_BLOCK_NIDS(idl) );
- if ( INDIRECT_BLOCK( idl ) ) {
- for ( i = 0; idl->b_ids[i] != NOID; i++ ) {
- fprintf( fp, "\t%d\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 ) ) {
- fprintf( fp, "\tALLIDS (1..%d)\n",
- idl->b_nids - 1 );
+ } else if ( ID_BLOCK_ALLIDS( idl ) ) {
+ fprintf( fp, "\tALLIDS (1..%ld)\n",
+ ID_BLOCK_NIDS(idl) - 1 );
} else {
- for ( i = 0; i < idl->b_nids; i++ ) {
- fprintf( fp, "\t%d\n", idl->b_ids[i] );
+ for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) {
+ fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl,i) );
}
}
}
}
static void
-get_keydata( fp, c, key, data )
- FILE *fp;
- char c;
- Datum *key;
- Datum *data;
+get_keydata( FILE *fp, char c, Datum *key, Datum *data )
{
static char kbuf[BUFSIZ], dbuf[BUFSIZ];
long n;