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 "createTimestamp: %s\n"
86 "modifyTimestamp: %s\n",
87 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
88 mi->oc_monitorCounterObject->soc_cname.bv_val,
89 mi->oc_monitorCounterObject->soc_cname.bv_val,
90 mi->mi_startTime.bv_val,
91 mi->mi_startTime.bv_val );
96 LDAP_LOG( OPERATION, CRIT,
97 "monitor_subsys_sent_init: "
98 "unable to create entry 'cn=Entries,%s'\n",
99 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
101 Debug( LDAP_DEBUG_ANY,
102 "monitor_subsys_sent_init: "
103 "unable to create entry 'cn=Entries,%s'\n%s%s",
104 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
112 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
114 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
115 e->e_private = ( void * )mp;
117 mp->mp_children = NULL;
118 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
119 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
120 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
122 if ( monitor_cache_add( mi, e ) ) {
124 LDAP_LOG( OPERATION, CRIT,
125 "monitor_subsys_sent_init: "
126 "unable to add entry 'cn=Entries,%s'\n",
127 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
129 Debug( LDAP_DEBUG_ANY,
130 "monitor_subsys_sent_init: "
131 "unable to add entry 'cn=Entries,%s'\n%s%s",
132 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
143 snprintf( buf, sizeof( buf ),
144 "dn: cn=Referrals,%s\n"
146 "structuralObjectClass: %s\n"
148 "createTimestamp: %s\n"
149 "modifyTimestamp: %s\n",
150 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
151 mi->oc_monitorCounterObject->soc_cname.bv_val,
152 mi->oc_monitorCounterObject->soc_cname.bv_val,
153 mi->mi_startTime.bv_val,
154 mi->mi_startTime.bv_val );
156 e = str2entry( buf );
159 LDAP_LOG( OPERATION, 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, 0, 0 );
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_one( e, mi->ad_monitorCounter, &bv, NULL );
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, 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, 0, 0 );
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 "structuralObjectClass: %s\n"
211 "createTimestamp: %s\n"
212 "modifyTimestamp: %s\n",
213 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
214 mi->oc_monitorCounterObject->soc_cname.bv_val,
215 mi->oc_monitorCounterObject->soc_cname.bv_val,
216 mi->mi_startTime.bv_val,
217 mi->mi_startTime.bv_val );
219 e = str2entry( buf );
222 LDAP_LOG( OPERATION, CRIT,
223 "monitor_subsys_sent_init: "
224 "unable to create entry 'cn=PDU,%s'\n",
225 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
227 Debug( LDAP_DEBUG_ANY,
228 "monitor_subsys_sent_init: "
229 "unable to create entry 'cn=PDU,%s'\n%s%s",
230 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
238 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
240 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
241 e->e_private = ( void * )mp;
243 mp->mp_children = NULL;
244 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
245 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
246 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
248 if ( monitor_cache_add( mi, e ) ) {
250 LDAP_LOG( OPERATION, CRIT,
251 "monitor_subsys_sent_init: "
252 "unable to add entry 'cn=PDU,%s'\n",
253 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
255 Debug( LDAP_DEBUG_ANY,
256 "monitor_subsys_sent_init: "
257 "unable to add entry 'cn=PDU,%s'\n%s%s",
258 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
269 snprintf( buf, sizeof( buf ),
272 "structuralObjectClass: %s\n"
274 "createTimestamp: %s\n"
275 "modifyTimestamp: %s\n",
276 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
277 mi->oc_monitorCounterObject->soc_cname.bv_val,
278 mi->oc_monitorCounterObject->soc_cname.bv_val,
279 mi->mi_startTime.bv_val,
280 mi->mi_startTime.bv_val );
282 e = str2entry( buf );
285 LDAP_LOG( OPERATION, CRIT,
286 "monitor_subsys_sent_init: "
287 "unable to create entry 'cn=Bytes,%s'\n",
288 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
290 Debug( LDAP_DEBUG_ANY,
291 "monitor_subsys_sent_init: "
292 "unable to create entry 'cn=Bytes,%s'\n%s%s",
293 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
301 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
303 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
304 e->e_private = ( void * )mp;
306 mp->mp_children = NULL;
307 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
308 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
309 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
311 if ( monitor_cache_add( mi, e ) ) {
313 LDAP_LOG( OPERATION, CRIT,
314 "monitor_subsys_sent_init: "
315 "unable to add entry 'cn=Bytes,%s'\n",
316 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
318 Debug( LDAP_DEBUG_ANY,
319 "monitor_subsys_sent_init: "
320 "unable to add entry 'cn=Bytes,%s'\n%s%s",
321 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
329 mp = ( struct monitorentrypriv * )e_sent->e_private;
330 mp->mp_children = e_tmp;
332 monitor_cache_release( mi, e_sent );
338 monitor_subsys_sent_update(
343 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
349 if ( strncasecmp( e->e_ndn, "cn=entries",
350 sizeof("cn=entries")-1 ) == 0 ) {
351 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
352 n = num_entries_sent;
353 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
355 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
356 sizeof("cn=referrals")-1 ) == 0 ) {
357 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
359 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
361 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
362 sizeof("cn=pdu")-1 ) == 0 ) {
363 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
365 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
367 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
368 sizeof("cn=bytes")-1 ) == 0 ) {
369 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
371 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
376 char buf[] = "+9223372036854775807L";
378 a = attr_find( e->e_attrs, mi->ad_monitorCounter);
383 snprintf( buf, sizeof( buf ), "%ld", n );
384 free( a->a_vals[ 0 ].bv_val );
385 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );