From 94e2c8385bf9bb43175f6bb44c265843f0a53ee5 Mon Sep 17 00:00:00 2001 From: rtognimp Date: Sat, 24 Apr 2004 13:16:16 +0000 Subject: Handle url redirection Patch by adland git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12269 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/network.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/libmpdemux/network.c b/libmpdemux/network.c index 9694d48fb8..92c02f3bd1 100644 --- a/libmpdemux/network.c +++ b/libmpdemux/network.c @@ -903,7 +903,9 @@ nop_streaming_seek( int fd, off_t pos, streaming_ctrl_t *stream_ctrl ) { int nop_streaming_start( stream_t *stream ) { HTTP_header_t *http_hdr = NULL; - int fd; + char *next_url=NULL; + URL_t *rd_url=NULL; + int fd,ret; if( stream==NULL ) return -1; fd = stream->fd; @@ -924,10 +926,36 @@ nop_streaming_start( stream_t *stream ) { } } break; + // Redirect + case 301: // Permanently + case 302: // Temporarily + ret=-1; + next_url = http_get_field( http_hdr, "Location" ); + + if (next_url != NULL) + rd_url=url_new(next_url); + + if (next_url != NULL && rd_url != NULL) { + mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url); + stream->streaming_ctrl->url=check4proxies(rd_url); + ret=nop_streaming_start(stream); //recursively get streaming started + } else { + mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n"); + closesocket( fd ); + fd = -1; + } + return ret; + break; + case 401: //Authorization required + case 403: //Forbidden + case 404: //Not found + case 500: //Server Error default: - mp_msg(MSGT_NETWORK,MSGL_ERR,"Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); + mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned code %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); closesocket( fd ); fd = -1; + return -1; + break; } stream->fd = fd; } else { -- cgit v1.2.3