idnode: handle short uuid identifiers better
This commit is contained in:
parent
1dc009a94d
commit
e1add61aa8
13 changed files with 47 additions and 22 deletions
|
@ -554,7 +554,7 @@ channel_create0
|
|||
{
|
||||
lock_assert(&global_lock);
|
||||
|
||||
idnode_insert(&ch->ch_id, uuid, idc);
|
||||
idnode_insert(&ch->ch_id, uuid, idc, IDNODE_SHORT_UUID);
|
||||
if (RB_INSERT_SORTED(&channels, ch, ch_link, ch_id_cmp)) {
|
||||
tvherror("channel", "id collision!");
|
||||
abort();
|
||||
|
|
|
@ -160,7 +160,7 @@ esfilter_create
|
|||
abort();
|
||||
}
|
||||
lock_assert(&global_lock);
|
||||
idnode_insert(&esf->esf_id, uuid, c);
|
||||
idnode_insert(&esf->esf_id, uuid, c, 0);
|
||||
if (conf)
|
||||
idnode_load(&esf->esf_id, conf);
|
||||
if (ESF_CLASS_IS_VALID(cls))
|
||||
|
|
37
src/idnode.c
37
src/idnode.c
|
@ -58,6 +58,14 @@ in_cmp(const idnode_t *a, const idnode_t *b)
|
|||
return memcmp(a->in_uuid, b->in_uuid, sizeof(a->in_uuid));
|
||||
}
|
||||
|
||||
static int
|
||||
in_cmp_short(const idnode_t *a, const idnode_t *b)
|
||||
{
|
||||
if (a->in_class != b->in_class)
|
||||
return memcmp(a->in_uuid, b->in_uuid, sizeof(a->in_uuid));
|
||||
return idnode_get_short_uuid(b) - idnode_get_short_uuid(a);
|
||||
}
|
||||
|
||||
/* **************************************************************************
|
||||
* Registration
|
||||
* *************************************************************************/
|
||||
|
@ -98,20 +106,35 @@ idnode_done(void)
|
|||
*
|
||||
*/
|
||||
int
|
||||
idnode_insert(idnode_t *in, const char *uuid, const idclass_t *class)
|
||||
idnode_insert(idnode_t *in, const char *uuid, const idclass_t *class, int flags)
|
||||
{
|
||||
idnode_t *c;
|
||||
idnode_t *c, skel;
|
||||
lock_assert(&global_lock);
|
||||
tvh_uuid_t u;
|
||||
if (uuid_init_bin(&u, uuid))
|
||||
return -1;
|
||||
memcpy(in->in_uuid, u.bin, sizeof(in->in_uuid));
|
||||
int retries = 5;
|
||||
|
||||
in->in_class = class;
|
||||
do {
|
||||
|
||||
if (uuid_init_bin(&u, uuid))
|
||||
return -1;
|
||||
memcpy(in->in_uuid, u.bin, sizeof(in->in_uuid));
|
||||
|
||||
c = NULL;
|
||||
if (flags & IDNODE_SHORT_UUID) {
|
||||
if(hex2bin(skel.in_uuid, sizeof(skel.in_uuid), uuid))
|
||||
return -1;
|
||||
c = RB_FIND(&idnodes, &skel, in_link, in_cmp_short);
|
||||
}
|
||||
|
||||
if (c == NULL)
|
||||
c = RB_INSERT_SORTED(&idnodes, in, in_link, in_cmp);
|
||||
|
||||
} while (c != NULL && --retries > 0);
|
||||
|
||||
c = RB_INSERT_SORTED(&idnodes, in, in_link, in_cmp);
|
||||
if(c != NULL) {
|
||||
fprintf(stderr, "Id node collision\n");
|
||||
fprintf(stderr, "Id node collision%s\n",
|
||||
(flags & IDNODE_SHORT_UUID) ? " (short)" : "");
|
||||
abort();
|
||||
}
|
||||
tvhtrace("idnode", "insert node %s", idnode_uuid_as_str(in));
|
||||
|
|
|
@ -113,7 +113,9 @@ typedef LIST_HEAD(,idnode_filter_ele) idnode_filter_t;
|
|||
void idnode_init(void);
|
||||
void idnode_done(void);
|
||||
|
||||
int idnode_insert(idnode_t *in, const char *uuid, const idclass_t *idc);
|
||||
#define IDNODE_SHORT_UUID (1<<0)
|
||||
|
||||
int idnode_insert(idnode_t *in, const char *uuid, const idclass_t *idc, int flags);
|
||||
void idnode_unlink(idnode_t *in);
|
||||
|
||||
uint32_t idnode_get_short_uuid (const idnode_t *in);
|
||||
|
|
|
@ -32,7 +32,7 @@ tvh_hardware_create0
|
|||
tvh_hardware_t *th = o;
|
||||
|
||||
/* Create node */
|
||||
if (idnode_insert(&th->th_id, uuid, idc)) {
|
||||
if (idnode_insert(&th->th_id, uuid, idc, 0)) {
|
||||
free(o);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ linuxdvb_lnb_create0
|
|||
/* Setup static entries */
|
||||
for (i = 0; i < ARRAY_SIZE(linuxdvb_lnb_all); i++)
|
||||
if (!linuxdvb_lnb_all[i].ld_id.in_class)
|
||||
idnode_insert(&linuxdvb_lnb_all[i].ld_id, NULL, &linuxdvb_lnb_class);
|
||||
idnode_insert(&linuxdvb_lnb_all[i].ld_id, NULL, &linuxdvb_lnb_class, 0);
|
||||
|
||||
/* Find */
|
||||
if (name) {
|
||||
|
|
|
@ -732,7 +732,7 @@ linuxdvb_satconf_create
|
|||
TAILQ_INIT(&ls->ls_elements);
|
||||
|
||||
/* Create node */
|
||||
if (idnode_insert(&ls->ls_id, uuid, lst->idc)) {
|
||||
if (idnode_insert(&ls->ls_id, uuid, lst->idc, 0)) {
|
||||
free(ls);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1113,7 +1113,7 @@ linuxdvb_satconf_ele_create0
|
|||
{
|
||||
htsmsg_t *e;
|
||||
linuxdvb_satconf_ele_t *lse = calloc(1, sizeof(*lse));
|
||||
if (idnode_insert(&lse->lse_id, uuid, &linuxdvb_satconf_ele_class)) {
|
||||
if (idnode_insert(&lse->lse_id, uuid, &linuxdvb_satconf_ele_class, 0)) {
|
||||
free(lse);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1210,7 +1210,7 @@ linuxdvb_diseqc_create0
|
|||
htsmsg_t *conf, const char *type, linuxdvb_satconf_ele_t *parent )
|
||||
{
|
||||
/* Insert */
|
||||
if (idnode_insert(&ld->ld_id, uuid, idc)) {
|
||||
if (idnode_insert(&ld->ld_id, uuid, idc, 0)) {
|
||||
free(ld);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1024,7 +1024,7 @@ mpegts_input_create0
|
|||
( mpegts_input_t *mi, const idclass_t *class, const char *uuid,
|
||||
htsmsg_t *c )
|
||||
{
|
||||
idnode_insert(&mi->ti_id, uuid, class);
|
||||
idnode_insert(&mi->ti_id, uuid, class, 0);
|
||||
LIST_INSERT_HEAD(&tvh_inputs, (tvh_input_t*)mi, ti_link);
|
||||
|
||||
/* Defaults */
|
||||
|
|
|
@ -54,7 +54,7 @@ mpegts_mux_instance_create0
|
|||
( mpegts_mux_instance_t *mmi, const idclass_t *class, const char *uuid,
|
||||
mpegts_input_t *mi, mpegts_mux_t *mm )
|
||||
{
|
||||
idnode_insert(&mmi->mmi_id, uuid, class);
|
||||
idnode_insert(&mmi->mmi_id, uuid, class, 0);
|
||||
// TODO: does this need to be an idnode?
|
||||
|
||||
/* Setup links */
|
||||
|
@ -881,7 +881,7 @@ mpegts_mux_create0
|
|||
{
|
||||
char buf[256];
|
||||
|
||||
idnode_insert(&mm->mm_id, uuid, class);
|
||||
idnode_insert(&mm->mm_id, uuid, class, 0);
|
||||
|
||||
/* Enabled by default */
|
||||
mm->mm_enabled = 1;
|
||||
|
|
|
@ -259,7 +259,7 @@ mpegts_mux_sched_create ( const char *uuid, htsmsg_t *conf )
|
|||
}
|
||||
|
||||
/* Insert node */
|
||||
idnode_insert(&mms->mms_id, uuid, &mpegts_mux_sched_class);
|
||||
idnode_insert(&mms->mms_id, uuid, &mpegts_mux_sched_class, 0);
|
||||
|
||||
/* Add to list */
|
||||
LIST_INSERT_HEAD(&mpegts_mux_sched_all, mms, mms_link);
|
||||
|
|
|
@ -281,7 +281,7 @@ mpegts_network_create0
|
|||
char buf[256];
|
||||
|
||||
/* Setup idnode */
|
||||
idnode_insert(&mn->mn_id, uuid, idc);
|
||||
idnode_insert(&mn->mn_id, uuid, idc, 0);
|
||||
|
||||
/* Default callbacks */
|
||||
mn->mn_display_name = mpegts_network_display_name;
|
||||
|
|
|
@ -233,7 +233,7 @@ satip_satconf_create0
|
|||
|
||||
if (conf)
|
||||
uuid = htsmsg_get_str(conf, "uuid");
|
||||
if (idnode_insert(&sfc->sfc_id, uuid, &satip_satconf_class)) {
|
||||
if (idnode_insert(&sfc->sfc_id, uuid, &satip_satconf_class, 0)) {
|
||||
free(sfc);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -827,7 +827,7 @@ service_create0
|
|||
( service_t *t, const idclass_t *class, const char *uuid,
|
||||
int source_type, htsmsg_t *conf )
|
||||
{
|
||||
idnode_insert(&t->s_id, uuid, class);
|
||||
idnode_insert(&t->s_id, uuid, class, 0);
|
||||
|
||||
lock_assert(&global_lock);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue