Exemple #1
0
int
cmyth_update_bookmark_setting(cmyth_database_t db, cmyth_proginfo_t prog)
{
	MYSQL_RES *res = NULL;
	const char *query_str = "UPDATE recorded SET bookmark = 1 WHERE chanid = ? AND starttime = ?";
	cmyth_mysql_query_t * query;
	char starttime[CMYTH_TIMESTAMP_LEN + 1];

	cmyth_timestamp_to_string(starttime, prog->proginfo_rec_start_ts);
	query = cmyth_mysql_query_create(db,query_str);
	if (cmyth_mysql_query_param_long(query, prog->proginfo_chanId) < 0
		|| cmyth_mysql_query_param_str(query, starttime) < 0 ) {
		cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__);
		ref_release(query);
		return -1;
	}
	res = cmyth_mysql_query_result(query);
	ref_release(query);
	if (res == NULL) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s, finalisation/execution of query failed!\n", __FUNCTION__);
		return -1;
	}
	mysql_free_result(res);
	return (1);
}
Exemple #2
0
/* used to set bookmark in mythtv */
long long 
cmyth_get_bookmark_mark(cmyth_database_t db, cmyth_proginfo_t prog, long long bk, int mode)
{
	MYSQL_RES *res = NULL;
	MYSQL_ROW row;
	const char *query_str = "SELECT mark,type FROM recordedseek WHERE chanid = ? AND offset< ? AND (type = 6 or type = 9 )AND starttime = ? ORDER by MARK DESC LIMIT 0,1;";
	int rows = 0;
	long long mark=0;
	int rectype = 0;
	char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1];
	cmyth_mysql_query_t * query;
	cmyth_timestamp_to_string(start_ts_dt, prog->proginfo_rec_start_ts);
	query = cmyth_mysql_query_create(db,query_str);

	if (cmyth_mysql_query_param_long(query, prog->proginfo_chanId) < 0
		|| cmyth_mysql_query_param_long(query, bk) < 0
		|| cmyth_mysql_query_param_str(query, start_ts_dt) < 0
		) {
		cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__);
		ref_release(query);
		return -1;
	}
	res = cmyth_mysql_query_result(query);
	ref_release(query);
	if (res == NULL) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s, finalisation/execution of query failed!\n", __FUNCTION__);
		return -1;
	}
	while ((row = mysql_fetch_row(res))) {
		mark = safe_atoi(row[0]);
		rectype = safe_atoi(row[1]);
		rows++;
	}
	mysql_free_result(res);

	if (rectype == 6) {
		if (mode == 0) {
			mark=(mark-1)*15;
		}
		else if (mode == 1) {
			mark=(mark-1)*12;
		}
	}


	return (mark);
}
Exemple #3
0
static int
proginfo_command(cmyth_conn_t control, cmyth_proginfo_t prog, char *cmd,
		 long *result)
{
	long c = 0;
	char *buf;
	unsigned int len = ((2 * CMYTH_LONGLONG_LEN) + 
			    (6 * CMYTH_TIMESTAMP_LEN) +
			    (16 * CMYTH_LONG_LEN));
	char start_ts[CMYTH_TIMESTAMP_LEN + 1];
	char end_ts[CMYTH_TIMESTAMP_LEN + 1];
	char rec_start_ts[CMYTH_TIMESTAMP_LEN + 1];
	char rec_end_ts[CMYTH_TIMESTAMP_LEN + 1];
	char originalairdate[CMYTH_TIMESTAMP_LEN + 1];
	char lastmodified[CMYTH_TIMESTAMP_LEN + 1];
	int err = 0;
	int count = 0;
	long r = 0;
	int ret = 0;

	if (!prog) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n",
			  __FUNCTION__);
		return -EINVAL;
	}

	len += strlen(prog->proginfo_title);
	len += strlen(prog->proginfo_subtitle);
	len += strlen(prog->proginfo_description);
	len += strlen(prog->proginfo_category);
	len += strlen(prog->proginfo_chanstr);
	len += strlen(prog->proginfo_chansign);
	len += strlen(prog->proginfo_channame);
	len += strlen(prog->proginfo_url);
	len += strlen(prog->proginfo_hostname);
	len += strlen(prog->proginfo_playgroup);
	len += strlen(prog->proginfo_seriesid);
	len += strlen(prog->proginfo_programid);
	if (prog->proginfo_inetref) {
		len += strlen(prog->proginfo_inetref);
	}
	if (prog->proginfo_recpriority_2) {
		len += strlen(prog->proginfo_recpriority_2);
	}
	if (prog->proginfo_storagegroup) {
		len += strlen(prog->proginfo_storagegroup);
	}

	buf = alloca(len + 1+2048);
	if (!buf) {
		return -ENOMEM;
	}

	if(control->conn_version < 14)
	{
	    cmyth_timestamp_to_string(start_ts, prog->proginfo_start_ts);
	    cmyth_timestamp_to_string(end_ts, prog->proginfo_end_ts);
	    cmyth_timestamp_to_string(rec_start_ts,
	    			      prog->proginfo_rec_start_ts);
	    cmyth_timestamp_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
	    cmyth_timestamp_to_string(originalairdate,
				      prog->proginfo_originalairdate);
	    cmyth_timestamp_to_string(lastmodified,
				      prog->proginfo_lastmodified);
	}
	else
	{
	    cmyth_datetime_to_string(start_ts, prog->proginfo_start_ts);
	    cmyth_datetime_to_string(end_ts, prog->proginfo_end_ts);
	    cmyth_datetime_to_string(rec_start_ts, prog->proginfo_rec_start_ts);
	    cmyth_datetime_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
	    cmyth_datetime_to_string(originalairdate,
				     prog->proginfo_originalairdate);
	    cmyth_datetime_to_string(lastmodified, prog->proginfo_lastmodified);
	}

	if(control->conn_version > 32) {
	    cmyth_timestamp_to_isostring(originalairdate,
				 prog->proginfo_originalairdate);
	}

	if(control->conn_version < 12)
	{
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: delete not supported with protocol ver %d\n",
			  __FUNCTION__, control->conn_version);
		return -EINVAL;
	}
	sprintf(buf, "%s 0[]:[]", cmd);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_title);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_subtitle);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_description);
	if (control->conn_version >= 67) {
		sprintf(buf + strlen(buf), "%u[]:[]", prog->proginfo_season);
		sprintf(buf + strlen(buf), "%u[]:[]", prog->proginfo_episode);
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_category);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_chanId);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_chanstr);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_chansign);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_channame);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_url);
	if (control->conn_version >= 57) {
		sprintf(buf + strlen(buf), "%"PRId64"[]:[]", prog->proginfo_Length);
	} else {
		sprintf(buf + strlen(buf), "%d[]:[]", (int32_t)(prog->proginfo_Length >> 32));
		sprintf(buf + strlen(buf), "%d[]:[]", (int32_t)(prog->proginfo_Length & 0xffffffff));
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  start_ts);
	sprintf(buf + strlen(buf), "%s[]:[]",  end_ts);
	if (control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%s[]:[]", prog->proginfo_unknown_0); // "duplicate"
		sprintf(buf + strlen(buf), "%ld[]:[]", 0L); // "shareable"
	}
	sprintf(buf + strlen(buf), "%ld[]:[]", 0L); // "findid"
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_hostname);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_source_id);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_card_id);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_input_id);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_rec_priority);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_rec_status);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_record_id);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_rec_type);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_rec_dups);
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_unknown_1); // "dupmethod"
	sprintf(buf + strlen(buf), "%s[]:[]",  rec_start_ts);
	sprintf(buf + strlen(buf), "%s[]:[]",  rec_end_ts);
	if (control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_repeat);
	}
	sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_program_flags);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_recgroup);
	if (control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%s[]:[]", prog->proginfo_chancommfree);
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_chan_output_filters);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_seriesid);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_programid);
	if (control->conn_version >= 67) {
		sprintf(buf + strlen(buf), "%s[]:[]", prog->proginfo_inetref);
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  lastmodified);
	sprintf(buf + strlen(buf), "%s[]:[]",  prog->proginfo_stars);
	sprintf(buf + strlen(buf), "%s[]:[]",  originalairdate);
	if (control->conn_version >= 15 && control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_hasairdate);
	}
	if (control->conn_version >= 18) {
		sprintf(buf + strlen(buf), "%s[]:[]", prog->proginfo_playgroup);
	}
	if (control->conn_version >= 25) {
		sprintf(buf + strlen(buf), "%s[]:[]", prog->proginfo_recpriority_2);
	}
	if (control->conn_version >= 31) {
		sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_parentid);
	}
	if (control->conn_version >= 32) {
		sprintf(buf + strlen(buf), "%s[]:[]", prog->proginfo_storagegroup);
	}
	if (control->conn_version >= 35) {
		sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_audioproperties);
		sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_videoproperties);
		sprintf(buf + strlen(buf), "%ld[]:[]", prog->proginfo_subtitletype);
	}
	if (control->conn_version >= 43) {
		sprintf(buf + strlen(buf), "%d[]:[]", prog->proginfo_year);
	}

	pthread_mutex_lock(&control->conn_mutex);

	if ((err = cmyth_send_message(control, buf)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_send_message() failed (%d)\n",
			  __FUNCTION__, err);
		ret = err;
		goto out;
	}

	count = cmyth_rcv_length(control);
	if ((r=cmyth_rcv_long(control, &err, &c, count)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_length() failed (%d)\n",
			  __FUNCTION__, r);
		ret = err;
		goto out;
	}

	if (result) {
		*result = c;
	}

    out:
	pthread_mutex_unlock(&control->conn_mutex);

	return ret;
}
Exemple #4
0
static int
delete_command(cmyth_conn_t control, cmyth_proginfo_t prog, char *cmd)
{
	long c = 0;
	char *buf;
	unsigned int len = ((2 * CMYTH_LONGLONG_LEN) + 
			    (4 * CMYTH_TIMESTAMP_LEN) +
			    (14 * CMYTH_LONG_LEN));
	char start_ts[CMYTH_TIMESTAMP_LEN + 1];
	char end_ts[CMYTH_TIMESTAMP_LEN + 1];
	char rec_start_ts[CMYTH_TIMESTAMP_LEN + 1];
	char rec_end_ts[CMYTH_TIMESTAMP_LEN + 1];
	char originalairdate[CMYTH_TIMESTAMP_LEN + 1];
	char lastmodified[CMYTH_TIMESTAMP_LEN + 1];
	int err;
	int count;
	long r;
	int ret;

	if (!prog) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n",
			  __FUNCTION__);
		return -EINVAL;
	}

	len += strlen(prog->proginfo_title);
	len += strlen(prog->proginfo_subtitle);
	len += strlen(prog->proginfo_description);
	len += strlen(prog->proginfo_category);
	len += strlen(prog->proginfo_chanstr);
	len += strlen(prog->proginfo_chansign);
	len += strlen(prog->proginfo_channame);
	len += strlen(prog->proginfo_url);
	len += strlen(prog->proginfo_hostname);

	buf = alloca(len + 1+2048);
	if (!buf) {
		return -ENOMEM;
	}

	if(control->conn_version < 14)
	{
	    cmyth_timestamp_to_string(start_ts, prog->proginfo_start_ts);
	    cmyth_timestamp_to_string(end_ts, prog->proginfo_end_ts);
	    cmyth_timestamp_to_string(rec_start_ts,
	    			      prog->proginfo_rec_start_ts);
	    cmyth_timestamp_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
	    cmyth_timestamp_to_string(originalairdate,
				      prog->proginfo_originalairdate);
	    cmyth_timestamp_to_string(lastmodified,
				      prog->proginfo_lastmodified);
	}
	else
	{
	    cmyth_datetime_to_string(start_ts, prog->proginfo_start_ts);
	    cmyth_datetime_to_string(end_ts, prog->proginfo_end_ts);
	    cmyth_datetime_to_string(rec_start_ts, prog->proginfo_rec_start_ts);
	    cmyth_datetime_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
	    cmyth_datetime_to_string(originalairdate,
				     prog->proginfo_originalairdate);
	    cmyth_datetime_to_string(lastmodified, prog->proginfo_lastmodified);
	}

	if(control->conn_version > 32) {
	    cmyth_timestamp_to_isostring(originalairdate,
				 prog->proginfo_originalairdate);
	}
	
	if(control->conn_version < 12)
	{
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: delete not supported with protocol ver %d\n",
			  __FUNCTION__, control->conn_version);
		return -EINVAL;
	}
	else if (control->conn_version < 57)
	{
		sprintf(buf,
			"%s 0[]:[]"
			"%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]"
			"%s[]:[]%s[]:[]%s[]:[]%s[]:[]%d[]:[]%d[]:[]"
			"%s[]:[]%s[]:[]%s[]:[]%ld[]:[]"
			"%ld[]:[]%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]"
			"%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]%ld[]:[]"
			"%ld[]:[]%s[]:[]%s[]:[]%ld[]:[]%ld[]:[]"
			"%s[]:[]%s[]:[]%s[]:[]%s[]:[]"
			"%s[]:[]%s[]:[]%s[]:[]%s[]:[]",
			cmd,
			prog->proginfo_title,
			prog->proginfo_subtitle,
			prog->proginfo_description,
			prog->proginfo_category,
			prog->proginfo_chanId,
			prog->proginfo_chanstr,
			prog->proginfo_chansign,
			prog->proginfo_chanicon,
			prog->proginfo_url,
			(int32_t)(prog->proginfo_Length >> 32),
			(int32_t)(prog->proginfo_Length & 0xffffffff),
			start_ts,
			end_ts,
			prog->proginfo_unknown_0,
			prog->proginfo_recording,
			prog->proginfo_override,
			prog->proginfo_hostname,
			prog->proginfo_source_id,
			prog->proginfo_card_id,
			prog->proginfo_input_id,
			prog->proginfo_rec_priority,
			prog->proginfo_rec_status,
			prog->proginfo_record_id,
			prog->proginfo_rec_type,
			prog->proginfo_rec_dups,
			prog->proginfo_unknown_1,
			rec_start_ts,
			rec_end_ts,
			prog->proginfo_repeat,
			prog->proginfo_program_flags,
			prog->proginfo_recgroup,
			prog->proginfo_chancommfree,
			prog->proginfo_chan_output_filters,
			prog->proginfo_seriesid,
			prog->proginfo_programid,
			lastmodified,
			prog->proginfo_stars,
			originalairdate);
		if (control->conn_version >= 15) {
		    sprintf(buf + strlen(buf), "%ld[]:[]",
		    		prog->proginfo_hasairdate);
		}
		if(control->conn_version >= 18) {
		    sprintf(buf + strlen(buf), "%s[]:[]",
		    		prog->proginfo_playgroup);
		}
		if(control->conn_version >= 25){
		    sprintf(buf + strlen(buf), "%s[]:[]",
		    		prog->proginfo_recpriority_2);
		}
		if (control->conn_version >= 31) {
		    sprintf(buf + strlen(buf), "%ld[]:[]",
		    		prog->proginfo_parentid);
		}
		if (control->conn_version >= 32) {
		    sprintf(buf + strlen(buf), "%s[]:[]",
		    		prog->proginfo_storagegroup);
		}
		if (control->conn_version >=35) {
		    sprintf(buf + strlen(buf), "%ld[]:[]%ld[]:[]%ld[]:[]",
		    		prog->proginfo_audioproperties,
				prog->proginfo_videoproperties,
				prog->proginfo_subtitletype);
		}		
	}
Exemple #5
0
char *
cmyth_proginfo_string(cmyth_conn_t control, cmyth_proginfo_t prog)
{
	char *buf;
	unsigned int len = ((2 * CMYTH_INT64_LEN) +
			    (6 * CMYTH_TIMESTAMP_LEN) +
			    (16 * CMYTH_INT32_LEN));
	char start_ts[CMYTH_TIMESTAMP_LEN + 1];
	char end_ts[CMYTH_TIMESTAMP_LEN + 1];
	char rec_start_ts[CMYTH_TIMESTAMP_LEN + 1];
	char rec_end_ts[CMYTH_TIMESTAMP_LEN + 1];
	char originalairdate[CMYTH_TIMESTAMP_LEN + 1];
	char lastmodified[CMYTH_TIMESTAMP_LEN + 1];

	if (!prog) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n",
			  __FUNCTION__);
		return NULL;
	}
#define S(a) ((a) == NULL ? "" : (a))

	len += strlen(S(prog->proginfo_title));
	len += strlen(S(prog->proginfo_subtitle));
	len += strlen(S(prog->proginfo_description));
	len += strlen(S(prog->proginfo_category));
	len += strlen(S(prog->proginfo_chanstr));
	len += strlen(S(prog->proginfo_chansign));
	len += strlen(S(prog->proginfo_channame));
	len += strlen(S(prog->proginfo_url));
	len += strlen(S(prog->proginfo_hostname));
	len += strlen(S(prog->proginfo_playgroup));
	len += strlen(S(prog->proginfo_seriesid));
	len += strlen(S(prog->proginfo_programid));
	len += strlen(S(prog->proginfo_inetref));
	len += strlen(S(prog->proginfo_storagegroup));

	buf = malloc(len + 1 + 2048);
	if (!buf) {
		return NULL;
	}
	*buf = '\0';

	if(control->conn_version < 14)
	{
		cmyth_timestamp_to_string(start_ts, prog->proginfo_start_ts);
		cmyth_timestamp_to_string(end_ts, prog->proginfo_end_ts);
		cmyth_timestamp_to_string(rec_start_ts, prog->proginfo_rec_start_ts);
		cmyth_timestamp_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
		cmyth_timestamp_to_string(originalairdate, prog->proginfo_originalairdate);
		cmyth_timestamp_to_string(lastmodified, prog->proginfo_lastmodified);
	}
	else
	{
		cmyth_datetime_to_string(start_ts, prog->proginfo_start_ts);
		cmyth_datetime_to_string(end_ts, prog->proginfo_end_ts);
		cmyth_datetime_to_string(rec_start_ts, prog->proginfo_rec_start_ts);
		cmyth_datetime_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
		cmyth_datetime_to_string(originalairdate, prog->proginfo_originalairdate);
		cmyth_datetime_to_string(lastmodified, prog->proginfo_lastmodified);
	}

	if(control->conn_version > 32) {
		cmyth_timestamp_to_isostring(originalairdate, prog->proginfo_originalairdate);
	}

	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_title));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_subtitle));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_description));
	if (control->conn_version >= 67) {
		sprintf(buf + strlen(buf), "%"PRIu16"[]:[]", prog->proginfo_season);
		sprintf(buf + strlen(buf), "%"PRIu16"[]:[]", prog->proginfo_episode);
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_category));
	sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_chanId);
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_chanstr));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_chansign));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_channame));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_url));
	if (control->conn_version >= 57) {
		sprintf(buf + strlen(buf), "%"PRId64"[]:[]", prog->proginfo_Length);
	} else {
		sprintf(buf + strlen(buf), "%"PRId32"[]:[]", (int32_t)(prog->proginfo_Length >> 32));
		sprintf(buf + strlen(buf), "%"PRId32"[]:[]", (int32_t)(prog->proginfo_Length & 0xffffffff));
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  start_ts);
	sprintf(buf + strlen(buf), "%s[]:[]",  end_ts);
	if (control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_unknown_0)); // "duplicate"
		sprintf(buf + strlen(buf), "%ld[]:[]", 0L); // "shareable"
	}
	sprintf(buf + strlen(buf), "%ld[]:[]", 0L); // "findid"
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_hostname));
	sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_source_id);
	sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_card_id);
	sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_input_id);
	sprintf(buf + strlen(buf), "%"PRId8"[]:[]", prog->proginfo_rec_priority);
	sprintf(buf + strlen(buf), "%"PRId8"[]:[]", prog->proginfo_rec_status);
	sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_record_id);
	sprintf(buf + strlen(buf), "%"PRIu8"[]:[]", prog->proginfo_rec_type);
	sprintf(buf + strlen(buf), "%"PRIu8"[]:[]", prog->proginfo_rec_dupin);
	sprintf(buf + strlen(buf), "%"PRIu8"[]:[]", prog->proginfo_rec_dupmethod);
	sprintf(buf + strlen(buf), "%s[]:[]",  rec_start_ts);
	sprintf(buf + strlen(buf), "%s[]:[]",  rec_end_ts);
	if (control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%"PRIu8"[]:[]", prog->proginfo_repeat);
	}
	sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_program_flags);
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_recgroup));
	if (control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_chancommfree));
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_chan_output_filters));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_seriesid));
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_programid));
	if (control->conn_version >= 67) {
		sprintf(buf + strlen(buf), "%s[]:[]", S(prog->proginfo_inetref));
	}
	sprintf(buf + strlen(buf), "%s[]:[]",  lastmodified);
	sprintf(buf + strlen(buf), "%s[]:[]",  S(prog->proginfo_stars));
	sprintf(buf + strlen(buf), "%s[]:[]",  originalairdate);
	if (control->conn_version >= 15 && control->conn_version < 57) {
		sprintf(buf + strlen(buf), "%"PRIu8"[]:[]", prog->proginfo_hasairdate);
	}
	if (control->conn_version >= 18) {
		sprintf(buf + strlen(buf), "%s[]:[]", S(prog->proginfo_playgroup));
	}
	if (control->conn_version >= 25) {
		sprintf(buf + strlen(buf), "%"PRId8"[]:[]", prog->proginfo_recpriority_2);
	}
	if (control->conn_version >= 31) {
		sprintf(buf + strlen(buf), "%"PRIu32"[]:[]", prog->proginfo_parentid);
	}
	if (control->conn_version >= 32) {
		sprintf(buf + strlen(buf), "%s[]:[]", S(prog->proginfo_storagegroup));
	}
	if (control->conn_version >= 35) {
		sprintf(buf + strlen(buf), "%"PRIu16"[]:[]", prog->proginfo_audioproperties);
		sprintf(buf + strlen(buf), "%"PRIu16"[]:[]", prog->proginfo_videoproperties);
		sprintf(buf + strlen(buf), "%"PRIu16"[]:[]", prog->proginfo_subtitletype);
	}
	if (control->conn_version >= 43) {
		sprintf(buf + strlen(buf), "%"PRIu16"[]:[]", prog->proginfo_year);
	}
#undef S

	return buf;
}
Exemple #6
0
static int
delete_command(cmyth_conn_t control, cmyth_proginfo_t prog, char *cmd)
{
    long c = 0;
    char *buf;
    unsigned int len = ((2 * CMYTH_LONGLONG_LEN) +
                        (6 * CMYTH_TIMESTAMP_LEN) +
                        (14 * CMYTH_LONG_LEN));
    char start_ts[CMYTH_TIMESTAMP_LEN + 1];
    char end_ts[CMYTH_TIMESTAMP_LEN + 1];
    char rec_start_ts[CMYTH_TIMESTAMP_LEN + 1];
    char rec_end_ts[CMYTH_TIMESTAMP_LEN + 1];
    char originalairdate[CMYTH_TIMESTAMP_LEN + 1];
    char lastmodified[CMYTH_TIMESTAMP_LEN + 1];
    int err;
    int count;
    long r;
    int ret;

    if (!prog) {
        cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n",
                  __FUNCTION__);
        return -EINVAL;
    }
#define S(a) ((a) == NULL ? "" : (a))

    len += strlen(S(prog->proginfo_title));
    len += strlen(S(prog->proginfo_subtitle));
    len += strlen(S(prog->proginfo_description));
    len += strlen(S(prog->proginfo_category));
    len += strlen(S(prog->proginfo_chanstr));
    len += strlen(S(prog->proginfo_chansign));
    len += strlen(S(prog->proginfo_channame));
    len += strlen(S(prog->proginfo_url));
    len += strlen(S(prog->proginfo_hostname));
    len += strlen(S(prog->proginfo_playgroup));
    len += strlen(S(prog->proginfo_recpriority_2));
    len += strlen(S(prog->proginfo_storagegroup));

    buf = alloca(len + 1+2048);
    if (!buf) {
        return -ENOMEM;
    }

    if(control->conn_version < 14)
    {
        cmyth_timestamp_to_string(start_ts, prog->proginfo_start_ts);
        cmyth_timestamp_to_string(end_ts, prog->proginfo_end_ts);
        cmyth_timestamp_to_string(rec_start_ts,
                                  prog->proginfo_rec_start_ts);
        cmyth_timestamp_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
        cmyth_timestamp_to_string(originalairdate,
                                  prog->proginfo_originalairdate);
        cmyth_timestamp_to_string(lastmodified,
                                  prog->proginfo_lastmodified);
    }
    else
    {
        cmyth_datetime_to_string(start_ts, prog->proginfo_start_ts);
        cmyth_datetime_to_string(end_ts, prog->proginfo_end_ts);
        cmyth_datetime_to_string(rec_start_ts, prog->proginfo_rec_start_ts);
        cmyth_datetime_to_string(rec_end_ts, prog->proginfo_rec_end_ts);
        cmyth_datetime_to_string(originalairdate,
                                 prog->proginfo_originalairdate);
        cmyth_datetime_to_string(lastmodified, prog->proginfo_lastmodified);
    }

    if(control->conn_version > 32) {
        cmyth_timestamp_to_isostring(originalairdate,
                                     prog->proginfo_originalairdate);
    }

    if(control->conn_version < 12)
    {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: delete not supported with protocol ver %d\n",
                  __FUNCTION__, control->conn_version);
        return -EINVAL;
    } else {
        sprintf(buf,
                "%s 0[]:[]"
                "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]"
                "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]"
                "%ld[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]"
                "%ld[]:[]%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]"
                "%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]%ld[]:[]"
                "%ld[]:[]%s[]:[]%s[]:[]%ld[]:[]%ld[]:[]"
                "%s[]:[]%s[]:[]%s[]:[]%s[]:[]"
                "%s[]:[]%s[]:[]%s[]:[]%s[]:[]",
                cmd,
                S(prog->proginfo_title),
                S(prog->proginfo_subtitle),
                S(prog->proginfo_description),
                S(prog->proginfo_category),
                prog->proginfo_chanId,
                S(prog->proginfo_chanstr),
                S(prog->proginfo_chansign),
                S(prog->proginfo_chanicon),
                S(prog->proginfo_url),
                (unsigned long)(prog->proginfo_Length >> 32),
                (unsigned long)(prog->proginfo_Length & 0xffffffff),
                start_ts,
                end_ts,
                S(prog->proginfo_unknown_0),
                prog->proginfo_recording,
                prog->proginfo_override,
                S(prog->proginfo_hostname),
                prog->proginfo_source_id,
                prog->proginfo_card_id,
                prog->proginfo_input_id,
                S(prog->proginfo_rec_priority),
                prog->proginfo_rec_status,
                prog->proginfo_record_id,
                prog->proginfo_rec_type,
                prog->proginfo_rec_dups,
                prog->proginfo_unknown_1,
                rec_start_ts,
                rec_end_ts,
                prog->proginfo_repeat,
                prog->proginfo_program_flags,
                S(prog->proginfo_recgroup),
                S(prog->proginfo_chancommfree),
                S(prog->proginfo_chan_output_filters),
                S(prog->proginfo_seriesid),
                S(prog->proginfo_programid),
                lastmodified,
                S(prog->proginfo_stars),
                originalairdate);
        if (control->conn_version >= 15) {
            sprintf(buf + strlen(buf), "%ld[]:[]",
                    prog->proginfo_hasairdate);
        }
        if (control->conn_version >= 18) {
            sprintf(buf + strlen(buf), "%s[]:[]",
                    S(prog->proginfo_playgroup));
        }
        if (control->conn_version >= 25) {
            sprintf(buf + strlen(buf), "%s[]:[]",
                    S(prog->proginfo_recpriority_2));
        }
        if (control->conn_version >= 31) {
            sprintf(buf + strlen(buf), "%ld[]:[]",
                    prog->proginfo_parentid);
        }
        if (control->conn_version >= 32) {
            sprintf(buf + strlen(buf), "%s[]:[]",
                    S(prog->proginfo_storagegroup));
        }
        if (control->conn_version >= 35) {
            sprintf(buf + strlen(buf), "%ld[]:[]%ld[]:[]%ld[]:[]",
                    prog->proginfo_audioproperties,
                    prog->proginfo_videoproperties,
                    prog->proginfo_subtitletype);
        }
        if (control->conn_version >= 41) {
            sprintf(buf + strlen(buf), "%s[]:[]",
                    S(prog->proginfo_prodyear));
        }
    }
#undef S

    pthread_mutex_lock(&mutex);

    if ((err = cmyth_send_message(control, buf)) < 0) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_send_message() failed (%d)\n",
                  __FUNCTION__, err);
        ret = err;
        goto out;
    }

    count = cmyth_rcv_length(control);
    if ((r=cmyth_rcv_long(control, &err, &c, count)) < 0) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_rcv_length() failed (%d)\n",
                  __FUNCTION__, r);
        ret = err;
        goto out;
    }

    /*
     * XXX: for some reason, this seems to return an error, even though
     *      it succeeds...
     */

    ret = 0;

out:
    pthread_mutex_unlock(&mutex);

    return ret;
}
Exemple #7
0
static int
show_proglist(cmyth_proglist_t episodes, int level, int show_card)
{
	int count, i;

	if (episodes == NULL) {
		return -1;
	}

	count = cmyth_proglist_get_count(episodes);

	for (i=0; i<count; i++) {
		char *title;
		char *subtitle=NULL, *channel = NULL;
		char *description=NULL, *category=NULL, *recgroup=NULL;
		char *pathname=NULL;
		cmyth_proginfo_t prog;
		int rec;

		prog = cmyth_proglist_get_item(episodes, i);

		title = cmyth_proginfo_title(prog);

		rec = cmyth_proginfo_check_recording(control, prog);

		if (level > 2) {
			subtitle = cmyth_proginfo_subtitle(prog);
			channel = cmyth_proginfo_channame(prog);
		}

		if (level > 3) {
			description = cmyth_proginfo_description(prog);
			category = cmyth_proginfo_category(prog);
			recgroup = cmyth_proginfo_recgroup(prog);
		}

		if (level > 4) {
			pathname = cmyth_proginfo_pathname(prog);
		}

		if (channel) {
			printf("\tChannel:         %s\n", channel);
		}
		if (title) {
			printf("\tTitle:           %s\n", title);
			if (rec > 0) {
				cmyth_timestamp_t end;
				char str[32];

				end = cmyth_proginfo_rec_end(prog);
				cmyth_timestamp_to_string(str, end);

				printf("\t                 RECORDING on %d until %s\n",
				       rec, str);

				ref_release(end);
			}
		}
		if (subtitle) {
			printf("\tSubtitle:        %s\n", subtitle);
		}
		if (description) {
			printf("\tDescription:     %s\n", description);
		}
		if (category) {
			printf("\tCategory:        %s\n", category);
		}
		if (recgroup) {
			printf("\tRecording Group: %s\n", recgroup);
		}
		if (pathname) {
			printf("\tPathname:        %s\n", pathname);
		}

		if (level > 4) {
			printf("\tBytes:           %lld\n",
			       cmyth_proginfo_length(prog));
		}

		if (level > 1 && show_card) {
			long card = cmyth_proginfo_card_id(prog);

			if (card == 0) {
				printf("\tRecorder:        will not record\n");
			} else {
				printf("\tRecorder:        %ld\n", card);
			}
		}

		ref_release(channel);
		ref_release(title);
		ref_release(subtitle);
		ref_release(description);
		ref_release(category);
		ref_release(recgroup);
		ref_release(pathname);

		ref_release(prog);
	}

	ref_release(episodes);

	return count;
}
Exemple #8
0
static int
get_recorders(int level)
{
	int i, j;

	for (i=0; i<=32; i++) {
		cmyth_recorder_t rec;
		int state;

		rec = cmyth_conn_get_recorder(control, i);

		if (rec == NULL) {
			continue;
		}

		state = cmyth_recorder_is_recording(rec);

		if (state == 0) {
			printf("Recorder %d is idle\n", i);
		} else if (state == 1) {
			cmyth_proginfo_t prog;
			cmyth_timestamp_t end;
			char str[32];
			char *title;

			prog = cmyth_recorder_get_cur_proginfo(rec);

			end = cmyth_proginfo_rec_end(prog);
			cmyth_timestamp_to_string(str, end);

			printf("Recorder %d is recording until %s\n", i, str);

			if (prog && (level > 0)) {
				title = cmyth_proginfo_title(prog);
				if (title) {
					printf("\tTitle:           %s\n",
					       title);
				}
				ref_release(title);
			}

			ref_release(prog);
			ref_release(end);
		} else {
			printf("Recorder %d is in an unknown state\n", i);
		}

		if (level > 1) {
			cmyth_chanlist_t cl;
			cmyth_channel_t chan;
			char *name;

			cl = cmyth_recorder_get_chanlist(rec);

			for (j=0; j<cmyth_chanlist_get_count(cl); j++) {
				chan = cmyth_chanlist_get_item(cl, j);
				name = cmyth_channel_string(chan);
				printf("\tChannel: %s\n", name);
				ref_release(name);
				ref_release(chan);
			}

			ref_release(cl);
		}

		ref_release(rec);
	}

	return 0;
}