]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/listener.c
Fix previous commit
[openldap] / servers / slapd / back-monitor / listener.c
1 /* listener.c - deals with listener subsystem */
2 /*
3  * Copyright 1998-2002 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
38 #include "slap.h"
39 #include "back-monitor.h"
40
41 int
42 monitor_subsys_listener_init(
43         BackendDB       *be
44 )
45 {
46         struct monitorinfo      *mi;
47         Entry                   *e, *e_listener, *e_tmp;
48         int                     i;
49         struct monitorentrypriv *mp;
50         struct berval           bv[2];
51         Listener                **l;
52
53         assert( be != NULL );
54         assert( monitor_ad_desc != NULL );
55
56         mi = ( struct monitorinfo * )be->be_private;
57
58         if ( monitor_cache_get( mi, 
59                                 &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, 
60                                 &e_listener ) ) {
61 #ifdef NEW_LOGGING
62                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
63                         "monitor_subsys_listener_init: "
64                         "unable to get entry '%s'\n",
65                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val ));
66 #else
67                 Debug( LDAP_DEBUG_ANY,
68                         "monitor_subsys_listener_init: "
69                         "unable to get entry '%s'\n%s%s",
70                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 
71                         "", "" );
72 #endif
73                 return( -1 );
74         }
75
76         if ( ( l = slapd_get_listeners() ) == NULL ) {
77 #ifdef NEW_LOGGING
78                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
79                         "monitor_subsys_listener_init: "
80                         "unable to get listeners\n" ));
81 #else
82                 Debug( LDAP_DEBUG_ANY,
83                         "monitor_subsys_listener_init: "
84                         "unable to get listeners\n", 0, 0, 0 );
85 #endif
86                 return( -1 );
87         }
88
89         e_tmp = NULL;
90         for ( i = 0; l[i]; i++ ) {
91                 char            buf[1024];
92
93                 snprintf( buf, sizeof( buf ),
94                                 "dn: cn=%s,%s\n"
95                                 SLAPD_MONITOR_OBJECTCLASSES
96                                 "cn: %s\n",
97                                 l[i]->sl_name,
98                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
99                                 l[i]->sl_name );
100                 
101                 e = str2entry( buf );
102                 if ( e == NULL ) {
103 #ifdef NEW_LOGGING
104                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
105                                 "monitor_subsys_listener_init: "
106                                 "unable to create entry 'cn=%s,%s'\n",
107                                 l[i]->sl_name,
108                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val ));
109 #else
110                         Debug( LDAP_DEBUG_ANY,
111                                 "monitor_subsys_listener_init: "
112                                 "unable to create entry 'cn=%s,%s'\n%s",
113                                 l[i]->sl_name, 
114                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
115                                 "" );
116 #endif
117                         return( -1 );
118                 }
119                 
120                 bv[1].bv_val = NULL;
121                 bv[0].bv_val = l[i]->sl_url;
122                 bv[0].bv_len = strlen( bv[0].bv_val );
123                 attr_merge( e, monitor_ad_desc, bv );
124                 
125                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
126                 e->e_private = ( void * )mp;
127                 mp->mp_next = e_tmp;
128                 mp->mp_children = NULL;
129                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
130                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
131                         | MONITOR_F_SUB;
132
133                 if ( monitor_cache_add( mi, e ) ) {
134 #ifdef NEW_LOGGING
135                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
136                                 "monitor_subsys_listener_init: "
137                                 "unable to add entry 'cn=%s,%s'\n",
138                                 l[i]->sl_name, 
139                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val ));
140 #else
141                         Debug( LDAP_DEBUG_ANY,
142                                 "monitor_subsys_listener_init: "
143                                 "unable to add entry 'cn=%s,%s'\n",
144                                 l[i]->sl_name, 
145                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
146                                 0 );
147 #endif
148                         return( -1 );
149                 }
150
151                 e_tmp = e;
152         }
153         
154         mp = ( struct monitorentrypriv * )e_listener->e_private;
155         mp->mp_children = e_tmp;
156
157         monitor_cache_release( mi, e_listener );
158
159         return( 0 );
160 }
161