]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/monitor.c
Merge remote-tracking branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / servers / slapd / back-ldap / monitor.c
index 54a6a6d7f5aa7f89f4ad273e9d1b8f58d56c39a0..c54913536d5417a39fda66b122d60460bbf9ef29 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2012 The OpenLDAP Foundation.
+ * Copyright 2003-2013 The OpenLDAP Foundation.
  * Portions Copyright 1999-2003 Howard Chu.
  * Portions Copyright 2000-2003 Pierangelo Masarati.
  * All rights reserved.
@@ -37,6 +37,9 @@
 static ObjectClass             *oc_olmLDAPDatabase;
 static ObjectClass             *oc_olmLDAPConnection;
 
+static ObjectClass             *oc_monitorContainer;
+static ObjectClass             *oc_monitorCounterObject;
+
 static AttributeDescription    *ad_olmDbURIList;
 static AttributeDescription    *ad_olmDbOperations;
 static AttributeDescription    *ad_olmDbBoundDN;
@@ -155,6 +158,16 @@ static struct {
        { NULL }
 };
 
+static struct {
+       char            *name;
+       ObjectClass     **oc;
+}              s_moc[] = {
+       { "monitorContainer", &oc_monitorContainer },
+       { "monitorCounterObject", &oc_monitorCounterObject },
+
+       { NULL }
+};
+
 static struct {
        char            *desc;
        ObjectClass     **oc;
@@ -377,6 +390,7 @@ ldap_back_monitor_subsystem_destroy(
  */
 
 struct ldap_back_monitor_conn_arg {
+       Operation *op;
        monitor_subsys_t *ms;
        Entry **ep;
 };
@@ -467,29 +481,18 @@ ldap_back_monitor_conn_entry(
 {
        Entry *e;
        monitor_entry_t         *mp;
+       monitor_extra_t *mbe = arg->op->o_bd->bd_info->bi_extra;
        char buf[SLAP_TEXT_BUFLEN];
        char *ptr;
-       struct berval bv, dn, ndn;
+       struct berval bv;
        int i;
 
-       e = entry_alloc();
-
        bv.bv_val = buf;
        bv.bv_len = snprintf( bv.bv_val, SLAP_TEXT_BUFLEN,
                "cn=Connection %lu", lc->lc_connid );
 
-       build_new_dn( &dn, &arg->ms->mss_dn, &bv, NULL );
-       build_new_dn( &ndn, &arg->ms->mss_ndn, &bv, NULL );
-
-       e->e_name = dn;
-       e->e_nname = ndn;
-
-       bv.bv_val += 3;
-       bv.bv_len -= 3;
-       attr_merge_normalize_one( e, slap_schema.si_ad_cn, &bv, NULL );
-
-       BER_BVSTR( &bv, "monitorContainer" );
-       attr_merge_normalize_one( e, slap_schema.si_ad_objectClass, &bv, NULL );
+       e = mbe->entry_stub( &arg->ms->mss_dn, &arg->ms->mss_ndn, &bv,
+               oc_monitorContainer, NULL, NULL );
 
        attr_merge_normalize_one( e, ad_olmDbBoundDN, &lc->lc_bound_ndn, NULL );
 
@@ -511,7 +514,7 @@ ldap_back_monitor_conn_entry(
        attr_merge_normalize_one( e, ad_olmDbPeerAddress, &bv, NULL );
        ch_free( bv.bv_val );
 
-       mp = monitor_entrypriv_create();
+       mp = mbe->entrypriv_create();
        e->e_private = mp;
        mp->mp_info = arg->ms;
        mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
@@ -545,6 +548,7 @@ ldap_back_monitor_conn_create(
        li = (ldapinfo_t *)ms->mss_private;
 
        arg = ch_calloc( 1, sizeof(struct ldap_back_monitor_conn_arg) );
+       arg->op = op;
        arg->ep = ep;
        arg->ms = ms;
 
@@ -574,14 +578,12 @@ ldap_back_monitor_conn_init(
        monitor_subsys_t        *ms )
 {
        ldapinfo_t      *li = (ldapinfo_t *) ms->mss_private;
-       monitor_info_t  *mi;
        monitor_extra_t *mbe;
 
        Entry           *e;
        int             rc;
 
        assert( be != NULL );
-       mi = (monitor_info_t *) be->be_private;
        mbe = (monitor_extra_t *) be->bd_info->bi_extra;
 
        ms->mss_dn = ms->mss_ndn = li->li_monitor_info.lmi_ndn;
@@ -589,9 +591,8 @@ ldap_back_monitor_conn_init(
        ms->mss_create = ldap_back_monitor_conn_create;
        ms->mss_destroy = ldap_back_monitor_subsystem_destroy;
 
-       e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn,
-               &ms->mss_rdn,
-               mi->mi_oc_monitorContainer, mi, NULL, NULL );
+       e = mbe->entry_stub( &ms->mss_dn, &ms->mss_ndn,
+               &ms->mss_rdn, oc_monitorContainer, NULL, NULL );
        if ( e == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "ldap_back_monitor_conn_init: "
@@ -733,7 +734,6 @@ ldap_back_monitor_ops_init(
 {
        ldapinfo_t      *li = (ldapinfo_t *) ms->mss_private;
 
-       monitor_info_t  *mi;
        monitor_extra_t *mbe;
        Entry           *e, *parent;
        int             rc;
@@ -742,16 +742,14 @@ ldap_back_monitor_ops_init(
 
        assert( be != NULL );
 
-       mi = (monitor_info_t *) be->be_private;
        mbe = (monitor_extra_t *) be->bd_info->bi_extra;
 
        ms->mss_dn = ms->mss_ndn = li->li_monitor_info.lmi_ndn;
        ms->mss_rdn = li->li_monitor_info.lmi_ops_rdn;
        ms->mss_destroy = ldap_back_monitor_subsystem_destroy;
 
-       parent = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn,
-               &ms->mss_rdn,
-               mi->mi_oc_monitorContainer, mi, NULL, NULL );
+       parent = mbe->entry_stub( &ms->mss_dn, &ms->mss_ndn,
+               &ms->mss_rdn, oc_monitorContainer, NULL, NULL );
        if ( parent == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "ldap_back_monitor_ops_init: "
@@ -779,9 +777,9 @@ ldap_back_monitor_ops_init(
                monitor_callback_t *cb;
                struct ldap_back_monitor_op_counter *counter;
 
-               e = monitor_entry_stub( &parent->e_name, &parent->e_nname,
+               e = mbe->entry_stub( &parent->e_name, &parent->e_nname,
                        &ldap_back_monitor_op[op].rdn,
-                       mi->mi_oc_monitorCounterObject, mi, NULL, NULL );
+                       oc_monitorCounterObject, NULL, NULL );
                if ( e == NULL ) {
                        Debug( LDAP_DEBUG_ANY,
                                "ldap_back_monitor_ops_init: "
@@ -902,6 +900,17 @@ ldap_back_monitor_initialize( void )
                }
        }
 
+       for ( i = 0; s_moc[ i ].name != NULL; i++ ) {
+               *s_moc[i].oc = oc_find( s_moc[ i ].name );
+               if ( ! *s_moc[i].oc ) {
+                       Debug( LDAP_DEBUG_ANY,
+                               "ldap_back_monitor_initialize: failed to find objectClass (%s)\n",
+                               s_moc[ i ].name, 0, 0 );
+                       return 5;
+
+               }
+       }
+
        return ( ldap_back_monitor_initialized_failure = LDAP_SUCCESS );
 }
 
@@ -990,7 +999,7 @@ ldap_back_monitor_db_open( BackendDB *be )
        mss->mss_open = ldap_back_monitor_conn_init;
        mss->mss_private = li;
 
-       if ( mbe->register_subsys( mss ) )
+       if ( mbe->register_subsys_late( mss ) )
        {
                Debug( LDAP_DEBUG_ANY,
                        "ldap_back_monitor_db_open: "
@@ -1005,7 +1014,7 @@ ldap_back_monitor_db_open( BackendDB *be )
        mss->mss_open = ldap_back_monitor_ops_init;
        mss->mss_private = li;
 
-       if ( mbe->register_subsys( mss ) )
+       if ( mbe->register_subsys_late( mss ) )
        {
                Debug( LDAP_DEBUG_ANY,
                        "ldap_back_monitor_db_open: "