[vlc-devel] [PATCH] LUA: Remove protocol from vlc.path after redirect

Gaurav Narula gnarula94 at gmail.com
Thu Jan 12 05:53:39 CET 2012


---
 modules/access/http.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/modules/access/http.c b/modules/access/http.c
index 1389810..3bfe64f 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -571,13 +571,13 @@ connect:
 
         /* Do not accept redirection outside of HTTP works */
         const char *psz_protocol;
-        if( !strncmp( p_sys->psz_location, "http:", 5 ) )
+        if( !strcmp( psz_access, "http") )
             psz_protocol = "http";
-        else if( !strncmp( p_sys->psz_location, "https:", 6 ) )
+        else if( !strcmp( psz_access, "https") )
             psz_protocol = "https";
         else
         {
-            msg_Err( p_access, "insecure redirection ignored" );
+            msg_Err( p_access, "Protocol: %s ; insecure redirection ignored", p_access->psz_access );
             goto error;
         }
         free( p_access->psz_location );
@@ -1461,31 +1461,38 @@ static int Request( access_t *p_access, uint64_t i_tell )
         else if( !strcasecmp( psz, "Location" ) )
         {
             char * psz_new_loc;
+            const char *psz_http_ext = p_sys->b_ssl ? "s" : "" ;
+
+            free( p_access->psz_access);            
 
             /* This does not follow RFC 2068, but yet if the url is not absolute,
              * handle it as everyone does. */
             if( p[0] == '/' )
             {
-                const char *psz_http_ext = p_sys->b_ssl ? "s" : "" ;
-
+                if (asprintf(&p_access->psz_access, "http%s", psz_http_ext) < 0)
+                    goto error;
                 if( p_sys->url.i_port == ( p_sys->b_ssl ? 443 : 80 ) )
                 {
-                    if( asprintf(&psz_new_loc, "http%s://%s%s", psz_http_ext,
-                                 p_sys->url.psz_host, p) < 0 )
+                    if( asprintf(&psz_new_loc, "%s%s", p_sys->url.psz_host, p) < 0 )
                         goto error;
                 }
                 else
                 {
-                    if( asprintf(&psz_new_loc, "http%s://%s:%d%s", psz_http_ext,
-                                 p_sys->url.psz_host, p_sys->url.i_port, p) < 0 )
+                    if( asprintf(&psz_new_loc, "%s:%d%s", p_sys->url.psz_host, p_sys->url.i_port, p) < 0 )
                         goto error;
                 }
             }
             else
             {
-                psz_new_loc = strdup( p );
+                const char *slash = strstr(p, "://");
+                if (slash && asprintf(&p_access->psz_access, "%.*s", strlen(p) - strlen(slash), p ) < 0)
+                {
+                    msg_Err(p_access, "Failed to parse the protocol after redirection");
+                    goto error; // :// should be there if request is RFC 2068 compliant
+                }
+                psz_new_loc = strdup( slash + 3 );
             }
-
+            msg_Dbg(p_access, "Location: %s", psz_new_loc);
             free( p_sys->psz_location );
             p_sys->psz_location = psz_new_loc;
         }
-- 
1.7.1




More information about the vlc-devel mailing list