lavf: Make make_absolute_url a lavf internal function

Message ID 1300357463-26517-1-git-send-email-martin@martin.st
State Committed
Commit f1f60f5252b0b448adcce0c1c52f3161ee69b9bf
Headers show

Commit Message

Martin Storsjö March 17, 2011, 10:24 a.m.
This is shared by both applehttp demuxer and protocol.
---
OKd by Ronald on ffmpeg-devel, claimed to be queued up by
Luca, but hasn't hit the git repo yet.

 libavformat/applehttp.c      |   55 +----------------------------------------
 libavformat/applehttpproto.c |   55 +----------------------------------------
 libavformat/internal.h       |   11 ++++++++
 libavformat/utils.c          |   51 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 106 deletions(-)

Comments

Luca Barbato March 17, 2011, 11:05 a.m. | #1
On 3/17/11 11:24 AM, Martin Storsjö wrote:
> This is shared by both applehttp demuxer and protocol.
> ---
> OKd by Ronald on ffmpeg-devel, claimed to be queued up by
> Luca, but hasn't hit the git repo yet.

Pushed now, sorry for the delay.

Patch

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 7a3d8b0..054e9fd 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -86,57 +86,6 @@  static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
     return len;
 }
 
-static void make_absolute_url(char *buf, int size, const char *base,
-                              const char *rel)
-{
-    char *sep;
-    /* Absolute path, relative to the current server */
-    if (base && strstr(base, "://") && rel[0] == '/') {
-        if (base != buf)
-            av_strlcpy(buf, base, size);
-        sep = strstr(buf, "://");
-        if (sep) {
-            sep += 3;
-            sep = strchr(sep, '/');
-            if (sep)
-                *sep = '\0';
-        }
-        av_strlcat(buf, rel, size);
-        return;
-    }
-    /* If rel actually is an absolute url, just copy it */
-    if (!base || strstr(rel, "://") || rel[0] == '/') {
-        av_strlcpy(buf, rel, size);
-        return;
-    }
-    if (base != buf)
-        av_strlcpy(buf, base, size);
-    /* Remove the file name from the base url */
-    sep = strrchr(buf, '/');
-    if (sep)
-        sep[1] = '\0';
-    else
-        buf[0] = '\0';
-    while (av_strstart(rel, "../", NULL) && sep) {
-        /* Remove the path delimiter at the end */
-        sep[0] = '\0';
-        sep = strrchr(buf, '/');
-        /* If the next directory name to pop off is "..", break here */
-        if (!strcmp(sep ? &sep[1] : buf, "..")) {
-            /* Readd the slash we just removed */
-            av_strlcat(buf, "/", size);
-            break;
-        }
-        /* Cut off the directory name */
-        if (sep)
-            sep[1] = '\0';
-        else
-            buf[0] = '\0';
-        rel += 3;
-    }
-    av_strlcat(buf, rel, size);
-}
-
 static void free_segment_list(struct variant *var)
 {
     int i;
@@ -183,7 +132,7 @@  static struct variant *new_variant(AppleHTTPContext *c, int bandwidth,
         return NULL;
     reset_packet(&var->pkt);
     var->bandwidth = bandwidth;
-    make_absolute_url(var->url, sizeof(var->url), base, url);
+    ff_make_absolute_url(var->url, sizeof(var->url), base, url);
     dynarray_add(&c->variants, &c->n_variants, var);
     return var;
 }
@@ -274,7 +223,7 @@  static int parse_playlist(AppleHTTPContext *c, const char *url,
                     goto fail;
                 }
                 seg->duration = duration;
-                make_absolute_url(seg->url, sizeof(seg->url), url, line);
+                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
                 dynarray_add(&var->segments, &var->n_segments, seg);
                 is_segment = 0;
             }
diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c
index 871f271..c287c6c 100644
--- a/libavformat/applehttpproto.c
+++ b/libavformat/applehttpproto.c
@@ -75,57 +75,6 @@  static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
     return len;
 }
 
