X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libraries%2Flibldap%2Fftest.c;h=ea9f29e0824ba7dc941ba1afd92c1cc54add6214;hb=cdbbed6c3b6a4f0b69fab6e37c3a098ca5d12620;hp=69c2a4f6fce982ae71311e7db2a1cf60379b5f43;hpb=bf5fc54473f2143586e43aada98ae8f5dab7570b;p=openldap diff --git a/libraries/libldap/ftest.c b/libraries/libldap/ftest.c index 69c2a4f6fc..ea9f29e082 100644 --- a/libraries/libldap/ftest.c +++ b/libraries/libldap/ftest.c @@ -1,9 +1,18 @@ +/* ftest.c -- OpenLDAP Filter API Test */ /* $OpenLDAP$ */ -/* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2005 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . */ -/* OpenLDAP Filter API Test */ #include "portable.h" @@ -15,35 +24,33 @@ #include -#include "ldap-int.h" +#include "ldap_pvt.h" +#include "lber_pvt.h" #include "ldif.h" #include "lutil.h" #include "lutil_ldap.h" #include "ldap_defaults.h" -static int filter2ber( const char *filter ); +static int filter2ber( char *filter ); int usage() { fprintf( stderr, "usage:\n" - " ftest [filter]" ); + " ftest [-d n] filter\n" + " filter - RFC 2254 string representation of an " + "LDAP search filter\n" ); return EXIT_FAILURE; } int main( int argc, char *argv[] ) { - int i, debug=0, ber=0; - char *filter=NULL; - - while( (i = getopt( argc, argv, "Aa:Ss:" - "bd:" )) != EOF ) - { - switch ( i ) { - case 'b': - ber++; - break; + int c; + int debug=0; + + while( (c = getopt( argc, argv, "d:" )) != EOF ) { + switch ( c ) { case 'd': debug = atoi( optarg ); break; @@ -69,44 +76,44 @@ main( int argc, char *argv[] ) } } - if( argc - optind > 1 ) { + if ( argc - optind != 1 ) { return usage(); - } else if ( argc - optind == 1 ) { - if( ber ) { - fprintf( stderr, "ftest: parameter %s unexpected\n", - argv[optind] ); - return usage(); - } - return filter2ber( argv[optind] ); } - return EXIT_FAILURE; + return filter2ber( strdup( argv[optind] ) ); } -static int filter2ber( const char *filter ) +static int filter2ber( char *filter ) { int rc; - BerElement *ber = ber_alloc_t( LBER_USE_DER ); - struct berval *bv = NULL; + struct berval bv = BER_BVNULL; + BerElement *ber; + + printf( "Filter: %s\n", filter ); + ber = ber_alloc_t( LBER_USE_DER ); if( ber == NULL ) { perror( "ber_alloc_t" ); return EXIT_FAILURE; } - rc = ldap_int_put_filter( ber, (char *) filter ); - - ber_dump( ber, 0 ); - - rc = ber_flatten( ber, &bv ); + rc = ldap_pvt_put_filter( ber, filter ); + if( rc < 0 ) { + fprintf( stderr, "Filter error!\n"); + return EXIT_FAILURE; + } + rc = ber_flatten2( ber, &bv, 0 ); if( rc < 0 ) { - perror( "ber_flatten" ); + perror( "ber_flatten2" ); return EXIT_FAILURE; } + printf( "BER encoding (len=%ld):\n", (long) bv.bv_len ); + ber_bprint( bv.bv_val, bv.bv_len ); + ber_free( ber, 1 ); - ber_bvfree( bv ); return EXIT_SUCCESS; -} \ No newline at end of file +} +