From 54c751ffc4f79dcd916b4dffe690f59615c7146d Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sat, 24 Oct 2009 14:10:37 +0000 Subject: Add back support for ports in snmp urls. * Note that for urls like: snmp://host1,host2:161/xxx the port applies to both hosts. --- common/config-parser.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'common/config-parser.c') diff --git a/common/config-parser.c b/common/config-parser.c index fbb9c70..881838f 100644 --- a/common/config-parser.c +++ b/common/config-parser.c @@ -356,9 +356,24 @@ cfg_parse_dir(const char* dirname, void* data) return ret; } +static int +looks_like_port (const char *port) +{ + if (!port || !*port) + return 0; + + while (*port) { + if (!isdigit(*port)) + return 0; + ++port; + } + + return 1; +} + const char* -cfg_parse_uri (char *uri, char** scheme, char** host, char** user, - char** path, char** query) +cfg_parse_uri (char *uri, char** scheme, char** host, char **port, + char** user, char** path, char** query) { char* t; @@ -367,6 +382,7 @@ cfg_parse_uri (char *uri, char** scheme, char** host, char** user, *user = NULL; *path = NULL; *query = NULL; + *port = NULL; *scheme = strsep(&uri, ":"); if(uri == NULL || (uri[0] != '/' && uri[1] != '/')) @@ -374,9 +390,10 @@ cfg_parse_uri (char *uri, char** scheme, char** host, char** user, uri += 2; *host = strsep(&uri, "/"); + + /* Parse the community out from the host */ if(*host[0]) { - /* Parse the community out from the host */ t = strchr(*host, '@'); if(t) { @@ -386,6 +403,17 @@ cfg_parse_uri (char *uri, char** scheme, char** host, char** user, } } + /* Parse out the port from the uri */ + if(*host[0]) + { + t = strrchr(*host, ':'); + if(t && looks_like_port(t + 1)) + { + *t = 0; + *port = t + 1; + } + } + if(!*host[0]) return "invalid uri: no host name found"; -- cgit v1.2.3