Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV: create sane mux name without username/password in URL
  • Loading branch information
perexg committed Aug 1, 2014
1 parent 47bb0ef commit 294fe5e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/input/mpegts/iptv/iptv_mux.c
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/input/mpegts/iptv/iptv_private.h
Expand Up @@ -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;
Expand Down

0 comments on commit 294fe5e

Please sign in to comment.