size_t l;
int64_t chnum2, vlcprog;
const char *url, *name, *logo, *epgid, *tags;
- char url2[512], custom[512], name2[128], buf[32], *n;
+ char custom[512], name2[128], buf[32], *n;
url = htsmsg_get_str(item, "m3u-url");
htsbuf_queue_flush(&q);
}
http_arg_flush(&args);
- l = 0;
- tvh_strlcatf(url2, sizeof(url2), l, "%s://", u.scheme);
- if (u.user && u.user[0] && u.pass && u.pass[0])
- tvh_strlcatf(url2, sizeof(url2), l, "%s:%s@", u.user, u.pass);
- tvh_strlcatf(url2, sizeof(url2), l, "%s", u.host);
- if (u.port > 0)
- tvh_strlcatf(url2, sizeof(url2), l, ":%d", u.port);
- if (u.path)
- tvh_strlcatf(url2, sizeof(url2), l, "%s", u.path);
- if (u.query)
- tvh_strlcatf(url2, sizeof(url2), l, "?%s", u.query);
- url = url2;
+ if (!urlrecompose(&u))
+ url = u.raw;
}
skip_url:
iptv_url_set ( char **url, char **sane_url, const char *str, int allow_file, int allow_pipe )
{
const char *x;
- char *buf, port[16] = "";
- size_t len;
url_t u;
if (strcmp(str ?: "", *url ?: "") == 0)
return 1;
}
urlinit(&u);
- if (!urlparse(str, &u)) {
- len = (u.scheme ? strlen(u.scheme) + 3 : 0) +
- (u.host ? strlen(u.host) + 1 : 0) +
- /* port */ 16 +
- (u.path ? strlen(u.path) + 1 : 0) +
- (u.query ? strlen(u.query) + 2 : 0);
- buf = alloca(len);
- if (u.port > 0 && u.port <= 65535)
- snprintf(port, sizeof(port), ":%d", u.port);
- snprintf(buf, len, "%s%s%s%s%s%s%s",
- u.scheme ?: "", u.scheme ? "://" : "",
- u.host ?: "", port,
- u.path ?: "", (u.query && u.query[0]) ? "?" : "",
- u.query ?: "");
- iptv_url_set0(url, sane_url, str, buf);
+ if (!urlparse(str, &u) && !urlrecompose(&u)) {
+ iptv_url_set0(url, sane_url, u.raw, str);
urlreset(&u);
return 1;
} else {
dst->raw = strdup(src->raw);
}
+int
+urlrecompose( url_t *url )
+{
+ size_t len;
+ char *raw, port[16];
+
+ len = strlen(url->scheme) + 4 +
+ (url->user && url->pass ?
+ ((url->user ? strlen(url->user) + 2 : 0) +
+ (url->pass ? strlen(url->pass) : 0)) : 0
+ ) +
+ strlen(url->host) +
+ (url->port > 0 ? 6 : 0) +
+ (url->path ? strlen(url->path) : 0) +
+ (url->query ? strlen(url->query) : 0);
+ raw = malloc(len);
+ if (raw == NULL)
+ return -ENOMEM;
+ if (url->port > 0 && url->port <= 65535)
+ snprintf(port, sizeof(port), ":%d", url->port);
+ snprintf(raw, len, "%s%s%s%s%s%s%s",
+ url->scheme ?: "", url->scheme ? "://" : "",
+ url->host ?: "", port,
+ url->path ?: "",
+ (url->query && url->query[0]) ? "?" : "",
+ url->query ?: "");
+ url->raw = raw;
+ return 0;
+}
+
/* Use liburiparser if available */
#if ENABLE_URIPARSER
#include <uriparser/Uri.h>
int urlparse ( const char *str, url_t *url );
void urlparse_done ( void );
void urlcopy ( url_t *dst, const url_t *src );
+int urlrecompose ( url_t *url );
#endif