changeset 5915:f716aa9e2df2

Convert printf to mp_msg in the network layer
author albeu
date Tue, 30 Apr 2002 16:58:54 +0000
parents 808e7bda84fc
children 568a56e40a3f
files libmpdemux/asf_streaming.c libmpdemux/http.c libmpdemux/network.c mp_msg.h
diffstat 4 files changed, 135 insertions(+), 136 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/asf_streaming.c	Tue Apr 30 14:37:41 2002 +0000
+++ b/libmpdemux/asf_streaming.c	Tue Apr 30 16:58:54 2002 +0000
@@ -51,28 +51,28 @@
 	strncpy( proto_s, stream->streaming_ctrl->url->protocol, 10 );
 	
 	if( !strncasecmp( proto_s, "mms", 3) && strncasecmp( proto_s, "mmst", 4) ) {
-		printf("Trying ASF/UDP...\n");
+		mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/UDP...\n");
 		//fd = asf_mmsu_streaming_start( stream );
 		if( fd!=-1 ) return fd;
-		printf("  ===> ASF/UDP failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_V,"  ===> ASF/UDP failed\n");
 	}
 	if( !strncasecmp( proto_s, "mms", 3) ) {
-		printf("Trying ASF/TCP...\n");
+		mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/TCP...\n");
 		//fd = asf_mmst_streaming_start( stream );
 		if( fd!=-1 ) return fd;
-		printf("  ===> ASF/TCP failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_V,"  ===> ASF/TCP failed\n");
 	}
 	if( 	!strncasecmp( proto_s, "http", 4) || 
 		!strncasecmp( proto_s, "mms", 3)  ||
 		!strncasecmp( proto_s, "http_proxy", 10)
 		) {
-		printf("Trying ASF/HTTP...\n");
+		mp_msg(MSGT_NETWORK,MSGL_V,"Trying ASF/HTTP...\n");
 		fd = asf_http_streaming_start( stream );
 		if( fd!=-1 ) return fd;
-		printf("  ===> ASF/HTTP failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_V,"  ===> ASF/HTTP failed\n");
 	}
 
-	printf("Unknown protocol: %s\n", proto_s );
+	mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown protocol: %s\n", proto_s );
 	return -1;
 }
 
@@ -86,11 +86,11 @@
 	if( drop_packet!=NULL ) *drop_packet = 0;
 
 	if( stream_chunck->size<8 ) {
-		printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
 		return -1;
 	}
 	if( stream_chunck->size!=stream_chunck->size_confirm ) {
-		printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
 		return -1;
 	}
 /*	
@@ -102,7 +102,7 @@
 */
 	switch(stream_chunck->type) {
 		case ASF_STREAMING_CLEAR:	// $C	Clear ASF configuration
-			printf("=====> Clearing ASF stream configuration!\n");
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> Clearing ASF stream configuration!\n");
 			if( drop_packet!=NULL ) *drop_packet = 1;
 			return stream_chunck->size;
 			break;
@@ -110,15 +110,15 @@
 //			printf("=====> Data follows\n");
 			break;
 		case ASF_STREAMING_END_TRANS:	// $E	Transfer complete
-			printf("=====> Transfer complete\n");
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> Transfer complete\n");
 			if( drop_packet!=NULL ) *drop_packet = 1;
 			return stream_chunck->size;
 			break;
 		case ASF_STREAMING_HEADER:	// $H	ASF header chunk follows
-			printf("=====> ASF header chunk follows\n");
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF header chunk follows\n");
 			break;
 		default:
-			printf("=====> Unknown stream type 0x%x\n", stream_chunck->type );
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> Unknown stream type 0x%x\n", stream_chunck->type );
 	}
 	return stream_chunck->size+4;
 }
@@ -150,19 +150,19 @@
 	  // Endian handling of the stream chunk
 	  le2me_ASF_stream_chunck_t(&chunk);
 	  size = asf_streaming( &chunk, &r) - sizeof(ASF_stream_chunck_t);
-	  if(r) printf("Warning : drop header ????\n");
+	  if(r) mp_msg(MSGT_NETWORK,MSGL_WARN,"Warning : drop header ????\n");
 	  if(size < 0){
-	    printf("Error while parsing chunk header\n");
+	    mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while parsing chunk header\n");
 		return -1;
 	  }
 	  if (chunk.type != ASF_STREAMING_HEADER) {
-	    printf("Don't got a header as first chunk !!!!\n");
+	    mp_msg(MSGT_NETWORK,MSGL_ERR,"Don't got a header as first chunk !!!!\n");
 	    return -1;
 	  }
 	  
 	  buffer = (char*) malloc(size+buffer_size);
 	  if(buffer == NULL) {
-	    printf("Error can't allocate %d bytes buffer\n",size+buffer_size);
+	    mp_msg(MSGT_NETWORK,MSGL_FATAL,"Error can't allocate %d bytes buffer\n",size+buffer_size);
 	    return -1;
 	  }
 	  if( chunk_buffer!=NULL ) {
@@ -176,7 +176,7 @@
 	  for(r = 0; r < size;) {
 	    i = nop_streaming_read(fd,buffer+r,size-r,streaming_ctrl);
 	    if(i < 0) {
-		    printf("Error while reading network stream\n");
+		    mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while reading network stream\n");
 		    return -1;
 	    }
 	    r += i;
@@ -184,20 +184,20 @@
 
 	  if( chunk_size2read==0 ) {
 		if(size < (int)sizeof(asfh)) {
-		    printf("Error chunk is too small\n");
+		    mp_msg(MSGT_NETWORK,MSGL_ERR,"Error chunk is too small\n");
 		    return -1;
-		} else printf("Got chunk\n");
+		} else mp_msg(MSGT_NETWORK,MSGL_DBG2,"Got chunk\n");
 	  	memcpy(&asfh,buffer,sizeof(asfh));
 	  	le2me_ASF_header_t(&asfh);
 		chunk_size2read = asfh.objh.size;
-		printf("Size 2 read=%d\n", chunk_size2read);
+		mp_msg(MSGT_NETWORK,MSGL_DBG2,"Size 2 read=%d\n", chunk_size2read);
 	  }
   } while( buffer_size<chunk_size2read);
   buffer = chunk_buffer;
   size = buffer_size;
 	  
   if(asfh.cno > 256) {
-    printf("Error sub chunks number is invalid\n");
+    mp_msg(MSGT_NETWORK,MSGL_ERR,"Error sub chunks number is invalid\n");
     return -1;
   }
 
@@ -280,7 +280,7 @@
 				    streaming_ctrl );
 	if(r <= 0){
 	  if( r < 0) 
-	    printf("Error while reading chunk header\n");
+	    mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while reading chunk header\n");
 	  return -1;
 	}
 	read += r;
