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.

671 lines
20KB

  1. /*
  2. * unbuffered I/O
  3. * Copyright (c) 2001 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avstring.h"
  22. #include "libavutil/dict.h"
  23. #include "libavutil/opt.h"
  24. #include "libavutil/time.h"
  25. #include "libavutil/avassert.h"
  26. #include "os_support.h"
  27. #include "avformat.h"
  28. #if CONFIG_NETWORK
  29. #include "network.h"
  30. #endif
  31. #include "url.h"
  32. /** @name Logging context. */
  33. /*@{*/
  34. static const char *urlcontext_to_name(void *ptr)
  35. {
  36. URLContext *h = (URLContext *)ptr;
  37. if (h->prot)
  38. return h->prot->name;
  39. else
  40. return "NULL";
  41. }
  42. static void *urlcontext_child_next(void *obj, void *prev)
  43. {
  44. URLContext *h = obj;
  45. if (!prev && h->priv_data && h->prot->priv_data_class)
  46. return h->priv_data;
  47. return NULL;
  48. }
  49. #define OFFSET(x) offsetof(URLContext,x)
  50. #define E AV_OPT_FLAG_ENCODING_PARAM
  51. #define D AV_OPT_FLAG_DECODING_PARAM
  52. static const AVOption options[] = {
  53. {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
  54. {"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
  55. {"rw_timeout", "Timeout for IO operations (in microseconds)", offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
  56. { NULL }
  57. };
  58. const AVClass ffurl_context_class = {
  59. .class_name = "URLContext",
  60. .item_name = urlcontext_to_name,
  61. .option = options,
  62. .version = LIBAVUTIL_VERSION_INT,
  63. .child_next = urlcontext_child_next,
  64. .child_class_next = ff_urlcontext_child_class_next,
  65. };
  66. /*@}*/
  67. static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
  68. const char *filename, int flags,
  69. const AVIOInterruptCB *int_cb)
  70. {
  71. URLContext *uc;
  72. int err;
  73. #if CONFIG_NETWORK
  74. if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init())
  75. return AVERROR(EIO);
  76. #endif
  77. if ((flags & AVIO_FLAG_READ) && !up->url_read) {
  78. av_log(NULL, AV_LOG_ERROR,
  79. "Impossible to open the '%s' protocol for reading\n", up->name);
  80. return AVERROR(EIO);
  81. }
  82. if ((flags & AVIO_FLAG_WRITE) && !up->url_write) {
  83. av_log(NULL, AV_LOG_ERROR,
  84. "Impossible to open the '%s' protocol for writing\n", up->name);
  85. return AVERROR(EIO);
  86. }
  87. uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
  88. if (!uc) {
  89. err = AVERROR(ENOMEM);
  90. goto fail;
  91. }
  92. uc->av_class = &ffurl_context_class;
  93. uc->filename = (char *)&uc[1];
  94. strcpy(uc->filename, filename);
  95. uc->prot = up;
  96. uc->flags = flags;
  97. uc->is_streamed = 0; /* default = not streamed */
  98. uc->max_packet_size = 0; /* default: stream file */
  99. if (up->priv_data_size) {
  100. uc->priv_data = av_mallocz(up->priv_data_size);
  101. if (!uc->priv_data) {
  102. err = AVERROR(ENOMEM);
  103. goto fail;
  104. }
  105. if (up->priv_data_class) {
  106. int proto_len= strlen(up->name);
  107. char *start = strchr(uc->filename, ',');
  108. *(const AVClass **)uc->priv_data = up->priv_data_class;
  109. av_opt_set_defaults(uc->priv_data);
  110. if(!strncmp(up->name, uc->filename, proto_len) && uc->filename + proto_len == start){
  111. int ret= 0;
  112. char *p= start;
  113. char sep= *++p;
  114. char *key, *val;
  115. p++;
  116. if (strcmp(up->name, "subfile"))
  117. ret = AVERROR(EINVAL);
  118. while(ret >= 0 && (key= strchr(p, sep)) && p<key && (val = strchr(key+1, sep))){
  119. *val= *key= 0;
  120. if (strcmp(p, "start") && strcmp(p, "end")) {
  121. ret = AVERROR_OPTION_NOT_FOUND;
  122. } else
  123. ret= av_opt_set(uc->priv_data, p, key+1, 0);
  124. if (ret == AVERROR_OPTION_NOT_FOUND)
  125. av_log(uc, AV_LOG_ERROR, "Key '%s' not found.\n", p);
  126. *val= *key= sep;
  127. p= val+1;
  128. }
  129. if(ret<0 || p!=key){
  130. av_log(uc, AV_LOG_ERROR, "Error parsing options string %s\n", start);
  131. av_freep(&uc->priv_data);
  132. av_freep(&uc);
  133. err = AVERROR(EINVAL);
  134. goto fail;
  135. }
  136. memmove(start, key+1, strlen(key));
  137. }
  138. }
  139. }
  140. if (int_cb)
  141. uc->interrupt_callback = *int_cb;
  142. *puc = uc;
  143. return 0;
  144. fail:
  145. *puc = NULL;
  146. if (uc)
  147. av_freep(&uc->priv_data);
  148. av_freep(&uc);
  149. #if CONFIG_NETWORK
  150. if (up->flags & URL_PROTOCOL_FLAG_NETWORK)
  151. ff_network_close();
  152. #endif
  153. return err;
  154. }
  155. int ffurl_connect(URLContext *uc, AVDictionary **options)
  156. {
  157. int err;
  158. AVDictionary *tmp_opts = NULL;
  159. AVDictionaryEntry *e;
  160. if (!options)
  161. options = &tmp_opts;
  162. // Check that URLContext was initialized correctly and lists are matching if set
  163. av_assert0(!(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) ||
  164. (uc->protocol_whitelist && !strcmp(uc->protocol_whitelist, e->value)));
  165. av_assert0(!(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) ||
  166. (uc->protocol_blacklist && !strcmp(uc->protocol_blacklist, e->value)));
  167. if (uc->protocol_whitelist && av_match_list(uc->prot->name, uc->protocol_whitelist, ',') <= 0) {
  168. av_log(uc, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", uc->prot->name, uc->protocol_whitelist);
  169. return AVERROR(EINVAL);
  170. }
  171. if (uc->protocol_blacklist && av_match_list(uc->prot->name, uc->protocol_blacklist, ',') > 0) {
  172. av_log(uc, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", uc->prot->name, uc->protocol_blacklist);
  173. return AVERROR(EINVAL);
  174. }
  175. if (!uc->protocol_whitelist && uc->prot->default_whitelist) {
  176. av_log(uc, AV_LOG_DEBUG, "Setting default whitelist '%s'\n", uc->prot->default_whitelist);
  177. uc->protocol_whitelist = av_strdup(uc->prot->default_whitelist);
  178. if (!uc->protocol_whitelist) {
  179. return AVERROR(ENOMEM);
  180. }
  181. } else if (!uc->protocol_whitelist)
  182. av_log(uc, AV_LOG_DEBUG, "No default whitelist set\n"); // This should be an error once all declare a default whitelist
  183. if ((err = av_dict_set(options, "protocol_whitelist", uc->protocol_whitelist, 0)) < 0)
  184. return err;
  185. if ((err = av_dict_set(options, "protocol_blacklist", uc->protocol_blacklist, 0)) < 0)
  186. return err;
  187. err =
  188. uc->prot->url_open2 ? uc->prot->url_open2(uc,
  189. uc->filename,
  190. uc->flags,
  191. options) :
  192. uc->prot->url_open(uc, uc->filename, uc->flags);
  193. av_dict_set(options, "protocol_whitelist", NULL, 0);
  194. av_dict_set(options, "protocol_blacklist", NULL, 0);
  195. if (err)
  196. return err;
  197. uc->is_connected = 1;
  198. /* We must be careful here as ffurl_seek() could be slow,
  199. * for example for http */
  200. if ((uc->flags & AVIO_FLAG_WRITE) || !strcmp(uc->prot->name, "file"))
  201. if (!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)
  202. uc->is_streamed = 1;
  203. return 0;
  204. }
  205. int ffurl_accept(URLContext *s, URLContext **c)
  206. {
  207. av_assert0(!*c);
  208. if (s->prot->url_accept)
  209. return s->prot->url_accept(s, c);
  210. return AVERROR(EBADF);
  211. }
  212. int ffurl_handshake(URLContext *c)
  213. {
  214. int ret;
  215. if (c->prot->url_handshake) {
  216. ret = c->prot->url_handshake(c);
  217. if (ret)
  218. return ret;
  219. }
  220. c->is_connected = 1;
  221. return 0;
  222. }
  223. #define URL_SCHEME_CHARS \
  224. "abcdefghijklmnopqrstuvwxyz" \
  225. "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
  226. "0123456789+-."
  227. static const struct URLProtocol *url_find_protocol(const char *filename)
  228. {
  229. const URLProtocol **protocols;
  230. char proto_str[128], proto_nested[128], *ptr;
  231. size_t proto_len = strspn(filename, URL_SCHEME_CHARS);
  232. int i;
  233. if (filename[proto_len] != ':' &&
  234. (strncmp(filename, "subfile,", 8) || !strchr(filename + proto_len + 1, ':')) ||
  235. is_dos_path(filename))
  236. strcpy(proto_str, "file");
  237. else
  238. av_strlcpy(proto_str, filename,
  239. FFMIN(proto_len + 1, sizeof(proto_str)));
  240. av_strlcpy(proto_nested, proto_str, sizeof(proto_nested));
  241. if ((ptr = strchr(proto_nested, '+')))
  242. *ptr = '\0';
  243. protocols = ffurl_get_protocols(NULL, NULL);
  244. if (!protocols)
  245. return NULL;
  246. for (i = 0; protocols[i]; i++) {
  247. const URLProtocol *up = protocols[i];
  248. if (!strcmp(proto_str, up->name)) {
  249. av_freep(&protocols);
  250. return up;
  251. }
  252. if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME &&
  253. !strcmp(proto_nested, up->name)) {
  254. av_freep(&protocols);
  255. return up;
  256. }
  257. }
  258. av_freep(&protocols);
  259. return NULL;
  260. }
  261. int ffurl_alloc(URLContext **puc, const char *filename, int flags,
  262. const AVIOInterruptCB *int_cb)
  263. {
  264. const URLProtocol *p = NULL;
  265. p = url_find_protocol(filename);
  266. if (p)
  267. return url_alloc_for_protocol(puc, p, filename, flags, int_cb);
  268. *puc = NULL;
  269. if (av_strstart(filename, "https:", NULL) || av_strstart(filename, "tls:", NULL))
  270. av_log(NULL, AV_LOG_WARNING, "https protocol not found, recompile FFmpeg with "
  271. "openssl, gnutls "
  272. "or securetransport enabled.\n");
  273. return AVERROR_PROTOCOL_NOT_FOUND;
  274. }
  275. int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags,
  276. const AVIOInterruptCB *int_cb, AVDictionary **options,
  277. const char *whitelist, const char* blacklist,
  278. URLContext *parent)
  279. {
  280. AVDictionary *tmp_opts = NULL;
  281. AVDictionaryEntry *e;
  282. int ret = ffurl_alloc(puc, filename, flags, int_cb);
  283. if (ret < 0)
  284. return ret;
  285. if (parent)
  286. av_opt_copy(*puc, parent);
  287. if (options &&
  288. (ret = av_opt_set_dict(*puc, options)) < 0)
  289. goto fail;
  290. if (options && (*puc)->prot->priv_data_class &&
  291. (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0)
  292. goto fail;
  293. if (!options)
  294. options = &tmp_opts;
  295. av_assert0(!whitelist ||
  296. !(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) ||
  297. !strcmp(whitelist, e->value));
  298. av_assert0(!blacklist ||
  299. !(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) ||
  300. !strcmp(blacklist, e->value));
  301. if ((ret = av_dict_set(options, "protocol_whitelist", whitelist, 0)) < 0)
  302. goto fail;
  303. if ((ret = av_dict_set(options, "protocol_blacklist", blacklist, 0)) < 0)
  304. goto fail;
  305. if ((ret = av_opt_set_dict(*puc, options)) < 0)
  306. goto fail;
  307. ret = ffurl_connect(*puc, options);
  308. if (!ret)
  309. return 0;
  310. fail:
  311. ffurl_close(*puc);
  312. *puc = NULL;
  313. return ret;
  314. }
  315. int ffurl_open(URLContext **puc, const char *filename, int flags,
  316. const AVIOInterruptCB *int_cb, AVDictionary **options)
  317. {
  318. return ffurl_open_whitelist(puc, filename, flags,
  319. int_cb, options, NULL, NULL, NULL);
  320. }
  321. static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf,
  322. int size, int size_min,
  323. int (*transfer_func)(URLContext *h,
  324. uint8_t *buf,
  325. int size))
  326. {
  327. int ret, len;
  328. int fast_retries = 5;
  329. int64_t wait_since = 0;
  330. len = 0;
  331. while (len < size_min) {
  332. if (ff_check_interrupt(&h->interrupt_callback))
  333. return AVERROR_EXIT;
  334. ret = transfer_func(h, buf + len, size - len);
  335. if (ret == AVERROR(EINTR))
  336. continue;
  337. if (h->flags & AVIO_FLAG_NONBLOCK)
  338. return ret;
  339. if (ret == AVERROR(EAGAIN)) {
  340. ret = 0;
  341. if (fast_retries) {
  342. fast_retries--;
  343. } else {
  344. if (h->rw_timeout) {
  345. if (!wait_since)
  346. wait_since = av_gettime_relative();
  347. else if (av_gettime_relative() > wait_since + h->rw_timeout)
  348. return AVERROR(EIO);
  349. }
  350. av_usleep(1000);
  351. }
  352. } else if (ret == AVERROR_EOF)
  353. return (len > 0) ? len : AVERROR_EOF;
  354. else if (ret < 0)
  355. return ret;
  356. if (ret) {
  357. fast_retries = FFMAX(fast_retries, 2);
  358. wait_since = 0;
  359. }
  360. len += ret;
  361. }
  362. return len;
  363. }
  364. int ffurl_read(URLContext *h, unsigned char *buf, int size)
  365. {
  366. if (!(h->flags & AVIO_FLAG_READ))
  367. return AVERROR(EIO);
  368. return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
  369. }
  370. int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
  371. {
  372. if (!(h->flags & AVIO_FLAG_READ))
  373. return AVERROR(EIO);
  374. return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
  375. }
  376. int ffurl_write(URLContext *h, const unsigned char *buf, int size)
  377. {
  378. if (!(h->flags & AVIO_FLAG_WRITE))
  379. return AVERROR(EIO);
  380. /* avoid sending too big packets */
  381. if (h->max_packet_size && size > h->max_packet_size)
  382. return AVERROR(EIO);
  383. return retry_transfer_wrapper(h, (unsigned char *)buf, size, size,
  384. (int (*)(struct URLContext *, uint8_t *, int))
  385. h->prot->url_write);
  386. }
  387. int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
  388. {
  389. int64_t ret;
  390. if (!h->prot->url_seek)
  391. return AVERROR(ENOSYS);
  392. ret = h->prot->url_seek(h, pos, whence & ~AVSEEK_FORCE);
  393. return ret;
  394. }
  395. int ffurl_closep(URLContext **hh)
  396. {
  397. URLContext *h= *hh;
  398. int ret = 0;
  399. if (!h)
  400. return 0; /* can happen when ffurl_open fails */
  401. if (h->is_connected && h->prot->url_close)
  402. ret = h->prot->url_close(h);
  403. #if CONFIG_NETWORK
  404. if (h->prot->flags & URL_PROTOCOL_FLAG_NETWORK)
  405. ff_network_close();
  406. #endif
  407. if (h->prot->priv_data_size) {
  408. if (h->prot->priv_data_class)
  409. av_opt_free(h->priv_data);
  410. av_freep(&h->priv_data);
  411. }
  412. av_opt_free(h);
  413. av_freep(hh);
  414. return ret;
  415. }
  416. int ffurl_close(URLContext *h)
  417. {
  418. return ffurl_closep(&h);
  419. }
  420. const char *avio_find_protocol_name(const char *url)
  421. {
  422. const URLProtocol *p = url_find_protocol(url);
  423. return p ? p->name : NULL;
  424. }
  425. int avio_check(const char *url, int flags)
  426. {
  427. URLContext *h;
  428. int ret = ffurl_alloc(&h, url, flags, NULL);
  429. if (ret < 0)
  430. return ret;
  431. if (h->prot->url_check) {
  432. ret = h->prot->url_check(h, flags);
  433. } else {
  434. ret = ffurl_connect(h, NULL);
  435. if (ret >= 0)
  436. ret = flags;
  437. }
  438. ffurl_close(h);
  439. return ret;
  440. }
  441. int avpriv_io_move(const char *url_src, const char *url_dst)
  442. {
  443. URLContext *h_src, *h_dst;
  444. int ret = ffurl_alloc(&h_src, url_src, AVIO_FLAG_READ_WRITE, NULL);
  445. if (ret < 0)
  446. return ret;
  447. ret = ffurl_alloc(&h_dst, url_dst, AVIO_FLAG_WRITE, NULL);
  448. if (ret < 0) {
  449. ffurl_close(h_src);
  450. return ret;
  451. }
  452. if (h_src->prot == h_dst->prot && h_src->prot->url_move)
  453. ret = h_src->prot->url_move(h_src, h_dst);
  454. else
  455. ret = AVERROR(ENOSYS);
  456. ffurl_close(h_src);
  457. ffurl_close(h_dst);
  458. return ret;
  459. }
  460. int avpriv_io_delete(const char *url)
  461. {
  462. URLContext *h;
  463. int ret = ffurl_alloc(&h, url, AVIO_FLAG_WRITE, NULL);
  464. if (ret < 0)
  465. return ret;
  466. if (h->prot->url_delete)
  467. ret = h->prot->url_delete(h);
  468. else
  469. ret = AVERROR(ENOSYS);
  470. ffurl_close(h);
  471. return ret;
  472. }
  473. int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
  474. {
  475. URLContext *h = NULL;
  476. AVIODirContext *ctx = NULL;
  477. int ret;
  478. av_assert0(s);
  479. ctx = av_mallocz(sizeof(*ctx));
  480. if (!ctx) {
  481. ret = AVERROR(ENOMEM);
  482. goto fail;
  483. }
  484. if ((ret = ffurl_alloc(&h, url, AVIO_FLAG_READ, NULL)) < 0)
  485. goto fail;
  486. if (h->prot->url_open_dir && h->prot->url_read_dir && h->prot->url_close_dir) {
  487. if (options && h->prot->priv_data_class &&
  488. (ret = av_opt_set_dict(h->priv_data, options)) < 0)
  489. goto fail;
  490. ret = h->prot->url_open_dir(h);
  491. } else
  492. ret = AVERROR(ENOSYS);
  493. if (ret < 0)
  494. goto fail;
  495. h->is_connected = 1;
  496. ctx->url_context = h;
  497. *s = ctx;
  498. return 0;
  499. fail:
  500. av_free(ctx);
  501. *s = NULL;
  502. ffurl_close(h);
  503. return ret;
  504. }
  505. int avio_read_dir(AVIODirContext *s, AVIODirEntry **next)
  506. {
  507. URLContext *h;
  508. int ret;
  509. if (!s || !s->url_context)
  510. return AVERROR(EINVAL);
  511. h = s->url_context;
  512. if ((ret = h->prot->url_read_dir(h, next)) < 0)
  513. avio_free_directory_entry(next);
  514. return ret;
  515. }
  516. int avio_close_dir(AVIODirContext **s)
  517. {
  518. URLContext *h;
  519. av_assert0(s);
  520. if (!(*s) || !(*s)->url_context)
  521. return AVERROR(EINVAL);
  522. h = (*s)->url_context;
  523. h->prot->url_close_dir(h);
  524. ffurl_close(h);
  525. av_freep(s);
  526. *s = NULL;
  527. return 0;
  528. }
  529. void avio_free_directory_entry(AVIODirEntry **entry)
  530. {
  531. if (!entry || !*entry)
  532. return;
  533. av_free((*entry)->name);
  534. av_freep(entry);
  535. }
  536. int64_t ffurl_size(URLContext *h)
  537. {
  538. int64_t pos, size;
  539. size = ffurl_seek(h, 0, AVSEEK_SIZE);
  540. if (size < 0) {
  541. pos = ffurl_seek(h, 0, SEEK_CUR);
  542. if ((size = ffurl_seek(h, -1, SEEK_END)) < 0)
  543. return size;
  544. size++;
  545. ffurl_seek(h, pos, SEEK_SET);
  546. }
  547. return size;
  548. }
  549. int ffurl_get_file_handle(URLContext *h)
  550. {
  551. if (!h || !h->prot || !h->prot->url_get_file_handle)
  552. return -1;
  553. return h->prot->url_get_file_handle(h);
  554. }
  555. int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
  556. {
  557. if (!h || !h->prot)
  558. return AVERROR(ENOSYS);
  559. if (!h->prot->url_get_multi_file_handle) {
  560. if (!h->prot->url_get_file_handle)
  561. return AVERROR(ENOSYS);
  562. *handles = av_malloc(sizeof(**handles));
  563. if (!*handles)
  564. return AVERROR(ENOMEM);
  565. *numhandles = 1;
  566. *handles[0] = h->prot->url_get_file_handle(h);
  567. return 0;
  568. }
  569. return h->prot->url_get_multi_file_handle(h, handles, numhandles);
  570. }
  571. int ffurl_get_short_seek(URLContext *h)
  572. {
  573. if (!h || !h->prot || !h->prot->url_get_short_seek)
  574. return AVERROR(ENOSYS);
  575. return h->prot->url_get_short_seek(h);
  576. }
  577. int ffurl_shutdown(URLContext *h, int flags)
  578. {
  579. if (!h || !h->prot || !h->prot->url_shutdown)
  580. return AVERROR(ENOSYS);
  581. return h->prot->url_shutdown(h, flags);
  582. }
  583. int ff_check_interrupt(AVIOInterruptCB *cb)
  584. {
  585. int ret;
  586. if (cb && cb->callback && (ret = cb->callback(cb->opaque)))
  587. return ret;
  588. return 0;
  589. }