# HG changeset patch
# User rosfran
# Date 1166142117 0
# Node ID b250ee0438a221aa259f489fb2da288ffdf27b9e
# Parent  462a3c81abd6070859da541fe1b48dddf1338bbc
[svn r222] Some fixes to the GTimeVal, non-conformant g_time_val (ISO 8601) functions.

diff -r 462a3c81abd6 -r b250ee0438a2 gmyth/src/gmyth_file_transfer.c
--- a/gmyth/src/gmyth_file_transfer.c	Wed Dec 13 23:44:04 2006 +0000
+++ b/gmyth/src/gmyth_file_transfer.c	Fri Dec 15 00:21:57 2006 +0000
@@ -201,7 +201,6 @@
 static void
 gmyth_file_transfer_finalize (GObject *object)
 {
-
   g_signal_handlers_destroy (object);
 
   G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->finalize (object);
@@ -440,9 +439,8 @@
 }
 
 static gboolean 
-myth_control_acquire_context( gboolean do_wait ) 
+myth_control_acquire_context( gboolean do_wait )
 {
-	
 	gboolean ret = TRUE;	
 	//guint max_iter = 50;
 	
@@ -466,13 +464,11 @@
   //g_static_mutex_lock( &st_mutex );
   
   return ret;
-  
 }
 
 static gboolean 
 myth_control_release_context( ) 
 {
-	
 	gboolean ret = TRUE;
     
   //g_static_mutex_unlock( &st_mutex );
@@ -488,7 +484,6 @@
   //g_mutex_unlock( mutex );  
  
   return ret;
-  
 }
 
 gint 
diff -r 462a3c81abd6 -r b250ee0438a2 gmyth/src/gmyth_file_transfer.h
--- a/gmyth/src/gmyth_file_transfer.h	Wed Dec 13 23:44:04 2006 +0000
+++ b/gmyth/src/gmyth_file_transfer.h	Fri Dec 15 00:21:57 2006 +0000
@@ -69,7 +69,7 @@
 
   /* signal default handlers */
   void (*program_info_changed_handler) ( GMythFileTransfer *transfer, 
-										gint msg_code, gpointer livetv_transfer );
+										gint msg_code, gpointer livetv_transfer, gpointer user_data );
 };
 
 struct _GMythFileTransfer
diff -r 462a3c81abd6 -r b250ee0438a2 gmyth/src/gmyth_util.c
--- a/gmyth/src/gmyth_util.c	Wed Dec 13 23:44:04 2006 +0000
+++ b/gmyth/src/gmyth_util.c	Fri Dec 15 00:21:57 2006 +0000
@@ -88,37 +88,59 @@
  * @return GString* the converted isoformat string 
  */
 static gchar*
-gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, GTimeVal* time)
+gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, GTimeVal* time_val )
 {
 	
-	gchar *result = g_time_val_to_iso8601( time );
-	gmyth_debug ("GMythUtil: before transcoding, result is: %s!\n", result);
+	gchar *result = NULL;
+	struct tm *tm_time = NULL;
 	
-	struct tm* tm_timeval = g_new0( struct tm, 1 );
+	gint buffer_len = 0;
 	
-	g_return_val_if_fail( fmt_string != NULL, NULL );
+	g_return_val_if_fail( fmt_string != NULL, NULL );	
+	g_return_val_if_fail( time_val != NULL, NULL );
+ 
+	time_t time = time_val->tv_sec + (gint)(time_val->tv_usec / G_USEC_PER_SEC);
 
-  if ( NULL == time ) { 
-		gmyth_debug ("GMythUtil: time_to_isoformat_from_time converter error (timeval == NULL)!\n");
-		return NULL;
+	tm_time = g_malloc0( sizeof(struct tm) );
+
+	g_static_mutex_lock ( &mutex );
+	
+	if ( NULL == gmtime_r( &time, tm_time ) ) {
+		g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
+	}	else {
+		// we first check the return of strftime to allocate a buffer of the correct size
+	  buffer_len = strftime( NULL, SSIZE_MAX, fmt_string, tm_time );
+	  if( buffer_len > 0 ){
+	    result = g_malloc0( buffer_len + 1 );
+	    if( result == NULL ){     
+				g_static_mutex_unlock ( &mutex );
+				g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
+				return NULL;
+	    }
+	    strftime( result, buffer_len + 1, fmt_string, tm_time );
+	    gmyth_debug( "Dateline (ISO result): %s\n", result );
+	  }
+		
 	}
 	
-	g_static_mutex_lock ( &mutex );
+	/* 
+	if ( NULL == asctime_r( tm_time, result ) ) {
+		g_static_mutex_unlock ( &mutex );
+		g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
+    return NULL;
+	}
+	*/
 	
-	strptime( result, "%Y-%m-%dT%H:%M:%SZ", tm_timeval ); 
+	gmyth_debug( "Result (after asctime_r) = %s", result );
 	
-	//g_date_set_time_val( date, time );
+	//strptime( result, "%Y-%m-%dT%H:%M:%SZ", tm_time ); 
 	
-	//g_date_strftime( result, 21, fmt_string, date );
-	strftime( result, strlen(result), fmt_string, tm_timeval );
+	//strftime( result, strlen(result), fmt_string, tm_time );
 	
 	g_static_mutex_unlock ( &mutex );
 	
 	gmyth_debug( "Result (ISO 8601) = %s", result  );
 	
-	//if ( date != NULL )
-	//	g_date_free( date );
-	
 	return result;	
 		
 }
@@ -135,7 +157,7 @@
 gchar*
 gmyth_util_time_to_isoformat_from_time_val ( GTimeVal* time )
 {
-	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%Y-%m-%d %T", time );
+	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%Y-%m-%dT%T", time );
 	//result[10] = ' ';
 	//result[ strlen(result) - 1] = '\0';
 	
@@ -209,6 +231,7 @@
 gmyth_util_time_to_string_from_time_val (GTimeVal *time_val)
 {
 	gchar *result = gmyth_util_time_to_isoformat_from_time_val (time_val);
+	result[10] = ' ';
 
 	return result;
 }