3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* OpenLDAP Filter API Test */
10 #include <ac/stdlib.h>
11 #include <ac/string.h>
12 #include <ac/unistd.h>
22 #include "lutil_ldap.h"
23 #include "ldap_defaults.h"
25 static int filter2ber( char *filter );
29 fprintf( stderr, "usage:\n"
30 " ftest [-d n] filter\n"
31 " filter - RFC 2254 string representation of an "
32 "LDAP search filter\n" );
37 main( int argc, char *argv[] )
42 while( (c = getopt( argc, argv, "d:" )) != EOF ) {
45 debug = atoi( optarg );
48 fprintf( stderr, "ftest: unrecognized option -%c\n",
55 if ( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
58 fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n",
61 if ( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
64 fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n",
69 if ( argc - optind != 1 ) {
73 return filter2ber( strdup( argv[optind] ) );
76 static int filter2ber( char *filter )
79 struct berval *bv = NULL;
82 printf( "Filter: %s\n", filter );
84 ber = ber_alloc_t( LBER_USE_DER );
86 perror( "ber_alloc_t" );
90 rc = ldap_pvt_put_filter( ber, filter );
92 fprintf( stderr, "Filter error!\n");
96 rc = ber_flatten( ber, &bv );
98 perror( "ber_flatten" );
102 printf( "BER encoding (len=%ld):\n", (long) bv->bv_len );
103 ber_bprint( bv->bv_val, bv->bv_len );