annotate libmpdemux/url.c @ 12337:6f1b4c989914

soft skipping for mencoder. rather than skipping decoding/filtering frames that will be skipped, mencoded tells vf_softskip (if present) that it should drop the next frame. this allows filters that need to see every input frame (inverse telecine, denoise3d, ...) to see skipped frames before they get dropped. in principle, a smarter softskip filter could be written that would buffer frames and choose to drop the one with least change, rather than strictly dropping the next one.
author rfelker
date Wed, 28 Apr 2004 04:29:17 +0000
parents b9f5f700bb1b
children 2677bfac3838
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
1 /*
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
2 * URL Helper
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
4 * (C) 2001, MPlayer team.
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
5 *
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
6 */
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
7
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
8 #include <string.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
9 #include <stdlib.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
10 #include <stdio.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
11
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
12 #include "url.h"
5933
14b46420840b printf to mp_msg
albeu
parents: 4653
diff changeset
13 #include "mp_msg.h"
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
14
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
15 URL_t*
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
16 url_new(const char* url) {
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
17 int pos1, pos2,v6addr = 0;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
18 URL_t* Curl;
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
19 char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL, *ptr4=NULL;
10056
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
20 int jumpSize = 3;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
21
4653
d2a7fcfeec6f Removed the url_copy function , since it was badly implemented,
bertrand
parents: 4119
diff changeset
22 if( url==NULL ) return NULL;
d2a7fcfeec6f Removed the url_copy function , since it was badly implemented,
bertrand
parents: 4119
diff changeset
23
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
24 // Create the URL container
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
25 Curl = (URL_t*)malloc(sizeof(URL_t));
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
26 if( Curl==NULL ) {
5933
14b46420840b printf to mp_msg
albeu
parents: 4653
diff changeset
27 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
28 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
29 }
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
30 // Initialisation of the URL container members
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
31 memset( Curl, 0, sizeof(URL_t) );
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
32
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
33 // Copy the url in the URL container
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3496
diff changeset
34 Curl->url = strdup(url);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
35 if( Curl->url==NULL ) {
5933
14b46420840b printf to mp_msg
albeu
parents: 4653
diff changeset
36 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
37 url_free(Curl);
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
38 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
39 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
40
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
41 // extract the protocol
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
42 ptr1 = strstr(url, "://");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
43 if( ptr1==NULL ) {
10056
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
44 // Check for a special case: "sip:" (without "//"):
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
45 if (strstr(url, "sip:") == url) {
11412
ec3dac7d17a0 Warning fixes (approved by A'rpi).
rathann
parents: 10056
diff changeset
46 ptr1 = (char *)&url[3]; // points to ':'
10056
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
47 jumpSize = 1;
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
48 } else {
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
49 mp_msg(MSGT_NETWORK,MSGL_V,"Not an URL!\n");
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
50 url_free(Curl);
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
51 return NULL;
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
52 }
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
53 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
54 pos1 = ptr1-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
55 Curl->protocol = (char*)malloc(pos1+1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
56 strncpy(Curl->protocol, url, pos1);
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
57 if( Curl->protocol==NULL ) {
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
58 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
59 url_free(Curl);
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
60 return NULL;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
61 }
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
62 Curl->protocol[pos1] = '\0';
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
63
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
64 // jump the "://"
10056
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
65 ptr1 += jumpSize;
88c855a174f3 Added some special-case code for checking for "sip:" URLs (because they
rsf
parents: 9924
diff changeset
66 pos1 += jumpSize;
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
67
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
68 // check if a username:password is given
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
69 ptr2 = strstr(ptr1, "@");
7330
2f3fe8274028 Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents: 6513
diff changeset
70 ptr3 = strstr(ptr1, "/");
2f3fe8274028 Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents: 6513
diff changeset
71 if( ptr3!=NULL && ptr3<ptr2 ) {
2f3fe8274028 Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents: 6513
diff changeset
72 // it isn't really a username but rather a part of the path
2f3fe8274028 Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents: 6513
diff changeset
73 ptr2 = NULL;
2f3fe8274028 Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents: 6513
diff changeset
74 }
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
75 if( ptr2!=NULL ) {
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
76 // We got something, at least a username...
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
77 int len = ptr2-ptr1;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
78 Curl->username = (char*)malloc(len+1);
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
79 if( Curl->username==NULL ) {
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
80 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
81 url_free(Curl);
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
82 return NULL;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
83 }
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
84 strncpy(Curl->username, ptr1, len);
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
85 Curl->username[len] = '\0';
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
86
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
87 ptr3 = strstr(ptr1, ":");
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
88 if( ptr3!=NULL && ptr3<ptr2 ) {
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
89 // We also have a password
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
90 int len2 = ptr2-ptr3-1;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
91 Curl->username[ptr3-ptr1]='\0';
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
92 Curl->password = (char*)malloc(len2+1);
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
93 if( Curl->password==NULL ) {
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
94 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
95 url_free(Curl);
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
96 return NULL;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
97 }
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
98 strncpy( Curl->password, ptr3+1, len2);
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
99 Curl->password[len2]='\0';
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
100 }
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
101 ptr1 = ptr2+1;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
102 pos1 = ptr1-url;
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
103 }
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
104
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
105 // before looking for a port number check if we have an IPv6 type numeric address
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
106 // in IPv6 URL the numeric address should be inside square braces.
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
107 ptr2 = strstr(ptr1, "[");
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
108 ptr3 = strstr(ptr1, "]");
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
109 ptr4 = strstr(ptr1, "/");
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
110 if( ptr2!=NULL && ptr3!=NULL && ptr2 < ptr3 && (!ptr4 || ptr4 > ptr3)) {
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
111 // we have an IPv6 numeric address
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
112 ptr1++;
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
113 pos1++;
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
114 ptr2 = ptr3;
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
115 v6addr = 1;
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
116 } else {
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
117 ptr2 = ptr1;
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
118
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
119 }
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
120
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
121 // look if the port is given
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
122 ptr2 = strstr(ptr2, ":");
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3040
diff changeset
123 // If the : is after the first / it isn't the port
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
124 ptr3 = strstr(ptr1, "/");
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3040
diff changeset
125 if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
126 if( ptr2==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
127 // No port is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
128 // Look if a path is given
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
129 if( ptr3==NULL ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
130 // No path/filename
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
131 // So we have an URL like http://www.hostname.com
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
132 pos2 = strlen(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
133 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
134 // We have an URL like http://www.hostname.com/file.txt
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
135 pos2 = ptr3-url;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
136 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
137 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
138 // We have an URL beginning like http://www.hostname.com:1212
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
139 // Get the port number
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
140 Curl->port = atoi(ptr2+1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
141 pos2 = ptr2-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
142 }
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
143 if( v6addr ) pos2--;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
144 // copy the hostname in the URL container
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
145 Curl->hostname = (char*)malloc(pos2-pos1+1);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
146 if( Curl->hostname==NULL ) {
5933
14b46420840b printf to mp_msg
albeu
parents: 4653
diff changeset
147 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
148 url_free(Curl);
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
149 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
150 }
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
151 strncpy(Curl->hostname, ptr1, pos2-pos1);
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
152 Curl->hostname[pos2-pos1] = '\0';
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
153
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
154 // Look if a path is given
6513
6e9d7a6b1806 Added support for URLs that contain an username:password
bertrand
parents: 5933
diff changeset
155 ptr2 = strstr(ptr1, "/");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
156 if( ptr2!=NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
157 // A path/filename is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
158 // check if it's not a trailing '/'
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
159 if( strlen(ptr2)>1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
160 // copy the path/filename in the URL container
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3496
diff changeset
161 Curl->file = strdup(ptr2);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
162 if( Curl->file==NULL ) {
5933
14b46420840b printf to mp_msg
albeu
parents: 4653
diff changeset
163 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
164 url_free(Curl);
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
165 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
166 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
167 }
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
168 }
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
169 // Check if a filename was given or set, else set it with '/'
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
170 if( Curl->file==NULL ) {
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
171 Curl->file = (char*)malloc(2);
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
172 if( Curl->file==NULL ) {
5933
14b46420840b printf to mp_msg
albeu
parents: 4653
diff changeset
173 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
7809
72a156e6d482 Fixed more potential mem leaks and use the url_free method
bertrand
parents: 7761
diff changeset
174 url_free(Curl);
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
175 return NULL;
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
176 }
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
177 strcpy(Curl->file, "/");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
178 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
179
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
180 return Curl;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
181 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
182
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
183 void
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
184 url_free(URL_t* url) {
1530
3effaac0ddb7 silly bug fixed - thanx Szekeres Istvan <szekeres@webvilag.com>
arpi
parents: 997
diff changeset
185 if(!url) return;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
186 if(url->url) free(url->url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
187 if(url->protocol) free(url->protocol);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
188 if(url->hostname) free(url->hostname);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
189 if(url->file) free(url->file);
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
190 if(url->username) free(url->username);
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
191 if(url->password) free(url->password);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
192 free(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
193 }
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
194
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
195
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
196 /* Replace escape sequences in an URL (or a part of an URL) */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
197 /* works like strcpy(), but without return argument */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
198 /* unescape_url_string comes from ASFRecorder */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
199 void
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
200 url_unescape_string(char *outbuf, const char *inbuf)
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
201 {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
202 unsigned char c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
203 do {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
204 c = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
205 if (c == '%') {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
206 unsigned char c1 = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
207 unsigned char c2 = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
208 if ( ((c1>='0' && c1<='9') || (c1>='A' && c1<='F')) &&
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
209 ((c2>='0' && c2<='9') || (c2>='A' && c2<='F')) ) {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
210 if (c1>='0' && c1<='9') c1-='0';
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
211 else c1-='A'-10;
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
212 if (c2>='0' && c2<='9') c2-='0';
11771
827cae571c5c Fix long standing bug where last (and sometimes first) char of the
albeu
parents: 11412
diff changeset
213 else c2-='A'-10;
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
214 c = (c1<<4) + c2;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
215 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
216 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
217 *outbuf++ = c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
218 } while (c != '\0');
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
219 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
220
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
221 /* Replace specific characters in the URL string by an escape sequence */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
222 /* works like strcpy(), but without return argument */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
223 /* escape_url_string comes from ASFRecorder */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
224 void
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
225 url_escape_string(char *outbuf, const char *inbuf) {
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
226 unsigned char c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
227 do {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
228 c = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
229 if( (c >= 'A' && c <= 'Z') ||
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
230 (c >= 'a' && c <= 'z') ||
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
231 (c >= '0' && c <= '9') ||
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
232 (c >= 0x7f) || /* fareast languages(Chinese, Korean, Japanese) */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
233 c=='-' || c=='_' || c=='.' || c=='!' || c=='~' || /* mark characters */
12153
b9f5f700bb1b '%' is unsafe and need to be escaped.
bertrand
parents: 11771
diff changeset
234 c=='*' || c=='\'' || c=='(' || c==')' || /* do not touch escape character */
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
235 c==';' || c=='/' || c=='?' || c==':' || c=='@' || /* reserved characters */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
236 c=='&' || c=='=' || c=='+' || c=='$' || c==',' || /* see RFC 2396 */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
237 c=='\0' ) {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
238 *outbuf++ = c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
239 } else {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
240 /* all others will be escaped */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
241 unsigned char c1 = ((c & 0xf0) >> 4);
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
242 unsigned char c2 = (c & 0x0f);
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
243 if (c1 < 10) c1+='0';
9924
d66ed2c80ddf Fix incorrect URL encoding.
ranma
parents: 9690
diff changeset
244 else c1+='A'-10;
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
245 if (c2 < 10) c2+='0';
9924
d66ed2c80ddf Fix incorrect URL encoding.
ranma
parents: 9690
diff changeset
246 else c2+='A'-10;
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
247 *outbuf++ = '%';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
248 *outbuf++ = c1;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
249 *outbuf++ = c2;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
250 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
251 } while (c != '\0');
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
252 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
253
4119
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
254 #ifdef __URL_DEBUG
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
255 void
9690
a9b7b6055563 Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents: 7809
diff changeset
256 url_debug(const URL_t *url) {
4119
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
257 if( url==NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
258 printf("URL pointer NULL\n");
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
259 return;
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
260 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
261 if( url->url!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
262 printf("url=%s\n", url->url );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
263 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
264 if( url->protocol!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
265 printf("protocol=%s\n", url->protocol );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
266 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
267 if( url->hostname!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
268 printf("hostname=%s\n", url->hostname );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
269 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
270 printf("port=%d\n", url->port );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
271 if( url->file!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
272 printf("file=%s\n", url->file );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
273 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
274 if( url->username!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
275 printf("username=%s\n", url->username );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
276 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
277 if( url->password!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
278 printf("password=%s\n", url->password );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
279 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
280 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
281 #endif //__URL_DEBUG