@@ -290,14 +290,14 @@
       le2me_ASF_stream_chunck_t(&chunk);
       chunk_size = asf_streaming( &chunk, &drop_chunk );
       if(chunk_size < 0) {
-	printf("Error while parsing chunk header\n");
+	mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while parsing chunk header\n");
 	return -1;
       }
       chunk_size -= sizeof(ASF_stream_chunck_t);
 	
       if(chunk.type != ASF_STREAMING_HEADER && (!drop_chunk)) {
 	if (asf_http_ctrl->packet_size < chunk_size) {
-	  printf("Error chunk_size > packet_size\n");
+	  mp_msg(MSGT_NETWORK,MSGL_ERR,"Error chunk_size > packet_size\n");
 	  return -1;
 	}
 	waiting = asf_http_ctrl->packet_size;
@@ -320,7 +320,7 @@
 	int got = nop_streaming_read( fd,buffer+read,chunk_size-read,streaming_ctrl );
 	if(got <= 0) {
 	  if(got < 0)
-	    printf("Error while reading chunk\n");
+	    mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while reading chunk\n");
 	  return -1;
 	}
 	read += got;
@@ -361,13 +361,13 @@
 	if( content_type==NULL ) return ASF_Unknown_e;
 	if( !strcasecmp(content_type, "application/octet-stream") ) {
 		if( features==NULL ) {
-			printf("=====> ASF Prerecorded\n");
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Prerecorded\n");
 			return ASF_Prerecorded_e;
 		} else if( strstr(features, "broadcast")) {
-			printf("=====> ASF Live stream\n");
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Live stream\n");
 			return ASF_Live_e;
 		} else {
-			printf("=====> ASF Prerecorded\n");
+			mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Prerecorded\n");
 			return ASF_Prerecorded_e;
 		}
 	} else {
@@ -377,10 +377,10 @@
 		// So we have to check for an asf header :(, but it works :p
 		if( http_hdr->body_size>sizeof(ASF_obj_header_t) ) {
 			if( asf_header_check( http_hdr )==0 ) {
-				printf("=====> ASF Plain text\n");
+				mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Plain text\n");
 				return ASF_PlainText_e;
 			} else {
-				printf("=====> ASF Redirector\n");
+				mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Redirector\n");
 				return ASF_Redirector_e;
 			}
 		} else {
@@ -391,13 +391,13 @@
 				(!strcasecmp(content_type, "video/x-ms-wvx")) ||
 				(!strcasecmp(content_type, "video/x-ms-wmv")) ||
 				(!strcasecmp(content_type, "video/x-ms-wma")) ) {
-				printf("=====> ASF Redirector\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"=====> ASF Redirector\n");
 				return ASF_Redirector_e;
 			} else if( !strcasecmp(content_type, "text/plain") ) {
-				printf("=====> ASF Plain text\n");
+				mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF Plain text\n");
 				return ASF_PlainText_e;
 			} else {
-				printf("=====> ASF unknown content-type: %s\n", content_type );
+				mp_msg(MSGT_NETWORK,MSGL_V,"=====> ASF unknown content-type: %s\n", content_type );
 				return ASF_Unknown_e;
 			}
 		}
@@ -433,7 +433,7 @@
 	if( !strcasecmp( url->protocol, "http_proxy" ) ) {
 		server_url = url_new( (url->file)+1 );
 		if( server_url==NULL ) {
-			printf("Invalid proxy URL\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Invalid proxy URL\n");
 			http_free( http_hdr );
 			return NULL;
 		}
@@ -469,7 +469,7 @@
 				}				
 				if(as < 0) {
 					if(audio_id > 0) 
-		       				printf("Audio stream %d don't exist\n", as);
+		       				mp_msg(MSGT_NETWORK,MSGL_ERR,"Audio stream %d don't exist\n", as);
 					as = asf_http_ctrl->audio_streams[0];
 				}
 				ptr += sprintf(ptr, " ffff:%d:0",as);
@@ -486,7 +486,7 @@
 				}
 				if(vs < 0) {
 					if(video_id > 0) 
-						printf("Video stream %d don't exist\n",vs);
+						mp_msg(MSGT_NETWORK,MSGL_ERR,"Video stream %d don't exist\n",vs);
 					vs = asf_http_ctrl->video_streams[0];
 		       		}
 				ptr += sprintf( ptr, " ffff:%d:0",vs);
@@ -502,7 +502,7 @@
 			// First request goes here.
 			break;
 		default:
-			printf("Unknown asf stream type\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown asf stream type\n");
 	}
 
 	http_set_field( http_hdr, "Connection: Close" );
