Revision f1f60f52 libavformat/utils.c

View differences:

libavformat/utils.c
3814 3814
    }
3815 3815
    return -1;
3816 3816
}
3817

  
3818
void ff_make_absolute_url(char *buf, int size, const char *base,
3819
                          const char *rel)
3820
{
3821
    char *sep;
3822
    /* Absolute path, relative to the current server */
3823
    if (base && strstr(base, "://") && rel[0] == '/') {
3824
        if (base != buf)
3825
            av_strlcpy(buf, base, size);
3826
        sep = strstr(buf, "://");
3827
        if (sep) {
3828
            sep += 3;
3829
            sep = strchr(sep, '/');
3830
            if (sep)
3831
                *sep = '\0';
3832
        }
3833
        av_strlcat(buf, rel, size);
3834
        return;
3835
    }
3836
    /* If rel actually is an absolute url, just copy it */
3837
    if (!base || strstr(rel, "://") || rel[0] == '/') {
3838
        av_strlcpy(buf, rel, size);
3839
        return;
3840
    }
3841
    if (base != buf)
3842
        av_strlcpy(buf, base, size);
3843
    /* Remove the file name from the base url */
3844
    sep = strrchr(buf, '/');
3845
    if (sep)
3846
        sep[1] = '\0';
3847
    else
3848
        buf[0] = '\0';
3849
    while (av_strstart(rel, "../", NULL) && sep) {
3850
        /* Remove the path delimiter at the end */
3851
        sep[0] = '\0';
3852
        sep = strrchr(buf, '/');
3853
        /* If the next directory name to pop off is "..", break here */
3854
        if (!strcmp(sep ? &sep[1] : buf, "..")) {
3855
            /* Readd the slash we just removed */
3856
            av_strlcat(buf, "/", size);
3857
            break;
3858
        }
3859
        /* Cut off the directory name */
3860
        if (sep)
3861
            sep[1] = '\0';
3862
        else
3863
            buf[0] = '\0';
3864
        rel += 3;
3865
    }
3866
    av_strlcat(buf, rel, size);
3867
}

Also available in: Unified diff