[svn r314] A lot of bug fixed. Test recordings program added.
1.1 --- a/gmyth/src/gmyth_debug.h Tue Jan 30 19:17:41 2007 +0000
1.2 +++ b/gmyth/src/gmyth_debug.h Tue Jan 30 20:52:35 2007 +0000
1.3 @@ -33,11 +33,11 @@
1.4
1.5 G_BEGIN_DECLS
1.6
1.7 -#ifdef GMYTH_USE_DEBUG
1.8 +//#ifdef GMYTH_USE_DEBUG
1.9 #define gmyth_debug(...) gmyth_debug_real (__FUNCTION__, __FILE__, __LINE__, TRUE, __VA_ARGS__)
1.10 -#else
1.11 -#define gmyth_debug(...)
1.12 -#endif
1.13 +//#else
1.14 +//#define gmyth_debug(...)
1.15 +//#endif
1.16
1.17 void gmyth_debug_real (const char *func,
1.18 const char *file,
2.1 --- a/gmyth/src/gmyth_epg.c Tue Jan 30 19:17:41 2007 +0000
2.2 +++ b/gmyth/src/gmyth_epg.c Tue Jan 30 20:52:35 2007 +0000
2.3 @@ -189,13 +189,19 @@
2.4 gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GList **proglist,
2.5 const gint chan_num, GTimeVal *starttime, GTimeVal *endtime)
2.6 {
2.7 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.8 +
2.9 gchar *startts = gmyth_util_time_to_string_from_time_val(starttime);
2.10 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.11 gchar *endts = gmyth_util_time_to_string_from_time_val(endtime);
2.12 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.13 MYSQL_ROW row;
2.14 GString *querystr;
2.15
2.16 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.17 assert(gmyth_epg);
2.18
2.19 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.20 querystr = g_string_new(
2.21 "SELECT DISTINCT program.chanid, program.starttime, program.endtime, "
2.22 " program.title, program.subtitle, program.description, "
2.23 @@ -214,6 +220,7 @@
2.24 " program.starttime = oldrecstatus.starttime "
2.25 );
2.26
2.27 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.28 g_string_append_printf (querystr,
2.29 "WHERE program.chanid = %d "
2.30 " AND program.endtime >= '%s' "
2.31 @@ -221,34 +228,51 @@
2.32 " AND program.manualid = 0 ",
2.33 chan_num, startts, endts);
2.34
2.35 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.36 if (!g_strrstr(querystr->str, " GROUP BY "))
2.37 querystr = g_string_append(querystr,
2.38 " GROUP BY program.starttime, channel.channum, "
2.39 " channel.callsign, program.title ");
2.40
2.41 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.42 if (!g_strrstr(querystr->str, " LIMIT "))
2.43 querystr = g_string_append(querystr, " LIMIT 1000 ");
2.44
2.45 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.46 MYSQL_RES *res_set =
2.47 gmyth_query_process_statement(gmyth_epg->sqlquery, querystr->str);
2.48
2.49 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.50 if (res_set == NULL) {
2.51 g_warning ("[%s] msql query returned NULL MYSQL_RES", __FUNCTION__);
2.52 return -1;
2.53 }
2.54
2.55 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.56 (*proglist) = NULL;
2.57 while ((row = mysql_fetch_row (res_set)) != NULL) {
2.58
2.59 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.60 GMythProgramInfo *p = gmyth_program_info_new ();
2.61 p->chanid = g_string_new (row[0]);
2.62 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.63
2.64 p->startts = gmyth_util_string_to_time_val (row[1]);
2.65 p->endts = gmyth_util_string_to_time_val (row[2]);
2.66 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.67
2.68 - p->recstartts = p->startts;
2.69 - p->recendts = p->endts;
2.70 - p->lastmodified = p->startts;
2.71 + p->recstartts = g_new0 (GTimeVal, 1);
2.72 + p->recstartts->tv_sec = p->startts->tv_sec;
2.73 + p->recstartts->tv_usec = p->startts->tv_usec;
2.74 +
2.75 + p->recendts = g_new0 (GTimeVal, 1);
2.76 + p->recendts->tv_sec = p->endts->tv_sec;
2.77 + p->recendts->tv_usec = p->endts->tv_usec;
2.78 +
2.79 + p->lastmodified = g_new0 (GTimeVal, 1);
2.80 + p->lastmodified->tv_sec = p->startts->tv_sec;
2.81 + p->lastmodified->tv_usec = p->startts->tv_usec;
2.82 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.83
2.84 p->title = g_string_new (row[3]);
2.85 p->subtitle = g_string_new (row[4]);
2.86 @@ -265,6 +289,7 @@
2.87 p->year = g_string_new (row[15]);
2.88 p->stars = g_ascii_strtod(row[16], NULL);
2.89
2.90 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.91 if (!row[17] || !strcmp(row[17], "")) {
2.92 p->originalAirDate = 0;
2.93 p->hasAirDate = FALSE;
2.94 @@ -273,6 +298,7 @@
2.95 p->hasAirDate = TRUE;
2.96 }
2.97
2.98 +printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
2.99 p->catType = g_string_new (row[18]);
2.100
2.101 *proglist = g_list_append((*proglist), p);
3.1 --- a/gmyth/src/gmyth_file_transfer.c Tue Jan 30 19:17:41 2007 +0000
3.2 +++ b/gmyth/src/gmyth_file_transfer.c Tue Jan 30 20:52:35 2007 +0000
3.3 @@ -62,7 +62,7 @@
3.4 #define GMYTHTV_RETRIES -1
3.5 #define GMYTHTV_FILE_SIZE 0
3.6
3.7 -#define GMYTHTV_BUFFER_SIZE 8*1024
3.8 +#define GMYTHTV_BUFFER_SIZE 64*1024
3.9
3.10 #define GMYTHTV_VERSION 30
3.11
4.1 --- a/gmyth/src/gmyth_programinfo.c Tue Jan 30 19:17:41 2007 +0000
4.2 +++ b/gmyth/src/gmyth_programinfo.c Tue Jan 30 20:52:35 2007 +0000
4.3 @@ -105,19 +105,22 @@
4.4 gmyth_program_info_dispose (GObject *object)
4.5 {
4.6 GMythProgramInfo *gmyth_program_info = GMYTH_PROGRAM_INFO(object);
4.7 -
4.8 +
4.9 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.10 if ( gmyth_program_info->chanid != NULL )
4.11 {
4.12 g_string_free( gmyth_program_info->chanid, TRUE );
4.13 gmyth_program_info->chanid = NULL;
4.14 }
4.15
4.16 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.17 /** The program start time. */
4.18 if ( gmyth_program_info->startts != NULL )
4.19 {
4.20 g_free( gmyth_program_info->startts);
4.21 gmyth_program_info->startts = NULL;
4.22 }
4.23 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.24
4.25 /** The program end time. */
4.26 if ( gmyth_program_info->endts != NULL )
4.27 @@ -125,6 +128,7 @@
4.28 g_free( gmyth_program_info->endts );
4.29 gmyth_program_info->endts = NULL;
4.30 }
4.31 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.32
4.33 /** The recording schedule start time. */
4.34 if ( gmyth_program_info->recstartts != NULL )
4.35 @@ -133,12 +137,14 @@
4.36 gmyth_program_info->recstartts = NULL;
4.37 }
4.38
4.39 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.40 /** The recording schedule end time */
4.41 if ( gmyth_program_info->recendts != NULL )
4.42 {
4.43 g_free(gmyth_program_info->recendts);
4.44 gmyth_program_info->recendts = NULL;
4.45 }
4.46 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.47
4.48 /** The program title. */
4.49 if (gmyth_program_info->title != NULL )
4.50 @@ -146,6 +152,7 @@
4.51 g_string_free(gmyth_program_info->title, TRUE);
4.52 gmyth_program_info->title = NULL;
4.53 }
4.54 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.55
4.56 /** The program subtitle. */
4.57 if (gmyth_program_info->subtitle != NULL )
4.58 @@ -153,12 +160,14 @@
4.59 g_string_free(gmyth_program_info->subtitle, TRUE );
4.60 gmyth_program_info->subtitle = NULL;
4.61 }
4.62 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.63 /** The program description. */
4.64 if ( gmyth_program_info->description != NULL )
4.65 {
4.66 g_string_free( gmyth_program_info->description, TRUE );
4.67 gmyth_program_info->description = NULL;
4.68 }
4.69 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.70
4.71 /** The program category. */
4.72 if ( gmyth_program_info->category != NULL )
4.73 @@ -166,35 +175,41 @@
4.74 g_string_free( gmyth_program_info->category, TRUE );
4.75 gmyth_program_info->category = NULL;
4.76 }
4.77 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.78
4.79 if ( gmyth_program_info->chanstr != NULL )
4.80 {
4.81 g_string_free( gmyth_program_info->chanstr, TRUE );
4.82 gmyth_program_info->chanstr = NULL;
4.83 }
4.84 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.85 if ( gmyth_program_info->chansign != NULL )
4.86 {
4.87 g_string_free( gmyth_program_info->chansign, TRUE );
4.88 gmyth_program_info->chansign = NULL;
4.89 }
4.90 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.91 /** The associated channel name. */
4.92 if ( gmyth_program_info->channame != NULL )
4.93 {
4.94 g_string_free( gmyth_program_info->channame, TRUE );
4.95 gmyth_program_info->channame = NULL;
4.96 }
4.97 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.98 if ( gmyth_program_info->chanOutputFilters != NULL )
4.99 {
4.100 g_string_free( gmyth_program_info->chanOutputFilters, TRUE );
4.101 gmyth_program_info->chanOutputFilters = NULL;
4.102 }
4.103 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.104
4.105 if ( gmyth_program_info->seriesid != NULL )
4.106 {
4.107 - g_string_free( gmyth_program_info->chanOutputFilters, TRUE );
4.108 + g_string_free( gmyth_program_info->seriesid, TRUE );
4.109 gmyth_program_info->chanOutputFilters = NULL;
4.110
4.111 }
4.112 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.113 /** The program unique id. */
4.114 if ( gmyth_program_info->programid != NULL )
4.115 {
4.116 @@ -202,12 +217,14 @@
4.117 gmyth_program_info->programid = NULL;
4.118
4.119 }
4.120 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.121 if ( gmyth_program_info->catType != NULL )
4.122 {
4.123 g_string_free( gmyth_program_info->catType, TRUE );
4.124 gmyth_program_info->catType = NULL;
4.125
4.126 }
4.127 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.128
4.129 if ( gmyth_program_info->sortTitle != NULL )
4.130 {
4.131 @@ -215,6 +232,7 @@
4.132 gmyth_program_info->sortTitle = NULL;
4.133
4.134 }
4.135 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.136
4.137 if ( gmyth_program_info->year != NULL )
4.138 {
4.139 @@ -222,29 +240,35 @@
4.140 gmyth_program_info->year = NULL;
4.141
4.142 }
4.143 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.144
4.145 if ( gmyth_program_info->originalAirDate != NULL )
4.146 {
4.147 g_free( gmyth_program_info->originalAirDate);
4.148 gmyth_program_info->originalAirDate = NULL;
4.149 }
4.150 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.151 if ( gmyth_program_info->lastmodified != NULL )
4.152 {
4.153 g_free( gmyth_program_info->lastmodified );
4.154 gmyth_program_info->lastmodified = NULL;
4.155
4.156 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.157 }
4.158 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.159 if (gmyth_program_info->lastInUseTime != NULL)
4.160 {
4.161 g_free( gmyth_program_info->lastInUseTime );
4.162 gmyth_program_info->lastInUseTime = NULL;
4.163 }
4.164 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.165
4.166 if ( gmyth_program_info->schedulerid != NULL )
4.167 {
4.168 g_string_free( gmyth_program_info->schedulerid, TRUE );
4.169 gmyth_program_info->schedulerid = NULL;
4.170 }
4.171 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.172
4.173 if ( gmyth_program_info->recgroup != NULL )
4.174 {
4.175 @@ -256,6 +280,7 @@
4.176 g_string_free( gmyth_program_info->playgroup, TRUE );
4.177 gmyth_program_info->playgroup = NULL;
4.178 }
4.179 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.180
4.181 /** The file name of the recorded program.*/
4.182 if ( gmyth_program_info->pathname != NULL)
4.183 @@ -263,11 +288,13 @@
4.184 g_string_free( gmyth_program_info->pathname, TRUE );
4.185 gmyth_program_info->pathname = NULL;
4.186 }
4.187 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.188 if ( gmyth_program_info->hostname != NULL )
4.189 {
4.190 g_string_free( gmyth_program_info->hostname, TRUE );
4.191 gmyth_program_info->hostname = NULL;
4.192 }
4.193 + printf ("XXXX %s %d\n", __FUNCTION__, __LINE__);
4.194
4.195 G_OBJECT_CLASS (gmyth_program_info_parent_class)->dispose (object);
4.196 }
5.1 --- a/gmyth/src/gmyth_query.c Tue Jan 30 19:17:41 2007 +0000
5.2 +++ b/gmyth/src/gmyth_query.c Tue Jan 30 20:52:35 2007 +0000
5.3 @@ -111,7 +111,6 @@
5.4 {
5.5 assert(gmyth_query);
5.6 g_return_val_if_fail (gmyth_query->conn != NULL, FALSE);
5.7 -printf ("XXXXXXXXX timeout %d\n", timeout);
5.8 if (timeout != 0) {
5.9 /* sets connection timeout */
5.10 mysql_options (gmyth_query->conn, MYSQL_OPT_CONNECT_TIMEOUT, (gchar*) &timeout);
5.11 @@ -156,7 +155,7 @@
5.12 return FALSE;
5.13 }
5.14
5.15 - gmyth_debug ("[%s] Connection to Mysql server succeeded! (host = %s, user = %s, "\
5.16 + g_debug ("[%s] Connection to Mysql server succeeded! (host = %s, user = %s, "\
5.17 "password = %s, db name = %s)", __FUNCTION__,
5.18 gmyth_query->backend_info->hostname, gmyth_query->backend_info->username,
5.19 gmyth_query->backend_info->password, gmyth_query->backend_info->db_name );
5.20 @@ -175,7 +174,7 @@
5.21 assert(gmyth_query);
5.22
5.23 /* TODO: Check how to return error */
5.24 - gmyth_debug ("[%s] Closing gmyth_query->conn", __FUNCTION__);
5.25 + g_debug ("[%s] Closing gmyth_query->conn", __FUNCTION__);
5.26 mysql_close (gmyth_query->conn);
5.27
5.28 return TRUE;
5.29 @@ -214,7 +213,7 @@
5.30
5.31 assert(gmyth_query);
5.32
5.33 - gmyth_debug ("[%s] Running mysql query %s", __FUNCTION__, stmt_str);
5.34 + g_debug ("[%s] Running mysql query %s", __FUNCTION__, stmt_str);
5.35
5.36 if (gmyth_query == NULL)
5.37 return NULL;
5.38 @@ -230,7 +229,7 @@
5.39 if (res_set) {
5.40 return res_set;
5.41 } else if (mysql_field_count (gmyth_query->conn) == 0) {
5.42 - gmyth_debug ("%lu rows affected\n",
5.43 + g_debug ("%lu rows affected\n",
5.44 (unsigned long) mysql_affected_rows (gmyth_query->conn));
5.45 } else {
5.46 gmyth_query_print_error (gmyth_query->conn, "Could not retrieve result set");
6.1 --- a/gmyth/src/gmyth_scheduler.c Tue Jan 30 19:17:41 2007 +0000
6.2 +++ b/gmyth/src/gmyth_scheduler.c Tue Jan 30 20:52:35 2007 +0000
6.3 @@ -266,7 +266,6 @@
6.4 RecordedInfo *record;
6.5 MYSQL_RES *msql_res;
6.6 GString *query_str = g_string_new ("");
6.7 - gchar *date_time = NULL;
6.8
6.9 assert(scheduler);
6.10
6.11 @@ -274,42 +273,29 @@
6.12 "SELECT recordid,programid,chanid,starttime,progstart,"
6.13 "endtime,progend,title,subtitle,description,category,filesize,basename FROM recorded WHERE recgroup != 'LiveTV'");
6.14
6.15 - if (scheduler->msqlquery == NULL) {
6.16 - g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
6.17 - return -1;
6.18 - }
6.19 + if (scheduler->msqlquery == NULL) {
6.20 + g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
6.21 + return -1;
6.22 + }
6.23
6.24 msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
6.25
6.26 if (msql_res == NULL) {
6.27 g_warning ("DB retrieval of recording list failed");
6.28 return -1;
6.29 - } else {
6.30 + } else {
6.31 MYSQL_ROW row;
6.32 *recorded_list = NULL;
6.33
6.34 while((row = mysql_fetch_row (msql_res))!=NULL){
6.35 - record = g_new0(RecordedInfo, 1);
6.36 + record = g_new0(RecordedInfo, 1);
6.37
6.38 record->record_id = (guint) g_ascii_strtoull (row[0], NULL, 10);
6.39 record->program_id = (guint) g_ascii_strtoull (row[1], NULL, 10);
6.40 record->channel_id = (guint) g_ascii_strtoull (row[2], NULL, 10);
6.41
6.42 - /* the db field time already contains the date. therefore
6.43 - * we are not using the date field */
6.44 - /* generate a time_t from a time and a date db field */
6.45 - /* g_string_printf (date_time, "%s %s", row[4], row[3]); */
6.46 - g_sprintf (date_time, "%sT%s", row[4], row[3]);
6.47 -
6.48 - record->start_time = gmyth_util_string_to_time_val (date_time);
6.49 -
6.50 - /* the db field time already contains the date. therefore
6.51 - * we are not using the date field */
6.52 - /* generate a time_t from a time and a date db field */
6.53 - /* g_string_printf (date_time, "%s %s", row[6], row[5]); */
6.54 - g_sprintf (date_time, "%sT%s", row[6], row[5]);
6.55 -
6.56 - record->end_time = gmyth_util_string_to_time_val (date_time);
6.57 + record->start_time = gmyth_util_string_to_time_val (row[3]);
6.58 + record->end_time = gmyth_util_string_to_time_val (row[5]);
6.59
6.60 record->title = g_string_new (row[7]);
6.61 record->subtitle = g_string_new (row[8]);
6.62 @@ -324,7 +310,6 @@
6.63
6.64 mysql_free_result (msql_res);
6.65 g_string_free(query_str, TRUE);
6.66 - g_free(date_time);
6.67
6.68 return (*recorded_list == NULL) ? 0 : g_list_length (*recorded_list);
6.69 }
6.70 @@ -339,7 +324,7 @@
6.71 */
6.72 gboolean
6.73 gmyth_scheduler_add_schedule (GMythScheduler *scheduler,
6.74 - ScheduleInfo *schedule_info)
6.75 + ScheduleInfo *schedule_info)
6.76 {
6.77 //GTimeVal *start_tm;
6.78 //GTimeVal *end_tm;
6.79 @@ -534,10 +519,15 @@
6.80 proginfo = gmyth_program_info_new();
6.81
6.82 proginfo->chanid = g_string_new (msql_row[0]);
6.83 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.84 proginfo->startts = gmyth_util_string_to_time_val (msql_row[23]);
6.85 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.86 proginfo->endts = gmyth_util_string_to_time_val (msql_row[24]);
6.87 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.88 proginfo->recstartts = gmyth_util_string_to_time_val (msql_row[1]);
6.89 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.90 proginfo->recendts = gmyth_util_string_to_time_val (msql_row[2]);
6.91 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.92 proginfo->title = g_string_new (msql_row[3]);
6.93 proginfo->subtitle = g_string_new (msql_row[4]);
6.94 proginfo->description = g_string_new (msql_row[5]);
6.95 @@ -551,6 +541,7 @@
6.96 proginfo->programid = g_string_new (msql_row[12]);
6.97 proginfo->filesize = g_ascii_strtoull (msql_row[13], NULL, 10);
6.98
6.99 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.100 proginfo->lastmodified = gmyth_util_string_to_time_val (msql_row[14]);
6.101
6.102 proginfo->stars = g_ascii_strtod (msql_row[15], NULL);
6.103 @@ -560,6 +551,7 @@
6.104 proginfo->originalAirDate = 0;
6.105 proginfo->hasAirDate = FALSE;
6.106 } else {
6.107 + printf ("xxxxxx %s %d\n", __FUNCTION__, __LINE__);
6.108 proginfo->originalAirDate = gmyth_util_string_to_time_val (msql_row[17]);
6.109 proginfo->hasAirDate = TRUE;
6.110 }
6.111 @@ -581,7 +573,7 @@
6.112 }
6.113 }
6.114
6.115 - mysql_free_result (msql_res);
6.116 + mysql_free_result (msql_res);
6.117 g_string_free(query_str, TRUE);
6.118 g_free(time_str);
6.119
7.1 --- a/gmyth/src/gmyth_socket.c Tue Jan 30 19:17:41 2007 +0000
7.2 +++ b/gmyth/src/gmyth_socket.c Tue Jan 30 20:52:35 2007 +0000
7.3 @@ -53,18 +53,14 @@
7.4 #include <fcntl.h>
7.5 #include <signal.h>
7.6
7.7 -#if defined(HAVE_IFADDRS_H)
7.8 - #include <ifaddrs.h>
7.9 -#else
7.10 - #include <sys/ioctl.h>
7.11 -#endif
7.12 +#include <sys/ioctl.h>
7.13
7.14 #include "gmyth_stringlist.h"
7.15 #include "gmyth_uri.h"
7.16 #include "gmyth_debug.h"
7.17
7.18 -#define BUFLEN 512
7.19 -#define MYTH_SEPARATOR "[]:[]"
7.20 +#define BUFLEN 512
7.21 +#define MYTH_SEPARATOR "[]:[]"
7.22 #define MYTH_PROTOCOL_FIELD_SIZE 8
7.23
7.24 /* max number of iterations */
7.25 @@ -117,6 +113,7 @@
7.26 gint errorn = EADDRNOTAVAIL;
7.27
7.28 g_return_val_if_fail ( addr != NULL, -1 );
7.29 + g_debug ("Calling %s\n", __FUNCTION__);
7.30
7.31 /* hints = g_malloc0 ( sizeof(struct addrinfo) ); */
7.32 memset ( &hints, 0, sizeof(struct addrinfo) );
7.33 @@ -127,7 +124,9 @@
7.34 if ( port != -1 )
7.35 portStr = g_strdup_printf ( "%d", port );
7.36 else
7.37 - portStr = NULL;
7.38 + portStr = NULL;
7.39 +
7.40 + gmyth_debug ("Getting name resolution for: %s, %d\n", addr, port);
7.41
7.42 if ( ( errorn = getaddrinfo(addr, portStr, &hints, addrInfo) ) != 0 ) {
7.43 g_printerr( "[%s] Socket ERROR: %s\n", __FUNCTION__, gai_strerror(errorn) );
7.44 @@ -149,65 +148,6 @@
7.45
7.46 }
7.47
7.48 -#if defined(HAVE_IFADDRS_H)
7.49 -
7.50 -/** Gets the list of all local network interfaces.
7.51 - *
7.52 - * @param current_connections A list with all the network interfaces are valid,
7.53 - * to be applied just like a filter.
7.54 - * @return List with all the local net interfaces.
7.55 - */
7.56 -static GList *
7.57 -gmyth_socket_get_local_addrs( GList *current_connections ) {
7.58 -
7.59 - GList *local_addrs = NULL;
7.60 -
7.61 - struct ifaddrs *ifaddr = g_malloc0( sizeof(struct ifaddrs) );
7.62 - struct ifaddrs *i = g_malloc0( sizeof(struct ifaddrs) );
7.63 -
7.64 - gchar *addr = g_new0( gchar, NI_MAXHOST+1 );
7.65 - gchar *ifname;
7.66 - gint ifIdx;
7.67 -
7.68 - if (getifaddrs(&ifaddr) != 0)
7.69 - {
7.70 - g_printerr("No addresses for interfaces!\n");
7.71 - return NULL;
7.72 - }
7.73 -
7.74 - for ( i = ifaddr; i != NULL; i = i->ifa_next ) {
7.75 - if (!(i->ifa_flags & IFF_UP))
7.76 - continue;
7.77 - if (i->ifa_flags & IFF_LOOPBACK)
7.78 - continue;
7.79 - if ( getnameinfo(i->ifa_addr, sizeof(struct sockaddr), addr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0 ) {
7.80 -
7.81 - ifname = i->ifa_name;
7.82 - ifIdx = if_nametoindex(ifname);
7.83 -
7.84 - if ( current_connections == NULL || ( current_connections != NULL &&
7.85 - g_list_find_custom( current_connections, (gchar *)addr,
7.86 - (GCompareFunc)gmyth_socket_find_match_address_uri ) == NULL ) )
7.87 - {
7.88 - local_addrs = g_list_append( local_addrs, g_strdup( addr ) );
7.89 - }
7.90 -
7.91 - if ( addr != NULL ) {
7.92 - g_free( addr );
7.93 - addr = g_new0( gchar, NI_MAXHOST+1 );
7.94 - }
7.95 -
7.96 - }
7.97 - } /* iterates over network interfaces */
7.98 -
7.99 - freeifaddrs(ifaddr);
7.100 -
7.101 - return local_addrs;
7.102 -
7.103 -}
7.104 -
7.105 -#else
7.106 -
7.107 static const gchar *PATH_PROC_NET_DEV = "/proc/net/dev";
7.108
7.109 /** Gets the list of all local network interfaces (using the /proc/net/dev directory).
7.110 @@ -266,7 +206,6 @@
7.111
7.112 }
7.113
7.114 -#endif
7.115
7.116 /**
7.117 * Get only the local addresses from the primary interface
7.118 @@ -304,6 +243,18 @@
7.119 GString *
7.120 gmyth_socket_get_local_hostname ()
7.121 {
7.122 +
7.123 + char hname[50];
7.124 + gint res = gethostname (hname, 50);
7.125 +
7.126 + if (res == -1) {
7.127 + g_debug ("Error while getting hostname");
7.128 + return NULL;
7.129 + }
7.130 +
7.131 + return g_string_new (hname);
7.132 +
7.133 +#if 0
7.134 GString *str = NULL;
7.135
7.136 if ( local_hostname != NULL && strlen(local_hostname) > 0 )
7.137 @@ -315,6 +266,7 @@
7.138 struct sockaddr_in* sa = NULL;
7.139 gchar localhostname[MAXHOSTNAMELEN];
7.140
7.141 +
7.142 if (gethostname (localhostname, MAXHOSTNAMELEN) != 0 ) {
7.143 gmyth_debug ( "Error on gethostname" );
7.144 }
7.145 @@ -375,6 +327,7 @@
7.146 local_hostname = g_strdup( str->str );
7.147
7.148 return str;
7.149 +#endif
7.150 }
7.151
7.152 static void
7.153 @@ -762,6 +715,10 @@
7.154 GString *hostname = NULL;
7.155
7.156 hostname = gmyth_socket_get_local_hostname();
7.157 + if (hostname == NULL) {
7.158 + g_debug ("Hostname not available, setting to n800frontend\n");
7.159 + hostname = g_strdup ("n800frontend");
7.160 + }
7.161
7.162 g_string_printf(base_str, "ANN %s %s %u",
7.163 (blocking_client ? "Playback" : "Monitor"),
8.1 --- a/gmyth/src/gmyth_util.c Tue Jan 30 19:17:41 2007 +0000
8.2 +++ b/gmyth/src/gmyth_util.c Tue Jan 30 20:52:35 2007 +0000
8.3 @@ -73,9 +73,9 @@
8.4 g_static_mutex_lock ( &mutex );
8.5
8.6 if (localtime_r(&time_value, &tm_time) == NULL) {
8.7 - g_static_mutex_unlock ( &mutex );
8.8 - g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
8.9 - return NULL;
8.10 + g_static_mutex_unlock ( &mutex );
8.11 + g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
8.12 + return NULL;
8.13 }
8.14
8.15 result = g_string_sized_new(20);
8.16 @@ -88,8 +88,6 @@
8.17 g_static_mutex_unlock ( &mutex );
8.18
8.19 return result;
8.20 -
8.21 -
8.22 }
8.23
8.24 /** Converts a time_t struct in a GString at ISO standard format
8.25 @@ -104,7 +102,6 @@
8.26 gchar*
8.27 gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, const GTimeVal* time_val )
8.28 {
8.29 -
8.30 gchar *result = NULL;
8.31 struct tm *tm_time = NULL;
8.32
8.33 @@ -133,7 +130,7 @@
8.34 return NULL;
8.35 }
8.36 strftime( result, buffer_len + 1, fmt_string, tm_time );
8.37 - gmyth_debug( "Dateline (ISO result): %s\n", result );
8.38 + gmyth_debug( "Dateline (ISO result): %s", result );
8.39 }
8.40
8.41 }
8.42 @@ -271,7 +268,7 @@
8.43 {
8.44 gint year, month, day, hour, min, sec;
8.45
8.46 - gmyth_debug( "[%s] time_str = %s. [%s]\n", __FUNCTION__, time_str != NULL ?
8.47 + gmyth_debug( "[%s] time_str = %s. [%s]", __FUNCTION__, time_str != NULL ?
8.48 time_str->str : "[time string is NULL!]", time_str->str );
8.49
8.50 if ( sscanf (time_str->str, "%04d-%02d-%02d %02d:%02d:%02d",
8.51 @@ -317,7 +314,7 @@
8.52 return NULL;
8.53 }
8.54
8.55 - gmyth_debug( "Converted from GTimeVal == %s to GDate\n", asctime( date ) );
8.56 + gmyth_debug( "Converted from GTimeVal == %s to GDate", asctime( date ) );
8.57
8.58 return date;
8.59 }
8.60 @@ -334,8 +331,9 @@
8.61 GTimeVal *time = g_new0( GTimeVal, 1 );
8.62 struct tm* tm_time = NULL;
8.63 time_t time_micros;
8.64 + gint result;
8.65
8.66 - gmyth_debug( "[%s] time_str = %s. [%s]\n", time_str, time_str != NULL ?
8.67 + gmyth_debug( "[%s] time_str = %s. [%s]", time_str, time_str != NULL ?
8.68 time_str : "[time string is NULL!]", time_str );
8.69
8.70 if ( NULL == time_str )
8.71 @@ -348,18 +346,25 @@
8.72
8.73 tm_time = g_malloc0( sizeof(struct tm) );
8.74
8.75 - if (strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time ) == NULL)
8.76 - if (strptime( time_str, "%Y-%m-%dT%H:%M", tm_time ) == NULL)
8.77 - if (strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time ) == NULL)
8.78 - if (strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time ) == NULL)
8.79 - {
8.80 - g_static_mutex_unlock ( &mutex );
8.81 - gmyth_debug( "Error with Dateline. Not recognised");
8.82 - return NULL;
8.83 - }
8.84 -
8.85 - time_micros = mktime( tm_time );
8.86 -
8.87 + /* we first check the return of strftime to allocate a buffer of the correct size */
8.88 + result = strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time );
8.89 + if ( NULL == result ) {
8.90 + /* we first check the return of strftime to allocate a buffer of the correct size */
8.91 + result = strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time );
8.92 + if ( NULL == result ) {
8.93 + /* we first check the return of strftime to allocate a buffer of the correct size */
8.94 + result = strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time );
8.95 + if ( NULL == result ) {
8.96 + g_static_mutex_unlock ( &mutex );
8.97 + gmyth_debug( "Dateline (ISO result): %s", result );
8.98 + time = NULL;
8.99 + //goto done;
8.100 + }
8.101 + }
8.102 + }
8.103 +
8.104 + time_micros = mktime( tm_time );
8.105 +
8.106 time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC );
8.107
8.108 gmyth_debug( "After mktime call... = %s", asctime(tm_time) );
9.1 --- a/gmyth/tests/compile_test_connection Tue Jan 30 19:17:41 2007 +0000
9.2 +++ b/gmyth/tests/compile_test_connection Tue Jan 30 20:52:35 2007 +0000
9.3 @@ -1,1 +1,1 @@
9.4 -gcc -o gmyth_test_connection gmyth_test_connection.c `pkg-config --cflags --libs gmyth-0.1`
9.5 +gcc -o gmyth_test_connection gmyth_test_connection.c `pkg-config --cflags --libs gmyth-0.1 glib-2.0`
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/gmyth/tests/compile_test_recordings Tue Jan 30 20:52:35 2007 +0000
10.3 @@ -0,0 +1,1 @@
10.4 +gcc -o gmyth_test_recordings gmyth_test_recordings.c `pkg-config --cflags --libs gmyth-0.1 glib-2.0`
11.1 --- a/gmyth/tests/gmyth_test_connection.c Tue Jan 30 19:17:41 2007 +0000
11.2 +++ b/gmyth/tests/gmyth_test_connection.c Tue Jan 30 20:52:35 2007 +0000
11.3 @@ -12,7 +12,24 @@
11.4 if (gmyth_socket_connect_with_timeout (socket,
11.5 gmyth_backend_info_get_hostname (backend_info),
11.6 gmyth_backend_info_get_port (backend_info), 4) == TRUE) {
11.7 - g_debug ("Connection success");
11.8 + g_debug ("Socket connection success");
11.9 + return TRUE;
11.10 + } else {
11.11 + g_debug ("Connection failed");
11.12 + return FALSE;
11.13 + }
11.14 +}
11.15 +
11.16 +static gboolean
11.17 +test_backend_connection2 (GMythBackendInfo *backend_info)
11.18 +{
11.19 + GMythSocket *socket = gmyth_socket_new ();
11.20 + if (gmyth_socket_connect_to_backend (socket,
11.21 + gmyth_backend_info_get_hostname (backend_info),
11.22 + gmyth_backend_info_get_port (backend_info), TRUE) == TRUE) {
11.23 +
11.24 +
11.25 + g_debug ("Backend socket connection success");
11.26 return TRUE;
11.27 } else {
11.28 g_debug ("Connection failed");
11.29 @@ -43,11 +60,12 @@
11.30
11.31 GMythBackendInfo *backend_info;
11.32 g_type_init ();
11.33 - g_thread_init (NULL);
11.34 + //g_thread_init (NULL);
11.35
11.36 backend_info = gmyth_backend_info_new_with_uri (argv[1]);
11.37
11.38 test_backend_connection1 (backend_info);
11.39 + test_backend_connection2 (backend_info);
11.40 test_mysql_connection1 (backend_info);
11.41 }
11.42
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/gmyth/tests/gmyth_test_recordings.c Tue Jan 30 20:52:35 2007 +0000
12.3 @@ -0,0 +1,59 @@
12.4 +#include <glib-object.h>
12.5 +
12.6 +#include "gmyth_uri.h"
12.7 +#include "gmyth_backendinfo.h"
12.8 +#include "gmyth_scheduler.h"
12.9 +#include "gmyth_epg.h"
12.10 +#include "gmyth_common.h"
12.11 +
12.12 +static gboolean
12.13 +test_recording_list (GMythBackendInfo *backend_info)
12.14 +{
12.15 + GList *list = NULL;
12.16 + gint length = 0;
12.17 + GMythScheduler *scheduler = gmyth_scheduler_new ();
12.18 +
12.19 + if (gmyth_scheduler_connect_with_timeout (scheduler,
12.20 + backend_info, 10) == TRUE) {
12.21 + g_debug ("===== Scheduler connection success =====");
12.22 + } else {
12.23 + g_debug ("===== Scheduler connection failed =====");
12.24 + return FALSE;
12.25 + }
12.26 +
12.27 + length = gmyth_scheduler_get_recorded_list (scheduler, &list);
12.28 +
12.29 + g_debug ("===== %d Recordings found =====\n", length);
12.30 + length--;
12.31 + while (length >= 0) {
12.32 + RecordedInfo *record = (RecordedInfo*) g_list_nth_data (list, length);
12.33 + if (record == 0) {
12.34 + g_debug ("===== Recorded list returned NULL pointer =====\n");
12.35 + length--;
12.36 + continue;
12.37 + }
12.38 + g_debug ("===== Record id = %d =====\n", record->record_id);
12.39 + g_debug ("===== Record name = %s =====\n", (record ? record->basename->str : "NULL"));
12.40 + length--;
12.41 + }
12.42 +
12.43 + gmyth_scheduler_disconnect (scheduler);
12.44 +
12.45 +}
12.46 +
12.47 +int
12.48 +main (int args, const char **argv)
12.49 +{
12.50 + const char* uri = argv[1];
12.51 +
12.52 + GMythBackendInfo *backend_info;
12.53 + g_type_init ();
12.54 +
12.55 + backend_info = gmyth_backend_info_new_with_uri (argv[1]);
12.56 +
12.57 + test_recording_list (backend_info);
12.58 +}
12.59 +
12.60 +
12.61 +
12.62 +