1998-08-09 08:43:13 +08:00
|
|
|
/* dtest.c - lber decoding test program */
|
1998-12-29 04:38:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-12-29 04:46:13 +08:00
|
|
|
/* Portions
|
1998-08-09 08:43:13 +08:00
|
|
|
* Copyright (c) 1990 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
1998-11-16 13:07:27 +08:00
|
|
|
#include <ac/unistd.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CONSOLE_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <console.h>
|
|
|
|
#endif /* MACOS */
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-03-03 23:46:50 +08:00
|
|
|
#include "lber-int.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
static void usage( char *name )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "usage: %s fmt\n", name );
|
|
|
|
}
|
|
|
|
|
1998-11-08 10:31:31 +08:00
|
|
|
int
|
1998-08-09 08:43:13 +08:00
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
1999-05-20 03:10:55 +08:00
|
|
|
char *s;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
unsigned long tag, len;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
BerElement *ber;
|
|
|
|
Sockbuf *sb;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-20 03:10:55 +08:00
|
|
|
/* enable debugging */
|
|
|
|
ber_int_debug = -1;
|
|
|
|
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
return( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_CONSOLE_H
|
1998-08-09 08:43:13 +08:00
|
|
|
ccommand( &argv );
|
|
|
|
cshow( stdout );
|
|
|
|
#endif /* MACOS */
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
sb = ber_sockbuf_alloc_fd( fileno(stdin) );
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
if( (ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
|
|
|
|
perror( "ber_alloc_t" );
|
1999-05-19 09:12:33 +08:00
|
|
|
return( EXIT_FAILURE );
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
1999-05-20 03:10:55 +08:00
|
|
|
if(( tag = ber_get_next( sb, &len, ber) ) == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
perror( "ber_get_next" );
|
1999-05-19 09:12:33 +08:00
|
|
|
return( EXIT_FAILURE );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-05-20 03:10:55 +08:00
|
|
|
printf("decode: message tag 0x%lx and length %ld\n",
|
|
|
|
tag, len );
|
|
|
|
|
|
|
|
for( s = argv[1]; *s; s++ ) {
|
|
|
|
char buf[128];
|
|
|
|
char fmt[2];
|
|
|
|
fmt[0] = *s;
|
|
|
|
fmt[1] = '\0';
|
|
|
|
|
|
|
|
printf("decode: format %s\n", fmt );
|
|
|
|
rc = ber_scanf( ber, fmt, buf );
|
|
|
|
|
|
|
|
if( rc == LBER_ERROR ) {
|
|
|
|
perror( "ber_scanf" );
|
|
|
|
return( EXIT_FAILURE );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_sockbuf_free( sb );
|
|
|
|
return( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|