Mercurial > mplayer.hg
annotate stream/url.c @ 35788:e3dcd5854344
Move video window initialization code to uiVideoInit().
author | ib |
---|---|
date | Fri, 25 Jan 2013 15:12:25 +0000 |
parents | dac86d3464e2 |
children | 389d43c448b3 |
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 |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
4 * Copyright (C) 2001 Bertrand Baudet <bertrand_baudet@yahoo.com> |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
5 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
6 * This file is part of MPlayer. |
902 | 7 * |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
11 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
12 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
16 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
17 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
902 | 21 */ |
22 | |
833 | 23 #include <string.h> |
24 #include <stdlib.h> | |
25 #include <stdio.h> | |
12391 | 26 #include <ctype.h> |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17048
diff
changeset
|
27 #include <inttypes.h> |
833 | 28 |
29 #include "url.h" | |
5933 | 30 #include "mp_msg.h" |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
31 #include "mp_strings.h" |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16421
diff
changeset
|
32 #include "help_mp.h" |
833 | 33 |
18671 | 34 #ifndef SIZE_MAX |
35 #define SIZE_MAX ((size_t)-1) | |
36 #endif | |
37 | |
35113 | 38 static int is_proxy(const URL_t *url) { |
39 return !strcasecmp(url->protocol, "http_proxy") && url->file && strstr(url->file, "://"); | |
40 } | |
41 | |
42 int url_is_protocol(const URL_t *url, const char *proto) { | |
43 int proxy = is_proxy(url); | |
44 if (proxy) { | |
45 URL_t *tmp = url_new(url->file + 1); | |
46 int res = !strcasecmp(tmp->protocol, proto); | |
47 url_free(tmp); | |
48 return res; | |
49 } | |
50 return !strcasecmp(url->protocol, proto); | |
51 } | |
52 | |
53 void url_set_protocol(URL_t *url, const char *proto) { | |
54 int proxy = is_proxy(url); | |
55 if (proxy) { | |
56 char *dst = url->file + 1; | |
57 int oldlen = strstr(dst, "://") - dst; | |
58 int newlen = strlen(proto); | |
59 if (newlen != oldlen) { | |
60 mp_msg(MSGT_NETWORK, MSGL_ERR, "Setting protocol not implemented!\n"); | |
61 return; | |
62 } | |
63 memcpy(dst, proto, newlen); | |
64 return; | |
65 } | |
66 free(url->protocol); | |
67 url->protocol = strdup(proto); | |
68 } | |
69 | |
20784
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
70 URL_t *url_redirect(URL_t **url, const char *redir) { |
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
71 URL_t *u = *url; |
35113 | 72 int proxy = is_proxy(u); |
73 const char *oldurl = proxy ? u->file + 1 : u->url; | |
74 const char *newurl = redir; | |
75 char *buffer = NULL; | |
20784
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
76 URL_t *res; |
21125
4aff19cc00bb
Also support absolute url redirection, e.g. http://www.youtube.com/v/buKaqRG2SFA
reimar
parents:
20784
diff
changeset
|
77 if (!strchr(redir, '/') || *redir == '/') { |
20784
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
78 char *tmp; |
35113 | 79 newurl = buffer = malloc(strlen(oldurl) + strlen(redir) + 1); |
80 strcpy(buffer, oldurl); | |
21125
4aff19cc00bb
Also support absolute url redirection, e.g. http://www.youtube.com/v/buKaqRG2SFA
reimar
parents:
20784
diff
changeset
|
81 if (*redir == '/') { |
4aff19cc00bb
Also support absolute url redirection, e.g. http://www.youtube.com/v/buKaqRG2SFA
reimar
parents:
20784
diff
changeset
|
82 redir++; |
35113 | 83 tmp = strstr(buffer, "://"); |
21125
4aff19cc00bb
Also support absolute url redirection, e.g. http://www.youtube.com/v/buKaqRG2SFA
reimar
parents:
20784
diff
changeset
|
84 if (tmp) tmp = strchr(tmp + 3, '/'); |
4aff19cc00bb
Also support absolute url redirection, e.g. http://www.youtube.com/v/buKaqRG2SFA
reimar
parents:
20784
diff
changeset
|
85 } else |
35113 | 86 tmp = strrchr(buffer, '/'); |
20784
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
87 if (tmp) tmp[1] = 0; |
35113 | 88 strcat(buffer, redir); |
89 } | |
90 if (proxy) { | |
91 char *tmp = get_http_proxy_url(u, newurl); | |
92 free(buffer); | |
93 newurl = buffer = tmp; | |
94 } | |
95 res = url_new(newurl); | |
96 free(buffer); | |
20784
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
97 url_free(u); |
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
98 *url = res; |
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
99 return res; |
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
100 } |
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
19271
diff
changeset
|
101 |
32885
34fb7af52b82
Make proxy and url parameter const in get_noauth_url and get_http_proxy_url.
cboesch
parents:
32884
diff
changeset
|
102 static char *get_noauth_url(const URL_t *url) |
32553
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
103 { |
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
104 if (url->port) |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
105 return mp_asprintf("%s://%s:%d%s", |
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
106 url->protocol, url->hostname, url->port, url->file); |
32553
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
107 else |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
108 return mp_asprintf("%s://%s%s", |
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
109 url->protocol, url->hostname, url->file); |
32553
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
110 } |
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
111 |
32885
34fb7af52b82
Make proxy and url parameter const in get_noauth_url and get_http_proxy_url.
cboesch
parents:
32884
diff
changeset
|
112 char *get_http_proxy_url(const URL_t *proxy, const char *host_url) |
32586
31a65f4ca3bb
Add support for login/password in http_proxy env variable.
cboesch
parents:
32553
diff
changeset
|
113 { |
31a65f4ca3bb
Add support for login/password in http_proxy env variable.
cboesch
parents:
32553
diff
changeset
|
114 if (proxy->username) |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
115 return mp_asprintf("http_proxy://%s:%s@%s:%d/%s", |
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
116 proxy->username, |
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
117 proxy->password ? proxy->password : "", |
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
118 proxy->hostname, proxy->port, host_url); |
32586
31a65f4ca3bb
Add support for login/password in http_proxy env variable.
cboesch
parents:
32553
diff
changeset
|
119 else |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
120 return mp_asprintf("http_proxy://%s:%d/%s", |
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
121 proxy->hostname, proxy->port, host_url); |
32586
31a65f4ca3bb
Add support for login/password in http_proxy env variable.
cboesch
parents:
32553
diff
changeset
|
122 } |
31a65f4ca3bb
Add support for login/password in http_proxy env variable.
cboesch
parents:
32553
diff
changeset
|
123 |
833 | 124 URL_t* |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
125 url_new(const char* url) { |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
126 int pos1, pos2,v6addr = 0; |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
127 URL_t* Curl = NULL; |
12391 | 128 char *escfilename=NULL; |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
129 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
|
130 int jumpSize = 3; |
833 | 131 |
4653
d2a7fcfeec6f
Removed the url_copy function , since it was badly implemented,
bertrand
parents:
4119
diff
changeset
|
132 if( url==NULL ) return NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
133 |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17048
diff
changeset
|
134 if (strlen(url) > (SIZE_MAX / 3 - 1)) { |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17048
diff
changeset
|
135 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17048
diff
changeset
|
136 goto err_out; |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17048
diff
changeset
|
137 } |
12391 | 138 escfilename=malloc(strlen(url)*3+1); |
139 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
|
140 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
|
141 goto err_out; |
12391 | 142 } |
143 | |
833 | 144 // Create the URL container |
32636 | 145 Curl = calloc(1, sizeof(*Curl)); |
833 | 146 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
|
147 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
|
148 goto err_out; |
833 | 149 } |
12391 | 150 |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
151 url_escape_string(escfilename,url); |
12391 | 152 |
833 | 153 // Copy the url in the URL container |
12391 | 154 Curl->url = strdup(escfilename); |
833 | 155 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
|
156 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
|
157 goto err_out; |
833 | 158 } |
12391 | 159 mp_msg(MSGT_OPEN,MSGL_V,"Filename for url is now %s\n",escfilename); |
833 | 160 |
161 // extract the protocol | |
12391 | 162 ptr1 = strstr(escfilename, "://"); |
833 | 163 if( ptr1==NULL ) { |
10056
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
164 // Check for a special case: "sip:" (without "//"): |
12391 | 165 if (strstr(escfilename, "sip:") == escfilename) { |
11412 | 166 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
|
167 jumpSize = 1; |
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
168 } else { |
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
169 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
|
170 goto err_out; |
10056
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
171 } |
833 | 172 } |
12391 | 173 pos1 = ptr1-escfilename; |
18879 | 174 Curl->protocol = malloc(pos1+1); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
175 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
|
176 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
|
177 goto err_out; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
178 } |
12637 | 179 strncpy(Curl->protocol, escfilename, pos1); |
833 | 180 Curl->protocol[pos1] = '\0'; |
181 | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
182 // jump the "://" |
10056
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
183 ptr1 += jumpSize; |
88c855a174f3
Added some special-case code for checking for "sip:" URLs (because they
rsf
parents:
9924
diff
changeset
|
184 pos1 += jumpSize; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
185 |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
186 // check if a username:password is given |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
187 ptr2 = strstr(ptr1, "@"); |
7330
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
188 ptr3 = strstr(ptr1, "/"); |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
189 if( ptr3!=NULL && ptr3<ptr2 ) { |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
190 // 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
|
191 ptr2 = NULL; |
2f3fe8274028
Applied patch from Gregory Kovriga <gkovriga@techunix.technion.ac.il>
bertrand
parents:
6513
diff
changeset
|
192 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
193 if( ptr2!=NULL ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
194 // We got something, at least a username... |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
195 int len = ptr2-ptr1; |
18879 | 196 Curl->username = malloc(len+1); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
197 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
|
198 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
|
199 goto err_out; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
200 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
201 strncpy(Curl->username, ptr1, len); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
202 Curl->username[len] = '\0'; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
203 |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
204 ptr3 = strstr(ptr1, ":"); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
205 if( ptr3!=NULL && ptr3<ptr2 ) { |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
206 // We also have a password |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
207 int len2 = ptr2-ptr3-1; |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
208 Curl->username[ptr3-ptr1]='\0'; |
18879 | 209 Curl->password = malloc(len2+1); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
210 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
|
211 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
|
212 goto err_out; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
213 } |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
214 strncpy( Curl->password, ptr3+1, len2); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
215 Curl->password[len2]='\0'; |
32534 | 216 url_unescape_string(Curl->password, Curl->password); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
217 } |
32534 | 218 url_unescape_string(Curl->username, Curl->username); |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
219 ptr1 = ptr2+1; |
12391 | 220 pos1 = ptr1-escfilename; |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
221 } |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
222 |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
223 // 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
|
224 // 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
|
225 ptr2 = strstr(ptr1, "["); |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
226 ptr3 = strstr(ptr1, "]"); |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
227 ptr4 = strstr(ptr1, "/"); |
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
228 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
|
229 // 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
|
230 ptr1++; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
231 pos1++; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
232 ptr2 = ptr3; |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
233 v6addr = 1; |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
234 } else { |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
235 ptr2 = ptr1; |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
236 |
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
237 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
238 |
833 | 239 // 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
|
240 ptr2 = strstr(ptr2, ":"); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3040
diff
changeset
|
241 // 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
|
242 ptr3 = strstr(ptr1, "/"); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3040
diff
changeset
|
243 if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL; |
833 | 244 if( ptr2==NULL ) { |
245 // No port is given | |
246 // 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
|
247 if( ptr3==NULL ) { |
833 | 248 // No path/filename |
249 // So we have an URL like http://www.hostname.com | |
12391 | 250 pos2 = strlen(escfilename); |
833 | 251 } else { |
252 // We have an URL like http://www.hostname.com/file.txt | |
12391 | 253 pos2 = ptr3-escfilename; |
833 | 254 } |
255 } else { | |
256 // We have an URL beginning like http://www.hostname.com:1212 | |
257 // Get the port number | |
258 Curl->port = atoi(ptr2+1); | |
12391 | 259 pos2 = ptr2-escfilename; |
833 | 260 } |
11771
827cae571c5c
Fix long standing bug where last (and sometimes first) char of the
albeu
parents:
11412
diff
changeset
|
261 if( v6addr ) pos2--; |
833 | 262 // copy the hostname in the URL container |
18879 | 263 Curl->hostname = malloc(pos2-pos1+1); |
833 | 264 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
|
265 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
|
266 goto err_out; |
833 | 267 } |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
268 strncpy(Curl->hostname, ptr1, pos2-pos1); |
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
269 Curl->hostname[pos2-pos1] = '\0'; |
833 | 270 |
271 // Look if a path is given | |
6513
6e9d7a6b1806
Added support for URLs that contain an username:password
bertrand
parents:
5933
diff
changeset
|
272 ptr2 = strstr(ptr1, "/"); |
833 | 273 if( ptr2!=NULL ) { |
274 // A path/filename is given | |
275 // check if it's not a trailing '/' | |
276 if( strlen(ptr2)>1 ) { | |
277 // copy the path/filename in the URL container | |
3612 | 278 Curl->file = strdup(ptr2); |
840 | 279 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
|
280 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
|
281 goto err_out; |
833 | 282 } |
283 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
284 } |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
285 // 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
|
286 if( Curl->file==NULL ) { |
18879 | 287 Curl->file = malloc(2); |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
288 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
|
289 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
|
290 goto err_out; |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
291 } |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
292 strcpy(Curl->file, "/"); |
833 | 293 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
294 |
32884
0d95f044c589
Use mp_asprintf in make_noauth_url and make_http_proxy_url.
cboesch
parents:
32746
diff
changeset
|
295 Curl->noauth_url = get_noauth_url(Curl); |
32553
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
296 if (!Curl->noauth_url) { |
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
297 mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MemAllocFailed); |
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
298 goto err_out; |
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
299 } |
c44141d4e443
Do not keep authentication in URL on connection through a proxy
cboesch
parents:
32534
diff
changeset
|
300 |
12391 | 301 free(escfilename); |
833 | 302 return Curl; |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
303 err_out: |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
304 free(escfilename); |
16421
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
305 if (Curl) url_free(Curl); |
c41e22d77214
memleak fix, escfilename was not freed for an invalid url
reimar
parents:
12637
diff
changeset
|
306 return NULL; |
833 | 307 } |
308 | |
309 void | |
902 | 310 url_free(URL_t* url) { |
1530
3effaac0ddb7
silly bug fixed - thanx Szekeres Istvan <szekeres@webvilag.com>
arpi
parents:
997
diff
changeset
|
311 if(!url) return; |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
312 free(url->url); |
35369 | 313 free(url->noauth_url); |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
314 free(url->protocol); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
315 free(url->hostname); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
316 free(url->file); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
317 free(url->username); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
318 free(url->password); |
833 | 319 free(url); |
320 } | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
321 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
322 |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
323 /* Replace escape sequences in an URL (or a part of an URL) */ |
32534 | 324 /* works like strcpy(), but without return argument, |
325 except that outbuf == inbuf is allowed */ | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
326 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
327 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
|
328 { |
12391 | 329 unsigned char c,c1,c2; |
330 int i,len=strlen(inbuf); | |
331 for (i=0;i<len;i++){ | |
332 c = inbuf[i]; | |
333 if (c == '%' && i<len-2) { //must have 2 more chars | |
334 c1 = toupper(inbuf[i+1]); // we need uppercase characters | |
335 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
|
336 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
|
337 ((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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 c = (c1<<4) + c2; |
12391 | 343 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
|
344 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
345 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
346 *outbuf++ = c; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
347 } |
12391 | 348 *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
|
349 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
350 |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
351 static void |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
352 url_escape_string_part(char *outbuf, const char *inbuf) { |
12391 | 353 unsigned char c,c1,c2; |
354 int i,len=strlen(inbuf); | |
355 | |
356 for (i=0;i<len;i++) { | |
357 c = inbuf[i]; | |
358 if ((c=='%') && i<len-2 ) { //need 2 more characters | |
359 c1=toupper(inbuf[i+1]); c2=toupper(inbuf[i+2]); // need uppercase chars | |
360 } else { | |
361 c1=129; c2=129; //not escape chars | |
362 } | |
363 | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
364 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
|
365 (c >= 'a' && c <= 'z') || |
32746
2372e26d24fe
Escape character values >= 127 in URLs as required by the RFC.
reimar
parents:
32636
diff
changeset
|
366 (c >= '0' && c <= '9')) { |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
367 *outbuf++ = c; |
12391 | 368 } else if ( c=='%' && ((c1 >= '0' && c1 <= '9') || (c1 >= 'A' && c1 <= 'F')) && |
369 ((c2 >= '0' && c2 <= '9') || (c2 >= 'A' && c2 <= 'F'))) { | |
370 // check if part of an escape sequence | |
371 *outbuf++=c; // already | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
372 |
12391 | 373 // dont escape again |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
16421
diff
changeset
|
374 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_URL_StringAlreadyEscaped,c,c1,c2); |
12391 | 375 // error as this should not happen against RFC 2396 |
376 // 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
|
377 } else { |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
378 /* all others will be escaped */ |
12391 | 379 c1 = ((c & 0xf0) >> 4); |
380 c2 = (c & 0x0f); | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
381 if (c1 < 10) c1+='0'; |
9924 | 382 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
|
383 if (c2 < 10) c2+='0'; |
9924 | 384 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
|
385 *outbuf++ = '%'; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
386 *outbuf++ = c1; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
387 *outbuf++ = c2; |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
388 } |
12391 | 389 } |
390 *outbuf++='\0'; | |
3496
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
391 } |
5c8a533dfa09
Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents:
3494
diff
changeset
|
392 |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
393 /* Replace specific characters in the URL string by an escape sequence */ |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
394 /* works like strcpy(), but without return argument */ |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
395 void |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
396 url_escape_string(char *outbuf, const char *inbuf) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
397 unsigned char c; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
398 int i = 0,j,len = strlen(inbuf); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
399 char* tmp,*unesc = NULL, *in; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
400 |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
401 // Look if we have an ip6 address, if so skip it there is |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
402 // no need to escape anything in there. |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
403 tmp = strstr(inbuf,"://["); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
404 if(tmp) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
405 tmp = strchr(tmp+4,']'); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
406 if(tmp && (tmp[1] == '/' || tmp[1] == ':' || |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
407 tmp[1] == '\0')) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
408 i = tmp+1-inbuf; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
409 strncpy(outbuf,inbuf,i); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
410 outbuf += i; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
411 tmp = NULL; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
412 } |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
413 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
414 |
25795
e96b4070ba66
Clear tmp between ip6 check and string escape to prevent reuse of the
rtogni
parents:
25620
diff
changeset
|
415 tmp = NULL; |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
416 while(i < len) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
417 // look for the next char that must be kept |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
418 for (j=i;j<len;j++) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
419 c = inbuf[j]; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
420 if(c=='-' || c=='_' || c=='.' || c=='!' || c=='~' || /* mark characters */ |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
421 c=='*' || c=='\'' || c=='(' || c==')' || /* do not touch escape character */ |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
422 c==';' || c=='/' || c=='?' || c==':' || c=='@' || /* reserved characters */ |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
423 c=='&' || c=='=' || c=='+' || c=='$' || c==',') /* see RFC 2396 */ |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
424 break; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
425 } |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
426 // we are on a reserved char, write it out |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
427 if(j == i) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
428 *outbuf++ = c; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
429 i++; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
430 continue; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
431 } |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
432 // we found one, take that part of the string |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
433 if(j < len) { |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
434 if(!tmp) tmp = malloc(len+1); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
435 strncpy(tmp,inbuf+i,j-i); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
436 tmp[j-i] = '\0'; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
437 in = tmp; |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
438 } else // take the rest of the string |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
439 in = (char*)inbuf+i; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25795
diff
changeset
|
440 |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
441 if(!unesc) unesc = malloc(len+1); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
442 // unescape first to avoid escaping escape |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
443 url_unescape_string(unesc,in); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
444 // then escape, including mark and other reserved chars |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
445 // that can come from escape sequences |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
446 url_escape_string_part(outbuf,unesc); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
447 outbuf += strlen(outbuf); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
448 i += strlen(in); |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
449 } |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
450 *outbuf = '\0'; |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
451 free(tmp); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
30426
diff
changeset
|
452 free(unesc); |
17048
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
453 } |
9e02b9cb171b
Fix URL escaping to correctly handle URL containing an ip6 address or
albeu
parents:
16908
diff
changeset
|
454 |
25620
53e5107ea80d
Fix illegal identifiers, names starting with __ are reserved for the system.
diego
parents:
21126
diff
changeset
|
455 #ifdef URL_DEBUG |
4119
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
456 void |
9690
a9b7b6055563
Added support for IPv6 numeric url like: http://[3ffe:400:100::1]:80/file
bertrand
parents:
7809
diff
changeset
|
457 url_debug(const URL_t *url) { |
4119
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
458 if( url==NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
459 printf("URL pointer NULL\n"); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
460 return; |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
461 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
462 if( url->url!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
463 printf("url=%s\n", url->url ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
464 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
465 if( url->protocol!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
466 printf("protocol=%s\n", url->protocol ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
467 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
468 if( url->hostname!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
469 printf("hostname=%s\n", url->hostname ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
470 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
471 printf("port=%d\n", url->port ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
472 if( url->file!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
473 printf("file=%s\n", url->file ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
474 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
475 if( url->username!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
476 printf("username=%s\n", url->username ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
477 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
478 if( url->password!=NULL ) { |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
479 printf("password=%s\n", url->password ); |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
480 } |
639b3b47b138
Added a debug function to print the struct's variables.
bertrand
parents:
3612
diff
changeset
|
481 } |
25620
53e5107ea80d
Fix illegal identifiers, names starting with __ are reserved for the system.
diego
parents:
21126
diff
changeset
|
482 #endif /* URL_DEBUG */ |