[vlc-commits] [Git][videolan/vlc][master] 8 commits: demux: require :// in MRL

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Sep 16 20:00:27 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
bf1ba89a by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
demux: require :// in MRL

Otherwise, creating the demux won't work anyway.
This is consistent with the current behaviour of access_New().

- - - - -
904c9c9d by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
url: handle proprietary dir:// MRL scheme

- - - - -
e124481d by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
access: use vlc_uri2path() directly

- - - - -
1b69f64b by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
demux: use vlc_uri2path() directly

- - - - -
23641449 by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
input: call vlc_uri2path() directly

...and skip redundant reverse conversion w/ vlc_path2uri().

- - - - -
cd661572 by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
input: remove no longer used get_path()

- - - - -
c14e2032 by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
input: pass full MRL to InputGetExtraFiles*()

- - - - -
b3be9953 by Rémi Denis-Courmont at 2021-09-16T19:32:34+00:00
input: avoid one strdup()

- - - - -


5 changed files:

- src/input/access.c
- src/input/demux.c
- src/input/input.c
- src/input/stream.h
- src/text/url.c


Changes:

=====================================
src/input/access.c
=====================================
@@ -47,22 +47,6 @@ struct vlc_access_stream_private
     input_thread_t *input;
 };
 
-/* Decode URL (which has had its scheme stripped earlier) to a file path. */
-char *get_path(const char *location)
-{
-    char *url, *path;
-
-    /* Prepending "file://" is a bit hackish. But then again, we do not want
-     * to hard-code the list of schemes that use file paths in vlc_uri2path().
-     */
-    if (asprintf(&url, "file://%s", location) == -1)
-        return NULL;
-
-    path = vlc_uri2path (url);
-    free (url);
-    return path;
-}
-
 static void vlc_access_Destroy(stream_t *access)
 {
     struct vlc_access_private *priv = vlc_stream_Private(access);
@@ -142,7 +126,7 @@ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input,
             goto error;
 
         access->psz_location = p + 3;
-        access->psz_filepath = get_path(access->psz_location);
+        access->psz_filepath = vlc_uri2path(url);
         if (access->psz_filepath != NULL)
             msg_Dbg(access, " (path: %s)", access->psz_filepath);
 


=====================================
src/input/demux.c
=====================================
@@ -118,6 +118,12 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_input,
                             const char *module, const char *url,
                             stream_t *s, es_out_t *out, bool b_preparsing )
 {
+    const char *p = strstr(url, "://");
+    if (p == NULL) {
+        errno = EINVAL;
+        return NULL;
+    }
+
     struct vlc_demux_private *priv;
     demux_t *p_demux = vlc_stream_CustomNew(p_obj, demux_DestroyDemux,
                                             sizeof (*priv), "demux");
@@ -137,9 +143,8 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_input,
     if (unlikely(p_demux->psz_url == NULL))
         goto error;
 
-    const char *p = strstr(p_demux->psz_url, "://");
-    p_demux->psz_location = (p != NULL) ? (p + 3) : "";
-    p_demux->psz_filepath = get_path(p_demux->psz_location); /* parse URL */
+    p_demux->psz_location = p_demux->psz_url + 3 + (p - url);
+    p_demux->psz_filepath = vlc_uri2path(url); /* parse URL */
 
     if( !b_preparsing )
         msg_Dbg( p_obj, "creating demux \"%s\", URL: %s, path: %s",


=====================================
src/input/input.c
=====================================
@@ -104,7 +104,7 @@ static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta );
 static void InputUpdateMeta( input_thread_t *p_input, demux_t *p_demux );
 static void InputGetExtraFiles( input_thread_t *p_input,
                                 int *pi_list, char ***pppsz_list,
-                                const char **psz_access, const char *psz_path );
+                                const char **psz_access, const char *mrl );
 
 static void AppendAttachment(input_thread_t* p_input,
                               int i_new, input_attachment_t **pp_new);
