3 * Copyright 1998-2000 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 "\tftest [-d n] filter\n" );
35 main( int argc, char *argv[] )
41 while( (i = getopt( argc, argv, "Aa:Ss:" "d:" )) != EOF ) {
44 debug = atoi( optarg );
47 fprintf( stderr, "ftest: unrecognized option -%c\n",
54 if ( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
57 fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n",
60 if ( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
63 fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n",
68 if( argc - optind > 1 ) {
71 } else if ( argc - optind != 1 ) {
75 return filter2ber( strdup( argv[optind] ) );
78 static int filter2ber( char *filter )
81 struct berval *bv = NULL;
84 printf( "Filter: %s\n", filter );
86 ber = ber_alloc_t( LBER_USE_DER );
88 perror( "ber_alloc_t" );
92 rc = ldap_int_put_filter( ber, filter );
94 fprintf( stderr, "Filter error!\n");
98 rc = ber_flatten( ber, &bv );
100 perror( "ber_flatten" );
104 printf( "BER encoding (len=%ld):\n", (long) bv->bv_len );
105 ber_bprint( bv->bv_val, bv->bv_len );