[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) trunk
authormorphbr
Sat Feb 10 20:01:54 2007 +0000 (2007-02-10)
branchtrunk
changeset 3497005e696052c
parent 348 eb7372f7a972
child 350 ff82d527d26a
[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
gmyth/src/gmyth_http.c
gmyth/src/gmyth_http.h
gmyth/src/gmyth_util.c
gmyth/src/gmyth_vlc.c
gmyth/src/gmyth_vlc.h
gmyth/tests/compile_test_http
gmyth/tests/gmyth_test_vlc.c
     1.1 --- a/gmyth/src/gmyth_http.c	Fri Feb 09 21:43:35 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_http.c	Sat Feb 10 20:01:54 2007 +0000
     1.3 @@ -129,20 +129,23 @@
     1.4  	int i;
     1.5  	epg->channelList = NULL;
     1.6  
     1.7 -	for (i=1; i <= epg->numOfChannels; i++)
     1.8 -	{
     1.9 -		GMythChannel* channel = (GMythChannel*)g_malloc(sizeof(struct _GMythChannel));
    1.10 -		
    1.11 -		channel->channelName = g_string_new((char *)xmlGetProp(node, (xmlChar *)"channelName"));
    1.12 -		channel->chanNum = g_string_new((char *)xmlGetProp(node, (xmlChar *)"chanNum"));
    1.13 +    if (node != NULL) {
    1.14  
    1.15 -		sscanf ((char *)xmlGetProp(node, (xmlChar *)"chanId"), "%d", &(channel->chanId));
    1.16 -		sscanf ((char *)xmlGetProp(node, (xmlChar *)"callSign"), "%d", &(channel->callSign));
    1.17 -
    1.18 -		channel->programList = get_Program_List(node->children);
    1.19 -
    1.20 -		epg->channelList = g_slist_append(epg->channelList, channel);
    1.21 -	}
    1.22 +      for (i=1; i <= epg->numOfChannels; i++)
    1.23 +        {
    1.24 +          GMythChannel* channel = (GMythChannel*)g_malloc(sizeof(struct _GMythChannel));
    1.25 +          
    1.26 +          channel->channelName = g_string_new((char *)xmlGetProp(node, (xmlChar *)"channelName"));
    1.27 +          channel->chanNum = g_string_new((char *)xmlGetProp(node, (xmlChar *)"chanNum"));
    1.28 +          
    1.29 +          sscanf ((char *)xmlGetProp(node, (xmlChar *)"chanId"), "%d", &(channel->chanId));
    1.30 +          sscanf ((char *)xmlGetProp(node, (xmlChar *)"callSign"), "%d", &(channel->callSign));
    1.31 +          
    1.32 +          channel->programList = get_Program_List(node->children);
    1.33 +          
    1.34 +          epg->channelList = g_slist_append(epg->channelList, channel);
    1.35 +        }
    1.36 +    }
    1.37  }
    1.38  
    1.39  /** Retrieves the properties from the ProgramGuide
    1.40 @@ -169,7 +172,10 @@
    1.41  	sscanf ((char *)xmlGetProp(nodeTab, (xmlChar *)"details"), "%d", &(epg->details));
    1.42  
    1.43  	// go to Channel section and retrieve Channels and Programs
    1.44 -	get_Channel_List(nodeTab->children->next->children->next, epg);
    1.45 +    if ( epg->numOfChannels > 0 )
    1.46 +      get_Channel_List(nodeTab->children->next->children->next, epg);
    1.47 +    else
    1.48 +      epg->channelList = NULL;
    1.49  }
    1.50  
    1.51  /** Aux function to retrieve the Eletronic Program Guide
    1.52 @@ -200,6 +206,50 @@
    1.53  
    1.54  }
    1.55  
    1.56 +
    1.57 +gchar* gmyth_http_retrieve_setting (GMythBackendInfo *backend_info,\
    1.58 +                                  gchar* key, gchar* hostname)
    1.59 +{
    1.60 +    xmlXPathObjectPtr result;
    1.61 +    xmlNodeSetPtr nodeset;
    1.62 +    xmlChar *keyword;
    1.63 +    MemoryStruct chunk;
    1.64 +    gchar* value = NULL;
    1.65 +
    1.66 +    chunk.memory = NULL;
    1.67 +    chunk.size = 0;
    1.68 +
    1.69 +    GString* command = g_string_new("");
    1.70 +    g_string_printf(command, "getSetting?Key=%s&HostName=%s&Default=NULL", \
    1.71 +                    key, hostname);
    1.72 +
    1.73 +    chunk = gmyth_http_request(backend_info, command);
    1.74 +
    1.75 +    if (chunk.memory != NULL)
    1.76 +    {
    1.77 +      xmlDocPtr doc = XMLParse(chunk.memory, strlen(chunk.memory));
    1.78 +
    1.79 +      result = getXPath((xmlChar *)"/*", doc);
    1.80 +
    1.81 +      if (result)
    1.82 +      {
    1.83 +        nodeset = result->nodesetval;
    1.84 +        keyword = (xmlChar*)nodeset->nodeTab[0]->name;
    1.85 +        if (g_ascii_strcasecmp((char *)keyword, "Value") == 0)
    1.86 +        {
    1.87 +          // Here we have the value
    1.88 +          value = (gchar*)nodeset->nodeTab[0]->children->content;
    1.89 +        }
    1.90 +        xmlXPathFreeObject (result);
    1.91 +      }
    1.92 +
    1.93 +      free(chunk.memory);
    1.94 +    }
    1.95 +
    1.96 +    return value;
    1.97 +}
    1.98 +
    1.99 +
   1.100  /** Retrieves the Eletronic Program Guide from the backend
   1.101   *
   1.102   * @param doc An XML document (xmlDocPtr)
   1.103 @@ -294,6 +344,8 @@
   1.104      return command;
   1.105  }
   1.106  
   1.107 +
   1.108 +
   1.109  /** Send HTTP Command and receives the result of it
   1.110   *
   1.111   * @return A string with the response from the server
     2.1 --- a/gmyth/src/gmyth_http.h	Fri Feb 09 21:43:35 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_http.h	Sat Feb 10 20:01:54 2007 +0000
     2.3 @@ -95,7 +95,13 @@
     2.4  	GSList* channelList;
     2.5  };
     2.6  
     2.7 -GMythEpg retrieve_epg(GMythBackendInfo *backend_info, int port, GTimeVal* StartTime, GTimeVal* EndTime, gint StartChanId, gint NumOfChannels, gchar* Details);
     2.8 +gchar* gmyth_http_retrieve_setting (GMythBackendInfo *backend_info,\
     2.9 +                                  gchar* key, gchar* hostname);
    2.10 +
    2.11 +GMythEpg retrieve_epg(GMythBackendInfo *backend_info, int port,\
    2.12 +                      GTimeVal* StartTime, GTimeVal* EndTime, \
    2.13 +                      gint StartChanId, gint NumOfChannels, gchar* Details);
    2.14 +
    2.15  MemoryStruct gmyth_http_request (GMythBackendInfo *backend_info, GString *command);
    2.16  
    2.17  G_END_DECLS
     3.1 --- a/gmyth/src/gmyth_util.c	Fri Feb 09 21:43:35 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_util.c	Sat Feb 10 20:01:54 2007 +0000
     3.3 @@ -332,46 +332,50 @@
     3.4  	struct tm* tm_time = NULL;
     3.5  	time_t time_micros;
     3.6  	gchar* result;
     3.7 -
     3.8 +    
     3.9  	gmyth_debug( "[%s] time_str = %s. [%s]", time_str, time_str != NULL ? 
    3.10 -					time_str : "[time string is NULL!]", time_str );
    3.11 -
    3.12 +                 time_str : "[time string is NULL!]", time_str );
    3.13 +    
    3.14  	if ( NULL == time_str ) 
    3.15 -	{ 
    3.16 +      { 
    3.17  		g_warning ("GMythUtil: isoformat_to_time converter error!\n");
    3.18  		return NULL;
    3.19 -	}
    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 +    
    3.27  	/* we first check the return of strftime to allocate a buffer of the correct size */
    3.28 -  result = strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time );
    3.29 -  if ( NULL == result ) {
    3.30 -		/* we first check the return of strftime to allocate a buffer of the correct size */
    3.31 +    result = strptime( time_str, "%Y-%m-%dT%H:%M:%S", tm_time );
    3.32 +    if ( NULL == result ) {
    3.33 +      /* we first check the return of strftime to allocate a buffer of the correct size */
    3.34  	  result = strptime( time_str, "%Y-%m-%dT%H:%M:%SZ", tm_time );
    3.35  	  if ( NULL == result ) {
    3.36  	  	/* we first check the return of strftime to allocate a buffer of the correct size */
    3.37 -		  result = strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time );
    3.38 -		  if ( NULL == result ) {
    3.39 -		  	g_static_mutex_unlock ( &mutex );
    3.40 -		    gmyth_debug( "Dateline (ISO result): %s", result );
    3.41 -		    time = NULL;
    3.42 -		    //goto done;	    
    3.43 -		  }
    3.44 +        result = strptime( time_str, "%Y-%m-%d %H:%M:%S", tm_time );
    3.45 +        if ( NULL == result) {
    3.46 +          result = strptime( time_str, "%Y-%m-%dT%H:%M", tm_time );
    3.47 +          if ( NULL == result ) {
    3.48 +            g_static_mutex_unlock ( &mutex );
    3.49 +            gmyth_debug( "Dateline (ISO result): %s", result );
    3.50 +            g_free(tm_time);
    3.51 +            return NULL;
    3.52 +            //goto done;	    
    3.53 +          }
    3.54 +        }
    3.55  	  }
    3.56 -  }
    3.57 -  
    3.58 -  time_micros = mktime( tm_time );
    3.59 -		
    3.60 -	time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC );
    3.61 -	
    3.62 -	gmyth_debug( "After mktime call... = %s", asctime(tm_time) );
    3.63 -
    3.64 -	g_static_mutex_unlock ( &mutex );
    3.65 -
    3.66 -	return time;
    3.67 +    }
    3.68 +    
    3.69 +    time_micros = mktime( tm_time );
    3.70 +    
    3.71 +    time->tv_sec = time_micros; // + (gint)( time_val->tv_usec / G_USEC_PER_SEC );
    3.72 +    
    3.73 +    gmyth_debug( "After mktime call... = %s", asctime(tm_time) );
    3.74 +    
    3.75 +    g_static_mutex_unlock ( &mutex );
    3.76 +    
    3.77 +    return time;
    3.78  }
    3.79  
    3.80  /** Converts a GString in the following format 
     4.1 --- a/gmyth/src/gmyth_vlc.c	Fri Feb 09 21:43:35 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_vlc.c	Sat Feb 10 20:01:54 2007 +0000
     4.3 @@ -209,7 +209,7 @@
     4.4   * @return 0 if success
     4.5   */
     4.6  int gmyth_vlc_connect(GMythVlc *vlc, GMythBackendInfo *backend_info,\
     4.7 -                      gchar* passwd)
     4.8 +                      gchar* passwd, int port)
     4.9  {
    4.10      int numbytes;  
    4.11      
    4.12 @@ -227,7 +227,7 @@
    4.13        
    4.14      // Socket properties
    4.15      vlc->their_addr.sin_family = AF_INET; 
    4.16 -    vlc->their_addr.sin_port = htons(VLC_TELNET_PORT); 
    4.17 +    vlc->their_addr.sin_port = htons(port); 
    4.18      vlc->their_addr.sin_addr = *((struct in_addr *)vlc->he->h_addr);
    4.19      memset(&(vlc->their_addr.sin_zero), '\0', 8);
    4.20      
     5.1 --- a/gmyth/src/gmyth_vlc.h	Fri Feb 09 21:43:35 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_vlc.h	Sat Feb 10 20:01:54 2007 +0000
     5.3 @@ -1,7 +1,7 @@
     5.4  /**
     5.5   * GMyth Library
     5.6   *
     5.7 - * @file gmyth/gmyth_vlc.c
     5.8 + * @file gmyth/gmyth_vlc.h
     5.9   * 
    5.10   * @brief <p> GMythVLC library provides functions that
    5.11   * interact with a VLC server running telnet interface.
    5.12 @@ -88,7 +88,7 @@
    5.13                               int port);
    5.14  
    5.15  int gmyth_vlc_connect(GMythVlc *vlc, GMythBackendInfo *backend_info,\
    5.16 -                      gchar* passwd);
    5.17 +                      gchar* passwd, int port);
    5.18  
    5.19  int gmyth_vlc_disconnect(GMythVlc *vlc);
    5.20  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/gmyth/tests/compile_test_http	Sat Feb 10 20:01:54 2007 +0000
     6.3 @@ -0,0 +1,2 @@
     6.4 +gcc -g -o http gmyth_test_http.c `pkg-config --cflags --libs gmyth-0.1`
     6.5 +
     7.1 --- a/gmyth/tests/gmyth_test_vlc.c	Fri Feb 09 21:43:35 2007 +0000
     7.2 +++ b/gmyth/tests/gmyth_test_vlc.c	Sat Feb 10 20:01:54 2007 +0000
     7.3 @@ -18,11 +18,18 @@
     7.4      gmyth_backend_info_set_hostname (backend_info, "192.168.3.137");
     7.5      gmyth_backend_info_set_port (backend_info, 6543);
     7.6      
     7.7 -    gmyth_vlc_connect(&vlc, backend_info, "admin");
     7.8 -    gmyth_vlc_create_channel(&vlc, "broadcast", 8080);
     7.9 -    gmyth_vlc_create_input(&vlc, 0, "/tmp/grande.nuv");
    7.10 -    gmyth_vlc_control_input(&vlc, 0, "play");
    7.11 -    gmyth_vlc_disconnect(&vlc);
    7.12 +    int res = gmyth_vlc_connect(&vlc, backend_info, "admin", 4212);
    7.13 +    
    7.14 +    if ( res >= 0 )
    7.15 +    {
    7.16 +    	gmyth_vlc_create_channel(&vlc, "broadcast", 8080);
    7.17 +        gmyth_vlc_create_input(&vlc, 0, "/tmp/grande.nuv");
    7.18 +        gmyth_vlc_control_input(&vlc, 0, "play");
    7.19 +        gmyth_vlc_disconnect(&vlc);
    7.20 +    }
    7.21 +
    7.22 +    //gchar* teste = gmyth_http_retrieve_setting(backend_info, "RecordFilePrefix", "hmelo-desktop");
    7.23 +
    7.24  
    7.25      return 0;    
    7.26  }