From: Jaroslav Kysela Date: Mon, 8 Jan 2018 16:38:12 +0000 (+0100) Subject: otaepg: do not use uuid strings, use binary representation X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f086430e0cd71d5dff32aa1bf5b321e0ae6e076e;p=thirdparty%2Ftvheadend.git otaepg: do not use uuid strings, use binary representation --- diff --git a/src/epggrab.h b/src/epggrab.h index 9c76624ea..638f82e1c 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -221,7 +221,7 @@ struct epggrab_module_ext struct epggrab_ota_svc_link { - char *uuid; + tvh_uuid_t uuid; uint64_t last_tune_count; RB_ENTRY(epggrab_ota_svc_link) link; }; @@ -232,7 +232,7 @@ struct epggrab_ota_svc_link */ struct epggrab_ota_mux { - char *om_mux_uuid; ///< Soft-link to mux + tvh_uuid_t om_mux_uuid; ///< Soft-link to mux LIST_HEAD(,epggrab_ota_map) om_modules; ///< List of linked mods uint8_t om_done; ///< The full completion mark for this round diff --git a/src/epggrab/module/eit.c b/src/epggrab/module/eit.c index d6ced7625..f330e4534 100644 --- a/src/epggrab/module/eit.c +++ b/src/epggrab/module/eit.c @@ -920,7 +920,6 @@ _eit_callback eit_data_t *data; const char *cridauth, *charset; int cridauth_len, charset_len, data_len; - char ubuf[UUID_HEX_SIZE]; if (!epggrab_ota_running) return -1; @@ -1031,7 +1030,7 @@ svc_ok: /* Register this */ if (ota) - epggrab_ota_service_add(map, ota, idnode_uuid_as_str(&svc->s_id, ubuf), 1); + epggrab_ota_service_add(map, ota, &svc->s_id.in_uuid, 1); /* No point processing */ if (!LIST_FIRST(&svc->s_channels)) @@ -1193,7 +1192,7 @@ static int _eit_tune nxt = RB_NEXT(osl, link); /* rule: if 5 mux scans fail for this service, remove it */ if (osl->last_tune_count + 5 <= map->om_tune_count || - !(s = mpegts_service_find_by_uuid(osl->uuid))) { + !(s = mpegts_service_find_by_uuid0(&osl->uuid))) { epggrab_ota_service_del(map, om, osl, 1); } else { if (LIST_FIRST(&s->s_channels)) diff --git a/src/epggrab/module/psip.c b/src/epggrab/module/psip.c index 34c3f6cd5..351994a70 100644 --- a/src/epggrab/module/psip.c +++ b/src/epggrab/module/psip.c @@ -458,7 +458,6 @@ _psip_eit_callback mpegts_psi_table_state_t *st; idnode_list_mapping_t *ilm; th_subscription_t *ths; - char ubuf[UUID_HEX_SIZE]; /* Validate */ if (tableid != 0xcb) return -1; @@ -507,8 +506,7 @@ _psip_eit_callback /* Register this */ if (ps->ps_ota) - epggrab_ota_service_add(map, ps->ps_ota, - idnode_uuid_as_str(&svc->s_id, ubuf), 1); + epggrab_ota_service_add(map, ps->ps_ota, &svc->s_id.in_uuid, 1); /* For each associated channels */ LIST_FOREACH(ilm, &svc->s_channels, ilm_in1_link) { @@ -757,7 +755,7 @@ static int _psip_tune nxt = RB_NEXT(osl, link); /* rule: if 5 mux scans fail for this service, remove it */ if (osl->last_tune_count + 5 <= map->om_tune_count || - !(s = mpegts_service_find_by_uuid(osl->uuid))) { + !(s = mpegts_service_find_by_uuid0(&osl->uuid))) { epggrab_ota_service_del(map, om, osl, 1); } else { if (LIST_FIRST(&s->s_channels)) diff --git a/src/epggrab/otamux.c b/src/epggrab/otamux.c index 7fff8c14b..8346bc3a2 100644 --- a/src/epggrab/otamux.c +++ b/src/epggrab/otamux.c @@ -78,14 +78,14 @@ static void epggrab_ota_free ( epggrab_ota_head_t *head, epggrab_ota_mux_t *ota static int om_id_cmp ( epggrab_ota_mux_t *a, epggrab_ota_mux_t *b ) { - return strcmp(a->om_mux_uuid, b->om_mux_uuid); + return uuid_cmp(&a->om_mux_uuid, &b->om_mux_uuid); } static int om_mux_cmp ( epggrab_ota_mux_t *a, epggrab_ota_mux_t *b ) { - mpegts_mux_t *a1 = mpegts_mux_find(a->om_mux_uuid); - mpegts_mux_t *b1 = mpegts_mux_find(b->om_mux_uuid); + mpegts_mux_t *a1 = mpegts_mux_find0(&a->om_mux_uuid); + mpegts_mux_t *b1 = mpegts_mux_find0(&b->om_mux_uuid); if (a1 == NULL || b1 == NULL) { if (a1 == NULL && b1 == NULL) return 0; @@ -97,7 +97,7 @@ om_mux_cmp ( epggrab_ota_mux_t *a, epggrab_ota_mux_t *b ) static int om_svcl_cmp ( epggrab_ota_svc_link_t *a, epggrab_ota_svc_link_t *b ) { - return strcmp(a->uuid, b->uuid); + return uuid_cmp(&a->uuid, &b->uuid); } static int @@ -128,22 +128,19 @@ epggrab_ota_queue_one( epggrab_ota_mux_t *om ) void epggrab_ota_queue_mux( mpegts_mux_t *mm ) { - const char *id; epggrab_ota_mux_t *om; int epg_flag; - char ubuf[UUID_HEX_SIZE]; if (!mm) return; lock_assert(&global_lock); - id = idnode_uuid_as_str(&mm->mm_id, ubuf); epg_flag = mm->mm_is_epg(mm); if (epg_flag < 0 || epg_flag == MM_EPG_DISABLE) return; RB_FOREACH(om, &epggrab_ota_all, om_global_link) - if (!strcmp(om->om_mux_uuid, id)) { + if (!uuid_cmp(&om->om_mux_uuid, &mm->mm_id.in_uuid)) { if (epggrab_ota_queue_one(om)) epggrab_ota_kick(4); break; @@ -193,7 +190,7 @@ epggrab_ota_done ( epggrab_ota_mux_t *om, int reason ) if (om->om_save) epggrab_ota_save(om); - mm = mpegts_mux_find(om->om_mux_uuid); + mm = mpegts_mux_find0(&om->om_mux_uuid); mpegts_mux_nice_name(mm, name, sizeof(name)); tvhdebug(LS_EPGGRAB, "grab done for %s (%s)", name, reasons[reason]); @@ -289,12 +286,10 @@ epggrab_mux_start ( mpegts_mux_t *mm, void *p ) { epggrab_module_t *m; epggrab_ota_mux_t *ota; - char ubuf[UUID_HEX_SIZE]; - const char *uuid = idnode_uuid_as_str(&mm->mm_id, ubuf); /* Already started */ TAILQ_FOREACH(ota, &epggrab_ota_active, om_q_link) - if (!strcmp(ota->om_mux_uuid, uuid)) + if (!uuid_cmp(&ota->om_mux_uuid, &mm->mm_id.in_uuid)) return; /* Register all modules */ @@ -312,8 +307,7 @@ static void epggrab_mux_stop ( mpegts_mux_t *mm, void *p, int reason ) { epggrab_ota_mux_t *ota; - char ubuf[UUID_HEX_SIZE], name[256]; - const char *uuid = idnode_uuid_as_str(&mm->mm_id, ubuf); + char name[256]; int done = EPGGRAB_OTA_DONE_STOLEN; if (reason == SM_CODE_NO_INPUT) @@ -324,7 +318,7 @@ epggrab_mux_stop ( mpegts_mux_t *mm, void *p, int reason ) tvhtrace(LS_EPGGRAB, "mux %s (%p) stop", name, mm); } TAILQ_FOREACH(ota, &epggrab_ota_active, om_q_link) - if (!strcmp(ota->om_mux_uuid, uuid)) { + if (!uuid_cmp(&ota->om_mux_uuid, &mm->mm_id.in_uuid)) { epggrab_ota_done(ota, done); break; } @@ -346,10 +340,8 @@ epggrab_ota_register if (ota == NULL) { /* Find mux entry */ - char ubuf[UUID_HEX_SIZE]; - const char *uuid = idnode_uuid_as_str(&mm->mm_id, ubuf); SKEL_ALLOC(epggrab_ota_mux_skel); - epggrab_ota_mux_skel->om_mux_uuid = (char*)uuid; + epggrab_ota_mux_skel->om_mux_uuid = mm->mm_id.in_uuid; ota = RB_INSERT_SORTED(&epggrab_ota_all, epggrab_ota_mux_skel, om_global_link, om_id_cmp); if (!ota) { @@ -358,7 +350,6 @@ epggrab_ota_register tvhinfo(LS_EPGGRAB, "%s - registering mux for OTA EPG", buf); ota = epggrab_ota_mux_skel; SKEL_USED(epggrab_ota_mux_skel); - ota->om_mux_uuid = strdup(uuid); TAILQ_INSERT_SORTED(&epggrab_ota_pending, ota, om_q_link, om_mux_cmp); ota->om_q_type = EPGGRAB_OTA_MUX_PENDING; if (TAILQ_FIRST(&epggrab_ota_pending) == ota) @@ -509,7 +500,7 @@ epggrab_ota_kick_cb ( void *p ) next_one: /* Find the mux */ - mm = mpegts_mux_find(om->om_mux_uuid); + mm = mpegts_mux_find0(&om->om_mux_uuid); if (!mm) { epggrab_ota_free(&epggrab_ota_pending, om); goto done; @@ -697,8 +688,8 @@ epggrab_ota_service_trace ( epggrab_ota_mux_t *ota, if (!tvhtrace_enabled()) return; - mm = mpegts_mux_find(ota->om_mux_uuid); - svc = mpegts_service_find_by_uuid(svcl->uuid); + mm = mpegts_mux_find0(&ota->om_mux_uuid); + svc = mpegts_service_find_by_uuid0(&svcl->uuid); if (mm && svc) { mpegts_mux_nice_name(mm, buf, sizeof(buf)); tvhtrace(LS_EPGGRAB, "ota %s %s service %s", buf, op, svc->s_nicename); @@ -708,19 +699,18 @@ epggrab_ota_service_trace ( epggrab_ota_mux_t *ota, void epggrab_ota_service_add ( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota, - const char *uuid, int save ) + tvh_uuid_t *uuid, int save ) { epggrab_ota_svc_link_t *svcl; if (uuid == NULL || !atomic_get(&epggrab_ota_running)) return; SKEL_ALLOC(epggrab_svc_link_skel); - epggrab_svc_link_skel->uuid = (char *)uuid; + epggrab_svc_link_skel->uuid = *uuid; svcl = RB_INSERT_SORTED(&map->om_svcs, epggrab_svc_link_skel, link, om_svcl_cmp); if (svcl == NULL) { svcl = epggrab_svc_link_skel; SKEL_USED(epggrab_svc_link_skel); - svcl->uuid = strdup(uuid); if (save) ota->om_save = 1; epggrab_ota_service_trace(ota, svcl, "add new"); @@ -736,7 +726,6 @@ epggrab_ota_service_del ( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota, return; epggrab_ota_service_trace(ota, svcl, "delete"); RB_REMOVE(&map->om_svcs, svcl, link); - free(svcl->uuid); free(svcl); if (save) ota->om_save = 1; @@ -752,6 +741,7 @@ epggrab_ota_save ( epggrab_ota_mux_t *ota ) epggrab_ota_map_t *map; epggrab_ota_svc_link_t *svcl; htsmsg_t *e, *l, *l2, *c = htsmsg_create_map(); + char ubuf[UUID_HEX_SIZE]; ota->om_save = 0; htsmsg_add_u32(c, "complete", ota->om_complete); @@ -762,14 +752,13 @@ epggrab_ota_save ( epggrab_ota_mux_t *ota ) if (RB_FIRST(&map->om_svcs)) { l2 = htsmsg_create_list(); RB_FOREACH(svcl, &map->om_svcs, link) - if (svcl->uuid) - htsmsg_add_str(l2, NULL, svcl->uuid); + htsmsg_add_uuid(l2, NULL, &svcl->uuid); htsmsg_add_msg(e, "services", l2); } htsmsg_add_msg(l, NULL, e); } htsmsg_add_msg(c, "modules", l); - hts_settings_save(c, "epggrab/otamux/%s", ota->om_mux_uuid); + hts_settings_save(c, "epggrab/otamux/%s", uuid_get_hex(&ota->om_mux_uuid, ubuf)); htsmsg_destroy(c); } @@ -797,9 +786,8 @@ epggrab_ota_load_one } ota = calloc(1, sizeof(epggrab_ota_mux_t)); - ota->om_mux_uuid = strdup(uuid); + ota->om_mux_uuid = mm->mm_id.in_uuid; if (RB_INSERT_SORTED(&epggrab_ota_all, ota, om_global_link, om_id_cmp)) { - free(ota->om_mux_uuid); free(ota); return; } @@ -816,8 +804,11 @@ epggrab_ota_load_one RB_INIT(&map->om_svcs); map->om_module = mod; if ((l2 = htsmsg_get_list(e, "services")) != NULL) { - HTSMSG_FOREACH(f2, l2) - epggrab_ota_service_add(map, ota, htsmsg_field_get_str(f2), 0); + HTSMSG_FOREACH(f2, l2) { + tvh_uuid_t u; + if (htsmsg_field_get_uuid(f2, &u)) + epggrab_ota_service_add(map, ota, &u, 0); + } } LIST_INSERT_HEAD(&ota->om_modules, map, om_link); } @@ -912,7 +903,6 @@ epggrab_ota_free ( epggrab_ota_head_t *head, epggrab_ota_mux_t *ota ) epggrab_ota_service_del(map, ota, svcl, 0); free(map); } - free(ota->om_mux_uuid); free(ota->om_force_modname); free(ota); } diff --git a/src/epggrab/private.h b/src/epggrab/private.h index 7066394b8..25d8116df 100644 --- a/src/epggrab/private.h +++ b/src/epggrab/private.h @@ -167,7 +167,7 @@ void epggrab_ota_complete void epggrab_ota_service_add ( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota, - const char *uuid, int save ); + tvh_uuid_t *uuid, int save ); void epggrab_ota_service_del ( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota, diff --git a/src/htsmsg.c b/src/htsmsg.c index c3ed116aa..41b7b6f37 100644 --- a/src/htsmsg.c +++ b/src/htsmsg.c @@ -960,6 +960,36 @@ htsmsg_get_bin return htsmsg_field_get_bin(f, binp, lenp); } +/** + * + */ +int +htsmsg_field_get_uuid(htsmsg_field_t *f, tvh_uuid_t *u) +{ + const void *p; + size_t l; + int r; + + switch(f->hmf_type) { + case HMF_UUID: + memcpy(&u->bin, f->hmf_uuid, UUID_BIN_SIZE); + break; + case HMF_BIN: + case HMF_STR: + r = htsmsg_field_get_bin(f, &p, &l); + if (r == 0) { + if (l != UUID_BIN_SIZE) + return HTSMSG_ERR_CONVERSION_IMPOSSIBLE; + memcpy(u->bin, p, UUID_BIN_SIZE); + return 0; + } + /* Fall through */ + default: + return HTSMSG_ERR_CONVERSION_IMPOSSIBLE; + } + return 0; +} + /* * */ @@ -972,20 +1002,7 @@ htsmsg_get_uuid if((f = htsmsg_field_find(msg, name)) == NULL) return HTSMSG_ERR_FIELD_NOT_FOUND; - if(f->hmf_type == HMF_UUID) { - memcpy(u->bin, f->hmf_uuid, UUID_BIN_SIZE); - return 0; - } else { - const void *p; - size_t l; - int r = htsmsg_field_get_bin(f, &p, &l); - if (r == 0) { - if (l != UUID_BIN_SIZE) - return HTSMSG_ERR_FIELD_NOT_FOUND; - memcpy(u->bin, p, UUID_BIN_SIZE); - } - return r; - } + return htsmsg_field_get_uuid(f, u); } /* diff --git a/src/htsmsg.h b/src/htsmsg.h index 6484bb61e..cf6af603e 100644 --- a/src/htsmsg.h +++ b/src/htsmsg.h @@ -383,6 +383,12 @@ int htsmsg_field_get_dbl(htsmsg_field_t *f, double *dblp); const char *htsmsg_field_get_string(htsmsg_field_t *f); #define htsmsg_field_get_str(f) htsmsg_field_get_string(f) +/** + * Given the field \p f, return a uuid if it is of type string, otherwise + * return NULL + */ +int htsmsg_field_get_uuid(htsmsg_field_t *f, tvh_uuid_t *u); + /** * Get a field of type 'bin'. * diff --git a/src/input/mpegts.h b/src/input/mpegts.h index 3c072f12f..9493e0d0d 100644 --- a/src/input/mpegts.h +++ b/src/input/mpegts.h @@ -893,6 +893,9 @@ mpegts_mux_t *mpegts_mux_create0 mpegts_mux_create0(calloc(1, sizeof(mpegts_mux_t)), &mpegts_mux_class, uuid,\ mn, onid, tsid, conf) +static inline mpegts_mux_t *mpegts_mux_find0(tvh_uuid_t *uuid) + { return idnode_find0(uuid, &mpegts_mux_class, NULL); } + static inline mpegts_mux_t *mpegts_mux_find(const char *uuid) { return idnode_find(uuid, &mpegts_mux_class, NULL); } @@ -1135,6 +1138,9 @@ mpegts_service_find_by_pid ( mpegts_mux_t *mm, int pid ); void mpegts_service_update_slave_pids ( mpegts_service_t *t, int del ); +static inline mpegts_service_t *mpegts_service_find_by_uuid0(tvh_uuid_t *uuid) + { return idnode_find0(uuid, &mpegts_service_class, NULL); } + static inline mpegts_service_t *mpegts_service_find_by_uuid(const char *uuid) { return idnode_find(uuid, &mpegts_service_class, NULL); }