1 /* sent.c - deal with data sent subsystem */
3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
8 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
12 * This work has beed deveolped for the OpenLDAP Foundation
13 * in the hope that it may be useful to the Open Source community,
14 * but WITHOUT ANY WARRANTY.
16 * Permission is granted to anyone to use this software for any purpose
17 * on any computer system, and to alter it and redistribute it, subject
18 * to the following restrictions:
20 * 1. The author and SysNet s.n.c. are not responsible for the consequences
21 * of use of this software, no matter how awful, even if they arise from
24 * 2. The origin of this software must not be misrepresented, either by
25 * explicit claim or by omission. Since few users ever read sources,
26 * credits should appear in the documentation.
28 * 3. Altered versions must be plainly marked as such, and must not be
29 * misrepresented as being the original software. Since few users
30 * ever read sources, credits should appear in the documentation.
31 * SysNet s.n.c. cannot be responsible for the consequences of the
34 * 4. This notice may not be removed or altered.
42 #include "back-monitor.h"
45 monitor_subsys_sent_init(
49 struct monitorinfo *mi;
51 Entry *e, *e_tmp, *e_sent;
52 struct monitorentrypriv *mp;
54 struct berval val, *bv[2] = { &val, NULL };
58 mi = ( struct monitorinfo * )be->be_private;
60 if ( monitor_cache_get( mi,
61 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
63 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
64 "monitor_subsys_sent_init: "
65 "unable to get entry '%s'\n",
66 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
68 Debug( LDAP_DEBUG_ANY,
69 "monitor_subsys_sent_init: "
70 "unable to get entry '%s'\n%s%s",
71 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
82 snprintf( buf, sizeof( buf ),
85 "objectClass: LDAPsubEntry\n"
86 #ifdef SLAPD_MONITORSUBENTRY
87 "objectClass: monitorSubEntry\n"
88 #else /* !SLAPD_MONITORSUBENTRY */
89 "objectClass: extensibleObject\n"
90 #endif /* !SLAPD_MONITORSUBENTRY */
92 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn->bv_val );
97 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
98 "monitor_subsys_sent_init: "
99 "unable to create entry 'cn=Entries,%s'\n",
100 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
102 Debug( LDAP_DEBUG_ANY,
103 "monitor_subsys_sent_init: "
104 "unable to create entry 'cn=Entries,%s'\n%s%s",
105 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
113 attr_merge( e, monitor_ad_desc, bv );
115 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
116 e->e_private = ( void * )mp;
118 mp->mp_children = NULL;
119 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
120 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
121 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
123 if ( monitor_cache_add( mi, e ) ) {
125 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
126 "monitor_subsys_sent_init: "
127 "unable to add entry 'cn=Entries,%s'\n",
128 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
130 Debug( LDAP_DEBUG_ANY,
131 "monitor_subsys_sent_init: "
132 "unable to add entry 'cn=Entries,%s'\n%s%s",
133 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
144 snprintf( buf, sizeof( buf ),
145 "dn: cn=Referrals,%s\n"
147 "objectClass: LDAPsubEntry\n"
148 #ifdef SLAPD_MONITORSUBENTRY
149 "objectClass: monitorSubEntry\n"
150 #else /* !SLAPD_MONITORSUBENTRY */
151 "objectClass: extensibleObject\n"
152 #endif /* !SLAPD_MONITORSUBENTRY */
154 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn->bv_val );
156 e = str2entry( buf );
159 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
160 "monitor_subsys_sent_init: "
161 "unable to create entry 'cn=Referrals,%s'\n",
162 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
164 Debug( LDAP_DEBUG_ANY,
165 "monitor_subsys_sent_init: "
166 "unable to create entry 'cn=Referrals,%s'\n%s%s",
167 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
175 attr_merge( e, monitor_ad_desc, bv );
177 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
178 e->e_private = ( void * )mp;
180 mp->mp_children = NULL;
181 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
182 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
183 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
185 if ( monitor_cache_add( mi, e ) ) {
187 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
188 "monitor_subsys_sent_init: "
189 "unable to add entry 'cn=Referrals,%s'\n",
190 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
192 Debug( LDAP_DEBUG_ANY,
193 "monitor_subsys_sent_init: "
194 "unable to add entry 'cn=Referrals,%s'\n%s%s",
195 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
206 snprintf( buf, sizeof( buf ),
209 "objectClass: LDAPsubEntry\n"
210 #ifdef SLAPD_MONITORSUBENTRY
211 "objectClass: monitorSubEntry\n"
212 #else /* !SLAPD_MONITORSUBENTRY */
213 "objectClass: extensibleObject\n"
214 #endif /* !SLAPD_MONITORSUBENTRY */
216 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn->bv_val );
218 e = str2entry( buf );
221 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
222 "monitor_subsys_sent_init: "
223 "unable to create entry 'cn=PDU,%s'\n",
224 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
226 Debug( LDAP_DEBUG_ANY,
227 "monitor_subsys_sent_init: "
228 "unable to create entry 'cn=PDU,%s'\n%s%s",
229 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
237 attr_merge( e, monitor_ad_desc, bv );
239 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
240 e->e_private = ( void * )mp;
242 mp->mp_children = NULL;
243 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
244 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
245 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
247 if ( monitor_cache_add( mi, e ) ) {
249 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
250 "monitor_subsys_sent_init: "
251 "unable to add entry 'cn=PDU,%s'\n",
252 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
254 Debug( LDAP_DEBUG_ANY,
255 "monitor_subsys_sent_init: "
256 "unable to add entry 'cn=PDU,%s'\n%s%s",
257 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
268 snprintf( buf, sizeof( buf ),
271 "objectClass: LDAPsubEntry\n"
272 #ifdef SLAPD_MONITORSUBENTRY
273 "objectClass: monitorSubEntry\n"
274 #else /* !SLAPD_MONITORSUBENTRY */
275 "objectClass: extensibleObject\n"
276 #endif /* !SLAPD_MONITORSUBENTRY */
278 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn->bv_val );
280 e = str2entry( buf );
283 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
284 "monitor_subsys_sent_init: "
285 "unable to create entry 'cn=Bytes,%s'\n",
286 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
288 Debug( LDAP_DEBUG_ANY,
289 "monitor_subsys_sent_init: "
290 "unable to create entry 'cn=Bytes,%s'\n%s%s",
291 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
299 attr_merge( e, monitor_ad_desc, bv );
301 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
302 e->e_private = ( void * )mp;
304 mp->mp_children = NULL;
305 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
306 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
307 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
309 if ( monitor_cache_add( mi, e ) ) {
311 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
312 "monitor_subsys_sent_init: "
313 "unable to add entry 'cn=Bytes,%s'\n",
314 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val ));
316 Debug( LDAP_DEBUG_ANY,
317 "monitor_subsys_sent_init: "
318 "unable to add entry 'cn=Bytes,%s'\n%s%s",
319 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn->bv_val,
327 mp = ( struct monitorentrypriv * )e_sent->e_private;
328 mp->mp_children = e_tmp;
330 monitor_cache_release( mi, e_sent );
336 monitor_subsys_sent_update(
337 struct monitorinfo *mi,
346 if ( strncasecmp( e->e_ndn, "CN=ENTRIES",
347 sizeof("CN=ENTRIES")-1 ) == 0 ) {
348 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
349 n = num_entries_sent;
350 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
352 } else if ( strncasecmp( e->e_ndn, "CN=REFERRALS",
353 sizeof("CN=REFERRALS")-1 ) == 0 ) {
354 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
356 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
358 } else if ( strncasecmp( e->e_ndn, "CN=PDU",
359 sizeof("CN=PDU")-1 ) == 0 ) {
360 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
362 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
364 } else if ( strncasecmp( e->e_ndn, "CN=BYTES",
365 sizeof("CN=BYTES")-1 ) == 0 ) {
366 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
368 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
375 a = attr_find( e->e_attrs, monitor_ad_desc );
380 snprintf( buf, sizeof( buf ), "%ld", n );
381 ber_bvfree( a->a_vals[ 0 ] );
382 a->a_vals[ 0 ] = ber_bvstrdup( buf );