/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2003-2008 The OpenLDAP Foundation.
+ * Copyright 2003-2009 The OpenLDAP Foundation.
* Portions Copyright 2003 IBM Corporation.
* Portions Copyright 2003 Symas Corporation.
* All rights reserved.
return len;
}
-/* compare the first value in each filter */
-static int pcache_filter_cmp( const void *v1, const void *v2 )
+/* compare the current value in each filter */
+static int pcache_filter_cmp( Filter *f1, Filter *f2 )
{
- const CachedQuery *q1 = v1, *q2 =v2;
int rc, weight1, weight2;
- switch( q1->first->f_choice ) {
+ switch( f1->f_choice ) {
case LDAP_FILTER_PRESENT:
weight1 = 0;
break;
default:
weight1 = 2;
}
- switch( q2->first->f_choice ) {
+ switch( f2->f_choice ) {
case LDAP_FILTER_PRESENT:
weight2 = 0;
break;
rc = weight1 - weight2;
if ( !rc ) {
switch( weight1 ) {
- case 0: return 0;
+ case 0:
+ break;
case 1:
- rc = lex_bvcmp( &q1->first->f_av_value, &q2->first->f_av_value );
+ rc = lex_bvcmp( &f1->f_av_value, &f2->f_av_value );
break;
case 2:
- if ( q1->first->f_choice == LDAP_FILTER_SUBSTRINGS ) {
+ if ( f1->f_choice == LDAP_FILTER_SUBSTRINGS ) {
rc = 0;
- if ( !BER_BVISNULL( &q1->first->f_sub_initial )) {
- if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
- rc = lex_bvcmp( &q1->first->f_sub_initial,
- &q2->first->f_sub_initial );
+ if ( !BER_BVISNULL( &f1->f_sub_initial )) {
+ if ( !BER_BVISNULL( &f2->f_sub_initial )) {
+ rc = lex_bvcmp( &f1->f_sub_initial,
+ &f2->f_sub_initial );
} else {
rc = 1;
}
- } else if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
+ } else if ( !BER_BVISNULL( &f2->f_sub_initial )) {
rc = -1;
}
if ( rc ) break;
- if ( q1->first->f_sub_any ) {
- if ( q2->first->f_sub_any ) {
- rc = lex_bvcmp( q1->first->f_sub_any,
- q2->first->f_sub_any );
+ if ( f1->f_sub_any ) {
+ if ( f2->f_sub_any ) {
+ rc = lex_bvcmp( f1->f_sub_any,
+ f2->f_sub_any );
} else {
rc = 1;
}
- } else if ( q2->first->f_sub_any ) {
+ } else if ( f2->f_sub_any ) {
rc = -1;
}
if ( rc ) break;
- if ( !BER_BVISNULL( &q1->first->f_sub_final )) {
- if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
- rc = lex_bvcmp( &q1->first->f_sub_final,
- &q2->first->f_sub_final );
+ if ( !BER_BVISNULL( &f1->f_sub_final )) {
+ if ( !BER_BVISNULL( &f2->f_sub_final )) {
+ rc = lex_bvcmp( &f1->f_sub_final,
+ &f2->f_sub_final );
} else {
rc = 1;
}
- } else if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
+ } else if ( !BER_BVISNULL( &f2->f_sub_final )) {
rc = -1;
}
} else {
- rc = lex_bvcmp( &q1->first->f_mr_value,
- &q2->first->f_mr_value );
+ rc = lex_bvcmp( &f1->f_mr_value,
+ &f2->f_mr_value );
}
break;
}
+ if ( !rc ) {
+ f1 = f1->f_next;
+ f2 = f2->f_next;
+ if ( f1 || f2 ) {
+ if ( !f1 )
+ rc = -1;
+ else if ( !f2 )
+ rc = 1;
+ else {
+ while ( f1->f_choice == LDAP_FILTER_AND || f1->f_choice == LDAP_FILTER_OR )
+ f1 = f1->f_and;
+ while ( f2->f_choice == LDAP_FILTER_AND || f2->f_choice == LDAP_FILTER_OR )
+ f2 = f2->f_and;
+ rc = pcache_filter_cmp( f1, f2 );
+ }
+ }
+ }
}
-
return rc;
}
+/* compare filters in each query */
+static int pcache_query_cmp( const void *v1, const void *v2 )
+{
+ const CachedQuery *q1 = v1, *q2 =v2;
+ return pcache_filter_cmp( q1->first, q2->first );
+}
+
/* add query on top of LRU list */
static void
add_query_on_top (query_manager* qm, CachedQuery* qc)
ptr = tavl_end( root, 1 );
dir = TAVL_DIR_LEFT;
} else {
- ptr = tavl_find3( root, &cq, pcache_filter_cmp, &ret );
+ ptr = tavl_find3( root, &cq, pcache_query_cmp, &ret );
dir = (first->f_choice == LDAP_FILTER_GE) ? TAVL_DIR_LEFT :
TAVL_DIR_RIGHT;
}
new_cached_query->prev = NULL;
new_cached_query->qbase = qbase;
rc = tavl_insert( &qbase->scopes[query->scope], new_cached_query,
- pcache_filter_cmp, avl_dup_error );
+ pcache_query_cmp, avl_dup_error );
if ( rc == 0 ) {
qbase->queries++;
if (templ->query == NULL)
qc->next->prev = qc->prev;
qc->prev->next = qc->next;
}
- tavl_delete( &qc->qbase->scopes[qc->scope], qc, pcache_filter_cmp );
+ tavl_delete( &qc->qbase->scopes[qc->scope], qc, pcache_query_cmp );
qc->qbase->queries--;
if ( qc->qbase->queries == 0 ) {
avl_delete( &template->qbase, qc->qbase, pcache_dn_cmp );
return rs->sr_err;
}
+ /* pickup runtime ACL changes */
+ cm->db.be_acl = op->o_bd->be_acl;
+
tempstr.bv_val = op->o_tmpalloc( op->ors_filterstr.bv_len+1, op->o_tmpmemctx );
tempstr.bv_len = 0;
if ( filter2template( op, op->ors_filter, &tempstr, &filter_attrs,