diff options
author | Stef Walter <stef@memberwebs.com> | 2006-03-11 03:55:14 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2006-03-11 03:55:14 +0000 |
commit | e5a80cae26f015e59e3fce266aae41306251b1c7 (patch) | |
tree | 9b04b6a7e2d9bfbd1ff5fb7ee4632a8accfb66b8 | |
parent | c2b4a3070f2063ab0fd2aa14d5dd247f8566c1e0 (diff) |
Hook in conf file parsing.
-rw-r--r-- | src/bsnmp-regex.c | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/src/bsnmp-regex.c b/src/bsnmp-regex.c index a2696df..2d20655 100644 --- a/src/bsnmp-regex.c +++ b/src/bsnmp-regex.c @@ -23,7 +23,7 @@ static struct lmodule *module; static const struct asn_oid oid_regex = OIDX_regexData; /* the Object Resource registration index */ -static u_int reg_index; +static u_int reg_index = 0; /* Various match types */ enum { @@ -54,7 +54,7 @@ static struct data_entry_list entries = TAILQ_HEAD_INITIALIZER(entries); static uint32_t entry_count = 0; /* configuration */ -static const char *config_file = NULL; +static u_char *regex_config = NULL; static char *config_memory = NULL; /* ----------------------------------------------------------------------------- @@ -269,18 +269,19 @@ config_read () FILE *f = NULL; long len; - if (!config_file) - config_file = DEFAULT_CONFIG; + /* XXXXXXXXXXXxx Move DEFAULT_CONFIG settings to init */ + if (!regex_config || !regex_config[0]) + regex_config = DEFAULT_CONFIG; - f = fopen (config_file, "r"); + f = fopen (regex_config, "r"); if (f == NULL) { - emsg ("couldn't open config file: %s", config_file); + emsg ("couldn't open config file: %s", regex_config); return -1; } /* Figure out size */ if (fseek (f, 0, SEEK_END) == -1 || (len = ftell (f)) == -1 || fseek (f, 0, SEEK_SET) == -1) { - emsg ("couldn't seek config file: %s", config_file); + emsg ("couldn't seek config file: %s", regex_config); return -1; } @@ -293,7 +294,7 @@ config_read () /* And read in one block */ if(fread(config_memory, 1, len, f) != len) { - emsg ("couldn't read config file: %s", config_file); + emsg ("couldn't read config file: %s", regex_config); free (config_memory); config_memory = NULL; return -1; @@ -342,7 +343,7 @@ config_parse () continue; t = strchr (t, ':'); - if (t != NULL) { + if (t == NULL) { emsg ("invalid config line: %s", p); return -1; } @@ -374,8 +375,44 @@ int op_regexconfig (struct snmp_context *ctx, struct snmp_value *value, u_int sub, u_int iidx, enum snmp_op op) { - fprintf(stderr, "op_regexconfig\n"); - return SNMP_ERR_NOT_WRITEABLE; + asn_subid_t which = value->var.subs[sub - 1]; + int r; + + switch (which) { + case LEAF_regexConfig: + + if (op == SNMP_OP_GET) + return string_get (value, regex_config, -1); + + /* Remainder only at initialization */ + if (community != COMM_INITIALIZE) + return SNMP_ERR_NOT_WRITEABLE; + + switch (op) { + case SNMP_OP_SET: + if ((r = string_save (value, ctx, -1, ®ex_config)) != SNMP_ERR_NOERROR) + return r; + if (config_parse () < 0) { + string_rollback (ctx, ®ex_config); + return SNMP_ERR_GENERR; + } + break; + case SNMP_OP_COMMIT: + string_commit (ctx); + break; + case SNMP_OP_ROLLBACK: + string_rollback (ctx, ®ex_config); + break; + default: + ASSERT(0); + break; + } + + return SNMP_ERR_NOERROR; + } + + ASSERT(0); + return -1; } int @@ -484,9 +521,13 @@ module_init (struct lmodule *mod, int argc, char *argv[]) if (argc != 0) { syslog(LOG_ERR, "bad number of arguments for %s", __func__); - return (EINVAL); + return EINVAL; } + regex_config = strdup (""); + if (!regex_config) + return ENOMEM; + return 0; } @@ -494,14 +535,19 @@ module_init (struct lmodule *mod, int argc, char *argv[]) static void module_start (void) { - reg_index = or_register(&oid_regex, "The MIB for regex data.", module); + reg_index = or_register (&oid_regex, "The MIB for regex data.", module); } /* Called, when the module is to be unloaded after it was successfully loaded */ static int module_fini (void) { - or_unregister(reg_index); + if (reg_index) + or_unregister (reg_index); + + ASSERT (regex_config); + free (regex_config); + return 0; } |