summaryrefslogtreecommitdiffstats
path: root/libmpdemux
diff options
context:
space:
mode:
authorbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-06-23 06:27:19 +0000
committerbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-06-23 06:27:19 +0000
commitd5ae6731503a272b0b8b89c774529d7e2f66582e (patch)
tree61f36789e25017c1e85f30ff3b8d3f106a960bc0 /libmpdemux
parent98571211e8a5fcdbf1f4f40eb3cbad12fffc89ad (diff)
downloadmpv-d5ae6731503a272b0b8b89c774529d7e2f66582e.tar.bz2
mpv-d5ae6731503a272b0b8b89c774529d7e2f66582e.tar.xz
Added support for URLs that contain an username:password
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6514 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/url.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/libmpdemux/url.c b/libmpdemux/url.c
index a8190f1fb9..b885de0657 100644
--- a/libmpdemux/url.c
+++ b/libmpdemux/url.c
@@ -3,8 +3,6 @@
* by Bertrand Baudet <bertrand_baudet@yahoo.com>
* (C) 2001, MPlayer team.
*
- * TODO:
- * Extract the username/password if present
*/
#include <string.h>
@@ -47,17 +45,55 @@ url_new(char* url) {
pos1 = ptr1-url;
Curl->protocol = (char*)malloc(pos1+1);
strncpy(Curl->protocol, url, pos1);
+ if( Curl->protocol==NULL ) {
+ mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
+ return NULL;
+ }
Curl->protocol[pos1] = '\0';
+ // jump the "://"
+ ptr1 += 3;
+ pos1 += 3;
+
+ // check if a username:password is given
+ ptr2 = strstr(ptr1, "@");
+ if( ptr2!=NULL ) {
+ // We got something, at least a username...
+ int len = ptr2-ptr1;
+ Curl->username = (char*)malloc(len+1);
+ if( Curl->username==NULL ) {
+ mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
+ return NULL;
+ }
+ strncpy(Curl->username, ptr1, len);
+ Curl->username[len] = '\0';
+
+ ptr3 = strstr(ptr1, ":");
+ if( ptr3!=NULL && ptr3<ptr2 ) {
+ // We also have a password
+ int len2 = ptr2-ptr3-1;
+ Curl->username[ptr3-ptr1]='\0';
+ Curl->password = (char*)malloc(len2+1);
+ if( Curl->password==NULL ) {
+ mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
+ return NULL;
+ }
+ strncpy( Curl->password, ptr3+1, len2);
+ Curl->password[len2]='\0';
+ }
+ ptr1 = ptr2+1;
+ pos1 = ptr1-url;
+ }
+
// look if the port is given
- ptr2 = strstr(ptr1+3, ":");
+ ptr2 = strstr(ptr1, ":");
// If the : is after the first / it isn't the port
- ptr3 = strstr(ptr1+3, "/");
+ 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+3, "/");
+ ptr2 = strstr(ptr1, "/");
if( ptr2==NULL ) {
// No path/filename
// So we have an URL like http://www.hostname.com
@@ -73,16 +109,16 @@ url_new(char* url) {
pos2 = ptr2-url;
}
// copy the hostname in the URL container
- Curl->hostname = (char*)malloc(pos2-pos1-3+1);
+ Curl->hostname = (char*)malloc(pos2-pos1+1);
if( Curl->hostname==NULL ) {
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
return NULL;
}
- strncpy(Curl->hostname, ptr1+3, pos2-pos1-3);
- Curl->hostname[pos2-pos1-3] = '\0';
+ strncpy(Curl->hostname, ptr1, pos2-pos1);
+ Curl->hostname[pos2-pos1] = '\0';
// Look if a path is given
- ptr2 = strstr(ptr1+3, "/");
+ ptr2 = strstr(ptr1, "/");
if( ptr2!=NULL ) {
// A path/filename is given
// check if it's not a trailing '/'