# HG changeset patch # User morphbr # Date 1171137714 0 # Node ID 7005e696052c50e07f467f792ee731a3a1e875ef # Parent eb7372f7a97217276bc662e2fbab40a506403a82 [svn r351] - Bug fix in gmyth_util.c: included support for time without seconds in gmyth_util_string_to_time_val_fmt (XML format from backend) - Bug fix in gmyth_http.c: fixed bug when there are no channels - gmyth_vlc.c/h: included support to specify a port when connecting to VLC - tests: fixed vlc test file regarding the fix above created script to compile http test app diff -r eb7372f7a972 -r 7005e696052c gmyth/src/gmyth_http.c --- a/gmyth/src/gmyth_http.c Fri Feb 09 21:43:35 2007 +0000 +++ b/gmyth/src/gmyth_http.c Sat Feb 10 20:01:54 2007 +0000 @@ -129,20 +129,23 @@ 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(node, (xmlChar *)"channelName")); - channel->chanNum = g_string_new((char *)xmlGetProp(node, (xmlChar *)"chanNum")); + if (node != NULL) { - sscanf ((char *)xmlGetProp(node, (xmlChar *)"chanId"), "%d", &(channel->chanId)); - sscanf ((char *)xmlGetProp(node, (xmlChar *)"callSign"), "%d", &(channel->callSign)); - - channel->programList = get_Program_List(node->children); - - epg->channelList = g_slist_append(epg->channelList, channel); - } + for (i=1; i <= epg->numOfChannels; i++) + { + GMythChannel* channel = (GMythChannel*)g_malloc(sizeof(struct _GMythChannel)); + + channel->channelName = g_string_new((char *)xmlGetProp(node, (xmlChar *)"channelName")); + channel->chanNum = g_string_new((char *)xmlGetProp(node, (xmlChar *)"chanNum")); + + sscanf ((char *)xmlGetProp(node, (xmlChar *)"chanId"), "%d", &(channel->chanId)); + sscanf ((char *)xmlGetProp(node, (xmlChar *)"callSign"), "%d", &(channel->callSign)); + + channel->programList = get_Program_List(node->children); + + epg->channelList = g_slist_append(epg->channelList, channel); + } + } } /** Retrieves the properties from the ProgramGuide @@ -169,7 +172,10 @@ 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); + if ( epg->numOfChannels > 0 ) + get_Channel_List(nodeTab->children->next->children->next, epg); + else + epg->channelList = NULL; } /** Aux function to retrieve the Eletronic Program Guide @@ -200,6 +206,50 @@ } + +gchar* gmyth_http_retrieve_setting (GMythBackendInfo *backend_info,\ + gchar* key, gchar* hostname) +{ + xmlXPathObjectPtr result; + xmlNodeSetPtr nodeset; + xmlChar *keyword; + MemoryStruct chunk; + gchar* value = NULL; + + chunk.memory = NULL; + chunk.size = 0; + + GString* command = g_string_new(""); + g_string_printf(command, "getSetting?Key=%s&HostName=%s&Default=NULL", \ + key, hostname); + + chunk = gmyth_http_request(backend_info, command); + + if (chunk.memory != NULL) + { + xmlDocPtr doc = XMLParse(chunk.memory, strlen(chunk.memory)); + + result = getXPath((xmlChar *)"/*", doc); + + if (result) + { + nodeset = result->nodesetval; + keyword = (xmlChar*)nodeset->nodeTab[0]->name; + if (g_ascii_strcasecmp((char *)keyword, "Value") == 0) + { + // Here we have the value + value = (gchar*)nodeset->nodeTab[0]->children->content; + } + xmlXPathFreeObject (result); + } + + free(chunk.memory); + } + + return value; +} + + /** Retrieves the Eletronic Program Guide from the backend * * @param doc An XML document (xmlDocPtr) @@ -294,6 +344,8 @@ return command; } + + /** Send HTTP Command and receives the result of it * * @return A string with the response from the server diff -r eb7372f7a972 -r 7005e696052c gmyth/src/gmyth_http.h --- a/gmyth/src/gmyth_http.h Fri Feb 09 21:43:35 2007 +0000 +++ b/gmyth/src/gmyth_http.h Sat Feb 10 20:01:54 2007 +0000 @@ -95,7 +95,13 @@ GSList* channelList; }; -GMythEpg retrieve_epg(GMythBackendInfo *backend_info, int port, GTimeVal* StartTime, GTimeVal* EndTime, gint StartChanId, gint NumOfChannels, gchar* Details); +gchar* gmyth_http_retrieve_setting (GMythBackendInfo *backend_info,\ + gchar* key, gchar* hostname); + +GMythEpg retrieve_epg(GMythBackendInfo *backend_info, int port,\ + GTimeVal* StartTime, GTimeVal* EndTime, \ + gint StartChanId, gint NumOfChannels, gchar* Details); + MemoryStruct gmyth_http_request (GMythBackendInfo *backend_info, GString *command); G_END_DECLS diff -r eb7372f7a972 -r 7005e696052c gmyth/src/gmyth_util.c --- a/gmyth/src/gmyth_util.c Fri Feb 09 21:43:35 2007 +0000 +++ b/gmyth/src/gmyth_util.c Sat Feb 10 20:01:54 2007 +0000 @@ -332,46 +332,50 @@ struct tm* tm_time = NULL; time_t time_micros; gchar* result; - + gmyth_debug( "[%s] time_str = %s. [%s]", time_str, time_str != NULL ? - time_str : "[time string is NULL!]", time_str ); - + time_str : "[time string is NULL!]", time_str ); + if ( NULL == time_str ) - { + { g_warning ("GMythUtil: isoformat_to_time converter error!\n"); 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:%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", result ); - time = NULL; - //goto done; - } + result = strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time ); + if ( NULL == result) { + result = strptime( time_str, "%Y-%m-%dT%H:%M", tm_time ); + if ( NULL == result ) { + g_static_mutex_unlock ( &mutex ); + gmyth_debug( "Dateline (ISO result): %s", result ); + g_free(tm_time); + return NULL; + //goto done; + } + } } - } - - time_micros = mktime( tm_time ); - - time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC ); - - gmyth_debug( "After mktime call... = %s", asctime(tm_time) ); - - g_static_mutex_unlock ( &mutex ); - - return time; + } + + time_micros = mktime( tm_time ); + + time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC ); + + gmyth_debug( "After mktime call... = %s", asctime(tm_time) ); + + g_static_mutex_unlock ( &mutex ); + + return time; } /** Converts a GString in the following format diff -r eb7372f7a972 -r 7005e696052c gmyth/src/gmyth_vlc.c --- a/gmyth/src/gmyth_vlc.c Fri Feb 09 21:43:35 2007 +0000 +++ b/gmyth/src/gmyth_vlc.c Sat Feb 10 20:01:54 2007 +0000 @@ -209,7 +209,7 @@ * @return 0 if success */ int gmyth_vlc_connect(GMythVlc *vlc, GMythBackendInfo *backend_info,\ - gchar* passwd) + gchar* passwd, int port) { int numbytes; @@ -227,7 +227,7 @@ // Socket properties vlc->their_addr.sin_family = AF_INET; - vlc->their_addr.sin_port = htons(VLC_TELNET_PORT); + vlc->their_addr.sin_port = htons(port); vlc->their_addr.sin_addr = *((struct in_addr *)vlc->he->h_addr); memset(&(vlc->their_addr.sin_zero), '\0', 8); diff -r eb7372f7a972 -r 7005e696052c gmyth/src/gmyth_vlc.h --- a/gmyth/src/gmyth_vlc.h Fri Feb 09 21:43:35 2007 +0000 +++ b/gmyth/src/gmyth_vlc.h Sat Feb 10 20:01:54 2007 +0000 @@ -1,7 +1,7 @@ /** * GMyth Library * - * @file gmyth/gmyth_vlc.c + * @file gmyth/gmyth_vlc.h * * @brief

