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.

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