stream: fold psz_access and psz_path into psz_url
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 26 Jul 2015 10:47:54 +0000 (13:47 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 26 Jul 2015 12:38:20 +0000 (15:38 +0300)
15 files changed:
include/vlc_stream.h
modules/access/archive/stream.c
modules/access/rar/rar.c
modules/access/rar/stream.c
modules/access/zip/zipstream.c
modules/demux/adaptative/playlist/AbstractPlaylist.cpp
modules/demux/image.c
modules/stream_filter/hds/hds.c
modules/stream_filter/smooth/smooth.c
src/input/input.c
src/input/stream.c
src/input/stream_access.c
src/input/stream_demux.c
src/input/stream_filter.c
src/input/stream_memory.c

index 9beb49c..ac242c5 100644 (file)
@@ -51,9 +51,7 @@ struct stream_t
     /* Module properties for stream filter */
     module_t    *p_module;
 
-    char        *psz_access;
-    /* Real or virtual path (it can only be changed during stream_t opening) */
-    char        *psz_path;
+    char        *psz_url;
 
     /* Stream source for stream filter */
     stream_t *p_source;
index 32a48e9..8eb0607 100644 (file)
@@ -142,8 +142,8 @@ static input_item_t *Browse(stream_t *p_stream)
     {
         char *psz_uri = NULL;
         char *psz_access_uri = NULL;
-        int i_ret = asprintf(&psz_access_uri, "%s://%s%c%s", p_stream->psz_access,
-                             p_stream->psz_path, ARCHIVE_SEP_CHAR, archive_entry_pathname(p_entry));
+        int i_ret = asprintf(&psz_access_uri, "%s%c%s", p_stream->psz_url,
+                             ARCHIVE_SEP_CHAR, archive_entry_pathname(p_entry));
         if (i_ret == -1)
             return NULL;
         i_ret = asprintf(&psz_uri, "archive://%s", psz_access_uri);
index bec9576..6ef343a 100644 (file)
@@ -317,12 +317,11 @@ int RarParse(stream_t *s, int *count, rar_file_t ***file, unsigned int *pi_nbvol
     *file = NULL;
     *pi_nbvols = 1;
 
-    const rar_pattern_t *pattern = FindVolumePattern(s->psz_path, b_extonly);
+    const rar_pattern_t *pattern = FindVolumePattern(s->psz_url, b_extonly);
     int volume_offset = 0;
 
-    char *volume_mrl;
-    if (asprintf(&volume_mrl, "%s://%s",
-                 s->psz_access, s->psz_path) < 0)
+    char *volume_mrl = strdup(s->psz_url);
+    if (volume_mrl == NULL)
         return VLC_EGENERIC;
 
     stream_t *vol = s;
@@ -374,10 +373,9 @@ int RarParse(stream_t *s, int *count, rar_file_t ***file, unsigned int *pi_nbvol
         if (volume_index > pattern->stop)
             return VLC_SUCCESS;
 
-        char *volume_base;
-        if (asprintf(&volume_base, "%s://%.*s",
-                     s->psz_access,
-                     (int)(strlen(s->psz_path) - strlen(pattern->match)), s->psz_path) < 0)
+        char *volume_base = strndup(s->psz_url,
+                                  strlen(s->psz_url) - strlen(pattern->match));
+        if (volume_base == NULL)
             return VLC_SUCCESS;
 
         if (pattern->start) {
index 7e5ae7d..ef34f0b 100644 (file)
@@ -104,13 +104,8 @@ int RarStreamOpen(vlc_object_t *object)
      * Reusing WriteXSPF from the zip access is probably a good idea
      * (becareful about '\' and '/'.
      */
-    char *mrl;
-    if (asprintf(&mrl, "%s://%s", s->psz_access, s->psz_path)< 0)
-        mrl = NULL;
     char *base;
-    char *encoded = mrl ? encode_URI_component(mrl) : NULL;
-    free(mrl);
-
+    char *encoded = encode_URI_component(s->psz_url);
     if (!encoded || asprintf(&base, "rar://%s", encoded) < 0)
         base = NULL;
     free(encoded);
@@ -150,12 +145,12 @@ int RarStreamOpen(vlc_object_t *object)
     sys->payload = payload;
 
     char *tmp;
-    if (asprintf(&tmp, "%s.m3u", s->psz_path) < 0) {
+    if (asprintf(&tmp, "%s.m3u", s->psz_url) < 0) {
         RarStreamClose(object);
         return VLC_ENOMEM;
     }
-    free(s->psz_path);
-    s->psz_path = tmp;
+    free(s->psz_url);
+    s->psz_url = tmp;
 
     return VLC_SUCCESS;
 }
index 9920c8c..72aeb5f 100644 (file)
@@ -185,10 +185,7 @@ int StreamOpen( vlc_object_t *p_this )
     p_sys->fileFunctions = ( zlib_filefunc_def * )
             calloc( 1, sizeof( zlib_filefunc_def ) );
     if( !p_sys->fileFunctions )
-    {
-        free( p_sys );
-        return VLC_ENOMEM;
-    }
+        goto error;
     p_sys->fileFunctions->zopen_file   = ZipIO_Open;
     p_sys->fileFunctions->zread_file   = ZipIO_Read;
     p_sys->fileFunctions->zwrite_file  = ZipIO_Write;
@@ -202,23 +199,31 @@ int StreamOpen( vlc_object_t *p_this )
     {
         msg_Warn( s, "unable to open file" );
         free( p_sys->fileFunctions );
-        free( p_sys );
-        return VLC_EGENERIC;
+        goto error;
     }
 
     /* Find the stream uri */
+    const char *p = strstr(s->psz_url, "://");
+    p_sys->psz_path = strdup(p ? p + 3 : "");
+
     char *psz_tmp;
-    if( asprintf( &psz_tmp, "%s.xspf", s->psz_path ) == -1 )
+    if( asprintf( &psz_tmp, "%s.xspf", s->psz_url ) == -1 )
+        psz_tmp = NULL;
+
+    if( p_sys->psz_path == NULL || psz_tmp == NULL )
     {
+        free( psz_tmp );
+        free( p_sys->psz_path );
         free( p_sys->fileFunctions );
-        free( p_sys );
-        return VLC_ENOMEM;
     }
-    p_sys->psz_path = s->psz_path;
-    s->psz_path = psz_tmp;
+    free(s->psz_url);
+    s->psz_url = psz_tmp;
     s->pf_read = Read;
     s->pf_control = Control;
     return VLC_SUCCESS;
+error:
+    free( p_sys );
+    return VLC_ENOMEM;
 }
 
 /** *************************************************************************
index 5e3022e..6153b38 100644 (file)
@@ -78,7 +78,7 @@ Url AbstractPlaylist::getUrlSegment() const
     else
     {
         std::stringstream ss;
-        ss << stream->psz_access << "://" << Helper::getDirectoryPath(stream->psz_path) << "/";
+        ss << Helper::getDirectoryPath(stream->psz_url) << "/";
         return Url(ss.str());
     }
 }
index d8a9d23..5b96605 100644 (file)
@@ -437,7 +437,7 @@ static bool FindSVGmarker(int *position, const uint8_t *data, const int size, co
 
 static bool IsSVG(stream_t *s)
 {
-    char *ext = strstr(s->psz_path, ".svg");
+    char *ext = strstr(s->psz_url, ".svg");
     if (!ext) return false;
 
     const uint8_t *header;
index 961c71f..8f0f21a 100644 (file)
@@ -1631,17 +1631,15 @@ static int Open( vlc_object_t *p_this )
     if( !isHDS( s ) )
         return VLC_EGENERIC;
 
-    msg_Info( p_this, "HTTP Dynamic Streaming (%s)", s->psz_path );
+    msg_Info( p_this, "HTTP Dynamic Streaming (%s)", s->psz_url );
 
     s->p_sys = p_sys = calloc( 1, sizeof(*p_sys ) );
     if( unlikely( p_sys == NULL ) )
         return VLC_ENOMEM;
 
-    char *uri_without_query = NULL;
-    size_t pathlen = strcspn( s->psz_path, "?" );
-    if( unlikely( ( pathlen > INT_MAX ) ||
-        ( asprintf( &uri_without_query, "%s://%.*s", s->psz_access,
-                    (int)pathlen, s->psz_path ) < 0 ) ) )
+    char *uri_without_query = strndup( s->psz_url,
+                                       strcspn( s->psz_url, "?" ) );
+    if( uri_without_query == NULL )
     {
         free( p_sys );
         return VLC_ENOMEM;
index 1b1b8b9..dfac375 100644 (file)
@@ -462,14 +462,14 @@ static int Open( vlc_object_t *p_this )
     if( !isSmoothStreaming( s ) )
         return VLC_EGENERIC;
 
-    msg_Info( p_this, "Smooth Streaming (%s)", s->psz_path );
+    msg_Info( p_this, "Smooth Streaming (%s)", s->psz_url );
 
     s->p_sys = p_sys = calloc( 1, sizeof(*p_sys ) );
     if( unlikely( p_sys == NULL ) )
         return VLC_ENOMEM;
 
-    char *uri = NULL;
-    if( unlikely( asprintf( &uri, "%s://%s", s->psz_access, s->psz_path ) < 0 ) )
+    char *uri = strdup( s->psz_url );
+    if( unlikely( uri == NULL ) )
     {
         free( p_sys );
         return VLC_ENOMEM;
index ff45457..99d8e61 100644 (file)
@@ -2341,10 +2341,14 @@ static int InputSourceInit( input_thread_t *p_input,
             stream_Control( p_stream, STREAM_GET_PTS_DELAY, &i_pts_delay );
         }
 
+        if( p_stream->psz_url != NULL )
+            /* Take access/stream redirections into account: */
+            psz_path = strstr( p_stream->psz_url, "://" );
+        if( psz_path == NULL )
+            psz_path = "";
+
         in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux,
-                   /* Take access/stream redirections into account: */
-                            p_stream->psz_path ? p_stream->psz_path : psz_path,
-                                 p_stream, p_input->p->p_es_out,
+                                 psz_path, p_stream, p_input->p->p_es_out,
                                  p_input->b_preparsing );
 
         if( in->p_demux == NULL )
index e98393c..d08a55c 100644 (file)
@@ -63,8 +63,7 @@ stream_t *stream_CommonNew(vlc_object_t *parent)
 
     stream_t *s = &priv->stream;
 
-    s->psz_access = NULL;
-    s->psz_path = NULL;
+    s->psz_url = NULL;
     priv->peek = NULL;
 
     /* UTF16 and UTF32 text file conversion */
@@ -88,8 +87,7 @@ void stream_CommonDelete( stream_t *s )
     if (priv->peek != NULL)
         block_Release(priv->peek);
 
-    free( s->psz_access );
-    free( s->psz_path );
+    free(s->psz_url);
     vlc_object_release( s );
 }
 
index 74169bb..6d8ca88 100644 (file)
@@ -194,10 +194,11 @@ stream_t *stream_AccessNew( access_t *p_access )
         return NULL;
 
     s->p_input = p_access->p_input;
-    s->psz_access = strdup( p_access->psz_access );
-    s->psz_path = strdup( p_access->psz_location );
+    if( asprintf( &s->psz_url, "%s://%s", p_access->psz_access,
+                  p_access->psz_location ) == -1 )
+        s->psz_url = NULL;
     s->p_sys = p_sys = malloc( sizeof( *p_sys ) );
-    if( !s->psz_access || !s->psz_path || !s->p_sys )
+    if( !s->psz_url || !s->p_sys )
     {
         stream_CommonDelete( s );
         return NULL;
index 484a230..e122cbc 100644 (file)
@@ -74,13 +74,13 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
     if( s == NULL )
         return NULL;
     s->p_input = p_demux->p_input;
-    s->psz_path  = strdup(""); /* N/A */
+    s->psz_url   = strdup(""); /* N/A */
     s->pf_read   = DStreamRead;
     s->pf_control= DStreamControl;
     s->pf_destroy= DStreamDelete;
 
     s->p_sys = p_sys = malloc( sizeof( *p_sys) );
-    if( !s->psz_path || !s->p_sys )
+    if( !s->psz_url || !s->p_sys )
     {
         free( p_sys );
         stream_CommonDelete( s );
index e0ce629..5cb57f7 100644 (file)
@@ -49,9 +49,8 @@ stream_t *stream_FilterNew( stream_t *p_source,
     s->p_input = p_source->p_input;
 
     /* */
-    s->psz_access = strdup( p_source->psz_access );
-    s->psz_path = strdup( p_source->psz_path );
-    if( !s->psz_path )
+    s->psz_url = strdup( p_source->psz_url );
+    if( unlikely(s->psz_url == NULL) )
     {
         stream_CommonDelete( s );
         return NULL;
index 6140398..219a155 100644 (file)
@@ -59,9 +59,9 @@ stream_t *stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
     if( !s )
         return NULL;
 
-    s->psz_path = strdup( "" ); /* N/A */
+    s->psz_url = strdup( "" ); /* N/A */
     s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
-    if( !s->psz_path || !s->p_sys )
+    if( !s->psz_url || !s->p_sys )
     {
         stream_CommonDelete( s );
         free( p_sys );