You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
7.0KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libavutil/avstring.h"
  20. #include "libavutil/mem.h"
  21. #include "url.h"
  22. extern const URLProtocol ff_async_protocol;
  23. extern const URLProtocol ff_bluray_protocol;
  24. extern const URLProtocol ff_cache_protocol;
  25. extern const URLProtocol ff_concat_protocol;
  26. extern const URLProtocol ff_crypto_protocol;
  27. extern const URLProtocol ff_data_protocol;
  28. extern const URLProtocol ff_ffrtmpcrypt_protocol;
  29. extern const URLProtocol ff_ffrtmphttp_protocol;
  30. extern const URLProtocol ff_file_protocol;
  31. extern const URLProtocol ff_ftp_protocol;
  32. extern const URLProtocol ff_gopher_protocol;
  33. extern const URLProtocol ff_hls_protocol;
  34. extern const URLProtocol ff_http_protocol;
  35. extern const URLProtocol ff_httpproxy_protocol;
  36. extern const URLProtocol ff_https_protocol;
  37. extern const URLProtocol ff_icecast_protocol;
  38. extern const URLProtocol ff_mmsh_protocol;
  39. extern const URLProtocol ff_mmst_protocol;
  40. extern const URLProtocol ff_md5_protocol;
  41. extern const URLProtocol ff_pipe_protocol;
  42. extern const URLProtocol ff_rtmp_protocol;
  43. extern const URLProtocol ff_rtmpe_protocol;
  44. extern const URLProtocol ff_rtmps_protocol;
  45. extern const URLProtocol ff_rtmpt_protocol;
  46. extern const URLProtocol ff_rtmpte_protocol;
  47. extern const URLProtocol ff_rtmpts_protocol;
  48. extern const URLProtocol ff_rtp_protocol;
  49. extern const URLProtocol ff_sctp_protocol;
  50. extern const URLProtocol ff_srtp_protocol;
  51. extern const URLProtocol ff_subfile_protocol;
  52. extern const URLProtocol ff_tcp_protocol;
  53. extern const URLProtocol ff_tls_gnutls_protocol;
  54. extern const URLProtocol ff_tls_schannel_protocol;
  55. extern const URLProtocol ff_tls_securetransport_protocol;
  56. extern const URLProtocol ff_tls_openssl_protocol;
  57. extern const URLProtocol ff_udp_protocol;
  58. extern const URLProtocol ff_udplite_protocol;
  59. extern const URLProtocol ff_unix_protocol;
  60. extern const URLProtocol ff_librtmp_protocol;
  61. extern const URLProtocol ff_librtmpe_protocol;
  62. extern const URLProtocol ff_librtmps_protocol;
  63. extern const URLProtocol ff_librtmpt_protocol;
  64. extern const URLProtocol ff_librtmpte_protocol;
  65. extern const URLProtocol ff_libssh_protocol;
  66. extern const URLProtocol ff_libsmbclient_protocol;
  67. static const URLProtocol *url_protocols[] = {
  68. #if CONFIG_ASYNC_PROTOCOL
  69. &ff_async_protocol,
  70. #endif
  71. #if CONFIG_BLURAY_PROTOCOL
  72. &ff_bluray_protocol,
  73. #endif
  74. #if CONFIG_CACHE_PROTOCOL
  75. &ff_cache_protocol,
  76. #endif
  77. #if CONFIG_CONCAT_PROTOCOL
  78. &ff_concat_protocol,
  79. #endif
  80. #if CONFIG_CRYPTO_PROTOCOL
  81. &ff_crypto_protocol,
  82. #endif
  83. #if CONFIG_DATA_PROTOCOL
  84. &ff_data_protocol,
  85. #endif
  86. #if CONFIG_FFRTMPCRYPT_PROTOCOL
  87. &ff_ffrtmpcrypt_protocol,
  88. #endif
  89. #if CONFIG_FFRTMPHTTP_PROTOCOL
  90. &ff_ffrtmphttp_protocol,
  91. #endif
  92. #if CONFIG_FILE_PROTOCOL
  93. &ff_file_protocol,
  94. #endif
  95. #if CONFIG_FTP_PROTOCOL
  96. &ff_ftp_protocol,
  97. #endif
  98. #if CONFIG_GOPHER_PROTOCOL
  99. &ff_gopher_protocol,
  100. #endif
  101. #if CONFIG_HLS_PROTOCOL
  102. &ff_hls_protocol,
  103. #endif
  104. #if CONFIG_HTTP_PROTOCOL
  105. &ff_http_protocol,
  106. #endif
  107. #if CONFIG_HTTPPROXY_PROTOCOL
  108. &ff_httpproxy_protocol,
  109. #endif
  110. #if CONFIG_HTTPS_PROTOCOL
  111. &ff_https_protocol,
  112. #endif
  113. #if CONFIG_ICECAST_PROTOCOL
  114. &ff_icecast_protocol,
  115. #endif
  116. #if CONFIG_MMSH_PROTOCOL
  117. &ff_mmsh_protocol,
  118. #endif
  119. #if CONFIG_MMST_PROTOCOL
  120. &ff_mmst_protocol,
  121. #endif
  122. #if CONFIG_MD5_PROTOCOL
  123. &ff_md5_protocol,
  124. #endif
  125. #if CONFIG_PIPE_PROTOCOL
  126. &ff_pipe_protocol,
  127. #endif
  128. #if CONFIG_RTMP_PROTOCOL
  129. &ff_rtmp_protocol,
  130. #endif
  131. #if CONFIG_RTMPE_PROTOCOL
  132. &ff_rtmpe_protocol,
  133. #endif
  134. #if CONFIG_RTMPS_PROTOCOL
  135. &ff_rtmps_protocol,
  136. #endif
  137. #if CONFIG_RTMPT_PROTOCOL
  138. &ff_rtmpt_protocol,
  139. #endif
  140. #if CONFIG_RTMPTE_PROTOCOL
  141. &ff_rtmpte_protocol,
  142. #endif
  143. #if CONFIG_RTMPTS_PROTOCOL
  144. &ff_rtmpts_protocol,
  145. #endif
  146. #if CONFIG_RTP_PROTOCOL
  147. &ff_rtp_protocol,
  148. #endif
  149. #if CONFIG_SCTP_PROTOCOL
  150. &ff_sctp_protocol,
  151. #endif
  152. #if CONFIG_SRTP_PROTOCOL
  153. &ff_srtp_protocol,
  154. #endif
  155. #if CONFIG_SUBFILE_PROTOCOL
  156. &ff_subfile_protocol,
  157. #endif
  158. #if CONFIG_TCP_PROTOCOL
  159. &ff_tcp_protocol,
  160. #endif
  161. #if CONFIG_TLS_GNUTLS_PROTOCOL
  162. &ff_tls_gnutls_protocol,
  163. #endif
  164. #if CONFIG_TLS_SCHANNEL_PROTOCOL
  165. &ff_tls_schannel_protocol,
  166. #endif
  167. #if CONFIG_TLS_SECURETRANSPORT_PROTOCOL
  168. &ff_tls_securetransport_protocol,
  169. #endif
  170. #if CONFIG_TLS_OPENSSL_PROTOCOL
  171. &ff_tls_openssl_protocol,
  172. #endif
  173. #if CONFIG_UDP_PROTOCOL
  174. &ff_udp_protocol,
  175. #endif
  176. #if CONFIG_UDPLITE_PROTOCOL
  177. &ff_udplite_protocol,
  178. #endif
  179. #if CONFIG_UNIX_PROTOCOL
  180. &ff_unix_protocol,
  181. #endif
  182. /* external libraries */
  183. #if CONFIG_LIBRTMP_PROTOCOL
  184. &ff_librtmp_protocol,
  185. #endif
  186. #if CONFIG_LIBRTMPE_PROTOCOL
  187. &ff_librtmpe_protocol,
  188. #endif
  189. #if CONFIG_LIBRTMPS_PROTOCOL
  190. &ff_librtmps_protocol,
  191. #endif
  192. #if CONFIG_LIBRTMPT_PROTOCOL
  193. &ff_librtmpt_protocol,
  194. #endif
  195. #if CONFIG_LIBRTMPTE_PROTOCOL
  196. &ff_librtmpte_protocol,
  197. #endif
  198. #if CONFIG_LIBSSH_PROTOCOL
  199. &ff_libssh_protocol,
  200. #endif
  201. #if CONFIG_LIBSMBCLIENT_PROTOCOL
  202. &ff_libsmbclient_protocol,
  203. #endif
  204. NULL,
  205. };
  206. const AVClass *ff_urlcontext_child_class_next(const AVClass *prev)
  207. {
  208. int i;
  209. /* find the protocol that corresponds to prev */
  210. for (i = 0; url_protocols[i]; i++) {
  211. if (url_protocols[i]->priv_data_class == prev) {
  212. i++;
  213. break;
  214. }
  215. }
  216. /* find next protocol with priv options */
  217. for (; url_protocols[i]; i++)
  218. if (url_protocols[i]->priv_data_class)
  219. return url_protocols[i]->priv_data_class;
  220. return NULL;
  221. }
  222. const char *avio_enum_protocols(void **opaque, int output)
  223. {
  224. const URLProtocol **p = *opaque;
  225. p = p ? p + 1 : url_protocols;
  226. *opaque = p;
  227. if (!*p) {
  228. *opaque = NULL;
  229. return NULL;
  230. }
  231. if ((output && (*p)->url_write) || (!output && (*p)->url_read))
  232. return (*p)->name;
  233. return avio_enum_protocols(opaque, output);
  234. }
  235. const URLProtocol **ffurl_get_protocols(const char *whitelist,
  236. const char *blacklist)
  237. {
  238. const URLProtocol **ret;
  239. int i, ret_idx = 0;
  240. ret = av_mallocz_array(FF_ARRAY_ELEMS(url_protocols), sizeof(*ret));
  241. if (!ret)
  242. return NULL;
  243. for (i = 0; url_protocols[i]; i++) {
  244. const URLProtocol *up = url_protocols[i];
  245. if (whitelist && *whitelist && !av_match_name(up->name, whitelist))
  246. continue;
  247. if (blacklist && *blacklist && av_match_name(up->name, blacklist))
  248. continue;
  249. ret[ret_idx++] = up;
  250. }
  251. return ret;
  252. }