# HG changeset patch # User morphbr # Date 1169749060 0 # Node ID 9d4af01c6a2f97def49af9a4e443d13845e2b2ff # Parent 467386b8394aa107aef63e19a212d0798f5a66b7 [svn r306] Corrected bug at gmyth_util.c - gmyth_util_string_to_time_val\n Updated getEpg at gmyth_http.c diff -r 467386b8394a -r 9d4af01c6a2f gmyth/src/gmyth_http.c --- a/gmyth/src/gmyth_http.c Thu Jan 25 18:09:52 2007 +0000 +++ b/gmyth/src/gmyth_http.c Thu Jan 25 18:17:40 2007 +0000 @@ -59,7 +59,7 @@ if(xmlXPathNodeSetIsEmpty(result->nodesetval)) { - g_printf("No result\n"); + g_fprintf(stderr, "Error: No result at XPath\n"); return NULL; } @@ -75,7 +75,7 @@ doc = xmlReadMemory(content, length, NULL, NULL, 0); if (doc == NULL) { - g_fprintf(stderr, "Failed to parse document\n"); + g_fprintf(stderr, "Error: Failed to parse XML document\n"); return NULL; } @@ -89,8 +89,31 @@ return result; } -void get_ProgramGuide_Properties(xmlNodePtr nodeTab, GMythEpg* epg) +void get_Channel_List (xmlNodePtr nodeTab, GMythEpg* epg) { + int i; + epg->channelList = NULL; + + for(i=1; i <= epg->numOfChannels; i++) + { + GMythChannel* channel = (GMythChannel*)g_malloc(sizeof(struct _GMythChannel)); + + channel->channelName = g_string_new((char *)xmlGetProp(nodeTab, (xmlChar *)"channelName")); + channel->chanNum = g_string_new((char *)xmlGetProp(nodeTab, (xmlChar *)"chanNum")); + + sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"chanId"), "%d", &(channel->chanId)); + sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"callSign"), "%d", &(channel->callSign)); + + epg->channelList = g_slist_append(epg->channelList, channel); + //get_Program_List(nodeTab, channel); + //TODO: programlist + } +} + +void get_ProgramGuide_Properties (xmlNodePtr nodeTab, GMythEpg* epg) +{ + //TODO: alloc GTimeVal -> it's loosing the value... + // gmyth_util_string_to_time_val does not alloc ! sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"startChanId"), "%d", &(epg->startChanId)); sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"endChanId"), "%d", &(epg->endChanId)); @@ -106,8 +129,15 @@ sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"details"), "%d", &(epg->details)); + // go to Channel section and retrieve Channels and Programs + get_Channel_List(nodeTab->children->next->children->next, epg); } +/** Retrieves the Eletronic Program Guide from the backend + * + * @param doc An XML document (xmlDocPtr) + * @return The epg + */ void getEpg (xmlDocPtr doc) { xmlXPathObjectPtr result; @@ -115,7 +145,7 @@ xmlChar *keyword; GMythEpg epg; - int i = 0; + int i; result = getXPath((xmlChar *)"/*", doc); @@ -123,27 +153,18 @@ { nodeset = result->nodesetval; for (i=0; i < nodeset->nodeNr; i++) - { - keyword = nodeset->nodeTab[i]->name; + { + keyword = (xmlChar*)nodeset->nodeTab[i]->name; + if (g_ascii_strcasecmp((char *)keyword, "ProgramGuide") == 0) + get_ProgramGuide_Properties(nodeset->nodeTab[i], &epg); + } + xmlXPathFreeObject (result); + } - if (g_ascii_strcasecmp(keyword, "ProgramGuide") == 0) - get_ProgramGuide_Properties(nodeset->nodeTab[i], &epg); -// -// else if g_ascii_strcasecmp(keyword, "Channel") -// get_Channel_Properties(nodeTab[i]); -// -// else if g_ascii_strcasecmp(keyword, "Program") -// get_Program_Properties(nodeTab[i]); - - g_printf("keyword: %s\n", keyword); - } - - xmlXPathFreeObject (result); - } } /* Aux functions got from libcurl */ -void *myrealloc(void *ptr, size_t size) +void *myrealloc (void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing NULL pointers, so we take care of it here */ @@ -154,7 +175,7 @@ } size_t -WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; @@ -175,7 +196,7 @@ * MUST FINISH WITH NULL!!! * @return The response */ -GString* gmyth_http_create_command(GString *command, ...) +GString* gmyth_http_create_command (GString *command, ...) { va_list args; va_start(args, command); @@ -211,7 +232,7 @@ LIBXML_TEST_VERSION size_t size = strlen(backend_info->hostname) + strlen(command->str) + 13; - gchar *URL = malloc(sizeof(gchar)*size); + gchar *URL = (gchar *)g_malloc(sizeof(gchar)*size); g_snprintf(URL, size+1, "http://%s:6544/%s", backend_info->hostname, command->str); CURL *curl_handle; diff -r 467386b8394a -r 9d4af01c6a2f gmyth/src/gmyth_http.h --- a/gmyth/src/gmyth_http.h Thu Jan 25 18:09:52 2007 +0000 +++ b/gmyth/src/gmyth_http.h Thu Jan 25 18:17:40 2007 +0000 @@ -49,8 +49,6 @@ #define MYTH_PORT_STATUS 6544 #define BUFLEN 2048 -#define TYPE_TEXT_XML 0 -#define TYPE_FORM_URLENCODED 1 typedef struct _GMythPacket GMythPacket; typedef struct _GMythProgram GMythProgram; @@ -82,7 +80,7 @@ GString* chanNum; gint chanId; gint callSign; - GSList programList; + GSList* programList; }; struct _GMythEpg @@ -97,7 +95,7 @@ GTimeVal* startTime; GTimeVal* endTime; gint details; - GSList channelList; + GSList* channelList; }; GString* gmyth_http_create_command(GString *command, ...); diff -r 467386b8394a -r 9d4af01c6a2f gmyth/src/gmyth_util.c --- a/gmyth/src/gmyth_util.c Thu Jan 25 18:09:52 2007 +0000 +++ b/gmyth/src/gmyth_util.c Thu Jan 25 18:17:40 2007 +0000 @@ -318,55 +318,38 @@ GTimeVal *time = g_new0( GTimeVal, 1 ); struct tm* tm_time = NULL; time_t time_micros; - gchar *result = NULL; - + gmyth_debug( "[%s] time_str = %s. [%s]\n", time_str, time_str != NULL ? time_str : "[time string is NULL!]", time_str ); - if ( NULL == time_str ) { + if ( NULL == time_str ) + { g_warning ("GMythUtil: isoformat_to_time converter error!\n"); - time = NULL; - goto done; + return NULL; } g_static_mutex_lock ( &mutex ); tm_time = g_malloc0( sizeof(struct tm) ); - /* we first check the return of strftime to allocate a buffer of the correct size */ - result = strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time ); - if ( NULL == result ) { - /* we first check the return of strftime to allocate a buffer of the correct size */ - result = strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time ); - if ( NULL == result ) { - /* we first check the return of strftime to allocate a buffer of the correct size */ - result = strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time ); - if ( NULL == result ) { - g_static_mutex_unlock ( &mutex ); - gmyth_debug( "Dateline (ISO result): %s\n", result ); - time = NULL; - goto done; - } - } - } - - time_micros = mktime( tm_time ); - + if (strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time ) == NULL) + if (strptime( time_str, "%Y-%m-%dT%H:%M", tm_time ) == NULL) + if (strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time ) == NULL) + if (strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time ) == NULL) + { + g_static_mutex_unlock ( &mutex ); + gmyth_debug( "Error with Dateline. Not recognised"); + return NULL; + } + + time_micros = mktime( tm_time ); + time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC ); - //strftime( result, SSIZE_MAX, "%Y-%m-%dT%H:%M:%S", tm_time ); - gmyth_debug( "After mktime call... = %s", asctime(tm_time) ); g_static_mutex_unlock ( &mutex ); -done: - //if ( tm_time ) - // g_free( tm_time ); - - //if ( result ) - // g_free( result ); - return time; }