htsp: Fix config profile selection based on user ACL

This commit is contained in:
Jaroslav Kysela 2014-09-22 08:45:53 +02:00
parent 616e774031
commit 4bdcdd2f64

View file

@ -1229,6 +1229,39 @@ htsp_method_getEpgObject(htsp_connection_t *htsp, htsmsg_t *in)
return out;
}
static const char *
htsp_dvr_config_name( access_t *perm, const char *config_name )
{
dvr_config_t *cfg = NULL, *cfg2;
htsmsg_field_t *f;
const char *uuid;
lock_assert(&global_lock);
if (config_name == NULL)
return "";
if (perm->aa_dvrcfgs == NULL)
return config_uuid; /* no change */
config_uuid = config_uuid ?: "";
HTSMSG_FOREACH(f, perm->aa_dvrcfgs) {
uuid = htsmsg_field_get_str(f) ?: "";
if (strcmp(uuid, config_name) == 0)
return config_name;
cfg2 = dvr_config_entry_find_by_uuid(uuid);
if (cfg2 && strcmp(cfg2->dvr_config_name, config_name) == 0)
return uuid;
if (!cfg)
cfg = cfg2;
}
if (!cfg && perm->aa_username)
tvhlog(LOG_INFO, "htsp", "User '%s' has no valid dvr config in ACL, using default...", perm->aa_username);
return cfg ? idnode_uuid_as_str(&cfg->dvr_id) : NULL;
}
/**
* add a Dvrentry
*/
@ -1246,8 +1279,7 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
channel_t *ch = NULL;
/* Options */
if(!(dvr_config_name = htsmsg_get_str(in, "configName")))
dvr_config_name = "";
dvr_config_name = htsp_dvr_config_name(htsmsg_get_str(in, "configName")))
if(htsmsg_get_s64(in, "startExtra", &start_extra))
start_extra = 0;
if(htsmsg_get_s64(in, "stopExtra", &stop_extra))
@ -1435,8 +1467,7 @@ htsp_method_addAutorecEntry(htsp_connection_t *htsp, htsmsg_t *in)
/* Options */
if(!(title = htsmsg_get_str(in, "title")))
return htsp_error("Invalid arguments");
if(!(dvr_config_name = htsmsg_get_str(in, "configName")))
dvr_config_name = "";
dvr_config_name = htsp_dvr_config_name(htsmsg_get_str(in, "configName")))
if(!htsmsg_get_u32(in, "channelId", &u32))
ch = channel_find_by_id(u32);
if(htsmsg_get_u32(in, "maxDuration", &max_duration))