From 1e735c038c86294df2ecfbd6a39abcfab4b3e8c3 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 4 Apr 2006 21:07:18 +0000 Subject: Move functionality for parsing MIBs, SNMP into common files. --- daemon/config.c | 65 ++++++++++++--------------------------------------------- 1 file changed, 13 insertions(+), 52 deletions(-) (limited to 'daemon/config.c') diff --git a/daemon/config.c b/daemon/config.c index 9a5320b..d95de8a 100644 --- a/daemon/config.c +++ b/daemon/config.c @@ -44,6 +44,8 @@ #include #include +#include + #include "rrdbotd.h" #include "config-parser.h" @@ -189,68 +191,27 @@ config_done(config_ctx* ctx) ctx->timeout = 0; } -static void -parse_uri(char *uri, char** scheme, char** host, - char** user, char** path, config_ctx* ctx) -{ - /* Copy only for error messages as we mess with original */ - char* copy = strdup(uri); - char* t; - - *host = NULL; - *path = NULL; - *user = NULL; - - *scheme = strsep(&uri, ":"); - if(uri == NULL) - errx(2, "%s: invalid poll uri (scheme invalid): %s", ctx->confname, copy); - - if((uri[0] != '/' && uri[1] != '/')) - errx(2, "%s: invalid poll uri (scheme invalid): %s", ctx->confname, copy); - - uri += 2; - *host = strsep(&uri, "/"); - if(*host[0]) - { - /* Parse the user name out from the host */ - t = strchr(*host, '@'); - if(t) - { - *t = 0; - *user = *host; - *host = t + 1; - } - } - - if(!*host[0]) - errx(2, "%s: invalid poll uri (no hostname found): %s", ctx->confname, copy); - - if(!uri || !uri[0] || !uri[1]) - errx(2, "%s: invalid poll uri (no pathname found): %s", ctx->confname, copy); - - *path = uri; - - while((*path)[0] == '/') - (*path)++; - - /* This copy only for error messages */ - free(copy); -} - static rb_item* parse_item(const char* field, char* uri, config_ctx *ctx) { rb_item *ritem; rb_host *rhost; + const char *msg; + char* copy; + char* scheme; char* host; char* user; - char* scheme; char* path; /* Parse the SNMP URI */ - parse_uri(uri, &scheme, &host, &user, &path, ctx); - ASSERT(scheme && host && path); + copy = strdup(uri); + msg = cfg_parse_uri(uri, &scheme, &host, &user, &path); + if(msg) + errx(2, "%s: %s: %s", ctx->confname, msg, copy); + free(copy); + + ASSERT(host && path); /* TODO: SNMP version support */ @@ -299,7 +260,7 @@ parse_item(const char* field, char* uri, config_ctx *ctx) ritem->vtype = VALUE_UNSET; /* And parse the OID */ - if(rb_snmp_parse_mib(path, &(ritem->snmpfield)) == -1) + if(mib_parse(path, &(ritem->snmpfield)) == -1) errx(2, "%s: invalid MIB: %s", ctx->confname, path); rb_messagex(LOG_DEBUG, "parsed MIB into oid: %s -> %s", path, -- cgit v1.2.3