[vlc-devel] [PATCH 2/2] http: get status before redirect

Thomas Guillem thomas at gllm.fr
Tue Mar 29 14:04:27 CEST 2016


There is no way to know if vlc_http_*_get_redirect() returns NULL because of a
connection failure (vlc_http_*_open() returning NULL) or because there is no
redirect.

Call vlc_http_*_get_status() first in order to check if connection failed or
not.

This fixes an issue when a blocking vlc_http_live_open() was interrupted and
was called again (and blocking again).
---
 modules/access/http/access.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/modules/access/http/access.c b/modules/access/http/access.c
index 28d4d09..bc878eb 100644
--- a/modules/access/http/access.c
+++ b/modules/access/http/access.c
@@ -194,36 +194,22 @@ static int Open(vlc_object_t *obj)
     bool live = var_InheritBool(obj, "http-continuous");
 
     if (live)
+    {
         sys->live = vlc_http_live_create(sys->manager, access->psz_url, ua,
                                          referer);
-    else
-        sys->file = vlc_http_file_create(sys->manager, access->psz_url, ua,
-                                         referer);
-    free(referer);
-    free(ua);
-
-    char *redir;
-
-    if (live)
-    {
+        free(referer);
+        free(ua);
         if (sys->live == NULL)
             goto error;
-
-        redir = vlc_http_live_get_redirect(sys->live);
     }
     else
     {
+        sys->file = vlc_http_file_create(sys->manager, access->psz_url, ua,
+                                         referer);
+        free(referer);
+        free(ua);
         if (sys->file == NULL)
             goto error;
-
-        redir = vlc_http_file_get_redirect(sys->file);
-    }
-
-    if (redir != NULL)
-    {
-        access->psz_url = redir;
-        ret = VLC_ACCESS_REDIRECT;
-        goto error;
     }
 
     ret = VLC_EGENERIC;
@@ -235,6 +221,21 @@ static int Open(vlc_object_t *obj)
         msg_Err(access, "HTTP connection failure");
         goto error;
     }
+
+    char *redir;
+
+    if (live)
+        redir = vlc_http_live_get_redirect(sys->live);
+    else
+        redir = vlc_http_file_get_redirect(sys->file);
+
+    if (redir != NULL)
+    {
+        access->psz_url = redir;
+        ret = VLC_ACCESS_REDIRECT;
+        goto error;
+    }
+
     if (status == 401) /* authentication */
         goto error; /* FIXME not implemented yet */
     if (status >= 300)
-- 
2.8.0.rc3



More information about the vlc-devel mailing list