-static void make_absolute_url(char *buf, int size, const char *base,
-                              const char *rel)
-{
-    char *sep;
-    /* Absolute path, relative to the current server */
-    if (base && strstr(base, "://") && rel[0] == '/') {
-        if (base != buf)
-            av_strlcpy(buf, base, size);
-        sep = strstr(buf, "://");
-        if (sep) {
-            sep += 3;
-            sep = strchr(sep, '/');
-            if (sep)
-                *sep = '\0';
-        }
-        av_strlcat(buf, rel, size);
-        return;
-    }
-    /* If rel actually is an absolute url, just copy it */
-    if (!base || strstr(rel, "://") || rel[0] == '/') {
-        av_strlcpy(buf, rel, size);
-        return;
-    }
-    if (base != buf)
-        av_strlcpy(buf, base, size);
-    /* Remove the file name from the base url */
-    sep = strrchr(buf, '/');
-    if (sep)
-        sep[1] = '\0';
-    else
-        buf[0] = '\0';
-    while (av_strstart(rel, "../", NULL) && sep) {
-        /* Remove the path delimiter at the end */
-        sep[0] = '\0';
-        sep = strrchr(buf, '/');
-        /* If the next directory name to pop off is "..", break here */
-        if (!strcmp(sep ? &sep[1] : buf, "..")) {
-            /* Readd the slash we just removed */
-            av_strlcat(buf, "/", size);
-            break;
-        }
-        /* Cut off the directory name */
-        if (sep)
-            sep[1] = '\0';
-        else
-            buf[0] = '\0';
-        rel += 3;
-    }
-    av_strlcat(buf, rel, size);
-}
-
 static void free_segment_list(AppleHTTPContext *s)
 {
     int i;
@@ -201,7 +150,7 @@  static int parse_playlist(URLContext *h, const char *url)
                     goto fail;
                 }
                 seg->duration = duration;
-                make_absolute_url(seg->url, sizeof(seg->url), url, line);
+                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
                 dynarray_add(&s->segments, &s->n_segments, seg);
                 is_segment = 0;
             } else if (is_variant) {
@@ -211,7 +160,7 @@  static int parse_playlist(URLContext *h, const char *url)
                     goto fail;
                 }
                 var->bandwidth = bandwidth;
-                make_absolute_url(var->url, sizeof(var->url), url, line);
+                ff_make_absolute_url(var->url, sizeof(var->url), url, line);
                 dynarray_add(&s->variants, &s->n_variants, var);
                 is_variant = 0;
             }
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 02a27e4..d5bfc33 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -239,4 +239,15 @@  AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
  */
 void ff_reduce_index(AVFormatContext *s, int stream_index);
 
+/*
+ * Convert a relative url into an absolute url, given a base url.
+ *
+ * @param buf the buffer where output absolute url is written
+ * @param size the size of buf
+ * @param base the base url, may be equal to buf.
+ * @param rel the new url, which is interpreted relative to base
+ */
+void ff_make_absolute_url(char *buf, int size, const char *base,
+                          const char *rel);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ad00ce8..d6a1700 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3814,3 +3814,54 @@  int ff_find_stream_index(AVFormatContext *s, int id)
     }
     return -1;
 }
+
+void ff_make_absolute_url(char *buf, int size, const char *base,
+                          const char *rel)
+{
+    char *sep;
+    /* Absolute path, relative to the current server */
+    if (base && strstr(base, "://") && rel[0] == '/') {
+        if (base != buf)
+            av_strlcpy(buf, base, size);
+        sep = strstr(buf, "://");
+        if (sep) {
+            sep += 3;
+            sep = strchr(sep, '/');
+            if (sep)
+                *sep = '\0';
+        }
+        av_strlcat(buf, rel, size);
+        return;
+    }
+    /* If rel actually is an absolute url, just copy it */
+    if (!base || strstr(rel, "://") || rel[0] == '/') {
+        av_strlcpy(buf, rel, size);
+        return;
+    }
+    if (base != buf)
+        av_strlcpy(buf, base, size);
+    /* Remove the file name from the base url */
+    sep = strrchr(buf, '/');
+    if (sep)
+        sep[1] = '\0';
+    else
+        buf[0] = '\0';
+    while (av_strstart(rel, "../", NULL) && sep) {
+        /* Remove the path delimiter at the end */
+        sep[0] = '\0';
+        sep = strrchr(buf, '/');
+        /* If the next directory name to pop off is "..", break here */
+        if (!strcmp(sep ? &sep[1] : buf, "..")) {
+            /* Readd the slash we just removed */
+            av_strlcat(buf, "/", size);
+            break;
+        }
+        /* Cut off the directory name */
+        if (sep)
+            sep[1] = '\0';
+        else
+            buf[0] = '\0';
+        rel += 3;
+    }
+    av_strlcat(buf, rel, size);
+}