GMythVLC library provides functions that * interact with a VLC server running telnet interface. @@ -88,7 +88,7 @@ int port); int gmyth_vlc_connect(GMythVlc *vlc, GMythBackendInfo *backend_info,\ - gchar* passwd); + gchar* passwd, int port); int gmyth_vlc_disconnect(GMythVlc *vlc); diff -r eb7372f7a972 -r 7005e696052c gmyth/tests/compile_test_http --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/compile_test_http Sat Feb 10 20:01:54 2007 +0000 @@ -0,0 +1,2 @@ +gcc -g -o http gmyth_test_http.c `pkg-config --cflags --libs gmyth-0.1` + diff -r eb7372f7a972 -r 7005e696052c gmyth/tests/gmyth_test_vlc.c --- a/gmyth/tests/gmyth_test_vlc.c Fri Feb 09 21:43:35 2007 +0000 +++ b/gmyth/tests/gmyth_test_vlc.c Sat Feb 10 20:01:54 2007 +0000 @@ -18,11 +18,18 @@ gmyth_backend_info_set_hostname (backend_info, "192.168.3.137"); gmyth_backend_info_set_port (backend_info, 6543); - gmyth_vlc_connect(&vlc, backend_info, "admin"); - gmyth_vlc_create_channel(&vlc, "broadcast", 8080); - gmyth_vlc_create_input(&vlc, 0, "/tmp/grande.nuv"); - gmyth_vlc_control_input(&vlc, 0, "play"); - gmyth_vlc_disconnect(&vlc); + int res = gmyth_vlc_connect(&vlc, backend_info, "admin", 4212); + + if ( res >= 0 ) + { + gmyth_vlc_create_channel(&vlc, "broadcast", 8080); + gmyth_vlc_create_input(&vlc, 0, "/tmp/grande.nuv"); + gmyth_vlc_control_input(&vlc, 0, "play"); + gmyth_vlc_disconnect(&vlc); + } + + //gchar* teste = gmyth_http_retrieve_setting(backend_info, "RecordFilePrefix", "hmelo-desktop"); + return 0; }