2 * Copyright 2010 Jacek Caban for CodeWeavers
3 * Copyright 2010 Thomas Mullaly
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "urlmon_main.h"
21 #include "wine/debug.h"
23 #define NO_SHLWAPI_REG
26 #define UINT_MAX 0xffffffff
27 #define USHORT_MAX 0xffff
29 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
31 static const IID IID_IUriObj
= {0x4b364760,0x9f51,0x11df,{0x98,0x1c,0x08,0x00,0x20,0x0c,0x9a,0x66}};
34 const IUriVtbl
*lpIUriVtbl
;
39 /* Information about the canonicalized URI's buffer. */
43 BOOL display_absolute
;
47 URL_SCHEME scheme_type
;
55 Uri_HOST_TYPE host_type
;
77 const IUriBuilderVtbl
*lpIUriBuilderVtbl
;
89 /* IPv6 addresses can hold up to 8 h16 components. */
93 /* An IPv6 can have 1 elision ("::"). */
96 /* An IPv6 can contain 1 IPv4 address as the last 32bits of the address. */
109 BOOL has_implicit_scheme
;
110 BOOL has_implicit_ip
;
115 URL_SCHEME scheme_type
;
117 const WCHAR
*userinfo
;
123 Uri_HOST_TYPE host_type
;
126 ipv6_address ipv6_address
;
138 const WCHAR
*fragment
;
142 static const CHAR hexDigits
[] = "0123456789ABCDEF";
144 /* List of scheme types/scheme names that are recognized by the IUri interface as of IE 7. */
145 static const struct {
147 WCHAR scheme_name
[16];
148 } recognized_schemes
[] = {
149 {URL_SCHEME_FTP
, {'f','t','p',0}},
150 {URL_SCHEME_HTTP
, {'h','t','t','p',0}},
151 {URL_SCHEME_GOPHER
, {'g','o','p','h','e','r',0}},
152 {URL_SCHEME_MAILTO
, {'m','a','i','l','t','o',0}},
153 {URL_SCHEME_NEWS
, {'n','e','w','s',0}},
154 {URL_SCHEME_NNTP
, {'n','n','t','p',0}},
155 {URL_SCHEME_TELNET
, {'t','e','l','n','e','t',0}},
156 {URL_SCHEME_WAIS
, {'w','a','i','s',0}},
157 {URL_SCHEME_FILE
, {'f','i','l','e',0}},
158 {URL_SCHEME_MK
, {'m','k',0}},
159 {URL_SCHEME_HTTPS
, {'h','t','t','p','s',0}},
160 {URL_SCHEME_SHELL
, {'s','h','e','l','l',0}},
161 {URL_SCHEME_SNEWS
, {'s','n','e','w','s',0}},
162 {URL_SCHEME_LOCAL
, {'l','o','c','a','l',0}},
163 {URL_SCHEME_JAVASCRIPT
, {'j','a','v','a','s','c','r','i','p','t',0}},
164 {URL_SCHEME_VBSCRIPT
, {'v','b','s','c','r','i','p','t',0}},
165 {URL_SCHEME_ABOUT
, {'a','b','o','u','t',0}},
166 {URL_SCHEME_RES
, {'r','e','s',0}},
167 {URL_SCHEME_MSSHELLROOTED
, {'m','s','-','s','h','e','l','l','-','r','o','o','t','e','d',0}},
168 {URL_SCHEME_MSSHELLIDLIST
, {'m','s','-','s','h','e','l','l','-','i','d','l','i','s','t',0}},
169 {URL_SCHEME_MSHELP
, {'h','c','p',0}},
170 {URL_SCHEME_WILDCARD
, {'*',0}}
173 /* List of default ports Windows recognizes. */
174 static const struct {
177 } default_ports
[] = {
178 {URL_SCHEME_FTP
, 21},
179 {URL_SCHEME_HTTP
, 80},
180 {URL_SCHEME_GOPHER
, 70},
181 {URL_SCHEME_NNTP
, 119},
182 {URL_SCHEME_TELNET
, 23},
183 {URL_SCHEME_WAIS
, 210},
184 {URL_SCHEME_HTTPS
, 443},
187 /* List of 3 character top level domain names Windows seems to recognize.
188 * There might be more, but, these are the only ones I've found so far.
190 static const struct {
192 } recognized_tlds
[] = {
202 static Uri
*get_uri_obj(IUri
*uri
)
207 hres
= IUri_QueryInterface(uri
, &IID_IUriObj
, (void**)&ret
);
208 return SUCCEEDED(hres
) ? ret
: NULL
;
211 static inline BOOL
is_alpha(WCHAR val
) {
212 return ((val
>= 'a' && val
<= 'z') || (val
>= 'A' && val
<= 'Z'));
215 static inline BOOL
is_num(WCHAR val
) {
216 return (val
>= '0' && val
<= '9');
219 static inline BOOL
is_drive_path(const WCHAR
*str
) {
220 return (is_alpha(str
[0]) && (str
[1] == ':' || str
[1] == '|'));
223 static inline BOOL
is_unc_path(const WCHAR
*str
) {
224 return (str
[0] == '\\' && str
[0] == '\\');
227 static inline BOOL
is_forbidden_dos_path_char(WCHAR val
) {
228 return (val
== '>' || val
== '<' || val
== '\"');
231 /* A URI is implicitly a file path if it begins with
232 * a drive letter (eg X:) or starts with "\\" (UNC path).
234 static inline BOOL
is_implicit_file_path(const WCHAR
*str
) {
235 return (is_unc_path(str
) || (is_alpha(str
[0]) && str
[1] == ':'));
238 /* Checks if the URI is a hierarchical URI. A hierarchical
239 * URI is one that has "//" after the scheme.
241 static BOOL
check_hierarchical(const WCHAR
**ptr
) {
242 const WCHAR
*start
= *ptr
;
257 /* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" */
258 static inline BOOL
is_unreserved(WCHAR val
) {
259 return (is_alpha(val
) || is_num(val
) || val
== '-' || val
== '.' ||
260 val
== '_' || val
== '~');
263 /* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
264 * / "*" / "+" / "," / ";" / "="
266 static inline BOOL
is_subdelim(WCHAR val
) {
267 return (val
== '!' || val
== '$' || val
== '&' ||
268 val
== '\'' || val
== '(' || val
== ')' ||
269 val
== '*' || val
== '+' || val
== ',' ||
270 val
== ';' || val
== '=');
273 /* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" */
274 static inline BOOL
is_gendelim(WCHAR val
) {
275 return (val
== ':' || val
== '/' || val
== '?' ||
276 val
== '#' || val
== '[' || val
== ']' ||
280 /* Characters that delimit the end of the authority
281 * section of a URI. Sometimes a '\\' is considered
282 * an authority delimeter.
284 static inline BOOL
is_auth_delim(WCHAR val
, BOOL acceptSlash
) {
285 return (val
== '#' || val
== '/' || val
== '?' ||
286 val
== '\0' || (acceptSlash
&& val
== '\\'));
289 /* reserved = gen-delims / sub-delims */
290 static inline BOOL
is_reserved(WCHAR val
) {
291 return (is_subdelim(val
) || is_gendelim(val
));
294 static inline BOOL
is_hexdigit(WCHAR val
) {
295 return ((val
>= 'a' && val
<= 'f') ||
296 (val
>= 'A' && val
<= 'F') ||
297 (val
>= '0' && val
<= '9'));
300 static inline BOOL
is_path_delim(WCHAR val
) {
301 return (!val
|| val
== '#' || val
== '?');
304 /* List of schemes types Windows seems to expect to be hierarchical. */
305 static inline BOOL
is_hierarchical_scheme(URL_SCHEME type
) {
306 return(type
== URL_SCHEME_HTTP
|| type
== URL_SCHEME_FTP
||
307 type
== URL_SCHEME_GOPHER
|| type
== URL_SCHEME_NNTP
||
308 type
== URL_SCHEME_TELNET
|| type
== URL_SCHEME_WAIS
||
309 type
== URL_SCHEME_FILE
|| type
== URL_SCHEME_HTTPS
||
310 type
== URL_SCHEME_RES
);
313 /* Determines if the URI is hierarchical using the information already parsed into
314 * data and using the current location of parsing in the URI string.
316 * Windows considers a URI hierarchical if on of the following is true:
317 * A.) It's a wildcard scheme.
318 * B.) It's an implicit file scheme.
319 * C.) It's a known hierarchical scheme and it has two '\\' after the scheme name.
320 * (the '\\' will be converted into "//" during canonicalization).
321 * D.) It's not a relative URI and "//" appears after the scheme name.
323 static inline BOOL
is_hierarchical_uri(const WCHAR
**ptr
, const parse_data
*data
) {
324 const WCHAR
*start
= *ptr
;
326 if(data
->scheme_type
== URL_SCHEME_WILDCARD
)
328 else if(data
->scheme_type
== URL_SCHEME_FILE
&& data
->has_implicit_scheme
)
330 else if(is_hierarchical_scheme(data
->scheme_type
) && (*ptr
)[0] == '\\' && (*ptr
)[1] == '\\') {
333 } else if(!data
->is_relative
&& check_hierarchical(ptr
))
340 /* Checks if the two Uri's are logically equivalent. It's a simple
341 * comparison, since they are both of type Uri, and it can access
342 * the properties of each Uri directly without the need to go
343 * through the "IUri_Get*" interface calls.
345 static BOOL
are_equal_simple(const Uri
*a
, const Uri
*b
) {
346 if(a
->scheme_type
== b
->scheme_type
) {
347 const BOOL known_scheme
= a
->scheme_type
!= URL_SCHEME_UNKNOWN
;
348 const BOOL are_hierarchical
=
349 (a
->authority_start
> -1 && b
->authority_start
> -1);
351 if(a
->scheme_type
== URL_SCHEME_FILE
) {
352 if(a
->canon_len
== b
->canon_len
)
353 return !StrCmpIW(a
->canon_uri
, b
->canon_uri
);
356 /* Only compare the scheme names (if any) if their unknown scheme types. */
358 if((a
->scheme_start
> -1 && b
->scheme_start
> -1) &&
359 (a
->scheme_len
== b
->scheme_len
)) {
360 /* Make sure the schemes are the same. */
361 if(StrCmpNW(a
->canon_uri
+a
->scheme_start
, b
->canon_uri
+b
->scheme_start
, a
->scheme_len
))
363 } else if(a
->scheme_len
!= b
->scheme_len
)
364 /* One of the Uri's has a scheme name, while the other doesn't. */
368 /* If they have a userinfo component, perform case sensitive compare. */
369 if((a
->userinfo_start
> -1 && b
->userinfo_start
> -1) &&
370 (a
->userinfo_len
== b
->userinfo_len
)) {
371 if(StrCmpNW(a
->canon_uri
+a
->userinfo_start
, b
->canon_uri
+b
->userinfo_start
, a
->userinfo_len
))
373 } else if(a
->userinfo_len
!= b
->userinfo_len
)
374 /* One of the Uri's had a userinfo, while the other one doesn't. */
377 /* Check if they have a host name. */
378 if((a
->host_start
> -1 && b
->host_start
> -1) &&
379 (a
->host_len
== b
->host_len
)) {
380 /* Perform a case insensitive compare if they are a known scheme type. */
382 if(StrCmpNIW(a
->canon_uri
+a
->host_start
, b
->canon_uri
+b
->host_start
, a
->host_len
))
384 } else if(StrCmpNW(a
->canon_uri
+a
->host_start
, b
->canon_uri
+b
->host_start
, a
->host_len
))
386 } else if(a
->host_len
!= b
->host_len
)
387 /* One of the Uri's had a host, while the other one didn't. */
390 if(a
->has_port
&& b
->has_port
) {
391 if(a
->port
!= b
->port
)
393 } else if(a
->has_port
|| b
->has_port
)
394 /* One had a port, while the other one didn't. */
397 /* Windows is weird with how it handles paths. For example
398 * One URI could be "http://google.com" (after canonicalization)
399 * and one could be "http://google.com/" and the IsEqual function
400 * would still evaluate to TRUE, but, only if they are both hierarchical
403 if((a
->path_start
> -1 && b
->path_start
> -1) &&
404 (a
->path_len
== b
->path_len
)) {
405 if(StrCmpNW(a
->canon_uri
+a
->path_start
, b
->canon_uri
+b
->path_start
, a
->path_len
))
407 } else if(are_hierarchical
&& a
->path_len
== -1 && b
->path_len
== 0) {
408 if(*(a
->canon_uri
+a
->path_start
) != '/')
410 } else if(are_hierarchical
&& b
->path_len
== 1 && a
->path_len
== 0) {
411 if(*(b
->canon_uri
+b
->path_start
) != '/')
413 } else if(a
->path_len
!= b
->path_len
)
416 /* Compare the query strings of the two URIs. */
417 if((a
->query_start
> -1 && b
->query_start
> -1) &&
418 (a
->query_len
== b
->query_len
)) {
419 if(StrCmpNW(a
->canon_uri
+a
->query_start
, b
->canon_uri
+b
->query_start
, a
->query_len
))
421 } else if(a
->query_len
!= b
->query_len
)
424 if((a
->fragment_start
> -1 && b
->fragment_start
> -1) &&
425 (a
->fragment_len
== b
->fragment_len
)) {
426 if(StrCmpNW(a
->canon_uri
+a
->fragment_start
, b
->canon_uri
+b
->fragment_start
, a
->fragment_len
))
428 } else if(a
->fragment_len
!= b
->fragment_len
)
431 /* If we get here, the two URIs are equivalent. */
438 /* Computes the size of the given IPv6 address.
439 * Each h16 component is 16bits, if there is an IPv4 address, it's
440 * 32bits. If there's an elision it can be 16bits to 128bits, depending
441 * on the number of other components.
443 * Modeled after google-url's CheckIPv6ComponentsSize function
445 static void compute_ipv6_comps_size(ipv6_address
*address
) {
446 address
->components_size
= address
->h16_count
* 2;
449 /* IPv4 address is 4 bytes. */
450 address
->components_size
+= 4;
452 if(address
->elision
) {
453 /* An elision can be anywhere from 2 bytes up to 16 bytes.
454 * It size depends on the size of the h16 and IPv4 components.
456 address
->elision_size
= 16 - address
->components_size
;
457 if(address
->elision_size
< 2)
458 address
->elision_size
= 2;
460 address
->elision_size
= 0;
463 /* Taken from dlls/jscript/lex.c */
464 static int hex_to_int(WCHAR val
) {
465 if(val
>= '0' && val
<= '9')
467 else if(val
>= 'a' && val
<= 'f')
468 return val
- 'a' + 10;
469 else if(val
>= 'A' && val
<= 'F')
470 return val
- 'A' + 10;
475 /* Helper function for converting a percent encoded string
476 * representation of a WCHAR value into its actual WCHAR value. If
477 * the two characters following the '%' aren't valid hex values then
478 * this function returns the NULL character.
481 * "%2E" will result in '.' being returned by this function.
483 static WCHAR
decode_pct_val(const WCHAR
*ptr
) {
486 if(*ptr
== '%' && is_hexdigit(*(ptr
+ 1)) && is_hexdigit(*(ptr
+ 2))) {
487 INT a
= hex_to_int(*(ptr
+ 1));
488 INT b
= hex_to_int(*(ptr
+ 2));
497 /* Helper function for percent encoding a given character
498 * and storing the encoded value into a given buffer (dest).
500 * It's up to the calling function to ensure that there is
501 * at least enough space in 'dest' for the percent encoded
502 * value to be stored (so dest + 3 spaces available).
504 static inline void pct_encode_val(WCHAR val
, WCHAR
*dest
) {
506 dest
[1] = hexDigits
[(val
>> 4) & 0xf];
507 dest
[2] = hexDigits
[val
& 0xf];
510 /* Scans the range of characters [str, end] and returns the last occurrence
511 * of 'ch' or returns NULL.
513 static const WCHAR
*str_last_of(const WCHAR
*str
, const WCHAR
*end
, WCHAR ch
) {
514 const WCHAR
*ptr
= end
;
525 /* Attempts to parse the domain name from the host.
527 * This function also includes the Top-level Domain (TLD) name
528 * of the host when it tries to find the domain name. If it finds
529 * a valid domain name it will assign 'domain_start' the offset
530 * into 'host' where the domain name starts.
532 * It's implied that if a domain name its range is implied to be
533 * [host+domain_start, host+host_len).
535 static void find_domain_name(const WCHAR
*host
, DWORD host_len
,
537 const WCHAR
*last_tld
, *sec_last_tld
, *end
;
539 end
= host
+host_len
-1;
543 /* There has to be at least enough room for a '.' followed by a
544 * 3 character TLD for a domain to even exist in the host name.
549 last_tld
= str_last_of(host
, end
, '.');
551 /* http://hostname -> has no domain name. */
554 sec_last_tld
= str_last_of(host
, last_tld
-1, '.');
556 /* If the '.' is at the beginning of the host there
557 * has to be at least 3 characters in the TLD for it
559 * Ex: .com -> .com as the domain name.
560 * .co -> has no domain name.
562 if(last_tld
-host
== 0) {
563 if(end
-(last_tld
-1) < 3)
565 } else if(last_tld
-host
== 3) {
568 /* If there's three characters in front of last_tld and
569 * they are on the list of recognized TLDs, then this
570 * host doesn't have a domain (since the host only contains
572 * Ex: edu.uk -> has no domain name.
573 * foo.uk -> foo.uk as the domain name.
575 for(i
= 0; i
< sizeof(recognized_tlds
)/sizeof(recognized_tlds
[0]); ++i
) {
576 if(!StrCmpNIW(host
, recognized_tlds
[i
].tld_name
, 3))
579 } else if(last_tld
-host
< 3)
580 /* Anything less than 3 characters is considered part
582 * Ex: ak.uk -> Has no domain name.
586 /* Otherwise the domain name is the whole host name. */
588 } else if(end
+1-last_tld
> 3) {
589 /* If the last_tld has more than 3 characters, then it's automatically
590 * considered the TLD of the domain name.
591 * Ex: www.winehq.org.uk.test -> uk.test as the domain name.
593 *domain_start
= (sec_last_tld
+1)-host
;
594 } else if(last_tld
- (sec_last_tld
+1) < 4) {
596 /* If the sec_last_tld is 3 characters long it HAS to be on the list of
597 * recognized to still be considered part of the TLD name, otherwise
598 * its considered the domain name.
599 * Ex: www.google.com.uk -> google.com.uk as the domain name.
600 * www.google.foo.uk -> foo.uk as the domain name.
602 if(last_tld
- (sec_last_tld
+1) == 3) {
603 for(i
= 0; i
< sizeof(recognized_tlds
)/sizeof(recognized_tlds
[0]); ++i
) {
604 if(!StrCmpNIW(sec_last_tld
+1, recognized_tlds
[i
].tld_name
, 3)) {
605 const WCHAR
*domain
= str_last_of(host
, sec_last_tld
-1, '.');
610 *domain_start
= (domain
+1) - host
;
611 TRACE("Found domain name %s\n", debugstr_wn(host
+*domain_start
,
612 (host
+host_len
)-(host
+*domain_start
)));
617 *domain_start
= (sec_last_tld
+1)-host
;
619 /* Since the sec_last_tld is less than 3 characters it's considered
621 * Ex: www.google.fo.uk -> google.fo.uk as the domain name.
623 const WCHAR
*domain
= str_last_of(host
, sec_last_tld
-1, '.');
628 *domain_start
= (domain
+1) - host
;
631 /* The second to last TLD has more than 3 characters making it
633 * Ex: www.google.test.us -> test.us as the domain name.
635 *domain_start
= (sec_last_tld
+1)-host
;
638 TRACE("Found domain name %s\n", debugstr_wn(host
+*domain_start
,
639 (host
+host_len
)-(host
+*domain_start
)));
642 /* Removes the dot segments from a hierarchical URIs path component. This
643 * function performs the removal in place.
645 * This is a modified version of Qt's QUrl function "removeDotsFromPath".
647 * This function returns the new length of the path string.
649 static DWORD
remove_dot_segments(WCHAR
*path
, DWORD path_len
) {
651 const WCHAR
*in
= out
;
652 const WCHAR
*end
= out
+ path_len
;
656 /* A. if the input buffer begins with a prefix of "/./" or "/.",
657 * where "." is a complete path segment, then replace that
658 * prefix with "/" in the input buffer; otherwise,
660 if(in
<= end
- 3 && in
[0] == '/' && in
[1] == '.' && in
[2] == '/') {
663 } else if(in
== end
- 2 && in
[0] == '/' && in
[1] == '.') {
669 /* B. if the input buffer begins with a prefix of "/../" or "/..",
670 * where ".." is a complete path segment, then replace that
671 * prefix with "/" in the input buffer and remove the last
672 * segment and its preceding "/" (if any) from the output
675 if(in
<= end
- 4 && in
[0] == '/' && in
[1] == '.' && in
[2] == '.' && in
[3] == '/') {
676 while(out
> path
&& *(--out
) != '/');
680 } else if(in
== end
- 3 && in
[0] == '/' && in
[1] == '.' && in
[2] == '.') {
681 while(out
> path
&& *(--out
) != '/');
690 /* C. move the first path segment in the input buffer to the end of
691 * the output buffer, including the initial "/" character (if
692 * any) and any subsequent characters up to, but not including,
693 * the next "/" character or the end of the input buffer.
696 while(in
< end
&& *in
!= '/')
701 TRACE("(%p %d): Path after dot segments removed %s len=%d\n", path
, path_len
,
702 debugstr_wn(path
, len
), len
);
706 /* Attempts to find the file extension in a given path. */
707 static INT
find_file_extension(const WCHAR
*path
, DWORD path_len
) {
710 for(end
= path
+path_len
-1; end
>= path
&& *end
!= '/' && *end
!= '\\'; --end
) {
718 /* Computes the location where the elision should occur in the IPv6
719 * address using the numerical values of each component stored in
720 * 'values'. If the address shouldn't contain an elision then 'index'
721 * is assigned -1 as it's value. Otherwise 'index' will contain the
722 * starting index (into values) where the elision should be, and 'count'
723 * will contain the number of cells the elision covers.
726 * Windows will expand an elision if the elision only represents 1 h16
727 * component of the URI.
729 * Ex: [1::2:3:4:5:6:7] -> [1:0:2:3:4:5:6:7]
731 * If the IPv6 address contains an IPv4 address, the IPv4 address is also
732 * considered for being included as part of an elision if all it's components
735 * Ex: [1:2:3:4:5:6:0.0.0.0] -> [1:2:3:4:5:6::]
737 static void compute_elision_location(const ipv6_address
*address
, const USHORT values
[8],
738 INT
*index
, DWORD
*count
) {
739 DWORD i
, max_len
, cur_len
;
740 INT max_index
, cur_index
;
742 max_len
= cur_len
= 0;
743 max_index
= cur_index
= -1;
744 for(i
= 0; i
< 8; ++i
) {
745 BOOL check_ipv4
= (address
->ipv4
&& i
== 6);
746 BOOL is_end
= (check_ipv4
|| i
== 7);
749 /* Check if the IPv4 address contains only zeros. */
750 if(values
[i
] == 0 && values
[i
+1] == 0) {
757 } else if(values
[i
] == 0) {
764 if(is_end
|| values
[i
] != 0) {
765 /* We only consider it for an elision if it's
766 * more than 1 component long.
768 if(cur_len
> 1 && cur_len
> max_len
) {
769 /* Found the new elision location. */
771 max_index
= cur_index
;
774 /* Reset the current range for the next range of zeros. */
784 /* Removes all the leading and trailing white spaces or
785 * control characters from the URI and removes all control
786 * characters inside of the URI string.
788 static BSTR
pre_process_uri(LPCWSTR uri
) {
791 const WCHAR
*start
, *end
;
797 /* Skip leading controls and whitespace. */
798 while(iscntrlW(*start
) || isspaceW(*start
)) ++start
;
802 /* URI consisted only of control/whitespace. */
803 ret
= SysAllocStringLen(NULL
, 0);
805 while(iscntrlW(*end
) || isspaceW(*end
)) --end
;
807 buf
= heap_alloc(((end
+1)-start
)*sizeof(WCHAR
));
811 for(ptr
= buf
; start
< end
+1; ++start
) {
812 if(!iscntrlW(*start
))
816 ret
= SysAllocStringLen(buf
, ptr
-buf
);
823 /* Converts the specified IPv4 address into an uint value.
825 * This function assumes that the IPv4 address has already been validated.
827 static UINT
ipv4toui(const WCHAR
*ip
, DWORD len
) {
829 DWORD comp_value
= 0;
832 for(ptr
= ip
; ptr
< ip
+len
; ++ptr
) {
838 comp_value
= comp_value
*10 + (*ptr
-'0');
847 /* Converts an IPv4 address in numerical form into it's fully qualified
848 * string form. This function returns the number of characters written
849 * to 'dest'. If 'dest' is NULL this function will return the number of
850 * characters that would have been written.
852 * It's up to the caller to ensure there's enough space in 'dest' for the
855 static DWORD
ui2ipv4(WCHAR
*dest
, UINT address
) {
856 static const WCHAR formatW
[] =
857 {'%','u','.','%','u','.','%','u','.','%','u',0};
861 digits
[0] = (address
>> 24) & 0xff;
862 digits
[1] = (address
>> 16) & 0xff;
863 digits
[2] = (address
>> 8) & 0xff;
864 digits
[3] = address
& 0xff;
868 ret
= sprintfW(tmp
, formatW
, digits
[0], digits
[1], digits
[2], digits
[3]);
870 ret
= sprintfW(dest
, formatW
, digits
[0], digits
[1], digits
[2], digits
[3]);
875 /* Converts an h16 component (from an IPv6 address) into it's
878 * This function assumes that the h16 component has already been validated.
880 static USHORT
h16tous(h16 component
) {
884 for(i
= 0; i
< component
.len
; ++i
) {
886 ret
+= hex_to_int(component
.str
[i
]);
892 /* Converts an IPv6 address into it's 128 bits (16 bytes) numerical value.
894 * This function assumes that the ipv6_address has already been validated.
896 static BOOL
ipv6_to_number(const ipv6_address
*address
, USHORT number
[8]) {
897 DWORD i
, cur_component
= 0;
898 BOOL already_passed_elision
= FALSE
;
900 for(i
= 0; i
< address
->h16_count
; ++i
) {
901 if(address
->elision
) {
902 if(address
->components
[i
].str
> address
->elision
&& !already_passed_elision
) {
903 /* Means we just passed the elision and need to add it's values to
904 * 'number' before we do anything else.
907 for(j
= 0; j
< address
->elision_size
; j
+=2)
908 number
[cur_component
++] = 0;
910 already_passed_elision
= TRUE
;
914 number
[cur_component
++] = h16tous(address
->components
[i
]);
917 /* Case when the elision appears after the h16 components. */
918 if(!already_passed_elision
&& address
->elision
) {
919 for(i
= 0; i
< address
->elision_size
; i
+=2)
920 number
[cur_component
++] = 0;
921 already_passed_elision
= TRUE
;
925 UINT value
= ipv4toui(address
->ipv4
, address
->ipv4_len
);
927 if(cur_component
!= 6) {
928 ERR("(%p %p): Failed sanity check with %d\n", address
, number
, cur_component
);
932 number
[cur_component
++] = (value
>> 16) & 0xffff;
933 number
[cur_component
] = value
& 0xffff;
939 /* Checks if the characters pointed to by 'ptr' are
940 * a percent encoded data octet.
942 * pct-encoded = "%" HEXDIG HEXDIG
944 static BOOL
check_pct_encoded(const WCHAR
**ptr
) {
945 const WCHAR
*start
= *ptr
;
951 if(!is_hexdigit(**ptr
)) {
957 if(!is_hexdigit(**ptr
)) {
966 /* dec-octet = DIGIT ; 0-9
967 * / %x31-39 DIGIT ; 10-99
968 * / "1" 2DIGIT ; 100-199
969 * / "2" %x30-34 DIGIT ; 200-249
970 * / "25" %x30-35 ; 250-255
972 static BOOL
check_dec_octet(const WCHAR
**ptr
) {
973 const WCHAR
*c1
, *c2
, *c3
;
976 /* A dec-octet must be at least 1 digit long. */
977 if(*c1
< '0' || *c1
> '9')
983 /* Since the 1 digit requirment was meet, it doesn't
984 * matter if this is a DIGIT value, it's considered a
987 if(*c2
< '0' || *c2
> '9')
993 /* Same explanation as above. */
994 if(*c3
< '0' || *c3
> '9')
997 /* Anything > 255 isn't a valid IP dec-octet. */
998 if(*c1
>= '2' && *c2
>= '5' && *c3
>= '5') {
1007 /* Checks if there is an implicit IPv4 address in the host component of the URI.
1008 * The max value of an implicit IPv4 address is UINT_MAX.
1011 * "234567" would be considered an implicit IPv4 address.
1013 static BOOL
check_implicit_ipv4(const WCHAR
**ptr
, UINT
*val
) {
1014 const WCHAR
*start
= *ptr
;
1018 while(is_num(**ptr
)) {
1019 ret
= ret
*10 + (**ptr
- '0');
1021 if(ret
> UINT_MAX
) {
1035 /* Checks if the string contains an IPv4 address.
1037 * This function has a strict mode or a non-strict mode of operation
1038 * When 'strict' is set to FALSE this function will return TRUE if
1039 * the string contains at least 'dec-octet "." dec-octet' since partial
1040 * IPv4 addresses will be normalized out into full IPv4 addresses. When
1041 * 'strict' is set this function expects there to be a full IPv4 address.
1043 * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
1045 static BOOL
check_ipv4address(const WCHAR
**ptr
, BOOL strict
) {
1046 const WCHAR
*start
= *ptr
;
1048 if(!check_dec_octet(ptr
)) {
1059 if(!check_dec_octet(ptr
)) {
1073 if(!check_dec_octet(ptr
)) {
1087 if(!check_dec_octet(ptr
)) {
1092 /* Found a four digit ip address. */
1095 /* Tries to parse the scheme name of the URI.
1097 * scheme = ALPHA *(ALPHA | NUM | '+' | '-' | '.') as defined by RFC 3896.
1098 * NOTE: Windows accepts a number as the first character of a scheme.
1100 static BOOL
parse_scheme_name(const WCHAR
**ptr
, parse_data
*data
) {
1101 const WCHAR
*start
= *ptr
;
1103 data
->scheme
= NULL
;
1104 data
->scheme_len
= 0;
1107 if(**ptr
== '*' && *ptr
== start
) {
1108 /* Might have found a wildcard scheme. If it is the next
1109 * char has to be a ':' for it to be a valid URI
1113 } else if(!is_num(**ptr
) && !is_alpha(**ptr
) && **ptr
!= '+' &&
1114 **ptr
!= '-' && **ptr
!= '.')
1123 /* Schemes must end with a ':' */
1129 data
->scheme
= start
;
1130 data
->scheme_len
= *ptr
- start
;
1136 /* Tries to deduce the corresponding URL_SCHEME for the given URI. Stores
1137 * the deduced URL_SCHEME in data->scheme_type.
1139 static BOOL
parse_scheme_type(parse_data
*data
) {
1140 /* If there's scheme data then see if it's a recognized scheme. */
1141 if(data
->scheme
&& data
->scheme_len
) {
1144 for(i
= 0; i
< sizeof(recognized_schemes
)/sizeof(recognized_schemes
[0]); ++i
) {
1145 if(lstrlenW(recognized_schemes
[i
].scheme_name
) == data
->scheme_len
) {
1146 /* Has to be a case insensitive compare. */
1147 if(!StrCmpNIW(recognized_schemes
[i
].scheme_name
, data
->scheme
, data
->scheme_len
)) {
1148 data
->scheme_type
= recognized_schemes
[i
].scheme
;
1154 /* If we get here it means it's not a recognized scheme. */
1155 data
->scheme_type
= URL_SCHEME_UNKNOWN
;
1157 } else if(data
->is_relative
) {
1158 /* Relative URI's have no scheme. */
1159 data
->scheme_type
= URL_SCHEME_UNKNOWN
;
1162 /* Should never reach here! what happened... */
1163 FIXME("(%p): Unable to determine scheme type for URI %s\n", data
, debugstr_w(data
->uri
));
1168 /* Tries to parse (or deduce) the scheme_name of a URI. If it can't
1169 * parse a scheme from the URI it will try to deduce the scheme_name and scheme_type
1170 * using the flags specified in 'flags' (if any). Flags that affect how this function
1171 * operates are the Uri_CREATE_ALLOW_* flags.
1173 * All parsed/deduced information will be stored in 'data' when the function returns.
1175 * Returns TRUE if it was able to successfully parse the information.
1177 static BOOL
parse_scheme(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1178 static const WCHAR fileW
[] = {'f','i','l','e',0};
1179 static const WCHAR wildcardW
[] = {'*',0};
1181 /* First check to see if the uri could implicitly be a file path. */
1182 if(is_implicit_file_path(*ptr
)) {
1183 if(flags
& Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
) {
1184 data
->scheme
= fileW
;
1185 data
->scheme_len
= lstrlenW(fileW
);
1186 data
->has_implicit_scheme
= TRUE
;
1188 TRACE("(%p %p %x): URI is an implicit file path.\n", ptr
, data
, flags
);
1190 /* Window's does not consider anything that can implicitly be a file
1191 * path to be a valid URI if the ALLOW_IMPLICIT_FILE_SCHEME flag is not set...
1193 TRACE("(%p %p %x): URI is implicitly a file path, but, the ALLOW_IMPLICIT_FILE_SCHEME flag wasn't set.\n",
1197 } else if(!parse_scheme_name(ptr
, data
)) {
1198 /* No Scheme was found, this means it could be:
1199 * a) an implicit Wildcard scheme
1203 if(flags
& Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
) {
1204 data
->scheme
= wildcardW
;
1205 data
->scheme_len
= lstrlenW(wildcardW
);
1206 data
->has_implicit_scheme
= TRUE
;
1208 TRACE("(%p %p %x): URI is an implicit wildcard scheme.\n", ptr
, data
, flags
);
1209 } else if (flags
& Uri_CREATE_ALLOW_RELATIVE
) {
1210 data
->is_relative
= TRUE
;
1211 TRACE("(%p %p %x): URI is relative.\n", ptr
, data
, flags
);
1213 TRACE("(%p %p %x): Malformed URI found. Unable to deduce scheme name.\n", ptr
, data
, flags
);
1218 if(!data
->is_relative
)
1219 TRACE("(%p %p %x): Found scheme=%s scheme_len=%d\n", ptr
, data
, flags
,
1220 debugstr_wn(data
->scheme
, data
->scheme_len
), data
->scheme_len
);
1222 if(!parse_scheme_type(data
))
1225 TRACE("(%p %p %x): Assigned %d as the URL_SCHEME.\n", ptr
, data
, flags
, data
->scheme_type
);
1229 /* Parses the userinfo part of the URI (if it exists). The userinfo field of
1230 * a URI can consist of "username:password@", or just "username@".
1233 * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
1236 * 1) If there is more than one ':' in the userinfo part of the URI Windows
1237 * uses the first occurrence of ':' to delimit the username and password
1241 * ftp://user:pass:word@winehq.org
1243 * Would yield, "user" as the username and "pass:word" as the password.
1245 * 2) Windows allows any character to appear in the "userinfo" part of
1246 * a URI, as long as it's not an authority delimeter character set.
1248 static void parse_userinfo(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1249 data
->userinfo
= *ptr
;
1250 data
->userinfo_split
= -1;
1252 while(**ptr
!= '@') {
1253 if(**ptr
== ':' && data
->userinfo_split
== -1)
1254 data
->userinfo_split
= *ptr
- data
->userinfo
;
1255 else if(**ptr
== '%') {
1256 /* If it's a known scheme type, it has to be a valid percent
1259 if(!check_pct_encoded(ptr
)) {
1260 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1261 *ptr
= data
->userinfo
;
1262 data
->userinfo
= NULL
;
1263 data
->userinfo_split
= -1;
1265 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr
, data
, flags
);
1270 } else if(is_auth_delim(**ptr
, data
->scheme_type
!= URL_SCHEME_UNKNOWN
))
1277 *ptr
= data
->userinfo
;
1278 data
->userinfo
= NULL
;
1279 data
->userinfo_split
= -1;
1281 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr
, data
, flags
);
1285 data
->userinfo_len
= *ptr
- data
->userinfo
;
1286 TRACE("(%p %p %x): Found userinfo=%s userinfo_len=%d split=%d.\n", ptr
, data
, flags
,
1287 debugstr_wn(data
->userinfo
, data
->userinfo_len
), data
->userinfo_len
, data
->userinfo_split
);
1291 /* Attempts to parse a port from the URI.
1294 * Windows seems to have a cap on what the maximum value
1295 * for a port can be. The max value is USHORT_MAX.
1299 static BOOL
parse_port(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1303 while(!is_auth_delim(**ptr
, data
->scheme_type
!= URL_SCHEME_UNKNOWN
)) {
1304 if(!is_num(**ptr
)) {
1310 port
= port
*10 + (**ptr
-'0');
1312 if(port
> USHORT_MAX
) {
1321 data
->port_value
= port
;
1322 data
->port_len
= *ptr
- data
->port
;
1324 TRACE("(%p %p %x): Found port %s len=%d value=%u\n", ptr
, data
, flags
,
1325 debugstr_wn(data
->port
, data
->port_len
), data
->port_len
, data
->port_value
);
1329 /* Attempts to parse a IPv4 address from the URI.
1332 * Window's normalizes IPv4 addresses, This means there's three
1333 * possibilities for the URI to contain an IPv4 address.
1334 * 1) A well formed address (ex. 192.2.2.2).
1335 * 2) A partially formed address. For example "192.0" would
1336 * normalize to "192.0.0.0" during canonicalization.
1337 * 3) An implicit IPv4 address. For example "256" would
1338 * normalize to "0.0.1.0" during canonicalization. Also
1339 * note that the maximum value for an implicit IP address
1340 * is UINT_MAX, if the value in the URI exceeds this then
1341 * it is not considered an IPv4 address.
1343 static BOOL
parse_ipv4address(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1344 const BOOL is_unknown
= data
->scheme_type
== URL_SCHEME_UNKNOWN
;
1347 if(!check_ipv4address(ptr
, FALSE
)) {
1348 if(!check_implicit_ipv4(ptr
, &data
->implicit_ipv4
)) {
1349 TRACE("(%p %p %x): URI didn't contain anything looking like an IPv4 address.\n",
1355 data
->has_implicit_ip
= TRUE
;
1358 /* Check if what we found is the only part of the host name (if it isn't
1359 * we don't have an IPv4 address).
1363 if(!parse_port(ptr
, data
, flags
)) {
1368 } else if(!is_auth_delim(**ptr
, !is_unknown
)) {
1369 /* Found more data which belongs the host, so this isn't an IPv4. */
1372 data
->has_implicit_ip
= FALSE
;
1376 data
->host_len
= *ptr
- data
->host
;
1377 data
->host_type
= Uri_HOST_IPV4
;
1379 TRACE("(%p %p %x): IPv4 address found. host=%s host_len=%d host_type=%d\n",
1380 ptr
, data
, flags
, debugstr_wn(data
->host
, data
->host_len
),
1381 data
->host_len
, data
->host_type
);
1385 /* Attempts to parse the reg-name from the URI.
1387 * Because of the way Windows handles ':' this function also
1388 * handles parsing the port.
1390 * reg-name = *( unreserved / pct-encoded / sub-delims )
1393 * Windows allows everything, but, the characters in "auth_delims" and ':'
1394 * to appear in a reg-name, unless it's an unknown scheme type then ':' is
1395 * allowed to appear (even if a valid port isn't after it).
1397 * Windows doesn't like host names which start with '[' and end with ']'
1398 * and don't contain a valid IP literal address in between them.
1400 * On Windows if an '[' is encountered in the host name the ':' no longer
1401 * counts as a delimiter until you reach the next ']' or an "authority delimeter".
1403 * A reg-name CAN be empty.
1405 static BOOL
parse_reg_name(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1406 const BOOL has_start_bracket
= **ptr
== '[';
1407 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1408 BOOL inside_brackets
= has_start_bracket
;
1409 BOOL ignore_col
= FALSE
;
1411 /* We have to be careful with file schemes. */
1412 if(data
->scheme_type
== URL_SCHEME_FILE
) {
1413 /* This is because an implicit file scheme could be "C:\\test" and it
1414 * would trick this function into thinking the host is "C", when after
1415 * canonicalization the host would end up being an empty string. A drive
1416 * path can also have a '|' instead of a ':' after the drive letter.
1418 if(is_drive_path(*ptr
)) {
1419 /* Regular old drive paths don't have a host type (or host name). */
1420 data
->host_type
= Uri_HOST_UNKNOWN
;
1424 } else if(is_unc_path(*ptr
))
1425 /* Skip past the "\\" of a UNC path. */
1431 while(!is_auth_delim(**ptr
, known_scheme
)) {
1432 if(**ptr
== ':' && !ignore_col
) {
1433 /* We can ignore ':' if were inside brackets.*/
1434 if(!inside_brackets
) {
1435 const WCHAR
*tmp
= (*ptr
)++;
1437 /* Attempt to parse the port. */
1438 if(!parse_port(ptr
, data
, flags
)) {
1439 /* Windows expects there to be a valid port for known scheme types. */
1440 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1443 TRACE("(%p %p %x): Expected valid port\n", ptr
, data
, flags
);
1446 /* Windows gives up on trying to parse a port when it
1447 * encounters 1 invalid port.
1451 data
->host_len
= tmp
- data
->host
;
1455 } else if(**ptr
== '%' && known_scheme
) {
1456 /* Has to be a legit % encoded value. */
1457 if(!check_pct_encoded(ptr
)) {
1463 } else if(**ptr
== ']')
1464 inside_brackets
= FALSE
;
1465 else if(**ptr
== '[')
1466 inside_brackets
= TRUE
;
1471 if(has_start_bracket
) {
1472 /* Make sure the last character of the host wasn't a ']'. */
1473 if(*(*ptr
-1) == ']') {
1474 TRACE("(%p %p %x): Expected an IP literal inside of the host\n",
1482 /* Don't overwrite our length if we found a port earlier. */
1484 data
->host_len
= *ptr
- data
->host
;
1486 /* If the host is empty, then it's an unknown host type. */
1487 if(data
->host_len
== 0)
1488 data
->host_type
= Uri_HOST_UNKNOWN
;
1490 data
->host_type
= Uri_HOST_DNS
;
1492 TRACE("(%p %p %x): Parsed reg-name. host=%s len=%d\n", ptr
, data
, flags
,
1493 debugstr_wn(data
->host
, data
->host_len
), data
->host_len
);
1497 /* Attempts to parse an IPv6 address out of the URI.
1499 * IPv6address = 6( h16 ":" ) ls32
1500 * / "::" 5( h16 ":" ) ls32
1501 * / [ h16 ] "::" 4( h16 ":" ) ls32
1502 * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1503 * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1504 * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1505 * / [ *4( h16 ":" ) h16 ] "::" ls32
1506 * / [ *5( h16 ":" ) h16 ] "::" h16
1507 * / [ *6( h16 ":" ) h16 ] "::"
1509 * ls32 = ( h16 ":" h16 ) / IPv4address
1510 * ; least-significant 32 bits of address.
1513 * ; 16 bits of address represented in hexadecimal.
1515 * Modeled after google-url's 'DoParseIPv6' function.
1517 static BOOL
parse_ipv6address(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1518 const WCHAR
*start
, *cur_start
;
1521 start
= cur_start
= *ptr
;
1522 memset(&ip
, 0, sizeof(ipv6_address
));
1525 /* Check if we're on the last character of the host. */
1526 BOOL is_end
= (is_auth_delim(**ptr
, data
->scheme_type
!= URL_SCHEME_UNKNOWN
)
1529 BOOL is_split
= (**ptr
== ':');
1530 BOOL is_elision
= (is_split
&& !is_end
&& *(*ptr
+1) == ':');
1532 /* Check if we're at the end of a component, or
1533 * if we're at the end of the IPv6 address.
1535 if(is_split
|| is_end
) {
1538 cur_len
= *ptr
- cur_start
;
1540 /* h16 can't have a length > 4. */
1544 TRACE("(%p %p %x): h16 component to long.\n",
1550 /* An h16 component can't have the length of 0 unless
1551 * the elision is at the beginning of the address, or
1552 * at the end of the address.
1554 if(!((*ptr
== start
&& is_elision
) ||
1555 (is_end
&& (*ptr
-2) == ip
.elision
))) {
1557 TRACE("(%p %p %x): IPv6 component cannot have a length of 0.\n",
1564 /* An IPv6 address can have no more than 8 h16 components. */
1565 if(ip
.h16_count
>= 8) {
1567 TRACE("(%p %p %x): Not a IPv6 address, to many h16 components.\n",
1572 ip
.components
[ip
.h16_count
].str
= cur_start
;
1573 ip
.components
[ip
.h16_count
].len
= cur_len
;
1575 TRACE("(%p %p %x): Found h16 component %s, len=%d, h16_count=%d\n",
1576 ptr
, data
, flags
, debugstr_wn(cur_start
, cur_len
), cur_len
,
1586 /* A IPv6 address can only have 1 elision ('::'). */
1590 TRACE("(%p %p %x): IPv6 address cannot have 2 elisions.\n",
1602 if(!check_ipv4address(ptr
, TRUE
)) {
1603 if(!is_hexdigit(**ptr
)) {
1604 /* Not a valid character for an IPv6 address. */
1609 /* Found an IPv4 address. */
1610 ip
.ipv4
= cur_start
;
1611 ip
.ipv4_len
= *ptr
- cur_start
;
1613 TRACE("(%p %p %x): Found an attached IPv4 address %s len=%d.\n",
1614 ptr
, data
, flags
, debugstr_wn(ip
.ipv4
, ip
.ipv4_len
),
1617 /* IPv4 addresses can only appear at the end of a IPv6. */
1623 compute_ipv6_comps_size(&ip
);
1625 /* Make sure the IPv6 address adds up to 16 bytes. */
1626 if(ip
.components_size
+ ip
.elision_size
!= 16) {
1628 TRACE("(%p %p %x): Invalid IPv6 address, did not add up to 16 bytes.\n",
1633 if(ip
.elision_size
== 2) {
1634 /* For some reason on Windows if an elision that represents
1635 * only 1 h16 component is encountered at the very begin or
1636 * end of an IPv6 address, Windows does not consider it a
1637 * valid IPv6 address.
1639 * Ex: [::2:3:4:5:6:7] is not valid, even though the sum
1640 * of all the components == 128bits.
1642 if(ip
.elision
< ip
.components
[0].str
||
1643 ip
.elision
> ip
.components
[ip
.h16_count
-1].str
) {
1645 TRACE("(%p %p %x): Invalid IPv6 address. Detected elision of 2 bytes at the beginning or end of the address.\n",
1651 data
->host_type
= Uri_HOST_IPV6
;
1652 data
->has_ipv6
= TRUE
;
1653 data
->ipv6_address
= ip
;
1655 TRACE("(%p %p %x): Found valid IPv6 literal %s len=%d\n",
1656 ptr
, data
, flags
, debugstr_wn(start
, *ptr
-start
),
1661 /* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) */
1662 static BOOL
parse_ipvfuture(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1663 const WCHAR
*start
= *ptr
;
1665 /* IPvFuture has to start with a 'v' or 'V'. */
1666 if(**ptr
!= 'v' && **ptr
!= 'V')
1669 /* Following the v there must be at least 1 hex digit. */
1671 if(!is_hexdigit(**ptr
)) {
1677 while(is_hexdigit(**ptr
))
1680 /* End of the hexdigit sequence must be a '.' */
1687 if(!is_unreserved(**ptr
) && !is_subdelim(**ptr
) && **ptr
!= ':') {
1693 while(is_unreserved(**ptr
) || is_subdelim(**ptr
) || **ptr
== ':')
1696 data
->host_type
= Uri_HOST_UNKNOWN
;
1698 TRACE("(%p %p %x): Parsed IPvFuture address %s len=%d\n", ptr
, data
, flags
,
1699 debugstr_wn(start
, *ptr
-start
), *ptr
-start
);
1704 /* IP-literal = "[" ( IPv6address / IPvFuture ) "]" */
1705 static BOOL
parse_ip_literal(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1714 if(!parse_ipv6address(ptr
, data
, flags
)) {
1715 if(!parse_ipvfuture(ptr
, data
, flags
)) {
1731 /* If a valid port is not found, then let it trickle down to
1734 if(!parse_port(ptr
, data
, flags
)) {
1740 data
->host_len
= *ptr
- data
->host
;
1745 /* Parses the host information from the URI.
1747 * host = IP-literal / IPv4address / reg-name
1749 static BOOL
parse_host(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1750 if(!parse_ip_literal(ptr
, data
, flags
)) {
1751 if(!parse_ipv4address(ptr
, data
, flags
)) {
1752 if(!parse_reg_name(ptr
, data
, flags
)) {
1753 TRACE("(%p %p %x): Malformed URI, Unknown host type.\n",
1763 /* Parses the authority information from the URI.
1765 * authority = [ userinfo "@" ] host [ ":" port ]
1767 static BOOL
parse_authority(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1768 parse_userinfo(ptr
, data
, flags
);
1770 /* Parsing the port will happen during one of the host parsing
1771 * routines (if the URI has a port).
1773 if(!parse_host(ptr
, data
, flags
))
1779 /* Attempts to parse the path information of a hierarchical URI. */
1780 static BOOL
parse_path_hierarchical(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1781 const WCHAR
*start
= *ptr
;
1782 static const WCHAR slash
[] = {'/',0};
1783 const BOOL is_file
= data
->scheme_type
== URL_SCHEME_FILE
;
1785 if(is_path_delim(**ptr
)) {
1786 if(data
->scheme_type
== URL_SCHEME_WILDCARD
) {
1787 /* Wildcard schemes don't get a '/' attached if their path is
1792 } else if(!(flags
& Uri_CREATE_NO_CANONICALIZE
)) {
1793 /* If the path component is empty, then a '/' is added. */
1798 while(!is_path_delim(**ptr
)) {
1799 if(**ptr
== '%' && data
->scheme_type
!= URL_SCHEME_UNKNOWN
&& !is_file
) {
1800 if(!check_pct_encoded(ptr
)) {
1805 } else if(is_forbidden_dos_path_char(**ptr
) && is_file
&&
1806 (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
1807 /* File schemes with USE_DOS_PATH set aren't allowed to have
1808 * a '<' or '>' or '\"' appear in them.
1812 } else if(**ptr
== '\\') {
1813 /* Not allowed to have a backslash if NO_CANONICALIZE is set
1814 * and the scheme is known type (but not a file scheme).
1816 if(flags
& Uri_CREATE_NO_CANONICALIZE
) {
1817 if(data
->scheme_type
!= URL_SCHEME_FILE
&&
1818 data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1828 /* The only time a URI doesn't have a path is when
1829 * the NO_CANONICALIZE flag is set and the raw URI
1830 * didn't contain one.
1837 data
->path_len
= *ptr
- start
;
1842 TRACE("(%p %p %x): Parsed path %s len=%d\n", ptr
, data
, flags
,
1843 debugstr_wn(data
->path
, data
->path_len
), data
->path_len
);
1845 TRACE("(%p %p %x): The URI contained no path\n", ptr
, data
, flags
);
1850 /* Parses the path of a opaque URI (much less strict then the parser
1851 * for a hierarchical URI).
1854 * Windows allows invalid % encoded data to appear in opaque URI paths
1855 * for unknown scheme types.
1857 * File schemes with USE_DOS_PATH set aren't allowed to have '<', '>', or '\"'
1860 static BOOL
parse_path_opaque(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1861 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1862 const BOOL is_file
= data
->scheme_type
== URL_SCHEME_FILE
;
1866 while(!is_path_delim(**ptr
)) {
1867 if(**ptr
== '%' && known_scheme
) {
1868 if(!check_pct_encoded(ptr
)) {
1874 } else if(is_forbidden_dos_path_char(**ptr
) && is_file
&&
1875 (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
1884 data
->path_len
= *ptr
- data
->path
;
1885 TRACE("(%p %p %x): Parsed opaque URI path %s len=%d\n", ptr
, data
, flags
,
1886 debugstr_wn(data
->path
, data
->path_len
), data
->path_len
);
1890 /* Determines how the URI should be parsed after the scheme information.
1892 * If the scheme is followed, by "//" then, it is treated as an hierarchical URI
1893 * which then the authority and path information will be parsed out. Otherwise, the
1894 * URI will be treated as an opaque URI which the authority information is not parsed
1897 * RFC 3896 definition of hier-part:
1899 * hier-part = "//" authority path-abempty
1904 * MSDN opaque URI definition:
1905 * scheme ":" path [ "#" fragment ]
1908 * If the URI is of an unknown scheme type and has a "//" following the scheme then it
1909 * is treated as a hierarchical URI, but, if the CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is
1910 * set then it is considered an opaque URI reguardless of what follows the scheme information
1911 * (per MSDN documentation).
1913 static BOOL
parse_hierpart(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1914 const WCHAR
*start
= *ptr
;
1916 /* Checks if the authority information needs to be parsed. */
1917 if(is_hierarchical_uri(ptr
, data
)) {
1918 /* Only treat it as a hierarchical URI if the scheme_type is known or
1919 * the Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is not set.
1921 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
||
1922 !(flags
& Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES
)) {
1923 TRACE("(%p %p %x): Treating URI as an hierarchical URI.\n", ptr
, data
, flags
);
1924 data
->is_opaque
= FALSE
;
1926 /* TODO: Handle hierarchical URI's, parse authority then parse the path. */
1927 if(!parse_authority(ptr
, data
, flags
))
1930 return parse_path_hierarchical(ptr
, data
, flags
);
1932 /* Reset ptr to it's starting position so opaque path parsing
1933 * begins at the correct location.
1938 /* If it reaches here, then the URI will be treated as an opaque
1942 TRACE("(%p %p %x): Treating URI as an opaque URI.\n", ptr
, data
, flags
);
1944 data
->is_opaque
= TRUE
;
1945 if(!parse_path_opaque(ptr
, data
, flags
))
1951 /* Attempts to parse the query string from the URI.
1954 * If NO_DECODE_EXTRA_INFO flag is set, then invalid percent encoded
1955 * data is allowed appear in the query string. For unknown scheme types
1956 * invalid percent encoded data is allowed to appear reguardless.
1958 static BOOL
parse_query(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1959 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1962 TRACE("(%p %p %x): URI didn't contain a query string.\n", ptr
, data
, flags
);
1969 while(**ptr
&& **ptr
!= '#') {
1970 if(**ptr
== '%' && known_scheme
&&
1971 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
1972 if(!check_pct_encoded(ptr
)) {
1983 data
->query_len
= *ptr
- data
->query
;
1985 TRACE("(%p %p %x): Parsed query string %s len=%d\n", ptr
, data
, flags
,
1986 debugstr_wn(data
->query
, data
->query_len
), data
->query_len
);
1990 /* Attempts to parse the fragment from the URI.
1993 * If NO_DECODE_EXTRA_INFO flag is set, then invalid percent encoded
1994 * data is allowed appear in the query string. For unknown scheme types
1995 * invalid percent encoded data is allowed to appear reguardless.
1997 static BOOL
parse_fragment(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1998 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2001 TRACE("(%p %p %x): URI didn't contain a fragment.\n", ptr
, data
, flags
);
2005 data
->fragment
= *ptr
;
2009 if(**ptr
== '%' && known_scheme
&&
2010 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
2011 if(!check_pct_encoded(ptr
)) {
2012 *ptr
= data
->fragment
;
2013 data
->fragment
= NULL
;
2022 data
->fragment_len
= *ptr
- data
->fragment
;
2024 TRACE("(%p %p %x): Parsed fragment %s len=%d\n", ptr
, data
, flags
,
2025 debugstr_wn(data
->fragment
, data
->fragment_len
), data
->fragment_len
);
2029 /* Parses and validates the components of the specified by data->uri
2030 * and stores the information it parses into 'data'.
2032 * Returns TRUE if it successfully parsed the URI. False otherwise.
2034 static BOOL
parse_uri(parse_data
*data
, DWORD flags
) {
2041 TRACE("(%p %x): BEGINNING TO PARSE URI %s.\n", data
, flags
, debugstr_w(data
->uri
));
2043 if(!parse_scheme(pptr
, data
, flags
))
2046 if(!parse_hierpart(pptr
, data
, flags
))
2049 if(!parse_query(pptr
, data
, flags
))
2052 if(!parse_fragment(pptr
, data
, flags
))
2055 TRACE("(%p %x): FINISHED PARSING URI.\n", data
, flags
);
2059 /* Canonicalizes the userinfo of the URI represented by the parse_data.
2061 * Canonicalization of the userinfo is a simple process. If there are any percent
2062 * encoded characters that fall in the "unreserved" character set, they are decoded
2063 * to their actual value. If a character is not in the "unreserved" or "reserved" sets
2064 * then it is percent encoded. Other than that the characters are copied over without
2067 static BOOL
canonicalize_userinfo(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2070 uri
->userinfo_start
= uri
->userinfo_split
= -1;
2071 uri
->userinfo_len
= 0;
2074 /* URI doesn't have userinfo, so nothing to do here. */
2077 uri
->userinfo_start
= uri
->canon_len
;
2079 while(i
< data
->userinfo_len
) {
2080 if(data
->userinfo
[i
] == ':' && uri
->userinfo_split
== -1)
2081 /* Windows only considers the first ':' as the delimiter. */
2082 uri
->userinfo_split
= uri
->canon_len
- uri
->userinfo_start
;
2083 else if(data
->userinfo
[i
] == '%') {
2084 /* Only decode % encoded values for known scheme types. */
2085 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
2086 /* See if the value really needs decoded. */
2087 WCHAR val
= decode_pct_val(data
->userinfo
+ i
);
2088 if(is_unreserved(val
)) {
2090 uri
->canon_uri
[uri
->canon_len
] = val
;
2094 /* Move pass the hex characters. */
2099 } else if(!is_reserved(data
->userinfo
[i
]) && !is_unreserved(data
->userinfo
[i
]) &&
2100 data
->userinfo
[i
] != '\\') {
2101 /* Only percent encode forbidden characters if the NO_ENCODE_FORBIDDEN_CHARACTERS flag
2104 if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
)) {
2106 pct_encode_val(data
->userinfo
[i
], uri
->canon_uri
+ uri
->canon_len
);
2108 uri
->canon_len
+= 3;
2115 /* Nothing special, so just copy the character over. */
2116 uri
->canon_uri
[uri
->canon_len
] = data
->userinfo
[i
];
2122 uri
->userinfo_len
= uri
->canon_len
- uri
->userinfo_start
;
2124 TRACE("(%p %p %x %d): Canonicalized userinfo, userinfo_start=%d, userinfo=%s, userinfo_split=%d userinfo_len=%d.\n",
2125 data
, uri
, flags
, computeOnly
, uri
->userinfo_start
, debugstr_wn(uri
->canon_uri
+ uri
->userinfo_start
, uri
->userinfo_len
),
2126 uri
->userinfo_split
, uri
->userinfo_len
);
2128 /* Now insert the '@' after the userinfo. */
2130 uri
->canon_uri
[uri
->canon_len
] = '@';
2136 /* Attempts to canonicalize a reg_name.
2138 * Things that happen:
2139 * 1) If Uri_CREATE_NO_CANONICALIZE flag is not set, then the reg_name is
2140 * lower cased. Unless it's an unknown scheme type, which case it's
2141 * no lower cased reguardless.
2143 * 2) Unreserved % encoded characters are decoded for known
2146 * 3) Forbidden characters are % encoded as long as
2147 * Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS flag is not set and
2148 * it isn't an unknown scheme type.
2150 * 4) If it's a file scheme and the host is "localhost" it's removed.
2152 static BOOL
canonicalize_reg_name(const parse_data
*data
, Uri
*uri
,
2153 DWORD flags
, BOOL computeOnly
) {
2154 static const WCHAR localhostW
[] =
2155 {'l','o','c','a','l','h','o','s','t',0};
2157 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2159 uri
->host_start
= uri
->canon_len
;
2161 if(data
->scheme_type
== URL_SCHEME_FILE
&&
2162 data
->host_len
== lstrlenW(localhostW
)) {
2163 if(!StrCmpNIW(data
->host
, localhostW
, data
->host_len
)) {
2164 uri
->host_start
= -1;
2166 uri
->host_type
= Uri_HOST_UNKNOWN
;
2171 for(ptr
= data
->host
; ptr
< data
->host
+data
->host_len
; ++ptr
) {
2172 if(*ptr
== '%' && known_scheme
) {
2173 WCHAR val
= decode_pct_val(ptr
);
2174 if(is_unreserved(val
)) {
2175 /* If NO_CANONICALZE is not set, then windows lower cases the
2178 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
) && isupperW(val
)) {
2180 uri
->canon_uri
[uri
->canon_len
] = tolowerW(val
);
2183 uri
->canon_uri
[uri
->canon_len
] = val
;
2187 /* Skip past the % encoded character. */
2191 /* Just copy the % over. */
2193 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2196 } else if(*ptr
== '\\') {
2197 /* Only unknown scheme types could have made it here with a '\\' in the host name. */
2199 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2201 } else if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) &&
2202 !is_unreserved(*ptr
) && !is_reserved(*ptr
) && known_scheme
) {
2204 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2206 /* The percent encoded value gets lower cased also. */
2207 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
)) {
2208 uri
->canon_uri
[uri
->canon_len
+1] = tolowerW(uri
->canon_uri
[uri
->canon_len
+1]);
2209 uri
->canon_uri
[uri
->canon_len
+2] = tolowerW(uri
->canon_uri
[uri
->canon_len
+2]);
2213 uri
->canon_len
+= 3;
2216 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
) && known_scheme
)
2217 uri
->canon_uri
[uri
->canon_len
] = tolowerW(*ptr
);
2219 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2226 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2229 TRACE("(%p %p %x %d): Canonicalize reg_name=%s len=%d\n", data
, uri
, flags
,
2230 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2234 find_domain_name(uri
->canon_uri
+uri
->host_start
, uri
->host_len
,
2235 &(uri
->domain_offset
));
2240 /* Attempts to canonicalize an implicit IPv4 address. */
2241 static BOOL
canonicalize_implicit_ipv4address(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2242 uri
->host_start
= uri
->canon_len
;
2244 TRACE("%u\n", data
->implicit_ipv4
);
2245 /* For unknown scheme types Window's doesn't convert
2246 * the value into an IP address, but, it still considers
2247 * it an IPv4 address.
2249 if(data
->scheme_type
== URL_SCHEME_UNKNOWN
) {
2251 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2252 uri
->canon_len
+= data
->host_len
;
2255 uri
->canon_len
+= ui2ipv4(uri
->canon_uri
+uri
->canon_len
, data
->implicit_ipv4
);
2257 uri
->canon_len
+= ui2ipv4(NULL
, data
->implicit_ipv4
);
2260 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2261 uri
->host_type
= Uri_HOST_IPV4
;
2264 TRACE("%p %p %x %d): Canonicalized implicit IP address=%s len=%d\n",
2265 data
, uri
, flags
, computeOnly
,
2266 debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2272 /* Attempts to canonicalize an IPv4 address.
2274 * If the parse_data represents a URI that has an implicit IPv4 address
2275 * (ex. http://256/, this function will convert 256 into 0.0.1.0). If
2276 * the implicit IP address exceeds the value of UINT_MAX (maximum value
2277 * for an IPv4 address) it's canonicalized as if were a reg-name.
2279 * If the parse_data contains a partial or full IPv4 address it normalizes it.
2280 * A partial IPv4 address is something like "192.0" and would be normalized to
2281 * "192.0.0.0". With a full (or partial) IPv4 address like "192.002.01.003" would
2282 * be normalized to "192.2.1.3".
2285 * Window's ONLY normalizes IPv4 address for known scheme types (one that isn't
2286 * URL_SCHEME_UNKNOWN). For unknown scheme types, it simply copies the data from
2287 * the original URI into the canonicalized URI, but, it still recognizes URI's
2288 * host type as HOST_IPV4.
2290 static BOOL
canonicalize_ipv4address(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2291 if(data
->has_implicit_ip
)
2292 return canonicalize_implicit_ipv4address(data
, uri
, flags
, computeOnly
);
2294 uri
->host_start
= uri
->canon_len
;
2296 /* Windows only normalizes for known scheme types. */
2297 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
2298 /* parse_data contains a partial or full IPv4 address, so normalize it. */
2299 DWORD i
, octetDigitCount
= 0, octetCount
= 0;
2300 BOOL octetHasDigit
= FALSE
;
2302 for(i
= 0; i
< data
->host_len
; ++i
) {
2303 if(data
->host
[i
] == '0' && !octetHasDigit
) {
2304 /* Can ignore leading zeros if:
2305 * 1) It isn't the last digit of the octet.
2306 * 2) i+1 != data->host_len
2309 if(octetDigitCount
== 2 ||
2310 i
+1 == data
->host_len
||
2311 data
->host
[i
+1] == '.') {
2313 uri
->canon_uri
[uri
->canon_len
] = data
->host
[i
];
2315 TRACE("Adding zero\n");
2317 } else if(data
->host
[i
] == '.') {
2319 uri
->canon_uri
[uri
->canon_len
] = data
->host
[i
];
2322 octetDigitCount
= 0;
2323 octetHasDigit
= FALSE
;
2327 uri
->canon_uri
[uri
->canon_len
] = data
->host
[i
];
2331 octetHasDigit
= TRUE
;
2335 /* Make sure the canonicalized IP address has 4 dec-octets.
2336 * If doesn't add "0" ones until there is 4;
2338 for( ; octetCount
< 3; ++octetCount
) {
2340 uri
->canon_uri
[uri
->canon_len
] = '.';
2341 uri
->canon_uri
[uri
->canon_len
+1] = '0';
2344 uri
->canon_len
+= 2;
2347 /* Windows doesn't normalize addresses in unknown schemes. */
2349 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2350 uri
->canon_len
+= data
->host_len
;
2353 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2355 TRACE("(%p %p %x %d): Canonicalized IPv4 address, ip=%s len=%d\n",
2356 data
, uri
, flags
, computeOnly
,
2357 debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2364 /* Attempts to canonicalize the IPv6 address of the URI.
2366 * Multiple things happen during the canonicalization of an IPv6 address:
2367 * 1) Any leading zero's in an h16 component are removed.
2368 * Ex: [0001:0022::] -> [1:22::]
2370 * 2) The longest sequence of zero h16 components are compressed
2371 * into a "::" (elision). If there's a tie, the first is choosen.
2373 * Ex: [0:0:0:0:1:6:7:8] -> [::1:6:7:8]
2374 * [0:0:0:0:1:2::] -> [::1:2:0:0]
2375 * [0:0:1:2:0:0:7:8] -> [::1:2:0:0:7:8]
2377 * 3) If an IPv4 address is attached to the IPv6 address, it's
2379 * Ex: [::001.002.022.000] -> [::1.2.22.0]
2381 * 4) If an elision is present, but, only represents 1 h16 component
2384 * Ex: [1::2:3:4:5:6:7] -> [1:0:2:3:4:5:6:7]
2386 * 5) If the IPv6 address contains an IPv4 address and there exists
2387 * at least 1 non-zero h16 component the IPv4 address is converted
2388 * into two h16 components, otherwise it's normalized and kept as is.
2390 * Ex: [::192.200.003.4] -> [::192.200.3.4]
2391 * [ffff::192.200.003.4] -> [ffff::c0c8:3041]
2394 * For unknown scheme types Windows simply copies the address over without any
2397 * IPv4 address can be included in an elision if all its components are 0's.
2399 static BOOL
canonicalize_ipv6address(const parse_data
*data
, Uri
*uri
,
2400 DWORD flags
, BOOL computeOnly
) {
2401 uri
->host_start
= uri
->canon_len
;
2403 if(data
->scheme_type
== URL_SCHEME_UNKNOWN
) {
2405 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2406 uri
->canon_len
+= data
->host_len
;
2410 DWORD i
, elision_len
;
2412 if(!ipv6_to_number(&(data
->ipv6_address
), values
)) {
2413 TRACE("(%p %p %x %d): Failed to compute numerical value for IPv6 address.\n",
2414 data
, uri
, flags
, computeOnly
);
2419 uri
->canon_uri
[uri
->canon_len
] = '[';
2422 /* Find where the elision should occur (if any). */
2423 compute_elision_location(&(data
->ipv6_address
), values
, &elision_start
, &elision_len
);
2425 TRACE("%p %p %x %d): Elision starts at %d, len=%u\n", data
, uri
, flags
,
2426 computeOnly
, elision_start
, elision_len
);
2428 for(i
= 0; i
< 8; ++i
) {
2429 BOOL in_elision
= (elision_start
> -1 && i
>= elision_start
&&
2430 i
< elision_start
+elision_len
);
2431 BOOL do_ipv4
= (i
== 6 && data
->ipv6_address
.ipv4
&& !in_elision
&&
2432 data
->ipv6_address
.h16_count
== 0);
2434 if(i
== elision_start
) {
2436 uri
->canon_uri
[uri
->canon_len
] = ':';
2437 uri
->canon_uri
[uri
->canon_len
+1] = ':';
2439 uri
->canon_len
+= 2;
2442 /* We can ignore the current component if we're in the elision. */
2446 /* We only add a ':' if we're not at i == 0, or when we're at
2447 * the very end of elision range since the ':' colon was handled
2448 * earlier. Otherwise we would end up with ":::" after elision.
2450 if(i
!= 0 && !(elision_start
> -1 && i
== elision_start
+elision_len
)) {
2452 uri
->canon_uri
[uri
->canon_len
] = ':';
2460 /* Combine the two parts of the IPv4 address values. */
2466 len
= ui2ipv4(uri
->canon_uri
+uri
->canon_len
, val
);
2468 len
= ui2ipv4(NULL
, val
);
2470 uri
->canon_len
+= len
;
2473 /* Write a regular h16 component to the URI. */
2475 /* Short circuit for the trivial case. */
2476 if(values
[i
] == 0) {
2478 uri
->canon_uri
[uri
->canon_len
] = '0';
2481 static const WCHAR formatW
[] = {'%','x',0};
2484 uri
->canon_len
+= sprintfW(uri
->canon_uri
+uri
->canon_len
,
2485 formatW
, values
[i
]);
2488 uri
->canon_len
+= sprintfW(tmp
, formatW
, values
[i
]);
2494 /* Add the closing ']'. */
2496 uri
->canon_uri
[uri
->canon_len
] = ']';
2500 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2503 TRACE("(%p %p %x %d): Canonicalized IPv6 address %s, len=%d\n", data
, uri
, flags
,
2504 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2510 /* Attempts to canonicalize the host of the URI (if any). */
2511 static BOOL
canonicalize_host(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2512 uri
->host_start
= -1;
2514 uri
->domain_offset
= -1;
2517 switch(data
->host_type
) {
2519 uri
->host_type
= Uri_HOST_DNS
;
2520 if(!canonicalize_reg_name(data
, uri
, flags
, computeOnly
))
2525 uri
->host_type
= Uri_HOST_IPV4
;
2526 if(!canonicalize_ipv4address(data
, uri
, flags
, computeOnly
))
2531 if(!canonicalize_ipv6address(data
, uri
, flags
, computeOnly
))
2534 uri
->host_type
= Uri_HOST_IPV6
;
2536 case Uri_HOST_UNKNOWN
:
2537 if(data
->host_len
> 0 || data
->scheme_type
!= URL_SCHEME_FILE
) {
2538 uri
->host_start
= uri
->canon_len
;
2540 /* Nothing happens to unknown host types. */
2542 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2543 uri
->canon_len
+= data
->host_len
;
2544 uri
->host_len
= data
->host_len
;
2547 uri
->host_type
= Uri_HOST_UNKNOWN
;
2550 FIXME("(%p %p %x %d): Canonicalization for host type %d not supported.\n", data
,
2551 uri
, flags
, computeOnly
, data
->host_type
);
2559 static BOOL
canonicalize_port(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2560 BOOL has_default_port
= FALSE
;
2561 USHORT default_port
= 0;
2564 uri
->has_port
= FALSE
;
2566 /* Check if the scheme has a default port. */
2567 for(i
= 0; i
< sizeof(default_ports
)/sizeof(default_ports
[0]); ++i
) {
2568 if(default_ports
[i
].scheme
== data
->scheme_type
) {
2569 has_default_port
= TRUE
;
2570 default_port
= default_ports
[i
].port
;
2575 if(data
->port
|| has_default_port
)
2576 uri
->has_port
= TRUE
;
2579 * 1) Has a port which is the default port.
2580 * 2) Has a port (not the default).
2581 * 3) Doesn't have a port, but, scheme has a default port.
2584 if(has_default_port
&& data
->port
&& data
->port_value
== default_port
) {
2585 /* If it's the default port and this flag isn't set, don't do anything. */
2586 if(flags
& Uri_CREATE_NO_CANONICALIZE
) {
2587 /* Copy the original port over. */
2589 uri
->canon_uri
[uri
->canon_len
] = ':';
2590 memcpy(uri
->canon_uri
+uri
->canon_len
+1, data
->port
, data
->port_len
*sizeof(WCHAR
));
2592 uri
->canon_len
+= data
->port_len
+1;
2595 uri
->port
= default_port
;
2596 } else if(data
->port
) {
2598 uri
->canon_uri
[uri
->canon_len
] = ':';
2601 if(flags
& Uri_CREATE_NO_CANONICALIZE
) {
2602 /* Copy the original over without changes. */
2604 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->port
, data
->port_len
*sizeof(WCHAR
));
2605 uri
->canon_len
+= data
->port_len
;
2607 const WCHAR formatW
[] = {'%','u',0};
2610 len
= sprintfW(uri
->canon_uri
+uri
->canon_len
, formatW
, data
->port_value
);
2613 len
= sprintfW(tmp
, formatW
, data
->port_value
);
2615 uri
->canon_len
+= len
;
2618 uri
->port
= data
->port_value
;
2619 } else if(has_default_port
)
2620 uri
->port
= default_port
;
2625 /* Canonicalizes the authority of the URI represented by the parse_data. */
2626 static BOOL
canonicalize_authority(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2627 uri
->authority_start
= uri
->canon_len
;
2628 uri
->authority_len
= 0;
2630 if(!canonicalize_userinfo(data
, uri
, flags
, computeOnly
))
2633 if(!canonicalize_host(data
, uri
, flags
, computeOnly
))
2636 if(!canonicalize_port(data
, uri
, flags
, computeOnly
))
2639 if(uri
->host_start
!= -1)
2640 uri
->authority_len
= uri
->canon_len
- uri
->authority_start
;
2642 uri
->authority_start
= -1;
2647 /* Attempts to canonicalize the path of a hierarchical URI.
2649 * Things that happen:
2650 * 1). Forbidden characters are percent encoded, unless the NO_ENCODE_FORBIDDEN
2651 * flag is set or it's a file URI. Forbidden characters are always encoded
2652 * for file schemes reguardless and forbidden characters are never encoded
2653 * for unknown scheme types.
2655 * 2). For known scheme types '\\' are changed to '/'.
2657 * 3). Percent encoded, unreserved characters are decoded to their actual values.
2658 * Unless the scheme type is unknown. For file schemes any percent encoded
2659 * character in the unreserved or reserved set is decoded.
2661 * 4). For File schemes if the path is starts with a drive letter and doesn't
2662 * start with a '/' then one is appended.
2663 * Ex: file://c:/test.mp3 -> file:///c:/test.mp3
2665 * 5). Dot segments are removed from the path for all scheme types
2666 * unless NO_CANONICALIZE flag is set. Dot segments aren't removed
2667 * for wildcard scheme types.
2670 * file://c:/test%20test -> file:///c:/test%2520test
2671 * file://c:/test%3Etest -> file:///c:/test%253Etest
2672 * file:///c:/test%20test -> file:///c:/test%20test
2673 * file:///c:/test%test -> file:///c:/test%25test
2675 static BOOL
canonicalize_path_hierarchical(const parse_data
*data
, Uri
*uri
,
2676 DWORD flags
, BOOL computeOnly
) {
2678 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2679 const BOOL is_file
= data
->scheme_type
== URL_SCHEME_FILE
;
2681 BOOL escape_pct
= FALSE
;
2684 uri
->path_start
= -1;
2689 uri
->path_start
= uri
->canon_len
;
2692 if(is_file
&& uri
->host_start
== -1) {
2693 /* Check if a '/' needs to be appended for the file scheme. */
2694 if(data
->path_len
> 1 && is_drive_path(ptr
) && !(flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2696 uri
->canon_uri
[uri
->canon_len
] = '/';
2699 } else if(*ptr
== '/') {
2700 if(!(flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2701 /* Copy the extra '/' over. */
2703 uri
->canon_uri
[uri
->canon_len
] = '/';
2709 if(is_drive_path(ptr
)) {
2711 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2712 /* If theres a '|' after the drive letter, convert it to a ':'. */
2713 uri
->canon_uri
[uri
->canon_len
+1] = ':';
2716 uri
->canon_len
+= 2;
2720 for(; ptr
< data
->path
+data
->path_len
; ++ptr
) {
2722 const WCHAR
*tmp
= ptr
;
2725 /* Check if the % represents a valid encoded char, or if it needs encoded. */
2726 BOOL force_encode
= !check_pct_encoded(&tmp
) && is_file
;
2727 val
= decode_pct_val(ptr
);
2729 if(force_encode
|| escape_pct
) {
2730 /* Escape the percent sign in the file URI. */
2732 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2733 uri
->canon_len
+= 3;
2734 } else if((is_unreserved(val
) && known_scheme
) ||
2735 (is_file
&& (is_unreserved(val
) || is_reserved(val
)))) {
2737 uri
->canon_uri
[uri
->canon_len
] = val
;
2744 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2747 } else if(*ptr
== '/' && is_file
&& (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2748 /* Convert the '/' back to a '\\'. */
2750 uri
->canon_uri
[uri
->canon_len
] = '\\';
2752 } else if(*ptr
== '\\' && known_scheme
) {
2753 if(is_file
&& (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2754 /* Don't convert the '\\' to a '/'. */
2756 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2760 uri
->canon_uri
[uri
->canon_len
] = '/';
2763 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
) &&
2764 (!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) || is_file
)) {
2765 if(is_file
&& (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2766 /* Don't escape the character. */
2768 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2771 /* Escape the forbidden character. */
2773 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2774 uri
->canon_len
+= 3;
2778 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2783 uri
->path_len
= uri
->canon_len
- uri
->path_start
;
2785 /* Removing the dot segments only happens when it's not in
2786 * computeOnly mode and it's not a wildcard scheme. File schemes
2787 * with USE_DOS_PATH set don't get dot segments removed.
2789 if(!(is_file
&& (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) &&
2790 data
->scheme_type
!= URL_SCHEME_WILDCARD
) {
2791 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
) && !computeOnly
) {
2792 /* Remove the dot segments (if any) and reset everything to the new
2795 DWORD new_len
= remove_dot_segments(uri
->canon_uri
+uri
->path_start
, uri
->path_len
);
2796 uri
->canon_len
-= uri
->path_len
-new_len
;
2797 uri
->path_len
= new_len
;
2802 TRACE("Canonicalized path %s len=%d\n",
2803 debugstr_wn(uri
->canon_uri
+uri
->path_start
, uri
->path_len
),
2809 /* Attempts to canonicalize the path for an opaque URI.
2811 * For known scheme types:
2812 * 1) forbidden characters are percent encoded if
2813 * NO_ENCODE_FORBIDDEN_CHARACTERS isn't set.
2815 * 2) Percent encoded, unreserved characters are decoded
2816 * to their actual values, for known scheme types.
2818 * 3) '\\' are changed to '/' for known scheme types
2819 * except for mailto schemes.
2821 * 4) For file schemes, if USE_DOS_PATH is set all '/'
2822 * are converted to backslashes.
2824 * 5) For file schemes, if USE_DOS_PATH isn't set all '\'
2825 * are converted to forward slashes.
2827 static BOOL
canonicalize_path_opaque(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2829 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2830 const BOOL is_file
= data
->scheme_type
== URL_SCHEME_FILE
;
2833 uri
->path_start
= -1;
2838 uri
->path_start
= uri
->canon_len
;
2840 /* Windows doesn't allow a "//" to appear after the scheme
2841 * of a URI, if it's an opaque URI.
2843 if(data
->scheme
&& *(data
->path
) == '/' && *(data
->path
+1) == '/') {
2844 /* So it inserts a "/." before the "//" if it exists. */
2846 uri
->canon_uri
[uri
->canon_len
] = '/';
2847 uri
->canon_uri
[uri
->canon_len
+1] = '.';
2850 uri
->canon_len
+= 2;
2853 for(ptr
= data
->path
; ptr
< data
->path
+data
->path_len
; ++ptr
) {
2854 if(*ptr
== '%' && known_scheme
) {
2855 WCHAR val
= decode_pct_val(ptr
);
2857 if(is_unreserved(val
)) {
2859 uri
->canon_uri
[uri
->canon_len
] = val
;
2866 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2869 } else if(*ptr
== '/' && is_file
&& (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2871 uri
->canon_uri
[uri
->canon_len
] = '\\';
2873 } else if(*ptr
== '\\' && is_file
) {
2874 if(!(flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2875 /* Convert to a '/'. */
2877 uri
->canon_uri
[uri
->canon_len
] = '/';
2880 /* Just copy it over. */
2882 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2885 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
) &&
2886 !(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
)) {
2887 if(is_file
&& (flags
& Uri_CREATE_FILE_USE_DOS_PATH
)) {
2888 /* Forbidden characters aren't percent encoded for file schemes
2889 * with USE_DOS_PATH set.
2892 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2896 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2897 uri
->canon_len
+= 3;
2901 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2906 uri
->path_len
= uri
->canon_len
- uri
->path_start
;
2908 TRACE("(%p %p %x %d): Canonicalized opaque URI path %s len=%d\n", data
, uri
, flags
, computeOnly
,
2909 debugstr_wn(uri
->canon_uri
+uri
->path_start
, uri
->path_len
), uri
->path_len
);
2913 /* Determines how the URI represented by the parse_data should be canonicalized.
2915 * Essentially, if the parse_data represents an hierarchical URI then it calls
2916 * canonicalize_authority and the canonicalization functions for the path. If the
2917 * URI is opaque it canonicalizes the path of the URI.
2919 static BOOL
canonicalize_hierpart(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2920 uri
->display_absolute
= TRUE
;
2922 if(!data
->is_opaque
) {
2923 /* "//" is only added for non-wildcard scheme types. */
2924 if(data
->scheme_type
!= URL_SCHEME_WILDCARD
) {
2926 INT pos
= uri
->canon_len
;
2928 uri
->canon_uri
[pos
] = '/';
2929 uri
->canon_uri
[pos
+1] = '/';
2931 uri
->canon_len
+= 2;
2934 if(!canonicalize_authority(data
, uri
, flags
, computeOnly
))
2937 /* TODO: Canonicalize the path of the URI. */
2938 if(!canonicalize_path_hierarchical(data
, uri
, flags
, computeOnly
))
2942 /* Opaque URI's don't have an authority. */
2943 uri
->userinfo_start
= uri
->userinfo_split
= -1;
2944 uri
->userinfo_len
= 0;
2945 uri
->host_start
= -1;
2947 uri
->host_type
= Uri_HOST_UNKNOWN
;
2948 uri
->has_port
= FALSE
;
2949 uri
->authority_start
= -1;
2950 uri
->authority_len
= 0;
2951 uri
->domain_offset
= -1;
2953 if(is_hierarchical_scheme(data
->scheme_type
)) {
2956 /* Absolute URIs aren't displayed for known scheme types
2957 * which should be hierarchical URIs.
2959 uri
->display_absolute
= FALSE
;
2961 /* Windows also sets the port for these (if they have one). */
2962 for(i
= 0; i
< sizeof(default_ports
)/sizeof(default_ports
[0]); ++i
) {
2963 if(data
->scheme_type
== default_ports
[i
].scheme
) {
2964 uri
->has_port
= TRUE
;
2965 uri
->port
= default_ports
[i
].port
;
2971 if(!canonicalize_path_opaque(data
, uri
, flags
, computeOnly
))
2975 if(uri
->path_start
> -1 && !computeOnly
)
2976 /* Finding file extensions happens for both types of URIs. */
2977 uri
->extension_offset
= find_file_extension(uri
->canon_uri
+uri
->path_start
, uri
->path_len
);
2979 uri
->extension_offset
= -1;
2984 /* Attempts to canonicalize the query string of the URI.
2986 * Things that happen:
2987 * 1) For known scheme types forbidden characters
2988 * are percent encoded, unless the NO_DECODE_EXTRA_INFO flag is set
2989 * or NO_ENCODE_FORBIDDEN_CHARACTERS is set.
2991 * 2) For known scheme types, percent encoded, unreserved characters
2992 * are decoded as long as the NO_DECODE_EXTRA_INFO flag isn't set.
2994 static BOOL
canonicalize_query(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2995 const WCHAR
*ptr
, *end
;
2996 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2999 uri
->query_start
= -1;
3004 uri
->query_start
= uri
->canon_len
;
3006 end
= data
->query
+data
->query_len
;
3007 for(ptr
= data
->query
; ptr
< end
; ++ptr
) {
3009 if(known_scheme
&& !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
3010 WCHAR val
= decode_pct_val(ptr
);
3011 if(is_unreserved(val
)) {
3013 uri
->canon_uri
[uri
->canon_len
] = val
;
3020 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
)) {
3021 if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) &&
3022 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
3024 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
3025 uri
->canon_len
+= 3;
3031 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
3035 uri
->query_len
= uri
->canon_len
- uri
->query_start
;
3038 TRACE("(%p %p %x %d): Canonicalized query string %s len=%d\n", data
, uri
, flags
,
3039 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->query_start
, uri
->query_len
),
3044 static BOOL
canonicalize_fragment(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
3045 const WCHAR
*ptr
, *end
;
3046 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
3048 if(!data
->fragment
) {
3049 uri
->fragment_start
= -1;
3050 uri
->fragment_len
= 0;
3054 uri
->fragment_start
= uri
->canon_len
;
3056 end
= data
->fragment
+ data
->fragment_len
;
3057 for(ptr
= data
->fragment
; ptr
< end
; ++ptr
) {
3059 if(known_scheme
&& !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
3060 WCHAR val
= decode_pct_val(ptr
);
3061 if(is_unreserved(val
)) {
3063 uri
->canon_uri
[uri
->canon_len
] = val
;
3070 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
)) {
3071 if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) &&
3072 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
3074 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
3075 uri
->canon_len
+= 3;
3081 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
3085 uri
->fragment_len
= uri
->canon_len
- uri
->fragment_start
;
3088 TRACE("(%p %p %x %d): Canonicalized fragment %s len=%d\n", data
, uri
, flags
,
3089 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->fragment_start
, uri
->fragment_len
),
3094 /* Canonicalizes the scheme information specified in the parse_data using the specified flags. */
3095 static BOOL
canonicalize_scheme(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
3096 uri
->scheme_start
= -1;
3097 uri
->scheme_len
= 0;
3100 /* The only type of URI that doesn't have to have a scheme is a relative
3103 if(!data
->is_relative
) {
3104 FIXME("(%p %p %x): Unable to determine the scheme type of %s.\n", data
,
3105 uri
, flags
, debugstr_w(data
->uri
));
3111 INT pos
= uri
->canon_len
;
3113 for(i
= 0; i
< data
->scheme_len
; ++i
) {
3114 /* Scheme name must be lower case after canonicalization. */
3115 uri
->canon_uri
[i
+ pos
] = tolowerW(data
->scheme
[i
]);
3118 uri
->canon_uri
[i
+ pos
] = ':';
3119 uri
->scheme_start
= pos
;
3121 TRACE("(%p %p %x): Canonicalized scheme=%s, len=%d.\n", data
, uri
, flags
,
3122 debugstr_wn(uri
->canon_uri
, uri
->scheme_len
), data
->scheme_len
);
3125 /* This happens in both computation modes. */
3126 uri
->canon_len
+= data
->scheme_len
+ 1;
3127 uri
->scheme_len
= data
->scheme_len
;
3132 /* Compute's what the length of the URI specified by the parse_data will be
3133 * after canonicalization occurs using the specified flags.
3135 * This function will return a non-zero value indicating the length of the canonicalized
3136 * URI, or -1 on error.
3138 static int compute_canonicalized_length(const parse_data
*data
, DWORD flags
) {
3141 memset(&uri
, 0, sizeof(Uri
));
3143 TRACE("(%p %x): Beginning to compute canonicalized length for URI %s\n", data
, flags
,
3144 debugstr_w(data
->uri
));
3146 if(!canonicalize_scheme(data
, &uri
, flags
, TRUE
)) {
3147 ERR("(%p %x): Failed to compute URI scheme length.\n", data
, flags
);
3151 if(!canonicalize_hierpart(data
, &uri
, flags
, TRUE
)) {
3152 ERR("(%p %x): Failed to compute URI hierpart length.\n", data
, flags
);
3156 if(!canonicalize_query(data
, &uri
, flags
, TRUE
)) {
3157 ERR("(%p %x): Failed to compute query string length.\n", data
, flags
);
3161 if(!canonicalize_fragment(data
, &uri
, flags
, TRUE
)) {
3162 ERR("(%p %x): Failed to compute fragment length.\n", data
, flags
);
3166 TRACE("(%p %x): Finished computing canonicalized URI length. length=%d\n", data
, flags
, uri
.canon_len
);
3168 return uri
.canon_len
;
3171 /* Canonicalizes the URI data specified in the parse_data, using the given flags. If the
3172 * canonicalization succeededs it will store all the canonicalization information
3173 * in the pointer to the Uri.
3175 * To canonicalize a URI this function first computes what the length of the URI
3176 * specified by the parse_data will be. Once this is done it will then perfom the actual
3177 * canonicalization of the URI.
3179 static HRESULT
canonicalize_uri(const parse_data
*data
, Uri
*uri
, DWORD flags
) {
3182 uri
->canon_uri
= NULL
;
3183 len
= uri
->canon_size
= uri
->canon_len
= 0;
3185 TRACE("(%p %p %x): beginning to canonicalize URI %s.\n", data
, uri
, flags
, debugstr_w(data
->uri
));
3187 /* First try to compute the length of the URI. */
3188 len
= compute_canonicalized_length(data
, flags
);
3190 ERR("(%p %p %x): Could not compute the canonicalized length of %s.\n", data
, uri
, flags
,
3191 debugstr_w(data
->uri
));
3192 return E_INVALIDARG
;
3195 uri
->canon_uri
= heap_alloc((len
+1)*sizeof(WCHAR
));
3197 return E_OUTOFMEMORY
;
3199 uri
->canon_size
= len
;
3200 if(!canonicalize_scheme(data
, uri
, flags
, FALSE
)) {
3201 ERR("(%p %p %x): Unable to canonicalize the scheme of the URI.\n", data
, uri
, flags
);
3202 heap_free(uri
->canon_uri
);
3203 return E_INVALIDARG
;
3205 uri
->scheme_type
= data
->scheme_type
;
3207 if(!canonicalize_hierpart(data
, uri
, flags
, FALSE
)) {
3208 ERR("(%p %p %x): Unable to canonicalize the heirpart of the URI\n", data
, uri
, flags
);
3209 heap_free(uri
->canon_uri
);
3210 return E_INVALIDARG
;
3213 if(!canonicalize_query(data
, uri
, flags
, FALSE
)) {
3214 ERR("(%p %p %x): Unable to canonicalize query string of the URI.\n",
3216 return E_INVALIDARG
;
3219 if(!canonicalize_fragment(data
, uri
, flags
, FALSE
)) {
3220 ERR("(%p %p %x): Unable to canonicalize fragment of the URI.\n",
3222 return E_INVALIDARG
;
3225 /* There's a possibility we didn't use all the space we allocated
3228 if(uri
->canon_len
< uri
->canon_size
) {
3229 /* This happens if the URI is hierarchical and dot
3230 * segments were removed from it's path.
3232 WCHAR
*tmp
= heap_realloc(uri
->canon_uri
, (uri
->canon_len
+1)*sizeof(WCHAR
));
3234 return E_OUTOFMEMORY
;
3236 uri
->canon_uri
= tmp
;
3237 uri
->canon_size
= uri
->canon_len
;
3240 uri
->canon_uri
[uri
->canon_len
] = '\0';
3241 TRACE("(%p %p %x): finished canonicalizing the URI. uri=%s\n", data
, uri
, flags
, debugstr_w(uri
->canon_uri
));
3246 #define URI(x) ((IUri*) &(x)->lpIUriVtbl)
3247 #define URIBUILDER(x) ((IUriBuilder*) &(x)->lpIUriBuilderVtbl)
3249 #define URI_THIS(iface) DEFINE_THIS(Uri, IUri, iface)
3251 static HRESULT WINAPI
Uri_QueryInterface(IUri
*iface
, REFIID riid
, void **ppv
)
3253 Uri
*This
= URI_THIS(iface
);
3255 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
3256 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
3258 }else if(IsEqualGUID(&IID_IUri
, riid
)) {
3259 TRACE("(%p)->(IID_IUri %p)\n", This
, ppv
);
3261 }else if(IsEqualGUID(&IID_IUriObj
, riid
)) {
3262 TRACE("(%p)->(IID_IUriObj %p)\n", This
, ppv
);
3266 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
3268 return E_NOINTERFACE
;
3271 IUnknown_AddRef((IUnknown
*)*ppv
);
3275 static ULONG WINAPI
Uri_AddRef(IUri
*iface
)
3277 Uri
*This
= URI_THIS(iface
);
3278 LONG ref
= InterlockedIncrement(&This
->ref
);
3280 TRACE("(%p) ref=%d\n", This
, ref
);
3285 static ULONG WINAPI
Uri_Release(IUri
*iface
)
3287 Uri
*This
= URI_THIS(iface
);
3288 LONG ref
= InterlockedDecrement(&This
->ref
);
3290 TRACE("(%p) ref=%d\n", This
, ref
);
3293 SysFreeString(This
->raw_uri
);
3294 heap_free(This
->canon_uri
);
3301 static HRESULT WINAPI
Uri_GetPropertyBSTR(IUri
*iface
, Uri_PROPERTY uriProp
, BSTR
*pbstrProperty
, DWORD dwFlags
)
3303 Uri
*This
= URI_THIS(iface
);
3305 TRACE("(%p)->(%d %p %x)\n", This
, uriProp
, pbstrProperty
, dwFlags
);
3310 if(uriProp
> Uri_PROPERTY_STRING_LAST
) {
3311 /* Windows allocates an empty BSTR for invalid Uri_PROPERTY's. */
3312 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3313 if(!(*pbstrProperty
))
3314 return E_OUTOFMEMORY
;
3316 /* It only returns S_FALSE for the ZONE property... */
3317 if(uriProp
== Uri_PROPERTY_ZONE
)
3323 /* Don't have support for flags yet. */
3325 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pbstrProperty
, dwFlags
);
3330 case Uri_PROPERTY_ABSOLUTE_URI
:
3331 if(!This
->display_absolute
) {
3332 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3335 *pbstrProperty
= SysAllocString(This
->canon_uri
);
3339 if(!(*pbstrProperty
))
3340 hres
= E_OUTOFMEMORY
;
3343 case Uri_PROPERTY_AUTHORITY
:
3344 if(This
->authority_start
> -1) {
3345 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->authority_start
, This
->authority_len
);
3348 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3352 if(!(*pbstrProperty
))
3353 hres
= E_OUTOFMEMORY
;
3356 case Uri_PROPERTY_DISPLAY_URI
:
3357 /* The Display URI contains everything except for the userinfo for known
3360 if(This
->scheme_type
!= URL_SCHEME_UNKNOWN
&& This
->userinfo_start
> -1) {
3361 *pbstrProperty
= SysAllocStringLen(NULL
, This
->canon_len
-This
->userinfo_len
);
3363 if(*pbstrProperty
) {
3364 /* Copy everything before the userinfo over. */
3365 memcpy(*pbstrProperty
, This
->canon_uri
, This
->userinfo_start
*sizeof(WCHAR
));
3366 /* Copy everything after the userinfo over. */
3367 memcpy(*pbstrProperty
+This
->userinfo_start
,
3368 This
->canon_uri
+This
->userinfo_start
+This
->userinfo_len
+1,
3369 (This
->canon_len
-(This
->userinfo_start
+This
->userinfo_len
+1))*sizeof(WCHAR
));
3372 *pbstrProperty
= SysAllocString(This
->canon_uri
);
3374 if(!(*pbstrProperty
))
3375 hres
= E_OUTOFMEMORY
;
3380 case Uri_PROPERTY_DOMAIN
:
3381 if(This
->domain_offset
> -1) {
3382 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->host_start
+This
->domain_offset
,
3383 This
->host_len
-This
->domain_offset
);
3386 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3390 if(!(*pbstrProperty
))
3391 hres
= E_OUTOFMEMORY
;
3394 case Uri_PROPERTY_EXTENSION
:
3395 if(This
->extension_offset
> -1) {
3396 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->path_start
+This
->extension_offset
,
3397 This
->path_len
-This
->extension_offset
);
3400 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3404 if(!(*pbstrProperty
))
3405 hres
= E_OUTOFMEMORY
;
3408 case Uri_PROPERTY_FRAGMENT
:
3409 if(This
->fragment_start
> -1) {
3410 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->fragment_start
, This
->fragment_len
);
3413 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3417 if(!(*pbstrProperty
))
3418 hres
= E_OUTOFMEMORY
;
3421 case Uri_PROPERTY_HOST
:
3422 if(This
->host_start
> -1) {
3423 /* The '[' and ']' aren't included for IPv6 addresses. */
3424 if(This
->host_type
== Uri_HOST_IPV6
)
3425 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->host_start
+1, This
->host_len
-2);
3427 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->host_start
, This
->host_len
);
3431 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3435 if(!(*pbstrProperty
))
3436 hres
= E_OUTOFMEMORY
;
3439 case Uri_PROPERTY_PASSWORD
:
3440 if(This
->userinfo_split
> -1) {
3441 *pbstrProperty
= SysAllocStringLen(
3442 This
->canon_uri
+This
->userinfo_start
+This
->userinfo_split
+1,
3443 This
->userinfo_len
-This
->userinfo_split
-1);
3446 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3450 if(!(*pbstrProperty
))
3451 return E_OUTOFMEMORY
;
3454 case Uri_PROPERTY_PATH
:
3455 if(This
->path_start
> -1) {
3456 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->path_start
, This
->path_len
);
3459 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3463 if(!(*pbstrProperty
))
3464 hres
= E_OUTOFMEMORY
;
3467 case Uri_PROPERTY_PATH_AND_QUERY
:
3468 if(This
->path_start
> -1) {
3469 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->path_start
, This
->path_len
+This
->query_len
);
3471 } else if(This
->query_start
> -1) {
3472 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->query_start
, This
->query_len
);
3475 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3479 if(!(*pbstrProperty
))
3480 hres
= E_OUTOFMEMORY
;
3483 case Uri_PROPERTY_QUERY
:
3484 if(This
->query_start
> -1) {
3485 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->query_start
, This
->query_len
);
3488 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3492 if(!(*pbstrProperty
))
3493 hres
= E_OUTOFMEMORY
;
3496 case Uri_PROPERTY_RAW_URI
:
3497 *pbstrProperty
= SysAllocString(This
->raw_uri
);
3498 if(!(*pbstrProperty
))
3499 hres
= E_OUTOFMEMORY
;
3503 case Uri_PROPERTY_SCHEME_NAME
:
3504 if(This
->scheme_start
> -1) {
3505 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+ This
->scheme_start
, This
->scheme_len
);
3508 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3512 if(!(*pbstrProperty
))
3513 hres
= E_OUTOFMEMORY
;
3516 case Uri_PROPERTY_USER_INFO
:
3517 if(This
->userinfo_start
> -1) {
3518 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->userinfo_start
, This
->userinfo_len
);
3521 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3525 if(!(*pbstrProperty
))
3526 hres
= E_OUTOFMEMORY
;
3529 case Uri_PROPERTY_USER_NAME
:
3530 if(This
->userinfo_start
> -1) {
3531 /* If userinfo_split is set, that means a password exists
3532 * so the username is only from userinfo_start to userinfo_split.
3534 if(This
->userinfo_split
> -1) {
3535 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+ This
->userinfo_start
, This
->userinfo_split
);
3538 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+ This
->userinfo_start
, This
->userinfo_len
);
3542 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3546 if(!(*pbstrProperty
))
3547 return E_OUTOFMEMORY
;
3551 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pbstrProperty
, dwFlags
);
3558 static HRESULT WINAPI
Uri_GetPropertyLength(IUri
*iface
, Uri_PROPERTY uriProp
, DWORD
*pcchProperty
, DWORD dwFlags
)
3560 Uri
*This
= URI_THIS(iface
);
3562 TRACE("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3565 return E_INVALIDARG
;
3567 /* Can only return a length for a property if it's a string. */
3568 if(uriProp
> Uri_PROPERTY_STRING_LAST
)
3569 return E_INVALIDARG
;
3571 /* Don't have support for flags yet. */
3573 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3578 case Uri_PROPERTY_ABSOLUTE_URI
:
3579 if(!This
->display_absolute
) {
3583 *pcchProperty
= This
->canon_len
;
3588 case Uri_PROPERTY_AUTHORITY
:
3589 *pcchProperty
= This
->authority_len
;
3590 hres
= (This
->authority_start
> -1) ? S_OK
: S_FALSE
;
3592 case Uri_PROPERTY_DISPLAY_URI
:
3593 if(This
->scheme_type
!= URL_SCHEME_UNKNOWN
&& This
->userinfo_start
> -1)
3594 *pcchProperty
= This
->canon_len
-This
->userinfo_len
-1;
3596 *pcchProperty
= This
->canon_len
;
3600 case Uri_PROPERTY_DOMAIN
:
3601 if(This
->domain_offset
> -1)
3602 *pcchProperty
= This
->host_len
- This
->domain_offset
;
3606 hres
= (This
->domain_offset
> -1) ? S_OK
: S_FALSE
;
3608 case Uri_PROPERTY_EXTENSION
:
3609 if(This
->extension_offset
> -1) {
3610 *pcchProperty
= This
->path_len
- This
->extension_offset
;
3618 case Uri_PROPERTY_FRAGMENT
:
3619 *pcchProperty
= This
->fragment_len
;
3620 hres
= (This
->fragment_start
> -1) ? S_OK
: S_FALSE
;
3622 case Uri_PROPERTY_HOST
:
3623 *pcchProperty
= This
->host_len
;
3625 /* '[' and ']' aren't included in the length. */
3626 if(This
->host_type
== Uri_HOST_IPV6
)
3629 hres
= (This
->host_start
> -1) ? S_OK
: S_FALSE
;
3631 case Uri_PROPERTY_PASSWORD
:
3632 *pcchProperty
= (This
->userinfo_split
> -1) ? This
->userinfo_len
-This
->userinfo_split
-1 : 0;
3633 hres
= (This
->userinfo_split
> -1) ? S_OK
: S_FALSE
;
3635 case Uri_PROPERTY_PATH
:
3636 *pcchProperty
= This
->path_len
;
3637 hres
= (This
->path_start
> -1) ? S_OK
: S_FALSE
;
3639 case Uri_PROPERTY_PATH_AND_QUERY
:
3640 *pcchProperty
= This
->path_len
+This
->query_len
;
3641 hres
= (This
->path_start
> -1 || This
->query_start
> -1) ? S_OK
: S_FALSE
;
3643 case Uri_PROPERTY_QUERY
:
3644 *pcchProperty
= This
->query_len
;
3645 hres
= (This
->query_start
> -1) ? S_OK
: S_FALSE
;
3647 case Uri_PROPERTY_RAW_URI
:
3648 *pcchProperty
= SysStringLen(This
->raw_uri
);
3651 case Uri_PROPERTY_SCHEME_NAME
:
3652 *pcchProperty
= This
->scheme_len
;
3653 hres
= (This
->scheme_start
> -1) ? S_OK
: S_FALSE
;
3655 case Uri_PROPERTY_USER_INFO
:
3656 *pcchProperty
= This
->userinfo_len
;
3657 hres
= (This
->userinfo_start
> -1) ? S_OK
: S_FALSE
;
3659 case Uri_PROPERTY_USER_NAME
:
3660 *pcchProperty
= (This
->userinfo_split
> -1) ? This
->userinfo_split
: This
->userinfo_len
;
3661 hres
= (This
->userinfo_start
> -1) ? S_OK
: S_FALSE
;
3664 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3671 static HRESULT WINAPI
Uri_GetPropertyDWORD(IUri
*iface
, Uri_PROPERTY uriProp
, DWORD
*pcchProperty
, DWORD dwFlags
)
3673 Uri
*This
= URI_THIS(iface
);
3676 TRACE("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3679 return E_INVALIDARG
;
3681 /* Microsoft's implementation for the ZONE property of a URI seems to be lacking...
3682 * From what I can tell, instead of checking which URLZONE the URI belongs to it
3683 * simply assigns URLZONE_INVALID and returns E_NOTIMPL. This also applies to the GetZone
3686 if(uriProp
== Uri_PROPERTY_ZONE
) {
3687 *pcchProperty
= URLZONE_INVALID
;
3691 if(uriProp
< Uri_PROPERTY_DWORD_START
) {
3693 return E_INVALIDARG
;
3697 case Uri_PROPERTY_HOST_TYPE
:
3698 *pcchProperty
= This
->host_type
;
3701 case Uri_PROPERTY_PORT
:
3702 if(!This
->has_port
) {
3706 *pcchProperty
= This
->port
;
3711 case Uri_PROPERTY_SCHEME
:
3712 *pcchProperty
= This
->scheme_type
;
3716 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3723 static HRESULT WINAPI
Uri_HasProperty(IUri
*iface
, Uri_PROPERTY uriProp
, BOOL
*pfHasProperty
)
3725 Uri
*This
= URI_THIS(iface
);
3726 TRACE("(%p)->(%d %p)\n", This
, uriProp
, pfHasProperty
);
3729 return E_INVALIDARG
;
3732 case Uri_PROPERTY_ABSOLUTE_URI
:
3733 *pfHasProperty
= This
->display_absolute
;
3735 case Uri_PROPERTY_AUTHORITY
:
3736 *pfHasProperty
= This
->authority_start
> -1;
3738 case Uri_PROPERTY_DISPLAY_URI
:
3739 *pfHasProperty
= TRUE
;
3741 case Uri_PROPERTY_DOMAIN
:
3742 *pfHasProperty
= This
->domain_offset
> -1;
3744 case Uri_PROPERTY_EXTENSION
:
3745 *pfHasProperty
= This
->extension_offset
> -1;
3747 case Uri_PROPERTY_FRAGMENT
:
3748 *pfHasProperty
= This
->fragment_start
> -1;
3750 case Uri_PROPERTY_HOST
:
3751 *pfHasProperty
= This
->host_start
> -1;
3753 case Uri_PROPERTY_PASSWORD
:
3754 *pfHasProperty
= This
->userinfo_split
> -1;
3756 case Uri_PROPERTY_PATH
:
3757 *pfHasProperty
= This
->path_start
> -1;
3759 case Uri_PROPERTY_PATH_AND_QUERY
:
3760 *pfHasProperty
= (This
->path_start
> -1 || This
->query_start
> -1);
3762 case Uri_PROPERTY_QUERY
:
3763 *pfHasProperty
= This
->query_start
> -1;
3765 case Uri_PROPERTY_RAW_URI
:
3766 *pfHasProperty
= TRUE
;
3768 case Uri_PROPERTY_SCHEME_NAME
:
3769 *pfHasProperty
= This
->scheme_start
> -1;
3771 case Uri_PROPERTY_USER_INFO
:
3772 case Uri_PROPERTY_USER_NAME
:
3773 *pfHasProperty
= This
->userinfo_start
> -1;
3775 case Uri_PROPERTY_HOST_TYPE
:
3776 *pfHasProperty
= TRUE
;
3778 case Uri_PROPERTY_PORT
:
3779 *pfHasProperty
= This
->has_port
;
3781 case Uri_PROPERTY_SCHEME
:
3782 *pfHasProperty
= TRUE
;
3784 case Uri_PROPERTY_ZONE
:
3785 *pfHasProperty
= FALSE
;
3788 FIXME("(%p)->(%d %p): Unsupported property type.\n", This
, uriProp
, pfHasProperty
);
3795 static HRESULT WINAPI
Uri_GetAbsoluteUri(IUri
*iface
, BSTR
*pstrAbsoluteUri
)
3797 TRACE("(%p)->(%p)\n", iface
, pstrAbsoluteUri
);
3798 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_ABSOLUTE_URI
, pstrAbsoluteUri
, 0);
3801 static HRESULT WINAPI
Uri_GetAuthority(IUri
*iface
, BSTR
*pstrAuthority
)
3803 TRACE("(%p)->(%p)\n", iface
, pstrAuthority
);
3804 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_AUTHORITY
, pstrAuthority
, 0);
3807 static HRESULT WINAPI
Uri_GetDisplayUri(IUri
*iface
, BSTR
*pstrDisplayUri
)
3809 TRACE("(%p)->(%p)\n", iface
, pstrDisplayUri
);
3810 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_DISPLAY_URI
, pstrDisplayUri
, 0);
3813 static HRESULT WINAPI
Uri_GetDomain(IUri
*iface
, BSTR
*pstrDomain
)
3815 TRACE("(%p)->(%p)\n", iface
, pstrDomain
);
3816 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_DOMAIN
, pstrDomain
, 0);
3819 static HRESULT WINAPI
Uri_GetExtension(IUri
*iface
, BSTR
*pstrExtension
)
3821 TRACE("(%p)->(%p)\n", iface
, pstrExtension
);
3822 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_EXTENSION
, pstrExtension
, 0);
3825 static HRESULT WINAPI
Uri_GetFragment(IUri
*iface
, BSTR
*pstrFragment
)
3827 TRACE("(%p)->(%p)\n", iface
, pstrFragment
);
3828 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_FRAGMENT
, pstrFragment
, 0);
3831 static HRESULT WINAPI
Uri_GetHost(IUri
*iface
, BSTR
*pstrHost
)
3833 TRACE("(%p)->(%p)\n", iface
, pstrHost
);
3834 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_HOST
, pstrHost
, 0);
3837 static HRESULT WINAPI
Uri_GetPassword(IUri
*iface
, BSTR
*pstrPassword
)
3839 TRACE("(%p)->(%p)\n", iface
, pstrPassword
);
3840 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_PASSWORD
, pstrPassword
, 0);
3843 static HRESULT WINAPI
Uri_GetPath(IUri
*iface
, BSTR
*pstrPath
)
3845 TRACE("(%p)->(%p)\n", iface
, pstrPath
);
3846 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_PATH
, pstrPath
, 0);
3849 static HRESULT WINAPI
Uri_GetPathAndQuery(IUri
*iface
, BSTR
*pstrPathAndQuery
)
3851 TRACE("(%p)->(%p)\n", iface
, pstrPathAndQuery
);
3852 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_PATH_AND_QUERY
, pstrPathAndQuery
, 0);
3855 static HRESULT WINAPI
Uri_GetQuery(IUri
*iface
, BSTR
*pstrQuery
)
3857 TRACE("(%p)->(%p)\n", iface
, pstrQuery
);
3858 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_QUERY
, pstrQuery
, 0);
3861 static HRESULT WINAPI
Uri_GetRawUri(IUri
*iface
, BSTR
*pstrRawUri
)
3863 Uri
*This
= URI_THIS(iface
);
3864 TRACE("(%p)->(%p)\n", This
, pstrRawUri
);
3866 /* Just forward the call to GetPropertyBSTR. */
3867 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_RAW_URI
, pstrRawUri
, 0);
3870 static HRESULT WINAPI
Uri_GetSchemeName(IUri
*iface
, BSTR
*pstrSchemeName
)
3872 Uri
*This
= URI_THIS(iface
);
3873 TRACE("(%p)->(%p)\n", This
, pstrSchemeName
);
3874 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_SCHEME_NAME
, pstrSchemeName
, 0);
3877 static HRESULT WINAPI
Uri_GetUserInfo(IUri
*iface
, BSTR
*pstrUserInfo
)
3879 TRACE("(%p)->(%p)\n", iface
, pstrUserInfo
);
3880 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_USER_INFO
, pstrUserInfo
, 0);
3883 static HRESULT WINAPI
Uri_GetUserName(IUri
*iface
, BSTR
*pstrUserName
)
3885 TRACE("(%p)->(%p)\n", iface
, pstrUserName
);
3886 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_USER_NAME
, pstrUserName
, 0);
3889 static HRESULT WINAPI
Uri_GetHostType(IUri
*iface
, DWORD
*pdwHostType
)
3891 TRACE("(%p)->(%p)\n", iface
, pdwHostType
);
3892 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_HOST_TYPE
, pdwHostType
, 0);
3895 static HRESULT WINAPI
Uri_GetPort(IUri
*iface
, DWORD
*pdwPort
)
3897 TRACE("(%p)->(%p)\n", iface
, pdwPort
);
3898 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_PORT
, pdwPort
, 0);
3901 static HRESULT WINAPI
Uri_GetScheme(IUri
*iface
, DWORD
*pdwScheme
)
3903 Uri
*This
= URI_THIS(iface
);
3904 TRACE("(%p)->(%p)\n", This
, pdwScheme
);
3905 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_SCHEME
, pdwScheme
, 0);
3908 static HRESULT WINAPI
Uri_GetZone(IUri
*iface
, DWORD
*pdwZone
)
3910 TRACE("(%p)->(%p)\n", iface
, pdwZone
);
3911 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_ZONE
,pdwZone
, 0);
3914 static HRESULT WINAPI
Uri_GetProperties(IUri
*iface
, DWORD
*pdwProperties
)
3916 Uri
*This
= URI_THIS(iface
);
3917 TRACE("(%p)->(%p)\n", This
, pdwProperties
);
3920 return E_INVALIDARG
;
3922 /* All URIs have these. */
3923 *pdwProperties
= Uri_HAS_DISPLAY_URI
|Uri_HAS_RAW_URI
|Uri_HAS_SCHEME
|Uri_HAS_HOST_TYPE
;
3925 if(This
->display_absolute
)
3926 *pdwProperties
|= Uri_HAS_ABSOLUTE_URI
;
3928 if(This
->scheme_start
> -1)
3929 *pdwProperties
|= Uri_HAS_SCHEME_NAME
;
3931 if(This
->authority_start
> -1) {
3932 *pdwProperties
|= Uri_HAS_AUTHORITY
;
3933 if(This
->userinfo_start
> -1)
3934 *pdwProperties
|= Uri_HAS_USER_INFO
|Uri_HAS_USER_NAME
;
3935 if(This
->userinfo_split
> -1)
3936 *pdwProperties
|= Uri_HAS_PASSWORD
;
3937 if(This
->host_start
> -1)
3938 *pdwProperties
|= Uri_HAS_HOST
;
3939 if(This
->domain_offset
> -1)
3940 *pdwProperties
|= Uri_HAS_DOMAIN
;
3944 *pdwProperties
|= Uri_HAS_PORT
;
3945 if(This
->path_start
> -1)
3946 *pdwProperties
|= Uri_HAS_PATH
|Uri_HAS_PATH_AND_QUERY
;
3947 if(This
->query_start
> -1)
3948 *pdwProperties
|= Uri_HAS_QUERY
|Uri_HAS_PATH_AND_QUERY
;
3950 if(This
->extension_offset
> -1)
3951 *pdwProperties
|= Uri_HAS_EXTENSION
;
3953 if(This
->fragment_start
> -1)
3954 *pdwProperties
|= Uri_HAS_FRAGMENT
;
3959 static HRESULT WINAPI
Uri_IsEqual(IUri
*iface
, IUri
*pUri
, BOOL
*pfEqual
)
3961 Uri
*This
= URI_THIS(iface
);
3964 TRACE("(%p)->(%p %p)\n", This
, pUri
, pfEqual
);
3972 /* For some reason Windows returns S_OK here... */
3976 /* Try to convert it to a Uri (allows for a more simple comparison). */
3977 if((other
= get_uri_obj(pUri
)))
3978 *pfEqual
= are_equal_simple(This
, other
);
3980 /* Do it the hard way. */
3981 FIXME("(%p)->(%p %p) No support for unknown IUri's yet.\n", iface
, pUri
, pfEqual
);
3990 static const IUriVtbl UriVtbl
= {
3994 Uri_GetPropertyBSTR
,
3995 Uri_GetPropertyLength
,
3996 Uri_GetPropertyDWORD
,
4007 Uri_GetPathAndQuery
,
4021 /***********************************************************************
4022 * CreateUri (urlmon.@)
4024 * Creates a new IUri object using the URI represented by pwzURI. This function
4025 * parses and validates the components of pwzURI and then canonicalizes the
4026 * parsed components.
4029 * pwzURI [I] The URI to parse, validate, and canonicalize.
4030 * dwFlags [I] Flags which can affect how the parsing/canonicalization is performed.
4031 * dwReserved [I] Reserved (not used).
4032 * ppURI [O] The resulting IUri after parsing/canonicalization occurs.
4035 * Success: Returns S_OK. ppURI contains the pointer to the newly allocated IUri.
4036 * Failure: E_INVALIDARG if there's invalid flag combinations in dwFlags, or an
4037 * invalid parameters, or pwzURI doesn't represnt a valid URI.
4038 * E_OUTOFMEMORY if any memory allocation fails.
4042 * Uri_CREATE_CANONICALIZE, Uri_CREATE_DECODE_EXTRA_INFO, Uri_CREATE_CRACK_UNKNOWN_SCHEMES,
4043 * Uri_CREATE_PRE_PROCESS_HTML_URI, Uri_CREATE_NO_IE_SETTINGS.
4045 HRESULT WINAPI
CreateUri(LPCWSTR pwzURI
, DWORD dwFlags
, DWORD_PTR dwReserved
, IUri
**ppURI
)
4047 const DWORD supported_flags
= Uri_CREATE_ALLOW_RELATIVE
|Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
|
4048 Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
|Uri_CREATE_NO_CANONICALIZE
|Uri_CREATE_CANONICALIZE
|
4049 Uri_CREATE_DECODE_EXTRA_INFO
|Uri_CREATE_NO_DECODE_EXTRA_INFO
|Uri_CREATE_CRACK_UNKNOWN_SCHEMES
|
4050 Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES
|Uri_CREATE_PRE_PROCESS_HTML_URI
|Uri_CREATE_NO_PRE_PROCESS_HTML_URI
|
4051 Uri_CREATE_NO_IE_SETTINGS
|Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
|Uri_CREATE_FILE_USE_DOS_PATH
;
4056 TRACE("(%s %x %x %p)\n", debugstr_w(pwzURI
), dwFlags
, (DWORD
)dwReserved
, ppURI
);
4059 return E_INVALIDARG
;
4063 return E_INVALIDARG
;
4066 /* Check for invalid flags. */
4067 if((dwFlags
& Uri_CREATE_DECODE_EXTRA_INFO
&& dwFlags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
) ||
4068 (dwFlags
& Uri_CREATE_CANONICALIZE
&& dwFlags
& Uri_CREATE_NO_CANONICALIZE
) ||
4069 (dwFlags
& Uri_CREATE_CRACK_UNKNOWN_SCHEMES
&& dwFlags
& Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES
) ||
4070 (dwFlags
& Uri_CREATE_PRE_PROCESS_HTML_URI
&& dwFlags
& Uri_CREATE_NO_PRE_PROCESS_HTML_URI
) ||
4071 (dwFlags
& Uri_CREATE_IE_SETTINGS
&& dwFlags
& Uri_CREATE_NO_IE_SETTINGS
)) {
4073 return E_INVALIDARG
;
4076 /* Currently unsupported. */
4077 if(dwFlags
& ~supported_flags
)
4078 FIXME("Ignoring unsupported flag(s) %x\n", dwFlags
& ~supported_flags
);
4080 ret
= heap_alloc(sizeof(Uri
));
4082 return E_OUTOFMEMORY
;
4084 ret
->lpIUriVtbl
= &UriVtbl
;
4087 /* Pre process the URI, unless told otherwise. */
4088 if(!(dwFlags
& Uri_CREATE_NO_PRE_PROCESS_HTML_URI
))
4089 ret
->raw_uri
= pre_process_uri(pwzURI
);
4091 ret
->raw_uri
= SysAllocString(pwzURI
);
4095 return E_OUTOFMEMORY
;
4098 memset(&data
, 0, sizeof(parse_data
));
4099 data
.uri
= ret
->raw_uri
;
4101 /* Validate and parse the URI into it's components. */
4102 if(!parse_uri(&data
, dwFlags
)) {
4103 /* Encountered an unsupported or invalid URI */
4104 SysFreeString(ret
->raw_uri
);
4107 return E_INVALIDARG
;
4110 /* Canonicalize the URI. */
4111 hr
= canonicalize_uri(&data
, ret
, dwFlags
);
4113 SysFreeString(ret
->raw_uri
);
4123 /***********************************************************************
4124 * CreateUriWithFragment (urlmon.@)
4126 * Creates a new IUri object. This is almost the same as CreateUri, expect that
4127 * it allows you to explicitly specify a fragment (pwzFragment) for pwzURI.
4130 * pwzURI [I] The URI to parse and perform canonicalization on.
4131 * pwzFragment [I] The explict fragment string which should be added to pwzURI.
4132 * dwFlags [I] The flags which will be passed to CreateUri.
4133 * dwReserved [I] Reserved (not used).
4134 * ppURI [O] The resulting IUri after parsing/canonicalization.
4137 * Success: S_OK. ppURI contains the pointer to the newly allocated IUri.
4138 * Failure: E_INVALIDARG if pwzURI already contains a fragment and pwzFragment
4139 * isn't NULL. Will also return E_INVALIDARG for the same reasons as
4140 * CreateUri will. E_OUTOFMEMORY if any allocations fail.
4142 HRESULT WINAPI
CreateUriWithFragment(LPCWSTR pwzURI
, LPCWSTR pwzFragment
, DWORD dwFlags
,
4143 DWORD_PTR dwReserved
, IUri
**ppURI
)
4146 TRACE("(%s %s %x %x %p)\n", debugstr_w(pwzURI
), debugstr_w(pwzFragment
), dwFlags
, (DWORD
)dwReserved
, ppURI
);
4149 return E_INVALIDARG
;
4153 return E_INVALIDARG
;
4156 /* Check if a fragment should be appended to the URI string. */
4159 DWORD uri_len
, frag_len
;
4162 /* Check if the original URI already has a fragment component. */
4163 if(StrChrW(pwzURI
, '#')) {
4165 return E_INVALIDARG
;
4168 uri_len
= lstrlenW(pwzURI
);
4169 frag_len
= lstrlenW(pwzFragment
);
4171 /* If the fragment doesn't start with a '#', one will be added. */
4172 add_pound
= *pwzFragment
!= '#';
4175 uriW
= heap_alloc((uri_len
+frag_len
+2)*sizeof(WCHAR
));
4177 uriW
= heap_alloc((uri_len
+frag_len
+1)*sizeof(WCHAR
));
4180 return E_OUTOFMEMORY
;
4182 memcpy(uriW
, pwzURI
, uri_len
*sizeof(WCHAR
));
4184 uriW
[uri_len
++] = '#';
4185 memcpy(uriW
+uri_len
, pwzFragment
, (frag_len
+1)*sizeof(WCHAR
));
4187 hres
= CreateUri(uriW
, dwFlags
, 0, ppURI
);
4191 /* A fragment string wasn't specified, so just forward the call. */
4192 hres
= CreateUri(pwzURI
, dwFlags
, 0, ppURI
);
4197 #define URIBUILDER_THIS(iface) DEFINE_THIS(UriBuilder, IUriBuilder, iface)
4199 static HRESULT WINAPI
UriBuilder_QueryInterface(IUriBuilder
*iface
, REFIID riid
, void **ppv
)
4201 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4203 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
4204 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
4205 *ppv
= URIBUILDER(This
);
4206 }else if(IsEqualGUID(&IID_IUriBuilder
, riid
)) {
4207 TRACE("(%p)->(IID_IUri %p)\n", This
, ppv
);
4208 *ppv
= URIBUILDER(This
);
4210 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
4212 return E_NOINTERFACE
;
4215 IUnknown_AddRef((IUnknown
*)*ppv
);
4219 static ULONG WINAPI
UriBuilder_AddRef(IUriBuilder
*iface
)
4221 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4222 LONG ref
= InterlockedIncrement(&This
->ref
);
4224 TRACE("(%p) ref=%d\n", This
, ref
);
4229 static ULONG WINAPI
UriBuilder_Release(IUriBuilder
*iface
)
4231 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4232 LONG ref
= InterlockedDecrement(&This
->ref
);
4234 TRACE("(%p) ref=%d\n", This
, ref
);
4237 if(This
->uri
) IUri_Release(This
->uri
);
4244 static HRESULT WINAPI
UriBuilder_CreateUriSimple(IUriBuilder
*iface
,
4245 DWORD dwAllowEncodingPropertyMask
,
4246 DWORD_PTR dwReserved
,
4249 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4250 TRACE("(%p)->(%d %d %p)\n", This
, dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
4255 /* Acts the same way as CreateUri. */
4256 if(dwAllowEncodingPropertyMask
&& !This
->uri
) {
4263 return INET_E_INVALID_URL
;
4266 FIXME("(%p)->(%d %d %p)\n", This
, dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
4270 static HRESULT WINAPI
UriBuilder_CreateUri(IUriBuilder
*iface
,
4271 DWORD dwCreateFlags
,
4272 DWORD dwAllowEncodingPropertyMask
,
4273 DWORD_PTR dwReserved
,
4276 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4277 TRACE("(%p)->(0x%08x %d %d %p)\n", This
, dwCreateFlags
, dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
4282 /* The only time it doesn't return E_NOTIMPL when the dwAllow parameter
4283 * has flags set, is when the IUriBuilder has a IUri set and it hasn't
4284 * been modified (a call to a "Set*" hasn't been performed).
4286 * TODO: Check if the IUriBuilder's properties have been modified.
4288 if(dwAllowEncodingPropertyMask
&& !This
->uri
) {
4295 return INET_E_INVALID_URL
;
4298 FIXME("(%p)->(0x%08x %d %d %p)\n", This
, dwCreateFlags
, dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
4302 static HRESULT WINAPI
UriBuilder_CreateUriWithFlags(IUriBuilder
*iface
,
4303 DWORD dwCreateFlags
,
4304 DWORD dwUriBuilderFlags
,
4305 DWORD dwAllowEncodingPropertyMask
,
4306 DWORD_PTR dwReserved
,
4309 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4310 TRACE("(%p)->(0x%08x 0x%08x %d %d %p)\n", This
, dwCreateFlags
, dwUriBuilderFlags
,
4311 dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
4316 /* Same as CreateUri. */
4317 if(dwAllowEncodingPropertyMask
&& !This
->uri
) {
4324 return INET_E_INVALID_URL
;
4327 FIXME("(%p)->(0x%08x 0x%08x %d %d %p)\n", This
, dwCreateFlags
, dwUriBuilderFlags
,
4328 dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
4332 static HRESULT WINAPI
UriBuilder_GetIUri(IUriBuilder
*iface
, IUri
**ppIUri
)
4334 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4335 TRACE("(%p)->(%p)\n", This
, ppIUri
);
4340 FIXME("(%p)->(%p)\n", This
, ppIUri
);
4344 static HRESULT WINAPI
UriBuilder_SetIUri(IUriBuilder
*iface
, IUri
*pIUri
)
4346 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4347 FIXME("(%p)->(%p)\n", This
, pIUri
);
4351 static HRESULT WINAPI
UriBuilder_GetFragment(IUriBuilder
*iface
, DWORD
*pcchFragment
, LPCWSTR
*ppwzFragment
)
4353 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4354 TRACE("(%p)->(%p %p)\n", This
, pcchFragment
, ppwzFragment
);
4358 *ppwzFragment
= NULL
;
4367 FIXME("(%p)->(%p %p)\n", This
, pcchFragment
, ppwzFragment
);
4371 static HRESULT WINAPI
UriBuilder_GetHost(IUriBuilder
*iface
, DWORD
*pcchHost
, LPCWSTR
*ppwzHost
)
4373 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4374 TRACE("(%p)->(%p %p)\n", This
, pcchHost
, ppwzHost
);
4387 FIXME("(%p)->(%p %p)\n", This
, pcchHost
, ppwzHost
);
4391 static HRESULT WINAPI
UriBuilder_GetPassword(IUriBuilder
*iface
, DWORD
*pcchPassword
, LPCWSTR
*ppwzPassword
)
4393 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4394 TRACE("(%p)->(%p %p)\n", This
, pcchPassword
, ppwzPassword
);
4398 *ppwzPassword
= NULL
;
4407 FIXME("(%p)->(%p %p)\n", This
, pcchPassword
, ppwzPassword
);
4411 static HRESULT WINAPI
UriBuilder_GetPath(IUriBuilder
*iface
, DWORD
*pcchPath
, LPCWSTR
*ppwzPath
)
4413 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4414 TRACE("(%p)->(%p %p)\n", This
, pcchPath
, ppwzPath
);
4427 FIXME("(%p)->(%p %p)\n", This
, pcchPath
, ppwzPath
);
4431 static HRESULT WINAPI
UriBuilder_GetPort(IUriBuilder
*iface
, BOOL
*pfHasPort
, DWORD
*pdwPort
)
4433 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4434 TRACE("(%p)->(%p %p)\n", This
, pfHasPort
, pdwPort
);
4447 FIXME("(%p)->(%p %p)\n", This
, pfHasPort
, pdwPort
);
4451 static HRESULT WINAPI
UriBuilder_GetQuery(IUriBuilder
*iface
, DWORD
*pcchQuery
, LPCWSTR
*ppwzQuery
)
4453 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4454 TRACE("(%p)->(%p %p)\n", This
, pcchQuery
, ppwzQuery
);
4467 FIXME("(%p)->(%p %p)\n", This
, pcchQuery
, ppwzQuery
);
4471 static HRESULT WINAPI
UriBuilder_GetSchemeName(IUriBuilder
*iface
, DWORD
*pcchSchemeName
, LPCWSTR
*ppwzSchemeName
)
4473 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4474 TRACE("(%p)->(%p %p)\n", This
, pcchSchemeName
, ppwzSchemeName
);
4476 if(!pcchSchemeName
) {
4478 *ppwzSchemeName
= NULL
;
4482 if(!ppwzSchemeName
) {
4483 *pcchSchemeName
= 0;
4487 FIXME("(%p)->(%p %p)\n", This
, pcchSchemeName
, ppwzSchemeName
);
4491 static HRESULT WINAPI
UriBuilder_GetUserName(IUriBuilder
*iface
, DWORD
*pcchUserName
, LPCWSTR
*ppwzUserName
)
4493 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4494 TRACE("(%p)->(%p %p)\n", This
, pcchUserName
, ppwzUserName
);
4498 *ppwzUserName
= NULL
;
4507 FIXME("(%p)->(%p %p)\n", This
, pcchUserName
, ppwzUserName
);
4511 static HRESULT WINAPI
UriBuilder_SetFragment(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4513 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4514 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4518 static HRESULT WINAPI
UriBuilder_SetHost(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4520 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4521 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4525 static HRESULT WINAPI
UriBuilder_SetPassword(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4527 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4528 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4532 static HRESULT WINAPI
UriBuilder_SetPath(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4534 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4535 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4539 static HRESULT WINAPI
UriBuilder_SetPort(IUriBuilder
*iface
, BOOL fHasPort
, DWORD dwNewValue
)
4541 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4542 FIXME("(%p)->(%d %d)\n", This
, fHasPort
, dwNewValue
);
4546 static HRESULT WINAPI
UriBuilder_SetQuery(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4548 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4549 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4553 static HRESULT WINAPI
UriBuilder_SetSchemeName(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4555 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4556 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4560 static HRESULT WINAPI
UriBuilder_SetUserName(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
4562 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4563 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
4567 static HRESULT WINAPI
UriBuilder_RemoveProperties(IUriBuilder
*iface
, DWORD dwPropertyMask
)
4569 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4570 FIXME("(%p)->(0x%08x)\n", This
, dwPropertyMask
);
4574 static HRESULT WINAPI
UriBuilder_HasBeenModified(IUriBuilder
*iface
, BOOL
*pfModified
)
4576 UriBuilder
*This
= URIBUILDER_THIS(iface
);
4577 TRACE("(%p)->(%p)\n", This
, pfModified
);
4582 FIXME("(%p)->(%p)\n", This
, pfModified
);
4586 #undef URIBUILDER_THIS
4588 static const IUriBuilderVtbl UriBuilderVtbl
= {
4589 UriBuilder_QueryInterface
,
4592 UriBuilder_CreateUriSimple
,
4593 UriBuilder_CreateUri
,
4594 UriBuilder_CreateUriWithFlags
,
4597 UriBuilder_GetFragment
,
4599 UriBuilder_GetPassword
,
4602 UriBuilder_GetQuery
,
4603 UriBuilder_GetSchemeName
,
4604 UriBuilder_GetUserName
,
4605 UriBuilder_SetFragment
,
4607 UriBuilder_SetPassword
,
4610 UriBuilder_SetQuery
,
4611 UriBuilder_SetSchemeName
,
4612 UriBuilder_SetUserName
,
4613 UriBuilder_RemoveProperties
,
4614 UriBuilder_HasBeenModified
,
4617 /***********************************************************************
4618 * CreateIUriBuilder (urlmon.@)
4620 HRESULT WINAPI
CreateIUriBuilder(IUri
*pIUri
, DWORD dwFlags
, DWORD_PTR dwReserved
, IUriBuilder
**ppIUriBuilder
)
4624 TRACE("(%p %x %x %p)\n", pIUri
, dwFlags
, (DWORD
)dwReserved
, ppIUriBuilder
);
4629 ret
= heap_alloc(sizeof(UriBuilder
));
4631 return E_OUTOFMEMORY
;
4633 ret
->lpIUriBuilderVtbl
= &UriBuilderVtbl
;
4640 *ppIUriBuilder
= URIBUILDER(ret
);