Mercurial > mplayer.hg
comparison stream/http.c @ 35301:8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
author | reimar |
---|---|
date | Sat, 10 Nov 2012 13:19:29 +0000 |
parents | 1d9aaca72672 |
children | f570e9faa3c7 |
comparison
equal
deleted
inserted
replaced
35300:ebcf337f1786 | 35301:8f6d3f8ffa61 |
---|---|
215 } | 215 } |
216 | 216 |
217 static int nop_streaming_start( stream_t *stream ) { | 217 static int nop_streaming_start( stream_t *stream ) { |
218 HTTP_header_t *http_hdr = NULL; | 218 HTTP_header_t *http_hdr = NULL; |
219 char *next_url=NULL; | 219 char *next_url=NULL; |
220 URL_t *rd_url=NULL; | |
221 int fd,ret; | 220 int fd,ret; |
222 if( stream==NULL ) return -1; | 221 if( stream==NULL ) return -1; |
223 | 222 |
224 fd = stream->fd; | 223 fd = stream->fd; |
225 if( fd<0 ) { | 224 if( fd<0 ) { |
245 case 303: // See Other | 244 case 303: // See Other |
246 case 307: // Temporarily (since HTTP/1.1) | 245 case 307: // Temporarily (since HTTP/1.1) |
247 ret=-1; | 246 ret=-1; |
248 next_url = http_get_field( http_hdr, "Location" ); | 247 next_url = http_get_field( http_hdr, "Location" ); |
249 | 248 |
250 if (next_url != NULL) | 249 if (next_url != NULL) { |
251 rd_url=url_new(next_url); | |
252 | |
253 if (next_url != NULL && rd_url != NULL) { | |
254 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url); | 250 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url); |
255 stream->streaming_ctrl->url=check4proxies(rd_url); | 251 stream->streaming_ctrl->url=url_new_with_proxy(next_url); |
256 ret=nop_streaming_start(stream); //recursively get streaming started | 252 ret=nop_streaming_start(stream); //recursively get streaming started |
257 } else { | 253 } else { |
258 mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n"); | 254 mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n"); |
259 closesocket( fd ); | 255 closesocket( fd ); |
260 fd = -1; | 256 fd = -1; |
888 return STREAM_OK; | 884 return STREAM_OK; |
889 } | 885 } |
890 | 886 |
891 static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) { | 887 static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) { |
892 int seekable=0; | 888 int seekable=0; |
893 URL_t *url; | |
894 | 889 |
895 stream->streaming_ctrl = streaming_ctrl_new(); | 890 stream->streaming_ctrl = streaming_ctrl_new(); |
896 if( stream->streaming_ctrl==NULL ) { | 891 if( stream->streaming_ctrl==NULL ) { |
897 return STREAM_ERROR; | 892 return STREAM_ERROR; |
898 } | 893 } |
899 stream->streaming_ctrl->bandwidth = network_bandwidth; | 894 stream->streaming_ctrl->bandwidth = network_bandwidth; |
900 url = url_new(stream->url); | 895 stream->streaming_ctrl->url = url_new_with_proxy(stream->url); |
901 stream->streaming_ctrl->url = check4proxies(url); | |
902 url_free(url); | |
903 | 896 |
904 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(1), URL: %s\n", stream->url); | 897 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(1), URL: %s\n", stream->url); |
905 seekable = http_streaming_start(stream, file_format); | 898 seekable = http_streaming_start(stream, file_format); |
906 if((seekable < 0) || (*file_format == DEMUXER_TYPE_ASF)) { | 899 if((seekable < 0) || (*file_format == DEMUXER_TYPE_ASF)) { |
907 if (stream->fd >= 0) | 900 if (stream->fd >= 0) |
917 return fixup_open(stream, seekable); | 910 return fixup_open(stream, seekable); |
918 } | 911 } |
919 | 912 |
920 static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) { | 913 static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) { |
921 int seekable=0; | 914 int seekable=0; |
922 URL_t *url; | |
923 | 915 |
924 stream->streaming_ctrl = streaming_ctrl_new(); | 916 stream->streaming_ctrl = streaming_ctrl_new(); |
925 if( stream->streaming_ctrl==NULL ) { | 917 if( stream->streaming_ctrl==NULL ) { |
926 return STREAM_ERROR; | 918 return STREAM_ERROR; |
927 } | 919 } |
928 stream->streaming_ctrl->bandwidth = network_bandwidth; | 920 stream->streaming_ctrl->bandwidth = network_bandwidth; |
929 url = url_new(stream->url); | 921 stream->streaming_ctrl->url = url_new_with_proxy(stream->url); |
930 stream->streaming_ctrl->url = check4proxies(url); | |
931 url_free(url); | |
932 | 922 |
933 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(2), URL: %s\n", stream->url); | 923 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(2), URL: %s\n", stream->url); |
934 seekable = http_streaming_start(stream, file_format); | 924 seekable = http_streaming_start(stream, file_format); |
935 if(seekable < 0) { | 925 if(seekable < 0) { |
936 if (stream->fd >= 0) | 926 if (stream->fd >= 0) |