1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
20 /* This is an altered version */
22 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
24 * This work has beed deveolped for the OpenLDAP Foundation
25 * in the hope that it may be useful to the Open Source community,
26 * but WITHOUT ANY WARRANTY.
28 * Permission is granted to anyone to use this software for any purpose
29 * on any computer system, and to alter it and redistribute it, subject
30 * to the following restrictions:
32 * 1. The author and SysNet s.n.c. are not responsible for the consequences
33 * of use of this software, no matter how awful, even if they arise from
36 * 2. The origin of this software must not be misrepresented, either by
37 * explicit claim or by omission. Since few users ever read sources,
38 * credits should appear in the documentation.
40 * 3. Altered versions must be plainly marked as such, and must not be
41 * misrepresented as being the original software. Since few users
42 * ever read sources, credits should appear in the documentation.
43 * SysNet s.n.c. cannot be responsible for the consequences of the
46 * 4. This notice may not be removed or altered.
53 #include <ac/string.h>
54 #include <ac/socket.h>
57 #include "back-monitor.h"
58 #include "proto-back-monitor.h"
61 monitor_send_children(
68 struct monitorinfo *mi =
69 (struct monitorinfo *) op->o_bd->be_private;
70 Entry *e, *e_tmp, *e_ch;
71 struct monitorentrypriv *mp;
74 mp = ( struct monitorentrypriv * )e_parent->e_private;
78 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
79 monitor_entry_create( op, NULL, e_parent, &e_ch );
81 monitor_cache_release( mi, e_parent );
83 /* no volatile entries? */
85 /* no persistent entries? return */
90 /* volatile entries */
92 /* if no persistent, return only volatile */
95 monitor_cache_lock( e_ch );
97 /* else append persistent to volatile */
101 mp = ( struct monitorentrypriv * )e_tmp->e_private;
104 if ( e_tmp == NULL ) {
114 for ( ; e != NULL; ) {
115 mp = ( struct monitorentrypriv * )e->e_private;
117 monitor_entry_update( op, e );
119 rc = test_filter( op, e, op->oq_search.rs_filter );
120 if ( rc == LDAP_COMPARE_TRUE ) {
122 send_search_entry( op, rs );
126 if ( ( mp->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
128 rc = monitor_send_children( op, rs, e, sub );
135 if ( e_tmp != NULL ) {
136 monitor_cache_lock( e_tmp );
138 monitor_cache_release( mi, e );
146 monitor_back_search( Operation *op, SlapReply *rs )
148 struct monitorinfo *mi
149 = (struct monitorinfo *) op->o_bd->be_private;
150 int rc = LDAP_SUCCESS;
151 Entry *e, *matched = NULL;
154 LDAP_LOG( BACK_MON, ENTRY,
155 "monitor_back_search: enter\n", 0, 0, 0 );
157 Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", "");
161 /* get entry with reader lock */
162 monitor_cache_dn2entry( op, &op->o_req_ndn, &e, &matched );
164 rs->sr_err = LDAP_NO_SUCH_OBJECT;
166 rs->sr_matched = matched->e_dn;
169 send_ldap_result( op, rs );
171 monitor_cache_release( mi, matched );
172 rs->sr_matched = NULL;
178 rs->sr_attrs = op->oq_search.rs_attrs;
179 switch ( op->oq_search.rs_scope ) {
180 case LDAP_SCOPE_BASE:
181 monitor_entry_update( op, e );
182 rc = test_filter( op, e, op->oq_search.rs_filter );
183 if ( rc == LDAP_COMPARE_TRUE ) {
185 send_search_entry( op, rs );
189 monitor_cache_release( mi, e );
192 case LDAP_SCOPE_ONELEVEL:
193 rc = monitor_send_children( op, rs, e, 0 );
200 case LDAP_SCOPE_SUBTREE:
201 monitor_entry_update( op, e );
202 rc = test_filter( op, e, op->oq_search.rs_filter );
203 if ( rc == LDAP_COMPARE_TRUE ) {
205 send_search_entry( op, rs );
209 rc = monitor_send_children( op, rs, e, 1 );
219 send_ldap_result( op, rs );
221 return( rc == LDAP_SUCCESS ? 0 : 1 );