[FFmpeg-devel] [PATCH] Handle the following type of relative URL correctly:

Duncan Salerno duncan.salerno at gmail.com
Sun Sep 23 22:12:54 CEST 2012


http://a/b + //c/d = http://c/d
http://a/b?c + ?d = http://a/b?d
http://a/b?c/d + /e = http://a/e
---
 libavformat/utils.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 6603483..d4919c5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4459,10 +4459,16 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
             av_strlcpy(buf, base, size);
         sep = strstr(buf, "://");
         if (sep) {
-            sep += 3;
-            sep = strchr(sep, '/');
-            if (sep)
-                *sep = '\0';
+            /* Take scheme from base url */
+            if (rel[1] == '/')
+                sep[1] = '\0';
+            else {
+                /* Take scheme and host from base url */
+                sep += 3;
+                sep = strchr(sep, '/');
+                if (sep)
+                    *sep = '\0';
+            }
         }
         av_strlcat(buf, rel, size);
         return;
@@ -4474,6 +4480,18 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
     }
     if (base != buf)
         av_strlcpy(buf, base, size);
+    
+    /* Stip off any query string from base */
+    char *path_query = strchr(buf, '?');
+    if (path_query != NULL)
+        *path_query = '\0';
+
+    /* Is relative path just a new query part? */
+    if (rel[0] == '?') {
+        av_strlcat(buf, rel, size);
+        return;
+    }
+
     /* Remove the file name from the base url */
     sep = strrchr(buf, '/');
     if (sep)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list