1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 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 struct monitorinfo *mi =
42 (struct monitorinfo *) op->o_bd->be_private;
43 Entry *e, *e_tmp, *e_ch;
44 struct monitorentrypriv *mp;
47 mp = ( struct monitorentrypriv * )e_parent->e_private;
51 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
52 monitor_entry_create( op, NULL, e_parent, &e_ch );
54 monitor_cache_release( mi, e_parent );
56 /* no volatile entries? */
58 /* no persistent entries? return */
63 /* volatile entries */
65 /* if no persistent, return only volatile */
68 monitor_cache_lock( e_ch );
70 /* else append persistent to volatile */
74 mp = ( struct monitorentrypriv * )e_tmp->e_private;
77 if ( e_tmp == NULL ) {
87 for ( ; e != NULL; ) {
88 mp = ( struct monitorentrypriv * )e->e_private;
90 monitor_entry_update( op, e );
92 rc = test_filter( op, e, op->oq_search.rs_filter );
93 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 struct monitorinfo *mi
122 = (struct monitorinfo *) op->o_bd->be_private;
123 int rc = LDAP_SUCCESS;
124 Entry *e, *matched = NULL;
127 LDAP_LOG( BACK_MON, ENTRY,
128 "monitor_back_search: enter\n", 0, 0, 0 );
130 Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", "");
134 /* get entry with reader lock */
135 monitor_cache_dn2entry( op, &op->o_req_ndn, &e, &matched );
137 rs->sr_err = LDAP_NO_SUCH_OBJECT;
139 rs->sr_matched = matched->e_dn;
142 send_ldap_result( op, rs );
144 monitor_cache_release( mi, matched );
145 rs->sr_matched = NULL;
151 rs->sr_attrs = op->oq_search.rs_attrs;
152 switch ( op->oq_search.rs_scope ) {
153 case LDAP_SCOPE_BASE:
154 monitor_entry_update( op, e );
155 rc = test_filter( op, e, op->oq_search.rs_filter );
156 if ( rc == LDAP_COMPARE_TRUE ) {
158 send_search_entry( op, rs );
162 monitor_cache_release( mi, e );
165 case LDAP_SCOPE_ONELEVEL:
166 rc = monitor_send_children( op, rs, e, 0 );
173 case LDAP_SCOPE_SUBTREE:
174 monitor_entry_update( op, e );
175 rc = test_filter( op, e, op->oq_search.rs_filter );
176 if ( rc == LDAP_COMPARE_TRUE ) {
178 send_search_entry( op, rs );
182 rc = monitor_send_children( op, rs, e, 1 );
192 send_ldap_result( op, rs );
194 return( rc == LDAP_SUCCESS ? 0 : 1 );