1998-08-09 08:43:13 +08:00
|
|
|
/* dtest.c - lber decoding test program */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 07:17:08 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-11-26 07:17:08 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1998-12-29 04:38:04 +08:00
|
|
|
*/
|
2003-11-26 07:17:08 +08:00
|
|
|
/* Portions Copyright (c) 1990 Regents of the University of Michigan.
|
1998-08-09 08:43:13 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2003-11-27 06:51:15 +08:00
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was originally developed by the University of Michigan
|
|
|
|
* (as part of U-MICH LDAP).
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
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>
|
2003-05-19 18:37:09 +08:00
|
|
|
#include <ac/errno.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
|
|
|
|
2001-12-20 05:22:04 +08:00
|
|
|
static void usage( const 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;
|
|
|
|
|
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
|
|
|
|
2002-04-03 02:40:04 +08:00
|
|
|
ber = ber_alloc_t(LBER_USE_DER);
|
|
|
|
if( ber == NULL ) {
|
1998-12-22 09:34:01 +08:00
|
|
|
perror( "ber_alloc_t" );
|
1999-05-19 09:12:33 +08:00
|
|
|
return( EXIT_FAILURE );
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
2003-05-19 18:37:09 +08:00
|
|
|
for (;;) {
|
|
|
|
tag = ber_get_next( sb, &len, ber);
|
2003-05-22 11:35:36 +08:00
|
|
|
if( tag != LBER_ERROR ) break;
|
|
|
|
|
|
|
|
if( errno == EWOULDBLOCK ) continue;
|
|
|
|
if( errno == EAGAIN ) continue;
|
|
|
|
|
|
|
|
perror( "ber_get_next" );
|
|
|
|
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",
|
2003-05-22 11:35:36 +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);
|
2002-04-03 02:40:04 +08:00
|
|
|
tag = ber_scanf( ber, fmt, &buf[0], &len );
|
1999-05-20 03:10:55 +08:00
|
|
|
|
2002-04-03 02:40:04 +08:00
|
|
|
if( tag == LBER_ERROR ) {
|
1999-05-20 03:10:55 +08:00
|
|
|
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
|
|
|
}
|