[Mplayer-cvslog] CVS: main/libmpdemux url.c,1.18,1.19 url.h,1.8,1.9

Bertrand Baudet bertrand at mplayerhq.hu
Wed Mar 26 12:28:11 CET 2003


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

Modified Files:
	url.c url.h 
Log Message:
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
Added const for arguments that shouldn't be changed


Index: url.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/url.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- url.c	19 Oct 2002 23:28:51 -0000	1.18
+++ url.c	26 Mar 2003 11:27:48 -0000	1.19
@@ -13,10 +13,10 @@
 #include "mp_msg.h"
 
 URL_t*
-url_new(char* url) {
+url_new(const char* url) {
 	int pos1, pos2;
 	URL_t* Curl;
-	char *ptr1, *ptr2, *ptr3;
+	char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL;
 
 	if( url==NULL ) return NULL;
 	
@@ -94,23 +94,36 @@
 		ptr1 = ptr2+1;
 		pos1 = ptr1-url;
 	}
+
+	// before looking for a port number check if we have an IPv6 type numeric address
+	// in IPv6 URL the numeric address should be inside square braces.
+	ptr2 = strstr(ptr1, "[");
+	ptr3 = strstr(ptr1, "]");
+	if( ptr2!=NULL && ptr3!=NULL ) {
+		// we have an IPv6 numeric address
+		ptr1++;
+		pos1++;
+		ptr2 = ptr3;
+	} else {
+		ptr2 = ptr1;
+
+	}
 	
 	// look if the port is given
-	ptr2 = strstr(ptr1, ":");
+	ptr2 = strstr(ptr2, ":");
 	// If the : is after the first / it isn't the port
 	ptr3 = strstr(ptr1, "/");
 	if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL;
 	if( ptr2==NULL ) {
 		// No port is given
 		// Look if a path is given
-		ptr2 = strstr(ptr1, "/");
-		if( ptr2==NULL ) {
+		if( ptr3==NULL ) {
 			// No path/filename
 			// So we have an URL like http://www.hostname.com
 			pos2 = strlen(url);
 		} else {
 			// We have an URL like http://www.hostname.com/file.txt
-			pos2 = ptr2-url;
+			pos2 = ptr3-url;
 		}
 	} else {
 		// We have an URL beginning like http://www.hostname.com:1212
@@ -118,6 +131,7 @@
 		Curl->port = atoi(ptr2+1);
 		pos2 = ptr2-url;
 	}
+	if( strstr(ptr1, "]")!=NULL ) pos2--;
 	// copy the hostname in the URL container
 	Curl->hostname = (char*)malloc(pos2-pos1+1);
 	if( Curl->hostname==NULL ) {
@@ -143,7 +157,7 @@
 			}
 		}
 	} 
-	// Check if a filenme was given or set, else set it with '/'
+	// Check if a filename was given or set, else set it with '/'
 	if( Curl->file==NULL ) {
 		Curl->file = (char*)malloc(2);
 		if( Curl->file==NULL ) {
@@ -174,7 +188,7 @@
 /* works like strcpy(), but without return argument */
 /* unescape_url_string comes from ASFRecorder */
 void
-url_unescape_string(char *outbuf, char *inbuf)
+url_unescape_string(char *outbuf, const char *inbuf)
 {
 	unsigned char c;
 	do {
@@ -199,7 +213,7 @@
 /* works like strcpy(), but without return argument */
 /* escape_url_string comes from ASFRecorder */
 void
-url_escape_string(char *outbuf, char *inbuf) {
+url_escape_string(char *outbuf, const char *inbuf) {
 	unsigned char c;
 	do {
 		c = *inbuf++;
@@ -230,7 +244,7 @@
 
 #ifdef __URL_DEBUG
 void
-url_debug(URL_t *url) {
+url_debug(const URL_t *url) {
 	if( url==NULL ) {
 		printf("URL pointer NULL\n");
 		return;

Index: url.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/url.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- url.h	5 Sep 2002 05:04:12 -0000	1.8
+++ url.h	26 Mar 2003 11:27:48 -0000	1.9
@@ -19,14 +19,14 @@
 	char *password;
 } URL_t;
 
-URL_t* url_new(char* url);
+URL_t* url_new(const char* url);
 void   url_free(URL_t* url);
 
-void url_unescape_string(char *outbuf, char *inbuf);
-void url_escape_string(char *outbuf, char *inbuf);
+void url_unescape_string(char *outbuf, const char *inbuf);
+void url_escape_string(char *outbuf, const char *inbuf);
 
 #ifdef __URL_DEBUG
-void url_debug(URL_t* url);
+void url_debug(const URL_t* url);
 #endif // __URL_DEBUG
 
 #endif // __URL_H



More information about the MPlayer-cvslog mailing list