diff --git a/src/ezstream.c b/src/ezstream.c index 8b49081..e4cf42f 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -74,7 +74,6 @@ typedef struct tag_ID3Tag { char genre; } ID3Tag; -int urlParse(const char *, char **, unsigned short *, char **); char * buildReencodeCommand(const char *, const char *, metadata_t); metadata_t getMetadata(const char *); FILE * openResource(stream_t, const char *, int *, metadata_t *, @@ -118,57 +117,6 @@ sig_handler(int sig) } #endif /* HAVE_SIGNALS */ -int -urlParse(const char *url, char **hostname, unsigned short *port, - char **mountname) -{ - const char *p1, *p2, *p3; - char tmpPort[6] = ""; - size_t hostsiz, mountsiz; - const char *errstr; - - if (strncmp(url, "http://", strlen("http://")) != 0) { - log_error("invalid : not an HTTP address"); - return (0); - } - - p1 = url + strlen("http://"); - p2 = strchr(p1, ':'); - if (p2 == NULL) { - log_error("invalid : missing port"); - return (0); - } - hostsiz = (p2 - p1) + 1; - if (hostsiz <= 1) { - log_error("invalid : missing host"); - return (0); - } - *hostname = xmalloc(hostsiz); - strlcpy(*hostname, p1, hostsiz); - - p2++; - p3 = strchr(p2, '/'); - if (p3 == NULL || p3 - p2 >= (int)sizeof(tmpPort)) { - log_error("invalid : mountpoint missing, or port number too long"); - xfree(*hostname); - return (0); - } - - strlcpy(tmpPort, p2, (p3 - p2) + 1UL); - *port = (unsigned short)strtonum(tmpPort, 1LL, (long long)USHRT_MAX, &errstr); - if (errstr) { - log_error("invalid : port: %s is %s", tmpPort, errstr); - xfree(*hostname); - return (0); - } - - mountsiz = strlen(p3) + 1; - *mountname = xmalloc(mountsiz); - strlcpy(*mountname, p3, mountsiz); - - return (1); -} - char * buildReencodeCommand(const char *extension, const char *fileName, metadata_t mdata) diff --git a/src/util.c b/src/util.c index 63b67a1..77fa20d 100644 --- a/src/util.c +++ b/src/util.c @@ -29,6 +29,7 @@ #ifdef HAVE_LANGINFO_H # include #endif +#include #ifdef HAVE_LOCALE_H # include #endif @@ -279,3 +280,54 @@ shellQuote(const char *in) return (out); } + +int +urlParse(const char *url, char **hostname, unsigned short *port, + char **mountname) +{ + const char *p1, *p2, *p3; + char tmpPort[6] = ""; + size_t hostsiz, mountsiz; + const char *errstr; + + if (strncmp(url, "http://", strlen("http://")) != 0) { + log_error("invalid : not an HTTP address"); + return (0); + } + + p1 = url + strlen("http://"); + p2 = strchr(p1, ':'); + if (p2 == NULL) { + log_error("invalid : missing port"); + return (0); + } + hostsiz = (p2 - p1) + 1; + if (hostsiz <= 1) { + log_error("invalid : missing host"); + return (0); + } + *hostname = xmalloc(hostsiz); + strlcpy(*hostname, p1, hostsiz); + + p2++; + p3 = strchr(p2, '/'); + if (p3 == NULL || p3 - p2 >= (int)sizeof(tmpPort)) { + log_error("invalid : mountpoint missing, or port number too long"); + xfree(*hostname); + return (0); + } + + strlcpy(tmpPort, p2, (p3 - p2) + 1UL); + *port = (unsigned short)strtonum(tmpPort, 1LL, (long long)USHRT_MAX, &errstr); + if (errstr) { + log_error("invalid : port: %s is %s", tmpPort, errstr); + xfree(*hostname); + return (0); + } + + mountsiz = strlen(p3) + 1; + *mountname = xmalloc(mountsiz); + strlcpy(*mountname, p3, mountsiz); + + return (1); +} diff --git a/src/util.h b/src/util.h index fef6323..eb18756 100644 --- a/src/util.h +++ b/src/util.h @@ -26,5 +26,6 @@ char * CHARtoUTF8(const char *, int); char * UTF8toCHAR(const char *, int); char * replaceString(const char *, const char *, const char *); char * shellQuote(const char *); +int urlParse(const char *, char **, unsigned short *, char **); #endif /* __UTIL_H__ */