* Simple function to respond with an error
*/
static htsmsg_t *
-htsp_error(const char *err)
+htsp_error(htsp_connection_t *htsp, const char *errstr)
{
htsmsg_t *r = htsmsg_create_map();
- htsmsg_add_str(r, "error", err);
+ htsmsg_add_str(r, "error", tvh_gettext_lang(htsp->htsp_language, errstr));
return r;
}
#define HTSP_CHECK_CHANNEL_ACCESS(htsp, ch)\
if (!htsp_user_access_channel(htsp, ch))\
- return htsp_error("User cannot access this channel");
+ return htsp_error(htsp, N_("User cannot access this channel"));
static const char *
htsp_dvr_config_name( htsp_connection_t *htsp, const char *config_name )
fd = tvh_open(path, O_RDONLY, 0);
tvhlog(LOG_DEBUG, "htsp", "Opening file %s -- %s", path, fd < 0 ? strerror(errno) : "OK");
if(fd == -1)
- return htsp_error("Unable to open file");
+ return htsp_error(htsp, N_("Unable to open file"));
}
htsp_file_t *hf = calloc(1, sizeof(htsp_file_t));
const char *name, *lang;
if(htsmsg_get_u32(in, "htspversion", &v))
- return htsp_error("Missing argument 'htspversion'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if((name = htsmsg_get_str(in, "clientname")) == NULL)
- return htsp_error("Missing argument 'clientname'");
+ return htsp_error(htsp, N_("Invalid arguments"));
r = htsmsg_create_map();
default:
htsmsg_destroy(args2);
htsmsg_destroy(ret);
- return htsp_error("Bad request");
+ return htsp_error(htsp, N_("Bad request"));
}
} else if (resp) {
/* Output response */
int64_t bfree, bused, btotal;
if (dvr_get_disk_space(&bfree, &bused, &btotal))
- return htsp_error("Unable to stat path");
+ return htsp_error(htsp, N_("Unable to stat path"));
out = htsmsg_create_map();
htsmsg_add_s64(out, "freediskspace", bfree);
struct tm serverLocalTime;
if(gettimeofday(&tv, &tz) == -1)
- return htsp_error("Unable to get system time");
+ return htsp_error(htsp, N_("Unable to get system time"));
if (!localtime_r(&tv.tv_sec, &serverLocalTime))
- return htsp_error("Unable to get system local time");
+ return htsp_error(htsp, N_("Unable to get system local time"));
#if defined(HAS_GMTOFF)
tz_offset = - serverLocalTime.tm_gmtoff / (60);
#else
// NB: This will be a day out when GMT offsets >= 13hrs or <11 hrs apply
struct tm serverGmTime;
if (!gmtime_r(&tv.tv_sec, &serverGmTime))
- return htsp_error("Unable to get system gmt");
+ return htsp_error(htsp, N_("Unable to get system UTC time"));
tz_offset = (serverGmTime.tm_hour - serverLocalTime.tm_hour) * 60;
tz_offset += serverGmTime.tm_min - serverLocalTime.tm_min;
if (tz_offset > 11 * 60)
channel_t *ch = NULL;
if (htsmsg_get_u32(in, "channelId", &channelId))
- return htsp_error("Missing argument 'channelId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if (!(ch = channel_find_by_id(channelId)))
- return htsp_error("Channel does not exist");
+ return htsp_error(htsp, N_("Channel does not exist"));
return htsp_build_channel(ch, NULL, htsp);
}
const char *lang;
if(htsmsg_get_u32(in, "eventId", &eventId))
- return htsp_error("Missing argument 'eventId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
lang = htsmsg_get_str(in, "language") ?: htsp->htsp_language;
if((e = epg_broadcast_find_by_id(eventId)) == NULL)
- return htsp_error("Event does not exist");
+ return htsp_error(htsp, N_("Event does not exist"));
return htsp_build_event(e, NULL, lang, 0, htsp);
}
/* Optional fields */
if (!htsmsg_get_u32(in, "channelId", &u32))
if (!(ch = channel_find_by_id(u32)))
- return htsp_error("Channel does not exist");
+ return htsp_error(htsp, N_("Channel does not exist"));
if (!htsmsg_get_u32(in, "eventId", &u32))
if (!(e = epg_broadcast_find_by_id(u32)))
- return htsp_error("Event does not exist");
+ return htsp_error(htsp, N_("Event does not exist"));
/* Check access */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
numFollowing = htsmsg_get_u32_or_default(in, "numFollowing", 0);
maxTime = htsmsg_get_s64_or_default(in, "maxTime", 0);
/* Required */
if( (query = htsmsg_get_str(in, "query")) == NULL )
- return htsp_error("Missing argument 'query'");
+ return htsp_error(htsp, N_("Invalid arguments"));
memset(&eq, 0, sizeof(eq));
/* Optional */
if(!(htsmsg_get_u32(in, "channelId", &u32))) {
if (!(ch = channel_find_by_id(u32)))
- return htsp_error("Channel does not exist");
+ return htsp_error(htsp, N_("Channel does not exist"));
else
eq.channel = strdup(idnode_uuid_as_str(&ch->ch_id, ubuf));
}
if(!(htsmsg_get_u32(in, "tagId", &u32))) {
if (!(ct = htsp_channel_tag_find_by_identifier(htsp, u32)))
- return htsp_error("Channel tag does not exist");
+ return htsp_error(htsp, N_("Channel tag does not exist"));
else
eq.channel_tag = strdup(idnode_uuid_as_str(&ct->ct_id, ubuf));
}
/* Check access */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Query */
epg_query(&eq, htsp->htsp_granted_access);
/* Required fields */
if (htsmsg_get_u32(in, "id", &id))
- return htsp_error("Missing argument: id");
+ return htsp_error(htsp, N_("Invalid arguments"));
/* Optional fields */
if (!htsmsg_get_u32(in, "type", &u32) && (u32 <= EPG_TYPEMAX))
/* Get object */
if (!(eo = epg_object_find_by_id(id, type)))
- return htsp_error("Invalid EPG object request");
+ return htsp_error(htsp, N_("Invalid EPG object request"));
/* Serialize */
if (!(out = epg_object_serialize(eo)))
- return htsp_error("Unknown: failed to serialize object");
+ return htsp_error(htsp, N_("Internal error"));
return out;
}
/* Check access */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Manual timer */
if (!e) {
if (!ch)
- return htsp_error("Channel does not exist");
+ return htsp_error(htsp, N_("Channel does not exist"));
/* Required attributes */
if (htsmsg_get_s64(in, "start", &start) ||
htsmsg_get_s64(in, "stop", &stop) ||
!(title = htsmsg_get_str(in, "title")))
- return htsp_error("Invalid arguments");
+ return htsp_error(htsp, N_("Invalid arguments"));
/* Optional attributes */
if (!(subtitle = htsmsg_get_str(in, "subtitle")))
dvr_entry_t *de;
if(htsmsg_get_u32(in, "id", &dvrEntryId)) {
- *out = htsp_error("Missing argument 'id'");
+ *out = htsp_error(htsp, N_("Invalid arguments"));
return NULL;
}
if((de = dvr_entry_find_by_id(dvrEntryId)) == NULL) {
- *out = htsp_error("id not found");
+ *out = htsp_error(htsp, N_("DVR entry not found"));
return NULL;
}
if(dvr_entry_verify(de, htsp->htsp_granted_access, 1)) {
- *out = htsp_error("User does not have access");
+ *out = htsp_error(htsp, N_("User does not have access"));
return NULL;
}
/* Check access */
if (chn && de->de_channel && !htsp_user_access_channel(htsp, de->de_channel)) {
- *out = htsp_error("User does not have access");
+ *out = htsp_error(htsp, N_("User does not have access"));
return NULL;
}
/* Check access new channel */
if (channel && !htsp_user_access_channel(htsp, channel))
- return htsp_error("User does not have access to channel");
+ return htsp_error(htsp, N_("User does not have access to channel"));
enabled = htsmsg_get_s64_or_default(in, "enabled", -1);
dvr_config_name = htsp_dvr_config_name(htsp, htsmsg_get_str(in, "configName"));
/* Options */
if(!(str = htsmsg_get_str(in, "title")))
- return htsp_error("Invalid arguments");
+ return htsp_error(htsp, N_("Invalid arguments"));
if (htsp->htsp_version > 24) {
if (!htsmsg_get_s64(in, "channelId", &s64)) { // not sending or -1 = any channel
/* Check access channel */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Create autorec config from htsp and add */
dae = dvr_autorec_create_htsp(serierec_convert(htsp, in, ch, 1, 1));
channel_t *ch = NULL;
if (!(daeId = htsmsg_get_str(in, "id")))
- return htsp_error("Missing argument 'id'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if((dae = dvr_autorec_find_by_uuid(daeId)) == NULL)
- return htsp_error("id not found");
+ return htsp_error(htsp, N_("Automatic schedule entry not found"));
if(dvr_autorec_entry_verify(dae, htsp->htsp_granted_access, 0))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Check access old channel*/
if (dae->dae_channel && !htsp_user_access_channel(htsp, dae->dae_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Do we have a channel? No = keep old one */
if (!htsmsg_get_s64(in, "channelId", &s64)) //s64 -> -1 = any channel
/* Check access new channel */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
}
/* Update autorec config from htsp and save */
dvr_autorec_entry_t *dae;
if (!(daeId = htsmsg_get_str(in, "id")))
- return htsp_error("Missing argument 'id'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if((dae = dvr_autorec_find_by_uuid(daeId)) == NULL)
- return htsp_error("id not found");
+ return htsp_error(htsp, N_("Automatic schedule entry not found"));
if(dvr_autorec_entry_verify(dae, htsp->htsp_granted_access, 0))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Check access */
if (dae->dae_channel && !htsp_user_access_channel(htsp, dae->dae_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
autorec_destroy_by_id(daeId, 1);
/* Options */
if(!(str = htsmsg_get_str(in, "title")))
- return htsp_error("Invalid arguments");
+ return htsp_error(htsp, N_("Invalid arguments"));
if (htsp->htsp_version > 24) {
if (!htsmsg_get_s64(in, "channelId", &s64)) { // not sending or -1 = any channel
/* Check access channel */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Create timerec config from htsp and add */
dte = dvr_timerec_create_htsp(serierec_convert(htsp, in, ch, 0, 1));
channel_t *ch = NULL;
if (!(dteId = htsmsg_get_str(in, "id")))
- return htsp_error("Missing argument 'id'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if((dte = dvr_timerec_find_by_uuid(dteId)) == NULL)
- return htsp_error("id not found");
+ return htsp_error(htsp, N_("Automatic time scheduler entry not found"));
if(dvr_timerec_entry_verify(dte, htsp->htsp_granted_access, 0))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Check access old channel */
if (dte->dte_channel && !htsp_user_access_channel(htsp, dte->dte_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Do we have a channel? No = keep old one */
if (!htsmsg_get_s64(in, "channelId", &s64)) //s64 -> -1 = any channel
/* Check access new channel */
if (ch && !htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
}
/* Update timerec config from htsp and save */
dvr_timerec_entry_t *dte;
if (!(dteId = htsmsg_get_str(in, "id")))
- return htsp_error("Missing argument 'id'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if((dte = dvr_timerec_find_by_uuid(dteId)) == NULL)
- return htsp_error("id not found");
+ return htsp_error(htsp, N_("Automatic time scheduler entry not found"));
if(dvr_timerec_entry_verify(dte, htsp->htsp_granted_access, 0))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Check access */
if (dte->dte_channel && !htsp_user_access_channel(htsp, dte->dte_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
timerec_destroy_by_id(dteId, 1);
uint32_t dvrEntryId;
dvr_entry_t *de;
if (htsmsg_get_u32(in, "id", &dvrEntryId))
- return htsp_error("Missing argument 'id'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if((de = dvr_entry_find_by_id(dvrEntryId)) == NULL)
- return htsp_error("id not found");
+ return htsp_error(htsp, N_("DVR schedule not found"));
if(dvr_entry_verify(de, htsp->htsp_granted_access, 1))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
/* Check access */
if (!htsp_user_access_channel(htsp, de->de_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
htsmsg_t *msg = htsmsg_create_map();
if(!htsmsg_get_u32(in, "channelId", &id)) {
if (!(ch = channel_find_by_id(id)))
- return htsp_error("Invalid channelId");
+ return htsp_error(htsp, N_("Channel not found"));
if (!htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
snprintf(path, sizeof(path), "/stream/channelid/%d", id);
ticket = access_ticket_create(path, htsp->htsp_granted_access);
} else if(!htsmsg_get_u32(in, "dvrId", &id)) {
if (!(de = dvr_entry_find_by_id(id)))
- return htsp_error("DVR entry does not exist");
+ return htsp_error(htsp, N_("DVR schedule does not exist"));
if (!htsp_user_access_channel(htsp, de->de_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
snprintf(path, sizeof(path), "/dvrfile/%d", id);
ticket = access_ticket_create(path, htsp->htsp_granted_access);
} else {
- return htsp_error("Missing argument 'channelId' or 'dvrId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
}
out = htsmsg_create_map();
profile_t *pro;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if(!htsmsg_get_u32(in, "channelId", &chid)) {
if((ch = channel_find_by_id(chid)) == NULL)
- return htsp_error("Requested channel does not exist");
+ return htsp_error(htsp, N_("Channel does not exist"));
} else if((str = htsmsg_get_str(in, "channelName")) != NULL) {
if((ch = channel_find_by_name(str)) == NULL)
- return htsp_error("Requested channel does not exist");
+ return htsp_error(htsp, N_("Channel does not exist"));
} else {
- return htsp_error("Missing argument 'channelId' or 'channelName'");
+ return htsp_error(htsp, N_("Invalid arguments"));
}
if (!htsp_user_access_channel(htsp, ch))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
weight = htsmsg_get_u32_or_default(in, "weight", 0);
req90khz = htsmsg_get_u32_or_default(in, "90khz", 0);
tvhlog(LOG_ERR, "htsp", "unable to create profile chain '%s'", profile_get_name(pro));
profile_chain_close(&hs->hs_prch);
free(hs);
- return htsp_error("Stream setup error");
+ return htsp_error(htsp, N_("Stream setup error"));
}
/*
uint32_t sid;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
LIST_FOREACH(s, &htsp->htsp_subscriptions, hs_link)
if(s->hs_sid == sid)
uint32_t sid, weight;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
weight = htsmsg_get_u32_or_default(in, "weight", 0);
break;
if(hs == NULL)
- return htsp_error("Requested subscription does not exist");
+ return htsp_error(htsp, N_("Subscription does not exist"));
htsp_reply(htsp, in, htsmsg_create_map());
streaming_skip_t skip;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link)
if(hs->hs_sid == sid)
break;
if(hs == NULL)
- return htsp_error("Requested subscription does not exist");
+ return htsp_error(htsp, N_("Subscription does not exist"));
abs = htsmsg_get_u32_or_default(in, "absolute", 0);
skip.size = s64;
tvhtrace("htsp-sub", "skip: %s by size %"PRId64, abs ? "abs" : "rel", s64);
} else {
- return htsp_error("Missing argument 'time' or 'size'");
+ return htsp_error(htsp, N_("Invalid arguments"));
}
subscription_set_skip(hs->hs_s, &skip);
int32_t speed;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
if(htsmsg_get_s32(in, "speed", &speed))
- return htsp_error("Missing argument 'speed'");
+ return htsp_error(htsp, N_("Invalid arguments"));
LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link)
if(hs->hs_sid == sid)
break;
if(hs == NULL)
- return htsp_error("Requested subscription does not exist");
+ return htsp_error(htsp, N_("Subscription does not exist"));
tvhtrace("htsp-sub", "speed: %d", speed);
subscription_set_speed(hs->hs_s, speed);
streaming_skip_t skip;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link)
if(hs->hs_sid == sid)
break;
if(hs == NULL)
- return htsp_error("Requested subscription does not exist");
+ return htsp_error(htsp, N_("Subscription does not exist"));
memset(&skip, 0, sizeof(skip));
skip.type = SMT_SKIP_LIVE;
uint32_t sid;
htsmsg_t *l;
if(htsmsg_get_u32(in, "subscriptionId", &sid))
- return htsp_error("Missing argument 'subscriptionId'");
+ return htsp_error(htsp, N_("Invalid arguments"));
LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link)
if(hs->hs_sid == sid)
break;
if(hs == NULL)
- return htsp_error("Requested subscription does not exist");
+ return htsp_error(htsp, N_("Subscription does not exist"));
if((l = htsmsg_get_list(in, "enable")) != NULL) {
htsmsg_field_t *f;
if((str = htsmsg_get_str(in, "file")) == NULL)
- return htsp_error("Missing argument 'file'");
+ return htsp_error(htsp, N_("Invalid arguments"));
// optional leading slash
if (*str == '/')
(s2 = tvh_strbegins(str, "dvrfile/")) != NULL) {
dvr_entry_t *de = dvr_entry_find_by_id(atoi(s2));
if(de == NULL)
- return htsp_error("DVR entry does not exist");
+ return htsp_error(htsp, N_("DVR schedule does not exist"));
if (dvr_entry_verify(de, htsp->htsp_granted_access, 1))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
if (!htsp_user_access_channel(htsp, de->de_channel))
- return htsp_error("User does not have access");
+ return htsp_error(htsp, N_("User does not have access"));
filename = dvr_get_filename(de);
if (filename == NULL)
- return htsp_error("DVR entry does not have a file yet");
+ return htsp_error(htsp, N_("DVR schedule does not have a file yet"));
return htsp_file_open(htsp, filename, 0);
} else if ((s2 = tvh_strbegins(str, "imagecache/")) != NULL) {
int fd = imagecache_open(atoi(s2));
if (fd < 0)
- return htsp_error("failed to open image");
+ return htsp_error(htsp, N_("Failed to open image"));
return htsp_file_open(htsp, str, fd);
} else {
- return htsp_error("Unknown file");
+ return htsp_error(htsp, N_("Unknown file"));
}
}
int fd;
if(hf == NULL)
- return htsp_error("Unknown file id");
+ return htsp_error(htsp, N_("Invalid file"));
if(htsmsg_get_s64(in, "size", &size))
- return htsp_error("Missing field 'size'");
+ return htsp_error(htsp, N_("Invalid parameters"));
fd = hf->hf_fd;
/* Read */
void *m = malloc(size);
if(m == NULL) {
- e = "Too big segment";
+ e = N_("Not enough memory");
goto error;
}
int r = read(fd, m, size);
if(r < 0) {
free(m);
- e = "Read error";
+ e = N_("Read error");
goto error;
}
error:
pthread_mutex_lock(&global_lock);
- return e ? htsp_error(e) : rep;
+ return e ? htsp_error(htsp, e) : rep;
}
/**
htsp_file_t *hf = htsp_file_find(htsp, in);
if(hf == NULL)
- return htsp_error("Unknown file id");
+ return htsp_error(htsp, N_("Invalid file"));
htsp_file_destroy(hf);
return htsmsg_create_map();
int fd;
if(hf == NULL)
- return htsp_error("Unknown file id");
+ return htsp_error(htsp, N_("Invalid file"));
fd = hf->hf_fd;
int fd, whence;
if(hf == NULL)
- return htsp_error("Unknown file id");
+ return htsp_error(htsp, N_("Invalid file"));
if (htsmsg_get_s64(in, "offset", &off))
- return htsp_error("Missing field 'offset'");
+ return htsp_error(htsp, N_("Invalid parameters"));
if ((str = htsmsg_get_str(in, "whence"))) {
if (!strcmp(str, "SEEK_SET"))
else if (!strcmp(str, "SEEK_END"))
whence = SEEK_END;
else
- return htsp_error("Field 'whence' contained invalid value");
+ return htsp_error(htsp, N_("Invalid parameters"));
} else {
whence = SEEK_SET;
}
if ((off = lseek(fd, off, whence)) < 0) {
pthread_mutex_lock(&global_lock);
- return htsp_error("Seek error");
+ return htsp_error(htsp, N_("Seek error"));
}
rep = htsmsg_create_map();
}
if(i == NUM_METHODS) {
- reply = htsp_error("Method not found");
+ reply = htsp_error(htsp, N_("Method not found"));
}
} else {
- reply = htsp_error("No 'method' argument");
+ reply = htsp_error(htsp, N_("Invalid arguments"));
}
pthread_mutex_unlock(&global_lock);