2012-10-06 01:38:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Martin Storsjo
|
|
|
|
*
|
2012-10-10 14:00:28 +03:00
|
|
|
* This file is part of FFmpeg.
|
2012-10-06 01:38:37 +03:00
|
|
|
*
|
2012-10-10 14:00:28 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2012-10-06 01:38:37 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-10-10 14:00:28 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2012-10-06 01:38:37 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-10-10 14:00:28 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2012-10-06 01:38:37 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2021-04-06 01:10:30 +02:00
|
|
|
#include "config.h"
|
2016-04-20 11:40:40 +02:00
|
|
|
#include "libavformat/url.h"
|
2020-02-03 02:13:28 +02:00
|
|
|
#include "libavformat/avformat.h"
|
2012-10-06 01:38:37 +03:00
|
|
|
|
2020-07-29 14:39:20 +02:00
|
|
|
static void test_decompose(const char *url)
|
|
|
|
{
|
|
|
|
URLComponents uc;
|
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
printf("%s =>\n", url);
|
|
|
|
ret = ff_url_decompose(&uc, url, NULL);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf(" error: %s\n", av_err2str(ret));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#define PRINT_COMPONENT(comp) \
|
|
|
|
len = uc.url_component_end_##comp - uc.comp; \
|
|
|
|
if (len) printf(" "#comp": %.*s\n", len, uc.comp);
|
|
|
|
PRINT_COMPONENT(scheme);
|
|
|
|
PRINT_COMPONENT(authority);
|
|
|
|
PRINT_COMPONENT(userinfo);
|
|
|
|
PRINT_COMPONENT(host);
|
|
|
|
PRINT_COMPONENT(port);
|
|
|
|
PRINT_COMPONENT(path);
|
|
|
|
PRINT_COMPONENT(query);
|
|
|
|
PRINT_COMPONENT(fragment);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2012-10-06 01:38:37 +03:00
|
|
|
static void test(const char *base, const char *rel)
|
|
|
|
{
|
2021-04-06 01:10:30 +02:00
|
|
|
char buf[200], buf2[200], buf_dos[200], buf_native[200];
|
2020-07-30 00:02:10 +02:00
|
|
|
int ret;
|
|
|
|
|
2021-04-06 01:10:30 +02:00
|
|
|
ret = ff_make_absolute_url2(buf, sizeof(buf), base, rel, 0);
|
2020-07-30 00:02:10 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
printf("%50s %-20s => error %s\n", base, rel, av_err2str(ret));
|
|
|
|
return;
|
|
|
|
}
|
2020-02-03 00:26:16 +02:00
|
|
|
printf("%50s %-20s => %s\n", base, rel, buf);
|
2021-04-06 01:10:30 +02:00
|
|
|
ret = ff_make_absolute_url2(buf_dos, sizeof(buf_dos), base, rel, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
snprintf(buf_dos, sizeof(buf_dos), "error %s", av_err2str(ret));
|
|
|
|
ret = ff_make_absolute_url(buf_native, sizeof(buf_native), base, rel);
|
|
|
|
if (ret < 0)
|
|
|
|
snprintf(buf_native, sizeof(buf_native), "error %s", av_err2str(ret));
|
|
|
|
if (strcmp(buf, buf_dos))
|
|
|
|
printf("%50s %-20sDOS %s\n", base, rel, buf_dos);
|
|
|
|
if (HAVE_DOS_PATHS && strcmp(buf_dos, buf_native) ||
|
|
|
|
!HAVE_DOS_PATHS && strcmp(buf, buf_native))
|
|
|
|
printf("Native mismatch\n");
|
2012-10-06 01:38:37 +03:00
|
|
|
if (base) {
|
|
|
|
/* Test in-buffer replacement */
|
|
|
|
snprintf(buf2, sizeof(buf2), "%s", base);
|
2021-04-06 01:10:30 +02:00
|
|
|
ff_make_absolute_url2(buf2, sizeof(buf2), buf2, rel, 0);
|
2012-10-06 01:38:37 +03:00
|
|
|
if (strcmp(buf, buf2)) {
|
|
|
|
printf("In-place handling of %s + %s failed\n", base, rel);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 02:13:28 +02:00
|
|
|
static void test2(const char *url)
|
|
|
|
{
|
|
|
|
char proto[64];
|
|
|
|
char auth[256];
|
|
|
|
char host[256];
|
|
|
|
char path[256];
|
|
|
|
int port=-1;
|
|
|
|
|
|
|
|
av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host), &port, path, sizeof(path), url);
|
|
|
|
printf("%-60s => %-15s %-15s %-15s %5d %s\n", url, proto, auth, host, port, path);
|
|
|
|
}
|
|
|
|
|
2012-10-06 01:38:37 +03:00
|
|
|
int main(void)
|
|
|
|
{
|
2020-07-29 14:39:20 +02:00
|
|
|
printf("Testing ff_url_decompose:\n\n");
|
|
|
|
test_decompose("http://user:pass@ffmpeg:8080/dir/file?query#fragment");
|
|
|
|
test_decompose("http://ffmpeg/dir/file");
|
|
|
|
test_decompose("file:///dev/null");
|
|
|
|
test_decompose("file:/dev/null");
|
|
|
|
test_decompose("http://[::1]/dev/null");
|
|
|
|
test_decompose("http://[::1]:8080/dev/null");
|
|
|
|
test_decompose("//ffmpeg/dev/null");
|
2020-10-17 17:17:14 +02:00
|
|
|
test_decompose("test?url=http://server/path");
|
|
|
|
test_decompose("dummy.mp4#t=0:02:00,121.5");
|
2020-07-29 14:39:20 +02:00
|
|
|
|
2020-02-03 00:26:16 +02:00
|
|
|
printf("Testing ff_make_absolute_url:\n");
|
2012-10-06 01:38:37 +03:00
|
|
|
test(NULL, "baz");
|
|
|
|
test("/foo/bar", "baz");
|
|
|
|
test("/foo/bar", "../baz");
|
|
|
|
test("/foo/bar", "/baz");
|
2020-04-29 06:50:57 +02:00
|
|
|
test("/foo/bar", "../../../baz");
|
2012-10-06 01:38:37 +03:00
|
|
|
test("http://server/foo/", "baz");
|
|
|
|
test("http://server/foo/bar", "baz");
|
|
|
|
test("http://server/foo/", "../baz");
|
|
|
|
test("http://server/foo/bar/123", "../../baz");
|
|
|
|
test("http://server/foo/bar/123", "/baz");
|
|
|
|
test("http://server/foo/bar/123", "https://other/url");
|
|
|
|
test("http://server/foo/bar?param=value/with/slashes", "/baz");
|
|
|
|
test("http://server/foo/bar?param&otherparam", "?someparam");
|
|
|
|
test("http://server/foo/bar", "//other/url");
|
2020-04-29 06:50:57 +02:00
|
|
|
test("http://server/foo/bar", "../../../../../other/url");
|
|
|
|
test("http://server/foo/bar", "/../../../../../other/url");
|
|
|
|
test("http://server/foo/bar", "/test/../../../../../other/url");
|
|
|
|
test("http://server/foo/bar", "/test/../../test/../../../other/url");
|
2020-07-30 00:02:10 +02:00
|
|
|
test("http://server/foo/bar", "file:../baz/qux");
|
|
|
|
test("http://server/foo//bar/", "../../");
|
|
|
|
test("file:../tmp/foo", "../bar/");
|
|
|
|
test("file:../tmp/foo", "file:../bar/");
|
|
|
|
test("http://server/foo/bar", "./");
|
|
|
|
test("http://server/foo/bar", ".dotfile");
|
|
|
|
test("http://server/foo/bar", "..doubledotfile");
|
|
|
|
test("http://server/foo/bar", "double..dotfile");
|
|
|
|
test("http://server/foo/bar", "doubledotfile..");
|
2021-04-06 01:10:30 +02:00
|
|
|
test("file1", "file2");
|
|
|
|
test("dir/file1", "file2");
|
|
|
|
test("dir/file1", "../file2");
|
|
|
|
test("dir\\file1", "file2");
|
|
|
|
test("\\\\srv\\shr\\file", "..\\..\\dummy");
|
|
|
|
test("\\\\srv\\shr\\file", "dummy");
|
|
|
|
test("\\\\srv\\shr\\file", "\\\\srv2\\shr2\\file2");
|
|
|
|
test("\\\\srv\\shr\\file", "d:/file");
|
|
|
|
test("C:\\dir\\a", "..\\file");
|
|
|
|
test("C:\\dir\\a", "\\\\srv\\shr\\file");
|
|
|
|
test("C:\\dir\\a", "d:\\file");
|
|
|
|
test("http://a/b", "\\\\srv\\shr\\file");
|
|
|
|
test("http://a/b", "//srv/shr/file");
|
|
|
|
test("http://a/b", "d:\\file");
|
|
|
|
test("http://a/b", "C:/file");
|
2020-07-30 00:02:10 +02:00
|
|
|
|
|
|
|
/* From https://tools.ietf.org/html/rfc3986#section-5.4 */
|
|
|
|
test("http://a/b/c/d;p?q", "g:h"); // g:h
|
|
|
|
test("http://a/b/c/d;p?q", "g"); // http://a/b/c/g
|
|
|
|
test("http://a/b/c/d;p?q", "./g"); // http://a/b/c/g
|
|
|
|
test("http://a/b/c/d;p?q", "g/"); // http://a/b/c/g/
|
|
|
|
test("http://a/b/c/d;p?q", "/g"); // http://a/g
|
|
|
|
test("http://a/b/c/d;p?q", "//g"); // http://g
|
|
|
|
test("http://a/b/c/d;p?q", "?y"); // http://a/b/c/d;p?y
|
|
|
|
test("http://a/b/c/d;p?q", "g?y"); // http://a/b/c/g?y
|
|
|
|
test("http://a/b/c/d;p?q", "#s"); // http://a/b/c/d;p?q#s
|
|
|
|
test("http://a/b/c/d;p?q", "g#s"); // http://a/b/c/g#s
|
|
|
|
test("http://a/b/c/d;p?q", "g?y#s"); // http://a/b/c/g?y#s
|
|
|
|
test("http://a/b/c/d;p?q", ";x"); // http://a/b/c/;x
|
|
|
|
test("http://a/b/c/d;p?q", "g;x"); // http://a/b/c/g;x
|
|
|
|
test("http://a/b/c/d;p?q", "g;x?y#s"); // http://a/b/c/g;x?y#s
|
|
|
|
test("http://a/b/c/d;p?q", ""); // http://a/b/c/d;p?q
|
|
|
|
test("http://a/b/c/d;p?q", "."); // http://a/b/c/
|
|
|
|
test("http://a/b/c/d;p?q", "./"); // http://a/b/c/
|
|
|
|
test("http://a/b/c/d;p?q", ".."); // http://a/b/
|
|
|
|
test("http://a/b/c/d;p?q", "../"); // http://a/b/
|
|
|
|
test("http://a/b/c/d;p?q", "../g"); // http://a/b/g
|
|
|
|
test("http://a/b/c/d;p?q", "../.."); // http://a/
|
|
|
|
test("http://a/b/c/d;p?q", "../../"); // http://a/
|
|
|
|
test("http://a/b/c/d;p?q", "../../g"); // http://a/g
|
|
|
|
test("http://a/b/c/d;p?q", "../../../g"); // http://a/g
|
|
|
|
test("http://a/b/c/d;p?q", "../../../../g"); // http://a/g
|
|
|
|
test("http://a/b/c/d;p?q", "/./g"); // http://a/g
|
|
|
|
test("http://a/b/c/d;p?q", "/../g"); // http://a/g
|
|
|
|
test("http://a/b/c/d;p?q", "g."); // http://a/b/c/g.
|
|
|
|
test("http://a/b/c/d;p?q", ".g"); // http://a/b/c/.g
|
|
|
|
test("http://a/b/c/d;p?q", "g.."); // http://a/b/c/g..
|
|
|
|
test("http://a/b/c/d;p?q", "..g"); // http://a/b/c/..g
|
|
|
|
test("http://a/b/c/d;p?q", "./../g"); // http://a/b/g
|
|
|
|
test("http://a/b/c/d;p?q", "./g/."); // http://a/b/c/g/
|
|
|
|
test("http://a/b/c/d;p?q", "g/./h"); // http://a/b/c/g/h
|
|
|
|
test("http://a/b/c/d;p?q", "g/../h"); // http://a/b/c/h
|
|
|
|
test("http://a/b/c/d;p?q", "g;x=1/./y"); // http://a/b/c/g;x=1/y
|
|
|
|
test("http://a/b/c/d;p?q", "g;x=1/../y"); // http://a/b/c/y
|
|
|
|
test("http://a/b/c/d;p?q", "g?y/./x"); // http://a/b/c/g?y/./x
|
|
|
|
test("http://a/b/c/d;p?q", "g?y/../x"); // http://a/b/c/g?y/../x
|
|
|
|
test("http://a/b/c/d;p?q", "g#s/./x"); // http://a/b/c/g#s/./x
|
|
|
|
test("http://a/b/c/d;p?q", "g#s/../x"); // http://a/b/c/g#s/../x
|
2020-02-03 02:13:28 +02:00
|
|
|
|
|
|
|
printf("\nTesting av_url_split:\n");
|
|
|
|
test2("/foo/bar");
|
|
|
|
test2("http://server/foo/");
|
|
|
|
test2("http://example.com/foo/bar");
|
|
|
|
test2("http://user:pass@localhost:8080/foo/bar/123");
|
|
|
|
test2("http://server/foo/bar?param=value/with/slashes");
|
|
|
|
test2("https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8");
|
|
|
|
test2("ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg");
|
|
|
|
test2("https://key.dns.com?key_id=2&model_id=12345&&access_key=");
|
2020-02-03 02:32:00 +02:00
|
|
|
test2("http://example.com#tag");
|
2020-02-03 02:13:28 +02:00
|
|
|
|
2012-10-06 01:38:37 +03:00
|
|
|
return 0;
|
|
|
|
}
|