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( const char *filter );
29 fprintf( stderr, "usage:\n"
35 main( int argc, char *argv[] )
37 int i, debug=0, ber=0;
40 while( (i = getopt( argc, argv, "Aa:Ss:"
48 debug = atoi( optarg );
51 fprintf( stderr, "ftest: unrecognized option -%c\n",
58 if ( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
61 fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n",
64 if ( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
67 fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n",
72 if( argc - optind > 1 ) {
74 } else if ( argc - optind == 1 ) {
76 fprintf( stderr, "ftest: parameter %s unexpected\n",
80 return filter2ber( argv[optind] );
86 static int filter2ber( const char *filter )
89 BerElement *ber = ber_alloc_t( LBER_USE_DER );
90 struct berval *bv = NULL;
93 perror( "ber_alloc_t" );
97 rc = ldap_int_put_filter( ber, (char *) filter );
101 rc = ber_flatten( ber, &bv );
104 perror( "ber_flatten" );