1998-08-09 08:43:13 +08:00
|
|
|
/* dtest.c - lber decoding test program */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-12-29 04:38:04 +08:00
|
|
|
/*
|
2000-05-13 10:36:07 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1998-12-29 04:38:04 +08:00
|
|
|
* 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>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/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>
|
1999-06-01 10:03:21 +08:00
|
|
|
#endif
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-05-31 13:27:32 +08:00
|
|
|
#include <lber.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;
|
|
|
|
|
1999-08-02 09:50:08 +08:00
|
|
|
ber_tag_t tag;
|
|
|
|
ber_len_t len;
|
1999-05-20 03:10:55 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
BerElement *ber;
|
|
|
|
Sockbuf *sb;
|
2000-06-02 04:59:21 +08:00
|
|
|
int fd;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-20 03:10:55 +08:00
|
|
|
/* enable debugging */
|
1999-05-31 13:27:32 +08:00
|
|
|
int ival = -1;
|
|
|
|
ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival );
|
1999-05-20 03:10:55 +08:00
|
|
|
|
|
|
|
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 );
|
1999-06-01 10:03:21 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-06-02 04:59:21 +08:00
|
|
|
sb = ber_sockbuf_alloc();
|
|
|
|
fd = fileno( stdin );
|
|
|
|
ber_sockbuf_add_io( sb, &ber_sockbuf_io_fd, LBER_SBIOD_LEVEL_PROVIDER,
|
|
|
|
(void *)&fd );
|
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",
|
1999-08-02 09:50:08 +08:00
|
|
|
(unsigned long) tag, (long) len );
|
1999-05-20 03:10:55 +08:00
|
|
|
|
|
|
|
for( s = argv[1]; *s; s++ ) {
|
|
|
|
char buf[128];
|
|
|
|
char fmt[2];
|
|
|
|
fmt[0] = *s;
|
|
|
|
fmt[1] = '\0';
|
|
|
|
|
|
|
|
printf("decode: format %s\n", fmt );
|
1999-05-20 08:04:16 +08:00
|
|
|
len = sizeof(buf);
|
1999-05-20 04:38:02 +08:00
|
|
|
rc = ber_scanf( ber, fmt, &buf[0], &len );
|
1999-05-20 03:10:55 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|