]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/operation.c
d4ea6f9c352b2cee691d0a6d21a02c4acd08d739
[openldap] / servers / slapd / back-monitor / operation.c
1 /* operation.c - deal with operation 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 #include "lber_pvt.h"
30
31 static struct berval 
32         bv_op[] = {
33                 BER_BVC( "Bind" ),
34                 BER_BVC( "Unbind" ),
35                 BER_BVC( "Add" ),
36                 BER_BVC( "Delete" ),
37                 BER_BVC( "Modrdn" ),
38                 BER_BVC( "Modify" ),
39                 BER_BVC( "Compare" ),
40                 BER_BVC( "Search" ),
41                 BER_BVC( "Abandon" ),
42                 BER_BVC( "Extended" ),
43                 { 0, NULL }
44         };
45
46 int
47 monitor_subsys_ops_init(
48         BackendDB               *be
49 )
50 {
51         struct monitorinfo      *mi;
52         
53         Entry                   *e, *e_tmp, *e_op;
54         struct monitorentrypriv *mp;
55         char                    buf[ BACKMONITOR_BUFSIZE ];
56         int                     i;
57
58         assert( be != NULL );
59
60         mi = ( struct monitorinfo * )be->be_private;
61
62         if ( monitor_cache_get( mi,
63                         &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
64 #ifdef NEW_LOGGING
65                 LDAP_LOG( OPERATION, CRIT,
66                         "monitor_subsys_ops_init: "
67                         "unable to get entry '%s'\n",
68                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
69 #else
70                 Debug( LDAP_DEBUG_ANY,
71                         "monitor_subsys_ops_init: "
72                         "unable to get entry '%s'\n%s%s",
73                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 
74                         "", "" );
75 #endif
76                 return( -1 );
77         }
78
79         e_tmp = NULL;
80
81         for ( i = SLAP_OP_LAST; i-- > 0; ) {
82
83                 /*
84                  * Initiated ops
85                  */
86                 snprintf( buf, sizeof( buf ),
87                                 "dn: cn=%s,%s\n"
88                                 "objectClass: %s\n"
89                                 "structuralObjectClass: %s\n"
90                                 "cn: %s\n"
91                                 "%s: 0\n"
92                                 "%s: 0\n"
93                                 "createTimestamp: %s\n"
94                                 "modifyTimestamp: %s\n",
95                                 bv_op[ i ].bv_val,
96                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
97                                 mi->mi_oc_monitorOperation->soc_cname.bv_val,
98                                 mi->mi_oc_monitorOperation->soc_cname.bv_val,
99                                 bv_op[ i ].bv_val,
100                                 mi->mi_ad_monitorOpInitiated->ad_cname.bv_val,
101                                 mi->mi_ad_monitorOpCompleted->ad_cname.bv_val,
102                                 mi->mi_startTime.bv_val,
103                                 mi->mi_startTime.bv_val );
104
105                 e = str2entry( buf );
106                 if ( e == NULL ) {
107 #ifdef NEW_LOGGING
108                         LDAP_LOG( OPERATION, CRIT,
109                                 "monitor_subsys_ops_init: "
110                                 "unable to create entry 'cn=%s,%s'\n",
111                                 bv_op[ i ].bv_val,
112                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
113 #else
114                         Debug( LDAP_DEBUG_ANY,
115                                 "monitor_subsys_ops_init: "
116                                 "unable to create entry 'cn=%s,%s'\n",
117                                 bv_op[ i ].bv_val,
118                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
119 #endif
120                         return( -1 );
121                 }
122         
123                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
124                 e->e_private = ( void * )mp;
125                 mp->mp_next = e_tmp;
126                 mp->mp_children = NULL;
127                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
128                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
129                         | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
130
131                 if ( monitor_cache_add( mi, e ) ) {
132 #ifdef NEW_LOGGING
133                         LDAP_LOG( OPERATION, CRIT,
134                                 "monitor_subsys_ops_init: "
135                                 "unable to add entry 'cn=%s,%s'\n",
136                                 bv_op[ i ].bv_val,
137                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
138 #else
139                         Debug( LDAP_DEBUG_ANY,
140                                 "monitor_subsys_ops_init: "
141                                 "unable to add entry 'cn=%s,%s'\n",
142                                 bv_op[ i ].bv_val,
143                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
144 #endif
145                         return( -1 );
146                 }
147         
148                 e_tmp = e;
149         }
150
151         mp = ( struct monitorentrypriv * )e_op->e_private;
152         mp->mp_children = e_tmp;
153
154         monitor_cache_release( mi, e_op );
155
156         return( 0 );
157 }
158
159 int
160 monitor_subsys_ops_update(
161         Operation               *op,
162         Entry                   *e
163 )
164 {
165         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
166         long            nInitiated = -1, nCompleted = -1;
167         char            *rdnvalue;
168         int             i;
169         Attribute       *a;
170         char            buf[] = "+9223372036854775807L";
171
172         assert( mi );
173         assert( e );
174
175         rdnvalue = e->e_dn + ( sizeof( "cn=" ) - 1 );
176
177         for (i = 0; i < SLAP_OP_LAST; i++ ) {
178                 if ( strncmp( rdnvalue, bv_op[ i ].bv_val, 
179                                         bv_op[ i ].bv_len ) == 0 ) {
180                         nInitiated = num_ops_initiated_[ i ];
181                         nCompleted = num_ops_completed_[ i ];
182                         break;
183                 }
184         }
185
186         if ( i == SLAP_OP_LAST ) {
187                 return( 0 );
188         }
189
190         a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated );
191         assert ( a != NULL );
192         snprintf( buf, sizeof( buf ), "%ld", nInitiated );
193         free( a->a_vals[ 0 ].bv_val );
194         ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
195
196         a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted );
197         assert ( a != NULL );
198         snprintf( buf, sizeof( buf ), "%ld", nCompleted );
199         free( a->a_vals[ 0 ].bv_val );
200         ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
201
202         return( 0 );
203 }
204