summaryrefslogtreecommitdiffstats
path: root/libmpdemux
diff options
context:
space:
mode:
authorbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-03-26 11:27:48 +0000
committerbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-03-26 11:27:48 +0000
commitdc49bda4bbb1f84e1c90fbf7457673cd660b32b5 (patch)
tree1f47eef9e10207e3ccbbb802034ef6f2ff4ae6d9 /libmpdemux
parentabca28586ac2fa2e257fd4767c1916e51ed5a249 (diff)
downloadmpv-dc49bda4bbb1f84e1c90fbf7457673cd660b32b5.tar.bz2
mpv-dc49bda4bbb1f84e1c90fbf7457673cd660b32b5.tar.xz
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
Added const for arguments that shouldn't be changed git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9691 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/url.c34
-rw-r--r--libmpdemux/url.h8
2 files changed, 28 insertions, 14 deletions
diff --git a/libmpdemux/url.c b/libmpdemux/url.c
index f139252341..20c24c0e71 100644
--- a/libmpdemux/url.c
+++ b/libmpdemux/url.c
@@ -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 @@ url_new(char* url) {
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 @@ url_new(char* url) {
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 @@ url_new(char* url) {
}
}
}
- // 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 @@ url_free(URL_t* url) {
/* 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 @@ url_unescape_string(char *outbuf, char *inbuf)
/* 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 @@ url_escape_string(char *outbuf, char *inbuf) {
#ifdef __URL_DEBUG
void
-url_debug(URL_t *url) {
+url_debug(const URL_t *url) {
if( url==NULL ) {
printf("URL pointer NULL\n");
return;
diff --git a/libmpdemux/url.h b/libmpdemux/url.h
index 9e45e00dcc..e344e75c85 100644
--- a/libmpdemux/url.h
+++ b/libmpdemux/url.h
@@ -19,14 +19,14 @@ typedef struct {
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