]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/sent.c
add {creators|modifiers}Name to all entries
[openldap] / servers / slapd / back-monitor / sent.c
1 /* sent.c - deal with data sent subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2004 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "slap.h"
28 #include "back-monitor.h"
29
30 int
31 monitor_subsys_sent_init(
32         BackendDB               *be
33 )
34 {
35         struct monitorinfo      *mi;
36         
37         Entry                   *e, *e_tmp, *e_sent;
38         struct monitorentrypriv *mp;
39         char                    buf[ BACKMONITOR_BUFSIZE ];
40         struct berval           bv;
41
42         assert( be != NULL );
43
44         mi = ( struct monitorinfo * )be->be_private;
45
46         if ( monitor_cache_get( mi,
47                         &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
48 #ifdef NEW_LOGGING
49                 LDAP_LOG( OPERATION, CRIT,
50                         "monitor_subsys_sent_init: "
51                         "unable to get entry '%s'\n",
52                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
53 #else
54                 Debug( LDAP_DEBUG_ANY,
55                         "monitor_subsys_sent_init: "
56                         "unable to get entry '%s'\n%s%s",
57                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 
58                         "", "" );
59 #endif
60                 return( -1 );
61         }
62
63         e_tmp = NULL;
64
65         /*
66          * Entries
67          */
68         snprintf( buf, sizeof( buf ),
69                         "dn: cn=Entries,%s\n"
70                         "objectClass: %s\n"
71                         "structuralObjectClass: %s\n"
72                         "cn: Entries\n"
73                         "creatorsName: %s\n"
74                         "modifiersName: %s\n"
75                         "createTimestamp: %s\n"
76                         "modifyTimestamp: %s\n",
77                         monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
78                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
79                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
80                         mi->mi_creatorsName.bv_val,
81                         mi->mi_creatorsName.bv_val,
82                         mi->mi_startTime.bv_val,
83                         mi->mi_startTime.bv_val );
84
85         e = str2entry( buf );
86         if ( e == NULL ) {
87 #ifdef NEW_LOGGING
88                 LDAP_LOG( OPERATION, CRIT,
89                         "monitor_subsys_sent_init: "
90                         "unable to create entry 'cn=Entries,%s'\n",
91                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
92 #else
93                 Debug( LDAP_DEBUG_ANY,
94                         "monitor_subsys_sent_init: "
95                         "unable to create entry 'cn=Entries,%s'\n%s%s",
96                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
97                         "", "" );
98 #endif
99                 return( -1 );
100         }
101         
102         bv.bv_val = "0";
103         bv.bv_len = 1;
104         attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
105         
106         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
107         e->e_private = ( void * )mp;
108         mp->mp_next = e_tmp;
109         mp->mp_children = NULL;
110         mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
111         mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
112                 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
113
114         if ( monitor_cache_add( mi, e ) ) {
115 #ifdef NEW_LOGGING
116                 LDAP_LOG( OPERATION, CRIT,
117                         "monitor_subsys_sent_init: "
118                         "unable to add entry 'cn=Entries,%s'\n",
119                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
120 #else
121                 Debug( LDAP_DEBUG_ANY,
122                         "monitor_subsys_sent_init: "
123                         "unable to add entry 'cn=Entries,%s'\n%s%s",
124                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
125                         "", "" );
126 #endif
127                 return( -1 );
128         }
129         
130         e_tmp = e;
131
132         /*
133          * Referrals
134          */
135         snprintf( buf, sizeof( buf ),
136                         "dn: cn=Referrals,%s\n"
137                         "objectClass: %s\n"
138                         "structuralObjectClass: %s\n"
139                         "cn: Referrals\n"
140                         "creatorsName: %s\n"
141                         "modifiersName: %s\n"
142                         "createTimestamp: %s\n"
143                         "modifyTimestamp: %s\n",
144                         monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
145                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
146                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
147                         mi->mi_creatorsName.bv_val,
148                         mi->mi_creatorsName.bv_val,
149                         mi->mi_startTime.bv_val,
150                         mi->mi_startTime.bv_val );
151
152         e = str2entry( buf );
153         if ( e == NULL ) {
154 #ifdef NEW_LOGGING
155                 LDAP_LOG( OPERATION, CRIT,
156                         "monitor_subsys_sent_init: "
157                         "unable to create entry 'cn=Referrals,%s'\n",
158                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
159 #else
160                 Debug( LDAP_DEBUG_ANY,
161                         "monitor_subsys_sent_init: "
162                         "unable to create entry 'cn=Referrals,%s'\n%s%s",
163                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
164                         "", "" );
165 #endif
166                 return( -1 );
167         }
168
169         bv.bv_val = "0";
170         bv.bv_len = 1;
171         attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
172         
173         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
174         e->e_private = ( void * )mp;
175         mp->mp_next = e_tmp;
176         mp->mp_children = NULL;
177         mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
178         mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
179                 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
180
181         if ( monitor_cache_add( mi, e ) ) {
182 #ifdef NEW_LOGGING
183                 LDAP_LOG( OPERATION, CRIT,
184                         "monitor_subsys_sent_init: "
185                         "unable to add entry 'cn=Referrals,%s'\n",
186                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
187 #else
188                 Debug( LDAP_DEBUG_ANY,
189                         "monitor_subsys_sent_init: "
190                         "unable to add entry 'cn=Referrals,%s'\n%s%s",
191                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
192                         "", "" );
193 #endif
194                 return( -1 );
195         }
196         
197         e_tmp = e;
198
199         /*
200          * PDU
201          */
202         snprintf( buf, sizeof( buf ),
203                         "dn: cn=PDU,%s\n"
204                         "objectClass: %s\n"
205                         "structuralObjectClass: %s\n"
206                         "cn: PDU\n"
207                         "creatorsName: %s\n"
208                         "modifiersName: %s\n"
209                         "createTimestamp: %s\n"
210                         "modifyTimestamp: %s\n",
211                         monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
212                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
213                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
214                         mi->mi_creatorsName.bv_val,
215                         mi->mi_creatorsName.bv_val,
216                         mi->mi_startTime.bv_val,
217                         mi->mi_startTime.bv_val );
218
219         e = str2entry( buf );
220         if ( e == NULL ) {
221 #ifdef NEW_LOGGING
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 );
226 #else
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,
231                         "", "" );
232 #endif
233                 return( -1 );
234         }
235
236         bv.bv_val = "0";
237         bv.bv_len = 1;
238         attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
239         
240         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
241         e->e_private = ( void * )mp;
242         mp->mp_next = e_tmp;
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;
247
248         if ( monitor_cache_add( mi, e ) ) {
249 #ifdef NEW_LOGGING
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 );
254 #else
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,
259                         "", "" );
260 #endif
261                 return( -1 );
262         }
263         
264         e_tmp = e;
265
266         /*
267          * Bytes
268          */
269         snprintf( buf, sizeof( buf ),
270                         "dn: cn=Bytes,%s\n"
271                         "objectClass: %s\n"
272                         "structuralObjectClass: %s\n"
273                         "cn: Bytes\n"
274                         "creatorsName: %s\n"
275                         "modifiersName: %s\n"
276                         "createTimestamp: %s\n"
277                         "modifyTimestamp: %s\n",
278                         monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val,
279                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
280                         mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
281                         mi->mi_creatorsName.bv_val,
282                         mi->mi_creatorsName.bv_val,
283                         mi->mi_startTime.bv_val,
284                         mi->mi_startTime.bv_val );
285
286         e = str2entry( buf );
287         if ( e == NULL ) {
288 #ifdef NEW_LOGGING
289                 LDAP_LOG( OPERATION, CRIT,
290                         "monitor_subsys_sent_init: "
291                         "unable to create entry 'cn=Bytes,%s'\n",
292                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
293 #else
294                 Debug( LDAP_DEBUG_ANY,
295                         "monitor_subsys_sent_init: "
296                         "unable to create entry 'cn=Bytes,%s'\n%s%s",
297                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
298                         "", "" );
299 #endif
300                 return( -1 );
301         }
302
303         bv.bv_val = "0";
304         bv.bv_len = 1;
305         attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
306         
307         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
308         e->e_private = ( void * )mp;
309         mp->mp_next = e_tmp;
310         mp->mp_children = NULL;
311         mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
312         mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
313                 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
314
315         if ( monitor_cache_add( mi, e ) ) {
316 #ifdef NEW_LOGGING
317                 LDAP_LOG( OPERATION, CRIT,
318                         "monitor_subsys_sent_init: "
319                         "unable to add entry 'cn=Bytes,%s'\n",
320                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
321 #else
322                 Debug( LDAP_DEBUG_ANY,
323                         "monitor_subsys_sent_init: "
324                         "unable to add entry 'cn=Bytes,%s'\n%s%s",
325                         monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
326                         "", "" );
327 #endif
328                 return( -1 );
329         }
330         
331         e_tmp = e;
332
333         mp = ( struct monitorentrypriv * )e_sent->e_private;
334         mp->mp_children = e_tmp;
335
336         monitor_cache_release( mi, e_sent );
337
338         return( 0 );
339 }
340
341 int
342 monitor_subsys_sent_update(
343         Operation               *op,
344         Entry                   *e
345 )
346 {
347         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
348         long            n = -1;
349
350         assert( mi );
351         assert( e );
352         
353         if ( strncasecmp( e->e_ndn, "cn=entries", 
354                                 sizeof("cn=entries")-1 ) == 0 ) {
355                 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
356                 n = num_entries_sent;
357                 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
358
359         } else if ( strncasecmp( e->e_ndn, "cn=referrals", 
360                                 sizeof("cn=referrals")-1 ) == 0 ) {
361                 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
362                 n = num_refs_sent;
363                 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
364
365         } else if ( strncasecmp( e->e_ndn, "cn=pdu", 
366                                 sizeof("cn=pdu")-1 ) == 0 ) {
367                 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
368                 n = num_pdu_sent;
369                 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
370
371         } else if ( strncasecmp( e->e_ndn, "cn=bytes", 
372                                 sizeof("cn=bytes")-1 ) == 0 ) {
373                 ldap_pvt_thread_mutex_lock(&num_sent_mutex);
374                 n = num_bytes_sent;
375                 ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
376         }
377
378         if ( n != -1 ) {
379                 Attribute       *a;
380                 char            buf[] = "+9223372036854775807L";
381
382                 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter);
383                 if ( a == NULL ) {
384                         return( -1 );
385                 }
386
387                 snprintf( buf, sizeof( buf ), "%ld", n );
388                 free( a->a_vals[ 0 ].bv_val );
389                 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
390         }
391
392         return( 0 );
393 }
394