Mercurial > libavformat.hg
comparison http.c @ 5544:fc48f8bfbf2e libavformat
restore old buffer content when seek failed in http protocol, fix issue #1631
| author | bcoudurier |
|---|---|
| date | Wed, 13 Jan 2010 23:27:52 +0000 |
| parents | 2d0a0d3e5df1 |
| children | 7c7fe75728dd |
comparison
equal
deleted
inserted
replaced
| 5543:fbedfacb36ed | 5544:fc48f8bfbf2e |
|---|---|
| 392 static int64_t http_seek(URLContext *h, int64_t off, int whence) | 392 static int64_t http_seek(URLContext *h, int64_t off, int whence) |
| 393 { | 393 { |
| 394 HTTPContext *s = h->priv_data; | 394 HTTPContext *s = h->priv_data; |
| 395 URLContext *old_hd = s->hd; | 395 URLContext *old_hd = s->hd; |
| 396 int64_t old_off = s->off; | 396 int64_t old_off = s->off; |
| 397 uint8_t old_buf[BUFFER_SIZE]; | |
| 398 int old_buf_size; | |
| 397 | 399 |
| 398 if (whence == AVSEEK_SIZE) | 400 if (whence == AVSEEK_SIZE) |
| 399 return s->filesize; | 401 return s->filesize; |
| 400 else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed) | 402 else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed) |
| 401 return -1; | 403 return -1; |
| 402 | 404 |
| 403 /* we save the old context in case the seek fails */ | 405 /* we save the old context in case the seek fails */ |
| 406 old_buf_size = s->buf_end - s->buf_ptr; | |
| 407 memcpy(old_buf, s->buf_ptr, old_buf_size); | |
| 404 s->hd = NULL; | 408 s->hd = NULL; |
| 405 if (whence == SEEK_CUR) | 409 if (whence == SEEK_CUR) |
| 406 off += s->off; | 410 off += s->off; |
| 407 else if (whence == SEEK_END) | 411 else if (whence == SEEK_END) |
| 408 off += s->filesize; | 412 off += s->filesize; |
| 409 s->off = off; | 413 s->off = off; |
| 410 | 414 |
| 411 /* if it fails, continue on old connection */ | 415 /* if it fails, continue on old connection */ |
| 412 if (http_open_cnx(h) < 0) { | 416 if (http_open_cnx(h) < 0) { |
| 417 memcpy(s->buffer, old_buf, old_buf_size); | |
| 418 s->buf_ptr = s->buffer; | |
| 419 s->buf_end = s->buffer + old_buf_size; | |
| 413 s->hd = old_hd; | 420 s->hd = old_hd; |
| 414 s->off = old_off; | 421 s->off = old_off; |
| 415 return -1; | 422 return -1; |
| 416 } | 423 } |
| 417 url_close(old_hd); | 424 url_close(old_hd); |
