| 314 | |
| 315 | |
| 316 | static int http_read(URLContext *h, uint8_t *buf, int size) |
| 317 | { |
| 318 | HTTPContext *s = h->priv_data; |
| 319 | int len; |
| 320 | |
| 321 | if (s->chunksize >= 0) { |
| 322 | if (!s->chunksize) { |
| 323 | char line[32]; |
| 324 | |
| 325 | for(;;) { |
| 326 | do { |
| 327 | if (http_get_line(s, line, sizeof(line)) < 0) |
| 328 | return AVERROR(EIO); |
| 329 | } while (!*line); /* skip CR LF from last chunk */ |
| 330 | |
| 331 | s->chunksize = strtoll(line, NULL, 16); |
| 332 | |
| 333 | dprintf(NULL, "Chunked encoding data size: %"PRId64"'\n", s->chunksize); |
| 334 | |
| 335 | if (!s->chunksize) |
| 336 | return 0; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | size = FFMIN(size, s->chunksize); |
| 341 | } |
| 342 | /* read bytes from input buffer first */ |
| 343 | len = s->buf_end - s->buf_ptr; |
| 344 | if (len > 0) { |
| 345 | if (len > size) |
| 346 | len = size; |
| 347 | memcpy(buf, s->buf_ptr, len); |
| 348 | s->buf_ptr += len; |
| 349 | } else { |
| 350 | len = url_read(s->hd, buf, size); |
| 351 | } |
| 352 | if (len > 0) { |
| 353 | s->off += len; |
| 354 | if (s->chunksize > 0) |
| 355 | s->chunksize -= len; |
| 356 | } |
| 357 | return len; |
| 358 | } |
| 359 | |
| 360 | /* used only when posting data */ |
| 361 | static int http_write(URLContext *h, uint8_t *buf, int size) |
nothing calls this directly
no test coverage detected