diff --git a/lib/cmyth/Win32/libcmyth.vcxproj b/lib/cmyth/Win32/libcmyth.vcxproj index 1582b7d0d..d083c301e 100644 --- a/lib/cmyth/Win32/libcmyth.vcxproj +++ b/lib/cmyth/Win32/libcmyth.vcxproj @@ -12,6 +12,7 @@ + @@ -26,10 +27,12 @@ + + diff --git a/lib/cmyth/Win32/libcmyth.vcxproj.filters b/lib/cmyth/Win32/libcmyth.vcxproj.filters index 96b7eb2dd..e074db661 100644 --- a/lib/cmyth/Win32/libcmyth.vcxproj.filters +++ b/lib/cmyth/Win32/libcmyth.vcxproj.filters @@ -79,6 +79,15 @@ refmem + + Source Files + + + Source Files + + + Source Files + diff --git a/lib/cmyth/include/cmyth/cmyth.h b/lib/cmyth/include/cmyth/cmyth.h index b8bc91238..e65df08f7 100644 --- a/lib/cmyth/include/cmyth/cmyth.h +++ b/lib/cmyth/include/cmyth/cmyth.h @@ -40,7 +40,7 @@ #ifndef __CMYTH_H #define __CMYTH_H -#ifdef __APPLE__ +#ifdef __APPLE__ #include #else #include @@ -159,34 +159,6 @@ struct cmyth_commbreaklist { }; typedef struct cmyth_commbreaklist *cmyth_commbreaklist_t; -/* Sergio: Added to support the tvguide functionality */ - -struct cmyth_channel; -typedef struct cmyth_channel *cmyth_channel_t; - -struct cmyth_chanlist; -typedef struct cmyth_chanlist *cmyth_chanlist_t; - -struct cmyth_tvguide_progs; -typedef struct cmyth_tvguide_progs *cmyth_tvguide_progs_t; - -/* fetzerch: Added to support querying of free inputs (is tunable on) */ -struct cmyth_input { - char *inputname; - unsigned long sourceid; - unsigned long inputid; - unsigned long cardid; - unsigned long multiplexid; - unsigned long livetvorder; /* new in V71 */ -}; -typedef struct cmyth_input *cmyth_input_t; - -struct cmyth_inputlist { - cmyth_input_t *input_list; - long input_count; -}; -typedef struct cmyth_inputlist *cmyth_inputlist_t; - /* * ----------------------------------------------------------------- * Debug Output Control @@ -255,9 +227,10 @@ extern cmyth_conn_t cmyth_conn_connect_ctrl(char *server, unsigned buflen, int tcp_rcvbuf); /** - * Create a control connection to a backend. + * Reconnect control connection to a backend. * \param control control handle - * \return integer success + * \return success: 1 + * \return failure: 0 */ extern int cmyth_conn_reconnect_ctrl(cmyth_conn_t control); @@ -274,9 +247,10 @@ extern cmyth_conn_t cmyth_conn_connect_event(char *server, unsigned buflen, int tcp_rcvbuf); /** - * Re-create an event connection to a backend. + * Reconnect event connection to a backend. * \param conn control handle - * \return integer success + * \return success: 1 + * \return failure: 0 */ extern int cmyth_conn_reconnect_event(cmyth_conn_t conn); @@ -292,7 +266,6 @@ extern cmyth_file_t cmyth_conn_connect_file(cmyth_proginfo_t prog, cmyth_conn_t control, unsigned buflen, int tcp_rcvbuf); - /** * Create a file connection to a backend. * \param path path to file @@ -648,21 +621,17 @@ extern int cmyth_livetv_read(cmyth_recorder_t rec, char *buf, unsigned long len); -extern int cmyth_livetv_keep_recording(cmyth_recorder_t rec, cmyth_database_t db, int keep); - -extern int mythtv_new_livetv(void); -extern int cmyth_tuner_type_check(cmyth_database_t db, cmyth_recorder_t rec, int check_tuner_enabled); +extern int cmyth_mysql_tuner_type_check(cmyth_database_t db, cmyth_recorder_t rec, int check_tuner_enabled); /* * ----------------------------------------------------------------- - * Database Operations + * Database Operations * ----------------------------------------------------------------- */ extern cmyth_database_t cmyth_database_init(char *host, char *db_name, char *user, char *pass, unsigned short port); extern void cmyth_database_close(cmyth_database_t db); -extern cmyth_chanlist_t myth_tvguide_load_channels(cmyth_database_t db, - int sort_desc); + extern int cmyth_database_set_host(cmyth_database_t db, char *host); extern int cmyth_database_set_user(cmyth_database_t db, char *user); extern int cmyth_database_set_pass(cmyth_database_t db, char *pass); @@ -671,8 +640,6 @@ extern int cmyth_database_set_port(cmyth_database_t db, unsigned short port); extern int cmyth_database_get_version(cmyth_database_t db); -extern int cmyth_set_watched_status_mysql(cmyth_database_t db, cmyth_proginfo_t prog, int watchedStat); - extern int cmyth_database_setup(cmyth_database_t db); /* @@ -835,7 +802,7 @@ extern int cmyth_proginfo_get_recorder_num(cmyth_conn_t control, cmyth_proginfo_t prog); extern cmyth_proginfo_t cmyth_proginfo_get_from_basename(cmyth_conn_t control, - const char* basename); + const char* basename); /** * Retrieve the title of a program. @@ -1111,7 +1078,7 @@ extern unsigned long long cmyth_file_length(cmyth_file_t file); extern unsigned long long cmyth_file_position(cmyth_file_t file); -extern int cmyth_update_file_length(cmyth_file_t file, unsigned long long newLength); +extern int cmyth_file_update_length(cmyth_file_t file, unsigned long long newlen); extern int cmyth_file_get_block(cmyth_file_t file, char *buf, unsigned long len); @@ -1134,30 +1101,6 @@ extern int cmyth_file_is_open(cmyth_file_t file); extern int cmyth_file_set_timeout(cmyth_file_t file, int fast); -/* - * ----------------------------------------------------------------- - * Channel Operations - * ----------------------------------------------------------------- - */ - -extern long cmyth_channel_chanid(cmyth_channel_t channel); - -extern long cmyth_channel_channum(cmyth_channel_t channel); - -extern char * cmyth_channel_channumstr(cmyth_channel_t channel); - -extern char * cmyth_channel_callsign(cmyth_channel_t channel); - -extern char * cmyth_channel_name(cmyth_channel_t channel); - -extern char * cmyth_channel_icon(cmyth_channel_t channel); - -extern int cmyth_channel_visible(cmyth_channel_t channel); - -extern cmyth_channel_t cmyth_chanlist_get_item(cmyth_chanlist_t pl, int index); - -extern int cmyth_chanlist_get_count(cmyth_chanlist_t pl); - /* * ----------------------------------------------------------------- * Free Space Operations @@ -1171,9 +1114,9 @@ extern cmyth_freespace_t cmyth_freespace_create(void); * ------- */ extern long long cmyth_get_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog); -extern long long cmyth_get_bookmark_offset(cmyth_database_t db, unsigned long chanid, long long mark, time_t starttime, int mode); -extern int cmyth_update_bookmark_setting(cmyth_database_t, cmyth_proginfo_t); -extern long long cmyth_get_bookmark_mark(cmyth_database_t, cmyth_proginfo_t, long long, int); +extern long long cmyth_mysql_get_bookmark_offset(cmyth_database_t db, unsigned long chanid, long long mark, time_t starttime, int mode); +extern int cmyth_mysql_update_bookmark_setting(cmyth_database_t, cmyth_proginfo_t); +extern long long cmyth_mysql_get_bookmark_mark(cmyth_database_t, cmyth_proginfo_t, long long, int); extern int cmyth_set_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog, long long bookmark); extern cmyth_commbreaklist_t cmyth_commbreaklist_create(void); @@ -1183,17 +1126,6 @@ extern cmyth_commbreaklist_t cmyth_get_commbreaklist(cmyth_conn_t conn, cmyth_pr extern cmyth_commbreaklist_t cmyth_get_cutlist(cmyth_conn_t conn, cmyth_proginfo_t prog); extern int cmyth_rcv_commbreaklist(cmyth_conn_t conn, int *err, cmyth_commbreaklist_t breaklist, int count); -/* - * ------- - * Card Input Operations - * ------- - */ -extern cmyth_inputlist_t cmyth_inputlist_create(void); -extern cmyth_input_t cmyth_input_create(void); -extern cmyth_inputlist_t cmyth_get_free_inputlist(cmyth_recorder_t rec); -extern int cmyth_rcv_free_inputlist(cmyth_conn_t conn, int *err, cmyth_inputlist_t inputlist, int count); - - /* * mysql info */ @@ -1226,176 +1158,911 @@ typedef struct cmyth_recgrougs { extern int cmyth_mysql_get_recgroups(cmyth_database_t, cmyth_recgroups_t **); +extern char *cmyth_mysql_get_recordid(cmyth_database_t db, unsigned long chanid, char *title, char *subtitle, char *description, char *seriesid, char *programid); +extern int cmyth_mysql_get_offset(cmyth_database_t db, int type, unsigned long recordid, unsigned long chanid, char *title, char *subtitle, char *description, char *seriesid, char *programid); + +extern int cmyth_mysql_get_prog_finder_char_title(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name); +extern int cmyth_mysql_get_prog_finder_time(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name); +extern int cmyth_mysql_get_prog_finder_time_title_chan(cmyth_database_t db, cmyth_program_t *prog, time_t starttime, char *program_name, unsigned long chanid); +extern int cmyth_mysql_get_guide(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, time_t endtime); +extern int cmyth_mysql_testdb_connection(cmyth_database_t db,char **message); +extern char *cmyth_mysql_escape_chars(cmyth_database_t db, char * string); +extern int cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t start_ts_dt, cmyth_commbreaklist_t breaklist, int conn_version); + +extern int cmyth_mysql_get_prev_recorded(cmyth_database_t db, cmyth_program_t **prog); + +extern int cmyth_get_delete_list(cmyth_conn_t, char *, cmyth_proglist_t); + +extern int cmyth_mysql_set_watched_status(cmyth_database_t db, cmyth_proginfo_t prog, int watchedStat); + + +/* + * ----------------------------------------------------------------- + * Card Input Operations + * ----------------------------------------------------------------- + */ + +struct cmyth_input { + char *inputname; + unsigned long sourceid; + unsigned long inputid; + unsigned long cardid; + unsigned long multiplexid; + unsigned long livetvorder; /* new in V71 */ +}; + +typedef struct cmyth_input *cmyth_input_t; + +struct cmyth_inputlist { + cmyth_input_t *input_list; + long input_count; +}; + +typedef struct cmyth_inputlist *cmyth_inputlist_t; + +extern cmyth_inputlist_t cmyth_inputlist_create(void); + +extern cmyth_input_t cmyth_input_create(void); + +extern cmyth_inputlist_t cmyth_get_free_inputlist(cmyth_recorder_t rec); + +extern int cmyth_rcv_free_inputlist(cmyth_conn_t conn, int *err, cmyth_inputlist_t inputlist, int count); + +/* + * ----------------------------------------------------------------- + * Recording Schedule Operations + * ----------------------------------------------------------------- + */ + +struct cmyth_recordingrule; +typedef struct cmyth_recordingrule *cmyth_recordingrule_t; + +struct cmyth_recordingrulelist; +typedef struct cmyth_recordingrulelist *cmyth_recordingrulelist_t; + +typedef enum { + RRULE_NOT_RECORDING = 0, + RRULE_SINGLE_RECORD = 1, + RRULE_TIME_SLOT_RECORD, + RRULE_CHANNEL_RECORD, + RRULE_ALL_RECORD, + RRULE_WEEK_SLOT_RECORD, + RRULE_FIND_ONE_RECORD, + RRULE_OVERRIDE_RECORD, + RRULE_DONT_RECORD, + RRULE_FIND_DAILY_RECORD, + RRULE_FIND_WEEKLY_RECORD, + RRULE_TEMPLATE_RECORD +} cmyth_recordingruletype_t; + +typedef enum { + RRULE_NO_SEARCH = 0, + RRULE_POWER_SEARCH = 1, + RRULE_TITLE_SEARCH, + RRULE_KEYWORD_SEARCH, + RRULE_PEOPLE_SEARCH, + RRULE_MANUAL_SEARCH +} cmyth_recordingrulesearch_t; + +typedef enum { + RRULE_CHECK_NONE = 0x01, + RRULE_CHECK_SUBTITLE = 0x02, + RRULE_CHECK_DESCRIPTION = 0x04, + RRULE_CHECK_SUBTITLE_AND_DESCRIPTION = 0x06, + RRULE_CHECK_SUBTITLE_THEN_DESCRIPTION = 0x08 +} cmyth_recordingruledupmethod_t; + +typedef enum { + RRULE_IN_RECORDED = 0x01, + RRULE_IN_OLD_RECORDED = 0x02, + RRULE_IN_ALL = 0x0F, + RRULE_NEW_EPI = 0x10 +} cmyth_recordingruledupin_t; + /** - * Run SQL query from param (backdoor) - * \deprecated alternative: cmyth_mysql_delete_timer + * Initialize a new recording rule structure. The structure is initialized + * to default values. + * Before forgetting the reference to this recording rule structure + * the caller must call ref_release(). + * \return success: A new recording rule + * \return failure: NULL */ -extern int cmyth_mysql_delete_scheduled_recording(cmyth_database_t db, char * query); +extern cmyth_recordingrule_t cmyth_recordingrule_init(void); /** - * Run SQL query from param (backdoor) - * \deprecated alternative: cmyth_mysql_add_timer + * Retrieves the 'recordid' field of a recording rule structure. + * \param rr + * \return success: recordid + * \return failure: -(errno) */ -extern int cmyth_mysql_insert_into_record(cmyth_database_t db, char * query, char * query1, char * query2, char *title, char * subtitle, char * description, char * callsign); +extern unsigned long cmyth_recordingrule_recordid(cmyth_recordingrule_t rr); -extern char* cmyth_get_recordid_mysql(cmyth_database_t, int, char *, char *, char *, char *, char *); -extern int cmyth_get_offset_mysql(cmyth_database_t, int, char *, int, char *, char *, char *, char *, char *); +/** + * Set the 'recordid' field of the recording rule structure 'rr'. + * \param rr + * \param recordid + */ +extern void cmyth_recordingrule_set_recordid(cmyth_recordingrule_t rr, unsigned long recordid); -extern int cmyth_mysql_get_prog_finder_char_title(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name); -extern int cmyth_mysql_get_prog_finder_time(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name); -extern int cmyth_mysql_get_guide(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, time_t endtime); -extern int cmyth_mysql_testdb_connection(cmyth_database_t db,char **message); +/** + * Retrieves the 'chanid' field of a recording rule structure. + * \param rr + * \return success: chanid + * \return failure: -(errno) + */ +extern unsigned long cmyth_recordingrule_chanid(cmyth_recordingrule_t rr); /** - * Send control message from param (backdoor) - * \deprecated alternative: cmyth_conn_reschedule_recordings + * Set the 'chanid' field of the recording rule structure 'rr'. + * \param rr + * \param chanid */ -extern int cmyth_schedule_recording(cmyth_conn_t conn, char * msg); +extern void cmyth_recordingrule_set_chanid(cmyth_recordingrule_t rr, unsigned long chanid); -extern char * cmyth_mysql_escape_chars(cmyth_database_t db, char * string); -extern int cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t start_ts_dt, cmyth_commbreaklist_t breaklist, int conn_version); +/** + * Retrieves the 'starttime' field of a recording rule structure. + * \param rr + * \return success: time_t starttime + * \return failure: -(errno) + */ +extern time_t cmyth_recordingrule_starttime(cmyth_recordingrule_t rr); -extern int cmyth_mysql_get_prev_recorded(cmyth_database_t db, cmyth_program_t **prog); +/** + * Set the 'starttime' field of the recording rule structure 'rr'. + * \param rr + * \param starttime + */ +extern void cmyth_recordingrule_set_starttime(cmyth_recordingrule_t rr, time_t starttime); -extern int cmyth_get_delete_list(cmyth_conn_t, char *, cmyth_proglist_t); +/** + * Retrieves the 'endtime' field of a recording rule structure. + * \param rr + * \return success: time_t endtime + * \return failure: -(errno) + */ +extern time_t cmyth_recordingrule_endtime(cmyth_recordingrule_t rr); + +/** + * Set the 'endtime' field of the recording rule structure 'rr'. + * \param rr + * \param endtime + */ +extern void cmyth_recordingrule_set_endtime(cmyth_recordingrule_t rr, time_t endtime); -#define PROGRAM_ADJUST 3600 +/** + * Retrieves the 'title' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: title + * \return failure: NULL + */ +extern char *cmyth_recordingrule_title(cmyth_recordingrule_t rr); -extern int cmyth_mythtv_remove_previous_recorded(cmyth_database_t db,char *query); +/** + * Set the 'title' field of the recording rule structure 'rr'. + * \param rr + * \param title + */ +extern void cmyth_recordingrule_set_title(cmyth_recordingrule_t rr, char *title); -extern cmyth_chanlist_t cmyth_mysql_get_chanlist(cmyth_database_t db); +/** + * Retrieves the 'description' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: description + * \return failure: NULL + */ +extern char *cmyth_recordingrule_description(cmyth_recordingrule_t rr); -/* tsp */ -extern int cmyth_mysql_is_radio(cmyth_database_t db, int chanid); - -/* timers */ -struct cmyth_timer; -typedef struct cmyth_timer* cmyth_timer_t; - -struct cmyth_timerlist; -typedef struct cmyth_timerlist* cmyth_timerlist_t; - -extern int cmyth_timer_recordid(cmyth_timer_t timer); -extern int cmyth_timer_chanid(cmyth_timer_t timer); -extern time_t cmyth_timer_starttime(cmyth_timer_t timer); -extern time_t cmyth_timer_endtime(cmyth_timer_t timer); -extern char* cmyth_timer_title(cmyth_timer_t timer); -extern char* cmyth_timer_description(cmyth_timer_t timer); -extern int cmyth_timer_type(cmyth_timer_t timer); -extern char* cmyth_timer_category(cmyth_timer_t timer); -extern char* cmyth_timer_subtitle(cmyth_timer_t timer); -extern int cmyth_timer_priority(cmyth_timer_t timer); -extern int cmyth_timer_startoffset(cmyth_timer_t timer); -extern int cmyth_timer_endoffset(cmyth_timer_t timer); -extern int cmyth_timer_searchtype(cmyth_timer_t timer); -extern int cmyth_timer_inactive(cmyth_timer_t timer); -extern char* cmyth_timer_callsign(cmyth_timer_t timer); -extern int cmyth_timer_dup_method(cmyth_timer_t timer); -extern int cmyth_timer_dup_in(cmyth_timer_t timer); -extern char* cmyth_timer_rec_group(cmyth_timer_t timer); -extern char* cmyth_timer_store_group(cmyth_timer_t timer); -extern char* cmyth_timer_play_group(cmyth_timer_t timer); -extern int cmyth_timer_autotranscode(cmyth_timer_t timer); -extern int cmyth_timer_userjobs(cmyth_timer_t timer); -extern int cmyth_timer_autocommflag(cmyth_timer_t timer); -extern int cmyth_timer_autoexpire(cmyth_timer_t timer); -extern int cmyth_timer_maxepisodes(cmyth_timer_t timer); -extern int cmyth_timer_maxnewest(cmyth_timer_t timer); -extern int cmyth_timer_transcoder(cmyth_timer_t timer); - - -extern cmyth_timer_t cmyth_timerlist_get_item(cmyth_timerlist_t pl, int index); -extern int cmyth_timerlist_get_count(cmyth_timerlist_t pl); - -extern cmyth_timerlist_t cmyth_mysql_get_timers(cmyth_database_t db); - - -extern int cmyth_mysql_add_timer(cmyth_database_t db, int chanid, char* callsign, char* description, time_t starttime, time_t endtime, char* title, char* category, int type, char* subtitle, int priority, int startoffset,int endoffset,int searchtype, int inactive, - int dup_method, int dup_in, char* rec_group, char* store_group, char* play_group, int autotranscode, int userjobs, int autocommflag, int autoexpire, int maxepisodes, int maxnewest, int transcoder); -extern int cmyth_mysql_delete_timer(cmyth_database_t db, int recordid); -extern int cmyth_mysql_update_timer(cmyth_database_t db, int recordid, int chanid, char* callsign, char* description, time_t starttime, time_t endtime, char* title, char* category, int type, char* subtitle, int priority, int startoffset, int endoffset, int searchtype, int inactive, - int dup_method, int dup_in, char* rec_group, char* store_group, char* play_group, int autotranscode, int userjobs, int autocommflag, int autoexpire, int maxepisodes, int maxnewest, int transcoder); - -typedef struct cmyth_channelgroups { - char channelgroup[65]; - unsigned int ID; -} cmyth_channelgroups_t; - -extern int cmyth_mysql_get_channelgroups(cmyth_database_t db, cmyth_channelgroups_t** changroups); -extern int cmyth_mysql_get_channelids_in_group(cmyth_database_t db, unsigned int groupid, int** chanids); - -extern int cmyth_channel_sourceid(cmyth_channel_t channel); -extern int cmyth_channel_multiplex(cmyth_channel_t channel); - -typedef struct cmyth_rec { - int recid; - int sourceid; -} cmyth_rec_t; - -extern int cmyth_mysql_get_recorder_list(cmyth_database_t db, cmyth_rec_t** reclist); - -extern int cmyth_mysql_get_prog_finder_time_title_chan(cmyth_database_t db, cmyth_program_t *prog, char* title, time_t starttime, int chanid); - -extern int cmyth_mysql_get_storagegroups(cmyth_database_t db, char** *profiles); -extern int cmyth_mysql_get_playgroups(cmyth_database_t db, char** *profiles); +/** + * Set the 'description' field of the recording rule structure 'rr'. + * \param rr + * \param description + */ +extern void cmyth_recordingrule_set_description(cmyth_recordingrule_t rr, char *description); -typedef struct cmyth_recprofile { - int id; - char name[128]; - char cardtype[32]; -} cmyth_recprofile_t; +/** + * Retrieves the 'type' field of a recording rule structure. + * \param rr + * \return success: type + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_type(cmyth_recordingrule_t rr); -extern int cmyth_mysql_get_recprofiles(cmyth_database_t db, cmyth_recprofile_t** profiles); +/** + * Set the 'type' field of the recording rule structure 'rr'. + * \param rr + * \param type + */ +extern void cmyth_recordingrule_set_type(cmyth_recordingrule_t rr, long type); -extern char* cmyth_mysql_get_cardtype(cmyth_database_t db, int chanid); +/** + * Retrieves the 'category' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: category + * \return failure: NULL + */ +extern char *cmyth_recordingrule_category(cmyth_recordingrule_t rr); -/* Get a storage group file list */ -extern int cmyth_storagegroup_filelist(cmyth_conn_t control, char** *sgFilelist, char* sg2List, char* hostname); +/** + * Set the 'category' field of the recording rule structure 'rr'. + * \param rr + * \param category + */ +extern void cmyth_recordingrule_set_category(cmyth_recordingrule_t rr, char *category); -struct cmyth_storagegroup_filelist; -typedef struct cmyth_storagegroup_filelist* cmyth_storagegroup_filelist_t; +/** + * Retrieves the 'subtitle' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: subtitle + * \return failure: NULL + */ +extern char *cmyth_recordingrule_subtitle(cmyth_recordingrule_t rr); + +/** + * Set the 'subtitle' field of the recording rule structure 'rr'. + * \param rr + * \param subtitle + */ +extern void cmyth_recordingrule_set_subtitle(cmyth_recordingrule_t rr, char *subtitle); + +/** + * Retrieves the 'recpriority' field of a recording rule structure. + * \param rr + * \return success: recpriority + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_recpriority(cmyth_recordingrule_t rr); + +/** + * Set the 'recpriority' field of the recording rule structure 'rr'. + * \param rr + * \param recpriority + */ +extern void cmyth_recordingrule_set_recpriority(cmyth_recordingrule_t rr, long recpriority); + +/** + * Retrieves the 'startoffset' field of a recording rule structure. + * \param rr + * \return success: startoffset + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_startoffset(cmyth_recordingrule_t rr); + +/** + * Set the 'startoffset' field of the recording rule structure 'rr'. + * \param rr + * \param startoffset + */ +extern void cmyth_recordingrule_set_startoffset(cmyth_recordingrule_t rr, long startoffset); + +/** + * Retrieves the 'endoffset' field of a recording rule structure. + * \param rr + * \return success: endoffset + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_endoffset(cmyth_recordingrule_t rr); + +/** + * Set the 'endoffset' field of the recording rule structure 'rr'. + * \param rr + * \param endoffset + */ +extern void cmyth_recordingrule_set_endoffset(cmyth_recordingrule_t rr, long endoffset); + +/** + * Retrieves the 'searchtype' field of a recording rule structure. + * \param rr + * \return success: searchtype + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_searchtype(cmyth_recordingrule_t rr); + +/** + * Set the 'searchtype' field of the recording rule structure 'rr'. + * \param rr + * \param searchtype + */ +extern void cmyth_recordingrule_set_searchtype(cmyth_recordingrule_t rr, long searchtype); + +/** + * Retrieves the 'inactive' field of a recording rule structure. + * \param rr + * \return success: inactive flag + * \return failure: -(errno) + */ +extern unsigned short cmyth_recordingrule_inactive(cmyth_recordingrule_t rr); + +/** + * Set the 'inactive' field of the recording rule structure 'rr'. + * \param rr + * \param inactive + */ +extern void cmyth_recordingrule_set_inactive(cmyth_recordingrule_t rr, unsigned short inactive); + +/** + * Retrieves the 'callsign' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: callsign + * \return failure: NULL + */ +extern char *cmyth_recordingrule_callsign(cmyth_recordingrule_t rr); + +/** + * Set the 'callsign' field of the recording rule structure 'rr'. + * \param rr + * \param callsign + */ +extern void cmyth_recordingrule_set_callsign(cmyth_recordingrule_t rr, char *callsign); + +/** + * Retrieves the 'dupmethod' field of a recording rule structure. + * \param rr + * \return success: dupmethod + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_dupmethod(cmyth_recordingrule_t rr); + +/** + * Set the 'dupmethod' field of the recording rule structure 'rr'. + * \param rr + * \param dupmethod + */ +extern void cmyth_recordingrule_set_dupmethod(cmyth_recordingrule_t rr, long dupmethod); + +/** + * Retrieves the 'dupin' field of a recording rule structure. + * \param rr + * \return success: dupin + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_dupin(cmyth_recordingrule_t rr); + +/** + * Set the 'dupin' field of the recording rule structure 'rr'. + * \param rr + * \param dupin + */ +extern void cmyth_recordingrule_set_dupin(cmyth_recordingrule_t rr, long dupin); + +/** + * Retrieves the 'recgroup' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: recgroup + * \return failure: NULL + */ +extern char *cmyth_recordingrule_recgroup(cmyth_recordingrule_t rr); + +/** + *Set the 'recgroup' field of the recording rule structure 'rr'. + * \param rr + * \param recgroup + */ +extern void cmyth_recordingrule_set_recgroup(cmyth_recordingrule_t rr, char *recgroup); + +/** + * Retrieves the 'storagegroup' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: storagegroup + * \return failure: NULL + */ +extern char *cmyth_recordingrule_storagegroup(cmyth_recordingrule_t rr); + +/** + * Set the 'storagegroup' field of the recording rule structure 'rr'. + * \param rr + * \param storagegroup + */ +extern void cmyth_recordingrule_set_storagegroup(cmyth_recordingrule_t rr, char *storagegroup); + +/** + * Retrieves the 'playgroup' field of a recording rule structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param rr + * \return success: playgroup + * \return failure: NULL + */ +extern char *cmyth_recordingrule_playgroup(cmyth_recordingrule_t rr); + +/** + * Set the 'playgroup' field of the recording rule structure 'rr'. + * \param rr + * \param playgroup + */ +extern void cmyth_recordingrule_set_playgroup(cmyth_recordingrule_t rr, char *playgroup); + +/** + * Retrieves the 'autotranscode' field of a recording rule structure. + * \param rr + * \return success: autotranscode + * \return failure: -(errno) + */ +extern unsigned short cmyth_recordingrule_autotranscode(cmyth_recordingrule_t rr); + +/** + * Set the 'autotranscode' field of the recording rule structure 'rr'. + * \param rr + * \param autotranscode + */ +extern void cmyth_recordingrule_set_autotranscode(cmyth_recordingrule_t rr, unsigned short autotranscode); + +/** + * Retrieves the 'userjobs' field of a recording rule structure. + * \param rr + * \return success: userjobs mask + * \return failure: -(errno) + */ +extern int cmyth_recordingrule_userjobs(cmyth_recordingrule_t rr); + +/** + * Set the 'userjobs' field of the recording rule structure 'rr'. + * \param rr + * \param userjobs + */ +extern void cmyth_recordingrule_set_userjobs(cmyth_recordingrule_t rr, int userjobs); + +/** + * Retrieves the 'autocommflag' field of a recording rule structure. + * \param rr + * \return success: autocommflag + * \return failure: -(errno) + */ +extern unsigned short cmyth_recordingrule_autocommflag(cmyth_recordingrule_t rr); + +/** + * Set the 'autocommflag' field of the recording rule structure 'rr'. + * \param rr + * \param autocommflag + */ +extern void cmyth_recordingrule_set_autocommflag(cmyth_recordingrule_t rr, unsigned short autocommflag); + +/** + * Retrieves the 'autoexpire' field of a recording rule structure. + * \param rr + * \return success: autoexpire + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_autoexpire(cmyth_recordingrule_t rr); + +/** + * Set the 'autoexpire' field of the recording rule structure 'rr'. + * \param rr + * \param autoexpire + */ +extern void cmyth_recordingrule_set_autoexpire(cmyth_recordingrule_t rr, long autoexpire); + +/** + * Retrieves the 'maxepisodes' field of a recording rule structure. + * \param rr + * \return success: maxepisodes + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_maxepisodes(cmyth_recordingrule_t rr); + +/** + * Set the 'maxepisodes' field of the recording rule structure 'rr'. + * \param rr + * \param maxepisodes + */ +extern void cmyth_recordingrule_set_maxepisodes(cmyth_recordingrule_t rr, long maxepisodes); + +/** + * Retrieves the 'maxnewest' field of a recording rule structure. + * \param rr + * \return success: maxnewest + * \return failure: -(errno) + */ +extern long cmyth_recordingrule_maxnewest(cmyth_recordingrule_t rr); + +/** + * Set the 'maxnewest' field of the recording rule structure 'rr'. + * \param rr + * \param maxnewest + */ +extern void cmyth_recordingrule_set_maxnewest(cmyth_recordingrule_t rr, long maxnewest); + +/** + * Retrieves the 'transcoder' field of a recording rule structure. + * \param rr + * \return success: transcoder + * \return failure: -(errno) + */ +extern unsigned long cmyth_recordingrule_transcoder(cmyth_recordingrule_t rr); + +/** + * Set the 'transcoder' field of the recording rule structure 'rr'. + * \param rr + * \param transcoder + */ +extern void cmyth_recordingrule_set_transcoder(cmyth_recordingrule_t rr, unsigned long transcoder); + +/** + * Retrieve the recording rule structure found at index 'index' in the list + * in 'rrl'. Return the recording rule structure held. + * Before forgetting the reference to this recording rule structure the + * caller must call ref_release(). + * \param rrl recordingrulelist handle + * \param index index in list + * \return success: recording rule handle + * \return failure: NULL + */ +extern cmyth_recordingrule_t cmyth_recordingrulelist_get_item(cmyth_recordingrulelist_t rrl, int index); + +/** + * Retrieves the number of elements in the recording rule list structure. + * \param rrl + * \return success: A number indicating the number of items in rrl + * \return failure: -(errno) + */ +extern int cmyth_recordingrulelist_get_count(cmyth_recordingrulelist_t rrl); + +/** + * Returns the recording rule list structure filled from database. + * \param db + * \return success: recording rule list handle + * \return failure: NULL + */ +extern cmyth_recordingrulelist_t cmyth_mysql_get_recordingrules(cmyth_database_t db); + +/** + * Add a recording rule within the database. + * \param db database + * \param rr recording rule to add + * \return success: the new recordid + * \return failure: -(errno) + */ +extern int cmyth_mysql_add_recordingrule(cmyth_database_t db, cmyth_recordingrule_t rr); + +/** + * Delete recording rule from the database. + * \param db database + * \param recordid handle + * \return success: 0 + * \return failire: -(errno) + * \see cmyth_recordingrule_recordid + */ +extern int cmyth_mysql_delete_recordingrule(cmyth_database_t db, unsigned long recordid); + +/** + * Update recording rule within the database. + * \param db database + * \param rr recording rule handle + * \return success: 0 + * \return failure: -(errno) + */ +extern int cmyth_mysql_update_recordingrule(cmyth_database_t db, cmyth_recordingrule_t rr); + +/* + * ----------------------------------------------------------------- + * Channel Operations + * ----------------------------------------------------------------- + */ + +struct cmyth_channel; +typedef struct cmyth_channel *cmyth_channel_t; + +struct cmyth_chanlist; +typedef struct cmyth_chanlist *cmyth_chanlist_t; + +/** + * Retrieves the 'chanid' field of a channel structure. + * \param channel + * \return success: chanid + * \return failure: -(errno) + */ +extern unsigned long cmyth_channel_chanid(cmyth_channel_t channel); + +/** + * Retrieves the 'channum' field of a channel structure. + * \param channel + * \return success: channum + * \return failure: -(errno) + */ +extern unsigned long cmyth_channel_channum(cmyth_channel_t channel); + +/** + * Retrieves the 'chanstr' field of a channel structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param channel + * \return success: channumstr + * \return failure: NULL + */ +extern char *cmyth_channel_channumstr(cmyth_channel_t channel); + +/** + * Retrieves the 'callsign' field of a channel structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param channel + * \return success: callsign + * \return failure: NULL + */ +extern char *cmyth_channel_callsign(cmyth_channel_t channel); + +/** + * Retrieves the 'name' field of a channel structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param channel + * \return success: name + * \return failure: NULL + */ +extern char *cmyth_channel_name(cmyth_channel_t channel); + +/** + * Retrieves the 'icon' field of a channel structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param channel + * \return success: icon + * \return failure: NULL + */ +extern char *cmyth_channel_icon(cmyth_channel_t channel); + +/** + * Retrieves the 'visible' field of a channel structure. + * \param channel + * \return success: visible flag + * \return failure: -(errno) + */ +extern unsigned short cmyth_channel_visible(cmyth_channel_t channel); + +/** + * Retrieves the 'sourceid' field of a channel structure. + * \param channel + * \return success: sourceid + * \return failure: -(errno) + */ +extern unsigned long cmyth_channel_sourceid(cmyth_channel_t channel); + +/** + * Retrieves the 'multiplex' field of a channel structure. + * \param channel + * \return success: multiplex + * \return failure: -(errno) + */ +extern unsigned long cmyth_channel_multiplex(cmyth_channel_t channel); + +/** + * Retrieve the channel structure found at index 'index' in the list in 'cl'. + * Return the channel structure held. + * Before forgetting the reference to this channel structure the caller + * must call ref_release(). + * \param channel + * \return success: non-null cmyth_channel_t (this is a pointer type) + * \return failure: NULL + */ +extern cmyth_channel_t cmyth_chanlist_get_item(cmyth_chanlist_t cl, int index); + +/** + * Retrieves the number of elements in the channels list structure. + * \param cl + * \return success: A number indicating the number of items in cl + * \return failure: -(errno) + */ +extern int cmyth_chanlist_get_count(cmyth_chanlist_t cl); + +/** + * Returns the channels list structure filled from database. + * Before forgetting the reference to this channels list structure the caller + * must call ref_release(). + * \param db + * \return success: channels list handle + * \return failure: NULL + */ +extern cmyth_chanlist_t cmyth_mysql_get_chanlist(cmyth_database_t db); + +/** + * Returns 'radio' flag of the channel identified by its 'chanid' from database. + * \param db + * \param chanid + * \return success: radio flag + * \return failure: -1 + */ +extern int cmyth_mysql_is_radio(cmyth_database_t db, unsigned long chanid); + +/** + * Returns capture card type for the channel identified by its 'chanid' from database. + * \param db + * \param chanid + * \return success: capture card type + * \return failure: NULL + */ +extern char *cmyth_mysql_get_cardtype(cmyth_database_t db, unsigned long chanid); + +/* + * ----------------------------------------------------------------- + * Storage Group operations + * ----------------------------------------------------------------- + */ struct cmyth_storagegroup_file; -typedef struct cmyth_storagegroup_file* cmyth_storagegroup_file_t; +typedef struct cmyth_storagegroup_file *cmyth_storagegroup_file_t; -extern cmyth_storagegroup_file_t cmyth_storagegroup_filelist_get_item(cmyth_storagegroup_filelist_t fl, int index); +struct cmyth_storagegroup_filelist; +typedef struct cmyth_storagegroup_filelist *cmyth_storagegroup_filelist_t; + +/** + * Returns the storagegroup files list structure of storagegroup. + * Before forgetting the reference to this storagegroup files list structure + * the caller must call ref_release(). + * \param control + * \param storagegroup + * \param hostname + * \return success: storage files list handle + * \return failure: NULL + */ +extern cmyth_storagegroup_filelist_t cmyth_storagegroup_get_filelist(cmyth_conn_t control, char *storagegroup, char *hostname); + +/** + * Retrieves the number of elements in the storagegroup files list structure. + * \param fl + * \return success: A number indicating the number of items in fl + * \return failure: -(errno) + */ extern int cmyth_storagegroup_filelist_count(cmyth_storagegroup_filelist_t fl); -extern cmyth_storagegroup_filelist_t cmyth_storagegroup_get_filelist(cmyth_conn_t control, char* storagegroup, char* hostname); +/** + * Retrieve the storagegroup file structure found at index 'index' in the list + * in 'fl'. + * Return the storagegroup file structure held. + * Before forgetting the reference to this storagegroup file structure the + * caller must call ref_release(). + * \param fl + * \return success: non-null cmyth_storagegroup_file_t (this is a pointer type) + * \return failure: NULL + */ +extern cmyth_storagegroup_file_t cmyth_storagegroup_filelist_get_item(cmyth_storagegroup_filelist_t fl, int index); -extern char* cmyth_storagegroup_file_get_filename(cmyth_storagegroup_file_t file); -extern unsigned long cmyth_storagegroup_file_get_lastmodified(cmyth_storagegroup_file_t file); -extern unsigned long long cmyth_storagegroup_file_get_size(cmyth_storagegroup_file_t file); +/** + * Retrieves the 'filename' field of a storagegroup file structure. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * \param file + * \return success: filename + * \return failure: NULL + */ +extern char *cmyth_storagegroup_file_filename(cmyth_storagegroup_file_t file); /** - * \enum Recording markup types + * Retrieves the 'lastmodified' field of a storagegroup file structure. + * \param file + * \return success: time_t lastmodified + * \return failure: -(errno) + */ +extern unsigned long cmyth_storagegroup_file_lastmodified(cmyth_storagegroup_file_t file); + +/** + * Retrieves the 'filesize' field of a storagegroup file structure. + * \param file + * \return success: long long file size + * \return failure: -(errno) + */ +extern unsigned long long cmyth_storagegroup_file_size(cmyth_storagegroup_file_t file); + +/* + * ----------------------------------------------------------------- + * Backend configuration infos + * ----------------------------------------------------------------- + */ + +typedef struct cmyth_recorder_source { + unsigned long recid; + unsigned long sourceid; +} cmyth_recorder_source_t; + +/** + * Retrieves recorder source list from database. + * \param db + * \param rsrc recorder source list handle + * \return success: A number indicating the number of recorder source in rsrc + * \return failure: -1 + */ +extern int cmyth_mysql_get_recorder_source_list(cmyth_database_t db, cmyth_recorder_source_t **rsrc); + +typedef struct cmyth_channelgroup { + char name[65]; + unsigned long grpid; +} cmyth_channelgroup_t; + +/** + * Retrieves channel group list from database. + * \param db + * \param changroups channel group list handle + * \return success: A number indicating the number of channel group in changroups + * \return failure: -1 + */ +extern int cmyth_mysql_get_channelgroups(cmyth_database_t db, cmyth_channelgroup_t **changroups); + +/** + * Retrieves channel ID list in group from database. + * \param db + * \param chanids channel ID list handle + * \return success: A number indicating the number of channel group in changroups + * \return failure: -1 */ +extern int cmyth_mysql_get_channelids_in_group(cmyth_database_t db, unsigned long grpid, unsigned long **chanids); + +/** + * Retrieves storagegroup name list from database. + * \param db + * \param sg storagegroup name list handle + * \return success: A number indicating the number of storagegroup name in sg + * \return failure: -1 + */ +extern int cmyth_mysql_get_storagegroups(cmyth_database_t db, char** *sg); + +typedef struct cmyth_recprofile { + int id; + char name[128]; + char cardtype[32]; +} cmyth_recprofile_t; + +/** + * Retrieves recording profile list from database. + * \param db + * \param profiles recording profile list handle + * \return success: A number indicating the number of profile in profiles + * \return failure: -1 + */ +extern int cmyth_mysql_get_recprofiles(cmyth_database_t db, cmyth_recprofile_t **profiles); + +/** + * Retrieves play group list from database. + * \param db + * \param pg play group list handle + * \return success: A number indicating the number of playgroup in pg + * \return failure: -1 + */ +extern int cmyth_mysql_get_playgroups(cmyth_database_t db, char** *pg); + +/* + * ----------------------------------------------------------------- + * Recording Markup and associated infos + * ----------------------------------------------------------------- + */ + typedef enum { - MARK_UNSET = -10, - MARK_TMP_CUT_END = -5, - MARK_TMP_CUT_START = -4, - MARK_UPDATED_CUT = -3, - MARK_PLACEHOLDER = -2, - MARK_CUT_END = 0, - MARK_CUT_START = 1, - MARK_BOOKMARK = 2, - MARK_BLANK_FRAME = 3, - MARK_COMM_START = 4, - MARK_COMM_END = 5, - MARK_GOP_START = 6, - MARK_KEYFRAME = 7, - MARK_SCENE_CHANGE = 8, - MARK_GOP_BYFRAME = 9, - MARK_ASPECT_1_1 = 10, //< deprecated, it is only 1:1 sample aspect ratio - MARK_ASPECT_4_3 = 11, - MARK_ASPECT_16_9 = 12, - MARK_ASPECT_2_21_1 = 13, - MARK_ASPECT_CUSTOM = 14, - MARK_VIDEO_WIDTH = 30, - MARK_VIDEO_HEIGHT = 31, - MARK_VIDEO_RATE = 32, - MARK_DURATION_MS = 33, - MARK_TOTAL_FRAMES = 34 + MARK_UNSET = -10, + MARK_TMP_CUT_END = -5, + MARK_TMP_CUT_START = -4, + MARK_UPDATED_CUT = -3, + MARK_PLACEHOLDER = -2, + MARK_CUT_END = 0, + MARK_CUT_START = 1, + MARK_BOOKMARK = 2, + MARK_BLANK_FRAME = 3, + MARK_COMM_START = 4, + MARK_COMM_END = 5, + MARK_GOP_START = 6, + MARK_KEYFRAME = 7, + MARK_SCENE_CHANGE = 8, + MARK_GOP_BYFRAME = 9, + MARK_ASPECT_1_1 = 10, //< deprecated, it is only 1:1 sample aspect ratio + MARK_ASPECT_4_3 = 11, + MARK_ASPECT_16_9 = 12, + MARK_ASPECT_2_21_1 = 13, + MARK_ASPECT_CUSTOM = 14, + MARK_VIDEO_WIDTH = 30, + MARK_VIDEO_HEIGHT = 31, + MARK_VIDEO_RATE = 32, + MARK_DURATION_MS = 33, + MARK_TOTAL_FRAMES = 34 } cmyth_recording_markup_t; /** diff --git a/lib/cmyth/libcmyth/Makefile.am b/lib/cmyth/libcmyth/Makefile.am index b4b66fdfd..733d959f4 100644 --- a/lib/cmyth/libcmyth/Makefile.am +++ b/lib/cmyth/libcmyth/Makefile.am @@ -20,7 +20,10 @@ libcmyth_la_SOURCES = bookmark.c \ socket.c \ timestamp.c \ debug.c \ - utf8tolatin1.c + utf8tolatin1.c \ + recordingrule.c \ + channel.c \ + storagegroup.c INCLUDES=-I../include/ $(MYSQL_INCLUDES) diff --git a/lib/cmyth/libcmyth/channel.c b/lib/cmyth/libcmyth/channel.c new file mode 100644 index 000000000..067ff4d2f --- /dev/null +++ b/lib/cmyth/libcmyth/channel.c @@ -0,0 +1,477 @@ +/* + * Copyright (C) 2005-2012 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include +#include +#include +#include +#include + +/* + * cmyth_chanlist_destroy(cmyth_chanlist_t rs) + * + * Scope: PRIVATE (static) + * + * Description + * + * Destroy the channels list structure pointed to by 'cl' and release + * its storage. This should only be called by ref_release(). All others should + * use ref_release() to release references to a channels list structure. + * + * Return Value: + * + * None. + */ +static void +cmyth_chanlist_destroy(cmyth_chanlist_t cl) +{ + int i; + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!cl) { + return; + } + for (i = 0; i < cl->chanlist_count; ++i) { + if (cl->chanlist_list[i]) { + ref_release(cl->chanlist_list[i]); + } + cl->chanlist_list[i] = NULL; + } + if (cl->chanlist_list) { + free(cl->chanlist_list); + } +} + +/* + * cmyth_chanlist_create(void) + * + * Scope: PRIVATE + * + * Description + * + * Create a channels list structure and return a pointer to the structure. + * Before forgetting the reference to this channel list structure the caller + * must call ref_release(). + * + * Return Value: + * + * Success: A non-NULL cmyth_chanlist_t (this type is a pointer) + * + * Failure: A NULL cmyth_chanlist_t + */ +cmyth_chanlist_t +cmyth_chanlist_create(void) +{ + cmyth_chanlist_t ret; + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + ret = ref_alloc(sizeof(*ret)); + if (!ret) { + return(NULL); + } + ref_set_destroy(ret, (ref_destroy_t)cmyth_chanlist_destroy); + + ret->chanlist_list = NULL; + ret->chanlist_count = 0; + return ret; +} + +/* + * cmyth_chanlist_get_item(cmyth_chanlist_t cl, int index) + * + * Scope: PUBLIC + * + * Description: + * + * Retrieve the channel structure found at index 'index' in the list in 'cl'. + * Return the channel structure held. + * Before forgetting the reference to this channel structure the caller + * must call ref_release(). + * + * Return Value: + * + * Success: A non-null cmyth_channel_t (this is a pointer type) + * + * Failure: A NULL cmyth_channel_t + */ +cmyth_channel_t +cmyth_chanlist_get_item(cmyth_chanlist_t cl, int index) +{ + if (!cl) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", + __FUNCTION__); + return NULL; + } + if (!cl->chanlist_list) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL list\n", + __FUNCTION__); + return NULL; + } + if ((index < 0) || (index >= cl->chanlist_count)) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: index %d out of range\n", + __FUNCTION__, index); + return NULL; + } + ref_hold(cl->chanlist_list[index]); + return cl->chanlist_list[index]; +} + +/* + * cmyth_chanlist_get_count(cmyth_chanlist_t cl) + * + * Scope: PUBLIC + * + * Description: + * + * Retrieve the number of elements in the channels list + * structure in 'cl'. + * + * Return Value: + * + * Success: A number >= 0 indicating the number of items in 'cl' + * + * Failure: -(errno) + */ +int +cmyth_chanlist_get_count(cmyth_chanlist_t cl) +{ + if (!cl) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", + __FUNCTION__); + return -EINVAL; + } + return cl->chanlist_count; +} + +/* + * cmyth_channel_destroy(cmyth_channel_t c) + * + * Scope: PRIVATE (static) + * + * Description + * + * Destroy the channel structure pointed to by 'c' and release + * its storage. This should only be called by ref_release(). + * All others should use ref_release() to release references to + * a channel structure. + * + * Return Value: + * + * None. + */ +static void +cmyth_channel_destroy(cmyth_channel_t c) +{ + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!c) { + return; + } + + if(c->name) + ref_release(c->name); + if(c->callsign) + ref_release(c->callsign); + if(c->icon) + ref_release(c->icon); +} + +/* + * cmyth_channel_create(void) + * + * Scope: PRIVATE + * + * Description + * + * Create a channel structure to be used to hold channel and return + * a pointer to the structure. The structure is initialized to + * default values. + * + * Return Value: + * + * Success: A non-NULL cmyth_channel_t (this type is a pointer) + * + * Failure: A NULL cmyth_channel_t + */ +cmyth_channel_t +cmyth_channel_create(void) +{ + cmyth_channel_t ret = ref_alloc(sizeof(*ret)); + memset(ret, 0, sizeof(*ret)); + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); + if (!ret) { + cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); + return NULL; + } + ref_set_destroy(ret, (ref_destroy_t)cmyth_channel_destroy); + + return ret; +} + +/* + * cmyth_channel_chanid(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'chanid' field of a channel structure. + * + * Return Value: + * + * Success: long chan ID. + * + * Failure: -(errno) + */ +unsigned long +cmyth_channel_chanid(cmyth_channel_t channel) +{ + if (!channel) { + return -EINVAL; + } + return channel->chanid; +} + +/* + * cmyth_channel_channum(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'channum' field of a channel structure. + * + * Return Value: + * + * Success: long channel number. + * + * Failure: -(errno) + */ +unsigned long +cmyth_channel_channum(cmyth_channel_t channel) +{ + if (!channel) { + return -EINVAL; + } + return channel->channum; +} + +/* + * cmyth_channel_channumstr(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'chanstr' field of a channel structure. + * + * The returned string is a pointer to the string within the channel + * structure, so it should not be modified by the caller. The + * return value is a 'char *' for this reason. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * + * Return Value: + * + * Success: A pointer to a 'char *' pointing to the field. + * + * Failure: NULL + */ +char * +cmyth_channel_channumstr(cmyth_channel_t channel) +{ + if (!channel) { + return NULL; + } + return ref_hold(channel->chanstr); +} + +/* + * cmyth_channel_name(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'name' field of a channel structure. + * + * The returned string is a pointer to the string within the channel + * structure, so it should not be modified by the caller. The + * return value is a 'char *' for this reason. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * + * Return Value: + * + * Success: A pointer to a 'char *' pointing to the field. + * + * Failure: NULL + */ +char * +cmyth_channel_name(cmyth_channel_t channel) +{ + if (!channel) { + return NULL; + } + return ref_hold(channel->name); +} + +/* + * cmyth_channel_callsign(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'callsign' field of a channel structure. + * + * The returned string is a pointer to the string within the channel + * structure, so it should not be modified by the caller. The + * return value is a 'char *' for this reason. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * + * Return Value: + * + * Success: A pointer to a 'char *' pointing to the field. + * + * Failure: NULL + */ +char * +cmyth_channel_callsign(cmyth_channel_t channel) +{ + if (!channel) { + return NULL; + } + return ref_hold(channel->callsign); +} + +/* + * cmyth_channel_icon(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'icon' field of a channel structure. + * + * The returned string is a pointer to the string within the channel + * structure, so it should not be modified by the caller. The + * return value is a 'char *' for this reason. + * Before forgetting the reference to this string the caller + * must call ref_release(). + * + * Return Value: + * + * Success: A pointer to a 'char *' pointing to the field. + * + * Failure: NULL + */ +char * +cmyth_channel_icon(cmyth_channel_t channel) +{ + if (!channel) { + return NULL; + } + return ref_hold(channel->icon); +} + +/* + * cmyth_channel_visible(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'visible' field of a channel structure. + * + * Return Value: + * + * Success: visible flag. + * + * Failure: -(errno) + */ +unsigned short +cmyth_channel_visible(cmyth_channel_t channel) +{ + if (!channel) { + return -EINVAL; + } + return channel->visible; +} + +/* + * cmyth_channel_sourceid(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'sourceid' field of a channel structure. + * + * Return Value: + * + * Success: long source ID. + * + * Failure: -(errno) + */ +unsigned long +cmyth_channel_sourceid(cmyth_channel_t channel) +{ + if (!channel) { + return -EINVAL; + } + return channel->sourceid; +} + +/* + * cmyth_channel_multiplex(cmyth_channel_t channel) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'multiplex' field of a channel structure. + * + * Return Value: + * + * Success: long multiplex ID. + * + * Failure: -(errno) + */ +unsigned long +cmyth_channel_multiplex(cmyth_channel_t channel) +{ + if (!channel) { + return -EINVAL; + } + return channel->multiplex; +} \ No newline at end of file diff --git a/lib/cmyth/libcmyth/cmyth_local.h b/lib/cmyth/libcmyth/cmyth_local.h index 2e2e86675..47bef0d72 100644 --- a/lib/cmyth/libcmyth/cmyth_local.h +++ b/lib/cmyth/libcmyth/cmyth_local.h @@ -118,76 +118,6 @@ struct cmyth_database { int db_version; /* JLB: -1 = No set, 0 = unknown else DBSchemaVer */ int db_tz_utc; /* JLB: 0 = No conversion, 1 = Enable UTC time zone conversion */ char db_tz_name[64]; /* JLB: db time zone name to convert query projection */ -}; - -/* Sergio: Added to clean up channel list handling */ -struct cmyth_channel { - long chanid; - int channum; - char chanstr[10]; - long cardids;/* A bit array of recorders/tuners supporting the channel */ - char *callsign; - char *name; - char *icon; - int visible; - /* tsp - added sourceID and multiplex */ - int sourceid; - int multiplex; -}; - -struct cmyth_chanlist { - cmyth_channel_t *chanlist_list; - int chanlist_count; -}; - - -/* tsp: Added timer */ - -struct cmyth_timer { - int recordid; - int chanid; - time_t starttime; - time_t endtime; - char* title; - char* description; - int type; - char* category; - char* subtitle; - int priority; - int startoffset; - int endoffset; - int searchtype; - int inactive; - char* callsign; - - int dup_method; - int dup_in; - char* rec_group; - char* store_group; - char* play_group; - int autotranscode; - int userjobs; - int autocommflag; - int autoexpire; - int maxepisodes; - int maxnewest; - int transcoder; - /* - char* profile; - int prefinput; - */ - }; - -struct cmyth_timerlist { - cmyth_timer_t *timerlist_list; - int timerlist_count; -}; - -/* Sergio: Added to support the tvguide functionality */ -struct cmyth_tvguide_progs { - cmyth_program_t * progs; - int count; - int alloc; }; struct cmyth_recorder { @@ -203,25 +133,6 @@ struct cmyth_recorder { double rec_framerate; }; -/** - * MythTV proglist - */ - -struct cmyth_storagegroup_filelist { - cmyth_storagegroup_file_t *storagegroup_filelist_list; - int storagegroup_filelist_count; -}; - - -struct cmyth_storagegroup_file { - char* filename; - char* storagegroup; - char* hostname; - unsigned long modified; - unsigned long size; -}; - - /** * MythTV file connection */ @@ -237,8 +148,6 @@ struct cmyth_file { cmyth_conn_t file_control; /**< master backend connection */ }; -long long cmyth_file_seek_unlocked(cmyth_file_t file, long long offset, int whence); - struct cmyth_ringbuf { cmyth_conn_t conn_data; long file_id; @@ -254,7 +163,7 @@ struct cmyth_ringbuf { struct cmyth_rec_num { char *recnum_host; unsigned short recnum_port; - unsigned recnum_id; + unsigned int recnum_id; }; struct cmyth_keyframe { @@ -263,7 +172,7 @@ struct cmyth_keyframe { }; struct cmyth_posmap { - unsigned posmap_count; + unsigned int posmap_count; struct cmyth_keyframe **posmap_list; }; @@ -466,8 +375,6 @@ extern int cmyth_rcv_recorder(cmyth_conn_t conn, int *err, #define cmyth_rcv_ringbuf __cmyth_rcv_ringbuf extern int cmyth_rcv_ringbuf(cmyth_conn_t conn, int *err, cmyth_ringbuf_t buf, int count); -#define cmyth_datetime_to_dbstring __cmyth_datetime_to_dbstring -extern int cmyth_datetime_to_dbstring(char *str, cmyth_timestamp_t ts); #define cmyth_toupper_string __cmyth_toupper_string extern void cmyth_toupper_string(char *str); @@ -478,9 +385,6 @@ extern void cmyth_toupper_string(char *str); #define cmyth_proginfo_string __cmyth_proginfo_string extern char *cmyth_proginfo_string(cmyth_conn_t control, cmyth_proginfo_t prog); -#define cmyth_chaninfo_string __cmyth_chaninfo_string -extern char *cmyth_chaninfo_string(cmyth_proginfo_t prog); - /* * From file.c */ @@ -534,4 +438,98 @@ extern int cmyth_mysql_query(cmyth_mysql_query_t * query); extern char* cmyth_utf8tolatin1(char* s); +/* + * From channel.c + */ +struct cmyth_channel { + unsigned long chanid; + unsigned long channum; + char *chanstr; + char *callsign; + char *name; + char *icon; + unsigned short visible; + unsigned long sourceid; + unsigned long multiplex; +}; + +struct cmyth_chanlist { + cmyth_channel_t *chanlist_list; + int chanlist_count; +}; + +#define cmyth_channel_create __cmyth_channel_create +extern cmyth_channel_t cmyth_channel_create(void); + +#define cmyth_chanlist_create __cmyth_chanlist_create +extern cmyth_chanlist_t cmyth_chanlist_create(void); + +/* + * From recordingrule.c + */ +struct cmyth_recordingrule { + unsigned long recordid; + unsigned long chanid; + cmyth_timestamp_t starttime; + cmyth_timestamp_t endtime; + char* title; + char* description; + long type; //enum + char* category; + char* subtitle; + long recpriority; //range -99,+99 + long startoffset; //nb minutes + long endoffset; //nb minutes + long searchtype; //enum + unsigned short inactive; //bool + char* callsign; + long dupmethod; //enum + long dupin; //enum + char* recgroup; + char* storagegroup; + char* playgroup; + unsigned short autotranscode; //bool + int userjobs; //#1111 + unsigned short autocommflag; //bool + long autoexpire; //bool + long maxepisodes; //range 0,100 + long maxnewest; //bool + unsigned long transcoder; //recordingprofiles id + //char* profile; + //unsigned long prefinput; + }; + +struct cmyth_recordingrulelist { + cmyth_recordingrule_t *recordingrulelist_list; + int recordingrulelist_count; +}; + +#define cmyth_recordingrule_create __cmyth_recordingrule_create +extern cmyth_recordingrule_t cmyth_recordingrule_create(void); + +#define cmyth_recordingrulelist_create __cmyth_recordingrulelist_create +extern cmyth_recordingrulelist_t cmyth_recordingrulelist_create(void); + +/* + * From storagegroup.c + */ +struct cmyth_storagegroup_file { + char* filename; + char* storagegroup; + char* hostname; + unsigned long lastmodified; + unsigned long size; +}; + +struct cmyth_storagegroup_filelist { + cmyth_storagegroup_file_t *storagegroup_filelist_list; + int storagegroup_filelist_count; +}; + +#define cmyth_storagegroup_file_create __cmyth_storagegroup_file_create +extern cmyth_storagegroup_file_t cmyth_storagegroup_file_create(void); + +#define cmyth_storagegroup_filelist_create __cmyth_storagegroup_filelist_create +extern cmyth_storagegroup_filelist_t cmyth_storagegroup_filelist_create(void); + #endif /* __CMYTH_LOCAL_H */ diff --git a/lib/cmyth/libcmyth/connection.c b/lib/cmyth/libcmyth/connection.c index 9d3505b25..902b92268 100644 --- a/lib/cmyth/libcmyth/connection.c +++ b/lib/cmyth/libcmyth/connection.c @@ -20,7 +20,7 @@ /** * \file connection.c * Functions to handle creating connections to a MythTV backend and - * interacting with those connections. + * interacting with those connections. */ #include @@ -83,7 +83,7 @@ static myth_protomap_t protomap[] = { /* * cmyth_conn_destroy(cmyth_conn_t conn) - * + * * Scope: PRIVATE (static) * * Description @@ -123,7 +123,7 @@ cmyth_conn_destroy(cmyth_conn_t conn) /* * cmyth_conn_create(void) - * + * * Scope: PRIVATE (static) * * Description @@ -163,7 +163,7 @@ cmyth_conn_create(void) /* * cmyth_connect(char *server, unsigned short port, unsigned buflen) - * + * * Scope: PUBLIC * * Description @@ -946,7 +946,7 @@ cmyth_conn_connect_file(cmyth_proginfo_t prog, cmyth_conn_t control, goto shut; } reply[sizeof(reply) - 1] = '\0'; - r = cmyth_rcv_string(conn, &err, reply, sizeof(reply) - 1, count); + r = cmyth_rcv_string(conn, &err, reply, sizeof(reply) - 1, count); if (err != 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", @@ -1100,7 +1100,7 @@ cmyth_conn_connect_path(char* path, cmyth_conn_t control, goto shut; } reply[sizeof(reply) - 1] = '\0'; - r = cmyth_rcv_string(conn, &err, reply, sizeof(reply) - 1, count); + r = cmyth_rcv_string(conn, &err, reply, sizeof(reply) - 1, count); if (err != 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", @@ -1261,7 +1261,7 @@ cmyth_conn_connect_recorder(cmyth_recorder_t rec, unsigned buflen, /* * cmyth_conn_check_block(cmyth_conn_t conn, unsigned long size) - * + * * Scope: PUBLIC * * Description @@ -1331,7 +1331,7 @@ cmyth_conn_check_block(cmyth_conn_t conn, unsigned long size) * cmyth_conn_get_recorder_from_num(cmyth_conn_t control, * cmyth_recorder_num_t num, * cmyth_recorder_t rec) - * + * * Scope: PUBLIC * * Description @@ -1428,8 +1428,8 @@ cmyth_conn_get_recorder_from_num(cmyth_conn_t conn, int id) /* * cmyth_conn_get_free_recorder(cmyth_conn_t control, cmyth_recorder_t rec) - * - * + * + * * Scope: PUBLIC * * Description @@ -1546,7 +1546,7 @@ cmyth_conn_get_freespace(cmyth_conn_t control, if (control->conn_version >= 32) { snprintf(msg, sizeof(msg), "QUERY_FREE_SPACE_SUMMARY"); } - else if (control->conn_version >= 17) + else if (control->conn_version >= 17) { snprintf(msg, sizeof(msg), "QUERY_FREE_SPACE"); } else { snprintf(msg, sizeof(msg), "QUERY_FREESPACE"); } @@ -1566,7 +1566,7 @@ cmyth_conn_get_freespace(cmyth_conn_t control, ret = count; goto out; } - + if (control->conn_version >= 17) { if ((r=cmyth_rcv_int64(control, &err, &lreply, count)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, @@ -1964,4 +1964,4 @@ cmyth_conn_reschedule_recordings(cmyth_conn_t conn, int recordid) out: pthread_mutex_unlock(&mutex); return err; -} +} \ No newline at end of file diff --git a/lib/cmyth/libcmyth/file.c b/lib/cmyth/libcmyth/file.c index d053e1322..db01e913a 100644 --- a/lib/cmyth/libcmyth/file.c +++ b/lib/cmyth/libcmyth/file.c @@ -26,7 +26,7 @@ /* * cmyth_file_destroy(cmyth_file_t file) - * + * * Scope: PRIVATE (static) * * Description @@ -107,7 +107,7 @@ void cmyth_file_set_closed_callback(cmyth_file_t file, void (*callback)(cmyth_fi /* * cmyth_file_create(cmyth_conn_t control) - * + * * Scope: PRIVATE (mapped to __cmyth_file_create) * * Description @@ -148,7 +148,7 @@ cmyth_file_create(cmyth_conn_t control) /* * cmyth_file_data(cmyth_file_t p) - * + * * Scope: PUBLIC * * Description @@ -177,7 +177,7 @@ cmyth_file_data(cmyth_file_t file) /* * cmyth_file_control(cmyth_file_t p) - * + * * Scope: PUBLIC * * Description @@ -206,7 +206,7 @@ cmyth_file_control(cmyth_file_t file) /* * cmyth_file_start(cmyth_file_t p) - * + * * Scope: PUBLIC * * Description @@ -230,7 +230,7 @@ cmyth_file_start(cmyth_file_t file) /* * cmyth_file_length(cmyth_file_t p) - * + * * Scope: PUBLIC * * Description @@ -253,7 +253,7 @@ cmyth_file_length(cmyth_file_t file) } /* - * cmyth_update_file_length(cmyth_file_t file, unsigned long long newLength) + * cmyth_file_update_length(cmyth_file_t file, unsigned long long newlen) * * Scope: PUBLIC * @@ -268,12 +268,12 @@ cmyth_file_length(cmyth_file_t file) * Failure: a int containing -errno */ int -cmyth_update_file_length(cmyth_file_t file, unsigned long long newLength) +cmyth_file_update_length(cmyth_file_t file, unsigned long long newlen) { if (!file) { return -EINVAL; } - file->file_length = newLength; + file->file_length = newlen; return 0; } @@ -304,7 +304,7 @@ cmyth_file_position(cmyth_file_t file) /* * cmyth_file_get_block(cmyth_file_t file, char *buf, unsigned long len) - * + * * Scope: PUBLIC * * Description @@ -378,7 +378,7 @@ cmyth_file_select(cmyth_file_t file, struct timeval *timeout) /* * cmyth_file_request_block(cmyth_file_t file, unsigned long len) - * + * * Scope: PUBLIC * * Description @@ -449,7 +449,7 @@ cmyth_file_request_block(cmyth_file_t file, unsigned long len) /* * cmyth_file_seek(cmyth_file_t file, long long offset, int whence) - * + * * Scope: PUBLIC * * Description @@ -567,112 +567,13 @@ cmyth_file_seek(cmyth_file_t file, long long offset, int whence) out: pthread_mutex_unlock(&mutex); - - return ret; -} - -long long -cmyth_file_seek_unlocked(cmyth_file_t file, long long offset, int whence) -{ - char msg[128]; - int err; - int count; - int64_t c; - long r; - long long ret; - - if (file == NULL) - return -EINVAL; - - if ((offset == 0) && (whence == SEEK_CUR)) - return file->file_pos; - - if ((offset == file->file_pos) && (whence == SEEK_SET)) - return file->file_pos; - - ret = 0; - while(file->file_pos < file->file_req) { - c = file->file_req - file->file_pos; - if(c > sizeof(msg)) - c = sizeof(msg); - if ((ret = cmyth_file_get_block(file, msg, (unsigned long)c)) < 0) - break; - } - if (ret < 0) - goto out; - - if (file->file_control->conn_version >= 66) { - /* - * Since protocol 66 mythbackend expects to receive a single 64 bit integer rather than - * two 32 bit hi and lo integers. - */ - snprintf(msg, sizeof(msg), - "QUERY_FILETRANSFER %ld[]:[]SEEK[]:[]%"PRIu64"[]:[]%d[]:[]%"PRIu64, - file->file_id, - (int64_t)offset, - whence, - (int64_t)file->file_pos); - } - else { - snprintf(msg, sizeof(msg), - "QUERY_FILETRANSFER %ld[]:[]SEEK[]:[]%d[]:[]%d[]:[]%d[]:[]%d[]:[]%d", - file->file_id, - (int32_t)(offset >> 32), - (int32_t)(offset & 0xffffffff), - whence, - (int32_t)(file->file_pos >> 32), - (int32_t)(file->file_pos & 0xffffffff)); - } - - if ((err = cmyth_send_message(file->file_control, msg)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_send_message() failed (%d)\n", - __FUNCTION__, err); - ret = err; - goto out; - } - - if ((count=cmyth_rcv_length(file->file_control)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_rcv_length() failed (%d)\n", - __FUNCTION__, count); - ret = count; - goto out; - } - if ((r=cmyth_rcv_int64(file->file_control, &err, &c, count)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_rcv_int64() failed (%d)\n", - __FUNCTION__, r); - ret = err; - goto out; - } - - switch (whence) { - case SEEK_SET: - file->file_pos = offset; - break; - case SEEK_CUR: - file->file_pos += offset; - break; - case SEEK_END: - file->file_pos = file->file_length - offset; - break; - } - - file->file_req = file->file_pos; - if(file->file_pos > file->file_length) - file->file_length = file->file_pos; - - ret = file->file_pos; - - out: return ret; } /* * cmyth_file_read(cmyth_file_t file, char *buf, unsigned long len) - * + * * Scope: PUBLIC * * Description @@ -1060,9 +961,9 @@ void __cdecl _dosmaperr ( ) { int i; - + _doserrno = oserrno; /* set _doserrno */ - + /* check the table for the OS error code */ for (i = 0; i < ERRTABLESIZE; ++i) { if (oserrno == errtable[i].oscode) { @@ -1070,11 +971,11 @@ void __cdecl _dosmaperr ( return; } } - + /* The error code wasn't in the table. We check for a range of */ /* EACCES errors or exec failure errors (ENOEXEC). Otherwise */ /* EINVAL is returned. */ - + if (oserrno >= MIN_EACCES_RANGE && oserrno <= MAX_EACCES_RANGE) errno = EACCES; else if (oserrno >= MIN_EXEC_ERROR && oserrno <= MAX_EXEC_ERROR) diff --git a/lib/cmyth/libcmyth/input.c b/lib/cmyth/libcmyth/input.c index b9bda31c6..6bfb575a4 100644 --- a/lib/cmyth/libcmyth/input.c +++ b/lib/cmyth/libcmyth/input.c @@ -148,13 +148,8 @@ int cmyth_rcv_free_inputlist(cmyth_conn_t conn, int *err, int consumed; int total = 0; char *failed = NULL; - cmyth_input_t input; - char inputname[100]; - unsigned long sourceid; - unsigned long inputid; - unsigned long cardid; - unsigned long multiplexid; - unsigned long livetvorder; + cmyth_input_t input = NULL; + char tmp_str[255]; if (count <= 0) { *err = EINVAL; @@ -162,65 +157,58 @@ int cmyth_rcv_free_inputlist(cmyth_conn_t conn, int *err, } while (count) { - consumed = cmyth_rcv_string(conn, err, inputname, sizeof(inputname)-1, count); - inputname[sizeof(inputname)-1] = 0; + input = cmyth_input_create(); + consumed = cmyth_rcv_string(conn, err, tmp_str, sizeof(tmp_str), count); count -= consumed; total += consumed; if (*err) { - failed = "cmyth_rcv_string"; + failed = "cmyth_rcv_string() inputname"; goto fail; } + input->inputname = ref_strdup(tmp_str); - consumed = cmyth_rcv_ulong(conn, err, &sourceid, count); + consumed = cmyth_rcv_ulong(conn, err, &input->sourceid, count); count -= consumed; total += consumed; if (*err) { - failed = "cmyth_rcv_ulong"; + failed = "cmyth_rcv_ulong() sourceid"; goto fail; } - consumed = cmyth_rcv_ulong(conn, err, &inputid, count); + consumed = cmyth_rcv_ulong(conn, err, &input->inputid, count); count -= consumed; total += consumed; if (*err) { - failed = "cmyth_rcv_ulong"; + failed = "cmyth_rcv_ulong() inputid"; goto fail; } - consumed = cmyth_rcv_ulong(conn, err, &cardid, count); + consumed = cmyth_rcv_ulong(conn, err, &input->cardid, count); count -= consumed; total += consumed; if (*err) { - failed = "cmyth_rcv_ulong"; + failed = "cmyth_rcv_ulong() cardid"; goto fail; } - consumed = cmyth_rcv_ulong(conn, err, &multiplexid, count); + consumed = cmyth_rcv_ulong(conn, err, &input->multiplexid , count); count -= consumed; total += consumed; if (*err) { - failed = "cmyth_rcv_ulong"; + failed = "cmyth_rcv_ulong() multiplexid"; goto fail; } if (conn->conn_version >= 71) { - consumed = cmyth_rcv_ulong(conn, err, &livetvorder, count); + consumed = cmyth_rcv_ulong(conn, err, &input->livetvorder, count); count -= consumed; total += consumed; if (*err) { - failed = "cmyth_rcv_ulong"; + failed = "cmyth_rcv_ulong() livetvorder"; goto fail; } } - input = cmyth_input_create(); - input->inputname = ref_strdup(inputname); - input->sourceid = sourceid; - input->inputid = inputid; - input->cardid = cardid; - input->multiplexid = multiplexid; - input->livetvorder = livetvorder; - inputlist->input_list = realloc(inputlist->input_list, (++inputlist->input_count) * sizeof(cmyth_input_t)); inputlist->input_list[inputlist->input_count - 1] = input; @@ -229,7 +217,8 @@ int cmyth_rcv_free_inputlist(cmyth_conn_t conn, int *err, return total; fail: - cmyth_dbg(CMYTH_DBG_ERROR, "%s: %s() failed (%d)\n", + ref_release(input); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: %s failed (%d)\n", __FUNCTION__, failed, *err); return total; } diff --git a/lib/cmyth/libcmyth/livetv.c b/lib/cmyth/libcmyth/livetv.c index 812d277a4..d689982f3 100644 --- a/lib/cmyth/libcmyth/livetv.c +++ b/lib/cmyth/libcmyth/livetv.c @@ -43,7 +43,7 @@ static int cmyth_livetv_chain_add(cmyth_recorder_t rec, char * url, /* * cmyth_livetv_chain_destroy(cmyth_livetv_chain_t ltc) - * + * * Scope: PRIVATE (static) * * Description @@ -92,7 +92,7 @@ cmyth_livetv_chain_destroy(cmyth_livetv_chain_t ltc) /* * cmyth_livetv_chain_create(void) - * + * * Scope: PUBLIC * * Description @@ -135,7 +135,7 @@ cmyth_livetv_chain_create(char * chainid) */ /* * cmyth_livetv_chain_has_url(void) - * + * * Scope: PRIVATE * * Description @@ -186,7 +186,7 @@ cmyth_livetv_get_cur_file(cmyth_recorder_t rec) /* * cmyth_livetv_chain_add_file(cmyth_recorder_t rec, char * url, * cmyth_file_t fp) - * + * * Scope: PRIVATE * * Description @@ -238,7 +238,7 @@ cmyth_livetv_chain_add_file(cmyth_recorder_t rec, char * url, cmyth_file_t ft) /* * cmyth_livetv_chain_add_prog(cmyth_recorder_t rec, char * url, * cmyth_proginfo_t prog) - * + * * Scope: PRIVATE * * Description @@ -290,7 +290,7 @@ cmyth_livetv_chain_add_prog(cmyth_recorder_t rec, char * url, /* * cmyth_livetv_chain_add_url(cmyth_recorder_t rec, char * url) - * + * * Scope: PRIVATE * * Description @@ -359,7 +359,7 @@ cmyth_livetv_chain_add_url(cmyth_recorder_t rec, char * url) /* * cmyth_livetv_chain_add(cmyth_recorder_t rec, char * url, cmyth_file_t ft) - * + * * Scope: PRIVATE * * Description @@ -392,7 +392,7 @@ cmyth_livetv_chain_add(cmyth_recorder_t rec, char * url, cmyth_file_t ft, /* * cmyth_livetv_chain_update(cmyth_recorder_t rec, char * chainid, int buff) - * + * * Scope: PUBLIC * * Description @@ -650,7 +650,7 @@ cmyth_livetv_done_recording(cmyth_recorder_t rec, char * msg) /* * cmyth_livetv_chain_setup(cmyth_recorder_t old_rec) - * + * * Scope: PUBLIC * * Description @@ -806,7 +806,7 @@ cmyth_livetv_chain_select(cmyth_recorder_t rec, struct timeval *timeout) /* * cmyth_livetv_chain_switch(cmyth_recorder_t rec, int dir) - * + * * Scope: PUBLIC * * Description @@ -918,7 +918,7 @@ cmyth_livetv_chain_switch_last(cmyth_recorder_t rec) /* * cmyth_livetv_chain_request_block(cmyth_recorder_t file, unsigned long len) - * + * * Scope: PUBLIC * * Description @@ -1072,7 +1072,7 @@ cmyth_livetv_chain_duration(cmyth_recorder_t rec) /* * cmyth_livetv_chain_seek(cmyth_recorder_t file, long long offset, int whence) - * + * * Scope: PUBLIC * * Description @@ -1129,51 +1129,47 @@ cmyth_livetv_chain_seek(cmyth_recorder_t rec, long long offset, int whence) if (whence == SEEK_CUR) { - if (offset == 0) { - cur = rec->rec_livetv_chain->chain_current; - offset += rec->rec_livetv_chain->chain_files[cur]->file_req; - for (; cur > 0; cur--) { - offset += rec->rec_livetv_chain->chain_files[cur-1]->file_length; + if (offset == 0) { + cur = rec->rec_livetv_chain->chain_current; + offset += rec->rec_livetv_chain->chain_files[cur]->file_req; + for (; cur > 0; cur--) { + offset += rec->rec_livetv_chain->chain_files[cur-1]->file_length; + } + return offset; + } else { + cur = rec->rec_livetv_chain->chain_current; + fp = rec->rec_livetv_chain->chain_files[cur]; } - return offset; - } else { - cur = rec->rec_livetv_chain->chain_current; - fp = rec->rec_livetv_chain->chain_files[cur]; - } - offset += fp->file_req; + offset += fp->file_req; - while (offset > (long long)fp->file_length) { - cur++; - offset -= fp->file_length; - if(cur == ct) - return -1; - fp = rec->rec_livetv_chain->chain_files[cur]; - } + while (offset > (long long)fp->file_length) { + cur++; + offset -= fp->file_length; + if(cur == ct) + return -1; + fp = rec->rec_livetv_chain->chain_files[cur]; + } - while (offset < 0) { - cur--; - if(cur < 0) - return -1; - fp = rec->rec_livetv_chain->chain_files[cur]; - offset += fp->file_length; - } + while (offset < 0) { + cur--; + if(cur < 0) + return -1; + fp = rec->rec_livetv_chain->chain_files[cur]; + offset += fp->file_length; + } - offset -= fp->file_req; - } + offset -= fp->file_req; + } if (fp && cur >=0) { - pthread_mutex_lock(&mutex); - - ret = cmyth_file_seek_unlocked(fp, offset, whence); - - if (ret >= 0 ) { + if ((ret = cmyth_file_seek(fp, offset, whence)) >= 0) { + pthread_mutex_lock(&mutex); cur -= rec->rec_livetv_chain->chain_current; - cmyth_livetv_chain_switch(rec, cur); + cmyth_livetv_chain_switch(rec, cur); + pthread_mutex_unlock(&mutex); } - - pthread_mutex_unlock(&mutex); } else return -1; @@ -1183,7 +1179,7 @@ cmyth_livetv_chain_seek(cmyth_recorder_t rec, long long offset, int whence) /* * cmyth_livetv_read(cmyth_recorder_t rec, char *buf, unsigned long len) - * + * * Scope: PUBLIC * * Description @@ -1202,12 +1198,12 @@ int cmyth_livetv_read(cmyth_recorder_t rec, char *buf, unsigned long len) return cmyth_livetv_chain_read(rec, buf, len); else return cmyth_ringbuf_read(rec, buf, len); - + } /* * cmyth_livetv_seek(cmyth_recorder_t file, long long offset, int whence) - * + * * Scope: PUBLIC * * Description @@ -1242,7 +1238,7 @@ cmyth_livetv_seek(cmyth_recorder_t rec, long long offset, int whence) /* * cmyth_livetv_request_block(cmyth_recorder_t file, unsigned long len) - * + * * Scope: PUBLIC * * Description @@ -1274,7 +1270,7 @@ int cmyth_livetv_select(cmyth_recorder_t rec, struct timeval *timeout) { int rtrn; - + if(rec->rec_conn->conn_version >= 26) rtrn = cmyth_livetv_chain_select(rec, timeout); else diff --git a/lib/cmyth/libcmyth/mythtv_mysql.c b/lib/cmyth/libcmyth/mythtv_mysql.c index 2b1f7dc25..42a8d0989 100644 --- a/lib/cmyth/libcmyth/mythtv_mysql.c +++ b/lib/cmyth/libcmyth/mythtv_mysql.c @@ -33,18 +33,6 @@ #include #include -#ifdef _MSC_VER -static void nullprint(a, ...) { return; } -#define PRINTF nullprint -#define TRC nullprint -#elif 0 -#define PRINTF(x...) PRINTF(x) -#define TRC(fmt, args...) PRINTF(fmt, ## args) -#else -#define PRINTF(x...) -#define TRC(fmt, args...) -#endif - void cmyth_database_close(cmyth_database_t db) { @@ -128,7 +116,6 @@ cmyth_database_setup(cmyth_database_t db) 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); @@ -141,7 +128,6 @@ cmyth_database_set_host(cmyth_database_t db, char *host) 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); @@ -154,7 +140,6 @@ cmyth_database_set_user(cmyth_database_t db, char *user) 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); @@ -167,7 +152,6 @@ cmyth_database_set_pass(cmyth_database_t db, char *pass) 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); @@ -180,7 +164,6 @@ cmyth_database_set_name(cmyth_database_t db, char *name) int cmyth_database_set_port(cmyth_database_t db, unsigned short port) { - PRINTF("** SSDEBUG: setting the db port to %i\n", port); cmyth_database_close(db); db->db_port = port; return 1; @@ -200,7 +183,7 @@ cmyth_db_check_connection(cmyth_database_t db) * still good */ if (mysql_stat(db->mysql) == NULL) { - fprintf(stderr, "%s: mysql_stat() failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_stat() failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); cmyth_database_close(db); mysql_close(db->mysql); db->mysql = NULL; @@ -209,12 +192,12 @@ cmyth_db_check_connection(cmyth_database_t db) if (db->mysql == NULL) { db->mysql = mysql_init(NULL); if(db->mysql == NULL) { - fprintf(stderr,"%s: mysql_init() failed, insufficient memory?\n", __FUNCTION__); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_init() failed, insufficient memory?\n", __FUNCTION__); return -1; } if(NULL == mysql_real_connect(db->mysql,db->db_host,db->db_user,db->db_pass,db->db_name,db->db_port,NULL,0)) { - fprintf(stderr,"%s: mysql_connect() failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_connect() failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); cmyth_database_close(db); mysql_close(db->mysql); db->mysql = NULL; @@ -276,53 +259,21 @@ cmyth_db_get_connection(cmyth_database_t db) return db->mysql; } -/* - * DEPRECATED - */ -int -cmyth_schedule_recording(cmyth_conn_t conn, char * msg) -{ - int err=0; - int count; - char buf[256]; - - fprintf (stderr, "In function : %s\n",__FUNCTION__); - if (!conn) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); - return -1; - } - - pthread_mutex_lock(&mutex); - - if ((err = cmyth_send_message(conn, msg)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_send_message() failed (%d)\n",__FUNCTION__,err); - return err; - } - - count = cmyth_rcv_length(conn); - cmyth_rcv_string(conn, &err, buf, sizeof(buf)-1,count); - pthread_mutex_unlock(&mutex); - return err; -} - char * -cmyth_mysql_escape_chars(cmyth_database_t db, char * string) +cmyth_mysql_escape_chars(cmyth_database_t db, char * string) { char *N_string; size_t len; if(cmyth_db_check_connection(db) != 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", - __FUNCTION__); - fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", __FUNCTION__); return NULL; } len = strlen(string); N_string=ref_alloc(len*2+1); - mysql_real_escape_string(db->mysql,N_string,string,len); + mysql_real_escape_string(db->mysql,N_string,string,len); return (N_string); } @@ -338,7 +289,6 @@ cmyth_mysql_get_offset(cmyth_database_t db, int type, unsigned long recordid, un if(cmyth_db_check_connection(db) != 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", __FUNCTION__); - fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__); return -1; } if (type == 1) { // startoffset @@ -349,7 +299,7 @@ cmyth_mysql_get_offset(cmyth_database_t db, int type, unsigned long recordid, un } cmyth_dbg(CMYTH_DBG_ERROR, "%s : query=%s\n",__FUNCTION__, query); - + if(mysql_query(db->mysql,query)) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); return -1; @@ -357,7 +307,7 @@ cmyth_mysql_get_offset(cmyth_database_t db, int type, unsigned long recordid, un res = mysql_store_result(db->mysql); if ( (count = (int)mysql_num_rows(res)) >0) { row = mysql_fetch_row(res); - fprintf(stderr, "row grabbed done count=%d\n",count); + cmyth_dbg(CMYTH_DBG_DEBUG, "row grabbed done count=%d\n", count); mysql_free_result(res); return atoi(row[0]); } @@ -368,7 +318,7 @@ cmyth_mysql_get_offset(cmyth_database_t db, int type, unsigned long recordid, un } int -cmyth_set_watched_status_mysql(cmyth_database_t db, cmyth_proginfo_t prog, int watchedStat) +cmyth_mysql_set_watched_status(cmyth_database_t db, cmyth_proginfo_t prog, int watchedStat) { MYSQL_RES *res = NULL; const char *query_str = "UPDATE recorded SET watched = ? WHERE chanid = ? AND starttime = ?"; @@ -408,13 +358,12 @@ cmyth_mysql_get_recordid(cmyth_database_t db, unsigned long chanid, char *title, if(cmyth_db_check_connection(db) != 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", __FUNCTION__); - fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__); return NULL; } sprintf (query,"SELECT recordid FROM record WHERE (chanid=%ld AND title='%s' AND subtitle='%s' AND description='%s' AND seriesid='%s' AND programid='%s')",chanid,title,subtitle,description,seriesid,programid); cmyth_dbg(CMYTH_DBG_DEBUG, "%s : query=%s\n",__FUNCTION__, query); - + if(mysql_query(db->mysql,query)) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); return NULL; @@ -422,7 +371,7 @@ cmyth_mysql_get_recordid(cmyth_database_t db, unsigned long chanid, char *title, res = mysql_store_result(db->mysql); if ( (count = (int)mysql_num_rows(res)) >0) { row = mysql_fetch_row(res); - fprintf(stderr, "row grabbed done count=%d\n",count); + cmyth_dbg(CMYTH_DBG_DEBUG, "row grabbed done count=%d\n", count); mysql_free_result(res); return row[0]; } @@ -432,89 +381,6 @@ cmyth_mysql_get_recordid(cmyth_database_t db, unsigned long chanid, char *title, } } -/* - * DEPRECATED - */ -int -cmyth_mysql_delete_scheduled_recording(cmyth_database_t db, char * query) -{ - int rows=0; - if(cmyth_db_check_connection(db) != 0) - { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", - __FUNCTION__); - fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__); - return -1; - } - cmyth_dbg(CMYTH_DBG_DEBUG, "mysql query :%s\n",query); - - if(mysql_real_query(db->mysql,query,(unsigned int) strlen(query))) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", - __FUNCTION__, mysql_error(db->mysql)); - return -1; - } - rows=(int)mysql_affected_rows(db->mysql); - - if (rows <=0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", - __FUNCTION__, mysql_error(db->mysql)); - } - - return rows; -} - -/* - * DEPRECATED - */ -int -cmyth_mysql_insert_into_record(cmyth_database_t db, char * query, char * query1, char * query2, char *title, char * subtitle, char * description, char * callsign) -{ - int rows=0; - char *N_title; - char *N_subtitle; - char *N_description; - char *N_callsign; - char N_query[2570]; - - if(cmyth_db_check_connection(db) != 0) - { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", - __FUNCTION__); - fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__); - return -1; - } - - N_title = ref_alloc(strlen(title)*2+1); - mysql_real_escape_string(db->mysql,N_title,title,strlen(title)); - N_subtitle = ref_alloc(strlen(subtitle)*2+1); - mysql_real_escape_string(db->mysql,N_subtitle,subtitle,strlen(subtitle)); - N_description = ref_alloc(strlen(description)*2+1); - mysql_real_escape_string(db->mysql,N_description,description,strlen(description)); - N_callsign = ref_alloc(strlen(callsign)*2+1); - mysql_real_escape_string(db->mysql,N_callsign,callsign,strlen(callsign)); - - snprintf(N_query,2500,"%s '%s','%s','%s' %s '%s' %s",query,N_title,N_subtitle,N_description,query1,N_callsign,query2); - ref_release(N_title); - ref_release(N_subtitle); - ref_release(N_callsign); - cmyth_dbg(CMYTH_DBG_DEBUG, "mysql query :%s\n",N_query); - - if(mysql_real_query(db->mysql,N_query,(unsigned int) strlen(N_query))) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", - __FUNCTION__, mysql_error(db->mysql)); - return -1; - } - rows=(int)mysql_insert_id(db->mysql); - - if (rows <=0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", - __FUNCTION__, mysql_error(db->mysql)); - } - - - return rows; -} - int cmyth_mysql_get_prev_recorded(cmyth_database_t db, cmyth_program_t **prog) { @@ -562,7 +428,6 @@ cmyth_mysql_get_prev_recorded(cmyth_database_t db, cmyth_program_t **prog) sizeof_strncpy((*prog)[rows].name, row[11]); //sizeof_strncpy((*prog)[rows].rec_status, row[14]); (*prog)[rows].rec_status = safe_atol(row[14]); - //fprintf(stderr, "row=%s val=%d\n",row[14],(*prog)[rows].rec_status); rows++; } mysql_free_result(res); @@ -571,7 +436,7 @@ cmyth_mysql_get_prev_recorded(cmyth_database_t db, cmyth_program_t **prog) } int -cmyth_mysql_get_guide(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, time_t endtime) +cmyth_mysql_get_guide(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, time_t endtime) { MYSQL_RES *res= NULL; MYSQL_ROW row; @@ -636,7 +501,7 @@ cmyth_mysql_get_guide(cmyth_database_t db, cmyth_program_t **prog, time_t startt return rows; } -int +int cmyth_mysql_get_recgroups(cmyth_database_t db, cmyth_recgroups_t **sqlrecgroups) { MYSQL_RES *res=NULL; @@ -671,7 +536,7 @@ cmyth_mysql_get_recgroups(cmyth_database_t db, cmyth_recgroups_t **sqlrecgroups) int -cmyth_mysql_get_prog_finder_char_title(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name) +cmyth_mysql_get_prog_finder_char_title(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name) { MYSQL_RES *res=NULL; MYSQL_ROW row; @@ -735,7 +600,7 @@ cmyth_mysql_get_prog_finder_char_title(cmyth_database_t db, cmyth_program_t **pr } int -cmyth_mysql_get_prog_finder_time(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name) +cmyth_mysql_get_prog_finder_time(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, char *program_name) { MYSQL_RES *res = NULL; MYSQL_ROW row; @@ -794,24 +659,8 @@ cmyth_mysql_get_prog_finder_time(cmyth_database_t db, cmyth_program_t **prog, t return rows; } -int -fill_program_recording_status(cmyth_conn_t conn, char * msg) -{ - int err=0; - fprintf (stderr, "In function : %s\n",__FUNCTION__); - if (!conn) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); - return -1; - } - if ((err = cmyth_send_message(conn, msg)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_send_message() failed (%d)\n",__FUNCTION__,err); - return err; - } - return err; -} int -cmyth_update_bookmark_setting(cmyth_database_t db, cmyth_proginfo_t prog) +cmyth_mysql_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 = ?"; @@ -836,8 +685,8 @@ cmyth_update_bookmark_setting(cmyth_database_t db, cmyth_proginfo_t prog) return (1); } -long long -cmyth_get_bookmark_mark(cmyth_database_t db, cmyth_proginfo_t prog, long long bk, int mode) +long long +cmyth_mysql_get_bookmark_mark(cmyth_database_t db, cmyth_proginfo_t prog, long long bk, int mode) { MYSQL_RES *res = NULL; MYSQL_ROW row; @@ -891,7 +740,7 @@ cmyth_mysql_get_bookmark_offset(cmyth_database_t db, unsigned long chanid, long int rows = 0; int rectype = 0; cmyth_mysql_query_t * query; - + const char *query_str = "SELECT chanid, UNIX_TIMESTAMP(CONVERT_TZ(starttime,?,'SYSTEM')), mark, offset, type FROM recordedseek WHERE chanid = ? AND mark<= ? AND starttime = ? ORDER BY MARK DESC LIMIT 1;"; query = cmyth_mysql_query_create(db,query_str); @@ -969,7 +818,7 @@ cmyth_mysql_query_commbreak_count(cmyth_database_t db, unsigned long chanid, tim count = (int)mysql_num_rows(res); mysql_free_result(res); return (count); -} +} int cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t start_ts_dt, cmyth_commbreaklist_t breaklist, int conn_version) @@ -988,7 +837,7 @@ cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t if (conn_version >= 43) { query_str = "SELECT m.type,m.mark,s.mark,s.offset FROM recordedmarkup m INNER JOIN recordedseek AS s ON m.chanid = s.chanid AND m.starttime = s.starttime WHERE m.chanid = ? AND m.starttime = ? AND m.type in (?,?) and FLOOR(m.mark/?)=FLOOR(s.mark/?) ORDER BY `m`.`mark` LIMIT 300 "; } - else { + else { query_str = "SELECT m.type AS type, m.mark AS mark, s.offset AS offset FROM recordedmarkup m INNER JOIN recordedseek AS s ON (m.chanid = s.chanid AND m.starttime = s.starttime AND (FLOOR(m.mark / 15) + 1) = s.mark) WHERE m.chanid = ? AND m.starttime = ? AND m.type IN (?, ?) ORDER BY mark;"; } @@ -1051,7 +900,7 @@ cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t commbreak->start_offset = safe_atoll(row[3]); start_previous = commbreak->start_mark; } - else if (safe_atoll(row[1]) == safe_atoll(row[2])) { + else if (safe_atoll(row[1]) == safe_atoll(row[2])) { commbreak = cmyth_commbreak_create(); commbreak->start_mark = safe_atoll(row[1]); commbreak->start_offset = safe_atoll(row[3]); @@ -1074,7 +923,7 @@ cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t } } else { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: Unknown COMMBREAK returned\n", + cmyth_dbg(CMYTH_DBG_ERROR, "%s: Unknown COMMBREAK returned\n", __FUNCTION__); return -1; } @@ -1082,7 +931,7 @@ cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t } } - // mythtv protolcol version < 43 + // mythtv protolcol version < 43 else { while ((row = mysql_fetch_row(res))) { if ((i % 2) == 0) { @@ -1111,7 +960,7 @@ cmyth_mysql_get_commbreak_list(cmyth_database_t db, unsigned long chanid, time_t } int -cmyth_tuner_type_check(cmyth_database_t db, cmyth_recorder_t rec, int check_tuner_type) { +cmyth_mysql_tuner_type_check(cmyth_database_t db, cmyth_recorder_t rec, int check_tuner_type) { MYSQL_RES *res=NULL; MYSQL_ROW row; const char * query_str = "SELECT cardtype from capturecard WHERE cardid=?"; @@ -1121,7 +970,7 @@ cmyth_tuner_type_check(cmyth_database_t db, cmyth_recorder_t rec, int check_tune cmyth_dbg(CMYTH_DBG_ERROR,"MythTV Tuner check not enabled in Mythtv Options\n"); return (1); } - + query = cmyth_mysql_query_create(db,query_str); if (cmyth_mysql_query_param_uint(query,rec->rec_id) < 0) { @@ -1152,39 +1001,6 @@ cmyth_tuner_type_check(cmyth_database_t db, cmyth_recorder_t rec, int check_tune } } -int -cmyth_mythtv_remove_previous_recorded(cmyth_database_t db,char *query) -{ - MYSQL_RES *res=NULL; - char N_query[128]; - int rows; - - if(cmyth_db_check_connection(db) != 0) - { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", - __FUNCTION__); - fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__); - return -1; - } - - mysql_real_escape_string(db->mysql,N_query,query,strlen(query)); - - if(mysql_query(db->mysql,query)) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", - __FUNCTION__, mysql_error(db->mysql)); - return -1; - } - res = mysql_store_result(db->mysql); - rows=(int)mysql_insert_id(db->mysql); - if (rows <=0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", - __FUNCTION__, mysql_error(db->mysql)); - } - mysql_free_result(res); - - return rows; -} - int cmyth_mysql_testdb_connection(cmyth_database_t db,char **message) { char *buf=ref_alloc(sizeof(char)*1001); @@ -1197,16 +1013,14 @@ cmyth_mysql_testdb_connection(cmyth_database_t db,char **message) { if (db->mysql == NULL) { db->mysql = mysql_init(NULL); if(db->mysql == NULL) { - fprintf(stderr,"%s: mysql_init() failed, insufficient memory?", __FUNCTION__); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_init() failed, insufficient memory?", __FUNCTION__); snprintf(buf, 1000, "mysql_init() failed, insufficient memory?"); *message=buf; return -1; } if (NULL == mysql_real_connect(db->mysql, db->db_host,db->db_user,db->db_pass,db->db_name,db->db_port,NULL,0)) { - fprintf(stderr,"%s: mysql_connect() failed: %s\n", __FUNCTION__, - mysql_error(db->mysql)); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_connect() failed: %s\n", __FUNCTION__, mysql_error(db->mysql)); snprintf(buf, 1000, "%s",mysql_error(db->mysql)); - fprintf (stderr,"buf = %s\n",buf); *message=buf; cmyth_database_close(db); return -1; @@ -1217,193 +1031,8 @@ cmyth_mysql_testdb_connection(cmyth_database_t db,char **message) { return 1; } -static void -cmyth_chanlist_destroy(cmyth_chanlist_t pl) -{ - int i; - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - if (!pl) { - return; - } - for (i = 0; i < pl->chanlist_count; ++i) { - if (pl->chanlist_list[i]) { - ref_release(pl->chanlist_list[i]); - } - pl->chanlist_list[i] = NULL; - } - if (pl->chanlist_list) { - free(pl->chanlist_list); - } -} - cmyth_chanlist_t -cmyth_chanlist_create(void) -{ - cmyth_chanlist_t ret; - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - ret = ref_alloc(sizeof(*ret)); - if (!ret) { - return(NULL); - } - ref_set_destroy(ret, (ref_destroy_t)cmyth_chanlist_destroy); - - ret->chanlist_list = NULL; - ret->chanlist_count = 0; - return ret; -} - -cmyth_channel_t -cmyth_chanlist_get_item(cmyth_chanlist_t pl, int index) -{ - if (!pl) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", - __FUNCTION__); - return NULL; - } - if (!pl->chanlist_list) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL list\n", - __FUNCTION__); - return NULL; - } - if ((index < 0) || (index >= pl->chanlist_count)) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: index %d out of range\n", - __FUNCTION__, index); - return NULL; - } - ref_hold(pl->chanlist_list[index]); - return pl->chanlist_list[index]; -} - -int -cmyth_chanlist_get_count(cmyth_chanlist_t pl) -{ - if (!pl) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", - __FUNCTION__); - return -EINVAL; - } - return pl->chanlist_count; -} - -static void -cmyth_channel_destroy(cmyth_channel_t pl) -{ - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - if (!pl) { - return; - } - - if(pl->name) - ref_release(pl->name); - if(pl->callsign) - ref_release(pl->callsign); - if(pl->icon) - ref_release(pl->icon); -} - -long -cmyth_channel_chanid(cmyth_channel_t channel) -{ - if (!channel) { - return -EINVAL; - } - return channel->chanid; -} - -long -cmyth_channel_channum(cmyth_channel_t channel) -{ - if (!channel) { - return -EINVAL; - } - return channel->channum; -} - -char * -cmyth_channel_channumstr(cmyth_channel_t channel) -{ - if (!channel) { - return NULL; - } - return channel->chanstr; -} - -char * -cmyth_channel_name(cmyth_channel_t channel) -{ - if (!channel) { - return NULL; - } - return ref_hold(channel->name); -} - -char * -cmyth_channel_callsign(cmyth_channel_t channel) -{ - if (!channel) { - return NULL; - } - return ref_hold(channel->callsign); -} - - -char * -cmyth_channel_icon(cmyth_channel_t channel) -{ - if (!channel) { - return NULL; - } - return ref_hold(channel->icon); -} - -int -cmyth_channel_visible(cmyth_channel_t channel) -{ - if (!channel) { - return -EINVAL; - } - return channel->visible; -} - -int -cmyth_channel_sourceid(cmyth_channel_t channel) -{ - if (!channel) { - return -EINVAL; - } - return channel->sourceid; -} - -int -cmyth_channel_multiplex(cmyth_channel_t channel) -{ - if (!channel) { - return -EINVAL; - } - return channel->multiplex; -} - -cmyth_channel_t -cmyth_channel_create(void) -{ - cmyth_channel_t ret = ref_alloc(sizeof(*ret)); - memset(ret, 0, sizeof(*ret)); - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); - if (!ret) { - cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); - return NULL; - } - ref_set_destroy(ret, (ref_destroy_t)cmyth_channel_destroy); - - return ret; -} - - -cmyth_chanlist_t cmyth_mysql_get_chanlist(cmyth_database_t db) +cmyth_mysql_get_chanlist(cmyth_database_t db) { MYSQL_RES *res = NULL; MYSQL_ROW row; @@ -1436,13 +1065,13 @@ cmyth_chanlist_t cmyth_mysql_get_chanlist(cmyth_database_t db) while ((row = mysql_fetch_row(res))) { channel = cmyth_channel_create(); channel->chanid = safe_atol(row[0]); - channel->channum = safe_atoi(row[1]); - strncpy(channel->chanstr, row[1], 10); + channel->channum = safe_atol(row[1]); + channel->chanstr = ref_strdup(row[1]); channel->name = ref_strdup(row[2]); channel->icon = ref_strdup(row[3]); channel->visible = safe_atoi(row[4]); - channel->sourceid = safe_atoi(row[5]); - channel->multiplex = safe_atoi(row[6]); + channel->sourceid = safe_atol(row[5]); + channel->multiplex = safe_atol(row[6]); channel->callsign = ref_strdup(row[7]); chanlist->chanlist_list[rows] = channel; rows++; @@ -1453,95 +1082,8 @@ cmyth_chanlist_t cmyth_mysql_get_chanlist(cmyth_database_t db) return chanlist; } - -int cmyth_livetv_keep_recording(cmyth_recorder_t rec, cmyth_database_t db, int keep) -{ - cmyth_proginfo_t prog; - int autoexpire; - const char* recgroup; - cmyth_mysql_query_t * query; - time_t timestamp; - - if(cmyth_db_check_connection(db) != 0) - { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", __FUNCTION__); - return -1; - } - - prog = cmyth_recorder_get_cur_proginfo(rec); - if(!prog) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_recorder_get_cur_proginfo failed\n", __FUNCTION__); - return -1; - } - - if(keep) { - char* str; - str = cmyth_conn_get_setting(rec->rec_conn, prog->proginfo_hostname, "AutoExpireDefault"); - if(!str) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: failed to get AutoExpireDefault\n", __FUNCTION__); - ref_release(prog); - return -1; - } - autoexpire = atol(str); - recgroup = "Default"; - ref_release(str); - } else { - autoexpire = 10000; - recgroup = "LiveTV"; - } - - - timestamp = cmyth_timestamp_to_unixtime(prog->proginfo_rec_start_ts); - - query = cmyth_mysql_query_create(db,"UPDATE recorded SET autoexpire = ?, recgroup = ? WHERE chanid = ? AND starttime = ?"); - - if(cmyth_mysql_query_param_long(query,autoexpire) < 0 - || cmyth_mysql_query_param_str(query,recgroup) < 0 - || cmyth_mysql_query_param_long(query,prog->proginfo_chanId) < 0 - || cmyth_mysql_query_param_unixtime(query, timestamp, db->db_tz_utc) < 0) - { - cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); - ref_release(query); - ref_release(prog); - return -1; - } - - if(cmyth_mysql_query(query) < 0) - { - cmyth_dbg(CMYTH_DBG_ERROR,"%s, finalisation/execution of query failed!\n", __FUNCTION__); - ref_release(query); - ref_release(prog); - return -1; - } - ref_release(query); - ref_release(prog); - - if(rec->rec_conn->conn_version >= 26) - { - char msg[256]; - int err; - snprintf(msg, sizeof(msg), "QUERY_RECORDER %d[]:[]SET_LIVE_RECORDING[]:[]%d", - rec->rec_id, keep); - - if ((err=cmyth_send_message(rec->rec_conn, msg)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_send_message() failed (%d)\n", - __FUNCTION__, err); - return -1; - } - - if ((err=cmyth_rcv_okay(rec->rec_conn)) < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, - "%s: cmyth_rcv_okay() failed (%d)\n", - __FUNCTION__, err); - return -1; - } - } - return 1; -} - - -int cmyth_mysql_is_radio(cmyth_database_t db, int chanid) +int +cmyth_mysql_is_radio(cmyth_database_t db, unsigned long chanid) { cmyth_mysql_query_t * query; MYSQL_RES *res = NULL; @@ -1555,7 +1097,7 @@ int cmyth_mysql_is_radio(cmyth_database_t db, int chanid) query = cmyth_mysql_query_create(db,"SELECT is_audio_service FROM channelscan_channel INNER JOIN channel ON channelscan_channel.service_id=channel.serviceid WHERE channel.chanid = ? ORDER BY channelscan_channel.scanid DESC;"); - if(cmyth_mysql_query_param_long(query,chanid) < 0) { + if(cmyth_mysql_query_param_ulong(query,chanid) < 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; @@ -1572,101 +1114,22 @@ int cmyth_mysql_is_radio(cmyth_database_t db, int chanid) if ((row = mysql_fetch_row(res))) { retval = safe_atoi(row[0]); } else { - cmyth_dbg(CMYTH_DBG_ERROR, "%s, Channum %i not found\n", __FUNCTION__,chanid); + cmyth_dbg(CMYTH_DBG_ERROR, "%s, Channum %ld not found\n", __FUNCTION__, chanid); return -1; } mysql_free_result(res); return retval; } - -static void -cmyth_timer_destroy(cmyth_timer_t pl) -{ - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - if (!pl) { - return; - } - - if(pl->title) - ref_release(pl->title); - if(pl->description) - ref_release(pl->description); - if(pl->category) - ref_release(pl->category); - if(pl->rec_group) - ref_release(pl->rec_group); - if(pl->store_group) - ref_release(pl->store_group); - if(pl->play_group) - ref_release(pl->play_group); -} - - -cmyth_timer_t -cmyth_timer_create(void) -{ - cmyth_timer_t ret = ref_alloc(sizeof(*ret)); - memset(ret, 0, sizeof(*ret)); - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); - if (!ret) { - cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); - return NULL; - } - ref_set_destroy(ret, (ref_destroy_t)cmyth_timer_destroy); - - return ret; -} - - -static void -cmyth_timerlist_destroy(cmyth_timerlist_t pl) -{ - int i; - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - if (!pl) { - return; - } - for (i = 0; i < pl->timerlist_count; ++i) { - if (pl->timerlist_list[i]) { - ref_release(pl->timerlist_list[i]); - } - pl->timerlist_list[i] = NULL; - } - if (pl->timerlist_list) { - free(pl->timerlist_list); - } -} - -cmyth_timerlist_t -cmyth_timerlist_create(void) -{ - cmyth_timerlist_t ret; - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - ret = ref_alloc(sizeof(*ret)); - if (!ret) { - return(NULL); - } - ref_set_destroy(ret, (ref_destroy_t)cmyth_timerlist_destroy); - - ret->timerlist_list = NULL; - ret->timerlist_count = 0; - return ret; -} - - -cmyth_timerlist_t -cmyth_mysql_get_timers(cmyth_database_t db) +cmyth_recordingrulelist_t +cmyth_mysql_get_recordingrules(cmyth_database_t db) { MYSQL_RES *res= NULL; MYSQL_ROW row; const char *query_str = "SELECT recordid, chanid, UNIX_TIMESTAMP(CONVERT_TZ(ADDTIME(startdate,starttime),?,'SYSTEM')), UNIX_TIMESTAMP(CONVERT_TZ(ADDTIME(enddate,endtime),?,'SYSTEM')),title,description, type, category, subtitle, recpriority, startoffset, endoffset, search, inactive, station, dupmethod, dupin, recgroup, storagegroup, playgroup, autotranscode, (autouserjob1 | (autouserjob2 << 1) | (autouserjob3 << 2) | (autouserjob4 << 3)), autocommflag, autoexpire, maxepisodes, maxnewest, transcoder FROM record ORDER BY recordid"; int rows=0; - cmyth_timer_t timer; - cmyth_timerlist_t timerlist; + cmyth_recordingrule_t rr; + cmyth_recordingrulelist_t rrl; cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); @@ -1685,123 +1148,112 @@ cmyth_mysql_get_timers(cmyth_database_t db) return NULL; } - timerlist = cmyth_timerlist_create(); + rrl = cmyth_recordingrulelist_create(); - timerlist->timerlist_count = (int)mysql_num_rows(res); - timerlist->timerlist_list = malloc(timerlist->timerlist_count * sizeof(cmyth_timerlist_t)); - if (!timerlist->timerlist_list) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: malloc() failed for list\n", + rrl->recordingrulelist_count = (int)mysql_num_rows(res); + rrl->recordingrulelist_list = malloc(rrl->recordingrulelist_count * sizeof(cmyth_recordingrulelist_t)); + if (!rrl->recordingrulelist_list) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: malloc() failed for recschedule list\n", __FUNCTION__); - ref_release(timerlist); + ref_release(rrl); return NULL; } - memset(timerlist->timerlist_list, 0, timerlist->timerlist_count * sizeof(cmyth_timerlist_t)); + memset(rrl->recordingrulelist_list, 0, rrl->recordingrulelist_count * sizeof(cmyth_recordingrulelist_t)); while ((row = mysql_fetch_row(res))) { - timer = cmyth_timer_create(); - timer->recordid = safe_atol(row[0]); - timer->chanid = safe_atoi(row[1]); - timer->starttime = (time_t)safe_atol(row[2]); - timer->endtime = (time_t)safe_atol(row[3]); - timer->title = ref_strdup(row[4]); - timer->description = ref_strdup(row[5]); - timer->type = safe_atoi(row[6]); - timer->category = ref_strdup(row[7]); - timer->subtitle = ref_strdup(row[8]); - timer->priority = safe_atoi(row[9]); - timer->startoffset = safe_atoi(row[10]); - timer->endoffset = safe_atoi(row[11]); - timer->searchtype = safe_atoi(row[12]); - timer->inactive = safe_atoi(row[13]); - timer->callsign = ref_strdup(row[14]); - timer->dup_method = safe_atoi(row[15]); - timer->dup_in = safe_atoi(row[16]); - timer->rec_group = ref_strdup(row[17]); - timer->store_group = ref_strdup(row[18]); - timer->play_group = ref_strdup(row[19]); - timer->autotranscode = safe_atoi(row[20]); - timer->userjobs = safe_atoi(row[21]); - timer->autocommflag = safe_atoi(row[22]); - timer->autoexpire = safe_atoi(row[23]); - timer->maxepisodes = safe_atoi(row[24]); - timer->maxnewest = safe_atoi(row[25]); - timer->transcoder = safe_atoi(row[26]); - timerlist->timerlist_list[rows] = timer; + rr = cmyth_recordingrule_create(); + rr->recordid = safe_atol(row[0]); + rr->chanid = safe_atol(row[1]); + rr->starttime = cmyth_timestamp_from_unixtime((time_t)safe_atol(row[2])); + rr->endtime = cmyth_timestamp_from_unixtime((time_t)safe_atol(row[3])); + rr->title = ref_strdup(row[4]); + rr->description = ref_strdup(row[5]); + rr->type = safe_atol(row[6]); + rr->category = ref_strdup(row[7]); + rr->subtitle = ref_strdup(row[8]); + rr->recpriority = safe_atol(row[9]); + rr->startoffset = safe_atol(row[10]); + rr->endoffset = safe_atol(row[11]); + rr->searchtype = safe_atol(row[12]); + rr->inactive = safe_atoi(row[13]); + rr->callsign = ref_strdup(row[14]); + rr->dupmethod = safe_atol(row[15]); + rr->dupin = safe_atol(row[16]); + rr->recgroup = ref_strdup(row[17]); + rr->storagegroup = ref_strdup(row[18]); + rr->playgroup = ref_strdup(row[19]); + rr->autotranscode = safe_atoi(row[20]); + rr->userjobs = safe_atoi(row[21]); + rr->autocommflag = safe_atoi(row[22]); + rr->autoexpire = safe_atol(row[23]); + rr->maxepisodes = safe_atol(row[24]); + rr->maxnewest = safe_atol(row[25]); + rr->transcoder = safe_atol(row[26]); + rrl->recordingrulelist_list[rows] = rr; rows++; } mysql_free_result(res); cmyth_dbg(CMYTH_DBG_DEBUG, "%s: rows= %d\n", __FUNCTION__, rows); - return timerlist; + return rrl; } - int -cmyth_mysql_add_timer(cmyth_database_t db, int chanid,char* callsign, char* description, time_t starttime, time_t endtime,char* title,char* category,int type,char* subtitle, int priority, int startoffset, int endoffset, int searchtype, int inactive, - int dup_method, - int dup_in, - char* rec_group, - char* store_group, - char* play_group, - int autotranscode, - int userjobs, - int autocommflag, - int autoexpire, - int maxepisodes, - int maxnewest, - int transcoder) +cmyth_mysql_add_recordingrule(cmyth_database_t db, cmyth_recordingrule_t rr) { int ret = -1; int id=0; MYSQL* sql=cmyth_db_get_connection(db); const char *query_str = "INSERT INTO record (record.type, chanid, starttime, startdate, endtime, enddate, title, description, category, findid, findtime, station, subtitle, recpriority, startoffset, endoffset, search, inactive, dupmethod, dupin, recgroup, storagegroup, playgroup, autotranscode, autouserjob1, autouserjob2, autouserjob3, autouserjob4, autocommflag, autoexpire, maxepisodes, maxnewest, transcoder) VALUES (?, ?, TIME(?), DATE(?), TIME(?), DATE(?), ?, ?, ?, TO_DAYS(DATE(?)), TIME(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,?, ?, ?, ?);"; - char* esctitle = cmyth_mysql_escape_chars(db,title); - char* escdescription = cmyth_mysql_escape_chars(db,description); - char* esccategory = cmyth_mysql_escape_chars(db,category); - char* esccallsign=cmyth_mysql_escape_chars(db,callsign); - char* escsubtitle = cmyth_mysql_escape_chars(db,subtitle); + char* esctitle = cmyth_mysql_escape_chars(db, rr->title); + char* escdescription = cmyth_mysql_escape_chars(db, rr->description); + char* esccategory = cmyth_mysql_escape_chars(db, rr->category); + char* esccallsign = cmyth_mysql_escape_chars(db, rr->callsign); + char* escsubtitle = cmyth_mysql_escape_chars(db, rr->subtitle); + + char* escrec_group = cmyth_mysql_escape_chars(db, rr->recgroup); + char* escstore_group = cmyth_mysql_escape_chars(db, rr->storagegroup); + char* escplay_group = cmyth_mysql_escape_chars(db, rr->playgroup); - char* escrec_group = cmyth_mysql_escape_chars(db,rec_group); - char* escstore_group = cmyth_mysql_escape_chars(db,store_group); - char* escplay_group = cmyth_mysql_escape_chars(db,play_group); + time_t starttime = cmyth_timestamp_to_unixtime(rr->starttime); + time_t endtime = cmyth_timestamp_to_unixtime(rr->endtime); cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); - if ( cmyth_mysql_query_param_long(query, type) < 0 - || cmyth_mysql_query_param_long(query, chanid) < 0 + if ( cmyth_mysql_query_param_long(query, rr->type) < 0 + || cmyth_mysql_query_param_ulong(query, rr->chanid) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, db->db_tz_utc) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, db->db_tz_utc) < 0 || cmyth_mysql_query_param_unixtime(query, endtime, db->db_tz_utc) < 0 || cmyth_mysql_query_param_unixtime(query, endtime, db->db_tz_utc) < 0 - || cmyth_mysql_query_param_str(query, title ) < 0 - || cmyth_mysql_query_param_str(query, description ) < 0 - || cmyth_mysql_query_param_str(query, category ) < 0 + || cmyth_mysql_query_param_str(query, rr->title ) < 0 + || cmyth_mysql_query_param_str(query, rr->description ) < 0 + || cmyth_mysql_query_param_str(query, rr->category ) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, 0) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, 0) < 0 - || cmyth_mysql_query_param_str(query, callsign ) < 0 - || cmyth_mysql_query_param_str(query, subtitle ) < 0 - || cmyth_mysql_query_param_long(query, priority ) < 0 - || cmyth_mysql_query_param_long(query, startoffset ) < 0 - || cmyth_mysql_query_param_long(query, endoffset ) < 0 - || cmyth_mysql_query_param_long(query, searchtype ) < 0 - || cmyth_mysql_query_param_long(query, inactive ) < 0 - - || cmyth_mysql_query_param_long(query, dup_method ) < 0 - || cmyth_mysql_query_param_long(query, dup_in ) < 0 - || cmyth_mysql_query_param_str(query, rec_group ) < 0 - || cmyth_mysql_query_param_str(query, store_group ) < 0 - || cmyth_mysql_query_param_str(query, play_group ) < 0 - || cmyth_mysql_query_param_long(query, autotranscode ) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 1) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 2) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 4) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 8) < 0 - || cmyth_mysql_query_param_long(query, autocommflag ) < 0 - || cmyth_mysql_query_param_long(query, autoexpire ) < 0 - || cmyth_mysql_query_param_long(query, maxepisodes ) < 0 - || cmyth_mysql_query_param_long(query, maxnewest ) < 0 - || cmyth_mysql_query_param_long(query, transcoder ) < 0 + || cmyth_mysql_query_param_str(query, rr->callsign ) < 0 + || cmyth_mysql_query_param_str(query, rr->subtitle ) < 0 + || cmyth_mysql_query_param_long(query, rr->recpriority ) < 0 + || cmyth_mysql_query_param_long(query, rr->startoffset ) < 0 + || cmyth_mysql_query_param_long(query, rr->endoffset ) < 0 + || cmyth_mysql_query_param_long(query, rr->searchtype ) < 0 + || cmyth_mysql_query_param_uint(query, rr->inactive ) < 0 + || cmyth_mysql_query_param_long(query, rr->dupmethod ) < 0 + || cmyth_mysql_query_param_long(query, rr->dupin ) < 0 + || cmyth_mysql_query_param_str(query, rr->recgroup ) < 0 + || cmyth_mysql_query_param_str(query, rr->storagegroup ) < 0 + || cmyth_mysql_query_param_str(query, rr->playgroup ) < 0 + || cmyth_mysql_query_param_uint(query, rr->autotranscode ) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 1) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 2) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 4) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 8) < 0 + || cmyth_mysql_query_param_uint(query, rr->autocommflag ) < 0 + || cmyth_mysql_query_param_long(query, rr->autoexpire ) < 0 + || cmyth_mysql_query_param_long(query, rr->maxepisodes ) < 0 + || cmyth_mysql_query_param_long(query, rr->maxnewest ) < 0 + || cmyth_mysql_query_param_ulong(query, rr->transcoder ) < 0 ) { cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); ref_release(query); @@ -1838,14 +1290,14 @@ cmyth_mysql_add_timer(cmyth_database_t db, int chanid,char* callsign, char* desc } int -cmyth_mysql_delete_timer(cmyth_database_t db, int recordid) +cmyth_mysql_delete_recordingrule(cmyth_database_t db, unsigned long recordid) { int ret = -1; const char *query_str = "DELETE FROM record WHERE recordid = ?;"; cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); - if (cmyth_mysql_query_param_long(query, recordid) < 0) { + if (cmyth_mysql_query_param_ulong(query, recordid) < 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; @@ -1862,70 +1314,59 @@ cmyth_mysql_delete_timer(cmyth_database_t db, int recordid) } int -cmyth_mysql_update_timer(cmyth_database_t db, int recordid, int chanid, char* callsign, char* description, time_t starttime, time_t endtime, char* title, char* category, int type, char* subtitle, int priority, int startoffset, int endoffset, int searchtype, int inactive, - int dup_method, - int dup_in, - char* rec_group, - char* store_group, - char* play_group, - int autotranscode, - int userjobs, - int autocommflag, - int autoexpire, - int maxepisodes, - int maxnewest, - int transcoder) +cmyth_mysql_update_recordingrule(cmyth_database_t db, cmyth_recordingrule_t rr) { int ret = -1; const char *query_str = "UPDATE record SET record.type = ?, chanid = ?, starttime = TIME(?), startdate = DATE(?), endtime = TIME(?), enddate = DATE(?) ,title = ?, description = ?, category = ?, subtitle = ?, recpriority = ?, startoffset = ?, endoffset = ?, search = ?, inactive = ?, station = ?, dupmethod = ?, dupin = ?, recgroup = ?, storagegroup = ?, playgroup = ?, autotranscode = ?, autouserjob1 = ?, autouserjob2 = ?, autouserjob3 = ?, autouserjob4 = ?, autocommflag = ?, autoexpire = ?, maxepisodes = ?, maxnewest = ?, transcoder = ? WHERE recordid = ? ;"; - char* esctitle=cmyth_mysql_escape_chars(db,title); - char* escdescription=cmyth_mysql_escape_chars(db,description); - char* esccategory=cmyth_mysql_escape_chars(db,category); - char* esccallsign=cmyth_mysql_escape_chars(db,callsign); - char* escsubtitle=cmyth_mysql_escape_chars(db,subtitle); + char* esctitle = cmyth_mysql_escape_chars(db, rr->title); + char* escdescription = cmyth_mysql_escape_chars(db, rr->description); + char* esccategory = cmyth_mysql_escape_chars(db, rr->category); + char* esccallsign = cmyth_mysql_escape_chars(db, rr->callsign); + char* escsubtitle = cmyth_mysql_escape_chars(db, rr->subtitle); - char* escrec_group = cmyth_mysql_escape_chars(db,rec_group); - char* escstore_group = cmyth_mysql_escape_chars(db,store_group); - char* escplay_group = cmyth_mysql_escape_chars(db,play_group); + char* escrec_group = cmyth_mysql_escape_chars(db, rr->recgroup); + char* escstore_group = cmyth_mysql_escape_chars(db, rr->storagegroup); + char* escplay_group = cmyth_mysql_escape_chars(db, rr->playgroup); + + time_t starttime = cmyth_timestamp_to_unixtime(rr->starttime); + time_t endtime = cmyth_timestamp_to_unixtime(rr->endtime); cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); - if ( cmyth_mysql_query_param_long(query, type) < 0 - || cmyth_mysql_query_param_long(query, chanid) < 0 + if ( cmyth_mysql_query_param_long(query, rr->type) < 0 + || cmyth_mysql_query_param_ulong(query, rr->chanid) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, db->db_tz_utc) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, db->db_tz_utc) < 0 || cmyth_mysql_query_param_unixtime(query, endtime, db->db_tz_utc) < 0 || cmyth_mysql_query_param_unixtime(query, endtime, db->db_tz_utc) < 0 - || cmyth_mysql_query_param_str(query, title ) < 0 - || cmyth_mysql_query_param_str(query, description ) < 0 - || cmyth_mysql_query_param_str(query, category ) < 0 - || cmyth_mysql_query_param_str(query, subtitle ) < 0 - || cmyth_mysql_query_param_long(query, priority ) < 0 - || cmyth_mysql_query_param_long(query, startoffset ) < 0 - || cmyth_mysql_query_param_long(query, endoffset ) < 0 - || cmyth_mysql_query_param_long(query, searchtype ) < 0 - || cmyth_mysql_query_param_long(query, inactive ) < 0 - || cmyth_mysql_query_param_str(query, callsign ) < 0 - - || cmyth_mysql_query_param_long(query, dup_method ) < 0 - || cmyth_mysql_query_param_long(query, dup_in ) < 0 - || cmyth_mysql_query_param_str(query, rec_group ) < 0 - || cmyth_mysql_query_param_str(query, store_group ) < 0 - || cmyth_mysql_query_param_str(query, play_group ) < 0 - || cmyth_mysql_query_param_long(query, autotranscode ) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 1) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 2) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 4) < 0 - || cmyth_mysql_query_param_long(query, userjobs & 8) < 0 - || cmyth_mysql_query_param_long(query, autocommflag ) < 0 - || cmyth_mysql_query_param_long(query, autoexpire ) < 0 - || cmyth_mysql_query_param_long(query, maxepisodes ) < 0 - || cmyth_mysql_query_param_long(query, maxnewest ) < 0 - || cmyth_mysql_query_param_long(query, transcoder ) < 0 - - || cmyth_mysql_query_param_long(query, recordid) < 0 + || cmyth_mysql_query_param_str(query, rr->title ) < 0 + || cmyth_mysql_query_param_str(query, rr->description ) < 0 + || cmyth_mysql_query_param_str(query, rr->category ) < 0 + || cmyth_mysql_query_param_str(query, rr->subtitle ) < 0 + || cmyth_mysql_query_param_long(query, rr->recpriority ) < 0 + || cmyth_mysql_query_param_long(query, rr->startoffset ) < 0 + || cmyth_mysql_query_param_long(query, rr->endoffset ) < 0 + || cmyth_mysql_query_param_long(query, rr->searchtype ) < 0 + || cmyth_mysql_query_param_uint(query, rr->inactive ) < 0 + || cmyth_mysql_query_param_str(query, rr->callsign ) < 0 + || cmyth_mysql_query_param_long(query, rr->dupmethod ) < 0 + || cmyth_mysql_query_param_long(query, rr->dupin ) < 0 + || cmyth_mysql_query_param_str(query, rr->recgroup ) < 0 + || cmyth_mysql_query_param_str(query, rr->storagegroup ) < 0 + || cmyth_mysql_query_param_str(query, rr->playgroup ) < 0 + || cmyth_mysql_query_param_uint(query, rr->autotranscode ) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 1) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 2) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 4) < 0 + || cmyth_mysql_query_param_uint(query, rr->userjobs & 8) < 0 + || cmyth_mysql_query_param_uint(query, rr->autocommflag ) < 0 + || cmyth_mysql_query_param_long(query, rr->autoexpire ) < 0 + || cmyth_mysql_query_param_long(query, rr->maxepisodes ) < 0 + || cmyth_mysql_query_param_long(query, rr->maxnewest ) < 0 + || cmyth_mysql_query_param_ulong(query, rr->transcoder ) < 0 + || cmyth_mysql_query_param_ulong(query, rr->recordid) < 0 ) { cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); ref_release(query); @@ -1961,266 +1402,17 @@ cmyth_mysql_update_timer(cmyth_database_t db, int recordid, int chanid, char* ca return 0; } - -int cmyth_timer_recordid(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->recordid; -} - - -int cmyth_timer_chanid(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->chanid; -} - -char* cmyth_timer_callsign(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->callsign); -} - -time_t cmyth_timer_starttime(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->starttime; -} - -time_t cmyth_timer_endtime(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->endtime; -} - -char* cmyth_timer_title(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->title); -} - -char* cmyth_timer_description(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->description); -} - -int cmyth_timer_type(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->type; -} - - -char* cmyth_timer_category(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->category); -} - -char* cmyth_timer_subtitle(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->subtitle); -} - -int cmyth_timer_priority(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->priority; -} - -int cmyth_timer_startoffset(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->startoffset; -} - -int cmyth_timer_endoffset(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->endoffset; -} - -int cmyth_timer_searchtype(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->searchtype; -} - -int cmyth_timer_inactive(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->inactive; -} - -int cmyth_timer_dup_method(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->dup_method; -} - -int cmyth_timer_dup_in(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->dup_in; -} - -char* cmyth_timer_rec_group(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->rec_group); -} - -char* cmyth_timer_store_group(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->store_group); -} - -char* cmyth_timer_play_group(cmyth_timer_t timer) -{ - if (!timer) { - return NULL; - } - return ref_hold(timer->play_group); -} - -int cmyth_timer_autotranscode(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->autotranscode; -} - -int cmyth_timer_userjobs(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->userjobs; -} - -int cmyth_timer_autocommflag(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->autocommflag; -} - -int cmyth_timer_autoexpire(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->autoexpire; -} - -int cmyth_timer_maxepisodes(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->maxepisodes; -} - -int cmyth_timer_maxnewest(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->maxnewest; -} - -int cmyth_timer_transcoder(cmyth_timer_t timer) -{ - if (!timer) { - return -EINVAL; - } - return timer->transcoder; -} - -cmyth_timer_t cmyth_timerlist_get_item(cmyth_timerlist_t pl, int index) -{ - if (!pl) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL timer list\n", - __FUNCTION__); - return NULL; - } - if (!pl->timerlist_list) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL list\n", - __FUNCTION__); - return NULL; - } - if ((index < 0) || (index >= pl->timerlist_count)) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: index %d out of range\n", - __FUNCTION__, index); - return NULL; - } - ref_hold(pl->timerlist_list[index]); - return pl->timerlist_list[index]; -} - -extern int cmyth_timerlist_get_count(cmyth_timerlist_t pl) -{ - if (!pl) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL timer list\n", - __FUNCTION__); - return -EINVAL; - } - return pl->timerlist_count; -} - -extern int cmyth_mysql_get_channelgroups(cmyth_database_t db, cmyth_channelgroups_t** changroups) +int +cmyth_mysql_get_channelgroups(cmyth_database_t db, cmyth_channelgroup_t **changroups) { - MYSQL_RES *res= NULL; + MYSQL_RES *res = NULL; MYSQL_ROW row; const char *query_str = "SELECT grpid, name FROM channelgroupnames"; - int rows=0; - cmyth_channelgroups_t* ret; + int rows = 0; + cmyth_channelgroup_t *ret; cmyth_mysql_query_t * query; - query = cmyth_mysql_query_create(db,query_str); + query = cmyth_mysql_query_create(db, query_str); res = cmyth_mysql_query_result(query); ref_release(query); @@ -2229,18 +1421,17 @@ extern int cmyth_mysql_get_channelgroups(cmyth_database_t db, cmyth_channelgroup return 0; } - ret = ref_alloc( sizeof( cmyth_channelgroups_t ) * (int)mysql_num_rows(res)); + ret = ref_alloc( sizeof( cmyth_channelgroup_t ) * (int)mysql_num_rows(res)); if (!ret) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", - __FUNCTION__); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", __FUNCTION__); mysql_free_result(res); - return 0; + return -1; } while ((row = mysql_fetch_row(res))) { - ret[rows].ID=safe_atoi(row[0]); - safe_strncpy(ret[rows].channelgroup, row[1], 65); + ret[rows].grpid = safe_atol(row[0]); + safe_strncpy(ret[rows].name, row[1], 65); rows++; } @@ -2251,18 +1442,19 @@ extern int cmyth_mysql_get_channelgroups(cmyth_database_t db, cmyth_channelgroup return rows; } -extern int cmyth_mysql_get_channelids_in_group(cmyth_database_t db, unsigned int groupid, int** chanids) +int +cmyth_mysql_get_channelids_in_group(cmyth_database_t db, unsigned long grpid, unsigned long **chanids) { - MYSQL_RES *res= NULL; + MYSQL_RES *res = NULL; MYSQL_ROW row; const char *query_str = "SELECT chanid FROM channelgroup WHERE grpid = ?"; - int rows=0; - int* ret; + int rows = 0; + unsigned long *ret; cmyth_mysql_query_t * query; - query = cmyth_mysql_query_create(db,query_str); - if (cmyth_mysql_query_param_long(query, groupid) < 0 + query = cmyth_mysql_query_create(db, query_str); + if (cmyth_mysql_query_param_ulong(query, grpid) < 0 ) { cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); ref_release(query); @@ -2277,17 +1469,16 @@ extern int cmyth_mysql_get_channelids_in_group(cmyth_database_t db, unsigned int return 0; } - ret = ref_alloc(sizeof(int)* (int)mysql_num_rows(res)); + ret = ref_alloc(sizeof(unsigned long)* (int)mysql_num_rows(res)); if (!ret) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", - __FUNCTION__); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", __FUNCTION__); mysql_free_result(res); - return 0; + return -1; } while ((row = mysql_fetch_row(res))) { - ret[rows]=safe_atoi(row[0]); + ret[rows] = safe_atol(row[0]); rows++; } @@ -2297,17 +1488,17 @@ extern int cmyth_mysql_get_channelids_in_group(cmyth_database_t db, unsigned int return rows; } - -int cmyth_mysql_get_recorder_list(cmyth_database_t db, cmyth_rec_t** reclist) +int +cmyth_mysql_get_recorder_source_list(cmyth_database_t db, cmyth_recorder_source_t **rsrc) { - MYSQL_RES *res= NULL; + MYSQL_RES *res = NULL; MYSQL_ROW row; const char *query_str = "SELECT cardid, sourceid FROM cardinput"; - int rows=0; - cmyth_rec_t* ret; + int rows = 0; + cmyth_recorder_source_t *ret; cmyth_mysql_query_t * query; - query = cmyth_mysql_query_create(db,query_str); + query = cmyth_mysql_query_create(db, query_str); res = cmyth_mysql_query_result(query); ref_release(query); @@ -2317,43 +1508,43 @@ int cmyth_mysql_get_recorder_list(cmyth_database_t db, cmyth_rec_t** reclist) return 0; } - ret = ref_alloc( sizeof( cmyth_rec_t ) * (int)mysql_num_rows(res)); + ret = ref_alloc( sizeof( cmyth_recorder_source_t ) * (int)mysql_num_rows(res)); if (!ret) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", - __FUNCTION__); + cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", __FUNCTION__); mysql_free_result(res); - return 0; + return -1; } while ((row = mysql_fetch_row(res))) { - ret[rows].recid=safe_atoi(row[0]); - ret[rows].sourceid=safe_atoi(row[1]); + ret[rows].recid = safe_atol(row[0]); + ret[rows].sourceid = safe_atol(row[1]); rows++; } mysql_free_result(res); cmyth_dbg(CMYTH_DBG_DEBUG, "%s: rows= %d\n", __FUNCTION__, rows); - *reclist = ret; + *rsrc = ret; return rows; } -int cmyth_mysql_get_prog_finder_time_title_chan(cmyth_database_t db, cmyth_program_t *prog, char* title, time_t starttime, int chanid) +int +cmyth_mysql_get_prog_finder_time_title_chan(cmyth_database_t db, cmyth_program_t *prog, time_t starttime, char *program_name, unsigned long chanid) { - MYSQL_RES *res= NULL; + MYSQL_RES *res = NULL; MYSQL_ROW row; const char *query_str = "SELECT program.chanid,UNIX_TIMESTAMP(CONVERT_TZ(program.starttime,?,'SYSTEM')),UNIX_TIMESTAMP(CONVERT_TZ(program.endtime,?,'SYSTEM')),program.title,program.description,program.subtitle,program.programid,program.seriesid,program.category,channel.channum,channel.callsign,channel.name,channel.sourceid FROM program INNER JOIN channel ON program.chanid=channel.chanid WHERE program.chanid = ? AND program.title LIKE ? AND program.starttime = ? AND program.manualid = 0 ORDER BY (channel.channum + 0), program.starttime ASC "; - int rows=0; + int rows = 0; - char* esctitle=cmyth_mysql_escape_chars(db,title); + char* esctitle=cmyth_mysql_escape_chars(db, program_name); cmyth_mysql_query_t * query; - query = cmyth_mysql_query_create(db,query_str); + query = cmyth_mysql_query_create(db, query_str); if (cmyth_mysql_query_param_str(query, db->db_tz_name) < 0 || cmyth_mysql_query_param_str(query, db->db_tz_name) < 0 - || cmyth_mysql_query_param_long(query, chanid) < 0 + || cmyth_mysql_query_param_ulong(query, chanid) < 0 || cmyth_mysql_query_param_str(query, esctitle ) < 0 || cmyth_mysql_query_param_unixtime(query, starttime, db->db_tz_utc) < 0 ) { @@ -2375,20 +1566,20 @@ int cmyth_mysql_get_prog_finder_time_title_chan(cmyth_database_t db, cmyth_progr if ((row = mysql_fetch_row(res))) { rows++; if(prog) { - prog->chanid = safe_atoi(row[0]); - prog->recording=0; - prog->starttime= (time_t)safe_atol(row[1]); - prog->endtime= (time_t)safe_atol(row[2]); + prog->chanid = safe_atol(row[0]); + prog->recording = 0; + prog->starttime = (time_t)safe_atol(row[1]); + prog->endtime = (time_t)safe_atol(row[2]); sizeof_strncpy(prog->title, row[3]); sizeof_strncpy(prog->description, row[4]); sizeof_strncpy(prog->subtitle, row[5]); sizeof_strncpy(prog->programid, row[6]); sizeof_strncpy(prog->seriesid, row[7]); sizeof_strncpy(prog->category, row[8]); - prog->channum = safe_atoi(row[9]); + prog->channum = safe_atol(row[9]); sizeof_strncpy(prog->callsign, row[10]); sizeof_strncpy(prog->name, row[11]); - prog->sourceid = safe_atoi(row[12]); + prog->sourceid = safe_atol(row[12]); prog->startoffset = 0; prog->endoffset = 0; } @@ -2399,9 +1590,10 @@ int cmyth_mysql_get_prog_finder_time_title_chan(cmyth_database_t db, cmyth_progr return rows; } -void destroy_char_array(void* p) +static void +destroy_char_array(void *p) { - char** ptr = (char**)p; + char **ptr = (char**)p; if(!ptr) return; while (*ptr) { @@ -2410,13 +1602,14 @@ void destroy_char_array(void* p) } } -int cmyth_mysql_get_storagegroups(cmyth_database_t db, char** *profiles) +int +cmyth_mysql_get_storagegroups(cmyth_database_t db, char** *sg) { MYSQL_RES *res = NULL; MYSQL_ROW row; const char *query_str = "SELECT groupname FROM storagegroup"; int rows = 0; - char **ret; /* = profiles;*/ + char **ret; cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); @@ -2446,18 +1639,19 @@ int cmyth_mysql_get_storagegroups(cmyth_database_t db, char** *profiles) mysql_free_result(res); cmyth_dbg(CMYTH_DBG_DEBUG, "%s: rows= %d\n", __FUNCTION__, rows); - *profiles = ret; + *sg = ret; return rows; } -int cmyth_mysql_get_playgroups(cmyth_database_t db, char** *profiles) +int +cmyth_mysql_get_playgroups(cmyth_database_t db, char** *pg) { MYSQL_RES *res = NULL; MYSQL_ROW row; const char *query_str = "SELECT name FROM playgroup"; int rows = 0; - char **ret; /* = profiles;*/ + char **ret; cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); @@ -2487,12 +1681,13 @@ int cmyth_mysql_get_playgroups(cmyth_database_t db, char** *profiles) mysql_free_result(res); cmyth_dbg(CMYTH_DBG_DEBUG, "%s: rows= %d\n", __FUNCTION__, rows); - *profiles = ret; + *pg = ret; return rows; } -int cmyth_mysql_get_recprofiles(cmyth_database_t db, cmyth_recprofile_t **profiles) +int +cmyth_mysql_get_recprofiles(cmyth_database_t db, cmyth_recprofile_t **profiles) { MYSQL_RES *res = NULL; MYSQL_ROW row; @@ -2532,17 +1727,18 @@ int cmyth_mysql_get_recprofiles(cmyth_database_t db, cmyth_recprofile_t **profil return rows; } -char* cmyth_mysql_get_cardtype(cmyth_database_t db, int chanid) +char * +cmyth_mysql_get_cardtype(cmyth_database_t db, unsigned long chanid) { MYSQL_RES *res = NULL; MYSQL_ROW row; - const char *query_str = "SELECT cardtype FROM channel LEFT JOIN cardinput ON channel.sourceid=cardinput.sourceid LEFT JOIN capturecard ON cardinput.cardid=capturecard.cardid WHERE channel.chanid = ?"; + const char *query_str = "SELECT cardtype FROM channel LEFT JOIN cardinput ON channel.sourceid=cardinput.sourceid LEFT JOIN capturecard ON cardinput.cardid=capturecard.cardid WHERE channel.chanid = ?"; char* retval = ""; cmyth_mysql_query_t * query; query = cmyth_mysql_query_create(db,query_str); - if ( cmyth_mysql_query_param_long(query, chanid) < 0) { + if ( cmyth_mysql_query_param_ulong(query, chanid) < 0) { cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); ref_release(query); return NULL; @@ -2591,7 +1787,7 @@ cmyth_mysql_get_recording_markup(cmyth_database_t db, cmyth_proginfo_t prog, cmy start_ts_dt = cmyth_timestamp_to_unixtime(prog->proginfo_rec_start_ts); query = cmyth_mysql_query_create(db, query_str); - if (cmyth_mysql_query_param_long(query, prog->proginfo_chanId) < 0 + if (cmyth_mysql_query_param_ulong(query, prog->proginfo_chanId) < 0 || cmyth_mysql_query_param_unixtime(query, start_ts_dt, db->db_tz_utc) < 0 || cmyth_mysql_query_param_int(query, type) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); @@ -2605,7 +1801,7 @@ cmyth_mysql_get_recording_markup(cmyth_database_t db, cmyth_proginfo_t prog, cmy return -1; } while ((row = mysql_fetch_row(res))) { - data = safe_atoi(row[0]); + data = safe_atoll(row[0]); rows++; } mysql_free_result(res); @@ -2653,7 +1849,7 @@ cmyth_mysql_estimate_rec_framerate(cmyth_database_t db, cmyth_proginfo_t prog) query = cmyth_mysql_query_create(db,query_str); - if (cmyth_mysql_query_param_long(query, prog->proginfo_chanId) < 0 + if (cmyth_mysql_query_param_ulong(query, prog->proginfo_chanId) < 0 || cmyth_mysql_query_param_unixtime(query, start_ts_dt, db->db_tz_utc) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); ref_release(query); @@ -2666,7 +1862,7 @@ cmyth_mysql_estimate_rec_framerate(cmyth_database_t db, cmyth_proginfo_t prog) return -1; } while ((row = mysql_fetch_row(res))) { - mark = safe_atoi(row[0]); + mark = safe_atoll(row[0]); rows++; } mysql_free_result(res); @@ -2681,7 +1877,7 @@ cmyth_mysql_estimate_rec_framerate(cmyth_database_t db, cmyth_proginfo_t prog) } /* - * cmyth_mysql_get_framerate(...) + * cmyth_mysql_get_recording_framerate(...) * * Scope: PUBLIC * diff --git a/lib/cmyth/libcmyth/proglist.c b/lib/cmyth/libcmyth/proglist.c index 0a718e45c..63ec6dd6e 100644 --- a/lib/cmyth/libcmyth/proglist.c +++ b/lib/cmyth/libcmyth/proglist.c @@ -29,350 +29,9 @@ #include #include -extern void destroy_char_array2(void* p) -{ - char** ptr = (char**)p; - if (!ptr) - return; - while (*ptr) { - ref_release(*ptr); - ptr++; - } -} - -int cmyth_storagegroup_filelist(cmyth_conn_t control, char** *sgFilelist, char* sg2List, char* host) -{ - char msg[256]; - int res = 0; - int count; - int err = 0; - int i = 0; - char **ret; - int consumed; /* = profiles;*/ - char tmp_str[32768]; - - if (!control) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); - return 0; - } - - pthread_mutex_lock(&mutex); - - snprintf(msg, sizeof(msg), "QUERY_SG_GETFILELIST[]:[]%s[]:[]%s[]:[][]:[]1", host, sg2List); - - err = cmyth_send_message(control, msg); - if (err < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); - res = 0; - goto out; - } - - count = cmyth_rcv_length(control); - if (count < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); - res = 0; - goto out; - } - - ret = (char**)ref_alloc(sizeof( char*) * (count + 1)); /* count + 1 ? */ - if (!ret) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", __FUNCTION__); - res = 0; - goto out; - } - ref_set_destroy((void*)ret,destroy_char_array2); - - while (i < count) { - consumed = cmyth_rcv_string(control, &err, tmp_str, sizeof(tmp_str) - 1, count); - count -= consumed; - if (err) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, count); - res = 0; - goto out; - } - ret[res] = ref_strdup(tmp_str); - res++; - } - - ret[res] = NULL; - - cmyth_dbg(CMYTH_DBG_ERROR, "%s: results= %d\n", __FUNCTION__, res); - *sgFilelist=ret; - - out: - pthread_mutex_unlock(&mutex); - return res; -} - -static void -cmyth_storagegroup_file_destroy(cmyth_storagegroup_file_t pl) -{ - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - if (!pl) { - return; - } - if(pl->filename) - ref_release(pl->filename); - if(pl->storagegroup) - ref_release(pl->storagegroup); - if(pl->hostname) - ref_release(pl->hostname); -} - -cmyth_storagegroup_file_t -cmyth_storagegroup_file_create(void) -{ - cmyth_storagegroup_file_t ret = ref_alloc(sizeof(*ret)); - memset(ret, 0, sizeof(*ret)); - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); - if (!ret) { - cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); - return NULL; - } - ref_set_destroy(ret, (ref_destroy_t)cmyth_storagegroup_file_destroy); - - return ret; -} - -static void -cmyth_storagegroup_filelist_destroy(cmyth_storagegroup_filelist_t pl) -{ - int i; - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - if (!pl) { - return; - } - for (i = 0; i < pl->storagegroup_filelist_count; ++i) { - if (pl->storagegroup_filelist_list[i]) { - ref_release(pl->storagegroup_filelist_list[i]); - } - pl->storagegroup_filelist_list[i] = NULL; - } - if (pl->storagegroup_filelist_list) { - free(pl->storagegroup_filelist_list); - } -} - -cmyth_storagegroup_filelist_t -cmyth_storagegroup_filelist_create(void) -{ - cmyth_storagegroup_filelist_t ret; - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); - ret = ref_alloc(sizeof(*ret)); - if (!ret) { - return(NULL); - } - ref_set_destroy(ret, (ref_destroy_t)cmyth_storagegroup_filelist_destroy); - - ret->storagegroup_filelist_list = NULL; - ret->storagegroup_filelist_count = 0; - return ret; -} - -int -cmyth_storagegroup_update_fileinfo(cmyth_conn_t control, cmyth_storagegroup_file_t file) -{ - char msg[256]; - int count; - int err = 0; - int consumed; /* = profiles;*/ - char tmp_str[32768]; - - if (!control) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); - return -1; - } - - if (!file) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: no file specified\n", __FUNCTION__); - return -1; - } - - snprintf(msg, sizeof(msg), "QUERY_SG_FILEQUERY[]:[]%s[]:[]%s[]:[]%s",file->hostname , file->storagegroup, file->filename); - - err = cmyth_send_message(control, msg); - if (err < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); - return -1; - } - - count = cmyth_rcv_length(control); - if (count < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); - return -1; - } - - consumed = cmyth_rcv_string(control, &err, tmp_str, sizeof(tmp_str) - 1, count); - count -= consumed; - - if (err) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, count); - return -1; - } else if (count == 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: QUERY_SG_FILEQUERY failed(%s)\n", __FUNCTION__, tmp_str); - return -1; - } - - consumed = cmyth_rcv_ulong(control, &err, &(file->modified), count); - count -= consumed; - if (err) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_ulong() failed (%d)\n", __FUNCTION__, count); - return -1; - } - - consumed = cmyth_rcv_ulong(control, &err, &(file->size), count); - count -= consumed; - if (err) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_ulong_long() failed (%d)\n", __FUNCTION__, count); - return -1; - } - - return 0; -} - -cmyth_storagegroup_filelist_t -cmyth_storagegroup_get_filelist(cmyth_conn_t control,char* storagegroup, char* hostname) -{ - char msg[256]; - int res = 0; - int count = 0; - int err = 0; - int i = 0; - int listsize = 10; - cmyth_storagegroup_filelist_t ret = 0; - cmyth_storagegroup_file_t file = 0; - int consumed = 0; /* = profiles; */ - char tmp_str[32768]; - - if (!control) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); - return 0; - } - - pthread_mutex_lock(&mutex); - - snprintf(msg, sizeof(msg), "QUERY_SG_GETFILELIST[]:[]%s[]:[]%s[]:[][]:[]1", hostname, storagegroup); - - err = cmyth_send_message(control, msg); - if (err < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); - goto out; - } - - count = cmyth_rcv_length(control); - if (count < 0) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); - goto out; - } - - ret = cmyth_storagegroup_filelist_create(); - - if (!ret) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", __FUNCTION__); - ref_release(ret); - ret = 0; - goto out; - } - - ret->storagegroup_filelist_count = 0; - ret->storagegroup_filelist_list = malloc(listsize * sizeof(cmyth_storagegroup_file_t)); - if (!ret->storagegroup_filelist_list) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for filelist list\n", __FUNCTION__); - ref_release(ret); - ret = 0; - goto out; - } - while (count) { - consumed = cmyth_rcv_string(control, &err, tmp_str, sizeof(tmp_str) - 1, count); - count -= consumed; - if (err) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, count); - ref_release(ret); - ret = 0; - goto out; - } - if (res>listsize-1) - { - listsize += 10; - ret->storagegroup_filelist_list = realloc(ret->storagegroup_filelist_list,listsize * sizeof(cmyth_storagegroup_file_t)); - if (!ret->storagegroup_filelist_list) { - cmyth_dbg(CMYTH_DBG_ERROR, "%s: realloc() failed for filelist list\n", __FUNCTION__); - ref_release(ret); - ret = 0; - goto out; - } - } - file = cmyth_storagegroup_file_create(); - file->filename = ref_strdup(tmp_str); - file->storagegroup = ref_strdup(storagegroup); - file->hostname = ref_strdup(hostname); - file->size = 0; - file->modified = 0; - ret->storagegroup_filelist_list[res] = file; - res++; - } - ret->storagegroup_filelist_count=res; - - for(i = 0;i< ret->storagegroup_filelist_count;i++) { - cmyth_storagegroup_update_fileinfo(control,ret->storagegroup_filelist_list[i]); - } - - cmyth_dbg(CMYTH_DBG_DEBUG, "%s: results= %d\n", __FUNCTION__, res); - - out: - pthread_mutex_unlock(&mutex); - return ret; -} - -int cmyth_storagegroup_filelist_count(cmyth_storagegroup_filelist_t fl) -{ - if (!fl) { - return -EINVAL; - } - return fl->storagegroup_filelist_count; -} - -cmyth_storagegroup_file_t cmyth_storagegroup_filelist_get_item(cmyth_storagegroup_filelist_t fl, int index) -{ - if (!fl||index>=fl->storagegroup_filelist_count) { - return NULL; - } - ref_hold(fl->storagegroup_filelist_list[index]); - return fl->storagegroup_filelist_list[index];; - } - -char* cmyth_storagegroup_file_get_filename(cmyth_storagegroup_file_t file) -{ - if (!file) { - return NULL; - } - return ref_hold(file->filename); -} - -unsigned long cmyth_storagegroup_file_get_lastmodified(cmyth_storagegroup_file_t file) -{ - if (!file) { - return 0; - } - return file->modified; -} - -unsigned long long cmyth_storagegroup_file_get_size(cmyth_storagegroup_file_t file) -{ - if (!file) { - return 0; - } - return file->size; -} - - /* * cmyth_proglist_destroy(void) - * + * * Scope: PRIVATE (static) * * Description @@ -407,7 +66,7 @@ cmyth_proglist_destroy(cmyth_proglist_t pl) /* * cmyth_proglist_create(void) - * + * * Scope: PUBLIC * * Description @@ -547,7 +206,7 @@ cmyth_proglist_get_count(cmyth_proglist_t pl) * cmyth_proglist_get_list(cmyth_conn_t conn, * cmyth_proglist_t proglist, * char *msg, char *func) - * + * * Scope: PRIVATE (static) * * Description @@ -633,7 +292,7 @@ cmyth_proglist_get_list(cmyth_conn_t conn, /* * cmyth_proglist_get_all_recorded(cmyth_conn_t control, * cmyth_proglist_t *proglist) - * + * * Scope: PUBLIC * * Description @@ -683,7 +342,7 @@ cmyth_proglist_get_all_recorded(cmyth_conn_t control) /* * cmyth_proglist_get_all_pending(cmyth_conn_t control, * cmyth_proglist_t *proglist) - * + * * Scope: PUBLIC * * Description @@ -726,7 +385,7 @@ cmyth_proglist_get_all_pending(cmyth_conn_t control) /* * cmyth_proglist_get_all_scheduled(cmyth_conn_t control, * cmyth_proglist_t *proglist) - * + * * Scope: PUBLIC * * Description @@ -769,7 +428,7 @@ cmyth_proglist_get_all_scheduled(cmyth_conn_t control) /* * cmyth_proglist_get_conflicting(cmyth_conn_t control, * cmyth_proglist_t *proglist) - * + * * Scope: PUBLIC * * Description @@ -818,7 +477,7 @@ cmyth_proglist_get_conflicting(cmyth_conn_t control) * * Return an integer value to specify the relative position of the timestamp * This is a helper function for the sort function called by qsort. It will - * sort any of the timetstamps for the qsort functions + * sort any of the timetstamps for the qsort functions * * Return Value: * @@ -846,7 +505,7 @@ static int sort_timestamp(cmyth_timestamp_t X, cmyth_timestamp_t Y) return 1; else if (X->timestamp_day < Y->timestamp_day) return -1; - else /* X->timestamp_day == Y->timestamp_day */ + else /* X->timestamp_day == Y->timestamp_day */ { if (X->timestamp_hour > Y->timestamp_hour) return 1; @@ -881,10 +540,10 @@ static int sort_timestamp(cmyth_timestamp_t X, cmyth_timestamp_t Y) * Description * * Return an integer value to a qsort function to specify the relative - * position of the recorded date + * position of the recorded date * * Return Value: - * + * * Same Day: 0 * Date a > b: 1 * Date a < b: -1 @@ -912,7 +571,7 @@ recorded_compare(const void *a, const void *b) * position of the original airdate * * Return Value: - * + * * Same Day: 0 * Date a > b: 1 * Date a < b: -1 @@ -936,15 +595,15 @@ airdate_compare(const void *a, const void *b) * * Description * - * Sort the epispde list by mythtv_sort setting. Check to ensure that the + * Sort the epispde list by mythtv_sort setting. Check to ensure that the * program list is not null and pass the proglist_list to the qsort function * * Return Value: - * + * * Success = 0 * Failure = -1 - */ -int + */ +int cmyth_proglist_sort(cmyth_proglist_t pl, int count, cmyth_proglist_sort_t sort) { if (!pl) { @@ -968,7 +627,7 @@ cmyth_proglist_sort(cmyth_proglist_t pl, int count, cmyth_proglist_sort_t sort) case MYTHTV_SORT_ORIGINAL_AIRDATE: /*Default Date Recorded */ qsort((cmyth_proginfo_t)pl->proglist_list, count, sizeof(pl->proglist_list) , airdate_compare); break; - default: + default: printf("Unsupported MythTV sort type\n"); } diff --git a/lib/cmyth/libcmyth/recordingrule.c b/lib/cmyth/libcmyth/recordingrule.c new file mode 100644 index 000000000..90896ef22 --- /dev/null +++ b/lib/cmyth/libcmyth/recordingrule.c @@ -0,0 +1,735 @@ +/* + * Copyright (C) 2005-2012 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include +#include +#include +#include +#include + +/* + * cmyth_recordingrule_destroy(cmyth_recordingrule_t rr) + * + * Scope: PRIVATE (static) + * + * Description + * + * Destroy the recording schedule structure pointed to by 'rr' and release + * its storage. This should only be called by ref_release(). + * All others should use ref_release() to release references to a recording + * schedule structure. + * + * Return Value: + * + * None. + */ +static void +cmyth_recordingrule_destroy(cmyth_recordingrule_t rr) +{ + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!rr) { + return; + } + + if (rr->title) + ref_release(rr->title); + if (rr->description) + ref_release(rr->description); + if (rr->category) + ref_release(rr->category); + if (rr->recgroup) + ref_release(rr->recgroup); + if (rr->storagegroup) + ref_release(rr->storagegroup); + if (rr->playgroup) + ref_release(rr->playgroup); + if (rr->starttime) + ref_release(rr->starttime); + if (rr->endtime) + ref_release(rr->endtime); +} + +/* + * cmyth_recordingrule_create(void) + * + * Scope: PRIVATE + * + * Description + * + * Create a recording schedule structure to be used to hold channel and return + * a pointer to the structure. + * Before forgetting the reference to this recording schedule structure the + * caller must call ref_release(). + * + * Return Value: + * + * Success: A non-NULL cmyth_channel_t (this type is a pointer) + * + * Failure: NULL + */ +cmyth_recordingrule_t +cmyth_recordingrule_create(void) +{ + cmyth_recordingrule_t ret = ref_alloc(sizeof(*ret)); + memset(ret, 0, sizeof(*ret)); + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!ret) { + cmyth_dbg(CMYTH_DBG_DEBUG, "%s: ref_alloc() failed\n", __FUNCTION__); + return NULL; + } + ref_set_destroy(ret, (ref_destroy_t)cmyth_recordingrule_destroy); + + ret->starttime = cmyth_timestamp_create(); + if (!ret->starttime) { + cmyth_dbg(CMYTH_DBG_DEBUG, "%s: cmyth_timestamp_create() failed\n", __FUNCTION__); + goto err; + } + ret->endtime = cmyth_timestamp_create(); + if (!ret->endtime) { + cmyth_dbg(CMYTH_DBG_DEBUG, "%s: cmyth_timestamp_create() failed\n", __FUNCTION__); + goto err; + } + return ret; + + err: + ref_release(ret); + return NULL; +} + +/* + * cmyth_recordingrulelist_destroy(cmyth_recordingrulelist_t rrl) + * + * Scope: PRIVATE (static) + * + * Description + * + * Destroy the recordings schedule list structure pointed to by 'rrl' and + * release its storage. This should only be called by ref_release(). + * All others should use ref_release() to release references to a recordings + * schedule list structure. + * + * Return Value: + * + * None. + */ +static void +cmyth_recordingrulelist_destroy(cmyth_recordingrulelist_t rrl) +{ + int i; + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!rrl) { + return; + } + for (i = 0; i < rrl->recordingrulelist_count; ++i) { + if (rrl->recordingrulelist_list[i]) { + ref_release(rrl->recordingrulelist_list[i]); + } + rrl->recordingrulelist_list[i] = NULL; + } + if (rrl->recordingrulelist_list) { + free(rrl->recordingrulelist_list); + } +} + +/* + * cmyth_recordingrulelist_create(void) + * + * Scope: PRIVATE + * + * Description + * + * Create a recordings schedule list structure and return a pointer to the + * structure. + * Before forgetting the reference to this recordings schedule list structure + * the caller must call ref_release(). + * + * Return Value: + * + * Success: A non-NULL cmyth_recordingrulelist_t (this type is a pointer) + * + * Failure: NULL + */ +cmyth_recordingrulelist_t +cmyth_recordingrulelist_create(void) +{ + cmyth_recordingrulelist_t ret; + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + ret = ref_alloc(sizeof(*ret)); + if (!ret) { + return(NULL); + } + ref_set_destroy(ret, (ref_destroy_t)cmyth_recordingrulelist_destroy); + + ret->recordingrulelist_list = NULL; + ret->recordingrulelist_count = 0; + return ret; +} + +/* + * cmyth_recordingrule_init(void) + * + * Scope: PUBLIC + * + * Description + * + * Initialize a new recording schedule structure. The structure is initialized + * to default values. + * Before forgetting the reference to this recording schedule structure + * the caller must call ref_release(). + * + * Return Value: + * + * Success: A non-NULL cmyth_recordingrule_t (this type is a pointer) + * + * Failure: NULL + */ +cmyth_recordingrule_t +cmyth_recordingrule_init(void) +{ + cmyth_recordingrule_t rr = cmyth_recordingrule_create(); + if (!rr) { + cmyth_dbg(CMYTH_DBG_ERROR,"%s: cmyth_recordingrule_create failed\n", __FUNCTION__); + return NULL; + } + cmyth_recordingrule_set_recordid(rr, 0); + cmyth_recordingrule_set_chanid(rr, 0); + cmyth_recordingrule_set_callsign(rr, ""); + cmyth_recordingrule_set_starttime(rr, 0); + cmyth_recordingrule_set_endtime(rr, 0); + cmyth_recordingrule_set_title(rr, ""); + cmyth_recordingrule_set_description(rr, ""); + cmyth_recordingrule_set_type(rr, RRULE_DONT_RECORD); + cmyth_recordingrule_set_category(rr, ""); + cmyth_recordingrule_set_subtitle(rr, ""); + cmyth_recordingrule_set_recpriority(rr, 0); + cmyth_recordingrule_set_startoffset(rr, 0); + cmyth_recordingrule_set_endoffset(rr, 0); + cmyth_recordingrule_set_searchtype(rr, RRULE_NO_SEARCH); + cmyth_recordingrule_set_inactive(rr, 0); + cmyth_recordingrule_set_dupmethod(rr, RRULE_CHECK_NONE); + cmyth_recordingrule_set_dupin(rr, RRULE_IN_RECORDED); + cmyth_recordingrule_set_recgroup(rr, "Default"); + cmyth_recordingrule_set_storagegroup(rr, "Default"); + cmyth_recordingrule_set_playgroup(rr, "Default"); + cmyth_recordingrule_set_autotranscode(rr, 0); + cmyth_recordingrule_set_userjobs(rr, 0); + cmyth_recordingrule_set_autocommflag(rr, 0); + cmyth_recordingrule_set_autoexpire(rr, 0); + cmyth_recordingrule_set_maxepisodes(rr, 0); + cmyth_recordingrule_set_maxnewest(rr, 0); + cmyth_recordingrule_set_transcoder(rr, 0); + return rr; +} + +unsigned long +cmyth_recordingrule_recordid(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->recordid; +} + +void +cmyth_recordingrule_set_recordid(cmyth_recordingrule_t rr, unsigned long recordid) +{ + rr->recordid = recordid; +} + +unsigned long +cmyth_recordingrule_chanid(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->chanid; +} + +void +cmyth_recordingrule_set_chanid(cmyth_recordingrule_t rr, unsigned long chanid) +{ + rr->chanid = chanid; +} + +char * +cmyth_recordingrule_callsign(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->callsign); +} + +void +cmyth_recordingrule_set_callsign(cmyth_recordingrule_t rr, char *callsign) +{ + if (rr->callsign) + ref_release(rr->callsign); + rr->callsign = ref_strdup(callsign); +} + +time_t +cmyth_recordingrule_starttime(cmyth_recordingrule_t rr) +{ + if (!rr) { + return 0; + } + return cmyth_timestamp_to_unixtime(rr->starttime); +} + +void +cmyth_recordingrule_set_starttime(cmyth_recordingrule_t rr, time_t starttime) +{ + if (rr->starttime) + ref_release(rr->starttime); + rr->starttime = cmyth_timestamp_from_unixtime(starttime); +} + +time_t +cmyth_recordingrule_endtime(cmyth_recordingrule_t rr) +{ + if (!rr) { + return 0; + } + return cmyth_timestamp_to_unixtime(rr->endtime); +} + +void +cmyth_recordingrule_set_endtime(cmyth_recordingrule_t rr, time_t endtime) +{ + if (rr->endtime) + ref_release(rr->endtime); + rr->endtime = cmyth_timestamp_from_unixtime(endtime); +} + +char * +cmyth_recordingrule_title(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->title); +} + +void +cmyth_recordingrule_set_title(cmyth_recordingrule_t rr, char *title) +{ + if (rr->title) + ref_release(rr->title); + rr->title = ref_strdup(title); +} + +char * +cmyth_recordingrule_description(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->description); +} + +void +cmyth_recordingrule_set_description(cmyth_recordingrule_t rr, char *description) +{ + if (rr->description) + ref_release(rr->description); + rr->description = ref_strdup(description); +} + +long +cmyth_recordingrule_type(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->type; +} + +void +cmyth_recordingrule_set_type(cmyth_recordingrule_t rr, long type) +{ + rr->type = type; +} + +char * +cmyth_recordingrule_category(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->category); +} + +void +cmyth_recordingrule_set_category(cmyth_recordingrule_t rr, char *category) +{ + if (rr->category) + ref_release(rr->category); + rr->category = ref_strdup(category); +} + +char * +cmyth_recordingrule_subtitle(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->subtitle); +} + +void +cmyth_recordingrule_set_subtitle(cmyth_recordingrule_t rr, char *subtitle) +{ + if (rr->subtitle) + ref_release(rr->subtitle); + rr->subtitle = ref_strdup(subtitle); +} + +long +cmyth_recordingrule_recpriority(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->recpriority; +} + +void +cmyth_recordingrule_set_recpriority(cmyth_recordingrule_t rr, long recpriority) +{ + rr->recpriority = recpriority; +} + +long +cmyth_recordingrule_startoffset(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->startoffset; +} + +void +cmyth_recordingrule_set_startoffset(cmyth_recordingrule_t rr, long startoffset) +{ + rr->startoffset = startoffset; +} + +long +cmyth_recordingrule_endoffset(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->endoffset; +} + +void +cmyth_recordingrule_set_endoffset(cmyth_recordingrule_t rr, long endoffset) +{ + rr->endoffset = endoffset; +} + +long +cmyth_recordingrule_searchtype(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->searchtype; +} + +void +cmyth_recordingrule_set_searchtype(cmyth_recordingrule_t rr, long searchtype) +{ + rr->searchtype = searchtype; +} + +unsigned short +cmyth_recordingrule_inactive(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->inactive; +} + +void +cmyth_recordingrule_set_inactive(cmyth_recordingrule_t rr, unsigned short inactive) +{ + rr->inactive = inactive; +} + +long +cmyth_recordingrule_dupmethod(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->dupmethod; +} + +void +cmyth_recordingrule_set_dupmethod(cmyth_recordingrule_t rr, long dupmethod) +{ + rr->dupmethod = dupmethod; +} + +long +cmyth_recordingrule_dupin(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->dupin; +} + +void +cmyth_recordingrule_set_dupin(cmyth_recordingrule_t rr, long dupin) +{ + rr->dupin = dupin; +} + +char * +cmyth_recordingrule_recgroup(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->recgroup); +} + +void +cmyth_recordingrule_set_recgroup(cmyth_recordingrule_t rr, char *recgroup) +{ + if (rr->recgroup) + ref_release(rr->recgroup); + rr->recgroup = ref_strdup(recgroup); +} + +char * +cmyth_recordingrule_storagegroup(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->storagegroup); +} + +void +cmyth_recordingrule_set_storagegroup(cmyth_recordingrule_t rr, char *storagegroup) +{ + if (rr->storagegroup) + ref_release(rr->storagegroup); + rr->storagegroup = ref_strdup(storagegroup); +} + +char * +cmyth_recordingrule_playgroup(cmyth_recordingrule_t rr) +{ + if (!rr) { + return NULL; + } + return ref_hold(rr->playgroup); +} + +void +cmyth_recordingrule_set_playgroup(cmyth_recordingrule_t rr, char *playgroup) +{ + if (rr->playgroup) + ref_release(rr->playgroup); + rr->playgroup = ref_strdup(playgroup); +} + +unsigned short +cmyth_recordingrule_autotranscode(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->autotranscode; +} + +void +cmyth_recordingrule_set_autotranscode(cmyth_recordingrule_t rr, unsigned short autotranscode) +{ + rr->autotranscode = autotranscode; +} + +int +cmyth_recordingrule_userjobs(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->userjobs; +} + +void +cmyth_recordingrule_set_userjobs(cmyth_recordingrule_t rr, int userjobs) +{ + rr->userjobs = userjobs; +} + +unsigned short +cmyth_recordingrule_autocommflag(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->autocommflag; +} + +void +cmyth_recordingrule_set_autocommflag(cmyth_recordingrule_t rr, unsigned short autocommflag) +{ + rr->autocommflag = autocommflag; +} + +long +cmyth_recordingrule_autoexpire(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->autoexpire; +} + +void +cmyth_recordingrule_set_autoexpire(cmyth_recordingrule_t rr, long autoexpire) +{ + rr->autoexpire = autoexpire; +} + +long +cmyth_recordingrule_maxepisodes(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->maxepisodes; +} + +void +cmyth_recordingrule_set_maxepisodes(cmyth_recordingrule_t rr, long maxepisodes) +{ + rr->maxepisodes = maxepisodes; +} + +long +cmyth_recordingrule_maxnewest(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->maxnewest; +} + +void +cmyth_recordingrule_set_maxnewest(cmyth_recordingrule_t rr, long maxnewest) +{ + rr->maxnewest = maxnewest; +} + +unsigned long +cmyth_recordingrule_transcoder(cmyth_recordingrule_t rr) +{ + if (!rr) { + return -EINVAL; + } + return rr->transcoder; +} + +void +cmyth_recordingrule_set_transcoder(cmyth_recordingrule_t rr, unsigned long transcoder) +{ + rr->transcoder = transcoder; +} + +/* + * cmyth_recordingrulelist_get_item(cmyth_recordingrulelist_t rrl, int index) + * + * Scope: PUBLIC + * + * Description + * + * Retrieve the recording schedule structure found at index 'index' in the list + * in 'rrl'. Return the recording schedule structure held. + * Before forgetting the reference to this recording schedule structure the + * caller must call ref_release(). + * + * Return Value: + * + * Success: A non-NULL cmyth_recordingrule_t (this type is a pointer) + * + * Failure: NULL + */ +cmyth_recordingrule_t +cmyth_recordingrulelist_get_item(cmyth_recordingrulelist_t rrl, int index) +{ + if (!rrl) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL recordingrule list\n", + __FUNCTION__); + return NULL; + } + if (!rrl->recordingrulelist_list) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL list\n", + __FUNCTION__); + return NULL; + } + if ((index < 0) || (index >= rrl->recordingrulelist_count)) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: index %d out of range\n", + __FUNCTION__, index); + return NULL; + } + ref_hold(rrl->recordingrulelist_list[index]); + return rrl->recordingrulelist_list[index]; +} + +/* + * cmyth_recordingrulelist_get_count(cmyth_recordingrulelist_t rrl) + * + * Scope: PUBLIC + * + * Description: + * + * Retrieve the number of elements in the recording schedule list + * structure in 'rrl'. + * + * Return Value: + * + * Success: A number >= 0 indicating the number of items in 'rrl' + * + * Failure: -(errno) + */ +int +cmyth_recordingrulelist_get_count(cmyth_recordingrulelist_t rrl) +{ + if (!rrl) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL recordingrule list\n", + __FUNCTION__); + return -EINVAL; + } + return rrl->recordingrulelist_count; +} \ No newline at end of file diff --git a/lib/cmyth/libcmyth/storagegroup.c b/lib/cmyth/libcmyth/storagegroup.c new file mode 100644 index 000000000..cd9ac9a97 --- /dev/null +++ b/lib/cmyth/libcmyth/storagegroup.c @@ -0,0 +1,296 @@ +/* + * Copyright (C) 2005-2012 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include +#include +#include +#include +#include + +static void +cmyth_storagegroup_file_destroy(cmyth_storagegroup_file_t fl) +{ + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!fl) { + return; + } + if(fl->filename) + ref_release(fl->filename); + if(fl->storagegroup) + ref_release(fl->storagegroup); + if(fl->hostname) + ref_release(fl->hostname); +} + +cmyth_storagegroup_file_t +cmyth_storagegroup_file_create(void) +{ + cmyth_storagegroup_file_t ret = ref_alloc(sizeof(*ret)); + memset(ret, 0, sizeof(*ret)); + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); + if (!ret) { + cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); + return NULL; + } + ref_set_destroy(ret, (ref_destroy_t)cmyth_storagegroup_file_destroy); + + return ret; +} + +static void +cmyth_storagegroup_filelist_destroy(cmyth_storagegroup_filelist_t fl) +{ + int i; + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + if (!fl) { + return; + } + for (i = 0; i < fl->storagegroup_filelist_count; ++i) { + if (fl->storagegroup_filelist_list[i]) { + ref_release(fl->storagegroup_filelist_list[i]); + } + fl->storagegroup_filelist_list[i] = NULL; + } + if (fl->storagegroup_filelist_list) { + free(fl->storagegroup_filelist_list); + } +} + +cmyth_storagegroup_filelist_t +cmyth_storagegroup_filelist_create(void) +{ + cmyth_storagegroup_filelist_t ret; + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); + ret = ref_alloc(sizeof(*ret)); + if (!ret) { + return(NULL); + } + ref_set_destroy(ret, (ref_destroy_t)cmyth_storagegroup_filelist_destroy); + + ret->storagegroup_filelist_list = NULL; + ret->storagegroup_filelist_count = 0; + return ret; +} + +static int +cmyth_storagegroup_update_fileinfo(cmyth_conn_t control, cmyth_storagegroup_file_t file) +{ + char msg[256]; + int count; + int err = 0; + int consumed; /* = profiles;*/ + char tmp_str[2048]; + + if (!control) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); + return -1; + } + + if (!file) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: no file specified\n", __FUNCTION__); + return -1; + } + + snprintf(msg, sizeof(msg), "QUERY_SG_FILEQUERY[]:[]%s[]:[]%s[]:[]%s", file->hostname , file->storagegroup, file->filename); + + err = cmyth_send_message(control, msg); + if (err < 0) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); + return -1; + } + + count = cmyth_rcv_length(control); + if (count < 0) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); + return -1; + } + + consumed = cmyth_rcv_string(control, &err, tmp_str, sizeof(tmp_str) - 1, count); + count -= consumed; + + if (err) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, count); + return -1; + } else if (count == 0) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: QUERY_SG_FILEQUERY failed(%s)\n", __FUNCTION__, tmp_str); + return -1; + } + + consumed = cmyth_rcv_ulong(control, &err, &(file->lastmodified), count); + count -= consumed; + if (err) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_ulong() failed (%d)\n", __FUNCTION__, count); + return -1; + } + + consumed = cmyth_rcv_ulong(control, &err, &(file->size), count); + count -= consumed; + if (err) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_ulong_long() failed (%d)\n", __FUNCTION__, count); + return -1; + } + + return 0; +} + +cmyth_storagegroup_filelist_t +cmyth_storagegroup_get_filelist(cmyth_conn_t control,char *storagegroup, char *hostname) +{ + char msg[256]; + int res = 0; + int count = 0; + int err = 0; + int i = 0; + int listsize = 10; + cmyth_storagegroup_filelist_t ret = 0; + cmyth_storagegroup_file_t file = 0; + int consumed = 0; /* = profiles; */ + char tmp_str[32768]; + + if (!control) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); + return 0; + } + + pthread_mutex_lock(&mutex); + + snprintf(msg, sizeof(msg), "QUERY_SG_GETFILELIST[]:[]%s[]:[]%s[]:[][]:[]1", hostname, storagegroup); + + err = cmyth_send_message(control, msg); + if (err < 0) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); + goto out; + } + + count = cmyth_rcv_length(control); + if (count < 0) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, count); + goto out; + } + + ret = cmyth_storagegroup_filelist_create(); + + if (!ret) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for list\n", __FUNCTION__); + ref_release(ret); + ret = 0; + goto out; + } + + ret->storagegroup_filelist_count = 0; + ret->storagegroup_filelist_list = malloc(listsize * sizeof(cmyth_storagegroup_file_t)); + if (!ret->storagegroup_filelist_list) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: alloc() failed for filelist list\n", __FUNCTION__); + ref_release(ret); + ret = 0; + goto out; + } + while (count) { + consumed = cmyth_rcv_string(control, &err, tmp_str, sizeof(tmp_str) - 1, count); + count -= consumed; + if (err) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_string() failed (%d)\n", __FUNCTION__, count); + ref_release(ret); + ret = 0; + goto out; + } + if (res>listsize-1) + { + listsize += 10; + ret->storagegroup_filelist_list = realloc(ret->storagegroup_filelist_list, listsize * sizeof(cmyth_storagegroup_file_t)); + if (!ret->storagegroup_filelist_list) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: realloc() failed for filelist list\n", __FUNCTION__); + ref_release(ret); + ret = 0; + goto out; + } + } + file = cmyth_storagegroup_file_create(); + file->filename = ref_strdup(tmp_str); + file->storagegroup = ref_strdup(storagegroup); + file->hostname = ref_strdup(hostname); + file->size = 0; + file->lastmodified = 0; + ret->storagegroup_filelist_list[res] = file; + res++; + } + ret->storagegroup_filelist_count = res; + + for(i = 0;i < ret->storagegroup_filelist_count;i++) { + cmyth_storagegroup_update_fileinfo(control, ret->storagegroup_filelist_list[i]); + } + + cmyth_dbg(CMYTH_DBG_DEBUG, "%s: results= %d\n", __FUNCTION__, res); + + out: + pthread_mutex_unlock(&mutex); + return ret; +} + +int +cmyth_storagegroup_filelist_count(cmyth_storagegroup_filelist_t fl) +{ + if (!fl) { + return -EINVAL; + } + return fl->storagegroup_filelist_count; +} + +cmyth_storagegroup_file_t +cmyth_storagegroup_filelist_get_item(cmyth_storagegroup_filelist_t fl, int index) +{ + if (!fl || index >= fl->storagegroup_filelist_count) { + return NULL; + } + ref_hold(fl->storagegroup_filelist_list[index]); + return fl->storagegroup_filelist_list[index]; + } + +char * +cmyth_storagegroup_file_filename(cmyth_storagegroup_file_t file) +{ + if (!file) { + return NULL; + } + return ref_hold(file->filename); +} + +unsigned long +cmyth_storagegroup_file_lastmodified(cmyth_storagegroup_file_t file) +{ + if (!file) { + return 0; + } + return file->lastmodified; +} + +unsigned long long +cmyth_storagegroup_file_size(cmyth_storagegroup_file_t file) +{ + if (!file) { + return 0; + } + return file->size; +} \ No newline at end of file