cmyth_database_t cmyth_database_init(char *host, char *db_name, char *user, char *pass) { cmyth_database_t rtrn = ref_alloc(sizeof(*rtrn)); cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); if (rtrn != NULL) { rtrn->db_host = ref_strdup(host); rtrn->db_user = ref_strdup(user); rtrn->db_pass = ref_strdup(pass); rtrn->db_name = ref_strdup(db_name); } return rtrn; }
void cmyth_recordingrule_set_programid(cmyth_recordingrule_t rr, char *programid) { if (rr->programid) ref_release(rr->programid); rr->programid = ref_strdup(programid); }
char* cmyth_recorder_get_filename(cmyth_recorder_t rec) { char buf[256], *ret; if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n", __FUNCTION__); return NULL; } if (rec->rec_conn->conn_version >= 26) { if (rec->rec_livetv_chain && rec->rec_livetv_chain->chain_current >= 0) { snprintf(buf, sizeof(buf), "%s", rec->rec_livetv_chain->chain_urls[rec->rec_livetv_chain->chain_current]); } else buf[0] = '\0'; } else snprintf(buf, sizeof(buf), "ringbuf%"PRIu32".nuv", rec->rec_id); ret = ref_strdup(buf); return ret; }
char* cmyth_recorder_get_filename(cmyth_recorder_t rec) { char buf[256], *ret; if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n", __FUNCTION__); return NULL; } if (!rec->rec_connected) { return NULL; } if(rec->rec_conn->conn_version >= 26) { cmyth_proginfo_t prog; prog = cmyth_chain_get_current(rec->rec_chain); ret = cmyth_proginfo_pathname(prog); ref_release(prog); } else { snprintf(buf, sizeof(buf), "ringbuf%d.nuv", rec->rec_id); ret = ref_strdup(buf); } return ret; }
void cmyth_recordingrule_set_profile(cmyth_recordingrule_t rr, char *profile) { if (rr->profile) ref_release(rr->profile); rr->profile = ref_strdup(profile); }
void cmyth_recordingrule_set_inetref(cmyth_recordingrule_t rr, char *inetref) { if (rr->inetref) ref_release(rr->inetref); rr->inetref = ref_strdup(inetref); }
void cmyth_recordingrule_set_storagegroup(cmyth_recordingrule_t rr, char *storagegroup) { if (rr->storagegroup) ref_release(rr->storagegroup); rr->storagegroup = ref_strdup(storagegroup); }
void cmyth_recordingrule_set_playgroup(cmyth_recordingrule_t rr, char *playgroup) { if (rr->playgroup) ref_release(rr->playgroup); rr->playgroup = ref_strdup(playgroup); }
void cmyth_recordingrule_set_subtitle(cmyth_recordingrule_t rr, char *subtitle) { if (rr->subtitle) ref_release(rr->subtitle); rr->subtitle = ref_strdup(subtitle); }
void cmyth_recordingrule_set_recgroup(cmyth_recordingrule_t rr, char *recgroup) { if (rr->recgroup) ref_release(rr->recgroup); rr->recgroup = ref_strdup(recgroup); }
void cmyth_recordingrule_set_description(cmyth_recordingrule_t rr, char *description) { if (rr->description) ref_release(rr->description); rr->description = ref_strdup(description); }
void cmyth_recordingrule_set_category(cmyth_recordingrule_t rr, char *category) { if (rr->category) ref_release(rr->category); rr->category = ref_strdup(category); }
void cmyth_recordingrule_set_callsign(cmyth_recordingrule_t rr, char *callsign) { if (rr->callsign) ref_release(rr->callsign); rr->callsign = ref_strdup(callsign); }
cmyth_chain_t cmyth_chain_create(cmyth_recorder_t rec, char *chain_id) { cmyth_chain_t chain; struct event_loop_args *args; args = ref_alloc(sizeof(*args)); chain = ref_alloc(sizeof(*chain)); chain->chain_id = ref_strdup(chain_id); chain->chain_count = 0; chain->chain_current = -1; chain->chain_list = NULL; chain->chain_callback = NULL; chain->chain_event = NULL; chain->chain_thread = 0; chain->chain_conn = ref_hold(rec->rec_conn); pthread_mutex_init(&chain->chain_mutex, NULL); pthread_cond_init(&chain->chain_cond, NULL); ref_set_destroy(chain, (ref_destroy_t)cmyth_chain_destroy); args->rec = ref_hold(rec); args->chain = ref_hold(chain); chain->chain_thread_args = (void*)args; pthread_create(&chain->chain_thread, NULL, cmyth_chain_event_loop, (void*)args); return chain; }
char * cmyth_conn_get_client_hostname(cmyth_conn_t conn) { char* result=NULL; result = ref_strdup(my_hostname); return result; }
void cmyth_recordingrule_set_seriesid(cmyth_recordingrule_t rr, char *seriesid) { if (rr->seriesid) ref_release(rr->seriesid); rr->seriesid = ref_strdup(seriesid); }
int cmyth_database_set_name(cmyth_database_t db, char *name) { cmyth_database_close(db); ref_release(db->db_name); db->db_name = ref_strdup(name); if(! db->db_name) return 0; else return 1; }
int cmyth_database_set_host(cmyth_database_t db, char *host) { cmyth_database_close(db); ref_release(db->db_host); db->db_host = ref_strdup(host); if(! db->db_host) return 0; else return 1; }
int cmyth_database_set_user(cmyth_database_t db, char *user) { cmyth_database_close(db); ref_release(db->db_user); db->db_user = ref_strdup(user); if(! db->db_user) return 0; else return 1; }
int cmyth_database_set_pass(cmyth_database_t db, char *pass) { cmyth_database_close(db); ref_release(db->db_user); db->db_pass = ref_strdup(pass); if(! db->db_pass) return 0; else return 1; }
int cmyth_database_set_name(cmyth_database_t db, char *name) { PRINTF("** SSDEBUG: setting the db name to %s\n", name); cmyth_database_close(db); ref_release(db->db_name); db->db_name = ref_strdup(name); if(! db->db_name) return 0; else return 1; }
int cmyth_database_set_pass(cmyth_database_t db, char *pass) { PRINTF("** SSDEBUG: setting the db pass to %s\n", pass); cmyth_database_close(db); ref_release(db->db_user); db->db_pass = ref_strdup(pass); if(! db->db_pass) return 0; else return 1; }
int cmyth_database_set_user(cmyth_database_t db, char *user) { PRINTF("** SSDEBUG: setting the db user to %s\n", user); cmyth_database_close(db); ref_release(db->db_user); db->db_user = ref_strdup(user); if(! db->db_user) return 0; else return 1; }
int cmyth_database_set_host(cmyth_database_t db, char *host) { PRINTF("** SSDEBUG: setting the db host to %s\n", host); cmyth_database_close(db); ref_release(db->db_host); db->db_host = ref_strdup(host); if(! db->db_host) return 0; else return 1; }
/* * cmyth_livetv_chain_add_url(cmyth_recorder_t rec, char * url) * * Scope: PRIVATE * * Description * * Called to add a url to a livetv chain structure. The url is added * only if it is not already there. * * Return Value: * * Success: 0 * * Faiure: -1 */ static int cmyth_livetv_chain_add_url(cmyth_recorder_t rec, char * url) { char ** tmp; cmyth_file_t * fp; cmyth_proginfo_t * pi; int ret = 0; if(cmyth_livetv_chain_has_url(rec,url) == -1) { if(rec->rec_livetv_chain->chain_current == -1) { rec->rec_livetv_chain->chain_ct = 1; rec->rec_livetv_chain->chain_current = 0; /* Nothing in the chain yet, allocate the space */ tmp = (char**)ref_alloc(sizeof(char *)); fp = (cmyth_file_t *)ref_alloc(sizeof(cmyth_file_t)); pi = (cmyth_proginfo_t *)ref_alloc(sizeof(cmyth_proginfo_t)); } else { rec->rec_livetv_chain->chain_ct++; tmp = (char**)ref_realloc(rec->rec_livetv_chain->chain_urls, sizeof(char *)*rec->rec_livetv_chain->chain_ct); fp = (cmyth_file_t *) ref_realloc(rec->rec_livetv_chain->chain_files, sizeof(cmyth_file_t)*rec->rec_livetv_chain->chain_ct); pi = (cmyth_proginfo_t *) ref_realloc(rec->rec_livetv_chain->progs, sizeof(cmyth_proginfo_t)*rec->rec_livetv_chain->chain_ct); } if(tmp != NULL && fp != NULL) { rec->rec_livetv_chain->chain_urls = ref_hold(tmp); rec->rec_livetv_chain->chain_files = ref_hold(fp); rec->rec_livetv_chain->progs = ref_hold(pi); ref_release(tmp); ref_release(fp); ref_release(pi); rec->rec_livetv_chain->chain_urls[rec->rec_livetv_chain->chain_ct-1] = ref_strdup(url); rec->rec_livetv_chain->chain_files[rec->rec_livetv_chain->chain_ct-1] = ref_hold(NULL); rec->rec_livetv_chain->progs[rec->rec_livetv_chain->chain_ct-1] = ref_hold(NULL); } else { ret = -1; cmyth_dbg(CMYTH_DBG_ERROR, "%s: memory allocation request failed\n", __FUNCTION__); } } return ret; }
/* * cmyth_rec_num_get(char *host, * unsigned short port, * unsigned id) * * Scope: PUBLIC * * Description * * Create a recorder number structure 'rn' using the values 'host', * 'port', and 'id'. * * Return Value: * * Success: A new cmyth_rec_num (this is a ppointer type) * * Failure: NULL */ cmyth_rec_num_t cmyth_rec_num_get(char *host, unsigned short port, unsigned id) { cmyth_rec_num_t ret; if ((ret = cmyth_rec_num_create()) == NULL) { return NULL; } ret->recnum_host = ref_strdup(host); if (!ret->recnum_host) { ref_release(ret); return NULL; } ret->recnum_port = port; ret->recnum_id = id; return ret; }
/* * cmyth_livetv_chain_create(void) * * Scope: PUBLIC * * Description * * Allocate and initialize a ring buffer structure. * * Return Value: * * Success: A non-NULL cmyth_livetv_chain_t (this type is a pointer) * * Failure: A NULL cmyth_livetv_chain_t */ cmyth_livetv_chain_t cmyth_livetv_chain_create(char * chainid) { cmyth_livetv_chain_t ret = ref_alloc(sizeof(*ret)); cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); if (!ret) { return NULL; } ret->chainid = ref_strdup(chainid); ret->chain_ct = 0; ret->chain_switch_on_create = 0; ret->chain_current = -1; ret->chain_urls = NULL; ret->chain_files = NULL; ret->progs = NULL; ref_set_destroy(ret, (ref_destroy_t)cmyth_livetv_chain_destroy); return ret; }
/* * cmyth_livetv_chain_create(void) * * Scope: PUBLIC * * Description * * Allocate and initialize a ring buffer structure. * * Return Value: * * Success: A non-NULL cmyth_livetv_chain_t (this type is a pointer) * * Failure: A NULL cmyth_livetv_chain_t */ cmyth_livetv_chain_t cmyth_livetv_chain_create(char * chainid) { cmyth_livetv_chain_t ret = ref_alloc(sizeof(*ret)); cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); if (!ret) { return NULL; } ret->chainid = ref_strdup(chainid); ret->chain_ct = 0; ret->chain_switch_on_create = 0; ret->chain_current = -1; ret->chain_urls = NULL; ret->chain_files = NULL; ret->progs = NULL; ret->livetv_watch = 0; /* JLB: Manage program breaks. Set to 1 on chain setup */ ret->livetv_tcp_rcvbuf = 0; ref_set_destroy(ret, (ref_destroy_t)cmyth_livetv_chain_destroy); return ret; }
/* * cmyth_recorder_get_next_program_info() * * Scope: PRIVATE (static) * * Description: * * Request program information from the recorder 'rec' for the next * program in the program guide from the current program (i.e. current * channel and time slot) in the direction specified by 'direction' * which may have any of the following values: * * BROWSE_DIRECTION_SAME - Stay in the same place * BROWSE_DIRECTION_UP - Move up one slot (down one channel) * BROWSE_DIRECTION_DOWN - Move down one slot (up one channel) * BROWSE_DIRECTION_LEFT - Move left one slot (down one time slot) * BROWSE_DIRECTION_RIGHT - Move right one slot (up one time slot) * BROWSE_DIRECTION_FAVORITE - Move to the next favorite slot * * The program information will be used to fill out 'proginfo'. * * This does not affect the current recording. * * Return Value: * * Success: 1 - valid channel, 0 - invalid channel * * Failure: -(ERRNO) */ int cmyth_recorder_get_next_program_info(cmyth_recorder_t rec, cmyth_proginfo_t cur_prog, cmyth_proginfo_t next_prog, cmyth_browsedir_t direction) { int err, count; int ret = -ENOSYS; char msg[256]; char title[256], subtitle[256], desc[256], category[256]; char callsign[256], iconpath[256]; char channelname[256], chanid[256], seriesid[256], programid[256]; char date[256]; struct tm *tm; time_t t; cmyth_conn_t control; if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n", __FUNCTION__); return -ENOSYS; } control = rec->rec_conn; pthread_mutex_lock(&mutex); t = time(NULL); tm = localtime(&t); snprintf(date, sizeof(date), "%.4d%.2d%.2d%.2d%.2d%.2d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); snprintf(msg, sizeof(msg), "QUERY_RECORDER %"PRIu32"[]:[]GET_NEXT_PROGRAM_INFO[]:[]%s[]:[]%"PRIu32"[]:[]%d[]:[]%s", rec->rec_id, cur_prog->proginfo_channame, cur_prog->proginfo_chanId, direction, date); if ((err=cmyth_send_message(control, msg)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ret = err; goto out; } count = cmyth_rcv_length(control); count -= cmyth_rcv_string(control, &err, title, sizeof(title), count); count -= cmyth_rcv_string(control, &err, subtitle, sizeof(subtitle), count); count -= cmyth_rcv_string(control, &err, desc, sizeof(desc), count); count -= cmyth_rcv_string(control, &err, category, sizeof(category), count); count -= cmyth_rcv_timestamp(control, &err, &next_prog->proginfo_start_ts, count); count -= cmyth_rcv_timestamp(control, &err, &next_prog->proginfo_end_ts, count); count -= cmyth_rcv_string(control, &err, callsign, sizeof(callsign), count); count -= cmyth_rcv_string(control, &err, iconpath, sizeof(iconpath), count); count -= cmyth_rcv_string(control, &err, channelname, sizeof(channelname), count); count -= cmyth_rcv_string(control, &err, chanid, sizeof(chanid), count); if (control->conn_version >= 12) { count -= cmyth_rcv_string(control, &err, seriesid, sizeof(seriesid), count); count -= cmyth_rcv_string(control, &err, programid, sizeof(programid), count); } if (count != 0) { ret = -1; goto out; } /* * if the program info is blank, return an error */ if ((strlen(title) == 0) && (strlen(subtitle) == 0) && (strlen(desc) == 0) && (strlen(channelname) == 0) && (strlen(chanid) == 0)) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: blank channel found\n", __FUNCTION__); ret = -1; goto out; } next_prog->proginfo_title = ref_strdup(title); next_prog->proginfo_subtitle = ref_strdup(subtitle); next_prog->proginfo_description = ref_strdup(desc); next_prog->proginfo_channame = ref_strdup(channelname); next_prog->proginfo_chanstr = ref_strdup(channelname); if (control->conn_version > 40) { /* we are hoping this is fixed by next version bump */ next_prog->proginfo_chansign = ref_strdup(callsign); } else { next_prog->proginfo_chansign = cmyth_utf8tolatin1(callsign); } next_prog->proginfo_chanicon = ref_strdup(iconpath); next_prog->proginfo_chanId = atoi(chanid); ref_hold(next_prog->proginfo_start_ts); ref_hold(next_prog->proginfo_end_ts); ret = 0; out: pthread_mutex_unlock(&mutex); return ret; }
/* * cmyth_conn_get_recorder_from_num(cmyth_conn_t control, * cmyth_recorder_num_t num, * cmyth_recorder_t rec) * * Scope: PUBLIC * * Description * * Obtain a recorder from a connection by its recorder number. The * recorder structure created by this describes how to set up a data * connection and play media streamed from a particular back-end recorder. * * This fills out the recorder structure specified by 'rec'. * * Return Value: * * Success: 0 for not complete, 1 for complete * * Failure: -(errno) */ cmyth_recorder_t cmyth_conn_get_recorder_from_num(cmyth_conn_t conn, int id) { int err, count; int r; long port; char msg[256]; char reply[256]; cmyth_recorder_t rec = NULL; if (!conn) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); return NULL; } pthread_mutex_lock(&mutex); if ((rec=cmyth_recorder_create()) == NULL) goto fail; snprintf(msg, sizeof(msg), "GET_RECORDER_FROM_NUM[]:[]%d", id); if ((err = cmyth_send_message(conn, msg)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); goto fail; } count = cmyth_rcv_length(conn); if (count < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); goto fail; } if ((r=cmyth_rcv_string(conn, &err, reply, sizeof(reply)-1, count)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, r); goto fail; } count -= r; if ((r=cmyth_rcv_long(conn, &err, &port, count)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_long() failed (%d)\n", __FUNCTION__, r); goto fail; } if (port == -1) goto fail; rec->rec_id = id; rec->rec_server = ref_strdup(reply); rec->rec_port = port; if (cmyth_conn_connect_recorder(rec, conn->conn_buflen, conn->conn_tcp_rcvbuf) < 0) goto fail; pthread_mutex_unlock(&mutex); return rec; fail: if (rec) ref_release(rec); pthread_mutex_unlock(&mutex); return NULL; }