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[] )
43 while( (c = getopt( argc, argv, "d:" )) != EOF ) {
46 debug = atoi( optarg );
49 fprintf( stderr, "ftest: unrecognized option -%c\n",
56 if ( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
59 fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n",
62 if ( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
65 fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n",
70 if ( argc - optind != 1 ) {
74 return filter2ber( strdup( argv[optind] ) );
77 static int filter2ber( char *filter )
80 struct berval *bv = NULL;
83 printf( "Filter: %s\n", filter );
85 ber = ber_alloc_t( LBER_USE_DER );
87 perror( "ber_alloc_t" );
91 rc = ldap_int_put_filter( ber, filter );
93 fprintf( stderr, "Filter error!\n");
97 rc = ber_flatten( ber, &bv );
99 perror( "ber_flatten" );
103 printf( "BER encoding (len=%ld):\n", (long) bv->bv_len );
104 ber_bprint( bv->bv_val, bv->bv_len );