mirror of
https://github.com/mpv-player/mpv
synced 2025-03-19 18:05:21 +00:00
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
This commit is contained in:
parent
abca28586a
commit
dc49bda4bb
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user