[vlc-devel] commit: RAM: use decode_URI(), not FromLocale(). Untested. ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon Jun 29 22:31:36 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 29 23:29:14 2009 +0300| [facce14d97f2d65e890ddac7ba0b4313dde817bf] | committer: Rémi Denis-Courmont 

RAM: use decode_URI(), not FromLocale(). Untested.

Also try to fix a few leaks (but meta handling still seems suspicious).

P.S.: That sort of things should be obvious.
Please don't commit such crap without reviewing.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=facce14d97f2d65e890ddac7ba0b4313dde817bf
---

 modules/demux/playlist/ram.c |   95 ++++++++++++-----------------------------
 1 files changed, 28 insertions(+), 67 deletions(-)

diff --git a/modules/demux/playlist/ram.c b/modules/demux/playlist/ram.c
index aad3b04..b6c0567 100644
--- a/modules/demux/playlist/ram.c
+++ b/modules/demux/playlist/ram.c
@@ -49,7 +49,7 @@ http://service.real.com/help/library/guides/realone/IntroGuide/HTML/htmfiles/ram
 
 #include <vlc_common.h>
 #include <vlc_demux.h>
-#include <vlc_charset.h>
+#include <vlc_url.h>
 
 #include <ctype.h>
 
@@ -101,34 +101,6 @@ void Close_RAM( vlc_object_t *p_this )
 }
 
 /**
- * Returns a UTF8 encoded version of the string
- * @param str: input string
- * @return pointer to UTF8 string
- */
-static inline char *MaybeFromLocaleDup (const char *str)
-{
-    if (str == NULL)
-        return NULL;
-
-    return IsUTF8 (str) ? strdup (str) : FromLocaleDup (str);
-}
-
-/**
- * Converts a string to UTF8 encoding
- * @param str: input string
- */
-static inline void MaybeFromLocaleRep (char **str)
-{
-    char *const orig_str = *str;
-
-    if ((orig_str != NULL) && !IsUTF8 (orig_str))
-    {
-        *str = FromLocaleDup (orig_str);
-        free (orig_str);
-    }
-}
-
-/**
  * Skips blanks in a given buffer
  * @param s: input string
  * @param i_strlen: length of the buffer
@@ -260,52 +232,47 @@ static int Demux( demux_t *p_demux )
         }
         else if( *psz_parse )
         {
-            char *psz_mrl, *psz_option_start, *psz_option_next, *psz_temp_mrl, *psz_option;
+            char *psz_mrl, *psz_option_next, *psz_option;
             char *psz_param, *psz_value;
 
             /* Get the MRL from the file. Note that this might contain parameters of form ?param1=value1&param2=value2 in a RAM file */
             psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix );
-            MaybeFromLocaleRep( &psz_mrl );
 
             b_cleanup = true;
             if ( !psz_mrl ) goto error;
 
             /* We have the MRL, now we have to check for options and parse them from MRL */
-            psz_temp_mrl = strdup( psz_mrl );
-            psz_option_start = strchr( psz_temp_mrl, '?' ); /* Look for start of options */
-            if( psz_option_start )
+            psz_option = strchr( psz_mrl, '?' ); /* Look for start of options */
+            if( psz_option )
             {
-                psz_option_start++;
-                psz_option_next = psz_option_start;
+                /* Remove options from MRL
+                   because VLC can't get the file otherwise */
+                *psz_option = '\0';
+                psz_option++;
+                psz_option_next = psz_option;
                 while( 1 ) /* Process each option */
                 {
                     /* Look for end of first option which maybe a & or \0 */
-                    psz_option_start = psz_option_next;
-                    psz_option_next = strchr( psz_option_start, '&' );
+                    psz_option = psz_option_next;
+                    psz_option_next = strchr( psz_option, '&' );
                     if( psz_option_next )
                     {
                         *psz_option_next = '\0';
                         psz_option_next++;
                     }
                     else
-                        psz_option_next = strchr( psz_option_start, '\0' );
+                        psz_option_next = strchr( psz_option, '\0' );
                     /* Quit if options are over */
-                    if( psz_option_next == psz_option_start )
+                    if( psz_option_next == psz_option )
                         break;
-                    psz_option = MaybeFromLocaleDup( psz_option_start );
-                    /* If this option is screwed up, try the next one */
-                    if( !psz_option )
-                        continue;
 
                     /* Parse out param and value */
                     psz_param = psz_option;
-                    if( strchr( psz_option, '=' ) )
-                    {
-                        psz_value = strchr( psz_option, '=' ) + 1;
-                        *(strchr( psz_option, '=' )) = '\0';
-                    }
-                    else
+                    psz_value = strchr( psz_option, '=' );
+                    if( psz_value == NULL )
                         break;
+                    *psz_value = '\0';
+                    psz_value++;
 
                     /* Take action based on parameter value in the below if else structure */
                     /* TODO: Remove any quotes surrounding values if required */
@@ -316,7 +283,7 @@ static int Demux( demux_t *p_demux )
                            &psz_cdnum, &psz_comments ); /* clipinfo has various sub parameters, which is parsed by this function */
                     }
                     else if( !strcmp( psz_param, "author" ) )
