From 7ebdc4a8af43d1335e417087f755972a5bd36a5b Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 25 Apr 2016 13:27:20 +0200 Subject: [PATCH] service/subscription: do not allow to subscribe services without PMT --- src/input/mpegts/mpegts_service.c | 8 +++++++- src/service.c | 27 +++++++++++++++++++++------ src/service.h | 4 ++-- src/service_mapper.c | 2 +- src/streaming.c | 2 ++ src/tvheadend.h | 1 + 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/input/mpegts/mpegts_service.c b/src/input/mpegts/mpegts_service.c index fe502afbe..704369ee8 100644 --- a/src/input/mpegts/mpegts_service.c +++ b/src/input/mpegts/mpegts_service.c @@ -280,7 +280,7 @@ mpegts_service_config_save ( service_t *t, char *filename, size_t fsize ) /* * Service instance list */ -static void +static int mpegts_service_enlist ( service_t *t, tvh_input_t *ti, struct service_instance_list *sil, int flags, int weight ) @@ -293,6 +293,10 @@ mpegts_service_enlist assert(s->s_source_type == S_MPEG_TS); + /* invalid PMT */ + if (s->s_pmt_pid <= 0 || s->s_pmt_pid >= 8191) + return SM_CODE_INVALID_SERVICE; + /* Create instances */ m->mm_create_instances(m); @@ -322,6 +326,8 @@ mpegts_service_enlist service_instance_add(sil, t, mi->mi_instance, mi->mi_name, p, w); } + + return 0; } /* diff --git a/src/service.c b/src/service.c index 244c9b07a..f1e302e34 100644 --- a/src/service.c +++ b/src/service.c @@ -697,7 +697,7 @@ service_find_instance idnode_list_mapping_t *ilm; service_instance_t *si, *next; profile_t *pro = prch ? prch->prch_pro : NULL; - int enlisted; + int enlisted, r, r1; lock_assert(&global_lock); @@ -705,6 +705,7 @@ service_find_instance TAILQ_FOREACH(si, sil, si_link) si->si_mark = 1; + r = 0; if (ch) { if (!ch->ch_enabled) { *error = SM_CODE_SVC_NOT_ENABLED; @@ -718,20 +719,34 @@ service_find_instance pro->pro_svfilter == PROFILE_SVF_NONE || (pro->pro_svfilter == PROFILE_SVF_SD && service_is_sdtv(s)) || (pro->pro_svfilter == PROFILE_SVF_HD && service_is_hdtv(s))) { - s->s_enlist(s, ti, sil, flags, weight); - enlisted++; + r1 = s->s_enlist(s, ti, sil, flags, weight); + if (r1 == 0) + enlisted++; + else if (enlisted == 0) + r = r1; } } } if (enlisted == 0) { LIST_FOREACH(ilm, &ch->ch_services, ilm_in2_link) { s = (service_t *)ilm->ilm_in1; - if (s->s_is_enabled(s, flags)) - s->s_enlist(s, ti, sil, flags, weight); + if (s->s_is_enabled(s, flags)) { + r1 = s->s_enlist(s, ti, sil, flags, weight); + if (r1 == 0) + enlisted++; + else if (enlisted == 0) + r = r1; + } } } } else { - s->s_enlist(s, ti, sil, flags, weight); + r = s->s_enlist(s, ti, sil, flags, weight); + } + + if (r) { + if (*error < r) + *error = r; + return NULL; } /* Clean */ diff --git a/src/service.h b/src/service.h index a568ccd3b..0470d8352 100644 --- a/src/service.h +++ b/src/service.h @@ -310,8 +310,8 @@ typedef struct service { int (*s_is_enabled)(struct service *t, int flags); - void (*s_enlist)(struct service *s, struct tvh_input *ti, - service_instance_list_t *sil, int flags, int weight); + int (*s_enlist)(struct service *s, struct tvh_input *ti, + service_instance_list_t *sil, int flags, int weight); int (*s_start_feed)(struct service *s, int instance, int weight, int flags); diff --git a/src/service_mapper.c b/src/service_mapper.c index 72147f820..1b3ed70c5 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -392,7 +392,7 @@ service_mapper_thread ( void *aux ) subscription_unsubscribe(sub, UNSUBSCRIBE_FINAL); if(err) { - tvhinfo("service_mapper", "%s: failed [err %s]", s->s_nicename, err); + tvhinfo("service_mapper", "%s: failed [reason: %s]", s->s_nicename, err); service_mapper_stat.fail++; } else service_mapper_process(&smi->conf, s, NULL); diff --git a/src/streaming.c b/src/streaming.c index e6925091a..f6e846b9b 100644 --- a/src/streaming.c +++ b/src/streaming.c @@ -445,6 +445,8 @@ streaming_code2txt(int code) return N_("No service assigned to channel"); case SM_CODE_NO_ADAPTERS: return N_("No assigned adapters"); + case SM_CODE_INVALID_SERVICE: + return N_("Invalid service"); case SM_CODE_ABORTED: return N_("Aborted by user"); diff --git a/src/tvheadend.h b/src/tvheadend.h index 62cd39862..c11e75a56 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -530,6 +530,7 @@ typedef enum { #define SM_CODE_NO_SERVICE 207 #define SM_CODE_NO_VALID_ADAPTER 208 #define SM_CODE_NO_ADAPTERS 209 +#define SM_CODE_INVALID_SERVICE 210 #define SM_CODE_ABORTED 300 -- 2.47.3