[Mplayer-cvslog] CVS: main/libmpdemux asf_streaming.c,1.18,1.19 network.c,1.23,1.24

Bertrand Baudet bertrand at mplayer.dev.hu
Sat Jan 12 22:08:14 CET 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mplayer:/var/tmp.root/cvs-serv10907/libmpdemux

Modified Files:
	asf_streaming.c network.c 
Log Message:
Added proxy support.


Index: asf_streaming.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/asf_streaming.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- asf_streaming.c	10 Jan 2002 01:42:31 -0000	1.18
+++ asf_streaming.c	12 Jan 2002 21:08:12 -0000	1.19
@@ -61,7 +61,10 @@
 		if( fd!=-1 ) return fd;
 		printf("  ===> ASF/TCP failed\n");
 	}
-	if( !strncasecmp( proto_s, "http", 4) || !strncasecmp( proto_s, "mms", 3) ) {
+	if( 	!strncasecmp( proto_s, "http", 4) || 
+		!strncasecmp( proto_s, "mms", 3)  ||
+		!strncasecmp( proto_s, "proxy", 5)
+		) {
 		printf("Trying ASF/HTTP...\n");
 		fd = asf_http_streaming_start( stream );
 		if( fd!=-1 ) return fd;
@@ -373,8 +376,9 @@
 HTTP_header_t *
 asf_http_request(streaming_ctrl_t *streaming_ctrl) {
 	HTTP_header_t *http_hdr;
-	URL_t *url = streaming_ctrl->url;
-	asf_http_streaming_ctrl_t *asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data;
+	URL_t *url = NULL;
+	URL_t *server_url = NULL;
+	asf_http_streaming_ctrl_t *asf_http_ctrl;
 	char str[250];
 	char *ptr;
 	int i,as = -1,vs = -1;
@@ -382,12 +386,33 @@
 	int offset_hi=0, offset_lo=0, length=0;
 	int asf_nb_stream=0;
 
+	// Sanity check
+	if( streaming_ctrl==NULL ) return NULL;
+	url = streaming_ctrl->url;
+	asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data;
+	if( url==NULL || asf_http_ctrl==NULL ) return NULL;
+
 	// Common header for all requests.
 	http_hdr = http_new_header();
-	http_set_uri( http_hdr, url->file );
 	http_set_field( http_hdr, "Accept: */*" );
 	http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" );
-        sprintf( str, "Host: %s:%d", url->hostname, url->port );
+
+	// Check if we are using a proxy
+	if( !strcasecmp( url->protocol, "proxy" ) ) {
+		server_url = url_new( (url->file)+1 );
+		if( server_url==NULL ) {
+			printf("Invalid proxy URL\n");
+			http_free( http_hdr );
+			return NULL;
+		}
+		http_set_uri( http_hdr, server_url->url );
+		sprintf( str, "Host: %s:%d", server_url->hostname, server_url->port );
+		url_free( server_url );
+	} else {
+		http_set_uri( http_hdr, url->file );
+		sprintf( str, "Host: %s:%d", url->hostname, url->port );
+	}
+	
 	http_set_field( http_hdr, str );
 	http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" );
 	sprintf(str, 
@@ -509,16 +534,6 @@
 	return asf_http_streaming_type( content_type, features );
 }
 
-URL_t *
-asf_http_ASX_redirect( HTTP_header_t *http_hdr ) {
-	URL_t *url_redirect=NULL;
-	printf("=========>> ASX parser not yet implemented <<==========\n");
-
-	printf("ASX=[%s]\n", http_hdr->body );
-
-	return url_redirect;
-}
-
 int
 asf_http_streaming_start( stream_t *stream ) {
 	HTTP_header_t *http_hdr=NULL;
@@ -546,7 +561,11 @@
 		done = 1;
 		if( fd>0 ) close( fd );
 
-		if( url->port==0 ) url->port = 80;
+		if( !strcasecmp( url->protocol, "proxy" ) ) {
+			if( url->port==0 ) url->port = 8080;
+		} else {
+			if( url->port==0 ) url->port = 80;
+		}
 		fd = connect2Server( url->hostname, url->port );
 		if( fd<0 ) return -1;
 
@@ -566,7 +585,7 @@
 		http_hdr = http_new_header();
 		do {
 			i = read( fd, buffer, BUFFER_SIZE );
-printf("read: %d\n", i );
+//printf("read: %d\n", i );
 			if( i<0 ) {
 				perror("read");
 				http_free( http_hdr );

Index: network.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/network.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- network.c	10 Jan 2002 01:37:53 -0000	1.23
+++ network.c	12 Jan 2002 21:08:12 -0000	1.24
@@ -25,6 +25,8 @@
 #include "asf.h"
 #include "rtp.h"
 
+extern int verbose;
+
 static struct {
 	char *mime_type;
 	int demuxer_type;
@@ -174,11 +176,23 @@
 int
 http_send_request( URL_t *url ) {
 	HTTP_header_t *http_hdr;
+	URL_t *server_url;
 	char str[80];
 	int fd;
+	int ret;
+	int proxy = 0;		// Boolean
+
 	http_hdr = http_new_header();
-	http_set_uri( http_hdr, url->file );
-	snprintf(str, 80, "Host: %s", url->hostname );
+
+	if( !strcasecmp(url->protocol, "proxy") ) {
+		proxy = 1;
+		server_url = url_new( (url->file)+1 );
+		http_set_uri( http_hdr, server_url->url );
+	} else {
+		server_url = url;
+		http_set_uri( http_hdr, server_url->file );
+	}
+	snprintf(str, 80, "Host: %s", server_url->hostname );
 	http_set_field( http_hdr, str);
 	http_set_field( http_hdr, "User-Agent: MPlayer");
 	http_set_field( http_hdr, "Connection: closed");
@@ -186,12 +200,27 @@
 		return -1;
 	}
 
-	if( url->port==0 ) url->port = 80;
-	fd = connect2Server( url->hostname, url->port );
+	if( proxy ) {
+		if( url->port==0 ) url->port = 8080;			// Default port for the proxy server
+		fd = connect2Server( url->hostname, url->port );
+		url_free( server_url );
+	} else {
+		if( server_url->port==0 ) server_url->port = 80;	// Default port for the web server
+		fd = connect2Server( server_url->hostname, server_url->port );
+	}
 	if( fd<0 ) {
 		return -1; 
 	}
-	write( fd, http_hdr->buffer, http_hdr->buffer_size );
+	if( verbose ) {
+		printf("Request: [%s]\n", http_hdr->buffer );
+	}
+	
+	ret = write( fd, http_hdr->buffer, http_hdr->buffer_size );
+	if( ret!=http_hdr->buffer_size ) {
+		printf("Error while sending HTTP request: didn't sent all the request\n");
+		return -1;
+	}
+	
 	http_free( http_hdr );
 
 	return fd;
@@ -296,8 +325,8 @@
 		}
 
 		// HTTP based protocol
-		if( !strcasecmp(url->protocol, "http") ) {
-			if( url->port==0 ) url->port = 80;
+		if( !strcasecmp(url->protocol, "http") || !strcasecmp(url->protocol, "proxy") ) {
+			//if( url->port==0 ) url->port = 80;
 
 			fd = http_send_request( url );
 			if( fd<0 ) {
@@ -312,8 +341,10 @@
 			}
 
 			*fd_out=fd;
-			http_debug_hdr( http_hdr );
-
+			if( verbose ) {
+				http_debug_hdr( http_hdr );
+			}
+			
 			streaming_ctrl->data = (void*)http_hdr;
 			
 			// Check if the response is an ICY status_code reason_phrase
@@ -582,7 +613,7 @@
 	if( stream==NULL ) return -1;
 	
 	// For RTP streams, we usually don't know the stream type until we open it.
-	if( !strcmp( stream->streaming_ctrl->url->protocol, "rtp")) {
+	if( !strcasecmp( stream->streaming_ctrl->url->protocol, "rtp")) {
 		if(stream->fd >= 0) {
 			if(close(stream->fd) < 0)
 				printf("streaming_start : Closing socket %d failed %s\n",stream->fd,strerror(errno));




More information about the MPlayer-cvslog mailing list