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