Unified · Split
| @@ -18,6 +18,7 @@ · 17 unmodified lines | |||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #include "config.h" | ||
| 21 | #include "libavformat/url.h" | 22 | #include "libavformat/url.h" |
| 22 | #include "libavformat/avformat.h" | 23 | #include "libavformat/avformat.h" |
| 23 | 24 | ||
| @@ -48,19 +49,30 @@ static void test_decompose(const char *url) · 24 unmodified lines | |||
| 48 | 49 | ||
| 49 | static void test(const char *base, const char *rel) | 50 | static void test(const char *base, const char *rel) |
| 50 | { | 51 | { |
| 51 | char buf[200], buf2[200]; | 52 | char buf[200], buf2[200], buf_dos[200], buf_native[200]; |
| 52 | int ret; | 53 | int ret; |
| 53 | 54 | ||
| 54 | ret = ff_make_absolute_url(buf, sizeof(buf), base, rel); | 55 | ret = ff_make_absolute_url2(buf, sizeof(buf), base, rel, 0); |
| 55 | if (ret < 0) { | 56 | if (ret < 0) { |
| 56 | printf("%50s %-20s => error %s\n", base, rel, av_err2str(ret)); | 57 | printf("%50s %-20s => error %s\n", base, rel, av_err2str(ret)); |
| 57 | return; | 58 | return; |
| 58 | } | 59 | } |
| 59 | printf("%50s %-20s => %s\n", base, rel, buf); | 60 | printf("%50s %-20s => %s\n", base, rel, buf); |
| 61 | ret = ff_make_absolute_url2(buf_dos, sizeof(buf_dos), base, rel, 1); | ||
| 62 | if (ret < 0) | ||
| 63 | snprintf(buf_dos, sizeof(buf_dos), "error %s", av_err2str(ret)); | ||
| 64 | ret = ff_make_absolute_url(buf_native, sizeof(buf_native), base, rel); | ||
| 65 | if (ret < 0) | ||
| 66 | snprintf(buf_native, sizeof(buf_native), "error %s", av_err2str(ret)); | ||
| 67 | if (strcmp(buf, buf_dos)) | ||
| 68 | printf("%50s %-20sDOS %s\n", base, rel, buf_dos); | ||
| 69 | if (HAVE_DOS_PATHS && strcmp(buf_dos, buf_native) || | ||
| 70 | !HAVE_DOS_PATHS && strcmp(buf, buf_native)) | ||
| 71 | printf("Native mismatch\n"); | ||
| 60 | if (base) { | 72 | if (base) { |
| 61 | /* Test in-buffer replacement */ | 73 | /* Test in-buffer replacement */ |
| 62 | snprintf(buf2, sizeof(buf2), "%s", base); | 74 | snprintf(buf2, sizeof(buf2), "%s", base); |
| 63 | ff_make_absolute_url(buf2, sizeof(buf2), buf2, rel); | 75 | ff_make_absolute_url2(buf2, sizeof(buf2), buf2, rel, 0); |
| 64 | if (strcmp(buf, buf2)) { | 76 | if (strcmp(buf, buf2)) { |
| 65 | printf("In-place handling of %s + %s failed\n", base, rel); | 77 | printf("In-place handling of %s + %s failed\n", base, rel); |
| 66 | exit(1); | 78 | exit(1); |
| @@ -121,6 +133,21 @@ int main(void) · 54 unmodified lines | |||
| 121 | test("http://server/foo/bar", "..doubledotfile"); | 133 | test("http://server/foo/bar", "..doubledotfile"); |
| 122 | test("http://server/foo/bar", "double..dotfile"); | 134 | test("http://server/foo/bar", "double..dotfile"); |
| 123 | test("http://server/foo/bar", "doubledotfile.."); | 135 | test("http://server/foo/bar", "doubledotfile.."); |
| 136 | test("file1", "file2"); | ||
| 137 | test("dir/file1", "file2"); | ||
| 138 | test("dir/file1", "../file2"); | ||
| 139 | test("dir\\file1", "file2"); | ||
| 140 | test("\\\\srv\\shr\\file", "..\\..\\dummy"); | ||
| 141 | test("\\\\srv\\shr\\file", "dummy"); | ||
| 142 | test("\\\\srv\\shr\\file", "\\\\srv2\\shr2\\file2"); | ||
| 143 | test("\\\\srv\\shr\\file", "d:/file"); | ||
| 144 | test("C:\\dir\\a", "..\\file"); | ||
| 145 | test("C:\\dir\\a", "\\\\srv\\shr\\file"); | ||
| 146 | test("C:\\dir\\a", "d:\\file"); | ||
| 147 | test("http://a/b", "\\\\srv\\shr\\file"); | ||
| 148 | test("http://a/b", "//srv/shr/file"); | ||
| 149 | test("http://a/b", "d:\\file"); | ||
| 150 | test("http://a/b", "C:/file"); | ||
| 124 | 151 | ||
| 125 | /* From https://tools.ietf.org/html/rfc3986#section-5.4 */ | 152 | /* From https://tools.ietf.org/html/rfc3986#section-5.4 */ |
| 126 | test("http://a/b/c/d;p?q", "g:h"); // g:h | 153 | test("http://a/b/c/d;p?q", "g:h"); // g:h |
| @@ -190,8 +190,8 @@ static int append_path(char *root, char *out_end, char **rout, · 189 unmodified lines | |||
| 190 | return 0; | 190 | return 0; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | int ff_make_absolute_url(char *buf, int size, const char *base, | 193 | int ff_make_absolute_url2(char *buf, int size, const char *base, |
| 194 | const char *rel) | 194 | const char *rel, int handle_dos_paths) |
| 195 | { | 195 | { |
| 196 | URLComponents ub, uc; | 196 | URLComponents ub, uc; |
| 197 | char *out, *out_end, *path; | 197 | char *out, *out_end, *path; |
| @@ -224,7 +224,7 @@ int ff_make_absolute_url(char *buf, int size, const char *base, · 26 unmodified lines | |||
| 224 | 224 | ||
| 225 | if (!base) | 225 | if (!base) |
| 226 | base = ""; | 226 | base = ""; |
| 227 | if (HAVE_DOS_PATHS) { | 227 | if (handle_dos_paths) { |
| 228 | if ((ret = ff_url_decompose(&ub, base, NULL)) < 0) | 228 | if ((ret = ff_url_decompose(&ub, base, NULL)) < 0) |
| 229 | goto error; | 229 | goto error; |
| 230 | if (is_fq_dos_path(base) || av_strstart(base, "file:", NULL) || ub.path == ub.url) { | 230 | if (is_fq_dos_path(base) || av_strstart(base, "file:", NULL) || ub.path == ub.url) { |
| @@ -316,6 +316,12 @@ error: · 85 unmodified lines | |||
| 316 | return ret; | 316 | return ret; |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | int ff_make_absolute_url(char *buf, int size, const char *base, | ||
| 320 | const char *rel) | ||
| 321 | { | ||
| 322 | return ff_make_absolute_url2(buf, size, base, rel, HAVE_DOS_PATHS); | ||
| 323 | } | ||
| 324 | |||
| 319 | AVIODirEntry *ff_alloc_dir_entry(void) | 325 | AVIODirEntry *ff_alloc_dir_entry(void) |
| 320 | { | 326 | { |
| 321 | AVIODirEntry *entry = av_mallocz(sizeof(AVIODirEntry)); | 327 | AVIODirEntry *entry = av_mallocz(sizeof(AVIODirEntry)); |
| @@ -308,6 +308,16 @@ int ff_url_join(char *str, int size, const char *proto, · 307 unmodified lines | |||
| 308 | * @param size the size of buf | 308 | * @param size the size of buf |
| 309 | * @param base the base url, may be equal to buf. | 309 | * @param base the base url, may be equal to buf. |
| 310 | * @param rel the new url, which is interpreted relative to base | 310 | * @param rel the new url, which is interpreted relative to base |
| 311 | * @param handle_dos_paths handle DOS paths for file or unspecified protocol | ||
| 312 | */ | ||
| 313 | int ff_make_absolute_url2(char *buf, int size, const char *base, | ||
| 314 | const char *rel, int handle_dos_paths); | ||
| 315 | |||
| 316 | /** | ||
| 317 | * Convert a relative url into an absolute url, given a base url. | ||
| 318 | * | ||
| 319 | * Same as ff_make_absolute_url2 with handle_dos_paths being equal to | ||
| 320 | * HAVE_DOS_PATHS config variable. | ||
| 311 | */ | 321 | */ |
| 312 | int ff_make_absolute_url(char *buf, int size, const char *base, | 322 | int ff_make_absolute_url(char *buf, int size, const char *base, |
| 313 | const char *rel); | 323 | const char *rel); |
| @@ -79,6 +79,26 @@ Testing ff_make_absolute_url: · 78 unmodified lines | |||
| 79 | http://server/foo/bar ..doubledotfile => http://server/foo/..doubledotfile | 79 | http://server/foo/bar ..doubledotfile => http://server/foo/..doubledotfile |
| 80 | http://server/foo/bar double..dotfile => http://server/foo/double..dotfile | 80 | http://server/foo/bar double..dotfile => http://server/foo/double..dotfile |
| 81 | http://server/foo/bar doubledotfile.. => http://server/foo/doubledotfile.. | 81 | http://server/foo/bar doubledotfile.. => http://server/foo/doubledotfile.. |
| 82 | file1 file2 => file2 | ||
| 83 | dir/file1 file2 => dir/file2 | ||
| 84 | dir/file1 ../file2 => dir/../file2 | ||
| 85 | dir\file1 file2 => file2 | ||
| 86 | dir\file1 file2 DOS dir\file2 | ||
| 87 | \\srv\shr\file ..\..\dummy => ..\..\dummy | ||
| 88 | \\srv\shr\file ..\..\dummy DOS \\srv\shr\..\..\dummy | ||
| 89 | \\srv\shr\file dummy => dummy | ||
| 90 | \\srv\shr\file dummy DOS \\srv\shr\dummy | ||
| 91 | \\srv\shr\file \\srv2\shr2\file2 => \\srv2\shr2\file2 | ||
| 92 | \\srv\shr\file d:/file => d:/file | ||
| 93 | C:\dir\a ..\file => C:..\file | ||
| 94 | C:\dir\a ..\file DOS C:\dir\..\file | ||
| 95 | C:\dir\a \\srv\shr\file => C:\\srv\shr\file | ||
| 96 | C:\dir\a \\srv\shr\file DOS \\srv\shr\file | ||
| 97 | C:\dir\a d:\file => d:\file | ||
| 98 | http://a/b \\srv\shr\file => http://a/\\srv\shr\file | ||
| 99 | http://a/b //srv/shr/file => http://srv/shr/file | ||
| 100 | http://a/b d:\file => d:\file | ||
| 101 | http://a/b C:/file => C:/file | ||
| 82 | http://a/b/c/d;p?q g:h => g:h | 102 | http://a/b/c/d;p?q g:h => g:h |
| 83 | http://a/b/c/d;p?q g => http://a/b/c/g | 103 | http://a/b/c/d;p?q g => http://a/b/c/g |
| 84 | http://a/b/c/d;p?q ./g => http://a/b/c/g | 104 | http://a/b/c/d;p?q ./g => http://a/b/c/g |