[FFmpeg-devel] [PATCH v2] Handle the following type of relative URL correctly:
Duncan Salerno
duncan.salerno at gmail.com
Tue Sep 25 22:19:38 CEST 2012
On Tue, Sep 25, 2012 at 8:51 PM, Clément Bœsch <ubitux at gmail.com> wrote:
> On Tue, Sep 25, 2012 at 07:19:32PM +0100, Duncan Salerno wrote:
>> http://a/b + //c/d = http://c/d
>
> Mmh after a though, shouldn't that be http://a/c/d since N * '/' should
> just be interpreted as a '/'.
No - see RFC 3986 5.4.1.
>> http://a/b?c + ?d = http://a/b?d
>> http://a/b?c/d + /e = http://a/e
>>
>> Updated with feedback from Clément Bœsch
>> ---
>> libavformat/utils.c | 28 +++++++++++++++++++++++-----
>> 1 file changed, 23 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavformat/utils.c b/libavformat/utils.c
>> index e5826c1..d2d57f1 100644
>> --- a/libavformat/utils.c
>> +++ b/libavformat/utils.c
>> @@ -4467,17 +4467,23 @@ int ff_find_stream_index(AVFormatContext *s, int id)
>> void ff_make_absolute_url(char *buf, int size, const char *base,
>> const char *rel)
>> {
>> - char *sep;
>> + char *sep, *path_query;
>> /* 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';
>> + /* 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;
>> @@ -4489,6 +4495,18 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
>> }
>> if (base != buf)
>> av_strlcpy(buf, base, size);
>> +
>> + /* Strip off any query string from base */
>> + 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)
>
> No more comment from me.
>
> [...]
>
> Note: could be nice to have a bunch of test-cases to run with this
> function.
Agreed. Happy to send a separate patch if you can give me some
pointers on how to add these tests (I'm new to ffmpeg).
More information about the ffmpeg-devel
mailing list