From f1f60f5252b0b448adcce0c1c52f3161ee69b9bf Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Thu, 17 Mar 2011 12:24:23 +0200 Subject: lavf: Make make_absolute_url a lavf internal function This is shared by both applehttp demuxer and protocol. Signed-off-by: Luca Barbato --- libavformat/utils.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'libavformat/utils.c') diff --git a/libavformat/utils.c b/libavformat/utils.c index ad00ce83e7..d6a17009db 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); +} -- cgit v1.2.3