]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/operation.c
More "char *" to struct berval DN changes
[openldap] / servers / slapd / back-monitor / operation.c
1 /* operation.c - deal with operation subsystem */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
8  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9  * 
10  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
11  * 
12  * This work has beed deveolped for the OpenLDAP Foundation 
13  * in the hope that it may be useful to the Open Source community, 
14  * but WITHOUT ANY WARRANTY.
15  * 
16  * Permission is granted to anyone to use this software for any purpose
17  * on any computer system, and to alter it and redistribute it, subject
18  * to the following restrictions:
19  * 
20  * 1. The author and SysNet s.n.c. are not responsible for the consequences
21  *    of use of this software, no matter how awful, even if they arise from
22  *    flaws in it.
23  * 
24  * 2. The origin of this software must not be misrepresented, either by
25  *    explicit claim or by omission.  Since few users ever read sources,
26  *    credits should appear in the documentation.
27  * 
28  * 3. Altered versions must be plainly marked as such, and must not be
29  *    misrepresented as being the original software.  Since few users
30  *    ever read sources, credits should appear in the documentation.
31  *    SysNet s.n.c. cannot be responsible for the consequences of the
32  *    alterations.
33  * 
34  * 4. This notice may not be removed or altered.
35  */
36
37 #include "portable.h"
38
39 #include <stdio.h>
40
41 #include "slap.h"
42 #include "back-monitor.h"
43
44 int
45 monitor_subsys_ops_init(
46         BackendDB               *be
47 )
48 {
49         struct monitorinfo      *mi;
50         
51         Entry                   *e, *e_tmp, *e_op;
52         struct monitorentrypriv *mp;
53         char                    buf[1024];
54         struct berval           val, *bv[2] = { &val, NULL };
55
56         assert( be != NULL );
57
58         mi = ( struct monitorinfo * )be->be_private;
59
60         if ( monitor_cache_get( mi,
61                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
62 #ifdef NEW_LOGGING
63                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
64                         "monitor_subsys_ops_init: "
65                         "unable to get entry '%s'\n",
66                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
67 #else
68                 Debug( LDAP_DEBUG_ANY,
69                         "monitor_subsys_ops_init: "
70                         "unable to get entry '%s'\n%s%s",
71                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, 
72                         "", "" );
73 #endif
74                 return( -1 );
75         }
76
77         e_tmp = NULL;
78
79         /*
80          * Initiated ops
81          */
82         snprintf( buf, sizeof( buf ),
83                         "dn: cn=Initiated,%s\n"
84                         "objectClass: top\n"
85                         "objectClass: LDAPsubEntry\n"
86 #ifdef SLAPD_MONITORSUBENTRY
87                         "objectClass: monitorSubEntry\n"
88 #else /* !SLAPD_MONITORSUBENTRY */
89                         "objectClass: extensibleObject\n"
90 #endif /* !SLAPD_MONITORSUBENTRY */
91                         "cn: Initiated\n",
92                         monitor_subsys[SLAPD_MONITOR_OPS].mss_dn );
93
94         e = str2entry( buf );
95         if ( e == NULL ) {
96 #ifdef NEW_LOGGING
97                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
98                         "monitor_subsys_ops_init: "
99                         "unable to create entry 'cn=Initiated,%s'\n",
100                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
101 #else
102                 Debug( LDAP_DEBUG_ANY,
103                         "monitor_subsys_ops_init: "
104                         "unable to create entry 'cn=Initiated,%s'\n%s%s",
105                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
106                         "", "" );
107 #endif
108                 return( -1 );
109         }
110         
111         val.bv_val = "0";
112         val.bv_len = 1;
113         attr_merge( e, monitor_ad_desc, bv );
114         
115         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
116         e->e_private = ( void * )mp;
117         mp->mp_next = e_tmp;
118         mp->mp_children = NULL;
119         mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
120         mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
121                 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
122
123         if ( monitor_cache_add( mi, e ) ) {
124 #ifdef NEW_LOGGING
125                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
126                         "monitor_subsys_ops_init: "
127                         "unable to add entry 'cn=Initiated,%s'\n",
128                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
129 #else
130                 Debug( LDAP_DEBUG_ANY,
131                         "monitor_subsys_ops_init: "
132                         "unable to add entry 'cn=Initiated,%s'\n%s%s",
133                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
134                         "", "" );
135 #endif
136                 return( -1 );
137         }
138         
139         e_tmp = e;
140
141         /*
142          * Completed ops
143          */
144         snprintf( buf, sizeof( buf ),
145                         "dn: cn=Completed,%s\n"
146                         "objectClass: top\n"
147                         "objectClass: LDAPsubEntry\n"
148 #ifdef SLAPD_MONITORSUBENTRY
149                         "objectClass: monitorSubEntry\n"
150 #else /* !SLAPD_MONITORSUBENTRY */
151                         "objectClass: extensibleObject\n"
152 #endif /* !SLAPD_MONITORSUBENTRY */
153                         "cn: Completed\n",
154                         monitor_subsys[SLAPD_MONITOR_OPS].mss_dn );
155
156         e = str2entry( buf );
157         if ( e == NULL ) {
158 #ifdef NEW_LOGGING
159                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
160                         "monitor_subsys_ops_init: "
161                         "unable to create entry 'cn=Completed,%s'\n",
162                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
163 #else
164                 Debug( LDAP_DEBUG_ANY,
165                         "monitor_subsys_ops_init: "
166                         "unable to create entry 'cn=Completed,%s'\n%s%s",
167                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
168                         "", "" );
169 #endif
170                 return( -1 );
171         }
172
173         val.bv_val = "0";
174         val.bv_len = 1;
175         attr_merge( e, monitor_ad_desc, bv );
176         
177         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
178         e->e_private = ( void * )mp;
179         mp->mp_next = e_tmp;
180         mp->mp_children = NULL;
181         mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
182         mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
183                 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
184
185         if ( monitor_cache_add( mi, e ) ) {
186 #ifdef NEW_LOGGING
187                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
188                         "monitor_subsys_ops_init: "
189                         "unable to add entry 'cn=Completed,%s'\n",
190                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
191 #else
192                 Debug( LDAP_DEBUG_ANY,
193                         "monitor_subsys_ops_init: "
194                         "unable to add entry 'cn=Completed,%s'\n%s%s",
195                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
196                         "", "" );
197 #endif
198                 return( -1 );
199         }
200         
201         e_tmp = e;
202
203         mp = ( struct monitorentrypriv * )e_op->e_private;
204         mp->mp_children = e_tmp;
205
206         monitor_cache_release( mi, e_op );
207
208         return( 0 );
209 }
210
211 int
212 monitor_subsys_ops_update(
213         struct monitorinfo      *mi,
214         Entry                   *e
215 )
216 {
217         long            n = -1;
218
219         assert( mi );
220         assert( e );
221         
222         if ( strncasecmp( e->e_ndn, "CN=INITIATED", 
223                                 sizeof("CN=INITIATED")-1 ) == 0 ) {
224                 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
225                 n = num_ops_initiated;
226                 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
227
228         } else if ( strncasecmp( e->e_ndn, "CN=COMPLETED", 
229                                 sizeof("CN=COMPLETED")-1 ) == 0 ) {
230                 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
231                 n = num_ops_completed;
232                 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
233         }
234
235         if ( n != -1 ) {
236                 Attribute       *a;
237                 char            buf[16];
238
239                 a = attr_find( e->e_attrs, monitor_ad_desc );
240                 if ( a == NULL ) {
241                         return( -1 );
242                 }
243
244                 snprintf( buf, sizeof( buf ), "%ld", n );
245                 ber_bvfree( a->a_vals[ 0 ] );
246                 a->a_vals[ 0 ] = ber_bvstrdup( buf );
247         }
248
249         return( 0 );
250 }
251