Mercurial > mplayer.hg
annotate libmpdemux/url.c @ 10007:b2d257e35577
slices support for vf_crop. now cropping black borders should make a
dvd play faster rather than slower... :)
author | rfelker |
---|---|
date | Sun, 27 Apr 2003 21:04:00 +0000 |
parents | d66ed2c80ddf |
children | 88c855a174f3 |
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> | |
11 | |
12 #include "url.h" | |
5933 | 13 #include "mp_msg.h" |
833 | 14 |
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) { |
833 | 17 int pos1, pos2; |
18 URL_t* Curl; | |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
19 char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL; |
833 | 20 |
4653
d2a7fcfeec6f
Removed the url_copy function , since it was badly implemented,
bertrand
parents:
4119
diff
changeset
|
21 if( url==NULL ) return NULL; |
d2a7fcfeec6f
Removed the url_copy function , since it was badly implemented,
bertrand
parents:
4119
diff
changeset
|
22 |
833 | 23 // Create the URL container |
24 Curl = (URL_t*)malloc(sizeof(URL_t)); | |
25 if( Curl==NULL ) { | |
5933 | 26 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n"); |
1631 | 27 return NULL; |
833 | 28 } |
840 | 29 // Initialisation of the URL container members |
902 | 30 memset( Curl, 0, sizeof(URL_t) ); |
840 | 31 |
833 | 32 // Copy the url in the URL container |
3612 | 33 Curl->url = strdup(url); |
833 | 34 if( Curl->url==NULL ) { |
5933 | 35 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
|
36 url_free(Curl); |
1631 | 37 return NULL; |
833 | 38 } |
39 | |
40 // extract the protocol | |
41 ptr1 = strstr(url, "://"); | |
42 if( ptr1==NULL ) { | |
5933 | 43 mp_msg(MSGT_NETWORK,MSGL_V,"Not an URL!\n"); |
7809
72a156e6d482
Fixed more potential mem leaks and use the url_free method
bertrand
parents:
7761
diff
changeset
|
44 url_free(Curl); |
833 | 45 return NULL; |
46 } | |
47 pos1 = ptr1-url; | |
48 Curl->protocol = (char*)malloc(pos1+1); | |
49 strncpy(Curl->protocol, url, pos1); | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
50 if( Curl->protocol==NULL ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
51 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
|
52 url_free(Curl); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
53 return NULL; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
54 } |
833 | 55 Curl->protocol[pos1] = '\0'; |
56 | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
57 // jump the "://" |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
58 ptr1 += 3; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
59 pos1 += 3; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
60 |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
61 // check if a username:password is given |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
62 ptr2 = strstr(ptr1, "@"); |
7330
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
63 ptr3 = strstr(ptr1, "/"); |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
64 if( ptr3!=NULL && ptr3<ptr2 ) { |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
65 // 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
|
66 ptr2 = NULL; |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
67 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
68 if( ptr2!=NULL ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
69 // We got something, at least a username... |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
70 int len = ptr2-ptr1; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
71 Curl->username = (char*)malloc(len+1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
72 if( Curl->username==NULL ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
73 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
|
74 url_free(Curl); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
75 return NULL; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
76 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
77 strncpy(Curl->username, ptr1, len); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
78 Curl->username[len] = '\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
79 |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
80 ptr3 = strstr(ptr1, ":"); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
81 if( ptr3!=NULL && ptr3<ptr2 ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
82 // We also have a password |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
83 int len2 = ptr2-ptr3-1; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
84 Curl->username[ptr3-ptr1]='\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
85 Curl->password = (char*)malloc(len2+1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
86 if( Curl->password==NULL ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
87 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
|
88 url_free(Curl); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
89 return NULL; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
90 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
91 strncpy( Curl->password, ptr3+1, len2); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
92 Curl->password[len2]='\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
93 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
94 ptr1 = ptr2+1; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
95 pos1 = ptr1-url; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
96 } |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
97 |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
98 // 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
|
99 // 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
|
100 ptr2 = strstr(ptr1, "["); |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
101 ptr3 = strstr(ptr1, "]"); |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
102 if( ptr2!=NULL && ptr3!=NULL ) { |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
103 // 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
|
104 ptr1++; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
105 pos1++; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
106 ptr2 = ptr3; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
107 } else { |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
108 ptr2 = ptr1; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
109 |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
110 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
111 |
833 | 112 // 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
|
113 ptr2 = strstr(ptr2, ":"); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3040
diff
changeset
|
114 // 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
|
115 ptr3 = strstr(ptr1, "/"); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3040
diff
changeset
|
116 if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL; |
833 | 117 if( ptr2==NULL ) { |
118 // No port is given | |
119 // 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
|
120 if( ptr3==NULL ) { |
833 | 121 // No path/filename |
122 // So we have an URL like http://www.hostname.com | |
123 pos2 = strlen(url); | |
124 } else { | |
125 // 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
|
126 pos2 = ptr3-url; |
833 | 127 } |
128 } else { | |
129 // We have an URL beginning like http://www.hostname.com:1212 | |
130 // Get the port number | |
131 Curl->port = atoi(ptr2+1); | |
132 pos2 = ptr2-url; | |
133 } | |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
134 if( strstr(ptr1, "]")!=NULL ) pos2--; |
833 | 135 // copy the hostname in the URL container |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
136 Curl->hostname = (char*)malloc(pos2-pos1+1); |
833 | 137 if( Curl->hostname==NULL ) { |
5933 | 138 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
|
139 url_free(Curl); |
1631 | 140 return NULL; |
833 | 141 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
142 strncpy(Curl->hostname, ptr1, pos2-pos1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
143 Curl->hostname[pos2-pos1] = '\0'; |
833 | 144 |
145 // Look if a path is given | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
146 ptr2 = strstr(ptr1, "/"); |
833 | 147 if( ptr2!=NULL ) { |
148 // A path/filename is given | |
149 // check if it's not a trailing '/' | |
150 if( strlen(ptr2)>1 ) { | |
151 // copy the path/filename in the URL container | |
3612 | 152 Curl->file = strdup(ptr2); |
840 | 153 if( Curl->file==NULL ) { |
5933 | 154 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
|
155 url_free(Curl); |
1631 | 156 return NULL; |
833 | 157 } |
158 } | |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
159 } |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
160 // 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
|
161 if( Curl->file==NULL ) { |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
162 Curl->file = (char*)malloc(2); |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
163 if( Curl->file==NULL ) { |
5933 | 164 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
|
165 url_free(Curl); |
1631 | 166 return NULL; |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
167 } |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
168 strcpy(Curl->file, "/"); |
833 | 169 } |
170 | |
171 return Curl; | |
172 } | |
173 | |
174 void | |
902 | 175 url_free(URL_t* url) { |
1530
3effaac0ddb7
silly bug fixed - thanx Szekeres Istvan <szekeres@webvilag.com>
arpi
parents:
997
diff
changeset
|
176 if(!url) return; |
833 | 177 if(url->url) free(url->url); |
178 if(url->protocol) free(url->protocol); | |
179 if(url->hostname) free(url->hostname); | |
840 | 180 if(url->file) free(url->file); |
902 | 181 if(url->username) free(url->username); |
182 if(url->password) free(url->password); | |
833 | 183 free(url); |
184 } | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
185 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
186 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
187 /* 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
|
188 /* 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
|
189 /* 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
|
190 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
191 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
|
192 { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
193 unsigned char c; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
194 do { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
195 c = *inbuf++; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
196 if (c == '%') { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
197 unsigned char c1 = *inbuf++; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
198 unsigned char c2 = *inbuf++; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
199 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
|
200 ((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
|
201 if (c1>='0' && c1<='9') c1-='0'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
202 else c1-='A'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
203 if (c2>='0' && c2<='9') c2-='0'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
204 else c2-='A'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
205 c = (c1<<4) + c2; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
206 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
207 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
208 *outbuf++ = c; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
209 } while (c != '\0'); |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
210 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
211 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
212 /* 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
|
213 /* 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
|
214 /* 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
|
215 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
216 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
|
217 unsigned char c; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
218 do { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
219 c = *inbuf++; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
220 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
|
221 (c >= 'a' && c <= 'z') || |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
222 (c >= '0' && c <= '9') || |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
223 (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
|
224 c=='-' || c=='_' || c=='.' || c=='!' || c=='~' || /* mark characters */ |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
225 c=='*' || c=='\'' || c=='(' || c==')' || c=='%' || /* do not touch escape character */ |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
226 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
|
227 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
|
228 c=='\0' ) { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
229 *outbuf++ = c; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
230 } else { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
231 /* 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
|
232 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
|
233 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
|
234 if (c1 < 10) c1+='0'; |
9924 | 235 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
|
236 if (c2 < 10) c2+='0'; |
9924 | 237 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
|
238 *outbuf++ = '%'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
239 *outbuf++ = c1; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
240 *outbuf++ = c2; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
241 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
242 } while (c != '\0'); |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
243 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
244 |
4119
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
245 #ifdef __URL_DEBUG |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
246 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
247 url_debug(const URL_t *url) { |
4119
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
248 if( url==NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
249 printf("URL pointer NULL\n"); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
250 return; |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
251 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
252 if( url->url!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
253 printf("url=%s\n", url->url ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
254 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
255 if( url->protocol!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
256 printf("protocol=%s\n", url->protocol ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
257 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
258 if( url->hostname!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
259 printf("hostname=%s\n", url->hostname ); |
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 printf("port=%d\n", url->port ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
262 if( url->file!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
263 printf("file=%s\n", url->file ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
264 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
265 if( url->username!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
266 printf("username=%s\n", url->username ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
267 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
268 if( url->password!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
269 printf("password=%s\n", url->password ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
270 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
271 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
272 #endif //__URL_DEBUG |