]> git.sur5r.net Git - openldap/commitdiff
apply Howard's cleanup of database monitoring registration
authorPierangelo Masarati <ando@openldap.org>
Sat, 15 Sep 2007 15:34:49 +0000 (15:34 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 15 Sep 2007 15:34:49 +0000 (15:34 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/monitor.c
servers/slapd/back-monitor/back-monitor.h
servers/slapd/back-monitor/database.c
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/proto-back-monitor.h

index 6776e3b68c798450d270bb19e8367b0b63f75b0a..5ddb2f370a330e221e81776e8c8f445f1962049e 100644 (file)
@@ -183,9 +183,7 @@ struct bdb_db_info {
 
 typedef struct bdb_monitor_t {
        void            *bdm_cb;
-       struct berval   bdm_nbase;
-       int             bdm_scope;
-       struct berval   bdm_filter;
+       struct berval   bdm_ndn;
 } bdb_monitor_t;
 
 /* From ldap_rq.h */
index c99204a65743552ac8f58748e50b4ef393151f0d..f30469702cda7bf85d632ba5204b7013c7f8a013 100644 (file)
@@ -317,8 +317,6 @@ bdb_monitor_db_init( BackendDB *be )
        ldap_pvt_thread_mutex_init( &bdb->bi_idx_mutex );
 #endif /* BDB_MONITOR_IDX */
 
-       bdb->bi_monitor.bdm_scope = -1;
-
        return 0;
 }
 
@@ -331,11 +329,10 @@ bdb_monitor_db_open( BackendDB *be )
        struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
        Attribute               *a, *next;
        monitor_callback_t      *cb = NULL;
-       struct berval           suffix, *filter, *base;
-       char                    *ptr;
        int                     rc = 0;
        BackendInfo             *mi;
        monitor_extra_t         *mbe;
+       struct berval dummy = BER_BVC("");
 
        if ( !SLAP_DBMONITORING( be ) ) {
                return 0;
@@ -366,47 +363,6 @@ bdb_monitor_db_open( BackendDB *be )
                return 0;
        }
 
-       if ( bdb->bi_monitor.bdm_scope == -1 ) {
-               bdb->bi_monitor.bdm_scope = LDAP_SCOPE_ONELEVEL;
-       }
-       base = &bdb->bi_monitor.bdm_nbase;
-       BER_BVSTR( base, "cn=databases,cn=monitor" );
-       filter = &bdb->bi_monitor.bdm_filter;
-       BER_BVZERO( filter );
-
-       suffix.bv_len = ldap_bv2escaped_filter_value_len( &be->be_nsuffix[ 0 ] );
-       if ( suffix.bv_len == be->be_nsuffix[ 0 ].bv_len ) {
-               suffix = be->be_nsuffix[ 0 ];
-
-       } else {
-               ldap_bv2escaped_filter_value( &be->be_nsuffix[ 0 ], &suffix );
-       }
-
-       if ( BER_BVISEMPTY( &suffix ) ) {
-               /* frontend also has empty suffix, sigh! */
-               filter->bv_len = STRLENOF( "(&(namingContexts:distinguishedNameMatch:=" )
-                       + suffix.bv_len + STRLENOF( ")(!(cn=frontend)))" );
-               ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
-               ptr = lutil_strcopy( ptr, "(&(namingContexts:distinguishedNameMatch:=" );
-               ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
-               ptr = lutil_strcopy( ptr, ")(!(cn=frontend)))" );
-
-       } else {
-               /* just look for the naming context */
-               filter->bv_len = STRLENOF( "(namingContexts:distinguishedNameMatch:=" )
-                       + suffix.bv_len + STRLENOF( ")" );
-               ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
-               ptr = lutil_strcopy( ptr, "(namingContexts:distinguishedNameMatch:=" );
-               ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
-               ptr = lutil_strcopy( ptr, ")" );
-       }
-       ptr[ 0 ] = '\0';
-       assert( filter->bv_len == ptr - filter->bv_val );
-       
-       if ( suffix.bv_val != be->be_nsuffix[ 0 ].bv_val ) {
-               ch_free( suffix.bv_val );
-       }
-
        /* alloc as many as required (plus 1 for objectClass) */
        a = attrs_alloc( 1 + 4 );
        if ( a == NULL ) {
@@ -497,10 +453,10 @@ bdb_monitor_db_open( BackendDB *be )
        cb->mc_private = (void *)bdb;
 
        /* make sure the database is registered; then add monitor attributes */
-       rc = mbe->register_database( be );
+       rc = mbe->register_database( be, &bdb->bi_monitor.bdm_ndn );
        if ( rc == 0 ) {
-               rc = mbe->register_entry_attrs( NULL, a, cb,
-                       base, bdb->bi_monitor.bdm_scope, filter );
+               rc = mbe->register_entry_attrs( &bdb->bi_monitor.bdm_ndn, a, cb,
+                       &dummy, 0, &dummy );
        }
 
 cleanup:;
@@ -514,11 +470,6 @@ cleanup:;
                        attrs_free( a );
                        a = NULL;
                }
-
-               if ( !BER_BVISNULL( filter ) ) {
-                       ch_free( filter->bv_val );
-                       BER_BVZERO( filter );
-               }
        }
 
        /* store for cleanup */
@@ -545,21 +496,15 @@ bdb_monitor_db_close( BackendDB *be )
                return 0;
        }
 
