1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
26 #include <ac/string.h>
27 #include <ac/socket.h>
30 #include "back-monitor.h"
31 #include "proto-back-monitor.h"
34 monitor_send_children(
41 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
42 Entry *e, *e_tmp, *e_ch;
46 mp = ( monitor_entry_t * )e_parent->e_private;
50 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
51 monitor_entry_create( op, NULL, e_parent, &e_ch );
53 monitor_cache_release( mi, e_parent );
55 /* no volatile entries? */
57 /* no persistent entries? return */
62 /* volatile entries */
64 /* if no persistent, return only volatile */
67 monitor_cache_lock( e_ch );
69 /* else append persistent to volatile */
73 mp = ( monitor_entry_t * )e_tmp->e_private;
76 if ( e_tmp == NULL ) {
86 for ( ; e != NULL; ) {
87 mp = ( monitor_entry_t * )e->e_private;
89 monitor_entry_update( op, e );
91 rc = test_filter( op, e, op->oq_search.rs_filter );
92 if ( rc == LDAP_COMPARE_TRUE ) {
95 send_search_entry( op, rs );
99 if ( ( mp->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
101 rc = monitor_send_children( op, rs, e, sub );
108 if ( e_tmp != NULL ) {
109 monitor_cache_lock( e_tmp );
111 monitor_cache_release( mi, e );
119 monitor_back_search( Operation *op, SlapReply *rs )
121 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
122 int rc = LDAP_SUCCESS;
123 Entry *e = NULL, *matched = NULL;
125 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
128 /* get entry with reader lock */
129 monitor_cache_dn2entry( op, &op->o_req_ndn, &e, &matched );
131 rs->sr_err = LDAP_NO_SUCH_OBJECT;
133 rs->sr_matched = matched->e_dn;
136 send_ldap_result( op, rs );
138 monitor_cache_release( mi, matched );
139 rs->sr_matched = NULL;
145 rs->sr_attrs = op->oq_search.rs_attrs;
146 switch ( op->oq_search.rs_scope ) {
147 case LDAP_SCOPE_BASE:
148 monitor_entry_update( op, e );
149 rc = test_filter( op, e, op->oq_search.rs_filter );
150 if ( rc == LDAP_COMPARE_TRUE ) {
153 send_search_entry( op, rs );
157 monitor_cache_release( mi, e );
160 case LDAP_SCOPE_ONELEVEL:
161 rc = monitor_send_children( op, rs, e, 0 );
168 case LDAP_SCOPE_SUBTREE:
169 monitor_entry_update( op, e );
170 rc = test_filter( op, e, op->oq_search.rs_filter );
171 if ( rc == LDAP_COMPARE_TRUE ) {
174 send_search_entry( op, rs );
178 rc = monitor_send_children( op, rs, e, 1 );
188 send_ldap_result( op, rs );
190 return( rc == LDAP_SUCCESS ? 0 : 1 );