Mercurial > mplayer.hg
annotate libmpdemux/url.c @ 16959:832a93fc5deb
Allow setting the mixer per instance so one can fallback between
several oos device and still have correct mixer settings all the
time.
The sytax is now: oss[:dsp_device[:mixer_device[:mixer_channel]]]
author | albeu |
---|---|
date | Thu, 10 Nov 2005 09:02:56 +0000 |
parents | bd4cac0d5e0e |
children | 9e02b9cb171b |
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 | 2 * URL Helper |
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com> | |
4 * (C) 2001, MPlayer team. | |
5 * | |
6 */ | |
7 | |
833 | 8 #include <string.h> |
9 #include <stdlib.h> | |
10 #include <stdio.h> | |
12391 | 11 #include <ctype.h> |
833 | 12 |
13 #include "url.h" | |
5933 | 14 #include "mp_msg.h" |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16421
diff
changeset
|
15 #include "help_mp.h" |
833 | 16 |
17 URL_t* | |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
18 url_new(const char* url) { |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
19 int pos1, pos2,v6addr = 0; |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
20 URL_t* Curl = NULL; |
12391 | 21 char *escfilename=NULL; |
22 char *unescfilename=NULL; | |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
23 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
|
24 int jumpSize = 3; |
833 | 25 |
4653
d2a7fcfeec6f
Removed the url_copy function , since it was badly implemented,
bertrand
parents:
4119
diff
changeset
|
26 if( url==NULL ) return NULL; |
d2a7fcfeec6f
Removed the url_copy function , since it was badly implemented,
bertrand
parents:
4119
diff
changeset
|
27 |
12391 | 28 // Create temp filename space |
29 unescfilename=malloc(strlen(url)+1); | |
30 if (!unescfilename ) { | |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
31 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
32 goto err_out; |
12391 | 33 } |
34 escfilename=malloc(strlen(url)*3+1); | |
35 if (!escfilename ) { | |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
36 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
37 goto err_out; |
12391 | 38 } |
39 | |
833 | 40 // Create the URL container |
41 Curl = (URL_t*)malloc(sizeof(URL_t)); | |
42 if( Curl==NULL ) { | |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
43 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
44 goto err_out; |
833 | 45 } |
12391 | 46 |
840 | 47 // Initialisation of the URL container members |
902 | 48 memset( Curl, 0, sizeof(URL_t) ); |
840 | 49 |
12391 | 50 //create unescaped/escaped versions of url |
51 url_unescape_string(unescfilename,url); // this is to prevent us from escaping an unescaped string | |
52 // violating RFC 2396 | |
53 url_escape_string(escfilename,unescfilename); | |
54 free(unescfilename); | |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
55 unescfilename = NULL; |
12391 | 56 |
833 | 57 // Copy the url in the URL container |
12391 | 58 Curl->url = strdup(escfilename); |
833 | 59 if( Curl->url==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
60 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
61 goto err_out; |
833 | 62 } |
12391 | 63 mp_msg(MSGT_OPEN,MSGL_V,"Filename for url is now %s\n",escfilename); |
833 | 64 |
65 // extract the protocol | |
12391 | 66 ptr1 = strstr(escfilename, "://"); |
833 | 67 if( ptr1==NULL ) { |
10056
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
68 // Check for a special case: "sip:" (without "//"): |
12391 | 69 if (strstr(escfilename, "sip:") == escfilename) { |
11412 | 70 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
|
71 jumpSize = 1; |
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
72 } else { |
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
73 mp_msg(MSGT_NETWORK,MSGL_V,"Not an URL!\n"); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
74 goto err_out; |
10056
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
75 } |
833 | 76 } |
12391 | 77 pos1 = ptr1-escfilename; |
833 | 78 Curl->protocol = (char*)malloc(pos1+1); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
79 if( Curl->protocol==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
80 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
81 goto err_out; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
82 } |
12637 | 83 strncpy(Curl->protocol, escfilename, pos1); |
833 | 84 Curl->protocol[pos1] = '\0'; |
85 | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
86 // jump the "://" |
10056
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
87 ptr1 += jumpSize; |
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
88 pos1 += jumpSize; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
89 |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
90 // check if a username:password is given |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
91 ptr2 = strstr(ptr1, "@"); |
7330
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
92 ptr3 = strstr(ptr1, "/"); |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
93 if( ptr3!=NULL && ptr3<ptr2 ) { |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
94 // 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
|
95 ptr2 = NULL; |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
96 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
97 if( ptr2!=NULL ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
98 // We got something, at least a username... |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
99 int len = ptr2-ptr1; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
100 Curl->username = (char*)malloc(len+1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
101 if( Curl->username==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
102 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
103 goto err_out; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
104 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
105 strncpy(Curl->username, ptr1, len); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
106 Curl->username[len] = '\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
107 |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
108 ptr3 = strstr(ptr1, ":"); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
109 if( ptr3!=NULL && ptr3<ptr2 ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
110 // We also have a password |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
111 int len2 = ptr2-ptr3-1; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
112 Curl->username[ptr3-ptr1]='\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
113 Curl->password = (char*)malloc(len2+1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
114 if( Curl->password==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
115 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
116 goto err_out; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
117 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
118 strncpy( Curl->password, ptr3+1, len2); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
119 Curl->password[len2]='\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
120 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
121 ptr1 = ptr2+1; |
12391 | 122 pos1 = ptr1-escfilename; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
123 } |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
124 |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
125 // 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
|
126 // 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
|
127 ptr2 = strstr(ptr1, "["); |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
128 ptr3 = strstr(ptr1, "]"); |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
129 ptr4 = strstr(ptr1, "/"); |
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
130 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
|
131 // 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
|
132 ptr1++; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
133 pos1++; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
134 ptr2 = ptr3; |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
135 v6addr = 1; |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
136 } else { |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
137 ptr2 = ptr1; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
138 |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
139 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
140 |
833 | 141 // 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
|
142 ptr2 = strstr(ptr2, ":"); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3040
diff
changeset
|
143 // 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
|
144 ptr3 = strstr(ptr1, "/"); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3040
diff
changeset
|
145 if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL; |
833 | 146 if( ptr2==NULL ) { |
147 // No port is given | |
148 // 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
|
149 if( ptr3==NULL ) { |
833 | 150 // No path/filename |
151 // So we have an URL like http://www.hostname.com | |
12391 | 152 pos2 = strlen(escfilename); |
833 | 153 } else { |
154 // We have an URL like http://www.hostname.com/file.txt | |
12391 | 155 pos2 = ptr3-escfilename; |
833 | 156 } |
157 } else { | |
158 // We have an URL beginning like http://www.hostname.com:1212 | |
159 // Get the port number | |
160 Curl->port = atoi(ptr2+1); | |
12391 | 161 pos2 = ptr2-escfilename; |
833 | 162 } |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
163 if( v6addr ) pos2--; |
833 | 164 // copy the hostname in the URL container |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
165 Curl->hostname = (char*)malloc(pos2-pos1+1); |
833 | 166 if( Curl->hostname==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
167 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
168 goto err_out; |
833 | 169 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
170 strncpy(Curl->hostname, ptr1, pos2-pos1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
171 Curl->hostname[pos2-pos1] = '\0'; |
833 | 172 |
173 // Look if a path is given | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
174 ptr2 = strstr(ptr1, "/"); |
833 | 175 if( ptr2!=NULL ) { |
176 // A path/filename is given | |
177 // check if it's not a trailing '/' | |
178 if( strlen(ptr2)>1 ) { | |
179 // copy the path/filename in the URL container | |
3612 | 180 Curl->file = strdup(ptr2); |
840 | 181 if( Curl->file==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
182 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
183 goto err_out; |
833 | 184 } |
185 } | |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
186 } |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
187 // 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
|
188 if( Curl->file==NULL ) { |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
189 Curl->file = (char*)malloc(2); |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
190 if( Curl->file==NULL ) { |
16908
bd4cac0d5e0e
Changed MSGTR_MPDEMUX_URL_MallocFailed to MSGTR_MemAllocFailed (msg defined two times in help_mp-en.h)
ptt
parents:
16882
diff
changeset
|
191 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
192 goto err_out; |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
193 } |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
194 strcpy(Curl->file, "/"); |
833 | 195 } |
196 | |
12391 | 197 free(escfilename); |
833 | 198 return Curl; |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
199 err_out: |
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
200 if (escfilename) free(escfilename); |
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
201 if (unescfilename) free(unescfilename); |
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
202 if (Curl) url_free(Curl); |
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
203 return NULL; |
833 | 204 } |
205 | |
206 void | |
902 | 207 url_free(URL_t* url) { |
1530
3effaac0ddb7
silly bug fixed - thanx Szekeres Istvan <szekeres@webvilag.com>
arpi
parents:
997
diff
changeset
|
208 if(!url) return; |
833 | 209 if(url->url) free(url->url); |
210 if(url->protocol) free(url->protocol); | |
211 if(url->hostname) free(url->hostname); | |
840 | 212 if(url->file) free(url->file); |
902 | 213 if(url->username) free(url->username); |
214 if(url->password) free(url->password); | |
833 | 215 free(url); |
216 } | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
217 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
218 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
219 /* 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
|
220 /* 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
|
221 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
222 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
|
223 { |
12391 | 224 unsigned char c,c1,c2; |
225 int i,len=strlen(inbuf); | |
226 for (i=0;i<len;i++){ | |
227 c = inbuf[i]; | |
228 if (c == '%' && i<len-2) { //must have 2 more chars | |
229 c1 = toupper(inbuf[i+1]); // we need uppercase characters | |
230 c2 = toupper(inbuf[i+2]); | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
231 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
|
232 ((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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 c = (c1<<4) + c2; |
12391 | 238 i=i+2; //only skip next 2 chars if valid esc |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
239 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
240 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
241 *outbuf++ = c; |
12391 | 242 } |
243 *outbuf++='\0'; //add nullterm to string | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
244 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
245 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
246 /* 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
|
247 /* 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
|
248 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
249 url_escape_string(char *outbuf, const char *inbuf) { |
12391 | 250 unsigned char c,c1,c2; |
251 int i,len=strlen(inbuf); | |
252 | |
253 for (i=0;i<len;i++) { | |
254 c = inbuf[i]; | |
255 if ((c=='%') && i<len-2 ) { //need 2 more characters | |
256 c1=toupper(inbuf[i+1]); c2=toupper(inbuf[i+2]); // need uppercase chars | |
257 } else { | |
258 c1=129; c2=129; //not escape chars | |
259 } | |
260 | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
261 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
|
262 (c >= 'a' && c <= 'z') || |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
263 (c >= '0' && c <= '9') || |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
264 (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
|
265 c=='-' || c=='_' || c=='.' || c=='!' || c=='~' || /* mark characters */ |
12153 | 266 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
|
267 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
|
268 c=='&' || c=='=' || c=='+' || c=='$' || c==',' || /* see RFC 2396 */ |
12391 | 269 c=='\0' ) { /* string term char */ |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
270 *outbuf++ = c; |
12391 | 271 } else if ( c=='%' && ((c1 >= '0' && c1 <= '9') || (c1 >= 'A' && c1 <= 'F')) && |
272 ((c2 >= '0' && c2 <= '9') || (c2 >= 'A' && c2 <= 'F'))) { | |
273 // check if part of an escape sequence | |
274 *outbuf++=c; // already | |
275 | |
276 // dont escape again | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16421
diff
changeset
|
277 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_URL_StringAlreadyEscaped,c,c1,c2); |
12391 | 278 // error as this should not happen against RFC 2396 |
279 // to escape a string twice | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
280 } else { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
281 /* all others will be escaped */ |
12391 | 282 c1 = ((c & 0xf0) >> 4); |
283 c2 = (c & 0x0f); | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
284 if (c1 < 10) c1+='0'; |
9924 | 285 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
|
286 if (c2 < 10) c2+='0'; |
9924 | 287 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
|
288 *outbuf++ = '%'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
289 *outbuf++ = c1; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
290 *outbuf++ = c2; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
291 } |
12391 | 292 } |
293 *outbuf++='\0'; | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
294 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
295 |
4119
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
296 #ifdef __URL_DEBUG |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
297 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
298 url_debug(const URL_t *url) { |
4119
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
299 if( url==NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
300 printf("URL pointer NULL\n"); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
301 return; |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
302 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
303 if( url->url!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
304 printf("url=%s\n", url->url ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
305 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
306 if( url->protocol!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
307 printf("protocol=%s\n", url->protocol ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
308 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
309 if( url->hostname!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
310 printf("hostname=%s\n", url->hostname ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
311 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
312 printf("port=%d\n", url->port ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
313 if( url->file!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
314 printf("file=%s\n", url->file ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
315 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
316 if( url->username!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
317 printf("username=%s\n", url->username ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
318 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
319 if( url->password!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
320 printf("password=%s\n", url->password ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
321 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
322 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
323 #endif //__URL_DEBUG |