| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 22 | #include "libavutil/avstring.h" | ||
| 23 | #include "libavutil/dict.h" | ||
| 24 | #include "libavutil/mem.h" | ||
| 25 | #include "libavutil/opt.h" | ||
| 26 | #include "libavutil/time.h" | ||
| 27 | #include "libavutil/avassert.h" | ||
| 28 | #include "avio_internal.h" | ||
| 29 | #include "os_support.h" | ||
| 30 | #include "internal.h" | ||
| 31 | #if CONFIG_NETWORK | ||
| 32 | #include "network.h" | ||
| 33 | #endif | ||
| 34 | #include "url.h" | ||
| 35 | |||
| 36 | #define IO_BUFFER_SIZE 32768 | ||
| 37 | |||
| 38 | /** @name Logging context. */ | ||
| 39 | /*@{*/ | ||
| 40 | 6 | static const char *urlcontext_to_name(void *ptr) | |
| 41 | { | ||
| 42 | 6 | URLContext *h = (URLContext *)ptr; | |
| 43 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (h->prot) |
| 44 | 6 | return h->prot->name; | |
| 45 | else | ||
| 46 | ✗ | return "NULL"; | |
| 47 | } | ||
| 48 | |||
| 49 | 35994 | static void *urlcontext_child_next(void *obj, void *prev) | |
| 50 | { | ||
| 51 | 35994 | URLContext *h = obj; | |
| 52 |
5/6✓ Branch 0 taken 17999 times.
✓ Branch 1 taken 17995 times.
✓ Branch 2 taken 17999 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17995 times.
✓ Branch 5 taken 4 times.
|
35994 | if (!prev && h->priv_data && h->prot->priv_data_class) |
| 53 | 17995 | return h->priv_data; | |
| 54 | 17999 | return NULL; | |
| 55 | } | ||
| 56 | |||
| 57 | #define OFFSET(x) offsetof(URLContext,x) | ||
| 58 | #define E AV_OPT_FLAG_ENCODING_PARAM | ||
| 59 | #define D AV_OPT_FLAG_DECODING_PARAM | ||
| 60 | static const AVOption options[] = { | ||
| 61 | {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D }, | ||
| 62 | {"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D }, | ||
| 63 | {"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 }, | ||
| 64 | { NULL } | ||
| 65 | }; | ||
| 66 | |||
| 67 | static const AVClass url_context_class = { | ||
| 68 | .class_name = "URLContext", | ||
| 69 | .item_name = urlcontext_to_name, | ||
| 70 | .option = options, | ||
| 71 | .version = LIBAVUTIL_VERSION_INT, | ||
| 72 | .child_next = urlcontext_child_next, | ||
| 73 | .child_class_iterate = ff_urlcontext_child_class_iterate, | ||
| 74 | }; | ||
| 75 | /*@}*/ | ||
| 76 | |||
| 77 | 35985 | static void *avio_child_next(void *obj, void *prev) | |
| 78 | { | ||
| 79 | 35985 | AVIOContext *s = obj; | |
| 80 |
2/2✓ Branch 0 taken 17999 times.
✓ Branch 1 taken 17986 times.
|
35985 | return prev ? NULL : s->opaque; |
| 81 | } | ||
| 82 | |||
| 83 | 235773 | static const AVClass *child_class_iterate(void **iter) | |
| 84 | { | ||
| 85 |
2/2✓ Branch 0 taken 117889 times.
✓ Branch 1 taken 117884 times.
|
235773 | const AVClass *c = *iter ? NULL : &url_context_class; |
| 86 | 235773 | *iter = (void*)(uintptr_t)c; | |
| 87 | 235773 | return c; | |
| 88 | } | ||
| 89 | |||
| 90 | #define AVIOOFFSET(x) offsetof(AVIOContext,x) | ||
| 91 | #define E AV_OPT_FLAG_ENCODING_PARAM | ||
| 92 | #define D AV_OPT_FLAG_DECODING_PARAM | ||
| 93 | static const AVOption avio_options[] = { | ||
| 94 | {"protocol_whitelist", "List of protocols that are allowed to be used", AVIOOFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D }, | ||
| 95 | { NULL }, | ||
| 96 | }; | ||
| 97 | |||
| 98 | const AVClass ff_avio_class = { | ||
| 99 | .class_name = "AVIOContext", | ||
| 100 | .item_name = av_default_item_name, | ||
| 101 | .version = LIBAVUTIL_VERSION_INT, | ||
| 102 | .option = avio_options, | ||
| 103 | .child_next = avio_child_next, | ||
| 104 | .child_class_iterate = child_class_iterate, | ||
| 105 | }; | ||
| 106 | |||
| 107 | ✗ | URLContext *ffio_geturlcontext(AVIOContext *s) | |
| 108 | { | ||
| 109 | ✗ | if (!s) | |
| 110 | ✗ | return NULL; | |
| 111 | |||
| 112 | ✗ | if (s->opaque && s->read_packet == ffurl_read2) | |
| 113 | ✗ | return s->opaque; | |
| 114 | else | ||
| 115 | ✗ | return NULL; | |
| 116 | } | ||
| 117 | |||
| 118 | 168899 | static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up, | |
| 119 | const char *filename, int flags, | ||
| 120 | const AVIOInterruptCB *int_cb) | ||
| 121 | { | ||
| 122 | URLContext *uc; | ||
| 123 | int err; | ||
| 124 | |||
| 125 | #if CONFIG_NETWORK | ||
| 126 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 168899 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
168899 | if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init()) |
| 127 | ✗ | return AVERROR(EIO); | |
| 128 | #endif | ||
| 129 |
3/4✓ Branch 0 taken 159258 times.
✓ Branch 1 taken 9641 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 159258 times.
|
168899 | if ((flags & AVIO_FLAG_READ) && !up->url_read) { |
| 130 | ✗ | av_log(NULL, AV_LOG_ERROR, | |
| 131 | ✗ | "Impossible to open the '%s' protocol for reading\n", up->name); | |
| 132 | ✗ | return AVERROR(EIO); | |
| 133 | } | ||
| 134 |
3/4✓ Branch 0 taken 9720 times.
✓ Branch 1 taken 159179 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9720 times.
|
168899 | if ((flags & AVIO_FLAG_WRITE) && !up->url_write) { |
| 135 | ✗ | av_log(NULL, AV_LOG_ERROR, | |
| 136 | ✗ | "Impossible to open the '%s' protocol for writing\n", up->name); | |
| 137 | ✗ | return AVERROR(EIO); | |
| 138 | } | ||
| 139 | 168899 | uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1); | |
| 140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168899 times.
|
168899 | if (!uc) { |
| 141 | ✗ | err = AVERROR(ENOMEM); | |
| 142 | ✗ | goto fail; | |
| 143 | } | ||
| 144 | 168899 | uc->av_class = &url_context_class; | |
| 145 | 168899 | uc->filename = (char *)&uc[1]; | |
| 146 | 168899 | strcpy(uc->filename, filename); | |
| 147 | 168899 | uc->prot = up; | |
| 148 | 168899 | uc->flags = flags; | |
| 149 | 168899 | uc->is_streamed = 0; /* default = not streamed */ | |
| 150 | 168899 | uc->max_packet_size = 0; /* default: stream file */ | |
| 151 |
1/2✓ Branch 0 taken 168899 times.
✗ Branch 1 not taken.
|
168899 | if (up->priv_data_size) { |
| 152 | 168899 | uc->priv_data = av_mallocz(up->priv_data_size); | |
| 153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168899 times.
|
168899 | if (!uc->priv_data) { |
| 154 | ✗ | err = AVERROR(ENOMEM); | |
| 155 | ✗ | goto fail; | |
| 156 | } | ||
| 157 |
2/2✓ Branch 0 taken 166099 times.
✓ Branch 1 taken 2800 times.
|
168899 | if (up->priv_data_class) { |
| 158 | char *start; | ||
| 159 | 166099 | *(const AVClass **)uc->priv_data = up->priv_data_class; | |
| 160 | 166099 | av_opt_set_defaults(uc->priv_data); | |
| 161 |
3/4✓ Branch 1 taken 2711 times.
✓ Branch 2 taken 163388 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2711 times.
|
166099 | if (av_strstart(uc->filename, up->name, (const char**)&start) && *start == ',') { |
| 162 | ✗ | int ret= 0; | |
| 163 | ✗ | char *p= start; | |
| 164 | ✗ | char sep= *++p; | |
| 165 | char *key, *val; | ||
| 166 | ✗ | p++; | |
| 167 | |||
| 168 | ✗ | if (strcmp(up->name, "subfile")) | |
| 169 | ✗ | ret = AVERROR(EINVAL); | |
| 170 | |||
| 171 | ✗ | while(ret >= 0 && (key= strchr(p, sep)) && p<key && (val = strchr(key+1, sep))){ | |
| 172 | ✗ | *val= *key= 0; | |
| 173 | ✗ | ret = av_opt_set(uc->priv_data, p, key+1, 0); | |
| 174 | ✗ | if (ret == AVERROR_OPTION_NOT_FOUND) | |
| 175 | ✗ | av_log(uc, AV_LOG_ERROR, "Key '%s' not found.\n", p); | |
| 176 | ✗ | *val= *key= sep; | |
| 177 | ✗ | p= val+1; | |
| 178 | } | ||
| 179 | ✗ | if(ret<0 || p!=key){ | |
| 180 | ✗ | av_log(uc, AV_LOG_ERROR, "Error parsing options string %s\n", start); | |
| 181 | ✗ | err = AVERROR(EINVAL); | |
| 182 | ✗ | goto fail; | |
| 183 | } | ||
| 184 | ✗ | memmove(start, key+1, strlen(key)); | |
| 185 | } | ||
| 186 | } | ||
| 187 | } | ||
| 188 |
2/2✓ Branch 0 taken 116250 times.
✓ Branch 1 taken 52649 times.
|
168899 | if (int_cb) |
| 189 | 116250 | uc->interrupt_callback = *int_cb; | |
| 190 | |||
| 191 | 168899 | *puc = uc; | |
| 192 | 168899 | return 0; | |
| 193 | ✗ | fail: | |
| 194 | ✗ | *puc = NULL; | |
| 195 | ✗ | if (uc) | |
| 196 | ✗ | av_freep(&uc->priv_data); | |
| 197 | ✗ | av_freep(&uc); | |
| 198 | #if CONFIG_NETWORK | ||
| 199 | ✗ | if (up->flags & URL_PROTOCOL_FLAG_NETWORK) | |
| 200 | ✗ | ff_network_close(); | |
| 201 | #endif | ||
| 202 | ✗ | return err; | |
| 203 | } | ||
| 204 | |||
| 205 | 116351 | int ffurl_connect(URLContext *uc, AVDictionary **options) | |
| 206 | { | ||
| 207 | int err; | ||
| 208 | 116351 | AVDictionary *tmp_opts = NULL; | |
| 209 | AVDictionaryEntry *e; | ||
| 210 | |||
| 211 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 116351 times.
|
116351 | if (!options) |
| 212 | ✗ | options = &tmp_opts; | |
| 213 | |||
| 214 | // Check that URLContext was initialized correctly and lists are matching if set | ||
| 215 |
1/6✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
116351 | av_assert0(!(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) || |
| 216 | (uc->protocol_whitelist && !strcmp(uc->protocol_whitelist, e->value))); | ||
| 217 |
1/6✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
116351 | av_assert0(!(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) || |
| 218 | (uc->protocol_blacklist && !strcmp(uc->protocol_blacklist, e->value))); | ||
| 219 | |||
| 220 |
3/4✓ Branch 0 taken 139 times.
✓ Branch 1 taken 116212 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
|
116351 | if (uc->protocol_whitelist && av_match_list(uc->prot->name, uc->protocol_whitelist, ',') <= 0) { |
| 221 | ✗ | av_log(uc, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", uc->prot->name, uc->protocol_whitelist); | |
| 222 | ✗ | return AVERROR(EINVAL); | |
| 223 | } | ||
| 224 | |||
| 225 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 116351 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
116351 | if (uc->protocol_blacklist && av_match_list(uc->prot->name, uc->protocol_blacklist, ',') > 0) { |
| 226 | ✗ | av_log(uc, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", uc->prot->name, uc->protocol_blacklist); | |
| 227 | ✗ | return AVERROR(EINVAL); | |
| 228 | } | ||
| 229 | |||
| 230 |
4/4✓ Branch 0 taken 116212 times.
✓ Branch 1 taken 139 times.
✓ Branch 2 taken 113412 times.
✓ Branch 3 taken 2800 times.
|
116351 | if (!uc->protocol_whitelist && uc->prot->default_whitelist) { |
| 231 | 113412 | av_log(uc, AV_LOG_DEBUG, "Setting default whitelist '%s'\n", uc->prot->default_whitelist); | |
| 232 | 113412 | uc->protocol_whitelist = av_strdup(uc->prot->default_whitelist); | |
| 233 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113412 times.
|
113412 | if (!uc->protocol_whitelist) { |
| 234 | ✗ | return AVERROR(ENOMEM); | |
| 235 | } | ||
| 236 |
2/2✓ Branch 0 taken 2800 times.
✓ Branch 1 taken 139 times.
|
2939 | } else if (!uc->protocol_whitelist) |
| 237 | 2800 | av_log(uc, AV_LOG_DEBUG, "No default whitelist set\n"); // This should be an error once all declare a default whitelist | |
| 238 | |||
| 239 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
|
116351 | if ((err = av_dict_set(options, "protocol_whitelist", uc->protocol_whitelist, 0)) < 0) |
| 240 | ✗ | return err; | |
| 241 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
|
116351 | if ((err = av_dict_set(options, "protocol_blacklist", uc->protocol_blacklist, 0)) < 0) |
| 242 | ✗ | return err; | |
| 243 | |||
| 244 | 116351 | err = | |
| 245 | 116352 | uc->prot->url_open2 ? uc->prot->url_open2(uc, | |
| 246 | 1 | uc->filename, | |
| 247 | uc->flags, | ||
| 248 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 116350 times.
|
116351 | options) : |
| 249 | 116350 | uc->prot->url_open(uc, uc->filename, uc->flags); | |
| 250 | |||
| 251 | 116351 | av_dict_set(options, "protocol_whitelist", NULL, 0); | |
| 252 | 116351 | av_dict_set(options, "protocol_blacklist", NULL, 0); | |
| 253 | |||
| 254 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 116350 times.
|
116351 | if (err) |
| 255 | 1 | return err; | |
| 256 | 116350 | uc->is_connected = 1; | |
| 257 | /* We must be careful here as ffurl_seek() could be slow, | ||
| 258 | * for example for http */ | ||
| 259 |
4/4✓ Branch 0 taken 106788 times.
✓ Branch 1 taken 9562 times.
✓ Branch 2 taken 106785 times.
✓ Branch 3 taken 3 times.
|
116350 | if ((uc->flags & AVIO_FLAG_WRITE) || !strcmp(uc->prot->name, "file")) |
| 260 |
4/4✓ Branch 0 taken 113638 times.
✓ Branch 1 taken 2709 times.
✓ Branch 3 taken 2799 times.
✓ Branch 4 taken 110839 times.
|
116347 | if (!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0) |
| 261 | 2799 | uc->is_streamed = 1; | |
| 262 | 116350 | return 0; | |
| 263 | } | ||
| 264 | |||
| 265 | ✗ | int ffurl_accept(URLContext *s, URLContext **c) | |
| 266 | { | ||
| 267 | ✗ | av_assert0(!*c); | |
| 268 | ✗ | if (s->prot->url_accept) | |
| 269 | ✗ | return s->prot->url_accept(s, c); | |
| 270 | ✗ | return AVERROR(EBADF); | |
| 271 | } | ||
| 272 | |||
| 273 | ✗ | int avio_accept(AVIOContext *s, AVIOContext **c) | |
| 274 | { | ||
| 275 | int ret; | ||
| 276 | ✗ | URLContext *sc = s->opaque; | |
| 277 | ✗ | URLContext *cc = NULL; | |
| 278 | ✗ | ret = ffurl_accept(sc, &cc); | |
| 279 | ✗ | if (ret < 0) | |
| 280 | ✗ | return ret; | |
| 281 | ✗ | return ffio_fdopen(c, cc); | |
| 282 | } | ||
| 283 | |||
| 284 | ✗ | int ffurl_handshake(URLContext *c) | |
| 285 | { | ||
| 286 | int ret; | ||
| 287 | ✗ | if (c->prot->url_handshake) { | |
| 288 | ✗ | ret = c->prot->url_handshake(c); | |
| 289 | ✗ | if (ret) | |
| 290 | ✗ | return ret; | |
| 291 | } | ||
| 292 | ✗ | c->is_connected = 1; | |
| 293 | ✗ | return 0; | |
| 294 | } | ||
| 295 | |||
| 296 | ✗ | int avio_handshake(AVIOContext *c) | |
| 297 | { | ||
| 298 | ✗ | URLContext *cc = c->opaque; | |
| 299 | ✗ | return ffurl_handshake(cc); | |
| 300 | } | ||
| 301 | |||
| 302 | #define URL_SCHEME_CHARS \ | ||
| 303 | "abcdefghijklmnopqrstuvwxyz" \ | ||
| 304 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ | ||
| 305 | "0123456789+-." | ||
| 306 | |||
| 307 | 178413 | static const struct URLProtocol *url_find_protocol(const char *filename) | |
| 308 | { | ||
| 309 | const URLProtocol **protocols; | ||
| 310 | char proto_str[128], proto_nested[128], *ptr; | ||
| 311 | 178413 | size_t proto_len = strspn(filename, URL_SCHEME_CHARS); | |
| 312 | int i; | ||
| 313 | |||
| 314 |
2/2✓ Branch 0 taken 167422 times.
✓ Branch 1 taken 10991 times.
|
178413 | if (filename[proto_len] != ':' && |
| 315 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 167422 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10991 times.
|
178413 | (strncmp(filename, "subfile,", 8) || !strchr(filename + proto_len + 1, ':')) || |
| 316 | 10991 | is_dos_path(filename)) | |
| 317 | 167422 | strcpy(proto_str, "file"); | |
| 318 | else | ||
| 319 | 10991 | av_strlcpy(proto_str, filename, | |
| 320 | 10991 | FFMIN(proto_len + 1, sizeof(proto_str))); | |
| 321 | |||
| 322 | 178413 | av_strlcpy(proto_nested, proto_str, sizeof(proto_nested)); | |
| 323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 178413 times.
|
178413 | if ((ptr = strchr(proto_nested, '+'))) |
| 324 | ✗ | *ptr = '\0'; | |
| 325 | |||
| 326 | 178413 | protocols = ffurl_get_protocols(NULL, NULL); | |
| 327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 178413 times.
|
178413 | if (!protocols) |
| 328 | ✗ | return NULL; | |
| 329 |
1/2✓ Branch 0 taken 1709997 times.
✗ Branch 1 not taken.
|
1709997 | for (i = 0; protocols[i]; i++) { |
| 330 | 1709997 | const URLProtocol *up = protocols[i]; | |
| 331 |
2/2✓ Branch 0 taken 178413 times.
✓ Branch 1 taken 1531584 times.
|
1709997 | if (!strcmp(proto_str, up->name)) { |
| 332 | 178413 | av_freep(&protocols); | |
| 333 | 178413 | return up; | |
| 334 | } | ||
| 335 |
2/2✓ Branch 0 taken 189400 times.
✓ Branch 1 taken 1342184 times.
|
1531584 | if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME && |
| 336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 189400 times.
|
189400 | !strcmp(proto_nested, up->name)) { |
| 337 | ✗ | av_freep(&protocols); | |
| 338 | ✗ | return up; | |
| 339 | } | ||
| 340 | } | ||
| 341 | ✗ | av_freep(&protocols); | |
| 342 | ✗ | if (av_strstart(filename, "https:", NULL) || av_strstart(filename, "tls:", NULL) || | |
| 343 | ✗ | av_strstart(filename, "dtls:", NULL)) | |
| 344 | ✗ | av_log(NULL, AV_LOG_WARNING, "https or dtls protocol not found, recompile FFmpeg with " | |
| 345 | "openssl, gnutls or securetransport enabled.\n"); | ||
| 346 | |||
| 347 | ✗ | return NULL; | |
| 348 | } | ||
| 349 | |||
| 350 | 168899 | int ffurl_alloc(URLContext **puc, const char *filename, int flags, | |
| 351 | const AVIOInterruptCB *int_cb) | ||
| 352 | { | ||
| 353 | 168899 | const URLProtocol *p = NULL; | |
| 354 | |||
| 355 | 168899 | p = url_find_protocol(filename); | |
| 356 |
1/2✓ Branch 0 taken 168899 times.
✗ Branch 1 not taken.
|
168899 | if (p) |
| 357 | 168899 | return url_alloc_for_protocol(puc, p, filename, flags, int_cb); | |
| 358 | |||
| 359 | ✗ | *puc = NULL; | |
| 360 | ✗ | return AVERROR_PROTOCOL_NOT_FOUND; | |
| 361 | } | ||
| 362 | |||
| 363 | 116351 | int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, | |
| 364 | const AVIOInterruptCB *int_cb, AVDictionary **options, | ||
| 365 | const char *whitelist, const char* blacklist, | ||
| 366 | URLContext *parent) | ||
| 367 | { | ||
| 368 | 116351 | AVDictionary *tmp_opts = NULL; | |
| 369 | AVDictionaryEntry *e; | ||
| 370 | 116351 | int ret = ffurl_alloc(puc, filename, flags, int_cb); | |
| 371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 116351 times.
|
116351 | if (ret < 0) |
| 372 | ✗ | return ret; | |
| 373 |
2/2✓ Branch 0 taken 409 times.
✓ Branch 1 taken 115942 times.
|
116351 | if (parent) { |
| 374 | 409 | ret = av_opt_copy(*puc, parent); | |
| 375 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 409 times.
|
409 | if (ret < 0) |
| 376 | ✗ | goto fail; | |
| 377 | } | ||
| 378 |
3/4✓ Branch 0 taken 13752 times.
✓ Branch 1 taken 102599 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13752 times.
|
130103 | if (options && |
| 379 | 13752 | (ret = av_opt_set_dict(*puc, options)) < 0) | |
| 380 | ✗ | goto fail; | |
| 381 |
5/6✓ Branch 0 taken 13752 times.
✓ Branch 1 taken 102599 times.
✓ Branch 2 taken 10952 times.
✓ Branch 3 taken 2800 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10952 times.
|
127303 | if (options && (*puc)->prot->priv_data_class && |
| 382 | 10952 | (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0) | |
| 383 | ✗ | goto fail; | |
| 384 | |||
| 385 |
2/2✓ Branch 0 taken 102599 times.
✓ Branch 1 taken 13752 times.
|
116351 | if (!options) |
| 386 | 102599 | options = &tmp_opts; | |
| 387 | |||
| 388 |
3/6✓ Branch 0 taken 139 times.
✓ Branch 1 taken 116212 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
116351 | av_assert0(!whitelist || |
| 389 | !(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) || | ||
| 390 | !strcmp(whitelist, e->value)); | ||
| 391 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 116351 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
116351 | av_assert0(!blacklist || |
| 392 | !(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) || | ||
| 393 | !strcmp(blacklist, e->value)); | ||
| 394 | |||
| 395 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
|
116351 | if ((ret = av_dict_set(options, "protocol_whitelist", whitelist, 0)) < 0) |
| 396 | ✗ | goto fail; | |
| 397 | |||
| 398 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
|
116351 | if ((ret = av_dict_set(options, "protocol_blacklist", blacklist, 0)) < 0) |
| 399 | ✗ | goto fail; | |
| 400 | |||
| 401 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 116351 times.
|
116351 | if ((ret = av_opt_set_dict(*puc, options)) < 0) |
| 402 | ✗ | goto fail; | |
| 403 | |||
| 404 | 116351 | ret = ffurl_connect(*puc, options); | |
| 405 | |||
| 406 |
2/2✓ Branch 0 taken 116350 times.
✓ Branch 1 taken 1 times.
|
116351 | if (!ret) |
| 407 | 116350 | return 0; | |
| 408 | 1 | fail: | |
| 409 | 1 | ffurl_closep(puc); | |
| 410 | 1 | return ret; | |
| 411 | } | ||
| 412 | |||
| 413 | 115941 | int ffio_fdopen(AVIOContext **sp, URLContext *h) | |
| 414 | { | ||
| 415 | AVIOContext *s; | ||
| 416 | 115941 | uint8_t *buffer = NULL; | |
| 417 | int buffer_size, max_packet_size; | ||
| 418 | |||
| 419 | 115941 | max_packet_size = h->max_packet_size; | |
| 420 |
2/2✓ Branch 0 taken 3650 times.
✓ Branch 1 taken 112291 times.
|
115941 | if (max_packet_size) { |
| 421 | 3650 | buffer_size = max_packet_size; /* no need to bufferize more than one packet */ | |
| 422 | } else { | ||
| 423 | 112291 | buffer_size = IO_BUFFER_SIZE; | |
| 424 | } | ||
| 425 |
3/4✓ Branch 0 taken 106783 times.
✓ Branch 1 taken 9158 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 106783 times.
|
115941 | if (!(h->flags & AVIO_FLAG_WRITE) && h->is_streamed) { |
| 426 | ✗ | if (buffer_size > INT_MAX/2) | |
| 427 | ✗ | return AVERROR(EINVAL); | |
| 428 | ✗ | buffer_size *= 2; | |
| 429 | } | ||
| 430 | 115941 | buffer = av_malloc(buffer_size); | |
| 431 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115941 times.
|
115941 | if (!buffer) |
| 432 | ✗ | return AVERROR(ENOMEM); | |
| 433 | |||
| 434 | 115941 | *sp = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h, | |
| 435 | ffurl_read2, ffurl_write2, ffurl_seek2); | ||
| 436 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115941 times.
|
115941 | if (!*sp) { |
| 437 | ✗ | av_freep(&buffer); | |
| 438 | ✗ | return AVERROR(ENOMEM); | |
| 439 | } | ||
| 440 | 115941 | s = *sp; | |
| 441 |
2/2✓ Branch 0 taken 113141 times.
✓ Branch 1 taken 2800 times.
|
115941 | if (h->protocol_whitelist) { |
| 442 | 113141 | s->protocol_whitelist = av_strdup(h->protocol_whitelist); | |
| 443 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113141 times.
|
113141 | if (!s->protocol_whitelist) { |
| 444 | ✗ | avio_closep(sp); | |
| 445 | ✗ | return AVERROR(ENOMEM); | |
| 446 | } | ||
| 447 | } | ||
| 448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115941 times.
|
115941 | if (h->protocol_blacklist) { |
| 449 | ✗ | s->protocol_blacklist = av_strdup(h->protocol_blacklist); | |
| 450 | ✗ | if (!s->protocol_blacklist) { | |
| 451 | ✗ | avio_closep(sp); | |
| 452 | ✗ | return AVERROR(ENOMEM); | |
| 453 | } | ||
| 454 | } | ||
| 455 | 115941 | s->direct = h->flags & AVIO_FLAG_DIRECT; | |
| 456 | |||
| 457 | 115941 | s->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL; | |
| 458 | 115941 | s->max_packet_size = max_packet_size; | |
| 459 | 115941 | s->min_packet_size = h->min_packet_size; | |
| 460 |
1/2✓ Branch 0 taken 115941 times.
✗ Branch 1 not taken.
|
115941 | if(h->prot) { |
| 461 | 115941 | s->read_pause = h->prot->url_read_pause; | |
| 462 | 115941 | s->read_seek = h->prot->url_read_seek; | |
| 463 | |||
| 464 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115941 times.
|
115941 | if (h->prot->url_read_seek) |
| 465 | ✗ | s->seekable |= AVIO_SEEKABLE_TIME; | |
| 466 | } | ||
| 467 | 115941 | ((FFIOContext*)s)->short_seek_get = ffurl_get_short_seek; | |
| 468 | 115941 | s->av_class = &ff_avio_class; | |
| 469 | 115941 | return 0; | |
| 470 | } | ||
| 471 | |||
| 472 | 115942 | int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, | |
| 473 | const AVIOInterruptCB *int_cb, AVDictionary **options, | ||
| 474 | const char *whitelist, const char *blacklist) | ||
| 475 | { | ||
| 476 | URLContext *h; | ||
| 477 | int err; | ||
| 478 | |||
| 479 | 115942 | *s = NULL; | |
| 480 | |||
| 481 | 115942 | err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL); | |
| 482 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 115941 times.
|
115942 | if (err < 0) |
| 483 | 1 | return err; | |
| 484 | 115941 | err = ffio_fdopen(s, h); | |
| 485 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115941 times.
|
115941 | if (err < 0) { |
| 486 | ✗ | ffurl_close(h); | |
| 487 | ✗ | return err; | |
| 488 | } | ||
| 489 | 115941 | return 0; | |
| 490 | } | ||
| 491 | |||
| 492 | 8410 | int avio_open2(AVIOContext **s, const char *filename, int flags, | |
| 493 | const AVIOInterruptCB *int_cb, AVDictionary **options) | ||
| 494 | { | ||
| 495 | 8410 | return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL); | |
| 496 | } | ||
| 497 | |||
| 498 | 101 | int avio_open(AVIOContext **s, const char *filename, int flags) | |
| 499 | { | ||
| 500 | 101 | return avio_open2(s, filename, flags, NULL, NULL); | |
| 501 | } | ||
| 502 | |||
| 503 | |||
| 504 | 618695 | static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf, | |
| 505 | const uint8_t *cbuf, | ||
| 506 | int size, int size_min, | ||
| 507 | int read) | ||
| 508 | { | ||
| 509 | int ret, len; | ||
| 510 | 618695 | int fast_retries = 5; | |
| 511 | 618695 | int64_t wait_since = 0; | |
| 512 | |||
| 513 | 618695 | len = 0; | |
| 514 |
2/2✓ Branch 0 taken 618695 times.
✓ Branch 1 taken 606294 times.
|
1224989 | while (len < size_min) { |
| 515 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 618695 times.
|
618695 | if (ff_check_interrupt(&h->interrupt_callback)) |
| 516 | ✗ | return AVERROR_EXIT; | |
| 517 |
2/2✓ Branch 0 taken 222216 times.
✓ Branch 1 taken 396479 times.
|
618695 | ret = read ? h->prot->url_read (h, buf + len, size - len): |
| 518 | 396479 | h->prot->url_write(h, cbuf + len, size - len); | |
| 519 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 618695 times.
|
618695 | if (ret == AVERROR(EINTR)) |
| 520 | ✗ | continue; | |
| 521 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 618695 times.
|
618695 | if (h->flags & AVIO_FLAG_NONBLOCK) |
| 522 | ✗ | return ret; | |
| 523 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 618695 times.
|
618695 | if (ret == AVERROR(EAGAIN)) { |
| 524 | ✗ | ret = 0; | |
| 525 | ✗ | if (fast_retries) { | |
| 526 | ✗ | fast_retries--; | |
| 527 | } else { | ||
| 528 | ✗ | if (h->rw_timeout) { | |
| 529 | ✗ | if (!wait_since) | |
| 530 | ✗ | wait_since = av_gettime_relative(); | |
| 531 | ✗ | else if (av_gettime_relative() > wait_since + h->rw_timeout) | |
| 532 | ✗ | return AVERROR(EIO); | |
| 533 | } | ||
| 534 | ✗ | av_usleep(1000); | |
| 535 | } | ||
| 536 |
2/2✓ Branch 0 taken 12401 times.
✓ Branch 1 taken 606294 times.
|
618695 | } else if (ret == AVERROR_EOF) |
| 537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12401 times.
|
12401 | return (len > 0) ? len : AVERROR_EOF; |
| 538 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 606294 times.
|
606294 | else if (ret < 0) |
| 539 | ✗ | return ret; | |
| 540 |
1/2✓ Branch 0 taken 606294 times.
✗ Branch 1 not taken.
|
606294 | if (ret) { |
| 541 | 606294 | fast_retries = FFMAX(fast_retries, 2); | |
| 542 | 606294 | wait_since = 0; | |
| 543 | } | ||
| 544 | 606294 | len += ret; | |
| 545 | } | ||
| 546 | 606294 | return len; | |
| 547 | } | ||
| 548 | |||
| 549 | 222216 | int ffurl_read2(void *urlcontext, uint8_t *buf, int size) | |
| 550 | { | ||
| 551 | 222216 | URLContext *h = urlcontext; | |
| 552 | |||
| 553 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 222216 times.
|
222216 | if (!(h->flags & AVIO_FLAG_READ)) |
| 554 | ✗ | return AVERROR(EIO); | |
| 555 | 222216 | return retry_transfer_wrapper(h, buf, NULL, size, 1, 1); | |
| 556 | } | ||
| 557 | |||
| 558 | ✗ | int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) | |
| 559 | { | ||
| 560 | ✗ | if (!(h->flags & AVIO_FLAG_READ)) | |
| 561 | ✗ | return AVERROR(EIO); | |
| 562 | ✗ | return retry_transfer_wrapper(h, buf, NULL, size, size, 1); | |
| 563 | } | ||
| 564 | |||
| 565 | 396479 | int ffurl_write2(void *urlcontext, const uint8_t *buf, int size) | |
| 566 | { | ||
| 567 | 396479 | URLContext *h = urlcontext; | |
| 568 | |||
| 569 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 396479 times.
|
396479 | if (!(h->flags & AVIO_FLAG_WRITE)) |
| 570 | ✗ | return AVERROR(EIO); | |
| 571 | /* avoid sending too big packets */ | ||
| 572 |
3/4✓ Branch 0 taken 78915 times.
✓ Branch 1 taken 317564 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 78915 times.
|
396479 | if (h->max_packet_size && size > h->max_packet_size) |
| 573 | ✗ | return AVERROR(EIO); | |
| 574 | |||
| 575 | 396479 | return retry_transfer_wrapper(h, NULL, buf, size, size, 0); | |
| 576 | } | ||
| 577 | |||
| 578 | 369050 | int64_t ffurl_seek2(void *urlcontext, int64_t pos, int whence) | |
| 579 | { | ||
| 580 | 369050 | URLContext *h = urlcontext; | |
| 581 | int64_t ret; | ||
| 582 | |||
| 583 |
2/2✓ Branch 0 taken 32273 times.
✓ Branch 1 taken 336777 times.
|
369050 | if (!h->prot->url_seek) |
| 584 | 32273 | return AVERROR(ENOSYS); | |
| 585 | 336777 | ret = h->prot->url_seek(h, pos, whence & ~AVSEEK_FORCE); | |
| 586 | 336777 | return ret; | |
| 587 | } | ||
| 588 | |||
| 589 | 168899 | int ffurl_closep(URLContext **hh) | |
| 590 | { | ||
| 591 | 168899 | URLContext *h= *hh; | |
| 592 | 168899 | int ret = 0; | |
| 593 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168899 times.
|
168899 | if (!h) |
| 594 | ✗ | return 0; /* can happen when ffurl_open fails */ | |
| 595 | |||
| 596 |
3/4✓ Branch 0 taken 116350 times.
✓ Branch 1 taken 52549 times.
✓ Branch 2 taken 116350 times.
✗ Branch 3 not taken.
|
168899 | if (h->is_connected && h->prot->url_close) |
| 597 | 116350 | ret = h->prot->url_close(h); | |
| 598 | #if CONFIG_NETWORK | ||
| 599 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168899 times.
|
168899 | if (h->prot->flags & URL_PROTOCOL_FLAG_NETWORK) |
| 600 | ✗ | ff_network_close(); | |
| 601 | #endif | ||
| 602 |
1/2✓ Branch 0 taken 168899 times.
✗ Branch 1 not taken.
|
168899 | if (h->prot->priv_data_size) { |
| 603 |
2/2✓ Branch 0 taken 166099 times.
✓ Branch 1 taken 2800 times.
|
168899 | if (h->prot->priv_data_class) |
| 604 | 166099 | av_opt_free(h->priv_data); | |
| 605 | 168899 | av_freep(&h->priv_data); | |
| 606 | } | ||
| 607 | 168899 | av_opt_free(h); | |
| 608 | 168899 | av_freep(hh); | |
| 609 | 168899 | return ret; | |
| 610 | } | ||
| 611 | |||
| 612 | 168893 | int ffurl_close(URLContext *h) | |
| 613 | { | ||
| 614 | 168893 | return ffurl_closep(&h); | |
| 615 | } | ||
| 616 | |||
| 617 | 124248 | int avio_close(AVIOContext *s) | |
| 618 | { | ||
| 619 | 124248 | FFIOContext *const ctx = ffiocontext(s); | |
| 620 | URLContext *h; | ||
| 621 | int ret, error; | ||
| 622 | |||
| 623 |
2/2✓ Branch 0 taken 8307 times.
✓ Branch 1 taken 115941 times.
|
124248 | if (!s) |
| 624 | 8307 | return 0; | |
| 625 | |||
| 626 | 115941 | avio_flush(s); | |
| 627 | 115941 | h = s->opaque; | |
| 628 | 115941 | s->opaque = NULL; | |
| 629 | |||
| 630 | 115941 | av_freep(&s->buffer); | |
| 631 |
2/2✓ Branch 0 taken 9158 times.
✓ Branch 1 taken 106783 times.
|
115941 | if (s->write_flag) |
| 632 | 9158 | av_log(s, AV_LOG_VERBOSE, | |
| 633 | "Statistics: %"PRId64" bytes written, %d seeks, %d writeouts\n", | ||
| 634 | ctx->bytes_written, ctx->seek_count, ctx->writeout_count); | ||
| 635 | else | ||
| 636 | 106783 | av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n", | |
| 637 | ctx->bytes_read, ctx->seek_count); | ||
| 638 | 115941 | av_opt_free(s); | |
| 639 | |||
| 640 | 115941 | error = s->error; | |
| 641 | 115941 | avio_context_free(&s); | |
| 642 | |||
| 643 | 115941 | ret = ffurl_close(h); | |
| 644 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115941 times.
|
115941 | if (ret < 0) |
| 645 | ✗ | return ret; | |
| 646 | |||
| 647 | 115941 | return error; | |
| 648 | } | ||
| 649 | |||
| 650 | 16717 | int avio_closep(AVIOContext **s) | |
| 651 | { | ||
| 652 | 16717 | int ret = avio_close(*s); | |
| 653 | 16717 | *s = NULL; | |
| 654 | 16717 | return ret; | |
| 655 | } | ||
| 656 | |||
| 657 | |||
| 658 | 9514 | const char *avio_find_protocol_name(const char *url) | |
| 659 | { | ||
| 660 | 9514 | const URLProtocol *p = url_find_protocol(url); | |
| 661 | |||
| 662 |
1/2✓ Branch 0 taken 9514 times.
✗ Branch 1 not taken.
|
9514 | return p ? p->name : NULL; |
| 663 | } | ||
| 664 | |||
| 665 | 52390 | int avio_check(const char *url, int flags) | |
| 666 | { | ||
| 667 | URLContext *h; | ||
| 668 | 52390 | int ret = ffurl_alloc(&h, url, flags, NULL); | |
| 669 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52390 times.
|
52390 | if (ret < 0) |
| 670 | ✗ | return ret; | |
| 671 | |||
| 672 |
1/2✓ Branch 0 taken 52390 times.
✗ Branch 1 not taken.
|
52390 | if (h->prot->url_check) { |
| 673 | 52390 | ret = h->prot->url_check(h, flags); | |
| 674 | } else { | ||
| 675 | ✗ | ret = ffurl_connect(h, NULL); | |
| 676 | ✗ | if (ret >= 0) | |
| 677 | ✗ | ret = flags; | |
| 678 | } | ||
| 679 | |||
| 680 | 52390 | ffurl_close(h); | |
| 681 | 52390 | return ret; | |
| 682 | } | ||
| 683 | |||
| 684 | 79 | int ffurl_move(const char *url_src, const char *url_dst) | |
| 685 | { | ||
| 686 | URLContext *h_src, *h_dst; | ||
| 687 | 79 | int ret = ffurl_alloc(&h_src, url_src, AVIO_FLAG_READ_WRITE, NULL); | |
| 688 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
|
79 | if (ret < 0) |
| 689 | ✗ | return ret; | |
| 690 | 79 | ret = ffurl_alloc(&h_dst, url_dst, AVIO_FLAG_WRITE, NULL); | |
| 691 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
|
79 | if (ret < 0) { |
| 692 | ✗ | ffurl_close(h_src); | |
| 693 | ✗ | return ret; | |
| 694 | } | ||
| 695 | |||
| 696 |
2/4✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
|
79 | if (h_src->prot == h_dst->prot && h_src->prot->url_move) |
| 697 | 79 | ret = h_src->prot->url_move(h_src, h_dst); | |
| 698 | else | ||
| 699 | ✗ | ret = AVERROR(ENOSYS); | |
| 700 | |||
| 701 | 79 | ffurl_close(h_src); | |
| 702 | 79 | ffurl_close(h_dst); | |
| 703 | 79 | return ret; | |
| 704 | } | ||
| 705 | |||
| 706 | ✗ | int ffurl_delete(const char *url) | |
| 707 | { | ||
| 708 | URLContext *h; | ||
| 709 | ✗ | int ret = ffurl_alloc(&h, url, AVIO_FLAG_WRITE, NULL); | |
| 710 | ✗ | if (ret < 0) | |
| 711 | ✗ | return ret; | |
| 712 | |||
| 713 | ✗ | if (h->prot->url_delete) | |
| 714 | ✗ | ret = h->prot->url_delete(h); | |
| 715 | else | ||
| 716 | ✗ | ret = AVERROR(ENOSYS); | |
| 717 | |||
| 718 | ✗ | ffurl_close(h); | |
| 719 | ✗ | return ret; | |
| 720 | } | ||
| 721 | |||
| 722 | struct AVIODirContext { | ||
| 723 | struct URLContext *url_context; | ||
| 724 | }; | ||
| 725 | |||
| 726 | ✗ | int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options) | |
| 727 | { | ||
| 728 | ✗ | URLContext *h = NULL; | |
| 729 | ✗ | AVIODirContext *ctx = NULL; | |
| 730 | int ret; | ||
| 731 | ✗ | av_assert0(s); | |
| 732 | |||
| 733 | ✗ | ctx = av_mallocz(sizeof(*ctx)); | |
| 734 | ✗ | if (!ctx) { | |
| 735 | ✗ | ret = AVERROR(ENOMEM); | |
| 736 | ✗ | goto fail; | |
| 737 | } | ||
| 738 | |||
| 739 | ✗ | if ((ret = ffurl_alloc(&h, url, AVIO_FLAG_READ, NULL)) < 0) | |
| 740 | ✗ | goto fail; | |
| 741 | |||
| 742 | ✗ | if (h->prot->url_open_dir && h->prot->url_read_dir && h->prot->url_close_dir) { | |
| 743 | ✗ | if (options && h->prot->priv_data_class && | |
| 744 | ✗ | (ret = av_opt_set_dict(h->priv_data, options)) < 0) | |
| 745 | ✗ | goto fail; | |
| 746 | ✗ | ret = h->prot->url_open_dir(h); | |
| 747 | } else | ||
| 748 | ✗ | ret = AVERROR(ENOSYS); | |
| 749 | ✗ | if (ret < 0) | |
| 750 | ✗ | goto fail; | |
| 751 | |||
| 752 | ✗ | h->is_connected = 1; | |
| 753 | ✗ | ctx->url_context = h; | |
| 754 | ✗ | *s = ctx; | |
| 755 | ✗ | return 0; | |
| 756 | |||
| 757 | ✗ | fail: | |
| 758 | ✗ | av_free(ctx); | |
| 759 | ✗ | *s = NULL; | |
| 760 | ✗ | ffurl_close(h); | |
| 761 | ✗ | return ret; | |
| 762 | } | ||
| 763 | |||
| 764 | ✗ | int avio_read_dir(AVIODirContext *s, AVIODirEntry **next) | |
| 765 | { | ||
| 766 | URLContext *h; | ||
| 767 | int ret; | ||
| 768 | |||
| 769 | ✗ | if (!s || !s->url_context) | |
| 770 | ✗ | return AVERROR(EINVAL); | |
| 771 | ✗ | h = s->url_context; | |
| 772 | ✗ | if ((ret = h->prot->url_read_dir(h, next)) < 0) | |
| 773 | ✗ | avio_free_directory_entry(next); | |
| 774 | ✗ | return ret; | |
| 775 | } | ||
| 776 | |||
| 777 | ✗ | int avio_close_dir(AVIODirContext **s) | |
| 778 | { | ||
| 779 | URLContext *h; | ||
| 780 | |||
| 781 | ✗ | av_assert0(s); | |
| 782 | ✗ | if (!(*s) || !(*s)->url_context) | |
| 783 | ✗ | return AVERROR(EINVAL); | |
| 784 | ✗ | h = (*s)->url_context; | |
| 785 | ✗ | h->prot->url_close_dir(h); | |
| 786 | ✗ | ffurl_close(h); | |
| 787 | ✗ | av_freep(s); | |
| 788 | ✗ | *s = NULL; | |
| 789 | ✗ | return 0; | |
| 790 | } | ||
| 791 | |||
| 792 | ✗ | void avio_free_directory_entry(AVIODirEntry **entry) | |
| 793 | { | ||
| 794 | ✗ | if (!entry || !*entry) | |
| 795 | ✗ | return; | |
| 796 | ✗ | av_free((*entry)->name); | |
| 797 | ✗ | av_freep(entry); | |
| 798 | } | ||
| 799 | |||
| 800 | 4 | int64_t ffurl_size(URLContext *h) | |
| 801 | { | ||
| 802 | int64_t pos, size; | ||
| 803 | |||
| 804 | 4 | size = ffurl_seek(h, 0, AVSEEK_SIZE); | |
| 805 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (size < 0) { |
| 806 | ✗ | pos = ffurl_seek(h, 0, SEEK_CUR); | |
| 807 | ✗ | if ((size = ffurl_seek(h, -1, SEEK_END)) < 0) | |
| 808 | ✗ | return size; | |
| 809 | ✗ | size++; | |
| 810 | ✗ | ffurl_seek(h, pos, SEEK_SET); | |
| 811 | } | ||
| 812 | 4 | return size; | |
| 813 | } | ||
| 814 | |||
| 815 | ✗ | int ffurl_get_file_handle(URLContext *h) | |
| 816 | { | ||
| 817 | ✗ | if (!h || !h->prot || !h->prot->url_get_file_handle) | |
| 818 | ✗ | return -1; | |
| 819 | ✗ | return h->prot->url_get_file_handle(h); | |
| 820 | } | ||
| 821 | |||
| 822 | ✗ | int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles) | |
| 823 | { | ||
| 824 | ✗ | if (!h || !h->prot) | |
| 825 | ✗ | return AVERROR(ENOSYS); | |
| 826 | ✗ | if (!h->prot->url_get_multi_file_handle) { | |
| 827 | ✗ | if (!h->prot->url_get_file_handle) | |
| 828 | ✗ | return AVERROR(ENOSYS); | |
| 829 | ✗ | *handles = av_malloc(sizeof(**handles)); | |
| 830 | ✗ | if (!*handles) | |
| 831 | ✗ | return AVERROR(ENOMEM); | |
| 832 | ✗ | *numhandles = 1; | |
| 833 | ✗ | *handles[0] = h->prot->url_get_file_handle(h); | |
| 834 | ✗ | return 0; | |
| 835 | } | ||
| 836 | ✗ | return h->prot->url_get_multi_file_handle(h, handles, numhandles); | |
| 837 | } | ||
| 838 | |||
| 839 | 319115 | int ffurl_get_short_seek(void *urlcontext) | |
| 840 | { | ||
| 841 | 319115 | URLContext *h = urlcontext; | |
| 842 | |||
| 843 |
3/6✓ Branch 0 taken 319115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 319115 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 319115 times.
✗ Branch 5 not taken.
|
319115 | if (!h || !h->prot || !h->prot->url_get_short_seek) |
| 844 | 319115 | return AVERROR(ENOSYS); | |
| 845 | ✗ | return h->prot->url_get_short_seek(h); | |
| 846 | } | ||
| 847 | |||
| 848 | ✗ | int ffurl_shutdown(URLContext *h, int flags) | |
| 849 | { | ||
| 850 | ✗ | if (!h || !h->prot || !h->prot->url_shutdown) | |
| 851 | ✗ | return AVERROR(ENOSYS); | |
| 852 | ✗ | return h->prot->url_shutdown(h, flags); | |
| 853 | } | ||
| 854 | |||
| 855 | 821960 | int ff_check_interrupt(AVIOInterruptCB *cb) | |
| 856 | { | ||
| 857 |
3/4✓ Branch 0 taken 821960 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 794268 times.
✓ Branch 3 taken 27692 times.
|
821960 | if (cb && cb->callback) |
| 858 | 794268 | return cb->callback(cb->opaque); | |
| 859 | 27692 | return 0; | |
| 860 | } | ||
| 861 | |||
| 862 | 79 | int ff_rename(const char *url_src, const char *url_dst, void *logctx) | |
| 863 | { | ||
| 864 | 79 | int ret = ffurl_move(url_src, url_dst); | |
| 865 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
|
79 | if (ret < 0) |
| 866 | ✗ | av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", url_src, url_dst, av_err2str(ret)); | |
| 867 | 79 | return ret; | |
| 868 | } | ||
| 869 |