changeset 9690:a9b7b6055563

Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file Added const for arguments that shouldn't be changed
author bertrand
date Wed, 26 Mar 2003 11:27:48 +0000
parents 70bba63f7e46
children ed72c158215d
files libmpdemux/url.c libmpdemux/url.h
diffstat 2 files changed, 28 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/url.c	Wed Mar 26 01:03:13 2003 +0000
+++ b/libmpdemux/url.c	Wed Mar 26 11:27:48 2003 +0000
@@ -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;
--- a/libmpdemux/url.h	Wed Mar 26 01:03:13 2003 +0000
+++ b/libmpdemux/url.h	Wed Mar 26 11:27:48 2003 +0000
@@ -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