-       if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_filter ) ) {
+       if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_ndn ) ) {
                BackendInfo             *mi = backend_info( "monitor" );
                monitor_extra_t         *mbe;
 
                if ( mi && &mi->bi_extra ) {
                        mbe = mi->bi_extra;
-                       mbe->unregister_entry_callback( NULL,
+                       mbe->unregister_entry_callback( &bdb->bi_monitor.bdm_ndn,
                                (monitor_callback_t *)bdb->bi_monitor.bdm_cb,
-                               &bdb->bi_monitor.bdm_nbase,
-                               bdb->bi_monitor.bdm_scope,
-                               &bdb->bi_monitor.bdm_filter );
-               }
-
-               if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_filter ) ) {
-                       ch_free( bdb->bi_monitor.bdm_filter.bv_val );
+                               NULL, 0, NULL );
                }
 
                memset( &bdb->bi_monitor, 0, sizeof( bdb->bi_monitor ) );
index 6e1ad91793b0d98d00bac7cd7005cb2648d2aa91..f69fa39ea12ebf574e5a33e0d7c19ea3e066cbc3 100644 (file)
@@ -288,7 +288,7 @@ typedef struct monitor_extra_t {
 
        int (*register_subsys)( monitor_subsys_t *ms );
        int (*register_backend)( BackendInfo *bi );
-       int (*register_database)( BackendDB *be );
+       int (*register_database)( BackendDB *be, struct berval *ndn );
        int (*register_overlay_info)( slap_overinst *on );
        int (*register_overlay)( BackendDB *be );
        int (*register_entry)( Entry *e, monitor_callback_t *cb,
index f09001ed2b0070e05e8d160f7789b91018a1563f..f150b177bd832c73349367e845713e37ae2700c3 100644 (file)
@@ -343,7 +343,8 @@ monitor_subsys_database_init_one(
 
 int
 monitor_back_register_database(
-       BackendDB               *be )
+       BackendDB               *be,
+       struct berval   *ndn )
 {
        monitor_info_t          *mi;
        Entry                   *e_database, **ep;
@@ -358,7 +359,7 @@ monitor_back_register_database(
        assert( be_monitor != NULL );
 
        if ( !monitor_subsys_is_opened() ) {
-               return monitor_back_register_database_limbo( be );
+               return monitor_back_register_database_limbo( be, ndn );
        }
 
        mi = ( monitor_info_t * )be_monitor->be_private;
@@ -443,6 +444,9 @@ monitor_back_register_database(
 
 done:;
        monitor_cache_release( mi, e_database );
+       if ( rc == 0 && ndn && ep && *ep ) {
+               *ndn = (*ep)->e_nname;
+       }
 
        return rc;
 }
index 3df03cba3a14f9dbb1d121445cf32184b682c076..5e0128ec0c2fca9ab3d32bc5de984e2f6ac0ab50 100644 (file)
@@ -291,7 +291,7 @@ typedef struct entry_limbo_t {
        slap_overinst           *el_on;
        Entry                   *el_e;
        Attribute               *el_a;
-       struct berval           el_ndn;
+       struct berval           *el_ndn;
        struct berval           el_nbase;
        int                     el_scope;
        struct berval           el_filter;
@@ -337,7 +337,8 @@ monitor_back_register_backend_limbo(
 
 int
 monitor_back_register_database_limbo(
-       BackendDB               *be )
+       BackendDB               *be,
+       struct berval   *ndn )
 {
        entry_limbo_t   **elpp, el = { 0 };
        monitor_info_t  *mi;
@@ -356,6 +357,7 @@ monitor_back_register_database_limbo(
        el.el_type = LIMBO_DATABASE;
 
        el.el_be = be;
+       el.el_ndn = ndn;
        
        for ( elpp = &mi->mi_entry_limbo;
                        *elpp;
@@ -1062,9 +1064,7 @@ done:;
                entry_limbo_t   **elpp, el = { 0 };
 
                el.el_type = LIMBO_ATTRS;
-               if ( !BER_BVISNULL( &ndn ) ) {
-                       ber_dupbv( &el.el_ndn, &ndn );
-               }
+               el.el_ndn = ndn_in;
                if ( !BER_BVISNULL( nbase ) ) {
                        ber_dupbv( &el.el_nbase, nbase);
                }
@@ -1102,9 +1102,6 @@ done:;
                        if ( !BER_BVISNULL( &el.el_nbase ) ) {
                                ch_free( &el.el_nbase.bv_val );
                        }
-                       if ( !BER_BVISNULL( &el.el_ndn ) ) {
-                               ch_free( el.el_ndn.bv_val );
-                       }
                        return -1;
                }
        }
@@ -2141,9 +2138,6 @@ monitor_back_destroy_limbo_entry(
        if ( el->el_a ) {
                attrs_free( el->el_a );
        }
-       if ( !BER_BVISNULL( &el->el_ndn ) ) {
-               ber_memfree( el->el_ndn.bv_val );
-       }
        if ( !BER_BVISNULL( &el->el_nbase ) ) {
                ber_memfree( el->el_nbase.bv_val );
        }
@@ -2401,7 +2395,7 @@ monitor_back_db_open(
 
                        case LIMBO_ATTRS:
                                rc = monitor_back_register_entry_attrs(
-                                               &el->el_ndn,
+                                               el->el_ndn,
                                                el->el_a,
                                                el->el_cb,
                                                &el->el_nbase,
@@ -2411,7 +2405,7 @@ monitor_back_db_open(
 
                        case LIMBO_CB:
                                rc = monitor_back_register_entry_callback(
-                                               &el->el_ndn,
+                                               el->el_ndn,
                                                el->el_cb,
                                                &el->el_nbase,
                                                el->el_scope,
@@ -2423,7 +2417,7 @@ monitor_back_db_open(
                                break;
 
                        case LIMBO_DATABASE:
-                               rc = monitor_back_register_database( el->el_be );
+                               rc = monitor_back_register_database( el->el_be, el->el_ndn );
                                break;
 
                        case LIMBO_OVERLAY_INFO:
index f09522db1ff77b7585c08eece0e32014d42a2a06..6b353563bf20402d35c8a4a435fe5ddb0cbebbe8 100644 (file)
@@ -145,7 +145,8 @@ monitor_back_register_backend LDAP_P((
        BackendInfo             *bi ));
 extern int
 monitor_back_register_database LDAP_P((
-       BackendDB               *be ));
+       BackendDB               *be,
+       struct berval   *ndn ));
 extern int
 monitor_back_register_overlay_info LDAP_P((
        slap_overinst           *on ));
@@ -157,7 +158,8 @@ monitor_back_register_backend_limbo LDAP_P((
        BackendInfo             *bi ));
 extern int
 monitor_back_register_database_limbo LDAP_P((
-       BackendDB               *be ));
+       BackendDB               *be,
+       struct berval   *ndn ));
 extern int
 monitor_back_register_overlay_info_limbo LDAP_P((
        slap_overinst           *on ));