torrentd

simple torrent daemon
git clone git@git.2f30.org/torrentd.git
Log | Files | Refs | LICENSE

commit 806f4e9f6b3ce9b2b643c016f41654296a784e2b
parent e8b189904e370ed3140d9ba6d482c3e8377a7b1c
Author: sin <sin@2f30.org>
Date:   Mon, 21 Dec 2015 15:51:56 +0000

Add parseurl() helper

Diffstat:
Mstorrent.h | 1+
Mutil.c | 28++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/storrent.h b/storrent.h @@ -75,3 +75,4 @@ void writeall(int, const void *, size_t); size_t strlcpy(char *, const char *, size_t); #undef strlcat size_t strlcat(char *, const char *, size_t); +char *parseurl(char *, char **, char **, char **); diff --git a/util.c b/util.c @@ -249,3 +249,31 @@ strlcat(char *dst, const char *src, size_t dsize) return(dlen + (src - osrc)); /* count does not include NUL */ } + +char * +parseurl(char *url, char **host, char **port, char **path) +{ + char *tmp, *p, *newurl; + + *host = *port = *path = NULL; + if (!(newurl = p = strdup(url))) + err(1, "strdup"); + if ((tmp = strstr(p, "://"))) + p = tmp + 3; + if (!*p) + return newurl; + *host = p; + if ((tmp = strchr(p, ':'))) { + p = tmp; + *p++ = '\0'; + *port = p; + } + if (!*p) + return newurl; + if ((tmp = strchr(p, '/'))) { + p = tmp; + *p++ = '\0'; + *path = p; + } + return newurl; +}