[svn r306] Corrected bug at gmyth_util.c - gmyth_util_string_to_time_val\n Updated getEpg at gmyth_http.c trunk
authormorphbr
Thu Jan 25 18:17:40 2007 +0000 (2007-01-25)
branchtrunk
changeset 3059d4af01c6a2f
parent 304 467386b8394a
child 306 bbf456814771
[svn r306] Corrected bug at gmyth_util.c - gmyth_util_string_to_time_val\n Updated getEpg at gmyth_http.c
gmyth/src/gmyth_http.c
gmyth/src/gmyth_http.h
gmyth/src/gmyth_util.c
     1.1 --- a/gmyth/src/gmyth_http.c	Thu Jan 25 18:09:52 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_http.c	Thu Jan 25 18:17:40 2007 +0000
     1.3 @@ -59,7 +59,7 @@
     1.4  
     1.5      if(xmlXPathNodeSetIsEmpty(result->nodesetval))
     1.6      {
     1.7 -        g_printf("No result\n");
     1.8 +        g_fprintf(stderr, "Error: No result at XPath\n");
     1.9          return NULL;
    1.10      }
    1.11  
    1.12 @@ -75,7 +75,7 @@
    1.13      doc = xmlReadMemory(content, length, NULL, NULL, 0);
    1.14      if (doc == NULL) 
    1.15      {
    1.16 -        g_fprintf(stderr, "Failed to parse document\n");
    1.17 +        g_fprintf(stderr, "Error: Failed to parse XML document\n");
    1.18          return NULL;
    1.19      }
    1.20  
    1.21 @@ -89,8 +89,31 @@
    1.22      return result;
    1.23  }
    1.24  
    1.25 -void get_ProgramGuide_Properties(xmlNodePtr nodeTab, GMythEpg* epg)
    1.26 +void get_Channel_List (xmlNodePtr nodeTab, GMythEpg* epg)
    1.27  {
    1.28 +	int i;
    1.29 +	epg->channelList = NULL;
    1.30 +
    1.31 +	for(i=1; i <= epg->numOfChannels; i++)
    1.32 +	{
    1.33 +		GMythChannel* channel = (GMythChannel*)g_malloc(sizeof(struct _GMythChannel));
    1.34 +		
    1.35 +		channel->channelName = g_string_new((char *)xmlGetProp(nodeTab, (xmlChar *)"channelName"));
    1.36 +		channel->chanNum = g_string_new((char *)xmlGetProp(nodeTab, (xmlChar *)"chanNum"));
    1.37 +
    1.38 +		sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"chanId"), "%d", &(channel->chanId));
    1.39 +		sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"callSign"), "%d", &(channel->callSign));
    1.40 +
    1.41 +		epg->channelList = g_slist_append(epg->channelList, channel);
    1.42 +		//get_Program_List(nodeTab, channel);
    1.43 +		//TODO: programlist
    1.44 +	}
    1.45 +}
    1.46 +
    1.47 +void get_ProgramGuide_Properties (xmlNodePtr nodeTab, GMythEpg* epg)
    1.48 +{
    1.49 +	//TODO: alloc GTimeVal -> it's loosing the value...
    1.50 +	//		gmyth_util_string_to_time_val does not alloc !
    1.51  	sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"startChanId"), "%d", &(epg->startChanId));
    1.52  	sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"endChanId"), "%d", &(epg->endChanId));
    1.53  
    1.54 @@ -106,8 +129,15 @@
    1.55  
    1.56  	sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"details"), "%d", &(epg->details));
    1.57  
    1.58 +	// go to Channel section and retrieve Channels and Programs
    1.59 +	get_Channel_List(nodeTab->children->next->children->next, epg);
    1.60  }
    1.61  
    1.62 +/** Retrieves the Eletronic Program Guide from the backend
    1.63 + *
    1.64 + * @param doc An XML document (xmlDocPtr)
    1.65 + * @return The epg
    1.66 + */
    1.67  void getEpg (xmlDocPtr doc)
    1.68  {
    1.69      xmlXPathObjectPtr result;
    1.70 @@ -115,7 +145,7 @@
    1.71      xmlChar *keyword;
    1.72  	GMythEpg epg;
    1.73  
    1.74 -    int i = 0;
    1.75 +    int i;
    1.76      result = getXPath((xmlChar *)"/*", doc);
    1.77  
    1.78  
    1.79 @@ -123,27 +153,18 @@
    1.80      {
    1.81          nodeset = result->nodesetval;
    1.82          for (i=0; i < nodeset->nodeNr; i++) 
    1.83 -        {
    1.84 -            keyword = nodeset->nodeTab[i]->name;
    1.85 +		{
    1.86 +			keyword = (xmlChar*)nodeset->nodeTab[i]->name;
    1.87 +			if (g_ascii_strcasecmp((char *)keyword, "ProgramGuide") == 0)
    1.88 +				get_ProgramGuide_Properties(nodeset->nodeTab[i], &epg);
    1.89 +		}
    1.90 +        xmlXPathFreeObject (result);
    1.91 +    }
    1.92  
    1.93 -			if (g_ascii_strcasecmp(keyword, "ProgramGuide") == 0)
    1.94 -				get_ProgramGuide_Properties(nodeset->nodeTab[i], &epg);
    1.95 -// 
    1.96 -// 			else if g_ascii_strcasecmp(keyword, "Channel")
    1.97 -// 				get_Channel_Properties(nodeTab[i]);
    1.98 -// 
    1.99 -// 			else if g_ascii_strcasecmp(keyword, "Program")
   1.100 -// 				get_Program_Properties(nodeTab[i]);
   1.101 -
   1.102 -            g_printf("keyword: %s\n", keyword);
   1.103 -        }
   1.104 -
   1.105 -        xmlXPathFreeObject (result);
   1.106 -    }	
   1.107  }
   1.108  
   1.109  /* Aux functions got from libcurl */
   1.110 -void *myrealloc(void *ptr, size_t size)
   1.111 +void *myrealloc (void *ptr, size_t size)
   1.112  {
   1.113      /* There might be a realloc() out there that doesn't like reallocing
   1.114          NULL pointers, so we take care of it here */
   1.115 @@ -154,7 +175,7 @@
   1.116  }
   1.117  
   1.118  size_t
   1.119 -WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
   1.120 +WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data)
   1.121  {
   1.122    size_t realsize = size * nmemb;
   1.123    struct MemoryStruct *mem = (struct MemoryStruct *)data;
   1.124 @@ -175,7 +196,7 @@
   1.125   *                    MUST FINISH WITH NULL!!!
   1.126   * @return The response
   1.127   */
   1.128 -GString* gmyth_http_create_command(GString *command, ...)
   1.129 +GString* gmyth_http_create_command (GString *command, ...)
   1.130  {
   1.131      va_list args;
   1.132      va_start(args, command);
   1.133 @@ -211,7 +232,7 @@
   1.134      LIBXML_TEST_VERSION
   1.135  
   1.136      size_t size = strlen(backend_info->hostname) + strlen(command->str) + 13;
   1.137 -    gchar *URL = malloc(sizeof(gchar)*size);
   1.138 +    gchar *URL = (gchar *)g_malloc(sizeof(gchar)*size);
   1.139      g_snprintf(URL, size+1, "http://%s:6544/%s", backend_info->hostname, command->str);     
   1.140  
   1.141      CURL *curl_handle;
     2.1 --- a/gmyth/src/gmyth_http.h	Thu Jan 25 18:09:52 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_http.h	Thu Jan 25 18:17:40 2007 +0000
     2.3 @@ -49,8 +49,6 @@
     2.4  
     2.5  #define MYTH_PORT_STATUS 6544
     2.6  #define BUFLEN 2048
     2.7 -#define TYPE_TEXT_XML 0
     2.8 -#define TYPE_FORM_URLENCODED 1
     2.9  
    2.10  typedef struct _GMythPacket     GMythPacket;
    2.11  typedef struct _GMythProgram    GMythProgram;
    2.12 @@ -82,7 +80,7 @@
    2.13  	GString* chanNum;
    2.14  	gint	chanId;
    2.15  	gint	callSign;
    2.16 -	GSList	programList;
    2.17 +	GSList*	programList;
    2.18  };
    2.19  
    2.20  struct _GMythEpg
    2.21 @@ -97,7 +95,7 @@
    2.22  	GTimeVal* startTime;
    2.23  	GTimeVal* endTime;
    2.24  	gint details;
    2.25 -	GSList channelList;
    2.26 +	GSList* channelList;
    2.27  };
    2.28  
    2.29  GString* gmyth_http_create_command(GString *command, ...);
     3.1 --- a/gmyth/src/gmyth_util.c	Thu Jan 25 18:09:52 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_util.c	Thu Jan 25 18:17:40 2007 +0000
     3.3 @@ -318,55 +318,38 @@
     3.4  	GTimeVal *time = g_new0( GTimeVal, 1 );
     3.5  	struct tm* tm_time = NULL;
     3.6  	time_t time_micros;
     3.7 -	gchar *result = NULL;
     3.8 -    
     3.9 +
    3.10  	gmyth_debug( "[%s] time_str = %s. [%s]\n", time_str, time_str != NULL ? 
    3.11  					time_str : "[time string is NULL!]", time_str );
    3.12  
    3.13 -  if ( NULL == time_str ) { 
    3.14 +	if ( NULL == time_str ) 
    3.15 +	{ 
    3.16  		g_warning ("GMythUtil: isoformat_to_time converter error!\n");
    3.17 -		time = NULL;
    3.18 -		goto done;
    3.19 +		return NULL;
    3.20  	}
    3.21  	
    3.22  	g_static_mutex_lock ( &mutex );
    3.23  	
    3.24  	tm_time = g_malloc0( sizeof(struct tm) );
    3.25  
    3.26 -	/* we first check the return of strftime to allocate a buffer of the correct size */
    3.27 -  result = strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time );
    3.28 -  if ( NULL == result ) {
    3.29 -		/* we first check the return of strftime to allocate a buffer of the correct size */
    3.30 -	  result = strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time );
    3.31 -	  if ( NULL == result ) {
    3.32 -	  	/* we first check the return of strftime to allocate a buffer of the correct size */
    3.33 -		  result = strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time );
    3.34 -		  if ( NULL == result ) {
    3.35 -		  	g_static_mutex_unlock ( &mutex );
    3.36 -		    gmyth_debug( "Dateline (ISO result): %s\n", result );
    3.37 -		    time = NULL;
    3.38 -		    goto done;	    
    3.39 -		  }
    3.40 -	  }
    3.41 -  }
    3.42 -  
    3.43 -  time_micros = mktime( tm_time );
    3.44 -		
    3.45 +	if (strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time ) == NULL)
    3.46 +		if (strptime( time_str, "%Y-%m-%dT%H:%M", tm_time ) == NULL)
    3.47 +			if (strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time ) == NULL)
    3.48 +				if (strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time ) == NULL)
    3.49 +				{
    3.50 +					g_static_mutex_unlock ( &mutex );
    3.51 +					gmyth_debug( "Error with Dateline. Not recognised");
    3.52 +					return NULL;
    3.53 +				}
    3.54 +
    3.55 +	time_micros = mktime( tm_time );
    3.56 +	
    3.57  	time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC );
    3.58  	
    3.59 -	//strftime( result, SSIZE_MAX, "%Y-%m-%dT%H:%M:%S", tm_time );
    3.60 -	
    3.61  	gmyth_debug( "After mktime call... = %s", asctime(tm_time) );
    3.62  
    3.63  	g_static_mutex_unlock ( &mutex );
    3.64  
    3.65 -done:	
    3.66 -	//if ( tm_time )
    3.67 -	//	g_free( tm_time );
    3.68 -		
    3.69 -	//if ( result )
    3.70 -	//	g_free( result );		
    3.71 -	
    3.72  	return time;
    3.73  }
    3.74