]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/entry.c
import fix for entry modification via callback from HEAD
[openldap] / servers / slapd / back-monitor / entry.c
1 /* entry.c - monitor backend entry handling routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2006 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <slap.h>
25 #include "back-monitor.h"
26
27 int
28 monitor_entry_update(
29         Operation               *op,
30         SlapReply               *rs,
31         Entry                   *e
32 )
33 {
34         monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
35         monitor_entry_t *mp;
36
37         int             rc = SLAP_CB_CONTINUE;
38
39         assert( mi != NULL );
40         assert( e != NULL );
41         assert( e->e_private != NULL );
42
43         mp = ( monitor_entry_t * )e->e_private;
44
45         if ( mp->mp_cb ) {
46                 struct monitor_callback_t       *mc;
47
48                 for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
49                         if ( mc->mc_update ) {
50                                 rc = mc->mc_update( op, rs, e, mc->mc_private );
51                                 if ( rc != SLAP_CB_CONTINUE ) {
52                                         break;
53                                 }
54                         }
55                 }
56         }
57
58         if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_update ) {
59                 rc = mp->mp_info->mss_update( op, rs, e );
60         }
61
62         if ( rc == SLAP_CB_CONTINUE ) {
63                 rc = LDAP_SUCCESS;
64         }
65
66         return rc;
67 }
68
69 int
70 monitor_entry_create(
71         Operation               *op,
72         SlapReply               *rs,
73         struct berval           *ndn,
74         Entry                   *e_parent,
75         Entry                   **ep )
76 {
77         monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
78         monitor_entry_t *mp;
79
80         int             rc = SLAP_CB_CONTINUE;
81
82         assert( mi != NULL );
83         assert( e_parent != NULL );
84         assert( e_parent->e_private != NULL );
85         assert( ep != NULL );
86
87         mp = ( monitor_entry_t * )e_parent->e_private;
88
89         if ( mp->mp_info && mp->mp_info->mss_create ) {
90                 rc = mp->mp_info->mss_create( op, rs, ndn, e_parent, ep );
91         }
92
93         if ( rc == SLAP_CB_CONTINUE ) {
94                 rc = LDAP_SUCCESS;
95         }
96         
97         return rc;
98 }
99
100 int
101 monitor_entry_modify(
102         Operation               *op,
103         SlapReply               *rs,
104         Entry                   *e
105 )
106 {
107         monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
108         monitor_entry_t *mp;
109
110         int             rc = SLAP_CB_CONTINUE;
111
112         assert( mi != NULL );
113         assert( e != NULL );
114         assert( e->e_private != NULL );
115
116         mp = ( monitor_entry_t * )e->e_private;
117
118         if ( mp->mp_cb ) {
119                 struct monitor_callback_t       *mc;
120
121                 for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
122                         if ( mc->mc_modify ) {
123                                 rc = mc->mc_modify( op, rs, e, mc->mc_private );
124                                 if ( rc != SLAP_CB_CONTINUE ) {
125                                         break;
126                                 }
127                         }
128                 }
129         }
130
131         if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_modify ) {
132                 rc = mp->mp_info->mss_modify( op, rs, e );
133         }
134
135         if ( rc == SLAP_CB_CONTINUE ) {
136                 rc = LDAP_SUCCESS;
137         }
138
139         return rc;
140 }
141
142 int
143 monitor_entry_test_flags(
144         monitor_entry_t         *mp,
145         int                     cond
146 )
147 {
148         assert( mp != NULL );
149
150         return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) );
151 }
152
153 monitor_entry_t *
154 monitor_entrypriv_create( void )
155 {
156         monitor_entry_t *mp;
157
158         mp = ( monitor_entry_t * )ch_calloc( sizeof( monitor_entry_t ), 1 );
159
160         mp->mp_next = NULL;
161         mp->mp_children = NULL;
162         mp->mp_info = NULL;
163         mp->mp_flags = MONITOR_F_NONE;
164         mp->mp_cb = NULL;
165
166         ldap_pvt_thread_mutex_init( &mp->mp_mutex );
167
168         return mp;
169 }