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 ) {
96 send_search_entry( op, rs );
100 if ( ( mp->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
102 rc = monitor_send_children( op, rs, e, sub );
109 if ( e_tmp != NULL ) {
110 monitor_cache_lock( e_tmp );
112 monitor_cache_release( mi, e );
120 monitor_back_search( Operation *op, SlapReply *rs )
122 struct monitorinfo *mi
123 = (struct monitorinfo *) op->o_bd->be_private;
124 int rc = LDAP_SUCCESS;
125 Entry *e, *matched = NULL;
127 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
130 /* get entry with reader lock */
131 monitor_cache_dn2entry( op, &op->o_req_ndn, &e, &matched );
133 rs->sr_err = LDAP_NO_SUCH_OBJECT;
135 rs->sr_matched = matched->e_dn;
138 send_ldap_result( op, rs );
140 monitor_cache_release( mi, matched );
141 rs->sr_matched = NULL;
147 rs->sr_attrs = op->oq_search.rs_attrs;
148 switch ( op->oq_search.rs_scope ) {
149 case LDAP_SCOPE_BASE:
150 monitor_entry_update( op, e );
151 rc = test_filter( op, e, op->oq_search.rs_filter );
152 if ( rc == LDAP_COMPARE_TRUE ) {
155 send_search_entry( op, rs );
159 monitor_cache_release( mi, e );
162 case LDAP_SCOPE_ONELEVEL:
163 rc = monitor_send_children( op, rs, e, 0 );
170 case LDAP_SCOPE_SUBTREE:
171 monitor_entry_update( op, e );
172 rc = test_filter( op, e, op->oq_search.rs_filter );
173 if ( rc == LDAP_COMPARE_TRUE ) {
176 send_search_entry( op, rs );
180 rc = monitor_send_children( op, rs, e, 1 );
190 send_ldap_result( op, rs );
192 return( rc == LDAP_SUCCESS ? 0 : 1 );