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 */
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 */
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 */
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;
}
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 );
}
}
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" );
}
}
+ 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 );
}
#include "portable.h"
#include <stdio.h>
+#include <stdlib.h>
#include <ac/socket.h>
#include <ac/string.h>
if ( argc < 2 ) {
usage( argv[0] );
- exit( 1 );
+ return( EXIT_FAILURE );
}
#ifdef HAVE_CONSOLE_H
if (( fd = open( "lber-test", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY ))
< 0 ) {
perror( "open" );
- exit( 1 );
+ return( EXIT_FAILURE );
}
#else
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++ ) {
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 */
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 );
}