-                        psz_author = strdup(psz_value);
+                        psz_author = decode_URI(psz_value);
                     else if( !strcmp( psz_param, "start" ) )
                     {
                         i_start = ParseTime( psz_value, strlen( psz_value ) );
@@ -338,22 +305,16 @@ static int Demux( demux_t *p_demux )
                         }
                     }
                     else if( !strcmp( psz_param, "title" ) )
-                        psz_title = strdup(psz_value);
+                        psz_title = decode_URI(psz_value);
                     else if( !strcmp( psz_param, "copyright" ) )
-                        psz_copyright = strdup(psz_value);
+                        psz_copyright = decode_URI(psz_value);
                     else
                     {   /* TODO: insert option anyway? Currently ignores*/
                         /* INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); */
                     }
-
-                    free( psz_option );
                 }
-
-                *(strchr( psz_mrl, '?' )) = '\0'; /* Remove options from MRL because VLC can't get the file otherwise */
             }
 
-            free( psz_temp_mrl );
-
             /* Create the input item and pump in all the options into playlist item */
             p_input = input_item_NewExt( p_demux, psz_mrl, psz_title, i_options, ppsz_options, 0, i_duration );
 
@@ -458,7 +419,7 @@ static void ParseClipInfo( const char *psz_clipinfo, char **ppsz_artist, char **
         if( psz_option_next == psz_option_start )
             break;
 
-        psz_suboption = MaybeFromLocaleDup( psz_option_start );
+        psz_suboption = strdup( psz_option_start );
         if( !psz_suboption )
             break;
 
@@ -473,19 +434,19 @@ static void ParseClipInfo( const char *psz_clipinfo, char **ppsz_artist, char **
             break;
         /* Put into args */
         if( !strcmp( psz_param, "artist name" ) )
-            *ppsz_artist = strdup( psz_value );
+            *ppsz_artist = decode_URI( psz_value );
         else if( !strcmp( psz_param, "title" ) )
-            *ppsz_title = strdup( psz_value );
+            *ppsz_title = decode_URI( psz_value );
         else if( !strcmp( psz_param, "album name" ) )
-            *ppsz_album = strdup( psz_value );
+            *ppsz_album = decode_URI( psz_value );
         else if( !strcmp( psz_param, "genre" ) )
-            *ppsz_genre = strdup( psz_value );
+            *ppsz_genre = decode_URI( psz_value );
         else if( !strcmp( psz_param, "year" ) )
-            *ppsz_year = strdup( psz_value );
+            *ppsz_year = decode_URI( psz_value );
         else if( !strcmp( psz_param, "cdnum" ) )
-            *ppsz_cdnum = strdup( psz_value );
+            *ppsz_cdnum = decode_URI( psz_value );
         else if( !strcmp( psz_param, "comments" ) )
-            *ppsz_comments = strdup( psz_value );
+            *ppsz_comments = decode_URI( psz_value );
 
         free( psz_suboption );
         psz_option_next++;




More information about the vlc-devel mailing list