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.
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;
50 char buf[ BACKMONITOR_BUFSIZE ];
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, CRIT,
61 "monitor_subsys_sent_init: "
62 "unable to get entry '%s'\n",
63 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
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 "structuralObjectClass: %s\n"
84 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
85 mi->oc_monitorCounterObject->soc_cname.bv_val,
86 mi->oc_monitorCounterObject->soc_cname.bv_val );
91 LDAP_LOG( OPERATION, CRIT,
92 "monitor_subsys_sent_init: "
93 "unable to create entry 'cn=Entries,%s'\n",
94 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
96 Debug( LDAP_DEBUG_ANY,
97 "monitor_subsys_sent_init: "
98 "unable to create entry 'cn=Entries,%s'\n%s%s",
99 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
107 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
109 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
110 e->e_private = ( void * )mp;
112 mp->mp_children = NULL;
113 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
114 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
115 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
117 if ( monitor_cache_add( mi, e ) ) {
119 LDAP_LOG( OPERATION, CRIT,
120 "monitor_subsys_sent_init: "
121 "unable to add entry 'cn=Entries,%s'\n",
122 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
124 Debug( LDAP_DEBUG_ANY,
125 "monitor_subsys_sent_init: "
126 "unable to add entry 'cn=Entries,%s'\n%s%s",
127 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
138 snprintf( buf, sizeof( buf ),
139 "dn: cn=Referrals,%s\n"
141 "structuralObjectClass: %s\n"
143 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
144 mi->oc_monitorCounterObject->soc_cname.bv_val,
145 mi->oc_monitorCounterObject->soc_cname.bv_val );
147 e = str2entry( buf );
150 LDAP_LOG( OPERATION, CRIT,
151 "monitor_subsys_sent_init: "
152 "unable to create entry 'cn=Referrals,%s'\n",
153 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
155 Debug( LDAP_DEBUG_ANY,
156 "monitor_subsys_sent_init: "
157 "unable to create entry 'cn=Referrals,%s'\n%s%s",
158 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
166 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
168 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
169 e->e_private = ( void * )mp;
171 mp->mp_children = NULL;
172 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
173 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
174 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
176 if ( monitor_cache_add( mi, e ) ) {
178 LDAP_LOG( OPERATION, CRIT,
179 "monitor_subsys_sent_init: "
180 "unable to add entry 'cn=Referrals,%s'\n",
181 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
183 Debug( LDAP_DEBUG_ANY,
184 "monitor_subsys_sent_init: "
185 "unable to add entry 'cn=Referrals,%s'\n%s%s",
186 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
197 snprintf( buf, sizeof( buf ),
200 "structuralObjectClass: %s\n"
202 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
203 mi->oc_monitorCounterObject->soc_cname.bv_val,
204 mi->oc_monitorCounterObject->soc_cname.bv_val );
206 e = str2entry( buf );
209 LDAP_LOG( OPERATION, CRIT,
210 "monitor_subsys_sent_init: "
211 "unable to create entry 'cn=PDU,%s'\n",
212 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
214 Debug( LDAP_DEBUG_ANY,
215 "monitor_subsys_sent_init: "
216 "unable to create entry 'cn=PDU,%s'\n%s%s",
217 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
225 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
227 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
228 e->e_private = ( void * )mp;
230 mp->mp_children = NULL;
231 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
232 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
233 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
235 if ( monitor_cache_add( mi, e ) ) {
237 LDAP_LOG( OPERATION, CRIT,
238 "monitor_subsys_sent_init: "
239 "unable to add entry 'cn=PDU,%s'\n",
240 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
242 Debug( LDAP_DEBUG_ANY,
243 "monitor_subsys_sent_init: "
244 "unable to add entry 'cn=PDU,%s'\n%s%s",
245 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
256 snprintf( buf, sizeof( buf ),
259 "structuralObjectClass: %s\n"
261 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
262 mi->oc_monitorCounterObject->soc_cname.bv_val,
263 mi->oc_monitorCounterObject->soc_cname.bv_val );
265 e = str2entry( buf );
268 LDAP_LOG( OPERATION, CRIT,
269 "monitor_subsys_sent_init: "
270 "unable to create entry 'cn=Bytes,%s'\n",
271 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
273 Debug( LDAP_DEBUG_ANY,
274 "monitor_subsys_sent_init: "
275 "unable to create entry 'cn=Bytes,%s'\n%s%s",
276 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
284 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
286 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
287 e->e_private = ( void * )mp;
289 mp->mp_children = NULL;
290 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
291 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
292 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
294 if ( monitor_cache_add( mi, e ) ) {
296 LDAP_LOG( OPERATION, CRIT,
297 "monitor_subsys_sent_init: "
298 "unable to add entry 'cn=Bytes,%s'\n",
299 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
301 Debug( LDAP_DEBUG_ANY,
302 "monitor_subsys_sent_init: "
303 "unable to add entry 'cn=Bytes,%s'\n%s%s",
304 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
312 mp = ( struct monitorentrypriv * )e_sent->e_private;
313 mp->mp_children = e_tmp;
315 monitor_cache_release( mi, e_sent );
321 monitor_subsys_sent_update(
326 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
332 if ( strncasecmp( e->e_ndn, "cn=entries",
333 sizeof("cn=entries")-1 ) == 0 ) {
334 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
335 n = num_entries_sent;
336 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
338 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
339 sizeof("cn=referrals")-1 ) == 0 ) {
340 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
342 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
344 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
345 sizeof("cn=pdu")-1 ) == 0 ) {
346 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
348 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
350 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
351 sizeof("cn=bytes")-1 ) == 0 ) {
352 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
354 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
359 char buf[] = "+9223372036854775807L";
361 a = attr_find( e->e_attrs, mi->ad_monitorCounter);
366 snprintf( buf, sizeof( buf ), "%ld", n );
367 free( a->a_vals[ 0 ].bv_val );
368 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );