int cmyth_set_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog, long long bookmark) { char *buf; unsigned int len = CMYTH_TIMESTAMP_LEN + CMYTH_LONGLONG_LEN * 2 + 18; char resultstr[3]; int r,err; int ret; int count; char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts); buf = alloca(len); if (!buf) { return -ENOMEM; } if (conn->conn_version >= 66) { /* * Since protocol 66 mythbackend expects a single 64 bit integer rather than two 32 bit * hi and lo integers. */ sprintf(buf, "SET_BOOKMARK %ld %s %"PRIu64, prog->proginfo_chanId, start_ts_dt, (int64_t)bookmark); } else { sprintf(buf, "SET_BOOKMARK %ld %s %d %d", prog->proginfo_chanId, start_ts_dt, (int32_t)(bookmark >> 32), (int32_t)(bookmark & 0xffffffff)); } pthread_mutex_lock(&conn->conn_mutex); if ((err = cmyth_send_message(conn,buf)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ret = err; goto out; } count = cmyth_rcv_length(conn); if ((r=cmyth_rcv_string(conn,&err,resultstr,sizeof(resultstr),count)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, err); ret = r; goto out; } count -= r; if (count == 0) { ret = (strncmp(resultstr,"OK",2) == 0); } else { ret = -1; cmyth_dbg(CMYTH_DBG_ERROR, "%s(): %d extra bytes\n", __FUNCTION__, count); } out: pthread_mutex_unlock(&conn->conn_mutex); return ret; }
long long cmyth_get_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog) { char *buf; unsigned int len = CMYTH_TIMESTAMP_LEN + CMYTH_LONGLONG_LEN + 18; int err; long long ret; int count; int64_t ll; int r; char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts); buf = alloca(len); if (!buf) { return -ENOMEM; } sprintf(buf,"%s %ld %s","QUERY_BOOKMARK",prog->proginfo_chanId, start_ts_dt); pthread_mutex_lock(&conn->conn_mutex); if ((err = cmyth_send_message(conn,buf)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ret = err; goto out; } count = cmyth_rcv_length(conn); if (count < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); ret = count; goto out; } if ((r=cmyth_rcv_int64(conn, &err, &ll, count)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_int64() failed (%d)\n", __FUNCTION__, r); ret = err; goto out; } ret = ll; out: pthread_mutex_unlock(&conn->conn_mutex); return ret; }
int cmyth_set_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog, int64_t bookmark) { char *buf; unsigned int len = CMYTH_TIMESTAMP_LEN + CMYTH_INT64_LEN * 2 + 18 + 2; int ret; char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts); buf = alloca(len); if (!buf) { return -ENOMEM; } if (conn->conn_version >= 66) { /* * Since protocol 66 mythbackend expects a single 64 bit integer rather than two 32 bit * hi and lo integers. Nevertheless the backend (at least up to 0.25) checks * the existence of the 4th parameter, so adding a 0. */ sprintf(buf, "SET_BOOKMARK %"PRIu32" %s %"PRId64" 0", prog->proginfo_chanId, start_ts_dt, bookmark); } else { sprintf(buf, "SET_BOOKMARK %"PRIu32" %s %"PRId32" %"PRId32, prog->proginfo_chanId, start_ts_dt, (int32_t)(bookmark >> 32), (int32_t)(bookmark & 0xffffffff)); } pthread_mutex_lock(&conn->conn_mutex);; if ((ret = cmyth_send_message(conn,buf)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, ret); goto out; } if ((ret = cmyth_rcv_okay(conn)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_okay() failed\n", __FUNCTION__); } out: pthread_mutex_unlock(&conn->conn_mutex); return ret; }
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; }
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); } }
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; }
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; }