X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-monitor%2Flistener.c;h=102d5c0d55c52d46620376785c38e0e242143f17;hb=0a465343fb6d6d8df9091699885bf352c3b1d4b3;hp=20695a664e8b9a8b814fee590f002ffe5c3720a1;hpb=1bbdcba854ee7f5c672915f86a6193af055bbb5f;p=openldap diff --git a/servers/slapd/back-monitor/listener.c b/servers/slapd/back-monitor/listener.c index 20695a664e..102d5c0d55 100644 --- a/servers/slapd/back-monitor/listener.c +++ b/servers/slapd/back-monitor/listener.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2001-2004 The OpenLDAP Foundation. + * Copyright 2001-2006 The OpenLDAP Foundation. * Portions Copyright 2001-2003 Pierangelo Masarati. * All rights reserved. * @@ -22,157 +22,115 @@ #include "portable.h" #include +#include #include "slap.h" #include "back-monitor.h" int monitor_subsys_listener_init( - BackendDB *be + BackendDB *be, + monitor_subsys_t *ms ) { - struct monitorinfo *mi; - Entry *e, *e_listener, *e_tmp; - int i; - struct monitorentrypriv *mp; - Listener **l; + monitor_info_t *mi; + Entry *e_listener, **ep; + int i; + monitor_entry_t *mp; + Listener **l; assert( be != NULL ); - mi = ( struct monitorinfo * )be->be_private; + if ( ( l = slapd_get_listeners() ) == NULL ) { + if ( slapMode & SLAP_TOOL_MODE ) { + return 0; + } - if ( monitor_cache_get( mi, - &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, - &e_listener ) ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, CRIT, - "monitor_subsys_listener_init: " - "unable to get entry '%s'\n", - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0, 0 ); -#else Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, - "", "" ); -#endif + "unable to get listeners\n", 0, 0, 0 ); return( -1 ); } - if ( ( l = slapd_get_listeners() ) == NULL ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, CRIT, - "monitor_subsys_listener_init: " - "unable to get listeners\n", 0, 0, 0 ); -#else + mi = ( monitor_info_t * )be->be_private; + + if ( monitor_cache_get( mi, &ms->mss_ndn, &e_listener ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to get listeners\n", 0, 0, 0 ); -#endif + "unable to get entry \"%s\"\n", + ms->mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; - for ( i = 0; l[i]; i++ ); - for ( ; i--; ) { + mp = ( monitor_entry_t * )e_listener->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; + + for ( i = 0; l[ i ]; i++ ) { char buf[ BACKMONITOR_BUFSIZE ]; + Entry *e; + struct berval bv; + + bv.bv_len = snprintf( buf, sizeof( buf ), + "cn=Listener %d", i ); + bv.bv_val = buf; + e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv, + mi->mi_oc_monitoredObject, mi, NULL, NULL ); - snprintf( buf, sizeof( buf ), - "dn: cn=Listener %d,%s\n" - "objectClass: %s\n" - "structuralObjectClass: %s\n" - "cn: Listener %d\n" - "%s: %s\n" - "labeledURI: %s\n" - "creatorsName: %s\n" - "modifiersName: %s\n" - "createTimestamp: %s\n" - "modifyTimestamp: %s\n", - i, - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val, - mi->mi_oc_monitoredObject->soc_cname.bv_val, - mi->mi_oc_monitoredObject->soc_cname.bv_val, - i, - mi->mi_ad_monitorConnectionLocalAddress->ad_cname.bv_val, - l[i]->sl_name.bv_val, - l[i]->sl_url.bv_val, - mi->mi_creatorsName.bv_val, - mi->mi_creatorsName.bv_val, - mi->mi_startTime.bv_val, - mi->mi_startTime.bv_val ); - - e = str2entry( buf ); if ( e == NULL ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, CRIT, - "monitor_subsys_listener_init: " - "unable to create entry 'cn=Listener, %d,%s'\n", - i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 ); -#else Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to create entry 'cn=Listener %d,%s'\n%s", - i, - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, - "" ); -#endif + "unable to create entry \"cn=Listener %d,%s\"\n", + i, ms->mss_ndn.bv_val, 0 ); return( -1 ); } + attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionLocalAddress, + &l[ i ]->sl_name, NULL ); + + attr_merge_normalize_one( e, slap_schema.si_ad_labeledURI, + &l[ i ]->sl_url, NULL ); + #ifdef HAVE_TLS - if ( l[i]->sl_is_tls ) { + if ( l[ i ]->sl_is_tls ) { struct berval bv; - bv.bv_val = "TLS"; - bv.bv_len = sizeof("TLS")-1; - + BER_BVSTR( &bv, "TLS" ); attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); } #endif /* HAVE_TLS */ #ifdef LDAP_CONNECTIONLESS - if ( l[i]->sl_is_udp ) { + if ( l[ i ]->sl_is_udp ) { struct berval bv; - bv.bv_val = "UDP"; - bv.bv_len = sizeof("UDP")-1; - + BER_BVSTR( &bv, "UDP" ); attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); } #endif /* HAVE_TLS */ - mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + mp = monitor_entrypriv_create(); + if ( mp == NULL ) { + return -1; + } e->e_private = ( void * )mp; - mp->mp_next = e_tmp; - mp->mp_children = NULL; - mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER]; - mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags + mp->mp_info = ms; + mp->mp_flags = ms->mss_flags | MONITOR_F_SUB; if ( monitor_cache_add( mi, e ) ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, CRIT, - "monitor_subsys_listener_init: " - "unable to add entry 'cn=Listener %d,%s'\n", - i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 ); -#else Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to add entry 'cn=Listener %d,%s'\n", - i, - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, - 0 ); -#endif + "unable to add entry \"cn=Listener %d,%s\"\n", + i, ms->mss_ndn.bv_val, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - mp = ( struct monitorentrypriv * )e_listener->e_private; - mp->mp_children = e_tmp; - monitor_cache_release( mi, e_listener ); return( 0 );