summaryrefslogtreecommitdiff
path: root/common/config-parser.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2006-04-04 21:07:18 +0000
committerStef Walter <stef@memberwebs.com>2006-04-04 21:07:18 +0000
commit1e735c038c86294df2ecfbd6a39abcfab4b3e8c3 (patch)
tree55dc3d3288d17d53fadf3471bb465fefb1b42b12 /common/config-parser.c
parent1fe43cb40fb54412528b7538718a457d2167c603 (diff)
Move functionality for parsing MIBs, SNMP into common files.
Diffstat (limited to 'common/config-parser.c')
-rw-r--r--common/config-parser.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/common/config-parser.c b/common/config-parser.c
index 905e019..c54b91e 100644
--- a/common/config-parser.c
+++ b/common/config-parser.c
@@ -314,3 +314,45 @@ cfg_parse_dir(const char* dirname, void* data)
return ret;
}
+
+const char*
+cfg_parse_uri (char *uri, char** scheme, char** host, char** user, char** path)
+{
+ char* t;
+
+ *scheme = NULL;
+ *host = NULL;
+ *user = NULL;
+ *path = NULL;
+
+ *scheme = strsep(&uri, ":");
+ if(uri == NULL || (uri[0] != '/' && uri[1] != '/'))
+ return "invalid uri";
+
+ uri += 2;
+ *host = strsep(&uri, "/");
+ if(*host[0])
+ {
+ /* Parse the community out from the host */
+ t = strchr(*host, '@');
+ if(t)
+ {
+ *t = 0;
+ *user = *host;
+ *host = t + 1;
+ }
+ }
+
+ if(!*host[0])
+ return "invalid uri: no host name found";
+
+ if(!uri || !uri[0] || !uri[1])
+ return "invalid uri: no path found";
+
+ *path = uri;
+
+ while((*path)[0] == '/')
+ (*path)++;
+
+ return NULL;
+}