]> git.sur5r.net Git - openldap/commitdiff
Works... now to test our filter parser!
authorKurt Zeilenga <kurt@openldap.org>
Fri, 28 Dec 2001 04:33:57 +0000 (04:33 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 28 Dec 2001 04:33:57 +0000 (04:33 +0000)
libraries/libldap/Makefile.in
libraries/libldap/ftest.c

index a73b656f2b41d3e1ac06f0ec1e8f64b390d29cff..a8a34954137b9ae142ea434b9ad80fd385ef99ec 100644 (file)
@@ -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
 
index 69c2a4f6fce982ae71311e7db2a1cf60379b5f43..22f7646e32d51fb37f0397253efc7a4f72d227ca 100644 (file)
 #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
+}
+