From 294fe5eefa19797fd690eaf0d34c74928be534fc Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 1 Aug 2014 14:34:53 +0200 Subject: [PATCH] IPTV: create sane mux name without username/password in URL --- src/input/mpegts/iptv/iptv_mux.c | 53 ++++++++++++++++++++++++++-- src/input/mpegts/iptv/iptv_private.h | 1 + 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/input/mpegts/iptv/iptv_mux.c b/src/input/mpegts/iptv/iptv_mux.c index fc4b81ee..c6de0ba4 100644 --- a/src/input/mpegts/iptv/iptv_mux.c +++ b/src/input/mpegts/iptv/iptv_mux.c @@ -26,6 +26,54 @@ extern const idclass_t mpegts_mux_class; extern const idclass_t mpegts_mux_instance_class; +static int +iptv_mux_url_set ( void *p, const void *v ) +{ + iptv_mux_t *im = p; + const char *str = v; + char *buf, port[16] = ""; + size_t len; + url_t url; + + if (strcmp(str, im->mm_iptv_url ?: "")) { + if (str == NULL || *str == '\0') { + free(im->mm_iptv_url); + free(im->mm_iptv_url_sane); + im->mm_iptv_url = NULL; + im->mm_iptv_url_sane = NULL; + return 1; + } + memset(&url, 0, sizeof(url)); + if (!urlparse(str ?: "", &url)) { + free(im->mm_iptv_url); + free(im->mm_iptv_url_sane); + im->mm_iptv_url = str ? strdup(str) : NULL; + if (im->mm_iptv_url) { + len = strlen(url.scheme) + 3 + + strlen(url.host) + 1 + + /* port */ 16 + + strlen(url.path) + 1 + + strlen(url.query) + 2; + buf = alloca(len); + if (url.port) + snprintf(port, sizeof(port), "%d", url.port); + snprintf(buf, len, "%s%s%s%s%s%s", + url.scheme ?: "", url.scheme ? "://" : "", + url.host ?: "", + url.path ?: "", url.query ? "?" : "", + url.query); + im->mm_iptv_url_sane = strdup(buf); + } else { + im->mm_iptv_url_sane = NULL; + } + urlreset(&url); + return 1; + } + urlreset(&url); + } + return 0; +} + const idclass_t iptv_mux_class = { .ic_super = &mpegts_mux_class, @@ -37,6 +85,7 @@ const idclass_t iptv_mux_class = .id = "iptv_url", .name = "URL", .off = offsetof(iptv_mux_t, mm_iptv_url), + .set = iptv_mux_url_set, }, { .type = PT_STR, @@ -93,8 +142,8 @@ static void iptv_mux_display_name ( mpegts_mux_t *mm, char *buf, size_t len ) { iptv_mux_t *im = (iptv_mux_t*)mm; - if(im->mm_iptv_url) - strncpy(buf, im->mm_iptv_url, len); + if(im->mm_iptv_url_sane) + strncpy(buf, im->mm_iptv_url_sane, len); else *buf = 0; } diff --git a/src/input/mpegts/iptv/iptv_private.h b/src/input/mpegts/iptv/iptv_private.h index cc32319d..8ae27fa4 100644 --- a/src/input/mpegts/iptv/iptv_private.h +++ b/src/input/mpegts/iptv/iptv_private.h @@ -78,6 +78,7 @@ struct iptv_mux int mm_iptv_fd; udp_connection_t *mm_iptv_connection; char *mm_iptv_url; + char *mm_iptv_url_sane; char *mm_iptv_interface; int mm_iptv_atsc;