changeset 12268:4ab5c05ef3eb

Handle url redirection Patch by adland
author rtognimp
date Sat, 24 Apr 2004 13:16:16 +0000
parents 14bdbd687113
children c0c2eb1bfbf1
files libmpdemux/network.c
diffstat 1 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/network.c	Sat Apr 24 13:15:31 2004 +0000
+++ b/libmpdemux/network.c	Sat Apr 24 13:16:16 2004 +0000
@@ -903,7 +903,9 @@
 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 @@
 					}
 				}
 				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 {