Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ACL: Add possibility to exclude channel tags, fixes #2631
  • Loading branch information
perexg committed Jun 16, 2015
1 parent 78d9eda commit f2e0b82
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
49 changes: 35 additions & 14 deletions src/access.c
Expand Up @@ -431,10 +431,8 @@ access_dump_a(access_t *a)
HTSMSG_FOREACH(f, a->aa_chtags) {
channel_tag_t *ct = channel_tag_find_by_uuid(htsmsg_field_get_str(f) ?: "");
if (ct) {
if (first)
tvh_strlcatf(buf, sizeof(buf), l, ", tags=");
tvh_strlcatf(buf, sizeof(buf), l, "%s'%s'",
first ? "" : ",", ct->ct_name ?: "");
first ? ", tags=" : ",", ct->ct_name ?: "");
first = 0;
}
}
Expand Down Expand Up @@ -490,7 +488,7 @@ access_update(access_t *a, access_entry_t *ae)
if(pro && pro->pro_name[0] != '\0') {
if (a->aa_profiles == NULL)
a->aa_profiles = htsmsg_create_list();
htsmsg_add_str(a->aa_profiles, NULL, idnode_uuid_as_str(&pro->pro_id));
htsmsg_add_str_exclusive(a->aa_profiles, idnode_uuid_as_str(&pro->pro_id));
}
}

Expand All @@ -499,16 +497,33 @@ access_update(access_t *a, access_entry_t *ae)
if(dvr && dvr->dvr_config_name[0] != '\0') {
if (a->aa_dvrcfgs == NULL)
a->aa_dvrcfgs = htsmsg_create_list();
htsmsg_add_str(a->aa_dvrcfgs, NULL, idnode_uuid_as_str(&dvr->dvr_id));
htsmsg_add_str_exclusive(a->aa_dvrcfgs, idnode_uuid_as_str(&dvr->dvr_id));
}
}

LIST_FOREACH(ilm, &ae->ae_chtags, ilm_in1_link) {
channel_tag_t *ct = (channel_tag_t *)ilm->ilm_in2;
if(ct && ct->ct_name[0] != '\0') {
if (a->aa_chtags == NULL)
a->aa_chtags = htsmsg_create_list();
htsmsg_add_str(a->aa_chtags, NULL, idnode_uuid_as_str(&ct->ct_id));
if (ae->ae_chtags_exclude) {
channel_tag_t *ct;
TAILQ_FOREACH(ct, &channel_tags, ct_link) {
if(ct && ct->ct_name[0] != '\0') {
LIST_FOREACH(ilm, &ae->ae_chtags, ilm_in1_link) {
channel_tag_t *ct2 = (channel_tag_t *)ilm->ilm_in2;
if (ct == ct2) break;
}
if (ilm == NULL) {
if (a->aa_chtags == NULL)
a->aa_chtags = htsmsg_create_list();
htsmsg_add_str_exclusive(a->aa_chtags, idnode_uuid_as_str(&ct->ct_id));
}
}
}
} else {
LIST_FOREACH(ilm, &ae->ae_chtags, ilm_in1_link) {
channel_tag_t *ct = (channel_tag_t *)ilm->ilm_in2;
if(ct && ct->ct_name[0] != '\0') {
if (a->aa_chtags == NULL)
a->aa_chtags = htsmsg_create_list();
htsmsg_add_str_exclusive(a->aa_chtags, idnode_uuid_as_str(&ct->ct_id));
}
}
}

Expand Down Expand Up @@ -1293,7 +1308,7 @@ const idclass_t access_entry_class = {
.type = PT_STR,
.islist = 1,
.id = "profile",
.name = "Streaming Profile",
.name = "Streaming Profiles",
.set = access_entry_profile_set,
.get = access_entry_profile_get,
.list = profile_class_get_list,
Expand Down Expand Up @@ -1334,7 +1349,7 @@ const idclass_t access_entry_class = {
.type = PT_STR,
.islist = 1,
.id = "dvr_config",
.name = "DVR Config Profile",
.name = "DVR Config Profiles",
.set = access_entry_dvr_config_set,
.get = access_entry_dvr_config_get,
.list = dvr_entry_class_config_name_list,
Expand Down Expand Up @@ -1379,11 +1394,17 @@ const idclass_t access_entry_class = {
.name = "Max Channel Num",
.off = offsetof(access_entry_t, ae_chmax),
},
{
.type = PT_BOOL,
.id = "channel_tag_exclude",
.name = "Exclude Channel Tags",
.off = offsetof(access_entry_t, ae_chtags_exclude),
},
{
.type = PT_STR,
.islist = 1,
.id = "channel_tag",
.name = "Channel Tag",
.name = "Channel Tags",
.set = access_entry_chtag_set,
.get = access_entry_chtag_get,
.list = channel_tag_class_get_list,
Expand Down
1 change: 1 addition & 0 deletions src/access.h
Expand Up @@ -102,6 +102,7 @@ typedef struct access_entry {
uint64_t ae_chmin;
uint64_t ae_chmax;

int ae_chtags_exclude;
idnode_list_head_t ae_chtags;

uint32_t ae_rights;
Expand Down
19 changes: 19 additions & 0 deletions src/htsmsg.c
Expand Up @@ -265,6 +265,25 @@ htsmsg_add_str(htsmsg_t *msg, const char *name, const char *str)
f->hmf_str = strdup(str);
}

/*
*
*/
void
htsmsg_add_str_exclusive(htsmsg_t *msg, const char *str)
{
htsmsg_field_t *f;

assert(msg->hm_islist);

TAILQ_FOREACH(f, &msg->hm_fields, hmf_link) {
assert(f->hmf_type == HMF_STR);
if (strcmp(f->hmf_str, str) == 0)
return;
}

htsmsg_add_str(msg, NULL, str);
}

/*
*
*/
Expand Down
5 changes: 5 additions & 0 deletions src/htsmsg.h
Expand Up @@ -153,6 +153,11 @@ htsmsg_set_s32(htsmsg_t *msg, const char *name, int32_t s32)
*/
void htsmsg_add_str(htsmsg_t *msg, const char *name, const char *str);

/**
* Add a string field to a list only once.
*/
void htsmsg_add_str_exclusive(htsmsg_t *msg, const char *str);

/**
* Add/update a string field
*/
Expand Down
7 changes: 4 additions & 3 deletions src/webui/static/app/acleditor.js
Expand Up @@ -9,15 +9,16 @@ tvheadend.acleditor = function(panel, index)
'streaming,adv_streaming,htsp_streaming,' +
'profile,conn_limit_type,conn_limit,' +
'dvr,htsp_dvr,all_dvr,all_rw_dvr,' +
'dvr_config,channel_min,channel_max,channel_tag,comment';
'dvr_config,channel_min,channel_max,' +
'channel_tag_exclude,channel_tag,comment';

var list2 = 'enabled,username,password,prefix,' +
'webui,admin,' +
'streaming,adv_streaming,htsp_streaming,' +
'profile,conn_limit_type,conn_limit,' +
'dvr,htsp_dvr,all_dvr,all_rw_dvr,' +
'failed_dvr,dvr_config,channel_min,channel_max,channel_tag,' +
'comment';
'failed_dvr,dvr_config,channel_min,channel_max,' +
'channel_tag_exclude,channel_tag,comment';

tvheadend.idnode_grid(panel, {
url: 'api/access/entry',
Expand Down

0 comments on commit f2e0b82

Please sign in to comment.