3 * Copyright 1999-2003 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"
28 MatchingRuleAssertion *mra,
33 test_substrings_vrFilter(
38 ValuesReturnFilter *f,
43 test_presence_vrFilter(
48 AttributeDescription *desc,
58 AttributeAssertion *ava,
65 filter_matched_values(
73 ValuesReturnFilter *f;
74 int rc = LDAP_SUCCESS;
77 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
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, 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" :
91 "error", f->f_result, 0 );
93 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
94 f->f_result == LDAP_COMPARE_FALSE ? "false" :
95 f->f_result == LDAP_COMPARE_TRUE ? "true" :
96 f->f_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
99 /*This type of filter does not affect the result */
103 case LDAP_FILTER_EQUALITY:
105 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
107 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
109 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
110 LDAP_FILTER_EQUALITY, e_flags );
116 case LDAP_FILTER_SUBSTRINGS:
118 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
120 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
123 rc = test_substrings_vrFilter( be, conn, op, a,
130 case LDAP_FILTER_PRESENT:
132 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
134 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
136 rc = test_presence_vrFilter( be, conn, op, a,
137 f->f_desc, e_flags );
144 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
145 LDAP_FILTER_GE, e_flags );
152 rc = test_ava_vrFilter( be, conn, op, a, f->f_ava,
153 LDAP_FILTER_LE, e_flags );
159 case LDAP_FILTER_EXT:
161 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
163 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
165 rc = test_mra_vrFilter( be, conn, op, a,
174 LDAP_LOG( FILTER, INFO,
175 "test_vrFilter: unknown filter type %lu\n", f->f_choice, 0, 0 );
177 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
180 rc = LDAP_PROTOCOL_ERROR;
185 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
187 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
198 AttributeAssertion *ava,
205 for ( i=0; a != NULL; a = a->a_next, i++ ) {
210 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
215 case LDAP_FILTER_APPROX:
216 mr = a->a_desc->ad_type->sat_approx;
217 if( mr != NULL ) break;
219 /* use EQUALITY matching rule if no APPROX rule */
220 case LDAP_FILTER_EQUALITY:
221 mr = a->a_desc->ad_type->sat_equality;
226 mr = a->a_desc->ad_type->sat_ordering;
238 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ ) {
243 rc = value_match( &ret, a->a_desc, mr,
244 SLAP_MR_ASSERTION_SYNTAX_MATCH, bv, &ava->aa_value, &text );
245 if( rc != LDAP_SUCCESS ) {
250 case LDAP_FILTER_EQUALITY:
251 case LDAP_FILTER_APPROX:
253 (*e_flags)[i][j] = 1;
259 (*e_flags)[i][j] = 1;
265 (*e_flags)[i][j] = 1;
271 return( LDAP_SUCCESS );
275 test_presence_vrFilter(
280 AttributeDescription *desc,
286 for ( i=0; a != NULL; a = a->a_next, i++ ) {
289 if ( !is_ad_subtype( a->a_desc, desc ) ) {
293 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
294 memset( (*e_flags)[i], 1, j);
297 return( LDAP_SUCCESS );
301 test_substrings_vrFilter(
306 ValuesReturnFilter *f,
312 for ( i=0; a != NULL; a = a->a_next, i++ ) {
313 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
316 if ( !is_ad_subtype( a->a_desc, f->f_sub_desc ) ) {
324 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
329 rc = value_match( &ret, a->a_desc, mr,
330 SLAP_MR_ASSERTION_SYNTAX_MATCH,
331 bv, f->f_sub, &text );
333 if( rc != LDAP_SUCCESS ) {
338 (*e_flags)[i][j] = 1;
352 MatchingRuleAssertion *mra,
358 for ( i=0; a != NULL; a = a->a_next, i++ ) {
359 struct berval *bv, value;
361 if ( mra->ma_desc ) {
362 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
365 value = mra->ma_value;
368 const char *text = NULL;
370 /* check if matching is appropriate */
371 if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
372 a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
376 /* normalize for equality */
377 if ( value_validate_normalize( a->a_desc,
379 &mra->ma_value, &value,
380 &text ) != LDAP_SUCCESS ) {
386 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
391 rc = value_match( &ret, a->a_desc, mra->ma_rule,
392 SLAP_MR_ASSERTION_SYNTAX_MATCH,
396 if( rc != LDAP_SUCCESS ) {
401 (*e_flags)[i][j] = 1;