1 /* sent.c - deal with data sent subsystem */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
39 #include "back-monitor.h"
42 monitor_subsys_sent_init(
46 struct monitorinfo *mi;
48 Entry *e, *e_tmp, *e_sent;
49 struct monitorentrypriv *mp;
55 mi = ( struct monitorinfo * )be->be_private;
57 if ( monitor_cache_get( mi,
58 &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
60 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
61 "monitor_subsys_sent_init: "
62 "unable to get entry '%s'\n",
63 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
65 Debug( LDAP_DEBUG_ANY,
66 "monitor_subsys_sent_init: "
67 "unable to get entry '%s'\n%s%s",
68 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
79 snprintf( buf, sizeof( buf ),
82 "objectClass: LDAPsubEntry\n"
83 #ifdef SLAPD_MONITORSUBENTRY
84 "objectClass: monitorSubEntry\n"
85 #else /* !SLAPD_MONITORSUBENTRY */
86 "objectClass: extensibleObject\n"
87 #endif /* !SLAPD_MONITORSUBENTRY */
89 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
94 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
95 "monitor_subsys_sent_init: "
96 "unable to create entry 'cn=Entries,%s'\n",
97 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
99 Debug( LDAP_DEBUG_ANY,
100 "monitor_subsys_sent_init: "
101 "unable to create entry 'cn=Entries,%s'\n%s%s",
102 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
111 attr_merge( e, monitor_ad_desc, bv );
113 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
114 e->e_private = ( void * )mp;
116 mp->mp_children = NULL;
117 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
118 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
119 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
121 if ( monitor_cache_add( mi, e ) ) {
123 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
124 "monitor_subsys_sent_init: "
125 "unable to add entry 'cn=Entries,%s'\n",
126 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
128 Debug( LDAP_DEBUG_ANY,
129 "monitor_subsys_sent_init: "
130 "unable to add entry 'cn=Entries,%s'\n%s%s",
131 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
142 snprintf( buf, sizeof( buf ),
143 "dn: cn=Referrals,%s\n"
145 "objectClass: LDAPsubEntry\n"
146 #ifdef SLAPD_MONITORSUBENTRY
147 "objectClass: monitorSubEntry\n"
148 #else /* !SLAPD_MONITORSUBENTRY */
149 "objectClass: extensibleObject\n"
150 #endif /* !SLAPD_MONITORSUBENTRY */
152 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
154 e = str2entry( buf );
157 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
158 "monitor_subsys_sent_init: "
159 "unable to create entry 'cn=Referrals,%s'\n",
160 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
162 Debug( LDAP_DEBUG_ANY,
163 "monitor_subsys_sent_init: "
164 "unable to create entry 'cn=Referrals,%s'\n%s%s",
165 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
173 attr_merge( e, monitor_ad_desc, bv );
175 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
176 e->e_private = ( void * )mp;
178 mp->mp_children = NULL;
179 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
180 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
181 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
183 if ( monitor_cache_add( mi, e ) ) {
185 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
186 "monitor_subsys_sent_init: "
187 "unable to add entry 'cn=Referrals,%s'\n",
188 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
190 Debug( LDAP_DEBUG_ANY,
191 "monitor_subsys_sent_init: "
192 "unable to add entry 'cn=Referrals,%s'\n%s%s",
193 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
204 snprintf( buf, sizeof( buf ),
207 "objectClass: LDAPsubEntry\n"
208 #ifdef SLAPD_MONITORSUBENTRY
209 "objectClass: monitorSubEntry\n"
210 #else /* !SLAPD_MONITORSUBENTRY */
211 "objectClass: extensibleObject\n"
212 #endif /* !SLAPD_MONITORSUBENTRY */
214 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
216 e = str2entry( buf );
219 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
220 "monitor_subsys_sent_init: "
221 "unable to create entry 'cn=PDU,%s'\n",
222 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
224 Debug( LDAP_DEBUG_ANY,
225 "monitor_subsys_sent_init: "
226 "unable to create entry 'cn=PDU,%s'\n%s%s",
227 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
235 attr_merge( e, monitor_ad_desc, bv );
237 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
238 e->e_private = ( void * )mp;
240 mp->mp_children = NULL;
241 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
242 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
243 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
245 if ( monitor_cache_add( mi, e ) ) {
247 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
248 "monitor_subsys_sent_init: "
249 "unable to add entry 'cn=PDU,%s'\n",
250 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
252 Debug( LDAP_DEBUG_ANY,
253 "monitor_subsys_sent_init: "
254 "unable to add entry 'cn=PDU,%s'\n%s%s",
255 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
266 snprintf( buf, sizeof( buf ),
269 "objectClass: LDAPsubEntry\n"
270 #ifdef SLAPD_MONITORSUBENTRY
271 "objectClass: monitorSubEntry\n"
272 #else /* !SLAPD_MONITORSUBENTRY */
273 "objectClass: extensibleObject\n"
274 #endif /* !SLAPD_MONITORSUBENTRY */
276 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
278 e = str2entry( buf );
281 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
282 "monitor_subsys_sent_init: "
283 "unable to create entry 'cn=Bytes,%s'\n",
284 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
286 Debug( LDAP_DEBUG_ANY,
287 "monitor_subsys_sent_init: "
288 "unable to create entry 'cn=Bytes,%s'\n%s%s",
289 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
297 attr_merge( e, monitor_ad_desc, bv );
299 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
300 e->e_private = ( void * )mp;
302 mp->mp_children = NULL;
303 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
304 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
305 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
307 if ( monitor_cache_add( mi, e ) ) {
309 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
310 "monitor_subsys_sent_init: "
311 "unable to add entry 'cn=Bytes,%s'\n",
312 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val ));
314 Debug( LDAP_DEBUG_ANY,
315 "monitor_subsys_sent_init: "
316 "unable to add entry 'cn=Bytes,%s'\n%s%s",
317 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
325 mp = ( struct monitorentrypriv * )e_sent->e_private;
326 mp->mp_children = e_tmp;
328 monitor_cache_release( mi, e_sent );
334 monitor_subsys_sent_update(
335 struct monitorinfo *mi,
344 if ( strncasecmp( e->e_ndn, "CN=ENTRIES",
345 sizeof("CN=ENTRIES")-1 ) == 0 ) {
346 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
347 n = num_entries_sent;
348 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
350 } else if ( strncasecmp( e->e_ndn, "CN=REFERRALS",
351 sizeof("CN=REFERRALS")-1 ) == 0 ) {
352 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
354 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
356 } else if ( strncasecmp( e->e_ndn, "CN=PDU",
357 sizeof("CN=PDU")-1 ) == 0 ) {
358 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
360 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
362 } else if ( strncasecmp( e->e_ndn, "CN=BYTES",
363 sizeof("CN=BYTES")-1 ) == 0 ) {
364 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
366 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
373 a = attr_find( e->e_attrs, monitor_ad_desc );
378 snprintf( buf, sizeof( buf ), "%ld", n );
379 free( a->a_vals[ 0 ].bv_val );
380 ber_str2bv( buf, 0, 1, a->a_vals );