]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
channel: Return unique list of services
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Sun, 30 Sep 2018 17:41:02 +0000 (18:41 +0100)
committerperexg <perex@perex.cz>
Tue, 2 Oct 2018 14:03:16 +0000 (16:03 +0200)
Previously if multiple services were mapped to same channel then
we would get duplicate entries in the csv, such as a string of
'DVB-T,DVB-T,DVB-S,DVB-S'.

Now we return a unique list of 'DVB-T,DVB-S'.

src/channels.c

index 47efe783dccd2ddbe2825f55850e12e08b9d78ff..835fbbe8fd4028002b1bb53760375ff4a7f65fa2 100644 (file)
@@ -961,12 +961,26 @@ channel_get_source ( channel_t *ch, char *dst, size_t dstlen )
 {
   const char *s;
   idnode_list_mapping_t *ilm;
-  size_t l = 0;
+  /* Unique sorted string list since many services with
+   * same source may be mapped so we want to avoid
+   * 'DVB-S, DVB-S, DVB-S'.
+   */
+  string_list_t *sources = string_list_create();
+  char *csv;
   dst[0] = '\0';
   LIST_FOREACH(ilm, &ch->ch_services, ilm_in2_link)
     if ((s = service_get_source((service_t *)ilm->ilm_in1)))
-      tvh_strlcatf(dst, dstlen, l, "%s%s", l > 0 ? "," : "", s);
-  return l > 0 ? dst : NULL;
+      string_list_insert(sources, s);
+  /* We own the returned list */
+  csv = string_list_2_csv(sources, ',', 1);
+  string_list_destroy(sources);
+  if (csv) {
+    strlcpy(dst, csv, dstlen);
+    free(csv);
+    return dst;
+  } else {
+    return NULL;
+  }
 }
 
 static char *