From: Kurt Zeilenga Date: Wed, 19 May 1999 20:38:02 +0000 (+0000) Subject: Improving e/d test (until I find the my damn bug) X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~40 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e27ba3f0eedbb2fb1b42cfe8cc935319f655895b;p=openldap Improving e/d test (until I find the my damn bug) --- diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index aed5ca4e5f..3fe5030ada 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -484,7 +484,7 @@ va_dcl case 'l': /* length of next item */ l = va_arg( ap, long * ); - rc = ber_peek_tag( ber, (unsigned long *)l ); + rc = ber_peek_tag( ber, l ); break; case 'n': /* null */ @@ -494,7 +494,7 @@ va_dcl case 's': /* octet string - in a buffer */ s = va_arg( ap, char * ); l = va_arg( ap, long * ); - rc = ber_get_stringb( ber, s, (unsigned long *)l ); + rc = ber_get_stringb( ber, s, l ); break; case 'o': /* octet string in a supplied berval */ @@ -511,17 +511,17 @@ va_dcl case 'B': /* bit string - allocate storage as needed */ ss = va_arg( ap, char ** ); l = va_arg( ap, long * ); /* for length, in bits */ - rc = ber_get_bitstringa( ber, ss, (unsigned long *)l ); + rc = ber_get_bitstringa( ber, ss, l ); break; case 't': /* tag of next item */ - i = va_arg( ap, int * ); - *i = rc = ber_peek_tag( ber, &len ); + l = va_arg( ap, long * ); + *l = rc = ber_peek_tag( ber, &len ); break; case 'T': /* skip tag of next item */ - i = va_arg( ap, int * ); - *i = rc = ber_skip_tag( ber, &len ); + l = va_arg( ap, long * ); + *l = rc = ber_skip_tag( ber, &len ); break; case 'v': /* sequence of strings */ @@ -652,17 +652,19 @@ va_dcl break; case 'b': /* boolean */ - case 't': /* tag of next item */ - case 'T': /* skip tag of next item */ (void) va_arg( ap, int * ); break; case 's': /* octet string - in a buffer */ (void) va_arg( ap, char * ); - /* Fall through */ + (void) va_arg( ap, long * ); + break; + case 'e': /* enumerated */ case 'i': /* int */ case 'l': /* length of next item */ + case 't': /* tag of next item */ + case 'T': /* skip tag of next item */ (void) va_arg( ap, long * ); break; @@ -712,15 +714,17 @@ va_dcl } break; -#if 0 /* No action for these format characters */ case 'n': /* null */ case 'x': /* skip the next element - whatever it is */ case '{': /* begin sequence */ case '[': /* begin set */ case '}': /* end sequence */ case ']': /* end set */ -#endif + break; + default: + /* format should be good */ + assert( 0 ); } } diff --git a/libraries/liblber/dtest.c b/libraries/liblber/dtest.c index 9fadb37edf..240909a0c3 100644 --- a/libraries/liblber/dtest.c +++ b/libraries/liblber/dtest.c @@ -81,7 +81,7 @@ main( int argc, char **argv ) fmt[1] = '\0'; printf("decode: format %s\n", fmt ); - rc = ber_scanf( ber, fmt, buf ); + rc = ber_scanf( ber, fmt, &buf[0], &len ); if( rc == LBER_ERROR ) { perror( "ber_scanf" ); @@ -89,6 +89,14 @@ main( int argc, char **argv ) } } + if(( tag = ber_get_next( sb, &len, ber) ) == LBER_ERROR ) { + perror( "ber_get_next" ); + return( EXIT_FAILURE ); + } + + printf("decode: message tag 0x%lx and length %ld\n", + tag, len ); + ber_sockbuf_free( sb ); return( EXIT_SUCCESS ); } diff --git a/libraries/liblber/etest.c b/libraries/liblber/etest.c index 7037b61090..0099e82ff5 100644 --- a/libraries/liblber/etest.c +++ b/libraries/liblber/etest.c @@ -11,6 +11,7 @@ #include "portable.h" #include +#include #include #include @@ -54,7 +55,7 @@ main( int argc, char **argv ) if ( argc < 2 ) { usage( argv[0] ); - exit( 1 ); + return( EXIT_FAILURE ); } #ifdef HAVE_CONSOLE_H @@ -64,7 +65,7 @@ main( int argc, char **argv ) if (( fd = open( "lber-test", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY )) < 0 ) { perror( "open" ); - exit( 1 ); + return( EXIT_FAILURE ); } #else @@ -75,12 +76,18 @@ main( int argc, char **argv ) if( sb == NULL ) { perror( "lber_sockbuf_alloc_fd" ); - exit( 1 ); + return( EXIT_FAILURE ); } if ( (ber = ber_alloc_t( LBER_USE_DER )) == NULL ) { perror( "ber_alloc" ); - exit( 1 ); + return( EXIT_FAILURE ); + } + + fprintf(stderr, "encode: start\n" ); + if( ber_printf( ber, "{" /*}*/ ) ) { + perror( "ber_printf {" /*}*/ ); + return( EXIT_FAILURE ); } for ( s = argv[1]; *s; s++ ) { @@ -90,7 +97,7 @@ main( int argc, char **argv ) fmt[0] = *s; fmt[1] = '\0'; - printf("encode: %s\n", fmt ); + fprintf(stderr, "encode: %s\n", fmt ); switch ( *s ) { case 'i': /* int */ case 'b': /* boolean */ @@ -129,15 +136,21 @@ main( int argc, char **argv ) if( rc == -1 ) { perror( "ber_printf" ); - exit( 1 ); + return( EXIT_FAILURE ); } } + fprintf(stderr, "encode: end\n" ); + if( ber_printf( ber, /*{*/ "}" ) == -1 ) { + perror( /*{*/ "ber_printf }" ); + return( EXIT_FAILURE ); + } + if ( ber_flush( sb, ber, 1 ) == -1 ) { perror( "ber_flush" ); - exit( 1 ); + return( EXIT_FAILURE ); } ber_sockbuf_free( sb ); - return( 0 ); + return( EXIT_SUCCESS ); }