1 /* sent.c - deal with data sent subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
20 /* This is an altered version */
22 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
24 * This work has beed deveolped for the OpenLDAP Foundation
25 * in the hope that it may be useful to the Open Source community,
26 * but WITHOUT ANY WARRANTY.
28 * Permission is granted to anyone to use this software for any purpose
29 * on any computer system, and to alter it and redistribute it, subject
30 * to the following restrictions:
32 * 1. The author and SysNet s.n.c. are not responsible for the consequences
33 * of use of this software, no matter how awful, even if they arise from
36 * 2. The origin of this software must not be misrepresented, either by
37 * explicit claim or by omission. Since few users ever read sources,
38 * credits should appear in the documentation.
40 * 3. Altered versions must be plainly marked as such, and must not be
41 * misrepresented as being the original software. Since few users
42 * ever read sources, credits should appear in the documentation.
43 * SysNet s.n.c. cannot be responsible for the consequences of the
46 * 4. This notice may not be removed or altered.
52 #include <ac/string.h>
55 #include "back-monitor.h"
58 monitor_subsys_sent_init(
62 struct monitorinfo *mi;
64 Entry *e, *e_tmp, *e_sent;
65 struct monitorentrypriv *mp;
66 char buf[ BACKMONITOR_BUFSIZE ];
71 mi = ( struct monitorinfo * )be->be_private;
73 if ( monitor_cache_get( mi,
74 &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
76 LDAP_LOG( OPERATION, CRIT,
77 "monitor_subsys_sent_init: "
78 "unable to get entry '%s'\n",
79 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
81 Debug( LDAP_DEBUG_ANY,
82 "monitor_subsys_sent_init: "
83 "unable to get entry '%s'\n%s%s",
84 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
95 snprintf( buf, sizeof( buf ),
98 "structuralObjectClass: %s\n"
100 "createTimestamp: %s\n"
101 "modifyTimestamp: %s\n",
102 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
103 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
104 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
105 mi->mi_startTime.bv_val,
106 mi->mi_startTime.bv_val );
108 e = str2entry( buf );
111 LDAP_LOG( OPERATION, CRIT,
112 "monitor_subsys_sent_init: "
113 "unable to create entry 'cn=Entries,%s'\n",
114 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
116 Debug( LDAP_DEBUG_ANY,
117 "monitor_subsys_sent_init: "
118 "unable to create entry 'cn=Entries,%s'\n%s%s",
119 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
127 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
129 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
130 e->e_private = ( void * )mp;
132 mp->mp_children = NULL;
133 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
134 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
135 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
137 if ( monitor_cache_add( mi, e ) ) {
139 LDAP_LOG( OPERATION, CRIT,
140 "monitor_subsys_sent_init: "
141 "unable to add entry 'cn=Entries,%s'\n",
142 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
144 Debug( LDAP_DEBUG_ANY,
145 "monitor_subsys_sent_init: "
146 "unable to add entry 'cn=Entries,%s'\n%s%s",
147 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
158 snprintf( buf, sizeof( buf ),
159 "dn: cn=Referrals,%s\n"
161 "structuralObjectClass: %s\n"
163 "createTimestamp: %s\n"
164 "modifyTimestamp: %s\n",
165 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
166 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
167 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
168 mi->mi_startTime.bv_val,
169 mi->mi_startTime.bv_val );
171 e = str2entry( buf );
174 LDAP_LOG( OPERATION, CRIT,
175 "monitor_subsys_sent_init: "
176 "unable to create entry 'cn=Referrals,%s'\n",
177 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
179 Debug( LDAP_DEBUG_ANY,
180 "monitor_subsys_sent_init: "
181 "unable to create entry 'cn=Referrals,%s'\n%s%s",
182 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
190 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
192 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
193 e->e_private = ( void * )mp;
195 mp->mp_children = NULL;
196 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
197 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
198 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
200 if ( monitor_cache_add( mi, e ) ) {
202 LDAP_LOG( OPERATION, CRIT,
203 "monitor_subsys_sent_init: "
204 "unable to add entry 'cn=Referrals,%s'\n",
205 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
207 Debug( LDAP_DEBUG_ANY,
208 "monitor_subsys_sent_init: "
209 "unable to add entry 'cn=Referrals,%s'\n%s%s",
210 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
221 snprintf( buf, sizeof( buf ),
224 "structuralObjectClass: %s\n"
226 "createTimestamp: %s\n"
227 "modifyTimestamp: %s\n",
228 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
229 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
230 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
231 mi->mi_startTime.bv_val,
232 mi->mi_startTime.bv_val );
234 e = str2entry( buf );
237 LDAP_LOG( OPERATION, CRIT,
238 "monitor_subsys_sent_init: "
239 "unable to create 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 create entry 'cn=PDU,%s'\n%s%s",
245 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
253 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
255 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
256 e->e_private = ( void * )mp;
258 mp->mp_children = NULL;
259 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
260 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
261 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
263 if ( monitor_cache_add( mi, e ) ) {
265 LDAP_LOG( OPERATION, CRIT,
266 "monitor_subsys_sent_init: "
267 "unable to add entry 'cn=PDU,%s'\n",
268 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
270 Debug( LDAP_DEBUG_ANY,
271 "monitor_subsys_sent_init: "
272 "unable to add entry 'cn=PDU,%s'\n%s%s",
273 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
284 snprintf( buf, sizeof( buf ),
287 "structuralObjectClass: %s\n"
289 "createTimestamp: %s\n"
290 "modifyTimestamp: %s\n",
291 monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
292 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
293 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
294 mi->mi_startTime.bv_val,
295 mi->mi_startTime.bv_val );
297 e = str2entry( buf );
300 LDAP_LOG( OPERATION, CRIT,
301 "monitor_subsys_sent_init: "
302 "unable to create entry 'cn=Bytes,%s'\n",
303 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
305 Debug( LDAP_DEBUG_ANY,
306 "monitor_subsys_sent_init: "
307 "unable to create entry 'cn=Bytes,%s'\n%s%s",
308 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
316 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
318 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
319 e->e_private = ( void * )mp;
321 mp->mp_children = NULL;
322 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
323 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
324 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
326 if ( monitor_cache_add( mi, e ) ) {
328 LDAP_LOG( OPERATION, CRIT,
329 "monitor_subsys_sent_init: "
330 "unable to add entry 'cn=Bytes,%s'\n",
331 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
333 Debug( LDAP_DEBUG_ANY,
334 "monitor_subsys_sent_init: "
335 "unable to add entry 'cn=Bytes,%s'\n%s%s",
336 monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
344 mp = ( struct monitorentrypriv * )e_sent->e_private;
345 mp->mp_children = e_tmp;
347 monitor_cache_release( mi, e_sent );
353 monitor_subsys_sent_update(
358 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
364 if ( strncasecmp( e->e_ndn, "cn=entries",
365 sizeof("cn=entries")-1 ) == 0 ) {
366 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
367 n = num_entries_sent;
368 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
370 } else if ( strncasecmp( e->e_ndn, "cn=referrals",
371 sizeof("cn=referrals")-1 ) == 0 ) {
372 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
374 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
376 } else if ( strncasecmp( e->e_ndn, "cn=pdu",
377 sizeof("cn=pdu")-1 ) == 0 ) {
378 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
380 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
382 } else if ( strncasecmp( e->e_ndn, "cn=bytes",
383 sizeof("cn=bytes")-1 ) == 0 ) {
384 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
386 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
391 char buf[] = "+9223372036854775807L";
393 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter);
398 snprintf( buf, sizeof( buf ), "%ld", n );
399 free( a->a_vals[ 0 ].bv_val );
400 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );