1 /* sent.c - deal with data sent subsystem */
3 * Copyright 1998-2003 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.
37 #include <ac/string.h>
40 #include "back-monitor.h"
43 monitor_subsys_sent_init(
47 struct monitorinfo *mi;
49 Entry *e, *e_tmp, *e_sent;
50 struct monitorentrypriv *mp;
51 char buf[ BACKMONITOR_BUFSIZE ];
56 mi = ( struct monitorinfo * )be->be_private;
58 if ( monitor_cache_get( mi,
59 &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
61 LDAP_LOG( OPERATION, CRIT,
62 "monitor_subsys_sent_init: "
63 "unable to get entry '%s'\n",
64 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
66 Debug( LDAP_DEBUG_ANY,
67 "monitor_subsys_sent_init: "
68 "unable to get entry '%s'\n%s%s",
69 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
80 snprintf( buf, sizeof( buf ),
83 "structuralObjectClass: %s\n"
85 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
86 mi->oc_monitorCounterObject->soc_cname.bv_val,
87 mi->oc_monitorCounterObject->soc_cname.bv_val );
92 LDAP_LOG( OPERATION, CRIT,
93 "monitor_subsys_sent_init: "
94 "unable to create entry 'cn=Entries,%s'\n",
95 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
97 Debug( LDAP_DEBUG_ANY,
98 "monitor_subsys_sent_init: "
99 "unable to create entry 'cn=Entries,%s'\n%s%s",
100 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
108 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
110 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
111 e->e_private = ( void * )mp;
113 mp->mp_children = NULL;
114 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
115 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
116 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
118 if ( monitor_cache_add( mi, e ) ) {
120 LDAP_LOG( OPERATION, CRIT,
121 "monitor_subsys_sent_init: "
122 "unable to add entry 'cn=Entries,%s'\n",
123 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
125 Debug( LDAP_DEBUG_ANY,
126 "monitor_subsys_sent_init: "
127 "unable to add entry 'cn=Entries,%s'\n%s%s",
128 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
139 snprintf( buf, sizeof( buf ),
140 "dn: cn=Referrals,%s\n"
142 "structuralObjectClass: %s\n"
144 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
145 mi->oc_monitorCounterObject->soc_cname.bv_val,
146 mi->oc_monitorCounterObject->soc_cname.bv_val );
148 e = str2entry( buf );
151 LDAP_LOG( OPERATION, CRIT,
152 "monitor_subsys_sent_init: "
153 "unable to create entry 'cn=Referrals,%s'\n",
154 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
156 Debug( LDAP_DEBUG_ANY,
157 "monitor_subsys_sent_init: "
158 "unable to create entry 'cn=Referrals,%s'\n%s%s",
159 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
167 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
169 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
170 e->e_private = ( void * )mp;
172 mp->mp_children = NULL;
173 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
174 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
175 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
177 if ( monitor_cache_add( mi, e ) ) {
179 LDAP_LOG( OPERATION, CRIT,
180 "monitor_subsys_sent_init: "
181 "unable to add entry 'cn=Referrals,%s'\n",
182 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
184 Debug( LDAP_DEBUG_ANY,
185 "monitor_subsys_sent_init: "
186 "unable to add entry 'cn=Referrals,%s'\n%s%s",
187 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
198 snprintf( buf, sizeof( buf ),
201 "structuralObjectClass: %s\n"
203 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
204 mi->oc_monitorCounterObject->soc_cname.bv_val,
205 mi->oc_monitorCounterObject->soc_cname.bv_val );
207 e = str2entry( buf );
210 LDAP_LOG( OPERATION, CRIT,
211 "monitor_subsys_sent_init: "
212 "unable to create entry 'cn=PDU,%s'\n",
213 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
215 Debug( LDAP_DEBUG_ANY,
216 "monitor_subsys_sent_init: "
217 "unable to create entry 'cn=PDU,%s'\n%s%s",
218 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
226 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
228 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
229 e->e_private = ( void * )mp;
231 mp->mp_children = NULL;
232 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
233 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
234 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
236 if ( monitor_cache_add( mi, e ) ) {
238 LDAP_LOG( OPERATION, CRIT,
239 "monitor_subsys_sent_init: "
240 "unable to add entry 'cn=PDU,%s'\n",
241 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
243 Debug( LDAP_DEBUG_ANY,
244 "monitor_subsys_sent_init: "
245 "unable to add entry 'cn=PDU,%s'\n%s%s",
246 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
257 snprintf( buf, sizeof( buf ),
260 "structuralObjectClass: %s\n"
262 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
263 mi->oc_monitorCounterObject->soc_cname.bv_val,
264 mi->oc_monitorCounterObject->soc_cname.bv_val );
266 e = str2entry( buf );
269 LDAP_LOG( OPERATION, CRIT,
270 "monitor_subsys_sent_init: "
271 "unable to create entry 'cn=Bytes,%s'\n",
272 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
274 Debug( LDAP_DEBUG_ANY,
275 "monitor_subsys_sent_init: "
276 "unable to create entry 'cn=Bytes,%s'\n%s%s",
277 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
285 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
287 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
288 e->e_private = ( void * )mp;
290 mp->mp_children = NULL;
291 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
292 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
293 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
295 if ( monitor_cache_add( mi, e ) ) {
297 LDAP_LOG( OPERATION, CRIT,
298 "monitor_subsys_sent_init: "
299 "unable to add entry 'cn=Bytes,%s'\n",
300 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
302 Debug( LDAP_DEBUG_ANY,
303 "monitor_subsys_sent_init: "
304 "unable to add entry 'cn=Bytes,%s'\n%s%s",
305 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
313 mp = ( struct monitorentrypriv * )e_sent->e_private;
314 mp->mp_children = e_tmp;
316 monitor_cache_release( mi, e_sent );
322 monitor_subsys_sent_update(
327 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
333 if ( strncasecmp( e->e_ndn, "cn=entries",
334 sizeof("cn=entries")-1 ) == 0 ) {
335 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
336 n = num_entries_sent;
337 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
339 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
340 sizeof("cn=referrals")-1 ) == 0 ) {
341 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
343 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
345 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
346 sizeof("cn=pdu")-1 ) == 0 ) {
347 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
349 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
351 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
352 sizeof("cn=bytes")-1 ) == 0 ) {
353 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
355 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
360 char buf[] = "+9223372036854775807L";
362 a = attr_find( e->e_attrs, mi->ad_monitorCounter);
367 snprintf( buf, sizeof( buf ), "%ld", n );
368 free( a->a_vals[ 0 ].bv_val );
369 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );