1 /* ftest.c -- OpenLDAP Filter API Test */
2 /* $OpenLDAP: pkg/ldap/libraries/libldap/ftest.c,v 1.15.2.3 2008/02/11 23:26:41 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
19 #include <ac/stdlib.h>
20 #include <ac/string.h>
21 #include <ac/unistd.h>
32 #include "lutil_ldap.h"
33 #include "ldap_defaults.h"
35 static int filter2ber( char *filter
);
39 fprintf( stderr
, "usage:\n"
40 " ftest [-d n] filter\n"
41 " filter - RFC 4515 string representation of an "
42 "LDAP search filter\n" );
47 main( int argc
, char *argv
[] )
52 while( (c
= getopt( argc
, argv
, "d:" )) != EOF
) {
55 debug
= atoi( optarg
);
58 fprintf( stderr
, "ftest: unrecognized option -%c\n",
65 if ( ber_set_option( NULL
, LBER_OPT_DEBUG_LEVEL
, &debug
)
68 fprintf( stderr
, "Could not set LBER_OPT_DEBUG_LEVEL %d\n",
71 if ( ldap_set_option( NULL
, LDAP_OPT_DEBUG_LEVEL
, &debug
)
74 fprintf( stderr
, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n",
79 if ( argc
- optind
!= 1 ) {
83 return filter2ber( strdup( argv
[optind
] ) );
86 static int filter2ber( char *filter
)
89 struct berval bv
= BER_BVNULL
;
92 printf( "Filter: %s\n", filter
);
94 ber
= ber_alloc_t( LBER_USE_DER
);
96 perror( "ber_alloc_t" );
100 rc
= ldap_pvt_put_filter( ber
, filter
);
102 fprintf( stderr
, "Filter error!\n");
106 rc
= ber_flatten2( ber
, &bv
, 0 );
108 perror( "ber_flatten2" );
112 printf( "BER encoding (len=%ld):\n", (long) bv
.bv_len
);
113 ber_bprint( bv
.bv_val
, bv
.bv_len
);