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
28 #if CONFIG_NETWORK
30 #endif
32
34
36 {
38 }
39
40 /** @name Logging context. */
41 /*@{*/
43 {
46 else return "NULL";
47 }
48
50 {
54 return NULL;
55 }
56
58 {
60
61 /* find the protocol that corresponds to prev */
64 break;
65
66 /* find next protocol with priv options */
70 return NULL;
71
72 }
73
82 };
83 /*@}*/
84
85
87 {
90 if (!(p = *opaque)) return NULL;
94 }
95
97 {
101 memcpy(temp, protocol, size);
103 }
105 while (*p != NULL) p = &(*p)->
next;
106 *p = protocol;
107 protocol->
next = NULL;
108 return 0;
109 }
110
112 const char *filename,
int flags,
114 {
116 int err;
117
118 #if CONFIG_NETWORK
121 #endif
124 "Impossible to open the '%s' protocol for reading\n", up->
name);
126 }
129 "Impossible to open the '%s' protocol for writing\n", up->
name);
131 }
133 if (!uc) {
135 goto fail;
136 }
148 goto fail;
149 }
151 int proto_len= strlen(up->
name);
158 char sep= *++p;
160 p++;
161 while(ret >= 0 && (key= strchr(p, sep)) && p<key && (val = strchr(key+1, sep))){
162 *val= *key= 0;
166 *val= *key= sep;
167 p= val+1;
168 }
169 if(ret<0 || p!=key){
174 goto fail;
175 }
176 memmove(start, key+1, strlen(key));
177 }
178 }
179 }
180 if (int_cb)
182
183 *puc = uc;
184 return 0;
185 fail:
186 *puc = NULL;
187 if (uc)
190 #if CONFIG_NETWORK
193 #endif
194 return err;
195 }
196
198 {
199 int err =
202 if (err)
203 return err;
205 //We must be careful here as ffurl_seek() could be slow, for example for http
210 return 0;
211 }
212
213 #define URL_SCHEME_CHARS \
214 "abcdefghijklmnopqrstuvwxyz" \
215 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
216 "0123456789+-."
217
220 {
222 char proto_str[128], proto_nested[128], *ptr;
224
225 if (!first_protocol) {
227 "Missing call to av_register_all()?\n");
228 }
229
230 if (filename[proto_len] != ':' &&
231 (filename[proto_len] != ',' || !strchr(filename + proto_len + 1, ':')) ||
233 strcpy(proto_str, "file");
234 else
235 av_strlcpy(proto_str, filename,
FFMIN(proto_len+1,
sizeof(proto_str)));
236
237 if ((ptr = strchr(proto_str, ',')))
238 *ptr = '0円';
239 av_strlcpy(proto_nested, proto_str,
sizeof(proto_nested));
240 if ((ptr = strchr(proto_nested, '+')))
241 *ptr = '0円';
242
244 if (!strcmp(proto_str, up->
name))
247 !strcmp(proto_nested, up->
name))
249 }
250 *puc = NULL;
251 if (!strcmp("https", proto_str))
252 av_log(NULL,
AV_LOG_WARNING,
"https protocol not found, recompile with openssl or gnutls enabled.\n");
254 }
255
258 {
260 if (ret)
262 if (options && (*puc)->prot->priv_data_class &&
264 goto fail;
266 if (!ret)
267 return 0;
268 fail:
270 *puc = NULL;
272 }
273
275 int (*transfer_func)(
URLContext *h,
unsigned char *buf,
int size))
276 {
278 int fast_retries = 5;
279 int64_t wait_since = 0;
280
281 len = 0;
282 while (len < size_min) {
285 ret = transfer_func(h, buf+len, size-len);
287 continue;
291 ret = 0;
292 if (fast_retries) {
293 fast_retries--;
294 } else {
296 if (!wait_since)
300 }
302 }
303 } else if (ret < 1)
305 if (ret)
306 fast_retries =
FFMAX(fast_retries, 2);
308 }
310 }
311
313 {
317 }
318
320 {
324 }
325
327 {
330 /* avoid sending too big packets */
333
335 }
336
338 {
340
345 }
346
348 {
351 if (!h) return 0; /* can happen when ffurl_open fails */
352
355 #if CONFIG_NETWORK
358 #endif
363 }
366 }
367
369 {
371 }
372
373
375 {
378 if (ret)
380
383 } else {
385 if (ret >= 0)
387 }
388
391 }
392
394 {
396
398 if(size<0){
402 size++;
404 }
406 }
407
409 {
411 return -1;
413 }
414
416 {
421 if (!*handles)
423 *numhandles = 1;
425 return 0;
426 }
428 }
429
431 {
435 }
436
438 {
442 return 0;
443 }