Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2012 Martin Storsjo | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include "config.h" | ||
22 | #include "libavformat/url.h" | ||
23 | #include "libavformat/avformat.h" | ||
24 | |||
25 | 9 | static void test_decompose(const char *url) | |
26 | { | ||
27 | URLComponents uc; | ||
28 | int len, ret; | ||
29 | |||
30 | 9 | printf("%s =>\n", url); | |
31 | 9 | ret = ff_url_decompose(&uc, url, NULL); | |
32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (ret < 0) { |
33 | ✗ | printf(" error: %s\n", av_err2str(ret)); | |
34 | ✗ | return; | |
35 | } | ||
36 | #define PRINT_COMPONENT(comp) \ | ||
37 | len = uc.url_component_end_##comp - uc.comp; \ | ||
38 | if (len) printf(" "#comp": %.*s\n", len, uc.comp); | ||
39 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | PRINT_COMPONENT(scheme); |
40 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | PRINT_COMPONENT(authority); |
41 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
|
9 | PRINT_COMPONENT(userinfo); |
42 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | PRINT_COMPONENT(host); |
43 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
|
9 | PRINT_COMPONENT(port); |
44 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | PRINT_COMPONENT(path); |
45 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
|
9 | PRINT_COMPONENT(query); |
46 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
|
9 | PRINT_COMPONENT(fragment); |
47 | 9 | printf("\n"); | |
48 | } | ||
49 | |||
50 | 83 | static void test(const char *base, const char *rel) | |
51 | { | ||
52 | char buf[200], buf2[200], buf_dos[200], buf_native[200]; | ||
53 | int ret; | ||
54 | |||
55 | 83 | ret = ff_make_absolute_url2(buf, sizeof(buf), base, rel, 0); | |
56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
|
83 | if (ret < 0) { |
57 | ✗ | printf("%50s %-20s => error %s\n", base, rel, av_err2str(ret)); | |
58 | ✗ | return; | |
59 | } | ||
60 | 83 | printf("%50s %-20s => %s\n", base, rel, buf); | |
61 | 83 | ret = ff_make_absolute_url2(buf_dos, sizeof(buf_dos), base, rel, 1); | |
62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
|
83 | if (ret < 0) |
63 | ✗ | snprintf(buf_dos, sizeof(buf_dos), "error %s", av_err2str(ret)); | |
64 | 83 | ret = ff_make_absolute_url(buf_native, sizeof(buf_native), base, rel); | |
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
|
83 | if (ret < 0) |
66 | ✗ | snprintf(buf_native, sizeof(buf_native), "error %s", av_err2str(ret)); | |
67 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 78 times.
|
83 | if (strcmp(buf, buf_dos)) |
68 | 5 | printf("%50s %-20sDOS %s\n", base, rel, buf_dos); | |
69 | 83 | if (HAVE_DOS_PATHS && strcmp(buf_dos, buf_native) || | |
70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
|
83 | !HAVE_DOS_PATHS && strcmp(buf, buf_native)) |
71 | ✗ | printf("Native mismatch\n"); | |
72 |
2/2✓ Branch 0 taken 82 times.
✓ Branch 1 taken 1 times.
|
83 | if (base) { |
73 | /* Test in-buffer replacement */ | ||
74 | 82 | snprintf(buf2, sizeof(buf2), "%s", base); | |
75 | 82 | ff_make_absolute_url2(buf2, sizeof(buf2), buf2, rel, 0); | |
76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
|
82 | if (strcmp(buf, buf2)) { |
77 | ✗ | printf("In-place handling of %s + %s failed\n", base, rel); | |
78 | ✗ | exit(1); | |
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | 9 | static void test2(const char *url) | |
84 | { | ||
85 | char proto[64]; | ||
86 | char auth[256]; | ||
87 | char host[256]; | ||
88 | char path[256]; | ||
89 | 9 | int port=-1; | |
90 | |||
91 | 9 | av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host), &port, path, sizeof(path), url); | |
92 | 9 | printf("%-60s => %-15s %-15s %-15s %5d %s\n", url, proto, auth, host, port, path); | |
93 | 9 | } | |
94 | |||
95 | 1 | int main(void) | |
96 | { | ||
97 | 1 | printf("Testing ff_url_decompose:\n\n"); | |
98 | 1 | test_decompose("http://user:pass@ffmpeg:8080/dir/file?query#fragment"); | |
99 | 1 | test_decompose("http://ffmpeg/dir/file"); | |
100 | 1 | test_decompose("file:///dev/null"); | |
101 | 1 | test_decompose("file:/dev/null"); | |
102 | 1 | test_decompose("http://[::1]/dev/null"); | |
103 | 1 | test_decompose("http://[::1]:8080/dev/null"); | |
104 | 1 | test_decompose("//ffmpeg/dev/null"); | |
105 | 1 | test_decompose("test?url=http://server/path"); | |
106 | 1 | test_decompose("dummy.mp4#t=0:02:00,121.5"); | |
107 | |||
108 | 1 | printf("Testing ff_make_absolute_url:\n"); | |
109 | 1 | test(NULL, "baz"); | |
110 | 1 | test("/foo/bar", "baz"); | |
111 | 1 | test("/foo/bar", "../baz"); | |
112 | 1 | test("/foo/bar", "/baz"); | |
113 | 1 | test("/foo/bar", "../../../baz"); | |
114 | 1 | test("http://server/foo/", "baz"); | |
115 | 1 | test("http://server/foo/bar", "baz"); | |
116 | 1 | test("http://server/foo/", "../baz"); | |
117 | 1 | test("http://server/foo/bar/123", "../../baz"); | |
118 | 1 | test("http://server/foo/bar/123", "/baz"); | |
119 | 1 | test("http://server/foo/bar/123", "https://other/url"); | |
120 | 1 | test("http://server/foo/bar?param=value/with/slashes", "/baz"); | |
121 | 1 | test("http://server/foo/bar?param&otherparam", "?someparam"); | |
122 | 1 | test("http://server/foo/bar", "//other/url"); | |
123 | 1 | test("http://server/foo/bar", "../../../../../other/url"); | |
124 | 1 | test("http://server/foo/bar", "/../../../../../other/url"); | |
125 | 1 | test("http://server/foo/bar", "/test/../../../../../other/url"); | |
126 | 1 | test("http://server/foo/bar", "/test/../../test/../../../other/url"); | |
127 | 1 | test("http://server/foo/bar", "file:../baz/qux"); | |
128 | 1 | test("http://server/foo//bar/", "../../"); | |
129 | 1 | test("file:../tmp/foo", "../bar/"); | |
130 | 1 | test("file:../tmp/foo", "file:../bar/"); | |
131 | 1 | test("http://server/foo/bar", "./"); | |
132 | 1 | test("http://server/foo/bar", ".dotfile"); | |
133 | 1 | test("http://server/foo/bar", "..doubledotfile"); | |
134 | 1 | test("http://server/foo/bar", "double..dotfile"); | |
135 | 1 | test("http://server/foo/bar", "doubledotfile.."); | |
136 | 1 | test("file1", "file2"); | |
137 | 1 | test("dir/file1", "file2"); | |
138 | 1 | test("dir/file1", "../file2"); | |
139 | 1 | test("dir\\file1", "file2"); | |
140 | 1 | test("\\\\srv\\shr\\file", "..\\..\\dummy"); | |
141 | 1 | test("\\\\srv\\shr\\file", "dummy"); | |
142 | 1 | test("\\\\srv\\shr\\file", "\\\\srv2\\shr2\\file2"); | |
143 | 1 | test("\\\\srv\\shr\\file", "d:/file"); | |
144 | 1 | test("C:\\dir\\a", "..\\file"); | |
145 | 1 | test("C:\\dir\\a", "\\\\srv\\shr\\file"); | |
146 | 1 | test("C:\\dir\\a", "d:\\file"); | |
147 | 1 | test("http://a/b", "\\\\srv\\shr\\file"); | |
148 | 1 | test("http://a/b", "//srv/shr/file"); | |
149 | 1 | test("http://a/b", "d:\\file"); | |
150 | 1 | test("http://a/b", "C:/file"); | |
151 | |||
152 | /* From https://tools.ietf.org/html/rfc3986#section-5.4 */ | ||
153 | 1 | test("http://a/b/c/d;p?q", "g:h"); // g:h | |
154 | 1 | test("http://a/b/c/d;p?q", "g"); // http://a/b/c/g | |
155 | 1 | test("http://a/b/c/d;p?q", "./g"); // http://a/b/c/g | |
156 | 1 | test("http://a/b/c/d;p?q", "g/"); // http://a/b/c/g/ | |
157 | 1 | test("http://a/b/c/d;p?q", "/g"); // http://a/g | |
158 | 1 | test("http://a/b/c/d;p?q", "//g"); // http://g | |
159 | 1 | test("http://a/b/c/d;p?q", "?y"); // http://a/b/c/d;p?y | |
160 | 1 | test("http://a/b/c/d;p?q", "g?y"); // http://a/b/c/g?y | |
161 | 1 | test("http://a/b/c/d;p?q", "#s"); // http://a/b/c/d;p?q#s | |
162 | 1 | test("http://a/b/c/d;p?q", "g#s"); // http://a/b/c/g#s | |
163 | 1 | test("http://a/b/c/d;p?q", "g?y#s"); // http://a/b/c/g?y#s | |
164 | 1 | test("http://a/b/c/d;p?q", ";x"); // http://a/b/c/;x | |
165 | 1 | test("http://a/b/c/d;p?q", "g;x"); // http://a/b/c/g;x | |
166 | 1 | test("http://a/b/c/d;p?q", "g;x?y#s"); // http://a/b/c/g;x?y#s | |
167 | 1 | test("http://a/b/c/d;p?q", ""); // http://a/b/c/d;p?q | |
168 | 1 | test("http://a/b/c/d;p?q", "."); // http://a/b/c/ | |
169 | 1 | test("http://a/b/c/d;p?q", "./"); // http://a/b/c/ | |
170 | 1 | test("http://a/b/c/d;p?q", ".."); // http://a/b/ | |
171 | 1 | test("http://a/b/c/d;p?q", "../"); // http://a/b/ | |
172 | 1 | test("http://a/b/c/d;p?q", "../g"); // http://a/b/g | |
173 | 1 | test("http://a/b/c/d;p?q", "../.."); // http://a/ | |
174 | 1 | test("http://a/b/c/d;p?q", "../../"); // http://a/ | |
175 | 1 | test("http://a/b/c/d;p?q", "../../g"); // http://a/g | |
176 | 1 | test("http://a/b/c/d;p?q", "../../../g"); // http://a/g | |
177 | 1 | test("http://a/b/c/d;p?q", "../../../../g"); // http://a/g | |
178 | 1 | test("http://a/b/c/d;p?q", "/./g"); // http://a/g | |
179 | 1 | test("http://a/b/c/d;p?q", "/../g"); // http://a/g | |
180 | 1 | test("http://a/b/c/d;p?q", "g."); // http://a/b/c/g. | |
181 | 1 | test("http://a/b/c/d;p?q", ".g"); // http://a/b/c/.g | |
182 | 1 | test("http://a/b/c/d;p?q", "g.."); // http://a/b/c/g.. | |
183 | 1 | test("http://a/b/c/d;p?q", "..g"); // http://a/b/c/..g | |
184 | 1 | test("http://a/b/c/d;p?q", "./../g"); // http://a/b/g | |
185 | 1 | test("http://a/b/c/d;p?q", "./g/."); // http://a/b/c/g/ | |
186 | 1 | test("http://a/b/c/d;p?q", "g/./h"); // http://a/b/c/g/h | |
187 | 1 | test("http://a/b/c/d;p?q", "g/../h"); // http://a/b/c/h | |
188 | 1 | test("http://a/b/c/d;p?q", "g;x=1/./y"); // http://a/b/c/g;x=1/y | |
189 | 1 | test("http://a/b/c/d;p?q", "g;x=1/../y"); // http://a/b/c/y | |
190 | 1 | test("http://a/b/c/d;p?q", "g?y/./x"); // http://a/b/c/g?y/./x | |
191 | 1 | test("http://a/b/c/d;p?q", "g?y/../x"); // http://a/b/c/g?y/../x | |
192 | 1 | test("http://a/b/c/d;p?q", "g#s/./x"); // http://a/b/c/g#s/./x | |
193 | 1 | test("http://a/b/c/d;p?q", "g#s/../x"); // http://a/b/c/g#s/../x | |
194 | |||
195 | 1 | printf("\nTesting av_url_split:\n"); | |
196 | 1 | test2("/foo/bar"); | |
197 | 1 | test2("http://server/foo/"); | |
198 | 1 | test2("http://example.com/foo/bar"); | |
199 | 1 | test2("http://user:pass@localhost:8080/foo/bar/123"); | |
200 | 1 | test2("http://server/foo/bar?param=value/with/slashes"); | |
201 | 1 | test2("https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8"); | |
202 | 1 | test2("ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg"); | |
203 | 1 | test2("https://key.dns.com?key_id=2&model_id=12345&&access_key="); | |
204 | 1 | test2("http://example.com#tag"); | |
205 | |||
206 | 1 | return 0; | |
207 | } | ||
208 |