openldap/libraries/libldap/ftest.c
Pierangelo Masarati 4a8ab5dbf2 Mostly based on patches provided by Hallvard B. Furuseth
ITS#1677 - cast away const warnings
ITS#1678 - unsigned char args to ctype funcs
ITS#1682 - don't redefine ldap_debug
ITS#1683 - uninitialized vars
ITS#1703 - ldo_debug initialization
ITS#1705 - unsigned testing
ITS#1706 - socklen_t args
ITS#1719 - back-tcl update (other cleanups/fixes/improvements; yet untested)
ITS#1724 - integerNormalize/integerFilter/integerIndexer bugs
ITS#1725 - libdes not required

Implement back-null (/dev/null style backend)
Cleanup some misc warnings ("%lu" format, unused/uninitialized vars,
        ambiguous operator precedence)

Kurt, please regenerate configure
2002-04-08 09:43:22 +00:00

111 lines
2.0 KiB
C

/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* OpenLDAP Filter API Test */
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include <stdio.h>
#include <ldap.h>
#include "ldap_pvt.h"
#include "ldif.h"
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
static int filter2ber( char *filter );
int usage()
{
fprintf( stderr, "usage:\n"
" ftest [-d n] filter\n"
" filter - RFC 2254 string representation of an "
"LDAP search filter\n" );
return EXIT_FAILURE;
}
int
main( int argc, char *argv[] )
{
int c;
int debug=0;
while( (c = getopt( argc, argv, "d:" )) != EOF ) {
switch ( c ) {
case 'd':
debug = atoi( optarg );
break;
default:
fprintf( stderr, "ftest: unrecognized option -%c\n",
optopt );
return usage();
}
}
if ( debug ) {
if ( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
!= LBER_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n",
debug );
}
if ( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n",
debug );
}
}
if ( argc - optind != 1 ) {
return usage();
}
return filter2ber( strdup( argv[optind] ) );
}
static int filter2ber( char *filter )
{
int rc;
struct berval *bv = NULL;
BerElement *ber;
printf( "Filter: %s\n", filter );
ber = ber_alloc_t( LBER_USE_DER );
if( ber == NULL ) {
perror( "ber_alloc_t" );
return EXIT_FAILURE;
}
rc = ldap_pvt_put_filter( ber, filter );
if( rc < 0 ) {
fprintf( stderr, "Filter error!\n");
return EXIT_FAILURE;
}
rc = ber_flatten( ber, &bv );
if( rc < 0 ) {
perror( "ber_flatten" );
return EXIT_FAILURE;
}
printf( "BER encoding (len=%ld):\n", (long) bv->bv_len );
ber_bprint( bv->bv_val, bv->bv_len );
ber_free( ber, 0 );
ber_bvfree( bv );
return EXIT_SUCCESS;
}