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, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
78 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
81 for ( f = op->vrFilter; f != NULL; f = f->f_next ) {
82 switch ( f->f_choice ) {
83 case SLAPD_FILTER_COMPUTED:
85 LDAP_LOG( FILTER, DETAIL1,
86 "test_vrFilter: COMPUTED %s (%d)\n",
87 f->f_result == LDAP_COMPARE_FALSE ? "false" :
88 f->f_result == LDAP_COMPARE_TRUE ? "true" :
89 f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
90 "error", f->f_result, 0 );
92 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
93 f->f_result == LDAP_COMPARE_FALSE ? "false" :
94 f->f_result == LDAP_COMPARE_TRUE ? "true" :
95 f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
98 /*This type of filter does not affect the result */
102 case LDAP_FILTER_EQUALITY:
104 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
106 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
108 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
109 LDAP_FILTER_EQUALITY, e_flags );
115 case LDAP_FILTER_SUBSTRINGS:
117 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
119 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
122 rc = test_substrings_vrFilter( be, conn, op, a,
129 case LDAP_FILTER_PRESENT:
131 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
133 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
135 rc = test_presence_vrFilter( be, conn, op, a,
136 f->f_desc, e_flags );
143 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
144 LDAP_FILTER_GE, e_flags );
151 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
152 LDAP_FILTER_LE, e_flags );
158 case LDAP_FILTER_EXT:
160 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
162 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
164 rc = test_mra_vrFilter( be, conn, op, a,
173 LDAP_LOG( FILTER, INFO,
174 "test_vrFilter: unknown filter type %lu\n", f->f_choice, 0, 0 );
176 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
179 rc = LDAP_PROTOCOL_ERROR;
184 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
186 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
197 AttributeAssertion *ava,
204 for ( i=0; a != NULL; a = a->a_next, i++ ) {
209 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
214 case LDAP_FILTER_APPROX:
215 mr = a->a_desc->ad_type->sat_approx;
216 if( mr != NULL ) break;
218 /* use EQUALITY matching rule if no APPROX rule */
219 case LDAP_FILTER_EQUALITY:
220 mr = a->a_desc->ad_type->sat_equality;
225 mr = a->a_desc->ad_type->sat_ordering;
237 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ ) {
242 rc = value_match( &ret, a->a_desc, mr,
243 SLAP_MR_ASSERTION_SYNTAX_MATCH, bv, &ava->aa_value, &text );
244 if( rc != LDAP_SUCCESS ) {
249 case LDAP_FILTER_EQUALITY:
250 case LDAP_FILTER_APPROX:
252 (*e_flags)[i][j] = 1;
258 (*e_flags)[i][j] = 1;
264 (*e_flags)[i][j] = 1;
270 return( LDAP_SUCCESS );
274 test_presence_vrFilter(
279 AttributeDescription *desc,
285 for ( i=0; a != NULL; a = a->a_next, i++ ) {
288 if ( !is_ad_subtype( a->a_desc, desc ) ) {
292 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
293 memset( (*e_flags)[i], 1, j);
296 return( LDAP_SUCCESS );
300 test_substrings_vrFilter(
305 ValuesReturnFilter *f,
311 for ( i=0; a != NULL; a = a->a_next, i++ ) {
312 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
315 if ( !is_ad_subtype( a->a_desc, f->f_sub_desc ) ) {
323 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
328 rc = value_match( &ret, a->a_desc, mr,
329 SLAP_MR_ASSERTION_SYNTAX_MATCH,
330 bv, f->f_sub, &text );
332 if( rc != LDAP_SUCCESS ) {
337 (*e_flags)[i][j] = 1;
345 static int test_mra_vrFilter(
350 MatchingRuleAssertion *mra,
356 for ( i=0; a != NULL; a = a->a_next, i++ ) {
359 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
360 return( LDAP_SUCCESS );
363 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
368 rc = value_match( &ret, a->a_desc, mra->ma_rule,
369 SLAP_MR_ASSERTION_SYNTAX_MATCH,
373 if( rc != LDAP_SUCCESS ) {
378 (*e_flags)[i][j] = 1;