[vlc-devel] [PATCH] Fix a segfault in the VLM command parser and add a new functionality.

Adrien Maglo magsoft at videolan.org
Wed Jul 30 13:56:22 CEST 2008


--> Segfault :
It occured when you gived a command to the VLM as :
> new test schedule date 18:00:00
( Even if this seemed be supported in the code, it segfaulted ! )

--> New functionality :
You can now replace elements in the date by a '*' and it will remplace them by the value of the same element in the current date and time.
So, for instance you can use command as :
> new test schedule date */*/*-18:00:00
And the date will be translated by 2008/7/30-18:00:00 if today, we are the 30th of July ...
---
 src/input/vlmshell.c |   99 ++++++++++++++++++++++++++++----------------------
 1 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/src/input/vlmshell.c b/src/input/vlmshell.c
index 90c59d9..c5b381c 100644
--- a/src/input/vlmshell.c
+++ b/src/input/vlmshell.c
@@ -1036,7 +1036,6 @@ static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
     else if( !strcmp( psz_cmd, "date" ) )
     {
         struct tm time;
-        const char *p;
         time_t date;
 
         time.tm_sec = 0;         /* seconds */
@@ -1049,58 +1048,72 @@ static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
         time.tm_yday = 0;        /* day in the year */
         time.tm_isdst = -1;       /* daylight saving time */
 
-        /* date should be year/month/day-hour:minutes:seconds */
-        p = strchr( psz_value, '-' );
-
         if( !strcmp( psz_value, "now" ) )
         {
             schedule->i_date = 0;
         }
-        else if( (p == NULL) && sscanf( psz_value, "%d:%d:%d", &time.tm_hour,
-                                        &time.tm_min, &time.tm_sec ) != 3 )
-                                        /* it must be a hour:minutes:seconds */
-        {
-            return 1;
-        }
         else
         {
-            unsigned i,j,k;
+             /* date should be year/month/day-hour:minutes:seconds */ 
+            unsigned int i_year, i_month, i_day, i_hour, i_min, i_sec; 
+            char *psz_year, *psz_month, *psz_day, *psz_hour,
+                *psz_min, *psz_sec;
 
-            switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
-            {
-                case 1:
-                    time.tm_sec = i;
-                    break;
-                case 2:
-                    time.tm_min = i;
-                    time.tm_sec = j;
-                    break;
-                case 3:
-                    time.tm_hour = i;
-                    time.tm_min = j;
-                    time.tm_sec = k;
-                    break;
-                default:
-                    return 1;
-            }
+            struct tm *local_tm;
+            time_t local_time_t = (time_t)( vlm_Date() / 1000000 );
 
-            switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
+            local_tm = localtime( &local_time_t );
+
+            if ( sscanf( psz_value, "%a[^/]/%a[^/]/%a[^-]-%a[^:]:%a[^:]:%as",
+                  &psz_year, &psz_month, &psz_day, &psz_hour,
+                  &psz_min, &psz_sec ) == 6 )
             {
-                case 1:
-                    time.tm_mday = i;
-                    break;
-                case 2:
-                    time.tm_mon = i - 1;
-                    time.tm_mday = j;
-                    break;
-                case 3:
-                    time.tm_year = i - 1900;
-                    time.tm_mon = j - 1;
-                    time.tm_mday = k;
-                    break;
-                default:
-                    return 1;
+                  i_year = atol( psz_year );
+                  i_month = atol( psz_month );
+                  i_day = atol( psz_day );
+                  i_hour = atol( psz_hour );
+                  i_min = atol( psz_min );
+                  i_sec = atol( psz_sec );
+                  
+                  if ( !strcmp( psz_year, "*" ) )
+                        time.tm_year = local_tm->tm_year;
+                  else
+                        time.tm_year = i_year - 1900;
+
+                  if ( !strcmp( psz_month, "*" ) )
+                        time.tm_mon = local_tm->tm_mon;
+                  else
+                        time.tm_mon = i_month - 1;
+
+                  if ( !strcmp( psz_day, "*" ) )
+                        time.tm_mday = local_tm->tm_mday;
+                  else
+                        time.tm_mday = i_day;
+
+                  if ( !strcmp( psz_hour, "*" ) )
+                        time.tm_hour = local_tm->tm_hour;
+                  else
+                        time.tm_hour = i_hour;
+
+                  if ( !strcmp( psz_min, "*" ) )
+                        time.tm_min = local_tm->tm_min;
+                  else
+                        time.tm_min = i_min;
+
+                  if ( !strcmp( psz_sec, "*" ) )
+                        time.tm_sec = local_tm->tm_sec;
+                  else
+                        time.tm_sec = i_sec;
+
+                  free( psz_year );
+                  free( psz_month );
+                  free( psz_day );
+                  free( psz_hour );
+                  free( psz_min );
+                  free( psz_sec );
             }
+            else
+                   return 1;
 
             date = mktime( &time );
             schedule->i_date = ((mtime_t) date) * 1000000;
-- 
1.5.4.3




More information about the vlc-devel mailing list