]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/ftest.c
Patch: More format bugs (ITS#1702)
[openldap] / libraries / libldap / ftest.c
index 22f7646e32d51fb37f0397253efc7a4f72d227ca..587c0638bfe6d6993105ab18dadad39aafc1722a 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* OpenLDAP Filter API Test */
@@ -15,7 +15,7 @@
 
 #include <ldap.h>
 
-#include "ldap-int.h"
+#include "ldap_pvt.h"
 
 #include "ldif.h"
 #include "lutil.h"
@@ -27,19 +27,21 @@ static int filter2ber( char *filter );
 int usage()
 {
        fprintf( stderr, "usage:\n"
-               "\tftest [-d n] filter" );
+               "  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 i;
+       int c;
        int debug=0;
        char *filter=NULL;
 
-    while( (i = getopt( argc, argv, "Aa:Ss:" "d:" )) != EOF ) {
-               switch ( i ) {
+    while( (c = getopt( argc, argv, "d:" )) != EOF ) {
+               switch ( c ) {
                case 'd':
                        debug = atoi( optarg );
                        break;
@@ -65,10 +67,7 @@ main( int argc, char *argv[] )
                }
        }
 
-       if( argc - optind > 1 ) {
-               return usage();
-
-       } else if ( argc - optind != 1 ) {
+       if ( argc - optind != 1 ) {
                return usage();
        }
 
@@ -89,9 +88,9 @@ static int filter2ber( char *filter )
                return EXIT_FAILURE;
        }
 
-       rc = ldap_int_put_filter( ber, filter );
-       if( rc ) {
-               perror( "ber_flatten" );
+       rc = ldap_pvt_put_filter( ber, filter );
+       if( rc < 0 ) {
+               fprintf( stderr, "Filter error!\n");
                return EXIT_FAILURE;
        }
 
@@ -101,6 +100,7 @@ static int filter2ber( char *filter )
                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 );