From c407b9b070d57361f888228037b7b9ce712dc6e2 Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 8 Nov 2006 22:42:31 +0000 Subject: Support URL redirections that do not specify full URL. Fixes crash with mplayer -playlist http://www.radioseven.se/radioseven.pls. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@20800 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/http.c | 3 +-- stream/url.c | 19 +++++++++++++++++++ stream/url.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/stream/http.c b/stream/http.c index 013c6491d9..8ae933a2bb 100644 --- a/stream/http.c +++ b/stream/http.c @@ -835,8 +835,7 @@ static int http_streaming_start(stream_t *stream, int* file_format) { next_url = http_get_field( http_hdr, "Location" ); if( next_url!=NULL ) { closesocket( fd ); - url_free( url ); - stream->streaming_ctrl->url = url = url_new( next_url ); + stream->streaming_ctrl->url = url_redirect( &url, next_url ); http_free( http_hdr ); redirect = 1; } diff --git a/stream/url.c b/stream/url.c index 52b850609b..a198628fe1 100644 --- a/stream/url.c +++ b/stream/url.c @@ -19,6 +19,25 @@ #define SIZE_MAX ((size_t)-1) #endif +URL_t *url_redirect(URL_t **url, const char *redir) { + URL_t *u = *url; + URL_t *res; + if (!strchr(redir, '/')) { + char *tmp; + char *newurl = malloc(strlen(u->url) + strlen(redir) + 1); + strcpy(newurl, u->url); + tmp = strrchr(newurl, '/'); + if (tmp) tmp[1] = 0; + strcat(newurl, redir); + res = url_new(newurl); + free(newurl); + } else + res = url_new(redir); + url_free(u); + *url = res; + return res; +} + URL_t* url_new(const char* url) { int pos1, pos2,v6addr = 0; diff --git a/stream/url.h b/stream/url.h index e344e75c85..1c2db9191a 100644 --- a/stream/url.h +++ b/stream/url.h @@ -19,6 +19,7 @@ typedef struct { char *password; } URL_t; +URL_t *url_redirect(URL_t **url, const char *redir); URL_t* url_new(const char* url); void url_free(URL_t* url); -- cgit v1.2.3