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;
128 LDAP_LOG( BACK_MON, ENTRY,
129 "monitor_back_search: enter\n", 0, 0, 0 );
131 Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", "");
135 /* get entry with reader lock */
136 monitor_cache_dn2entry( op, &op->o_req_ndn, &e, &matched );
138 rs->sr_err = LDAP_NO_SUCH_OBJECT;
140 rs->sr_matched = matched->e_dn;
143 send_ldap_result( op, rs );
145 monitor_cache_release( mi, matched );
146 rs->sr_matched = NULL;
152 rs->sr_attrs = op->oq_search.rs_attrs;
153 switch ( op->oq_search.rs_scope ) {
154 case LDAP_SCOPE_BASE:
155 monitor_entry_update( op, e );
156 rc = test_filter( op, e, op->oq_search.rs_filter );
157 if ( rc == LDAP_COMPARE_TRUE ) {
160 send_search_entry( op, rs );
164 monitor_cache_release( mi, e );
167 case LDAP_SCOPE_ONELEVEL:
168 rc = monitor_send_children( op, rs, e, 0 );
175 case LDAP_SCOPE_SUBTREE:
176 monitor_entry_update( op, e );
177 rc = test_filter( op, e, op->oq_search.rs_filter );
178 if ( rc == LDAP_COMPARE_TRUE ) {
181 send_search_entry( op, rs );
185 rc = monitor_send_children( op, rs, e, 1 );
195 send_ldap_result( op, rs );
197 return( rc == LDAP_SUCCESS ? 0 : 1 );