[svn r280] Some fixes to the TV chain creation, and gmyth_uri query parsing (set channel). trunk
authorrosfran
Fri Jan 19 18:05:58 2007 +0000 (2007-01-19)
branchtrunk
changeset 2795a224299ab37
parent 278 a24bacc8d752
child 280 e5199e48abec
[svn r280] Some fixes to the TV chain creation, and gmyth_uri query parsing (set channel).
gmyth/src/gmyth_backendinfo.c
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_tvchain.c
gmyth/src/gmyth_uri.c
gmyth/src/gmyth_uri.h
     1.1 --- a/gmyth/src/gmyth_backendinfo.c	Fri Jan 19 13:09:21 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_backendinfo.c	Fri Jan 19 18:05:58 2007 +0000
     1.3 @@ -143,7 +143,6 @@
     1.4      if ( NULL == hostname || strlen(hostname) <= 0 )
     1.5      { 
     1.6  	  	gmyth_debug ( "Error trying to set a hostname equals to NULL." );
     1.7 -  		return NULL;
     1.8      } else {    	
     1.9      	backend_info->hostname = g_strdup (hostname);
    1.10      }
    1.11 @@ -181,7 +180,6 @@
    1.12      if ( port <= 0 )
    1.13      { 
    1.14  	  	gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
    1.15 -  		return NULL;
    1.16      } else {    	
    1.17      	backend_info->port = port;
    1.18      }
     2.1 --- a/gmyth/src/gmyth_livetv.c	Fri Jan 19 13:09:21 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_livetv.c	Fri Jan 19 18:05:58 2007 +0000
     2.3 @@ -266,7 +266,28 @@
     2.4  		res = FALSE;
     2.5  		goto error;
     2.6  	}
     2.7 +	
     2.8 +	// Init remote encoder. Opens its control socket.
     2.9 +	res = gmyth_recorder_setup(livetv->recorder);
    2.10 +	if ( !res ) {
    2.11 +		g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
    2.12 +		res = FALSE;
    2.13 +		goto error;
    2.14 +	}
    2.15 +	
    2.16 +	if ( channel != -1 ) 
    2.17 +	{
    2.18 +	  gint ch = channel;
    2.19 +  	//if ( gmyth_recorder_check_channel( livetv->recorder, ch ) ) 
    2.20 +  	//{
    2.21 +	  	if ( gmyth_recorder_set_channel( livetv->recorder, ch ) )
    2.22 +	  	{
    2.23 +	  		g_print( "[%s] Channel changed!!! [%d].\n", __FUNCTION__, ch );
    2.24 +	  	}
    2.25 +  	//}
    2.26  
    2.27 +	}
    2.28 +	
    2.29  	// Creates livetv chain handler
    2.30  	livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
    2.31  	gmyth_tvchain_initialize ( livetv->tvchain, livetv->backend_info );
    2.32 @@ -276,27 +297,13 @@
    2.33  		goto error;
    2.34  	}
    2.35  
    2.36 -	// Init remote encoder. Opens its control socket.
    2.37 -	res = gmyth_recorder_setup(livetv->recorder);
    2.38 -	if ( !res ) {
    2.39 -		g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
    2.40 +	// Reload all TV chain from Mysql database.
    2.41 +	gmyth_tvchain_reload_all (livetv->tvchain);
    2.42 +
    2.43 +	if ( livetv->tvchain == NULL ) {
    2.44  		res = FALSE;
    2.45  		goto error;
    2.46  	}
    2.47 -	
    2.48 -	if ( channel != -1 ) {
    2.49 -	  gint ch = channel;
    2.50 -	  gint ch_idx = 0;  
    2.51 -	  for ( ; ch_idx < 5; ch_idx++ ) {
    2.52 -	  	if ( gmyth_recorder_check_channel( livetv->recorder, ch ) ) {
    2.53 -		  	if ( gmyth_recorder_set_channel( livetv->recorder, ch ) ) {
    2.54 -		  		g_print( "[%s] Channel changed!!! [%d].\n", __FUNCTION__, ch );
    2.55 -		  		break;
    2.56 -		  	}
    2.57 -	  	}
    2.58 -	  	++ch;
    2.59 -	  }
    2.60 -	}
    2.61  
    2.62  	// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
    2.63  	res = gmyth_recorder_spawntv ( livetv->recorder,
    2.64 @@ -307,14 +314,6 @@
    2.65  		goto error;
    2.66  	}
    2.67  
    2.68 -	// Reload all TV chain from Mysql database.
    2.69 -	gmyth_tvchain_reload_all (livetv->tvchain);
    2.70 -
    2.71 -	if ( livetv->tvchain == NULL ) {
    2.72 -		res = FALSE;
    2.73 -		goto error;
    2.74 -	}
    2.75 -
    2.76  	// Get program info from database using chanid and starttime
    2.77  	livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ );
    2.78  	if ( livetv->proginfo == NULL ) {
     3.1 --- a/gmyth/src/gmyth_tvchain.c	Fri Jan 19 13:09:21 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_tvchain.c	Fri Jan 19 18:05:58 2007 +0000
     3.3 @@ -226,7 +226,7 @@
     3.4  			entry->inputname = g_string_new (msql_row[8]);
     3.5  
     3.6  			//m_maxpos = query.value(4).toInt() + 1;
     3.7 -			g_print( "[%s] Reading TV chain entry: [%s, %s, %s]\n", __FUNCTION__, entry->chanid->str, 
     3.8 +			g_print( "[%s] Reading TV chain entry (channel %d): [%s, %s, %s]\n", __FUNCTION__, entry->channum, entry->chanid->str, 
     3.9  					(gchar*)msql_row[1], (gchar*)msql_row[2] );
    3.10  			
    3.11  			/* add this to get the actual start timestamp of the last recording */
     4.1 --- a/gmyth/src/gmyth_uri.c	Fri Jan 19 13:09:21 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_uri.c	Fri Jan 19 18:05:58 2007 +0000
     4.3 @@ -215,6 +215,7 @@
     4.4  	gint 		atIdx;
     4.5  	gint 		colonIdx;
     4.6  	gint 		shashIdx;
     4.7 +	gint 		eIdx;
     4.8  	gchar 	    *host;
     4.9  	gint 		eblacketIdx;
    4.10  	gint 		hostLen;
    4.11 @@ -273,8 +274,8 @@
    4.12  		/**** port ****/
    4.13  		portStr = g_string_new_len (hostStr->str+colonIdx+1, hostLen-colonIdx-1);
    4.14  		uri->port = (gint)g_ascii_strtoull( portStr->str, NULL, 10 );
    4.15 -		g_string_free (portStr, TRUE);
    4.16 -		g_string_free (hostStr, TRUE);
    4.17 +		g_string_free (portStr, FALSE);
    4.18 +		g_string_free (hostStr, FALSE);
    4.19  	}
    4.20  	else {
    4.21          const gchar* protocol = gmyth_uri_get_protocol(uri);
    4.22 @@ -306,22 +307,24 @@
    4.23  		/* First set path simply to the rest of URI */
    4.24  		uri->path = g_string_new_len (value+currIdx,  uriLen-currIdx );
    4.25  	}
    4.26 -		
    4.27 +	
    4.28 +	gmyth_debug( "uri value:  %s", value );
    4.29 +	uri->query = g_string_new ( g_strstr_len( value, strlen(value), GMYTH_URI_E_DELIM ) );
    4.30 +	
    4.31 +	eIdx = gmyth_strstr( value+currIdx, GMYTH_URI_E_DELIM );
    4.32 +	
    4.33 +	if ( 0 < eIdx ) {
    4.34 +		uri->query = g_string_new ( g_strstr_len( value, strlen(value), GMYTH_URI_E_DELIM ) );
    4.35 +		gmyth_debug( "query = %s", uri->query->str );
    4.36 +	}
    4.37 +	
    4.38  	/**** Path (Query/Fragment) ****/
    4.39  	sharpIdx = gmyth_strstr(value+currIdx, GMYTH_URI_SHARP_DELIM);
    4.40  	if (0 < sharpIdx) {
    4.41  		uri->path = g_string_append_len( uri->path, value+currIdx, sharpIdx);
    4.42  		uri->fragment = g_string_new_len (value+currIdx+sharpIdx+1, uriLen-(currIdx+sharpIdx+1));
    4.43 -	}
    4.44 -	
    4.45 -	questionIdx = gmyth_strstr( value+currIdx, GMYTH_URI_QUESTION_DELIM );
    4.46 -	if ( 0 < questionIdx ) {
    4.47 -		uri->path = g_string_append_len (uri->path, value+currIdx, questionIdx );
    4.48 -		queryLen = uriLen-(currIdx+questionIdx+1);
    4.49 -		if ( 0 < sharpIdx )
    4.50 -			queryLen -= uriLen - (currIdx+sharpIdx+1);
    4.51 -		uri->query = g_string_new_len (value+currIdx+questionIdx+1, queryLen );
    4.52 -	}
    4.53 +	}	
    4.54 +
    4.55  	gmyth_debug( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "\
    4.56  								"user = %s, password = %s.\n", __FUNCTION__, gmyth_uri_print_field( uri->host ), uri->port,
    4.57  													gmyth_uri_print_field( uri->path ), gmyth_uri_print_field( uri->query ), gmyth_uri_print_field( uri->fragment ),
    4.58 @@ -336,3 +339,44 @@
    4.59  				gmyth_uri_get_port( uri1 ) == gmyth_uri_get_port( uri2 ) );
    4.60  }
    4.61  
    4.62 +gboolean
    4.63 +gmyth_uri_is_livetv( GMythURI* uri )
    4.64 +{
    4.65 +	
    4.66 +	g_return_val_if_fail( uri != NULL && uri->uri != NULL && uri->uri->str != NULL, FALSE );
    4.67 +	
    4.68 +	return ( g_strstr_len( uri->uri->str, strlen( uri->uri->str ), "/?" ) != NULL );
    4.69 +	
    4.70 +}
    4.71 +
    4.72 +gint
    4.73 +gmyth_uri_get_channel_num( GMythURI* uri )
    4.74 +{
    4.75 +	gint channel = -1;
    4.76 +	
    4.77 +	g_return_val_if_fail( uri != NULL && uri->uri != NULL && uri->uri->str != NULL, FALSE );
    4.78 +	
    4.79 +	gchar *channel_query = g_strstr_len( gmyth_uri_get_query( uri ), strlen( gmyth_uri_get_query( uri ) ), "channel" );
    4.80 +	
    4.81 +	if ( channel_query != NULL )
    4.82 +	{
    4.83 +		gmyth_debug( "Channel is in the following URI segment: %s", channel_query );
    4.84 +		
    4.85 +		gchar **chan_key_value = g_strsplit( gmyth_uri_get_query( uri ), "=", 2 );
    4.86 +		
    4.87 +		gmyth_debug( "Channel tuple is [ %s, %s ]", chan_key_value[0], chan_key_value[1] );
    4.88 +		
    4.89 +		if ( chan_key_value[1] != NULL )
    4.90 +		{
    4.91 +			channel = g_ascii_strtoull( chan_key_value[1], NULL, 10 ); 
    4.92 +		}
    4.93 +		
    4.94 +		if ( chan_key_value )		
    4.95 +			g_strfreev( chan_key_value );
    4.96 +	}
    4.97 +	
    4.98 +	gmyth_debug( "Got channel decimal value from the URI: %d", channel );
    4.99 +		
   4.100 +	return channel;
   4.101 +	
   4.102 +}
     5.1 --- a/gmyth/src/gmyth_uri.h	Fri Jan 19 13:09:21 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_uri.h	Fri Jan 19 18:05:58 2007 +0000
     5.3 @@ -67,6 +67,7 @@
     5.4  #define GMYTH_URI_EBLACET_DELIM 			"]"
     5.5  #define GMYTH_URI_SHARP_DELIM 				"#"
     5.6  #define GMYTH_URI_QUESTION_DELIM 			"?"
     5.7 +#define GMYTH_URI_E_DELIM 						"&"
     5.8  #define GMYTH_URI_ESCAPING_CHAR 			"%"
     5.9  
    5.10  #define GMYTH_URI_PROTOCOL_MYTH 			"myth"
    5.11 @@ -104,9 +105,13 @@
    5.12  GType       gmyth_uri_get_type (void);
    5.13  GMythURI*   gmyth_uri_new (void);
    5.14  GMythURI*   gmyth_uri_new_with_value (const gchar *value);
    5.15 -gboolean 		gmyth_uri_is_equals (GMythURI* uri1, GMythURI* uri2);
    5.16 +gboolean 		gmyth_uri_is_equals ( GMythURI* uri1, GMythURI* uri2 );
    5.17 +gboolean		gmyth_uri_is_livetv ( GMythURI* uri );
    5.18 +gint				gmyth_uri_get_channel_num( GMythURI* uri );
    5.19 +
    5.20 +
    5.21  #define 		gmyth_uri_get_host(urip) 			( urip->host != NULL ? urip->host->str : "" )
    5.22 -#define 		gmyth_uri_get_port(urip) 			(urip->port)
    5.23 +#define 		gmyth_uri_get_port(urip) 			( urip->port )
    5.24  #define 		gmyth_uri_get_protocol(urip) 	( urip->protocol != NULL ? urip->protocol->str : "" )
    5.25  #define 		gmyth_uri_get_path(urip) 			( urip->path != NULL ? urip->path->str : "" )
    5.26  #define 		gmyth_uri_get_user(urip) 			( urip->user != NULL ? urip->user->str : "" )