Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-monitor / entry.c
blobd09ad85e4b39a97ae129342be1b21014467cdabb
1 /* entry.c - monitor backend entry handling routines */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-monitor/entry.c,v 1.21.2.5 2008/02/11 23:26:47 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2008 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
7 * All rights reserved.
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.
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>.
17 /* ACKNOWLEDGEMENTS:
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
22 #include "portable.h"
24 #include <slap.h>
25 #include "back-monitor.h"
27 int
28 monitor_entry_update(
29 Operation *op,
30 SlapReply *rs,
31 Entry *e
34 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
35 monitor_entry_t *mp;
37 int rc = SLAP_CB_CONTINUE;
39 assert( mi != NULL );
40 assert( e != NULL );
41 assert( e->e_private != NULL );
43 mp = ( monitor_entry_t * )e->e_private;
45 if ( mp->mp_cb ) {
46 struct monitor_callback_t *mc;
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;
58 if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_update ) {
59 rc = mp->mp_info->mss_update( op, rs, e );
62 if ( rc == SLAP_CB_CONTINUE ) {
63 rc = LDAP_SUCCESS;
66 return rc;
69 int
70 monitor_entry_create(
71 Operation *op,
72 SlapReply *rs,
73 struct berval *ndn,
74 Entry *e_parent,
75 Entry **ep )
77 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
78 monitor_entry_t *mp;
80 int rc = SLAP_CB_CONTINUE;
82 assert( mi != NULL );
83 assert( e_parent != NULL );
84 assert( e_parent->e_private != NULL );
85 assert( ep != NULL );
87 mp = ( monitor_entry_t * )e_parent->e_private;
89 if ( mp->mp_info && mp->mp_info->mss_create ) {
90 rc = mp->mp_info->mss_create( op, rs, ndn, e_parent, ep );
93 if ( rc == SLAP_CB_CONTINUE ) {
94 rc = LDAP_SUCCESS;
97 return rc;
101 monitor_entry_modify(
102 Operation *op,
103 SlapReply *rs,
104 Entry *e
107 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
108 monitor_entry_t *mp;
110 int rc = SLAP_CB_CONTINUE;
112 assert( mi != NULL );
113 assert( e != NULL );
114 assert( e->e_private != NULL );
116 mp = ( monitor_entry_t * )e->e_private;
118 if ( mp->mp_cb ) {
119 struct monitor_callback_t *mc;
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;
131 if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_modify ) {
132 rc = mp->mp_info->mss_modify( op, rs, e );
135 if ( rc == SLAP_CB_CONTINUE ) {
136 rc = LDAP_SUCCESS;
139 return rc;
143 monitor_entry_test_flags(
144 monitor_entry_t *mp,
145 int cond
148 assert( mp != NULL );
150 return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) );
153 monitor_entry_t *
154 monitor_entrypriv_create( void )
156 monitor_entry_t *mp;
158 mp = ( monitor_entry_t * )ch_calloc( sizeof( monitor_entry_t ), 1 );
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;
166 ldap_pvt_thread_mutex_init( &mp->mp_mutex );
168 return mp;
171 Entry *
172 monitor_entry_stub(
173 struct berval *pdn,
174 struct berval *pndn,
175 struct berval *rdn,
176 ObjectClass *oc,
177 monitor_info_t *mi,
178 struct berval *create,
179 struct berval *modify
182 AttributeDescription *nad = NULL;
183 Entry *e;
184 struct berval nat;
185 char *ptr;
186 const char *text;
187 int rc;
189 nat = *rdn;
190 ptr = strchr( nat.bv_val, '=' );
191 nat.bv_len = ptr - nat.bv_val;
192 rc = slap_bv2ad( &nat, &nad, &text );
193 if ( rc )
194 return NULL;
196 e = entry_alloc();
197 if ( e ) {
198 struct berval nrdn;
200 rdnNormalize( 0, NULL, NULL, rdn, &nrdn, NULL );
201 build_new_dn( &e->e_name, pdn, rdn, NULL );
202 build_new_dn( &e->e_nname, pndn, &nrdn, NULL );
203 ber_memfree( nrdn.bv_val );
204 nat.bv_val = ptr + 1;
205 nat.bv_len = rdn->bv_len - ( nat.bv_val - rdn->bv_val );
206 attr_merge_normalize_one( e, slap_schema.si_ad_objectClass,
207 &oc->soc_cname, NULL );
208 attr_merge_normalize_one( e, slap_schema.si_ad_structuralObjectClass,
209 &oc->soc_cname, NULL );
210 attr_merge_normalize_one( e, nad, &nat, NULL );
211 attr_merge_one( e, slap_schema.si_ad_creatorsName, &mi->mi_creatorsName,
212 &mi->mi_ncreatorsName );
213 attr_merge_one( e, slap_schema.si_ad_modifiersName, &mi->mi_creatorsName,
214 &mi->mi_ncreatorsName );
215 attr_merge_normalize_one( e, slap_schema.si_ad_createTimestamp,
216 create ? create : &mi->mi_startTime, NULL );
217 attr_merge_normalize_one( e, slap_schema.si_ad_modifyTimestamp,
218 modify ? modify : &mi->mi_startTime, NULL );
220 return e;