From: Pierangelo Masarati Date: Sat, 23 Jul 2005 11:32:10 +0000 (+0000) Subject: add infrastructure to register verbmasks; allow to register loglevels programmaticall... X-Git-Tag: OPENLDAP_AC_BP~235 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4c1339cf22e8fd2b8e5b3f4628faa04cbb8c4859;p=openldap add infrastructure to register verbmasks; allow to register loglevels programmatically; cleanup glue protos --- diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 08f8b04776..042d4b0d58 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -1854,11 +1854,12 @@ config_requires(ConfigArgs *c) { return(0); } +static slap_verbmasks *loglevel_ops; + static int -config_loglevel(ConfigArgs *c) { - int i; - char *next; - slap_verbmasks loglevel_ops[] = { +loglevel_init( void ) +{ + slap_verbmasks lo[] = { { BER_BVC("Any"), -1 }, { BER_BVC("Trace"), LDAP_DEBUG_TRACE }, { BER_BVC("Packets"), LDAP_DEBUG_PACKETS }, @@ -1878,6 +1879,39 @@ config_loglevel(ConfigArgs *c) { { BER_BVNULL, 0 } }; + return slap_verbmasks_init( &loglevel_ops, lo ); +} + +static slap_mask_t loglevel_ignore[] = { -1, 0 }; + +int +slap_loglevel_register( slap_mask_t m, struct berval *s ) +{ + int rc; + + if ( loglevel_ops == NULL ) { + loglevel_init(); + } + + rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore ); + + if ( rc != 0 ) { + Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%d, \"%s\") failed\n", + m, s->bv_val, 0 ); + } + + return rc; +} + +static int +config_loglevel(ConfigArgs *c) { + int i; + char *next; + + if ( loglevel_ops == NULL ) { + loglevel_init(); + } + if (c->op == SLAP_CONFIG_EMIT) { return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals ); } else if ( c->op == LDAP_MOD_DELETE ) { diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 992ae80809..484e8c5a20 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -802,6 +802,94 @@ mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) { return 0; } +int +slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v ) +{ + int i; + + assert( *vp == NULL ); + + for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) + ; + + *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) ); + + for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) { + ber_dupbv( &(*vp)[ i ].word, &v[ i ].word ); + *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask; + } + + BER_BVZERO( &(*vp)[ i ].word ); + + return 0; +} + +int +slap_verbmasks_destroy( slap_verbmasks *v ) +{ + int i; + + assert( v != NULL ); + + for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) { + ch_free( v[ i ].word.bv_val ); + } + + ch_free( v ); + + return 0; +} + +int +slap_verbmasks_append( + slap_verbmasks **vp, + slap_mask_t m, + struct berval *v, + slap_mask_t *ignore ) +{ + int i; + + if ( !m ) { + return 1; + } + + for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) { + if ( !(*vp)[ i ].mask ) continue; + + if ( ignore != NULL ) { + int j; + + for ( j = 0; ignore[ j ] != 0; j++ ) { + if ( (*vp)[ i ].mask == ignore[ j ] ) { + goto check_next; + } + } + } + + if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) { + if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) { + /* already set; ignore */ + return 0; + } + /* conflicts */ + return 1; + } + + if ( m & (*vp)[ i ].mask ) { + /* conflicts */ + return 1; + } +check_next:; + } + + *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) ); + ber_dupbv( &(*vp)[ i ].word, v ); + *((slap_mask_t *)&(*vp)[ i ].mask) = m; + BER_BVZERO( &(*vp)[ i + 1 ].word ); + + return 0; +} + int enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) { int i; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 9502b9b367..72823cb2c0 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -342,17 +342,9 @@ LDAP_SLAPD_F (int) backend_operational LDAP_P(( LDAP_SLAPD_V(BackendInfo) slap_binfo[]; -/* - * backglue.c - */ - -LDAP_SLAPD_F (int) glue_back_initialize( BackendInfo *bi ); -LDAP_SLAPD_F (int) glue_sub_init( void ); - /* * backover.c */ - LDAP_SLAPD_F (int) overlay_register LDAP_P(( slap_overinst *on )); LDAP_SLAPD_F (int) overlay_config LDAP_P(( BackendDB *be, const char *ov )); LDAP_SLAPD_F (void) overlay_destroy_one LDAP_P(( @@ -372,6 +364,11 @@ LDAP_SLAPD_F (int) overlay_op_walk LDAP_P(( slap_overinfo *oi, slap_overinst *on )); +/* + * bconfig.c + */ +LDAP_SLAPD_F (int) slap_loglevel_register LDAP_P (( slap_mask_t m, struct berval *s )); + /* * ch_malloc.c */ @@ -537,6 +534,10 @@ LDAP_SLAPD_F (int) mask_to_verbs LDAP_P(( slap_verbmasks *v, slap_mask_t m, BerVarray *bva )); LDAP_SLAPD_F (int) enum_to_verb LDAP_P(( slap_verbmasks *v, slap_mask_t m, struct berval *bv )); +LDAP_SLAPD_F (int) slap_verbmasks_init LDAP_P(( slap_verbmasks **vp, slap_verbmasks *v )); +LDAP_SLAPD_F (int) slap_verbmasks_destroy LDAP_P(( slap_verbmasks *v )); +LDAP_SLAPD_F (int) slap_verbmasks_append LDAP_P(( slap_verbmasks **vp, + slap_mask_t m, struct berval *v, slap_mask_t *ignore )); LDAP_SLAPD_F (int) bindconf_parse LDAP_P(( const char *word, slap_bindconf *bc )); LDAP_SLAPD_F (int) bindconf_unparse LDAP_P((