From: Kurt Zeilenga Date: Fri, 28 Dec 2001 04:33:57 +0000 (+0000) Subject: Works... now to test our filter parser! X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~444 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c214a13a5995460e756c61127937adc7ee98bd1c;p=openldap Works... now to test our filter parser! --- diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index a73b656f2b..a8a3495413 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -7,7 +7,7 @@ LIBRARY = libldap.la XLIBRARY = ../libldap.a -PROGRAMS = apitest ltest dntest +PROGRAMS = apitest dntest ftest ltest SRCS = bind.c open.c result.c error.c compare.c search.c \ controls.c messages.c references.c extended.c cyrus.c \ @@ -39,10 +39,12 @@ NT_LINK_LIBS = -llber $(AC_LIBS) $(SECURITY_LIBS) apitest: $(LIBRARY) apitest.o $(LDAP_LIBLBER_DEPEND) $(LTLINK) -o $@ apitest.o $(LIBS) -ltest: $(LIBRARY) test.o $(LDAP_LIBLBER_DEPEND) - $(LTLINK) -o $@ test.o $(LIBS) dntest: $(LIBRARY) dntest.o $(LDAP_LIBLBER_DEPEND) $(LTLINK) -o $@ dntest.o $(LIBS) +ftest: $(LIBRARY) ftest.o $(LDAP_LIBLBER_DEPEND) + $(LTLINK) -o $@ ftest.o $(LIBS) +ltest: $(LIBRARY) test.o $(LDAP_LIBLBER_DEPEND) + $(LTLINK) -o $@ test.o $(LIBS) CFFILES=ldap.conf ldapfilter.conf diff --git a/libraries/libldap/ftest.c b/libraries/libldap/ftest.c index 69c2a4f6fc..22f7646e32 100644 --- a/libraries/libldap/ftest.c +++ b/libraries/libldap/ftest.c @@ -22,28 +22,24 @@ #include "lutil_ldap.h" #include "ldap_defaults.h" -static int filter2ber( const char *filter ); +static int filter2ber( char *filter ); int usage() { fprintf( stderr, "usage:\n" - " ftest [filter]" ); + "\tftest [-d n] filter" ); return EXIT_FAILURE; } int main( int argc, char *argv[] ) { - int i, debug=0, ber=0; + int i; + int debug=0; char *filter=NULL; - while( (i = getopt( argc, argv, "Aa:Ss:" - "bd:" )) != EOF ) - { + while( (i = getopt( argc, argv, "Aa:Ss:" "d:" )) != EOF ) { switch ( i ) { - case 'b': - ber++; - break; case 'd': debug = atoi( optarg ); break; @@ -71,42 +67,45 @@ main( int argc, char *argv[] ) if( argc - optind > 1 ) { return usage(); - } else if ( argc - optind == 1 ) { - if( ber ) { - fprintf( stderr, "ftest: parameter %s unexpected\n", - argv[optind] ); - return usage(); - } - return filter2ber( argv[optind] ); + + } else if ( argc - optind != 1 ) { + return usage(); } - return EXIT_FAILURE; + return filter2ber( strdup( argv[optind] ) ); } -static int filter2ber( const char *filter ) +static int filter2ber( char *filter ) { int rc; - BerElement *ber = ber_alloc_t( LBER_USE_DER ); 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_int_put_filter( ber, (char *) filter ); - - ber_dump( ber, 0 ); + rc = ldap_int_put_filter( ber, filter ); + if( rc ) { + perror( "ber_flatten" ); + return EXIT_FAILURE; + } rc = ber_flatten( ber, &bv ); - if( rc < 0 ) { perror( "ber_flatten" ); return EXIT_FAILURE; } - ber_free( ber, 1 ); + ber_bprint( bv->bv_val, bv->bv_len ); + + ber_free( ber, 0 ); ber_bvfree( bv ); return EXIT_SUCCESS; -} \ No newline at end of file +} +