]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
IPTV: create sane mux name without username/password in URL
authorJaroslav Kysela <perex@perex.cz>
Fri, 1 Aug 2014 12:34:53 +0000 (14:34 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 1 Aug 2014 12:34:53 +0000 (14:34 +0200)
src/input/mpegts/iptv/iptv_mux.c
src/input/mpegts/iptv/iptv_private.h

index fc4b81ee41724a29f3c64e4e0d7307e56ec9ab89..c6de0ba4ca5750e4323dba910e6ef4bd9d21d43a 100644 (file)
 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;
 }
index cc32319de39b1fd988d614cc5ec72a108ca0a85b..8ae27fa4335958e79b2d88271d64a1c8ee15cfb6 100644 (file)
@@ -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;