35 #define PRINT_COMPONENT(comp) \ 36 len = uc.url_component_end_##comp - uc.comp; \ 37 if (len) printf(" "#comp": %.*s\n", len, uc.comp); 49 static void test(
const char *
base,
const char *rel)
51 char buf[200], buf2[200];
59 printf(
"%50s %-20s => %s\n", base, rel, buf);
62 snprintf(buf2,
sizeof(buf2),
"%s", base);
64 if (strcmp(buf, buf2)) {
65 printf(
"In-place handling of %s + %s failed\n", base, rel);
71 static void test2(
const char *url)
79 av_url_split(proto,
sizeof(proto), auth,
sizeof(auth), host,
sizeof(host), &port, path,
sizeof(path), url);
80 printf(
"%-60s => %-15s %-15s %-15s %5d %s\n", url, proto, auth, host, port, path);
85 printf(
"Testing ff_url_decompose:\n\n");
86 test_decompose(
"http://user:pass@ffmpeg:8080/dir/file?query#fragment");
96 printf(
"Testing ff_make_absolute_url:\n");
98 test(
"/foo/bar",
"baz");
99 test(
"/foo/bar",
"../baz");
100 test(
"/foo/bar",
"/baz");
101 test(
"/foo/bar",
"../../../baz");
102 test(
"http://server/foo/",
"baz");
103 test(
"http://server/foo/bar",
"baz");
104 test(
"http://server/foo/",
"../baz");
105 test(
"http://server/foo/bar/123",
"../../baz");
106 test(
"http://server/foo/bar/123",
"/baz");
107 test(
"http://server/foo/bar/123",
"https://other/url");
108 test(
"http://server/foo/bar?param=value/with/slashes",
"/baz");
109 test(
"http://server/foo/bar?param&otherparam",
"?someparam");
110 test(
"http://server/foo/bar",
"//other/url");
111 test(
"http://server/foo/bar",
"../../../../../other/url");
112 test(
"http://server/foo/bar",
"/../../../../../other/url");
113 test(
"http://server/foo/bar",
"/test/../../../../../other/url");
114 test(
"http://server/foo/bar",
"/test/../../test/../../../other/url");
115 test(
"http://server/foo/bar",
"file:../baz/qux");
116 test(
"http://server/foo//bar/",
"../../");
117 test(
"file:../tmp/foo",
"../bar/");
118 test(
"file:../tmp/foo",
"file:../bar/");
119 test(
"http://server/foo/bar",
"./");
120 test(
"http://server/foo/bar",
".dotfile");
121 test(
"http://server/foo/bar",
"..doubledotfile");
122 test(
"http://server/foo/bar",
"double..dotfile");
123 test(
"http://server/foo/bar",
"doubledotfile..");
126 test(
"http://a/b/c/d;p?q",
"g:h");
127 test(
"http://a/b/c/d;p?q",
"g");
128 test(
"http://a/b/c/d;p?q",
"./g");
129 test(
"http://a/b/c/d;p?q",
"g/");
130 test(
"http://a/b/c/d;p?q",
"/g");
131 test(
"http://a/b/c/d;p?q",
"//g");
132 test(
"http://a/b/c/d;p?q",
"?y");
133 test(
"http://a/b/c/d;p?q",
"g?y");
134 test(
"http://a/b/c/d;p?q",
"#s");
135 test(
"http://a/b/c/d;p?q",
"g#s");
136 test(
"http://a/b/c/d;p?q",
"g?y#s");
137 test(
"http://a/b/c/d;p?q",
";x");
138 test(
"http://a/b/c/d;p?q",
"g;x");
139 test(
"http://a/b/c/d;p?q",
"g;x?y#s");
140 test(
"http://a/b/c/d;p?q",
"");
141 test(
"http://a/b/c/d;p?q",
".");
142 test(
"http://a/b/c/d;p?q",
"./");
143 test(
"http://a/b/c/d;p?q",
"..");
144 test(
"http://a/b/c/d;p?q",
"../");
145 test(
"http://a/b/c/d;p?q",
"../g");
146 test(
"http://a/b/c/d;p?q",
"../..");
147 test(
"http://a/b/c/d;p?q",
"../../");
148 test(
"http://a/b/c/d;p?q",
"../../g");
149 test(
"http://a/b/c/d;p?q",
"../../../g");
150 test(
"http://a/b/c/d;p?q",
"../../../../g");
151 test(
"http://a/b/c/d;p?q",
"/./g");
152 test(
"http://a/b/c/d;p?q",
"/../g");
153 test(
"http://a/b/c/d;p?q",
"g.");
154 test(
"http://a/b/c/d;p?q",
".g");
155 test(
"http://a/b/c/d;p?q",
"g..");
156 test(
"http://a/b/c/d;p?q",
"..g");
157 test(
"http://a/b/c/d;p?q",
"./../g");
158 test(
"http://a/b/c/d;p?q",
"./g/.");
159 test(
"http://a/b/c/d;p?q",
"g/./h");
160 test(
"http://a/b/c/d;p?q",
"g/../h");
161 test(
"http://a/b/c/d;p?q",
"g;x=1/./y");
162 test(
"http://a/b/c/d;p?q",
"g;x=1/../y");
163 test(
"http://a/b/c/d;p?q",
"g?y/./x");
164 test(
"http://a/b/c/d;p?q",
"g?y/../x");
165 test(
"http://a/b/c/d;p?q",
"g#s/./x");
166 test(
"http://a/b/c/d;p?q",
"g#s/../x");
168 printf(
"\nTesting av_url_split:\n");
170 test2(
"http://server/foo/");
171 test2(
"http://example.com/foo/bar");
172 test2(
"http://user:pass@localhost:8080/foo/bar/123");
173 test2(
"http://server/foo/bar?param=value/with/slashes");
174 test2(
"https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8");
175 test2(
"ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg");
176 test2(
"https://key.dns.com?key_id=2&model_id=12345&&access_key=");
177 test2(
"http://example.com#tag");
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
int ff_url_decompose(URLComponents *uc, const char *url, const char *end)
Parse an URL to find the components.
#define PRINT_COMPONENT(comp)
static void test_decompose(const char *url)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
Convert a relative url into an absolute url, given a base url.
static void test2(const char *url)
printf("static const uint8_t my_array[100] = {\n")
unbuffered private I/O API
static void test(const char *base, const char *rel)