From: Howard Chu Date: Mon, 9 May 2005 05:02:01 +0000 (+0000) Subject: Table-driven config X-Git-Tag: OPENLDAP_AC_BP~688 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bd635078686b675e559534856c0d3ea277317628;p=openldap Table-driven config --- diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 3309eba85a..dbe93b61f1 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -25,6 +25,7 @@ #include #include "lutil.h" #include "slap.h" +#include "config.h" /* A modify request on a particular entry */ typedef struct modinst { @@ -1994,42 +1995,93 @@ syncprov_operational( return SLAP_CB_CONTINUE; } +enum { + SP_CHKPT = 1, + SP_SESSL +}; + +static ConfigDriver sp_cf_gen; + +static ConfigTable spcfg[] = { + { "syncprov-checkpoint", "ops> bd_info; + slap_overinst *on = (slap_overinst *)c->bi; syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private; - - if ( strcasecmp( argv[ 0 ], "syncprov-checkpoint" ) == 0 ) { - if ( argc != 3 ) { - fprintf( stderr, "%s: line %d: wrong number of arguments in " - "\"syncprov-checkpoint \"\n", fname, lineno ); - return -1; + int rc = 0; + + if ( c->op == SLAP_CONFIG_EMIT ) { + switch ( c->type ) { + case SP_CHKPT: + if ( si->si_chkops || si->si_chktime ) { + struct berval bv; + bv.bv_len = sprintf( c->msg, "%d %d", + si->si_chkops, si->si_chktime ); + bv.bv_val = c->msg; + value_add_one( &c->rvalue_vals, &bv ); + } else { + rc = 1; + } + break; + case SP_SESSL: + if ( si->si_logs ) { + c->value_int = si->si_logs->sl_size; + } else { + rc = 1; + } + break; } - si->si_chkops = atoi( argv[1] ); - si->si_chktime = atoi( argv[2] ) * 60; - return 0; - - } else if ( strcasecmp( argv[0], "syncprov-sessionlog" ) == 0 ) { - sessionlog *sl; - int size; - if ( argc != 2 ) { - fprintf( stderr, "%s: line %d: wrong number of arguments in " - "\"syncprov-sessionlog \"\n", fname, lineno ); - return -1; + return rc; + } else if ( c->op == LDAP_MOD_DELETE ) { + switch ( c->type ) { + case SP_CHKPT: + si->si_chkops = 0; + si->si_chktime = 0; + break; + case SP_SESSL: + if ( si->si_logs ) + si->si_logs->sl_size = 0; + else + rc = LDAP_NO_SUCH_ATTRIBUTE; + break; } - size = atoi( argv[1] ); + return rc; + } + switch ( c->type ) { + case SP_CHKPT: + si->si_chkops = atoi( c->argv[1] ); + si->si_chktime = atoi( c->argv[2] ) * 60; + break; + case SP_SESSL: { + sessionlog *sl; + int size = c->value_int; + if ( size < 0 ) { - fprintf( stderr, - "%s: line %d: session log size %d is negative\n", - fname, lineno, size ); - return -1; + sprintf( c->msg, "%s size %d is negative", + c->argv[0], size ); + Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 ); + return ARG_BAD_CONF; } sl = si->si_logs; if ( !sl ) { @@ -2042,10 +2094,10 @@ syncprov_db_config( si->si_logs = sl; } sl->sl_size = size; - return 0; + } + break; } - - return SLAP_CONF_UNKNOWN; + return rc; } /* Cheating - we have no thread pool context for these functions, @@ -2344,7 +2396,6 @@ syncprov_init() syncprov.on_bi.bi_type = "syncprov"; syncprov.on_bi.bi_db_init = syncprov_db_init; - syncprov.on_bi.bi_db_config = syncprov_db_config; syncprov.on_bi.bi_db_destroy = syncprov_db_destroy; syncprov.on_bi.bi_db_open = syncprov_db_open; syncprov.on_bi.bi_db_close = syncprov_db_close; @@ -2361,6 +2412,11 @@ syncprov_init() syncprov.on_bi.bi_extended = syncprov_op_extended; syncprov.on_bi.bi_operational = syncprov_operational; + syncprov.on_bi.bi_cf_ocs = spocs; + + rc = config_register_schema( spcfg, spocs ); + if ( rc ) return rc; + return overlay_register( &syncprov ); }