3 * Copyright 1999-2002 The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
15 #include <ac/string.h>
16 #include <ac/socket.h>
20 #include "../../libraries/liblber/lber-int.h"
22 static int test_mra_vrFilter(
27 MatchingRuleAssertion *mra,
32 test_substrings_vrFilter(
37 ValuesReturnFilter *f,
42 test_presence_vrFilter(
47 AttributeDescription *desc,
57 AttributeAssertion *ava,
64 filter_matched_values(
72 ValuesReturnFilter *f;
73 int rc = LDAP_SUCCESS;
76 LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
77 "filter_matched_values: begin\n" ));
79 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
82 for ( f = op->vrFilter; f != NULL; f = f->f_next ) {
83 switch ( f->f_choice ) {
84 case SLAPD_FILTER_COMPUTED:
86 LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
87 "test_vrFilter: COMPUTED %s (%d)\n",
88 f->f_result == LDAP_COMPARE_FALSE ? "false" :
89 f->f_result == LDAP_COMPARE_TRUE ? "true" :
90 f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
94 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
95 f->f_result == LDAP_COMPARE_FALSE ? "false" :
96 f->f_result == LDAP_COMPARE_TRUE ? "true" :
97 f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
100 /*This type of filter does not affect the result */
104 case LDAP_FILTER_EQUALITY:
106 LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
107 "test_vrFilter: EQUALITY\n" ));
109 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
111 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
112 LDAP_FILTER_EQUALITY, e_flags );
118 case LDAP_FILTER_SUBSTRINGS:
120 LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
121 "test_vrFilter SUBSTRINGS\n" ));
123 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
126 rc = test_substrings_vrFilter( be, conn, op, a,
133 case LDAP_FILTER_PRESENT:
135 LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
136 "test_vrFilter: PRESENT\n" ));
138 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
140 rc = test_presence_vrFilter( be, conn, op, a,
141 f->f_desc, e_flags );
148 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
149 LDAP_FILTER_GE, e_flags );
156 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
157 LDAP_FILTER_LE, e_flags );
163 case LDAP_FILTER_EXT:
165 LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
166 "test_vrFilter: EXT\n" ));
168 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
170 rc = test_mra_vrFilter( be, conn, op, a,
179 LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
180 "test_vrFilter: unknown filter type %lu\n",
183 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
186 rc = LDAP_PROTOCOL_ERROR;
191 LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
192 "filter_matched_values: return=%d\n", rc ));
194 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
205 AttributeAssertion *ava,
212 for ( i=0; a != NULL; a = a->a_next, i++ ) {
217 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
222 case LDAP_FILTER_APPROX:
223 mr = a->a_desc->ad_type->sat_approx;
224 if( mr != NULL ) break;
226 /* use EQUALITY matching rule if no APPROX rule */
227 case LDAP_FILTER_EQUALITY:
228 mr = a->a_desc->ad_type->sat_equality;
233 mr = a->a_desc->ad_type->sat_ordering;
245 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ ) {
250 rc = value_match( &ret, a->a_desc, mr,
251 SLAP_MR_ASSERTION_SYNTAX_MATCH, bv, &ava->aa_value, &text );
252 if( rc != LDAP_SUCCESS ) {
257 case LDAP_FILTER_EQUALITY:
258 case LDAP_FILTER_APPROX:
260 (*e_flags)[i][j] = 1;
266 (*e_flags)[i][j] = 1;
272 (*e_flags)[i][j] = 1;
278 return( LDAP_SUCCESS );
282 test_presence_vrFilter(
287 AttributeDescription *desc,
293 for ( i=0; a != NULL; a = a->a_next, i++ ) {
296 if ( !is_ad_subtype( a->a_desc, desc ) ) {
300 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
301 memset( (*e_flags)[i], 1, j);
304 return( LDAP_SUCCESS );
308 test_substrings_vrFilter(
313 ValuesReturnFilter *f,
319 for ( i=0; a != NULL; a = a->a_next, i++ ) {
320 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
323 if ( !is_ad_subtype( a->a_desc, f->f_sub_desc ) ) {
331 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
336 rc = value_match( &ret, a->a_desc, mr,
337 SLAP_MR_ASSERTION_SYNTAX_MATCH,
338 bv, f->f_sub, &text );
340 if( rc != LDAP_SUCCESS ) {
345 (*e_flags)[i][j] = 1;
353 static int test_mra_vrFilter(
358 MatchingRuleAssertion *mra,
364 for ( i=0; a != NULL; a = a->a_next, i++ ) {
367 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
368 return( LDAP_SUCCESS );
371 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
376 rc = value_match( &ret, a->a_desc, mra->ma_rule,
377 SLAP_MR_ASSERTION_SYNTAX_MATCH,
381 if( rc != LDAP_SUCCESS ) {
386 (*e_flags)[i][j] = 1;