* commit 'df9f22d42b0905385629a9d368bb5a1eef2b45ef':
avf: move url utility functions in a separate file
Conflicts:
libavformat/internal.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -90,31 +90,6 @@ void ff_read_frame_flush(AVFormatContext *s); |
90 | 90 |
uint64_t ff_ntp_time(void); |
91 | 91 |
|
92 | 92 |
/** |
93 |
- * Assemble a URL string from components. This is the reverse operation |
|
94 |
- * of av_url_split. |
|
95 |
- * |
|
96 |
- * Note, this requires networking to be initialized, so the caller must |
|
97 |
- * ensure ff_network_init has been called. |
|
98 |
- * |
|
99 |
- * @see av_url_split |
|
100 |
- * |
|
101 |
- * @param str the buffer to fill with the url |
|
102 |
- * @param size the size of the str buffer |
|
103 |
- * @param proto the protocol identifier, if null, the separator |
|
104 |
- * after the identifier is left out, too |
|
105 |
- * @param authorization an optional authorization string, may be null. |
|
106 |
- * An empty string is treated the same as a null string. |
|
107 |
- * @param hostname the host name string |
|
108 |
- * @param port the port number, left out from the string if negative |
|
109 |
- * @param fmt a generic format string for everything to add after the |
|
110 |
- * host/port, may be null |
|
111 |
- * @return the number of characters written to the destination buffer |
|
112 |
- */ |
|
113 |
-int ff_url_join(char *str, int size, const char *proto, |
|
114 |
- const char *authorization, const char *hostname, |
|
115 |
- int port, const char *fmt, ...) av_printf_format(7, 8); |
|
116 |
- |
|
117 |
-/** |
|
118 | 93 |
* Append the media-specific SDP fragment for the media stream c |
119 | 94 |
* to the buffer buff. |
120 | 95 |
* |
... | ... |
@@ -240,17 +215,6 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, |
240 | 240 |
*/ |
241 | 241 |
void ff_reduce_index(AVFormatContext *s, int stream_index); |
242 | 242 |
|
243 |
-/** |
|
244 |
- * Convert a relative url into an absolute url, given a base url. |
|
245 |
- * |
|
246 |
- * @param buf the buffer where output absolute url is written |
|
247 |
- * @param size the size of buf |
|
248 |
- * @param base the base url, may be equal to buf. |
|
249 |
- * @param rel the new url, which is interpreted relative to base |
|
250 |
- */ |
|
251 |
-void ff_make_absolute_url(char *buf, int size, const char *base, |
|
252 |
- const char *rel); |
|
253 |
- |
|
254 | 243 |
enum AVCodecID ff_guess_image2_codec(const char *filename); |
255 | 244 |
|
256 | 245 |
/** |
25 | 25 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,147 @@ |
0 |
+/* |
|
1 |
+ * URL utility functions |
|
2 |
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard |
|
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 |
+ |
|
22 |
+#include "avformat.h" |
|
23 |
+#include "config.h" |
|
24 |
+#include "url.h" |
|
25 |
+#if CONFIG_NETWORK |
|
26 |
+#include "network.h" |
|
27 |
+#endif |
|
28 |
+#include "libavutil/avstring.h" |
|
29 |
+ |
|
30 |
+/** |
|
31 |
+ * @file |
|
32 |
+ * URL utility functions. |
|
33 |
+ */ |
|
34 |
+ |
|
35 |
+int ff_url_join(char *str, int size, const char *proto, |
|
36 |
+ const char *authorization, const char *hostname, |
|
37 |
+ int port, const char *fmt, ...) |
|
38 |
+{ |
|
39 |
+#if CONFIG_NETWORK |
|
40 |
+ struct addrinfo hints = { 0 }, *ai; |
|
41 |
+#endif |
|
42 |
+ |
|
43 |
+ str[0] = '\0'; |
|
44 |
+ if (proto) |
|
45 |
+ av_strlcatf(str, size, "%s://", proto); |
|
46 |
+ if (authorization && authorization[0]) |
|
47 |
+ av_strlcatf(str, size, "%s@", authorization); |
|
48 |
+#if CONFIG_NETWORK && defined(AF_INET6) |
|
49 |
+ /* Determine if hostname is a numerical IPv6 address, |
|
50 |
+ * properly escape it within [] in that case. */ |
|
51 |
+ hints.ai_flags = AI_NUMERICHOST; |
|
52 |
+ if (!getaddrinfo(hostname, NULL, &hints, &ai)) { |
|
53 |
+ if (ai->ai_family == AF_INET6) { |
|
54 |
+ av_strlcat(str, "[", size); |
|
55 |
+ av_strlcat(str, hostname, size); |
|
56 |
+ av_strlcat(str, "]", size); |
|
57 |
+ } else { |
|
58 |
+ av_strlcat(str, hostname, size); |
|
59 |
+ } |
|
60 |
+ freeaddrinfo(ai); |
|
61 |
+ } else |
|
62 |
+#endif |
|
63 |
+ /* Not an IPv6 address, just output the plain string. */ |
|
64 |
+ av_strlcat(str, hostname, size); |
|
65 |
+ |
|
66 |
+ if (port >= 0) |
|
67 |
+ av_strlcatf(str, size, ":%d", port); |
|
68 |
+ if (fmt) { |
|
69 |
+ va_list vl; |
|
70 |
+ int len = strlen(str); |
|
71 |
+ |
|
72 |
+ va_start(vl, fmt); |
|
73 |
+ vsnprintf(str + len, size > len ? size - len : 0, fmt, vl); |
|
74 |
+ va_end(vl); |
|
75 |
+ } |
|
76 |
+ return strlen(str); |
|
77 |
+} |
|
78 |
+ |
|
79 |
+void ff_make_absolute_url(char *buf, int size, const char *base, |
|
80 |
+ const char *rel) |
|
81 |
+{ |
|
82 |
+ char *sep, *path_query; |
|
83 |
+ /* Absolute path, relative to the current server */ |
|
84 |
+ if (base && strstr(base, "://") && rel[0] == '/') { |
|
85 |
+ if (base != buf) |
|
86 |
+ av_strlcpy(buf, base, size); |
|
87 |
+ sep = strstr(buf, "://"); |
|
88 |
+ if (sep) { |
|
89 |
+ /* Take scheme from base url */ |
|
90 |
+ if (rel[1] == '/') { |
|
91 |
+ sep[1] = '\0'; |
|
92 |
+ } else { |
|
93 |
+ /* Take scheme and host from base url */ |
|
94 |
+ sep += 3; |
|
95 |
+ sep = strchr(sep, '/'); |
|
96 |
+ if (sep) |
|
97 |
+ *sep = '\0'; |
|
98 |
+ } |
|
99 |
+ } |
|
100 |
+ av_strlcat(buf, rel, size); |
|
101 |
+ return; |
|
102 |
+ } |
|
103 |
+ /* If rel actually is an absolute url, just copy it */ |
|
104 |
+ if (!base || strstr(rel, "://") || rel[0] == '/') { |
|
105 |
+ av_strlcpy(buf, rel, size); |
|
106 |
+ return; |
|
107 |
+ } |
|
108 |
+ if (base != buf) |
|
109 |
+ av_strlcpy(buf, base, size); |
|
110 |
+ |
|
111 |
+ /* Strip off any query string from base */ |
|
112 |
+ path_query = strchr(buf, '?'); |
|
113 |
+ if (path_query != NULL) |
|
114 |
+ *path_query = '\0'; |
|
115 |
+ |
|
116 |
+ /* Is relative path just a new query part? */ |
|
117 |
+ if (rel[0] == '?') { |
|
118 |
+ av_strlcat(buf, rel, size); |
|
119 |
+ return; |
|
120 |
+ } |
|
121 |
+ |
|
122 |
+ /* Remove the file name from the base url */ |
|
123 |
+ sep = strrchr(buf, '/'); |
|
124 |
+ if (sep) |
|
125 |
+ sep[1] = '\0'; |
|
126 |
+ else |
|
127 |
+ buf[0] = '\0'; |
|
128 |
+ while (av_strstart(rel, "../", NULL) && sep) { |
|
129 |
+ /* Remove the path delimiter at the end */ |
|
130 |
+ sep[0] = '\0'; |
|
131 |
+ sep = strrchr(buf, '/'); |
|
132 |
+ /* If the next directory name to pop off is "..", break here */ |
|
133 |
+ if (!strcmp(sep ? &sep[1] : buf, "..")) { |
|
134 |
+ /* Readd the slash we just removed */ |
|
135 |
+ av_strlcat(buf, "/", size); |
|
136 |
+ break; |
|
137 |
+ } |
|
138 |
+ /* Cut off the directory name */ |
|
139 |
+ if (sep) |
|
140 |
+ sep[1] = '\0'; |
|
141 |
+ else |
|
142 |
+ buf[0] = '\0'; |
|
143 |
+ rel += 3; |
|
144 |
+ } |
|
145 |
+ av_strlcat(buf, rel, size); |
|
146 |
+} |
... | ... |
@@ -248,4 +248,41 @@ URLProtocol *ffurl_protocol_next(URLProtocol *prev); |
248 | 248 |
int ff_udp_set_remote_url(URLContext *h, const char *uri); |
249 | 249 |
int ff_udp_get_local_port(URLContext *h); |
250 | 250 |
|
251 |
+/** |
|
252 |
+ * Assemble a URL string from components. This is the reverse operation |
|
253 |
+ * of av_url_split. |
|
254 |
+ * |
|
255 |
+ * Note, this requires networking to be initialized, so the caller must |
|
256 |
+ * ensure ff_network_init has been called. |
|
257 |
+ * |
|
258 |
+ * @see av_url_split |
|
259 |
+ * |
|
260 |
+ * @param str the buffer to fill with the url |
|
261 |
+ * @param size the size of the str buffer |
|
262 |
+ * @param proto the protocol identifier, if null, the separator |
|
263 |
+ * after the identifier is left out, too |
|
264 |
+ * @param authorization an optional authorization string, may be null. |
|
265 |
+ * An empty string is treated the same as a null string. |
|
266 |
+ * @param hostname the host name string |
|
267 |
+ * @param port the port number, left out from the string if negative |
|
268 |
+ * @param fmt a generic format string for everything to add after the |
|
269 |
+ * host/port, may be null |
|
270 |
+ * @return the number of characters written to the destination buffer |
|
271 |
+ */ |
|
272 |
+int ff_url_join(char *str, int size, const char *proto, |
|
273 |
+ const char *authorization, const char *hostname, |
|
274 |
+ int port, const char *fmt, ...) av_printf_format(7, 8); |
|
275 |
+ |
|
276 |
+/** |
|
277 |
+ * Convert a relative url into an absolute url, given a base url. |
|
278 |
+ * |
|
279 |
+ * @param buf the buffer where output absolute url is written |
|
280 |
+ * @param size the size of buf |
|
281 |
+ * @param base the base url, may be equal to buf. |
|
282 |
+ * @param rel the new url, which is interpreted relative to base |
|
283 |
+ */ |
|
284 |
+void ff_make_absolute_url(char *buf, int size, const char *base, |
|
285 |
+ const char *rel); |
|
286 |
+ |
|
287 |
+ |
|
251 | 288 |
#endif /* AVFORMAT_URL_H */ |
... | ... |
@@ -3840,50 +3840,6 @@ void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, |
3840 | 3840 |
s->pts_wrap_bits = pts_wrap_bits; |
3841 | 3841 |
} |
3842 | 3842 |
|
3843 |
-int ff_url_join(char *str, int size, const char *proto, |
|
3844 |
- const char *authorization, const char *hostname, |
|
3845 |
- int port, const char *fmt, ...) |
|
3846 |
-{ |
|
3847 |
-#if CONFIG_NETWORK |
|
3848 |
- struct addrinfo hints = { 0 }, *ai; |
|
3849 |
-#endif |
|
3850 |
- |
|
3851 |
- str[0] = '\0'; |
|
3852 |
- if (proto) |
|
3853 |
- av_strlcatf(str, size, "%s://", proto); |
|
3854 |
- if (authorization && authorization[0]) |
|
3855 |
- av_strlcatf(str, size, "%s@", authorization); |
|
3856 |
-#if CONFIG_NETWORK && defined(AF_INET6) |
|
3857 |
- /* Determine if hostname is a numerical IPv6 address, |
|
3858 |
- * properly escape it within [] in that case. */ |
|
3859 |
- hints.ai_flags = AI_NUMERICHOST; |
|
3860 |
- if (!getaddrinfo(hostname, NULL, &hints, &ai)) { |
|
3861 |
- if (ai->ai_family == AF_INET6) { |
|
3862 |
- av_strlcat(str, "[", size); |
|
3863 |
- av_strlcat(str, hostname, size); |
|
3864 |
- av_strlcat(str, "]", size); |
|
3865 |
- } else { |
|
3866 |
- av_strlcat(str, hostname, size); |
|
3867 |
- } |
|
3868 |
- freeaddrinfo(ai); |
|
3869 |
- } else |
|
3870 |
-#endif |
|
3871 |
- /* Not an IPv6 address, just output the plain string. */ |
|
3872 |
- av_strlcat(str, hostname, size); |
|
3873 |
- |
|
3874 |
- if (port >= 0) |
|
3875 |
- av_strlcatf(str, size, ":%d", port); |
|
3876 |
- if (fmt) { |
|
3877 |
- va_list vl; |
|
3878 |
- int len = strlen(str); |
|
3879 |
- |
|
3880 |
- va_start(vl, fmt); |
|
3881 |
- vsnprintf(str + len, size > len ? size - len : 0, fmt, vl); |
|
3882 |
- va_end(vl); |
|
3883 |
- } |
|
3884 |
- return strlen(str); |
|
3885 |
-} |
|
3886 |
- |
|
3887 | 3843 |
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, |
3888 | 3844 |
void *context) |
3889 | 3845 |
{ |
... | ... |
@@ -3948,75 +3904,6 @@ int ff_find_stream_index(AVFormatContext *s, int id) |
3948 | 3948 |
return -1; |
3949 | 3949 |
} |
3950 | 3950 |
|
3951 |
-void ff_make_absolute_url(char *buf, int size, const char *base, |
|
3952 |
- const char *rel) |
|
3953 |
-{ |
|
3954 |
- char *sep, *path_query; |
|
3955 |
- /* Absolute path, relative to the current server */ |
|
3956 |
- if (base && strstr(base, "://") && rel[0] == '/') { |
|
3957 |
- if (base != buf) |
|
3958 |
- av_strlcpy(buf, base, size); |
|
3959 |
- sep = strstr(buf, "://"); |
|
3960 |
- if (sep) { |
|
3961 |
- /* Take scheme from base url */ |
|
3962 |
- if (rel[1] == '/') { |
|
3963 |
- sep[1] = '\0'; |
|
3964 |
- } else { |
|
3965 |
- /* Take scheme and host from base url */ |
|
3966 |
- sep += 3; |
|
3967 |
- sep = strchr(sep, '/'); |
|
3968 |
- if (sep) |
|
3969 |
- *sep = '\0'; |
|
3970 |
- } |
|
3971 |
- } |
|
3972 |
- av_strlcat(buf, rel, size); |
|
3973 |
- return; |
|
3974 |
- } |
|
3975 |
- /* If rel actually is an absolute url, just copy it */ |
|
3976 |
- if (!base || strstr(rel, "://") || rel[0] == '/') { |
|
3977 |
- av_strlcpy(buf, rel, size); |
|
3978 |
- return; |
|
3979 |
- } |
|
3980 |
- if (base != buf) |
|
3981 |
- av_strlcpy(buf, base, size); |
|
3982 |
- |
|
3983 |
- /* Strip off any query string from base */ |
|
3984 |
- path_query = strchr(buf, '?'); |
|
3985 |
- if (path_query != NULL) |
|
3986 |
- *path_query = '\0'; |
|
3987 |
- |
|
3988 |
- /* Is relative path just a new query part? */ |
|
3989 |
- if (rel[0] == '?') { |
|
3990 |
- av_strlcat(buf, rel, size); |
|
3991 |
- return; |
|
3992 |
- } |
|
3993 |
- |
|
3994 |
- /* Remove the file name from the base url */ |
|
3995 |
- sep = strrchr(buf, '/'); |
|
3996 |
- if (sep) |
|
3997 |
- sep[1] = '\0'; |
|
3998 |
- else |
|
3999 |
- buf[0] = '\0'; |
|
4000 |
- while (av_strstart(rel, "../", NULL) && sep) { |
|
4001 |
- /* Remove the path delimiter at the end */ |
|
4002 |
- sep[0] = '\0'; |
|
4003 |
- sep = strrchr(buf, '/'); |
|
4004 |
- /* If the next directory name to pop off is "..", break here */ |
|
4005 |
- if (!strcmp(sep ? &sep[1] : buf, "..")) { |
|
4006 |
- /* Readd the slash we just removed */ |
|
4007 |
- av_strlcat(buf, "/", size); |
|
4008 |
- break; |
|
4009 |
- } |
|
4010 |
- /* Cut off the directory name */ |
|
4011 |
- if (sep) |
|
4012 |
- sep[1] = '\0'; |
|
4013 |
- else |
|
4014 |
- buf[0] = '\0'; |
|
4015 |
- rel += 3; |
|
4016 |
- } |
|
4017 |
- av_strlcat(buf, rel, size); |
|
4018 |
-} |
|
4019 |
- |
|
4020 | 3951 |
int64_t ff_iso8601_to_unix_time(const char *datestr) |
4021 | 3952 |
{ |
4022 | 3953 |
struct tm time1 = {0}, time2 = {0}; |