@@ -2683,7 +2683,7 @@ static int InputSourceInit( input_source_t *in, input_thread_t *p_input,
         char **tab;
 
         TAB_INIT( count, tab );
-        InputGetExtraFiles( p_input, &count, &tab, &psz_access, psz_path );
+        InputGetExtraFiles( p_input, &count, &tab, &psz_access, psz_mrl );
         if( count > 0 )
         {
             char *list = NULL;
@@ -3159,7 +3159,7 @@ static void InputUpdateMeta( input_thread_t *p_input, demux_t *p_demux )
  *****************************************************************************/
 static void InputGetExtraFilesPattern( input_thread_t *p_input,
                                        int *pi_list, char ***pppsz_list,
-                                       const char *psz_path,
+                                       const char *uri,
                                        const char *psz_match,
                                        const char *psz_format,
                                        int i_start, int i_stop )
@@ -3168,43 +3168,33 @@ static void InputGetExtraFilesPattern( input_thread_t *p_input,
     char **ppsz_list;
     TAB_INIT( i_list, ppsz_list );
 
-    char *psz_base = strdup( psz_path );
-    if( !psz_base )
-        goto exit;
-
     /* Remove the extension */
-    char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
-    assert( psz_end >= psz_base);
-    *psz_end = '\0';
+    size_t end = strlen(uri) - strlen(psz_match);
+    if (unlikely(end > INT_MAX))
+        goto exit;
 
     /* Try to list files */
     for( int i = i_start; i <= i_stop; i++ )
     {
-        char *psz_probe;
-        if( asprintf( &psz_probe, psz_format, psz_base, i ) < 0 )
+        char *url;
+        if( asprintf( &url, psz_format, (int)end, uri, i ) < 0 )
             break;
 
-        char *filepath = get_path( psz_probe );
+        char *filepath = vlc_uri2path(url);
 
         struct stat st;
         if( filepath == NULL ||
             vlc_stat( filepath, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
         {
             free( filepath );
-            free( psz_probe );
+            free( url );
             break;
         }
 
         msg_Dbg( p_input, "Detected extra file `%s'", filepath );
-
-        char* psz_uri = vlc_path2uri( filepath, NULL );
-        if( psz_uri )
-            TAB_APPEND( i_list, ppsz_list, psz_uri );
-
         free( filepath );
-        free( psz_probe );
+        TAB_APPEND( i_list, ppsz_list, url );
     }
-    free( psz_base );
 exit:
     *pi_list = i_list;
     *pppsz_list = ppsz_list;
@@ -3212,7 +3202,7 @@ exit:
 
 static void InputGetExtraFiles( input_thread_t *p_input,
                                 int *pi_list, char ***pppsz_list,
-                                const char **ppsz_access, const char *psz_path )
+                                const char **ppsz_access, const char *mrl )
 {
     static const struct pattern
     {
@@ -3223,20 +3213,21 @@ static void InputGetExtraFiles( input_thread_t *p_input,
         int i_stop;
     } patterns[] = {
         /* XXX the order is important */
-        { "concat", ".001", "%s.%.3d", 2, 999 },
-        { NULL, ".part1.rar","%s.part%.1d.rar", 2, 9 },
-        { NULL, ".part01.rar","%s.part%.2d.rar", 2, 99, },
-        { NULL, ".part001.rar", "%s.part%.3d.rar", 2, 999 },
-        { NULL, ".rar", "%s.r%.2d", 0, 99 },
-        { "concat", ".mts", "%s.mts%d", 1, 999 },
+        { "concat", ".001", "%.*s.%.3d", 2, 999 },
+        { NULL, ".part1.rar","%.*s.part%.1d.rar", 2, 9 },
+        { NULL, ".part01.rar","%.*s.part%.2d.rar", 2, 99, },
+        { NULL, ".part001.rar", "%.*s.part%.3d.rar", 2, 999 },
+        { NULL, ".rar", "%.*s.r%.2d", 0, 99 },
+        { "concat", ".mts", "%.*s.mts%d", 1, 999 },
     };
 
+    assert(mrl != NULL);
     TAB_INIT( *pi_list, *pppsz_list );
 
-    if( ( **ppsz_access && strcmp( *ppsz_access, "file" ) ) || !psz_path )
+    if( **ppsz_access && strcmp( *ppsz_access, "file" ) )
         return;
 
-    const size_t i_path = strlen(psz_path);
+    const size_t i_path = strlen(mrl);
 
     for( size_t i = 0; i < ARRAY_SIZE( patterns ); ++i )
     {
@@ -3246,9 +3237,9 @@ static void InputGetExtraFiles( input_thread_t *p_input,
         if( i_path < i_ext )
             continue;
 
-        if( !strcmp( &psz_path[i_path-i_ext], pat->psz_match ) )
+        if( !strcmp( &mrl[i_path-i_ext], pat->psz_match ) )
         {
-            InputGetExtraFilesPattern( p_input, pi_list, pppsz_list, psz_path,
+            InputGetExtraFilesPattern( p_input, pi_list, pppsz_list, mrl,
                 pat->psz_match, pat->psz_format, pat->i_start, pat->i_stop );
 
             if( *pi_list > 0 && pat->psz_access_force )


=====================================
src/input/stream.h
=====================================
@@ -120,6 +120,4 @@ stream_t *stream_FilterChainNew( stream_t *source, const char *list ) VLC_USED;
 int stream_extractor_AttachParsed( stream_t** stream, const char* psz_data,
                                    char const** out_extra );
 
-char *get_path(const char *location);
-
 #endif


=====================================
src/text/url.c
=====================================
@@ -266,7 +266,8 @@ char *vlc_uri2path (const char *url)
     /* Decode path */
     vlc_uri_decode (path);
 
-    if (schemelen == 4 && !strncasecmp (url, "file", 4))
+    if ((schemelen == 4 && !strncasecmp(url, "file", 4))
+     || (schemelen == 3 && !strncasecmp(url, "dir", 3)))
     {
 #if !defined (_WIN32) && !defined (__OS2__)
         /* Leading slash => local path */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5d9fae860b1bbe1e202089be40f87ed55a3ea4dc...b3be9953d3cbadc74c7fb57f5828a34f50e8733c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5d9fae860b1bbe1e202089be40f87ed55a3ea4dc...b3be9953d3cbadc74c7fb57f5828a34f50e8733c
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list