entry.c 3.33 KB
Newer Older
1
/* entry.c - monitor backend entry handling routines */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
3
4
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
 * Copyright 2001-2006 The OpenLDAP Foundation.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
 * Portions Copyright 2001-2003 Pierangelo Masarati.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* ACKNOWLEDGEMENTS:
 * This work was initially developed by Pierangelo Masarati for inclusion
 * in OpenLDAP Software.
 */
21
22
23
24
25
26
27
28

#include "portable.h"

#include <slap.h>
#include "back-monitor.h"

int
monitor_entry_update(
29
	Operation		*op,
30
	SlapReply		*rs,
31
32
33
	Entry 			*e
)
{
34
35
	monitor_info_t	*mi = ( monitor_info_t * )op->o_bd->be_private;
	monitor_entry_t *mp;
36
37

	int		rc = SLAP_CB_CONTINUE;
38
39
40
41
42

	assert( mi != NULL );
	assert( e != NULL );
	assert( e->e_private != NULL );

43
	mp = ( monitor_entry_t * )e->e_private;
44

45
	if ( mp->mp_cb ) {
46
47
48
		struct monitor_callback_t	*mc;

		for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
49
50
51
52
53
			if ( mc->mc_update ) {
				rc = mc->mc_update( op, rs, e, mc->mc_private );
				if ( rc != SLAP_CB_CONTINUE ) {
					break;
				}
54
55
			}
		}
56
57
	}

58
59
60
61
	if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_update ) {
		rc = mp->mp_info->mss_update( op, rs, e );
	}

62
63
64
65
	if ( rc == SLAP_CB_CONTINUE ) {
		rc = LDAP_SUCCESS;
	}

66
	return rc;
67
68
69
70
}

int
monitor_entry_create(
71
	Operation		*op,
72
	SlapReply		*rs,
73
	struct berval		*ndn,
74
	Entry			*e_parent,
75
	Entry			**ep )
76
{
77
78
	monitor_info_t	*mi = ( monitor_info_t * )op->o_bd->be_private;
	monitor_entry_t *mp;
79

80
81
	int		rc = SLAP_CB_CONTINUE;

82
83
84
85
86
	assert( mi != NULL );
	assert( e_parent != NULL );
	assert( e_parent->e_private != NULL );
	assert( ep != NULL );

87
	mp = ( monitor_entry_t * )e_parent->e_private;
88
89

	if ( mp->mp_info && mp->mp_info->mss_create ) {
90
91
92
93
94
		rc = mp->mp_info->mss_create( op, rs, ndn, e_parent, ep );
	}

	if ( rc == SLAP_CB_CONTINUE ) {
		rc = LDAP_SUCCESS;
95
96
	}
	
97
	return rc;
98
99
}

100
101
int
monitor_entry_modify(
102
	Operation		*op,
103
	SlapReply		*rs,
104
	Entry 			*e
105
106
)
{
107
108
	monitor_info_t	*mi = ( monitor_info_t * )op->o_bd->be_private;
	monitor_entry_t *mp;
109

110
111
	int		rc = SLAP_CB_CONTINUE;

112
113
114
115
	assert( mi != NULL );
	assert( e != NULL );
	assert( e->e_private != NULL );

116
	mp = ( monitor_entry_t * )e->e_private;
117

118
	if ( mp->mp_cb ) {
119
120
121
122
123
124
125
126
127
128
129
130
		struct monitor_callback_t	*mc;

		for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
			if ( mc->mc_modify ) {
				rc = mc->mc_modify( op, rs, e, mc->mc_private );
				if ( rc != SLAP_CB_CONTINUE ) {
					break;
				}
			}
		}
	}

131
132
133
134
	if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_modify ) {
		rc = mp->mp_info->mss_modify( op, rs, e );
	}

135
136
137
138
139
	if ( rc == SLAP_CB_CONTINUE ) {
		rc = LDAP_SUCCESS;
	}

	return rc;
140
141
}

142
143
int
monitor_entry_test_flags(
144
	monitor_entry_t		*mp,
145
146
147
148
149
150
151
152
	int			cond
)
{
	assert( mp != NULL );

	return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) );
}

153
monitor_entry_t *
154
155
monitor_entrypriv_create( void )
{
156
	monitor_entry_t	*mp;
157

158
	mp = ( monitor_entry_t * )ch_calloc( sizeof( monitor_entry_t ), 1 );
159
160
161
162
163

	mp->mp_next = NULL;
	mp->mp_children = NULL;
	mp->mp_info = NULL;
	mp->mp_flags = MONITOR_F_NONE;
164
	mp->mp_cb = NULL;
165

Kurt Zeilenga's avatar
Kurt Zeilenga committed
166
167
	ldap_pvt_thread_mutex_init( &mp->mp_mutex );

168
169
	return mp;
}