changeset 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 ebcf337f1786
children 990a80ea52d3
files stream/asf_streaming.c stream/http.c stream/network.c stream/network.h stream/pnm.c stream/stream_live555.c stream/stream_nemesi.c stream/stream_rtsp.c
diffstat 8 files changed, 18 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/stream/asf_streaming.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/asf_streaming.c	Sat Nov 10 13:19:29 2012 +0000
@@ -826,16 +826,12 @@
 }
 
 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
-	URL_t *url;
-
 	stream->streaming_ctrl = streaming_ctrl_new();
 	if( stream->streaming_ctrl==NULL ) {
 		return STREAM_ERROR;
 	}
 	stream->streaming_ctrl->bandwidth = network_bandwidth;
-	url = url_new(stream->url);
-	stream->streaming_ctrl->url = check4proxies(url);
-	url_free(url);
+	stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
 
 	mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_MPDEMUX_ASF_InfoStreamASFURL, stream->url);
 	if((!strncmp(stream->url, "http", 4)) && (*file_format!=DEMUXER_TYPE_ASF && *file_format!=DEMUXER_TYPE_UNKNOWN)) {
--- a/stream/http.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/http.c	Sat Nov 10 13:19:29 2012 +0000
@@ -217,7 +217,6 @@
 static int nop_streaming_start( stream_t *stream ) {
 	HTTP_header_t *http_hdr = NULL;
 	char *next_url=NULL;
-	URL_t *rd_url=NULL;
 	int fd,ret;
 	if( stream==NULL ) return -1;
 
@@ -247,12 +246,9 @@
 				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) {
+				if (next_url != NULL) {
 					mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url);
-							stream->streaming_ctrl->url=check4proxies(rd_url);
+							stream->streaming_ctrl->url=url_new_with_proxy(next_url);
 					ret=nop_streaming_start(stream); //recursively get streaming started
 				} else {
 					mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n");
@@ -890,16 +886,13 @@
 
 static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) {
 	int seekable=0;
-	URL_t *url;
 
 	stream->streaming_ctrl = streaming_ctrl_new();
 	if( stream->streaming_ctrl==NULL ) {
 		return STREAM_ERROR;
 	}
 	stream->streaming_ctrl->bandwidth = network_bandwidth;
-	url = url_new(stream->url);
-	stream->streaming_ctrl->url = check4proxies(url);
-	url_free(url);
+	stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
 
 	mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(1), URL: %s\n", stream->url);
 	seekable = http_streaming_start(stream, file_format);
@@ -919,16 +912,13 @@
 
 static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) {
 	int seekable=0;
-	URL_t *url;
 
 	stream->streaming_ctrl = streaming_ctrl_new();
 	if( stream->streaming_ctrl==NULL ) {
 		return STREAM_ERROR;
 	}
 	stream->streaming_ctrl->bandwidth = network_bandwidth;
-	url = url_new(stream->url);
-	stream->streaming_ctrl->url = check4proxies(url);
-	url_free(url);
+	stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
 
 	mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(2), URL: %s\n", stream->url);
 	seekable = http_streaming_start(stream, file_format);
--- a/stream/network.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/network.c	Sat Nov 10 13:19:29 2012 +0000
@@ -186,6 +186,14 @@
 	return url_out;
 }
 
+URL_t *url_new_with_proxy(const char *urlstr)
+{
+	URL_t *url = url_new(urlstr);
+	URL_t *url_with_proxy = check4proxies(url);
+	url_free(url);
+	return url_with_proxy;
+}
+
 int
 http_send_request( URL_t *url, off_t pos ) {
 	HTTP_header_t *http_hdr;
--- a/stream/network.h	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/network.h	Sat Nov 10 13:19:29 2012 +0000
@@ -84,6 +84,7 @@
 
 int http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry);
 URL_t* check4proxies(const URL_t *url);
+URL_t *url_new_with_proxy(const char *urlstr);
 
 void fixup_network_stream_cache(stream_t *stream);
 int http_seek(stream_t *stream, off_t pos);
--- a/stream/pnm.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/pnm.c	Sat Nov 10 13:19:29 2012 +0000
@@ -821,7 +821,6 @@
 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
   int fd;
   pnm_t *pnm;
-  URL_t *url;
 
   mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_PNM, URL: %s\n", stream->url);
   stream->streaming_ctrl = streaming_ctrl_new();
@@ -829,9 +828,7 @@
     return STREAM_ERROR;
 
   stream->streaming_ctrl->bandwidth = network_bandwidth;
-  url = url_new(stream->url);
-  stream->streaming_ctrl->url = check4proxies(url);
-  url_free(url);
+  stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
 
   fd = connect2Server( stream->streaming_ctrl->url->hostname,
     stream->streaming_ctrl->url->port ? stream->streaming_ctrl->url->port : 7070,1 );
--- a/stream/stream_live555.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/stream_live555.c	Sat Nov 10 13:19:29 2012 +0000
@@ -40,16 +40,12 @@
 
 
 static int open_live_rtsp_sip(stream_t *stream,int mode, void* opts, int* file_format) {
-  URL_t *url;
-
   stream->streaming_ctrl = streaming_ctrl_new();
   if( stream->streaming_ctrl==NULL ) {
     return STREAM_ERROR;
   }
   stream->streaming_ctrl->bandwidth = network_bandwidth;
-  url = url_new(stream->url);
-  stream->streaming_ctrl->url = check4proxies(url);
-  url_free(url);
+  stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
 
   mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_LIVE555, URL: %s\n", stream->url);
 
--- a/stream/stream_nemesi.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/stream_nemesi.c	Sat Nov 10 13:19:29 2012 +0000
@@ -47,7 +47,6 @@
 static int rtsp_streaming_open (stream_t *stream, int mode, void *opts,
                                 int *file_format)
 {
-    URL_t *url;
     stream->fd = -1;
 
     mp_msg (MSGT_OPEN, MSGL_V, "STREAM_RTSP, URL: %s\n", stream->url);
@@ -56,8 +55,7 @@
     return STREAM_ERROR;
 
     stream->streaming_ctrl->bandwidth = network_bandwidth;
-    url = url_new(stream->url);
-    stream->streaming_ctrl->url = check4proxies(url);
+    stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
     stream->streaming_ctrl->streaming_seek = rtsp_streaming_seek;
 
     *file_format = DEMUXER_TYPE_RTP_NEMESI;
--- a/stream/stream_rtsp.c	Sat Nov 10 13:18:38 2012 +0000
+++ b/stream/stream_rtsp.c	Sat Nov 10 13:19:29 2012 +0000
@@ -141,16 +141,13 @@
 static int
 rtsp_streaming_open (stream_t *stream, int mode, void *opts, int *file_format)
 {
-  URL_t *url;
-
   mp_msg (MSGT_OPEN, MSGL_V, "STREAM_RTSP, URL: %s\n", stream->url);
   stream->streaming_ctrl = streaming_ctrl_new ();
   if (!stream->streaming_ctrl)
     return STREAM_ERROR;
 
   stream->streaming_ctrl->bandwidth = network_bandwidth;
-  url = url_new (stream->url);
-  stream->streaming_ctrl->url = check4proxies (url);
+  stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
 
   stream->fd = -1;
   index_mode = -1; /* prevent most RTSP streams from locking due to -idx */