@@ -517,11 +517,11 @@
 	char features[64] = "\0";
 	int len;
 	if( http_response_parse(http_hdr)<0 ) {
-		printf("Failed to parse HTTP response\n");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to parse HTTP response\n");
 		return -1;
 	}
 	if( http_hdr->status_code!=200 ) {
-		printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase);
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase);
 		return -1;
 	}
 
@@ -542,7 +542,7 @@
 				if( end==NULL ) {
 				  int s = strlen(pragma);
 				  if(s > sizeof(features)) {
-				    printf("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features));
+				    mp_msg(MSGT_NETWORK,MSGL_WARN,"ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features));
 				    len = sizeof(features);
 				  } else {				   
 				    len = s;
@@ -580,7 +580,7 @@
 
 	asf_http_ctrl = (asf_http_streaming_ctrl_t*)malloc(sizeof(asf_http_streaming_ctrl_t));
 	if( asf_http_ctrl==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return -1;
 	}
 	asf_http_ctrl->streaming_type = ASF_Unknown_e;
@@ -602,13 +602,11 @@
 		if( fd<0 ) return -1;
 
 		http_hdr = asf_http_request( stream->streaming_ctrl );
-		if( verbose>0 ) {
-			printf("Request [%s]\n", http_hdr->buffer );
-		}
+		mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request [%s]\n", http_hdr->buffer );
 		for(i=0; i <  http_hdr->buffer_size ; ) {
 			int r = write( fd, http_hdr->buffer+i, http_hdr->buffer_size-i );
 			if(r <0) {
-				printf("Socket write error : %s\n",strerror(errno));
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"Socket write error : %s\n",strerror(errno));
 				return -1;
 			}
 			i += r;
@@ -627,11 +625,11 @@
 		} while( !http_is_header_entire( http_hdr ) );
 		if( verbose>0 ) {
 			http_hdr->buffer[http_hdr->buffer_size]='\0';
-			printf("Response [%s]\n", http_hdr->buffer );
+			mp_msg(MSGT_NETWORK,MSGL_DBG2,"Response [%s]\n", http_hdr->buffer );
 		}
 		streaming_type = asf_http_parse_response(http_hdr);
 		if( streaming_type<0 ) {
-			printf("Failed to parse header\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to parse header\n");
 			http_free( http_hdr );
 			return -1;
 		}
@@ -652,7 +650,7 @@
 						ret = asf_streaming_parse_header(fd,stream->streaming_ctrl);
 						if(ret < 0) return -1;
 						if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) {
-							printf("No stream found\n");
+							mp_msg(MSGT_NETWORK,MSGL_ERR,"No stream found\n");
 							return -1;
 						}
 						asf_http_ctrl->request++;
@@ -674,7 +672,7 @@
 				break;
 			case ASF_Unknown_e:
 			default:
-				printf("Unknown ASF streaming type\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown ASF streaming type\n");
 				close(fd);
 				http_free( http_hdr );
 				return -1;
--- a/libmpdemux/http.c	Tue Apr 30 14:37:41 2002 +0000
+++ b/libmpdemux/http.c	Tue Apr 30 16:58:54 2002 +0000
@@ -10,6 +10,7 @@
 
 #include "http.h"
 #include "url.h"
+#include "mp_msg.h"
 
 HTTP_header_t *
 http_new_header() {
@@ -49,7 +50,7 @@
 	if( http_hdr==NULL || response==NULL || length<0 ) return -1;
 	ptr = (char*)malloc( http_hdr->buffer_size+length );
 	if( ptr==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return -1;
 	}
 	if( http_hdr->buffer_size==0 ) {
@@ -87,27 +88,27 @@
 	// Get the protocol
 	hdr_ptr = strstr( http_hdr->buffer, " " );
 	if( hdr_ptr==NULL ) {
-		printf("Malformed answer. No space separator found.\n");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. No space separator found.\n");
 		return -1;
 	}
 	len = hdr_ptr-http_hdr->buffer;
 	http_hdr->protocol = (char*)malloc(len+1);
 	if( http_hdr->protocol==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return -1;
 	}
 	strncpy( http_hdr->protocol, http_hdr->buffer, len );
 	http_hdr->protocol[len]='\0';
 	if( !strncasecmp( http_hdr->protocol, "HTTP", 4) ) {
 		if( sscanf( http_hdr->protocol+5,"1.%d", &(http_hdr->http_minor_version) )!=1 ) {
-			printf("Malformed answer. Unable to get HTTP minor version.\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get HTTP minor version.\n");
 			return -1;
 		}
 	}
 
 	// Get the status code
 	if( sscanf( ++hdr_ptr, "%d", &(http_hdr->status_code) )!=1 ) {
-		printf("Malformed answer. Unable to get status code.\n");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get status code.\n");
 		return -1;
 	}
 	hdr_ptr += 4;
@@ -115,13 +116,13 @@
 	// Get the reason phrase
 	ptr = strstr( hdr_ptr, "\n" );
 	if( hdr_ptr==NULL ) {
-		printf("Malformed answer. Unable to get the reason phrase.\n");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n");
 		return -1;
 	}
 	len = ptr-hdr_ptr;
 	http_hdr->reason_phrase = (char*)malloc(len+1);
 	if( http_hdr->reason_phrase==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return -1;
 	}
 	strncpy( http_hdr->reason_phrase, hdr_ptr, len );
@@ -135,7 +136,7 @@
 	if( ptr==NULL ) {
 		ptr = strstr( http_hdr->buffer, "\n\n" );
 		if( ptr==NULL ) {
-			printf("Header may be incomplete. No CRLF CRLF found.\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Header may be incomplete. No CRLF CRLF found.\n");
 			return -1;
 		}
 	}
@@ -150,7 +151,7 @@
 		if( len==0 ) break;
 		field = (char*)realloc(field, len+1);
 		if( field==NULL ) {
-			printf("Memory allocation failed\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
 			return -1;
 		}
 		strncpy( field, hdr_ptr, len );
@@ -166,7 +167,7 @@
 		int data_length = http_hdr->buffer_size-(pos_hdr_sep+4);
 		http_hdr->body = (char*)malloc( data_length );
 		if( http_hdr->body==NULL ) {
-			printf("Memory allocation failed\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
 			return -1;
 		}
 		memcpy( http_hdr->body, http_hdr->buffer+pos_hdr_sep+4, data_length );
@@ -189,7 +190,7 @@
 	else {
 		uri = (char*)malloc(strlen(http_hdr->uri)*2);
 		if( uri==NULL ) {
-			printf("Memory allocation failed\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
 			return NULL;
 		}
 		url_escape_string( uri, http_hdr->uri );
@@ -217,7 +218,7 @@
 	}
 	http_hdr->buffer = (char*)malloc(len+1);
 	if( http_hdr->buffer==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
 		return NULL;
 	}
 	http_hdr->buffer_size = len;
@@ -248,7 +249,7 @@
 	http_hdr->field_search_pos = http_hdr->first_field;
 	http_hdr->field_search = (char*)realloc( http_hdr->field_search, strlen(field_name)+1 );
 	if( http_hdr->field_search==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return NULL;
 	}
 	strcpy( http_hdr->field_search, field_name );
@@ -283,13 +284,13 @@
 
 	new_field = (HTTP_field_t*)malloc(sizeof(HTTP_field_t));
 	if( new_field==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return;
 	}
 	new_field->next = NULL;
 	new_field->field_name = (char*)malloc(strlen(field_name)+1);
 	if( new_field->field_name==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return;
 	}
 	strcpy( new_field->field_name, field_name );
@@ -309,7 +310,7 @@
 
 	http_hdr->method = (char*)malloc(strlen(method)+1);
 	if( http_hdr->method==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return;
 	}
 	strcpy( http_hdr->method, method );
@@ -321,7 +322,7 @@
 
 	http_hdr->uri = (char*)malloc(strlen(uri)+1);
 	if( http_hdr->uri==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return;
 	}
 	strcpy( http_hdr->uri, uri );
@@ -333,20 +334,20 @@
 	int i = 0;
 	if( http_hdr==NULL ) return;
 
-	printf("--- HTTP DEBUG HEADER --- START ---\n");
-	printf("protocol:           [%s]\n", http_hdr->protocol );
-	printf("http minor version: [%d]\n", http_hdr->http_minor_version );
-	printf("uri:                [%s]\n", http_hdr->uri );
-	printf("method:             [%s]\n", http_hdr->method );
-	printf("status code:        [%d]\n", http_hdr->status_code );
-	printf("reason phrase:      [%s]\n", http_hdr->reason_phrase );
-	printf("body size:          [%d]\n", http_hdr->body_size );
+	mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- START ---\n");
+	mp_msg(MSGT_NETWORK,MSGL_V,"protocol:           [%s]\n", http_hdr->protocol );
+	mp_msg(MSGT_NETWORK,MSGL_V,"http minor version: [%d]\n", http_hdr->http_minor_version );
+	mp_msg(MSGT_NETWORK,MSGL_V,"uri:                [%s]\n", http_hdr->uri );
+	mp_msg(MSGT_NETWORK,MSGL_V,"method:             [%s]\n", http_hdr->method );
+	mp_msg(MSGT_NETWORK,MSGL_V,"status code:        [%d]\n", http_hdr->status_code );
+	mp_msg(MSGT_NETWORK,MSGL_V,"reason phrase:      [%s]\n", http_hdr->reason_phrase );
+	mp_msg(MSGT_NETWORK,MSGL_V,"body size:          [%d]\n", http_hdr->body_size );
 
-	printf("Fields:\n");
+	mp_msg(MSGT_NETWORK,MSGL_V,"Fields:\n");
 	field = http_hdr->first_field;
 	while( field!=NULL ) {
-		printf(" %d - %s\n", i++, field->field_name );
+		mp_msg(MSGT_NETWORK,MSGL_V," %d - %s\n", i++, field->field_name );
 		field = field->next;
 	}
-	printf("--- HTTP DEBUG HEADER --- END ---\n");
+	mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- END ---\n");
 }
--- a/libmpdemux/network.c	Tue Apr 30 14:37:41 2002 +0000
+++ b/libmpdemux/network.c	Tue Apr 30 16:58:54 2002 +0000
@@ -84,7 +84,7 @@
 	streaming_ctrl_t *streaming_ctrl;
 	streaming_ctrl = (streaming_ctrl_t*)malloc(sizeof(streaming_ctrl_t));
 	if( streaming_ctrl==NULL ) {
-		printf("Failed to allocate memory\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Failed to allocate memory\n");
 		return NULL;
 	}
 	memset( streaming_ctrl, 0, sizeof(streaming_ctrl_t) );
@@ -112,7 +112,7 @@
 
 	getrtp2(fd, &rh, &data, &len);
 	if( got_first && rh.b.sequence != (unsigned short)(sequence+1) )
-		printf("RTP packet sequence error!  Expected: %d, received: %d\n", 
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"RTP packet sequence error!  Expected: %d, received: %d\n", 
 			sequence+1, rh.b.sequence);
 	got_first = 1;
 	sequence = rh.b.sequence;
@@ -130,11 +130,11 @@
 	struct timeval tv;
 	struct sockaddr_in server_address;
 
-	printf("Connecting to server %s:%d ...\n", host, port );
+	mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s:%d ...\n", host, port );
 
 	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
 	if( socket_server_fd==-1 ) {
-		perror("Failed to create socket");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket");
 		return -1;
 	}
 
@@ -142,7 +142,7 @@
 		struct hostent *hp;
 		hp=(struct hostent*)gethostbyname( host );
 		if( hp==NULL ) {
-			printf("Counldn't resolve name: %s\n", host);
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", host);
 			return -1;
 		}
 		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
@@ -156,7 +156,7 @@
 	fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
 	if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
 		if( errno!=EINPROGRESS ) {
-			perror("Failed to connect to server");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server");
 			close(socket_server_fd);
 			return -1;
 		}
@@ -167,13 +167,13 @@
 	FD_SET( socket_server_fd, &set );
 	// When the connection will be made, we will have a writable fd
 	while((ret = select(socket_server_fd+1, NULL, &set, NULL, &tv)) == 0) {
-	      if( ret<0 ) perror("select failed");
+	      if( ret<0 ) mp_msg(MSGT_NETWORK,MSGL_ERR,"select failed");
 	      else if(ret > 0) break;
 	      else if(count > 15 || mpdemux_check_interrupt(500)) {
 		if(count > 15)
-		  printf("Connection timeout\n");
+		  mp_msg(MSGT_NETWORK,MSGL_ERR,"Connection timeout\n");
 		else
-		  printf("Connection interuppted by user\n");
+		  mp_msg(MSGT_NETWORK,MSGL_V,"Connection interuppted by user\n");
 		return -1;
 	      }
 	      count++;
@@ -187,11 +187,11 @@
 	err_len = sizeof(int);
 	ret =  getsockopt(socket_server_fd,SOL_SOCKET,SO_ERROR,&err,&err_len);
 	if(ret < 0) {
-		printf("getsockopt failed : %s\n",strerror(errno));
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"getsockopt failed : %s\n",strerror(errno));
 		return -1;
 	}
 	if(err > 0) {
-		printf("Connect error : %s\n",strerror(err));
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Connect error : %s\n",strerror(err));
 		return -1;
 	}
 	return socket_server_fd;
@@ -203,7 +203,7 @@
 	if( url==NULL ) return NULL;
 	url_out = url_new( url->url );
 	if( !strcasecmp(url->protocol, "http_proxy") ) {
-		printf("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port );
+		mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: http://%s:%d\n", url->hostname, url->port );
 		return url_out;
 	}
 	// Check if the http_proxy environment variable is set.
@@ -218,18 +218,18 @@
 			URL_t *proxy_url = url_new( proxy );
 
 			if( proxy_url==NULL ) {
-				printf("Invalid proxy setting...Trying without proxy.\n");
+				mp_msg(MSGT_NETWORK,MSGL_WARN,"Invalid proxy setting...Trying without proxy.\n");
 				return url_out;
 			}
 
-			printf("Using HTTP proxy: %s\n", proxy_url->url );
+			mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n", proxy_url->url );
 			len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20;	// 20 = http_proxy:// + port
 			new_url = malloc( len+1 );
 			if( new_url==NULL ) {
-				printf("Memory allocation failed\n");
+				mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 				return url_out;
 			}
-			sprintf( new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url );
+			sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url );
 			tmp_url = url_new( new_url );
 			if( tmp_url==NULL ) {
 				return url_out;
@@ -281,13 +281,11 @@
 	if( fd<0 ) {
 		return -1; 
 	}
-	if( verbose ) {
-		printf("Request: [%s]\n", http_hdr->buffer );
-	}
+	mp_msg(MSGT_NETWORK,MSGL_DBG2,"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");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Error while sending HTTP request: didn't sent all the request\n");
 		return -1;
 	}
 	
@@ -310,12 +308,12 @@
 	do {
 		i = read( fd, response, BUFFER_SIZE ); 
 		if( i<0 ) {
-			printf("Read failed\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Read failed\n");
 			http_free( http_hdr );
 			return NULL;
 		}
 		if( i==0 ) {
-			printf("http_read_response read 0 -ie- EOF\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"http_read_response read 0 -ie- EOF\n");
 			http_free( http_hdr );
 			return NULL;
 		}
@@ -362,7 +360,7 @@
 		}
 extension=NULL;	
 		if( extension!=NULL ) {
-			printf("Extension: %s\n", extension );
+			mp_msg(MSGT_NETWORK,MSGL_DBG2,"Extension: %s\n", extension );
 			// Look for the extension in the extensions table
 			for( i=0 ; i<(sizeof(extensions_table)/sizeof(extensions_table[0])) ; i++ ) {
 				if( !strcasecmp(extension, extensions_table[i].extension) ) {
@@ -374,14 +372,14 @@
 
 		// Checking for RTSP
 		if( !strcasecmp(url->protocol, "rtsp") ) {
-			printf("RTSP protocol not yet implemented!\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"RTSP protocol not yet implemented!\n");
 			return -1;
 		}
 
 		// Checking for RTP
 		if( !strcasecmp(url->protocol, "rtp") ) {
 			if( url->port==0 ) {
-				printf("You must enter a port number for RTP streams!\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"You must enter a port number for RTP streams!\n");
 				return -1;
 			}
 			return 0;
@@ -422,28 +420,28 @@
 						// note: I skip icy-notice1 and 2, as they contain html <BR>
 						// and are IMHO useless info ::atmos
 						if( (field_data = http_get_field(http_hdr, "icy-name")) != NULL )
-							printf("Name   : %s\n", field_data); field_data = NULL;
+							mp_msg(MSGT_NETWORK,MSGL_INFO,"Name   : %s\n", field_data); field_data = NULL;
 						if( (field_data = http_get_field(http_hdr, "icy-genre")) != NULL )
-							printf("Genre  : %s\n", field_data); field_data = NULL;
+							mp_msg(MSGT_NETWORK,MSGL_INFO,"Genre  : %s\n", field_data); field_data = NULL;
 						if( (field_data = http_get_field(http_hdr, "icy-url")) != NULL )
-							printf("Website: %s\n", field_data); field_data = NULL;
+							mp_msg(MSGT_NETWORK,MSGL_INFO,"Website: %s\n", field_data); field_data = NULL;
 						// XXX: does this really mean public server? ::atmos
 						if( (field_data = http_get_field(http_hdr, "icy-pub")) != NULL )
-							printf("Public : %s\n", atoi(field_data)?"yes":"no"); field_data = NULL;
+							mp_msg(MSGT_NETWORK,MSGL_INFO,"Public : %s\n", atoi(field_data)?"yes":"no"); field_data = NULL;
 						if( (field_data = http_get_field(http_hdr, "icy-br")) != NULL )
-							printf("Bitrate: %skbit/s\n", field_data); field_data = NULL;
+							mp_msg(MSGT_NETWORK,MSGL_INFO,"Bitrate: %skbit/s\n", field_data); field_data = NULL;
 						// Ok, we have detected an mp3 stream
 						*file_format = DEMUXER_TYPE_AUDIO;
 						return 0;
 					}
 					case 401: // Service Unavailable
-						printf("Error: ICY-Server return service unavailable, skipping!\n");
+						mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return service unavailable, skipping!\n");
 						return -1;
 					case 404: // Resource Not Found
-						printf("Error: ICY-Server couldn't find requested stream, skipping!\n");
+						mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server couldn't find requested stream, skipping!\n");
 						return -1;
 					default:
-						printf("Error: unhandled ICY-Errorcode, contact MPlayer developers!\n");
+						mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: unhandled ICY-Errorcode, contact MPlayer developers!\n");
 						return -1;
 				}
 			}
@@ -455,9 +453,9 @@
 					content_type = http_get_field( http_hdr, "Content-Type" );
 					if( content_type!=NULL ) {
 						char *content_length = NULL;
-						printf("Content-Type: [%s]\n", content_type );
+						mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", content_type );
 						if( (content_length = http_get_field(http_hdr, "Content-Length")) != NULL)
-							printf("Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length"));
+							mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length"));
 						// Check in the mime type table for a demuxer type
 						for( i=0 ; i<(sizeof(mime_type_table)/sizeof(mime_type_table[0])) ; i++ ) {
 							if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) {
@@ -483,11 +481,11 @@
 					}
 					break;
 				default:
-					printf("Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
+					mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
 					return -1;
 			}
 		} else {
-			printf("Unknown protocol '%s'\n", url->protocol );
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown protocol '%s'\n", url->protocol );
 			return -1;
 		}
 	} while( redirect );
@@ -500,7 +498,7 @@
 //printf("streaming_bufferize\n");
 	streaming_ctrl->buffer = (char*)malloc(size);
 	if( streaming_ctrl->buffer==NULL ) {
-		printf("Memory allocation failed\n");
+		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
 		return -1;
 	}
 	memcpy( streaming_ctrl->buffer, buffer, size );
@@ -533,7 +531,7 @@
 		int ret;
 		ret = read( fd, buffer+len, size-len );
 		if( ret<0 ) {
-			printf("nop_streaming_read error : %s\n",strerror(errno));
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_read error : %s\n",strerror(errno));
 		}
 		len += ret;
 //printf("read %d bytes from network\n", len );
@@ -562,8 +560,8 @@
 
 		switch( http_hdr->status_code ) {
 			case 200: // OK
-				printf("Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") );
-				printf("Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
+				mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") );
+				mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
 				if( http_hdr->body_size>0 ) {
 					if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
 						http_free( http_hdr );
@@ -572,7 +570,7 @@
 				}
 				break;
 			default:
-				printf("Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
 				close( fd );
 				fd = -1;
 		}
@@ -611,19 +609,19 @@
 	struct ip_mreq mcast;
         struct timeval tv;
 
-	printf("Listening for traffic on %s:%d ...\n", url->hostname, url->port );
+	mp_msg(MSGT_NETWORK,MSGL_V,"Listening for traffic on %s:%d ...\n", url->hostname, url->port );
 
 	socket_server_fd = socket(AF_INET, SOCK_DGRAM, 0);
 //	fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
 	if( socket_server_fd==-1 ) {
-		perror("Failed to create socket");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket");
 		return -1;
 	}
 
 	if( isalpha(url->hostname[0]) ) {
 		struct hostent *hp =(struct hostent*)gethostbyname( url->hostname );
 		if( hp==NULL ) {
-			printf("Counldn't resolve name: %s\n", url->hostname);
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
 			return -1;
 		}
 		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
@@ -635,7 +633,7 @@
 
 	if( bind( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
 		if( errno!=EINPROGRESS ) {
-			perror("Failed to connect to server");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server");
 			close(socket_server_fd);
 			return -1;
 		}
@@ -644,7 +642,7 @@
 	// Increase the socket rx buffer size to maximum -- this is UDP
 	rxsockbufsz = 240 * 1024;
 	if( setsockopt( socket_server_fd, SOL_SOCKET, SO_RCVBUF, &rxsockbufsz, sizeof(rxsockbufsz))) {
-		perror("Couldn't set receive socket buffer size");
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Couldn't set receive socket buffer size");
 	}
 
 	if((ntohl(server_address.sin_addr.s_addr) >> 28) == 0xe) {
@@ -652,7 +650,7 @@
 		//mcast.imr_interface.s_addr = inet_addr("10.1.1.2");
 		mcast.imr_interface.s_addr = 0;
 		if( setsockopt( socket_server_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof(mcast))) {
-			perror("IP_ADD_MEMBERSHIP failed (do you have multicasting enabled in your kernel?)");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"IP_ADD_MEMBERSHIP failed (do you have multicasting enabled in your kernel?)");
 			return -1;
 		}
 	}
@@ -666,8 +664,8 @@
 		err_len = sizeof( err );
 		getsockopt( socket_server_fd, SOL_SOCKET, SO_ERROR, &err, &err_len );
 		if( err ) {
-			printf("Timeout! No data from host %s\n", url->hostname );
-			printf("Socket error: %d\n", err );
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Timeout! No data from host %s\n", url->hostname );
+			mp_msg(MSGT_NETWORK,MSGL_DBG2,"Socket error: %d\n", err );
 			close(socket_server_fd);
 			return -1;
 		}
@@ -723,7 +721,7 @@
 	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));
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"streaming_start : Closing socket %d failed %s\n",stream->fd,strerror(errno));
 		}
 		stream->fd = -1;
 		ret = rtp_streaming_start( stream );
@@ -736,7 +734,7 @@
 			// ASF raw stream is encapsulated.
 			ret = asf_streaming_start( stream );
 			if( ret<0 ) {
-				printf("asf_streaming_start failed\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"asf_streaming_start failed\n");
 			}
 			break;
 		case DEMUXER_TYPE_MPEG_ES:
@@ -756,13 +754,13 @@
 			// the network stream, it's a raw stream
 			ret = nop_streaming_start( stream );
 			if( ret<0 ) {
-				printf("nop_streaming_start failed\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_start failed\n");
 			}
 			if((*demuxer_type) == DEMUXER_TYPE_PLAYLIST)
 			  stream->type = STREAMTYPE_PLAYLIST;
 			break;
 		default:
-			printf("Unable to detect the streaming type\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Unable to detect the streaming type\n");
 			ret = -1;
 	}
 
@@ -774,14 +772,14 @@
 		int ret, val;
 		ret = m_config_is_option_set(mconfig,"cache");
 		if(ret < 0) {
-			printf("Unable to know if cache size option was set\n");
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Unable to know if cache size option was set\n");
 		} else if(!ret) {
 			// cache option not set, will use the our computed value.
 			// buffer in KBytes, *5 because the prefill is 20% of the buffer.
 			val = (stream->streaming_ctrl->prebuffer_size/1024)*5;
 			if( val<16 ) val = 16;	// 16KBytes min buffer
 			if( m_config_set_int( mconfig, "cache", val )<0 ) { 
-				printf("Unable to set the cache size option\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"Unable to set the cache size option\n");
 			} else {
 				cache_size = val;
 			}
@@ -789,12 +787,12 @@
 			// cache option set, will use the given one.
 			val = m_config_get_int( mconfig, "cache", NULL );
 			if( val<0 ) {
-				printf("Unable to retrieve the cache option value\n");
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"Unable to retrieve the cache option value\n");
 			} else {
 				cache_size = val;
 			}
 		}
-		printf("Cache size set to %d KBytes\n", cache_size );
+		mp_msg(MSGT_NETWORK,MSGL_INFO,"Cache size set to %d KBytes\n", cache_size );
 	}
 	return ret;
 }
--- a/mp_msg.h	Tue Apr 30 14:37:41 2002 +0000
+++ b/mp_msg.h	Tue Apr 30 16:58:54 2002 +0000
@@ -70,6 +70,8 @@
 
 #define MSGT_OSD 30
 
+#define MSGT_NETWORK 31
+
 #define MSGT_MAX 64
 
 void mp_msg_init();