diff options
author | Stef Walter <stef@memberwebs.com> | 2009-10-24 14:10:37 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2009-10-24 14:10:37 +0000 |
commit | 54c751ffc4f79dcd916b4dffe690f59615c7146d (patch) | |
tree | 33664990f79460c120a6e00ba88026664cc46abb /common/config-parser.c | |
parent | b6c94d893237f4c339a1ad9ede7b809811001f77 (diff) |
Add back support for ports in snmp urls.
* Note that for urls like: snmp://host1,host2:161/xxx the
port applies to both hosts.
Diffstat (limited to 'common/config-parser.c')
-rw-r--r-- | common/config-parser.c | 34 |
1 files changed, 31 insertions, 3 deletions
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"; |