summaryrefslogtreecommitdiff
path: root/common/config-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/config-parser.c')
-rw-r--r--common/config-parser.c34
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";