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