Add BackendInfo.bi_extra for backend custom APIs

Use bi_extra for back-monitor entry points. Backends should never
directly reference each other's symbols.
This commit is contained in:
Howard Chu 2006-09-13 11:38:51 +00:00
parent dd74acbf74
commit 2bfe79fe88
5 changed files with 76 additions and 29 deletions

View File

@ -675,14 +675,6 @@ bdb_back_initialize(
bi->bi_connection_init = 0;
bi->bi_connection_destroy = 0;
/*
* initialize monitor stuff
*/
rc = bdb_monitor_initialize();
if ( rc ) {
return rc;
}
rc = bdb_back_init_cf( bi );
return rc;

View File

@ -25,8 +25,6 @@
#include "lutil.h"
#include "back-bdb.h"
#ifdef SLAPD_MONITOR
#include "../back-monitor/back-monitor.h"
static ObjectClass *oc_olmBDBDatabase;
@ -200,22 +198,23 @@ bdb_monitor_free(
return SLAP_CB_CONTINUE;
}
#endif /* SLAPD_MONITOR */
/*
* call from within bdb_initialize()
*/
int
bdb_monitor_initialize( void )
{
#ifdef SLAPD_MONITOR
int i, code;
const char *err;
BackendInfo *bi;
static int bdb_monitor_initialized = 0;
/* register schema here; if compiled as dynamic object,
* must be loaded __after__ back_monitor.la */
bi = backend_info("monitor");
if ( !bi )
return -1;
/* register schema here */
if ( bdb_monitor_initialized++ ) {
return 0;
@ -322,7 +321,6 @@ done_oc:;
ldap_memfree( oc );
}
#endif /* SLAPD_MONITOR */
return 0;
}
@ -333,9 +331,9 @@ done_oc:;
int
bdb_monitor_init( BackendDB *be )
{
#ifdef SLAPD_MONITOR
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
#endif /* SLAPD_MONITOR */
if ( bdb_monitor_initialize() == LDAP_SUCCESS ) {
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
}
return 0;
}
@ -346,20 +344,29 @@ bdb_monitor_init( BackendDB *be )
int
bdb_monitor_open( BackendDB *be )
{
#ifdef SLAPD_MONITOR
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;
monitor_extra_t *mbe;
if ( !SLAP_DBMONITORING( be ) ) {
return 0;
}
{
BackendInfo *mi = backend_info( "monitor" );
if ( !mi || !mi->bi_extra ) {
SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
return 0;
}
mbe = mi->bi_extra;
}
/* don't bother if monitor is not configured */
if ( !monitor_back_is_configured() ) {
if ( !mbe->is_configured() ) {
static int warning = 0;
if ( warning++ == 0 ) {
@ -490,7 +497,7 @@ bdb_monitor_open( BackendDB *be )
cb->mc_free = bdb_monitor_free;
cb->mc_private = (void *)bdb;
rc = monitor_back_register_entry_attrs( NULL, a, cb,
rc = mbe->register_entry_attrs( NULL, a, cb,
base, LDAP_SCOPE_SUBORDINATE, filter );
cleanup:;
@ -521,9 +528,6 @@ cleanup:;
}
return rc;
#else /* !SLAPD_MONITOR */
return 0;
#endif /* SLAPD_MONITOR */
}
/*
@ -532,11 +536,16 @@ cleanup:;
int
bdb_monitor_close( BackendDB *be )
{
#ifdef SLAPD_MONITOR
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_filter ) ) {
monitor_back_unregister_entry_callback( NULL,
BackendInfo *mi = backend_info( "monitor" );
monitor_extra_t *mbe;
if ( !mi || !mi->bi_extra )
return 0;
mbe = mi->bi_extra;
mbe->unregister_entry_callback( NULL,
(monitor_callback_t *)bdb->bi_monitor.bdm_cb,
&bdb->bi_monitor.bdm_nbase,
bdb->bi_monitor.bdm_scope,
@ -548,7 +557,6 @@ bdb_monitor_close( BackendDB *be )
memset( &bdb->bi_monitor, 0, sizeof( bdb->bi_monitor ) );
}
#endif /* SLAPD_MONITOR */
return 0;
}

View File

@ -268,6 +268,33 @@ extern BackendDB *be_monitor;
/* increase this bufsize if entries in string form get too big */
#define BACKMONITOR_BUFSIZE 8192
typedef int (monitor_cbfunc)( struct berval *ndn, monitor_callback_t *cb,
struct berval *base, int scope, struct berval *filter );
typedef int (monitor_cbafunc)( struct berval *ndn, Attribute *a,
monitor_callback_t *cb,
struct berval *base, int scope, struct berval *filter );
typedef struct monitor_extra_t {
int (*is_configured)(void);
monitor_subsys_t * (*get_subsys)( const char *name );
monitor_subsys_t * (*get_subsys_by_dn)( struct berval *ndn, int sub );
int (*register_subsys)( monitor_subsys_t *ms );
int (*register_entry)( Entry *e, monitor_callback_t *cb,
monitor_subsys_t *ms, unsigned long flags );
int (*register_entry_parent)( Entry *e, monitor_callback_t *cb,
monitor_subsys_t *ms, unsigned long flags,
struct berval *base, int scope, struct berval *filter );
monitor_cbafunc *register_entry_attrs;
monitor_cbfunc *register_entry_callback;
int (*unregister_entry)( struct berval *ndn );
monitor_cbfunc *unregister_entry_parent;
monitor_cbafunc *unregister_entry_attrs;
monitor_cbfunc *unregister_entry_callback;
} monitor_extra_t;
LDAP_END_DECL
#include "proto-back-monitor.h"

View File

@ -44,6 +44,23 @@ BackendDB *be_monitor;
static struct monitor_subsys_t **monitor_subsys;
static int monitor_subsys_opened;
static monitor_info_t monitor_info;
static const monitor_extra_t monitor_extra = {
monitor_back_is_configured,
monitor_back_get_subsys,
monitor_back_get_subsys_by_dn,
monitor_back_register_subsys,
monitor_back_register_entry,
monitor_back_register_entry_parent,
monitor_back_register_entry_attrs,
monitor_back_register_entry_callback,
monitor_back_unregister_entry,
monitor_back_unregister_entry_parent,
monitor_back_unregister_entry_attrs,
monitor_back_unregister_entry_callback
};
/*
* subsystem data
@ -1978,6 +1995,8 @@ monitor_back_initialize(
bi->bi_connection_init = 0;
bi->bi_connection_destroy = 0;
bi->bi_extra = (void *)&monitor_extra;
/*
* configuration objectClasses (fake)
*/

View File

@ -2193,7 +2193,8 @@ struct slap_backend_info {
unsigned int bi_nDB; /* number of databases of this type */
struct ConfigOCs *bi_cf_ocs;
char **bi_obsolete_names;
void *bi_private; /* anything the backend type needs */
void *bi_extra; /* backend type-specific APIs */
void *bi_private; /* backend type-specific config data */
LDAP_STAILQ_ENTRY(slap_backend_info) bi_next ;
};