--- servers/slapd/filter.c 1998/10/20 23:24:28 1.3.10.1 +++ servers/slapd/filter.c 1999/06/17 17:09:54 1.10.2.1 @@ -3,22 +3,19 @@ #include "portable.h" #include -#include -#include -#include -#include "slap.h" -static int get_filter_list(); -static int get_substring_filter(); +#include +#include + +#include "slap.h" -extern int get_ava(); -extern char *ch_malloc(); -extern char *ch_realloc(); +static int get_filter_list(Connection *conn, BerElement *ber, Filter **f, char **fstr); +static int get_substring_filter(Connection *conn, BerElement *ber, Filter *f, char **fstr); int get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) { - unsigned long tag, len; + unsigned long len; int err; Filter *f; char *ftmp; @@ -50,13 +47,12 @@ get_filter( Connection *conn, BerElement */ f = (Filter *) ch_malloc( sizeof(Filter) ); - *filt = f; f->f_next = NULL; err = 0; *fstr = NULL; f->f_choice = ber_peek_tag( ber, &len ); -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 if ( conn->c_version == 30 ) { switch ( f->f_choice ) { case LDAP_FILTER_EQUALITY: @@ -137,7 +133,7 @@ get_filter( Connection *conn, BerElement Debug( LDAP_DEBUG_FILTER, "AND\n", 0, 0, 0 ); if ( (err = get_filter_list( conn, ber, &f->f_and, &ftmp )) == 0 ) { - if (ftmp == NULL) ftmp = strdup(""); + if (ftmp == NULL) ftmp = ch_strdup(""); *fstr = ch_malloc( 4 + strlen( ftmp ) ); sprintf( *fstr, "(&%s)", ftmp ); free( ftmp ); @@ -148,7 +144,7 @@ get_filter( Connection *conn, BerElement Debug( LDAP_DEBUG_FILTER, "OR\n", 0, 0, 0 ); if ( (err = get_filter_list( conn, ber, &f->f_or, &ftmp )) == 0 ) { - if (ftmp == NULL) ftmp = strdup(""); + if (ftmp == NULL) ftmp = ch_strdup(""); *fstr = ch_malloc( 4 + strlen( ftmp ) ); sprintf( *fstr, "(|%s)", ftmp ); free( ftmp ); @@ -159,7 +155,7 @@ get_filter( Connection *conn, BerElement Debug( LDAP_DEBUG_FILTER, "NOT\n", 0, 0, 0 ); (void) ber_skip_tag( ber, &len ); if ( (err = get_filter( conn, ber, &f->f_not, &ftmp )) == 0 ) { - if (ftmp == NULL) ftmp = strdup(""); + if (ftmp == NULL) ftmp = ch_strdup(""); *fstr = ch_malloc( 4 + strlen( ftmp ) ); sprintf( *fstr, "(!%s)", ftmp ); free( ftmp ); @@ -167,8 +163,8 @@ get_filter( Connection *conn, BerElement break; default: - Debug( LDAP_DEBUG_ANY, "unknown filter type %d\n", f->f_choice, - 0, 0 ); + Debug( LDAP_DEBUG_ANY, "unknown filter type %lu\n", + f->f_choice, 0, 0 ); err = LDAP_PROTOCOL_ERROR; break; } @@ -178,6 +174,8 @@ get_filter( Connection *conn, BerElement if ( *fstr != NULL ) { free( *fstr ); } + } else { + *filt = f; } Debug( LDAP_DEBUG_FILTER, "end get_filter %d\n", err, 0, 0 ); @@ -194,7 +192,7 @@ get_filter_list( Connection *conn, BerEl Debug( LDAP_DEBUG_FILTER, "begin get_filter_list\n", 0, 0, 0 ); -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 if ( conn->c_version == 30 ) { (void) ber_skip_tag( ber, &len ); } @@ -235,12 +233,12 @@ get_substring_filter( Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 ); -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 if ( conn->c_version == 30 ) { (void) ber_skip_tag( ber, &len ); } #endif - if ( ber_scanf( ber, "{a", &f->f_sub_type ) == LBER_ERROR ) { + if ( ber_scanf( ber, "{a" /*}*/, &f->f_sub_type ) == LBER_ERROR ) { return( LDAP_PROTOCOL_ERROR ); } attr_normalize( f->f_sub_type ); @@ -253,7 +251,7 @@ get_substring_filter( sprintf( *fstr, "(%s=", f->f_sub_type ); for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT; tag = ber_next_element( ber, &len, last ) ) { -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 if ( conn->c_version == 30 ) { rc = ber_scanf( ber, "{a}", &val ); } else @@ -271,7 +269,7 @@ get_substring_filter( value_normalize( val, syntax ); switch ( tag ) { -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 case LDAP_SUBSTRING_INITIAL_30: #endif case LDAP_SUBSTRING_INITIAL: @@ -285,7 +283,7 @@ get_substring_filter( strcat( *fstr, val ); break; -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 case LDAP_SUBSTRING_ANY_30: #endif case LDAP_SUBSTRING_ANY: @@ -297,7 +295,7 @@ get_substring_filter( strcat( *fstr, val ); break; -#ifdef COMPAT30 +#ifdef LDAP_COMPAT30 case LDAP_SUBSTRING_FINAL_30: #endif case LDAP_SUBSTRING_FINAL: @@ -374,8 +372,8 @@ filter_free( Filter *f ) break; default: - Debug( LDAP_DEBUG_ANY, "unknown filter type %d\n", f->f_choice, - 0, 0 ); + Debug( LDAP_DEBUG_ANY, "unknown filter type %lu\n", + f->f_choice, 0, 0 ); break; } free( f ); @@ -390,63 +388,63 @@ filter_print( Filter *f ) Filter *p; if ( f == NULL ) { - printf( "NULL" ); + fprintf( stderr, "NULL" ); } switch ( f->f_choice ) { case LDAP_FILTER_EQUALITY: - printf( "(%s=%s)", f->f_ava.ava_type, + fprintf( stderr, "(%s=%s)", f->f_ava.ava_type, f->f_ava.ava_value.bv_val ); break; case LDAP_FILTER_GE: - printf( "(%s>=%s)", f->f_ava.ava_type, + fprintf( stderr, "(%s>=%s)", f->f_ava.ava_type, f->f_ava.ava_value.bv_val ); break; case LDAP_FILTER_LE: - printf( "(%s<=%s)", f->f_ava.ava_type, + fprintf( stderr, "(%s<=%s)", f->f_ava.ava_type, f->f_ava.ava_value.bv_val ); break; case LDAP_FILTER_APPROX: - printf( "(%s~=%s)", f->f_ava.ava_type, + fprintf( stderr, "(%s~=%s)", f->f_ava.ava_type, f->f_ava.ava_value.bv_val ); break; case LDAP_FILTER_SUBSTRINGS: - printf( "(%s=", f->f_sub_type ); + fprintf( stderr, "(%s=", f->f_sub_type ); if ( f->f_sub_initial != NULL ) { - printf( "%s", f->f_sub_initial ); + fprintf( stderr, "%s", f->f_sub_initial ); } if ( f->f_sub_any != NULL ) { for ( i = 0; f->f_sub_any[i] != NULL; i++ ) { - printf( "*%s", f->f_sub_any[i] ); + fprintf( stderr, "*%s", f->f_sub_any[i] ); } } charray_free( f->f_sub_any ); if ( f->f_sub_final != NULL ) { - printf( "*%s", f->f_sub_final ); + fprintf( stderr, "*%s", f->f_sub_final ); } break; case LDAP_FILTER_PRESENT: - printf( "%s=*", f->f_type ); + fprintf( stderr, "%s=*", f->f_type ); break; case LDAP_FILTER_AND: case LDAP_FILTER_OR: case LDAP_FILTER_NOT: - printf( "(%c", f->f_choice == LDAP_FILTER_AND ? '&' : + fprintf( stderr, "(%c", f->f_choice == LDAP_FILTER_AND ? '&' : f->f_choice == LDAP_FILTER_OR ? '|' : '!' ); for ( p = f->f_list; p != NULL; p = p->f_next ) { filter_print( p ); } - printf( ")" ); + fprintf( stderr, ")" ); break; default: - printf( "unknown type %d", f->f_choice ); + fprintf( stderr, "unknown type %lu", f->f_choice ); break; } }