[vlc-commits] http: factor and test redirection URL resolution

Rémi Denis-Courmont git at videolan.org
Tue Aug 2 21:05:32 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug  2 22:02:22 2016 +0300| [3ea757959a61982c202044287bb30b8207d21ccd] | committer: Rémi Denis-Courmont

http: factor and test redirection URL resolution

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

 modules/access/http/access.c    | 11 +----------
 modules/access/http/file_test.c |  3 ++-
 modules/access/http/resource.c  | 22 +++++++++++++++++++---
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/modules/access/http/access.c b/modules/access/http/access.c
index 0b0e56e..819a066 100644
--- a/modules/access/http/access.c
+++ b/modules/access/http/access.c
@@ -30,7 +30,6 @@
 #include <vlc_common.h>
 #include <vlc_access.h>
 #include <vlc_plugin.h>
-#include <vlc_url.h>
 
 #include "connmgr.h"
 #include "resource.h"
@@ -195,15 +194,7 @@ static int Open(vlc_object_t *obj)
     char *redir = vlc_http_res_get_redirect(sys->resource);
     if (redir != NULL)
     {
-        char *fixed = vlc_uri_fixup(redir);
-        if (likely(fixed != NULL))
-        {
-            free(redir);
-            redir = fixed;
-        }
-
-        access->psz_url = vlc_uri_resolve(access->psz_url, redir);
-        free(redir);
+        access->psz_url = redir;
         ret = VLC_ACCESS_REDIRECT;
         goto error;
     }
diff --git a/modules/access/http/file_test.c b/modules/access/http/file_test.c
index 21cfeb4..c74b5c6 100644
--- a/modules/access/http/file_test.c
+++ b/modules/access/http/file_test.c
@@ -139,7 +139,8 @@ int main(void)
     assert(!vlc_http_file_can_seek(f));
     assert(vlc_http_file_get_size(f) == (uintmax_t)-1);
     str = vlc_http_file_get_redirect(f);
-    assert(str != NULL && !strcmp(str, "/somewhere/else/"));
+    assert(str != NULL);
+    assert(!strcmp(str, "https://www.example.com:8443/somewhere/else/"));
     free(str);
     vlc_http_file_destroy(f);
 
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index e092a4f..8688d23 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -275,10 +275,26 @@ char *vlc_http_res_get_redirect(struct vlc_http_resource *restrict res)
 
     /* TODO: if status is 3xx, check for Retry-After and wait */
 
-    /* NOTE: The anchor is discard if it is present as VLC does not support
+    char *base;
+
+    if (unlikely(asprintf(&base, "http%s://%s%s", res->secure ? "s" : "",
+                          res->authority, res->path) == -1))
+        return NULL;
+
+    char *fixed = vlc_uri_fixup(location);
+    if (fixed != NULL)
+        location = fixed;
+
+    char *abs = vlc_uri_resolve(base, location);
+
+    free(fixed);
+    free(base);
+
+    /* NOTE: The anchor is discarded if it is present as VLC does not support
      * HTML anchors so far. */
-    size_t len = strcspn(location, "#");
-    return strndup(location, len);
+    size_t len = strcspn(abs, "#");
+    abs[len] = '\0';
+    return abs;
 }
 
 char *vlc_http_res_get_type(struct vlc_http_resource *res)



More information about the vlc-commits mailing list