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
);
32 const IUriVtbl
*lpIUriVtbl
;
37 /* Information about the canonicalized URI's buffer. */
44 URL_SCHEME scheme_type
;
52 Uri_HOST_TYPE host_type
;
74 const IUriBuilderVtbl
*lpIUriBuilderVtbl
;
84 /* IPv6 addresses can hold up to 8 h16 components. */
88 /* An IPv6 can have 1 elision ("::"). */
91 /* An IPv6 can contain 1 IPv4 address as the last 32bits of the address. */
104 BOOL has_implicit_scheme
;
105 BOOL has_implicit_ip
;
110 URL_SCHEME scheme_type
;
112 const WCHAR
*userinfo
;
118 Uri_HOST_TYPE host_type
;
121 ipv6_address ipv6_address
;
133 const WCHAR
*fragment
;
137 static const CHAR hexDigits
[] = "0123456789ABCDEF";
139 /* List of scheme types/scheme names that are recognized by the IUri interface as of IE 7. */
140 static const struct {
142 WCHAR scheme_name
[16];
143 } recognized_schemes
[] = {
144 {URL_SCHEME_FTP
, {'f','t','p',0}},
145 {URL_SCHEME_HTTP
, {'h','t','t','p',0}},
146 {URL_SCHEME_GOPHER
, {'g','o','p','h','e','r',0}},
147 {URL_SCHEME_MAILTO
, {'m','a','i','l','t','o',0}},
148 {URL_SCHEME_NEWS
, {'n','e','w','s',0}},
149 {URL_SCHEME_NNTP
, {'n','n','t','p',0}},
150 {URL_SCHEME_TELNET
, {'t','e','l','n','e','t',0}},
151 {URL_SCHEME_WAIS
, {'w','a','i','s',0}},
152 {URL_SCHEME_FILE
, {'f','i','l','e',0}},
153 {URL_SCHEME_MK
, {'m','k',0}},
154 {URL_SCHEME_HTTPS
, {'h','t','t','p','s',0}},
155 {URL_SCHEME_SHELL
, {'s','h','e','l','l',0}},
156 {URL_SCHEME_SNEWS
, {'s','n','e','w','s',0}},
157 {URL_SCHEME_LOCAL
, {'l','o','c','a','l',0}},
158 {URL_SCHEME_JAVASCRIPT
, {'j','a','v','a','s','c','r','i','p','t',0}},
159 {URL_SCHEME_VBSCRIPT
, {'v','b','s','c','r','i','p','t',0}},
160 {URL_SCHEME_ABOUT
, {'a','b','o','u','t',0}},
161 {URL_SCHEME_RES
, {'r','e','s',0}},
162 {URL_SCHEME_MSSHELLROOTED
, {'m','s','-','s','h','e','l','l','-','r','o','o','t','e','d',0}},
163 {URL_SCHEME_MSSHELLIDLIST
, {'m','s','-','s','h','e','l','l','-','i','d','l','i','s','t',0}},
164 {URL_SCHEME_MSHELP
, {'h','c','p',0}},
165 {URL_SCHEME_WILDCARD
, {'*',0}}
168 /* List of default ports Windows recognizes. */
169 static const struct {
172 } default_ports
[] = {
173 {URL_SCHEME_FTP
, 21},
174 {URL_SCHEME_HTTP
, 80},
175 {URL_SCHEME_GOPHER
, 70},
176 {URL_SCHEME_NNTP
, 119},
177 {URL_SCHEME_TELNET
, 23},
178 {URL_SCHEME_WAIS
, 210},
179 {URL_SCHEME_HTTPS
, 443},
182 /* List of 3 character top level domain names Windows seems to recognize.
183 * There might be more, but, these are the only ones I've found so far.
185 static const struct {
187 } recognized_tlds
[] = {
197 static inline BOOL
is_alpha(WCHAR val
) {
198 return ((val
>= 'a' && val
<= 'z') || (val
>= 'A' && val
<= 'Z'));
201 static inline BOOL
is_num(WCHAR val
) {
202 return (val
>= '0' && val
<= '9');
205 /* A URI is implicitly a file path if it begins with
206 * a drive letter (eg X:) or starts with "\\" (UNC path).
208 static inline BOOL
is_implicit_file_path(const WCHAR
*str
) {
209 if(is_alpha(str
[0]) && str
[1] == ':')
211 else if(str
[0] == '\\' && str
[1] == '\\')
217 /* Checks if the URI is a hierarchical URI. A hierarchical
218 * URI is one that has "//" after the scheme.
220 static BOOL
check_hierarchical(const WCHAR
**ptr
) {
221 const WCHAR
*start
= *ptr
;
236 /* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" */
237 static inline BOOL
is_unreserved(WCHAR val
) {
238 return (is_alpha(val
) || is_num(val
) || val
== '-' || val
== '.' ||
239 val
== '_' || val
== '~');
242 /* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
243 * / "*" / "+" / "," / ";" / "="
245 static inline BOOL
is_subdelim(WCHAR val
) {
246 return (val
== '!' || val
== '$' || val
== '&' ||
247 val
== '\'' || val
== '(' || val
== ')' ||
248 val
== '*' || val
== '+' || val
== ',' ||
249 val
== ';' || val
== '=');
252 /* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" */
253 static inline BOOL
is_gendelim(WCHAR val
) {
254 return (val
== ':' || val
== '/' || val
== '?' ||
255 val
== '#' || val
== '[' || val
== ']' ||
259 /* Characters that delimit the end of the authority
260 * section of a URI. Sometimes a '\\' is considered
261 * an authority delimeter.
263 static inline BOOL
is_auth_delim(WCHAR val
, BOOL acceptSlash
) {
264 return (val
== '#' || val
== '/' || val
== '?' ||
265 val
== '\0' || (acceptSlash
&& val
== '\\'));
268 /* reserved = gen-delims / sub-delims */
269 static inline BOOL
is_reserved(WCHAR val
) {
270 return (is_subdelim(val
) || is_gendelim(val
));
273 static inline BOOL
is_hexdigit(WCHAR val
) {
274 return ((val
>= 'a' && val
<= 'f') ||
275 (val
>= 'A' && val
<= 'F') ||
276 (val
>= '0' && val
<= '9'));
279 static inline BOOL
is_path_delim(WCHAR val
) {
280 return (!val
|| val
== '#' || val
== '?');
283 /* Computes the size of the given IPv6 address.
284 * Each h16 component is 16bits, if there is an IPv4 address, it's
285 * 32bits. If there's an elision it can be 16bits to 128bits, depending
286 * on the number of other components.
288 * Modeled after google-url's CheckIPv6ComponentsSize function
290 static void compute_ipv6_comps_size(ipv6_address
*address
) {
291 address
->components_size
= address
->h16_count
* 2;
294 /* IPv4 address is 4 bytes. */
295 address
->components_size
+= 4;
297 if(address
->elision
) {
298 /* An elision can be anywhere from 2 bytes up to 16 bytes.
299 * It size depends on the size of the h16 and IPv4 components.
301 address
->elision_size
= 16 - address
->components_size
;
302 if(address
->elision_size
< 2)
303 address
->elision_size
= 2;
305 address
->elision_size
= 0;
308 /* Taken from dlls/jscript/lex.c */
309 static int hex_to_int(WCHAR val
) {
310 if(val
>= '0' && val
<= '9')
312 else if(val
>= 'a' && val
<= 'f')
313 return val
- 'a' + 10;
314 else if(val
>= 'A' && val
<= 'F')
315 return val
- 'A' + 10;
320 /* Helper function for converting a percent encoded string
321 * representation of a WCHAR value into its actual WCHAR value. If
322 * the two characters following the '%' aren't valid hex values then
323 * this function returns the NULL character.
326 * "%2E" will result in '.' being returned by this function.
328 static WCHAR
decode_pct_val(const WCHAR
*ptr
) {
331 if(*ptr
== '%' && is_hexdigit(*(ptr
+ 1)) && is_hexdigit(*(ptr
+ 2))) {
332 INT a
= hex_to_int(*(ptr
+ 1));
333 INT b
= hex_to_int(*(ptr
+ 2));
342 /* Helper function for percent encoding a given character
343 * and storing the encoded value into a given buffer (dest).
345 * It's up to the calling function to ensure that there is
346 * at least enough space in 'dest' for the percent encoded
347 * value to be stored (so dest + 3 spaces available).
349 static inline void pct_encode_val(WCHAR val
, WCHAR
*dest
) {
351 dest
[1] = hexDigits
[(val
>> 4) & 0xf];
352 dest
[2] = hexDigits
[val
& 0xf];
355 /* Scans the range of characters [str, end] and returns the last occurence
356 * of 'ch' or returns NULL.
358 static const WCHAR
*str_last_of(const WCHAR
*str
, const WCHAR
*end
, WCHAR ch
) {
359 const WCHAR
*ptr
= end
;
370 /* Attempts to parse the domain name from the host.
372 * This function also includes the Top-level Domain (TLD) name
373 * of the host when it tries to find the domain name. If it finds
374 * a valid domain name it will assign 'domain_start' the offset
375 * into 'host' where the domain name starts.
377 * It's implied that if a domain name its range is implied to be
378 * [host+domain_start, host+host_len).
380 static void find_domain_name(const WCHAR
*host
, DWORD host_len
,
382 const WCHAR
*last_tld
, *sec_last_tld
, *end
;
384 end
= host
+host_len
-1;
388 /* There has to be at least enough room for a '.' followed by a
389 * 3 character TLD for a domain to even exist in the host name.
394 last_tld
= str_last_of(host
, end
, '.');
396 /* http://hostname -> has no domain name. */
399 sec_last_tld
= str_last_of(host
, last_tld
-1, '.');
401 /* If the '.' is at the beginning of the host there
402 * has to be at least 3 characters in the TLD for it
404 * Ex: .com -> .com as the domain name.
405 * .co -> has no domain name.
407 if(last_tld
-host
== 0) {
408 if(end
-(last_tld
-1) < 3)
410 } else if(last_tld
-host
== 3) {
413 /* If there's three characters in front of last_tld and
414 * they are on the list of recognized TLDs, then this
415 * host doesn't have a domain (since the host only contains
417 * Ex: edu.uk -> has no domain name.
418 * foo.uk -> foo.uk as the domain name.
420 for(i
= 0; i
< sizeof(recognized_tlds
)/sizeof(recognized_tlds
[0]); ++i
) {
421 if(!StrCmpNIW(host
, recognized_tlds
[i
].tld_name
, 3))
424 } else if(last_tld
-host
< 3)
425 /* Anything less then 3 characters is considered part
427 * Ex: ak.uk -> Has no domain name.
431 /* Otherwise the domain name is the whole host name. */
433 } else if(end
+1-last_tld
> 3) {
434 /* If the last_tld has more then 3 characters then it's automatically
435 * considered the TLD of the domain name.
436 * Ex: www.winehq.org.uk.test -> uk.test as the domain name.
438 *domain_start
= (sec_last_tld
+1)-host
;
439 } else if(last_tld
- (sec_last_tld
+1) < 4) {
441 /* If the sec_last_tld is 3 characters long it HAS to be on the list of
442 * recognized to still be considered part of the TLD name, otherwise
443 * its considered the domain name.
444 * Ex: www.google.com.uk -> google.com.uk as the domain name.
445 * www.google.foo.uk -> foo.uk as the domain name.
447 if(last_tld
- (sec_last_tld
+1) == 3) {
448 for(i
= 0; i
< sizeof(recognized_tlds
)/sizeof(recognized_tlds
[0]); ++i
) {
449 if(!StrCmpNIW(sec_last_tld
+1, recognized_tlds
[i
].tld_name
, 3)) {
450 const WCHAR
*domain
= str_last_of(host
, sec_last_tld
-1, '.');
455 *domain_start
= (domain
+1) - host
;
456 TRACE("Found domain name %s\n", debugstr_wn(host
+*domain_start
,
457 (host
+host_len
)-(host
+*domain_start
)));
462 *domain_start
= (sec_last_tld
+1)-host
;
464 /* Since the sec_last_tld is less then 3 characters it's considered
466 * Ex: www.google.fo.uk -> google.fo.uk as the domain name.
468 const WCHAR
*domain
= str_last_of(host
, sec_last_tld
-1, '.');
473 *domain_start
= (domain
+1) - host
;
476 /* The second to last TLD has more then 3 characters making it
478 * Ex: www.google.test.us -> test.us as the domain name.
480 *domain_start
= (sec_last_tld
+1)-host
;
483 TRACE("Found domain name %s\n", debugstr_wn(host
+*domain_start
,
484 (host
+host_len
)-(host
+*domain_start
)));
487 /* Removes the dot segments from a heirarchical URIs path component. This
488 * function performs the removal in place.
490 * This is a modified version of Qt's QUrl function "removeDotsFromPath".
492 * This function returns the new length of the path string.
494 static DWORD
remove_dot_segments(WCHAR
*path
, DWORD path_len
) {
496 const WCHAR
*in
= out
;
497 const WCHAR
*end
= out
+ path_len
;
501 /* A. if the input buffer begins with a prefix of "/./" or "/.",
502 * where "." is a complete path segment, then replace that
503 * prefix with "/" in the input buffer; otherwise,
505 if(in
<= end
- 3 && in
[0] == '/' && in
[1] == '.' && in
[2] == '/') {
508 } else if(in
== end
- 2 && in
[0] == '/' && in
[1] == '.') {
514 /* B. if the input buffer begins with a prefix of "/../" or "/..",
515 * where ".." is a complete path segment, then replace that
516 * prefix with "/" in the input buffer and remove the last
517 * segment and its preceding "/" (if any) from the output
520 if(in
<= end
- 4 && in
[0] == '/' && in
[1] == '.' && in
[2] == '.' && in
[3] == '/') {
521 while(out
> path
&& *(--out
) != '/');
525 } else if(in
== end
- 3 && in
[0] == '/' && in
[1] == '.' && in
[2] == '.') {
526 while(out
> path
&& *(--out
) != '/');
535 /* C. move the first path segment in the input buffer to the end of
536 * the output buffer, including the initial "/" character (if
537 * any) and any subsequent characters up to, but not including,
538 * the next "/" character or the end of the input buffer.
541 while(in
< end
&& *in
!= '/')
546 TRACE("(%p %d): Path after dot segments removed %s len=%d\n", path
, path_len
,
547 debugstr_wn(path
, len
), len
);
551 /* Attempts to find the file extension in a given path. */
552 static INT
find_file_extension(const WCHAR
*path
, DWORD path_len
) {
555 for(end
= path
+path_len
-1; end
>= path
&& *end
!= '/' && *end
!= '\\'; --end
) {
563 /* Computes the location where the elision should occur in the IPv6
564 * address using the numerical values of each component stored in
565 * 'values'. If the address shouldn't contain an elision then 'index'
566 * is assigned -1 as it's value. Otherwise 'index' will contain the
567 * starting index (into values) where the elision should be, and 'count'
568 * will contain the number of cells the elision covers.
571 * Windows will expand an elision if the elision only represents 1 h16
572 * component of the URI.
574 * Ex: [1::2:3:4:5:6:7] -> [1:0:2:3:4:5:6:7]
576 * If the IPv6 address contains an IPv4 address, the IPv4 address is also
577 * considered for being included as part of an elision if all it's components
580 * Ex: [1:2:3:4:5:6:0.0.0.0] -> [1:2:3:4:5:6::]
582 static void compute_elision_location(const ipv6_address
*address
, const USHORT values
[8],
583 INT
*index
, DWORD
*count
) {
584 DWORD i
, max_len
, cur_len
;
585 INT max_index
, cur_index
;
587 max_len
= cur_len
= 0;
588 max_index
= cur_index
= -1;
589 for(i
= 0; i
< 8; ++i
) {
590 BOOL check_ipv4
= (address
->ipv4
&& i
== 6);
591 BOOL is_end
= (check_ipv4
|| i
== 7);
594 /* Check if the IPv4 address contains only zeros. */
595 if(values
[i
] == 0 && values
[i
+1] == 0) {
602 } else if(values
[i
] == 0) {
609 if(is_end
|| values
[i
] != 0) {
610 /* We only consider it for an elision if it's
611 * more then 1 component long.
613 if(cur_len
> 1 && cur_len
> max_len
) {
614 /* Found the new elision location. */
616 max_index
= cur_index
;
619 /* Reset the current range for the next range of zeros. */
629 /* Converts the specified IPv4 address into an uint value.
631 * This function assumes that the IPv4 address has already been validated.
633 static UINT
ipv4toui(const WCHAR
*ip
, DWORD len
) {
635 DWORD comp_value
= 0;
638 for(ptr
= ip
; ptr
< ip
+len
; ++ptr
) {
644 comp_value
= comp_value
*10 + (*ptr
-'0');
653 /* Converts an IPv4 address in numerical form into it's fully qualified
654 * string form. This function returns the number of characters written
655 * to 'dest'. If 'dest' is NULL this function will return the number of
656 * characters that would have been written.
658 * It's up to the caller to ensure there's enough space in 'dest' for the
661 static DWORD
ui2ipv4(WCHAR
*dest
, UINT address
) {
662 static const WCHAR formatW
[] =
663 {'%','u','.','%','u','.','%','u','.','%','u',0};
667 digits
[0] = (address
>> 24) & 0xff;
668 digits
[1] = (address
>> 16) & 0xff;
669 digits
[2] = (address
>> 8) & 0xff;
670 digits
[3] = address
& 0xff;
674 ret
= sprintfW(tmp
, formatW
, digits
[0], digits
[1], digits
[2], digits
[3]);
676 ret
= sprintfW(dest
, formatW
, digits
[0], digits
[1], digits
[2], digits
[3]);
681 /* Converts an h16 component (from an IPv6 address) into it's
684 * This function assumes that the h16 component has already been validated.
686 static USHORT
h16tous(h16 component
) {
690 for(i
= 0; i
< component
.len
; ++i
) {
692 ret
+= hex_to_int(component
.str
[i
]);
698 /* Converts an IPv6 address into it's 128 bits (16 bytes) numerical value.
700 * This function assumes that the ipv6_address has already been validated.
702 static BOOL
ipv6_to_number(const ipv6_address
*address
, USHORT number
[8]) {
703 DWORD i
, cur_component
= 0;
704 BOOL already_passed_elision
= FALSE
;
706 for(i
= 0; i
< address
->h16_count
; ++i
) {
707 if(address
->elision
) {
708 if(address
->components
[i
].str
> address
->elision
&& !already_passed_elision
) {
709 /* Means we just passed the elision and need to add it's values to
710 * 'number' before we do anything else.
713 for(j
= 0; j
< address
->elision_size
; j
+=2)
714 number
[cur_component
++] = 0;
716 already_passed_elision
= TRUE
;
720 number
[cur_component
++] = h16tous(address
->components
[i
]);
723 /* Case when the elision appears after the h16 components. */
724 if(!already_passed_elision
&& address
->elision
) {
725 for(i
= 0; i
< address
->elision_size
; i
+=2)
726 number
[cur_component
++] = 0;
727 already_passed_elision
= TRUE
;
731 UINT value
= ipv4toui(address
->ipv4
, address
->ipv4_len
);
733 if(cur_component
!= 6) {
734 ERR("(%p %p): Failed sanity check with %d\n", address
, number
, cur_component
);
738 number
[cur_component
++] = (value
>> 16) & 0xffff;
739 number
[cur_component
] = value
& 0xffff;
745 /* Checks if the characters pointed to by 'ptr' are
746 * a percent encoded data octet.
748 * pct-encoded = "%" HEXDIG HEXDIG
750 static BOOL
check_pct_encoded(const WCHAR
**ptr
) {
751 const WCHAR
*start
= *ptr
;
757 if(!is_hexdigit(**ptr
)) {
763 if(!is_hexdigit(**ptr
)) {
772 /* dec-octet = DIGIT ; 0-9
773 * / %x31-39 DIGIT ; 10-99
774 * / "1" 2DIGIT ; 100-199
775 * / "2" %x30-34 DIGIT ; 200-249
776 * / "25" %x30-35 ; 250-255
778 static BOOL
check_dec_octet(const WCHAR
**ptr
) {
779 const WCHAR
*c1
, *c2
, *c3
;
782 /* A dec-octet must be at least 1 digit long. */
783 if(*c1
< '0' || *c1
> '9')
789 /* Since the 1 digit requirment was meet, it doesn't
790 * matter if this is a DIGIT value, it's considered a
793 if(*c2
< '0' || *c2
> '9')
799 /* Same explanation as above. */
800 if(*c3
< '0' || *c3
> '9')
803 /* Anything > 255 isn't a valid IP dec-octet. */
804 if(*c1
>= '2' && *c2
>= '5' && *c3
>= '5') {
813 /* Checks if there is an implicit IPv4 address in the host component of the URI.
814 * The max value of an implicit IPv4 address is UINT_MAX.
817 * "234567" would be considered an implicit IPv4 address.
819 static BOOL
check_implicit_ipv4(const WCHAR
**ptr
, UINT
*val
) {
820 const WCHAR
*start
= *ptr
;
824 while(is_num(**ptr
)) {
825 ret
= ret
*10 + (**ptr
- '0');
841 /* Checks if the string contains an IPv4 address.
843 * This function has a strict mode or a non-strict mode of operation
844 * When 'strict' is set to FALSE this function will return TRUE if
845 * the string contains at least 'dec-octet "." dec-octet' since partial
846 * IPv4 addresses will be normalized out into full IPv4 addresses. When
847 * 'strict' is set this function expects there to be a full IPv4 address.
849 * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
851 static BOOL
check_ipv4address(const WCHAR
**ptr
, BOOL strict
) {
852 const WCHAR
*start
= *ptr
;
854 if(!check_dec_octet(ptr
)) {
865 if(!check_dec_octet(ptr
)) {
879 if(!check_dec_octet(ptr
)) {
893 if(!check_dec_octet(ptr
)) {
898 /* Found a four digit ip address. */
901 /* Tries to parse the scheme name of the URI.
903 * scheme = ALPHA *(ALPHA | NUM | '+' | '-' | '.') as defined by RFC 3896.
904 * NOTE: Windows accepts a number as the first character of a scheme.
906 static BOOL
parse_scheme_name(const WCHAR
**ptr
, parse_data
*data
) {
907 const WCHAR
*start
= *ptr
;
910 data
->scheme_len
= 0;
913 if(**ptr
== '*' && *ptr
== start
) {
914 /* Might have found a wildcard scheme. If it is the next
915 * char has to be a ':' for it to be a valid URI
919 } else if(!is_num(**ptr
) && !is_alpha(**ptr
) && **ptr
!= '+' &&
920 **ptr
!= '-' && **ptr
!= '.')
929 /* Schemes must end with a ':' */
935 data
->scheme
= start
;
936 data
->scheme_len
= *ptr
- start
;
942 /* Tries to deduce the corresponding URL_SCHEME for the given URI. Stores
943 * the deduced URL_SCHEME in data->scheme_type.
945 static BOOL
parse_scheme_type(parse_data
*data
) {
946 /* If there's scheme data then see if it's a recognized scheme. */
947 if(data
->scheme
&& data
->scheme_len
) {
950 for(i
= 0; i
< sizeof(recognized_schemes
)/sizeof(recognized_schemes
[0]); ++i
) {
951 if(lstrlenW(recognized_schemes
[i
].scheme_name
) == data
->scheme_len
) {
952 /* Has to be a case insensitive compare. */
953 if(!StrCmpNIW(recognized_schemes
[i
].scheme_name
, data
->scheme
, data
->scheme_len
)) {
954 data
->scheme_type
= recognized_schemes
[i
].scheme
;
960 /* If we get here it means it's not a recognized scheme. */
961 data
->scheme_type
= URL_SCHEME_UNKNOWN
;
963 } else if(data
->is_relative
) {
964 /* Relative URI's have no scheme. */
965 data
->scheme_type
= URL_SCHEME_UNKNOWN
;
968 /* Should never reach here! what happened... */
969 FIXME("(%p): Unable to determine scheme type for URI %s\n", data
, debugstr_w(data
->uri
));
974 /* Tries to parse (or deduce) the scheme_name of a URI. If it can't
975 * parse a scheme from the URI it will try to deduce the scheme_name and scheme_type
976 * using the flags specified in 'flags' (if any). Flags that affect how this function
977 * operates are the Uri_CREATE_ALLOW_* flags.
979 * All parsed/deduced information will be stored in 'data' when the function returns.
981 * Returns TRUE if it was able to successfully parse the information.
983 static BOOL
parse_scheme(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
984 static const WCHAR fileW
[] = {'f','i','l','e',0};
985 static const WCHAR wildcardW
[] = {'*',0};
987 /* First check to see if the uri could implicitly be a file path. */
988 if(is_implicit_file_path(*ptr
)) {
989 if(flags
& Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
) {
990 data
->scheme
= fileW
;
991 data
->scheme_len
= lstrlenW(fileW
);
992 data
->has_implicit_scheme
= TRUE
;
994 TRACE("(%p %p %x): URI is an implicit file path.\n", ptr
, data
, flags
);
996 /* Window's does not consider anything that can implicitly be a file
997 * path to be a valid URI if the ALLOW_IMPLICIT_FILE_SCHEME flag is not set...
999 TRACE("(%p %p %x): URI is implicitly a file path, but, the ALLOW_IMPLICIT_FILE_SCHEME flag wasn't set.\n",
1003 } else if(!parse_scheme_name(ptr
, data
)) {
1004 /* No Scheme was found, this means it could be:
1005 * a) an implicit Wildcard scheme
1009 if(flags
& Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
) {
1010 data
->scheme
= wildcardW
;
1011 data
->scheme_len
= lstrlenW(wildcardW
);
1012 data
->has_implicit_scheme
= TRUE
;
1014 TRACE("(%p %p %x): URI is an implicit wildcard scheme.\n", ptr
, data
, flags
);
1015 } else if (flags
& Uri_CREATE_ALLOW_RELATIVE
) {
1016 data
->is_relative
= TRUE
;
1017 TRACE("(%p %p %x): URI is relative.\n", ptr
, data
, flags
);
1019 TRACE("(%p %p %x): Malformed URI found. Unable to deduce scheme name.\n", ptr
, data
, flags
);
1024 if(!data
->is_relative
)
1025 TRACE("(%p %p %x): Found scheme=%s scheme_len=%d\n", ptr
, data
, flags
,
1026 debugstr_wn(data
->scheme
, data
->scheme_len
), data
->scheme_len
);
1028 if(!parse_scheme_type(data
))
1031 TRACE("(%p %p %x): Assigned %d as the URL_SCHEME.\n", ptr
, data
, flags
, data
->scheme_type
);
1035 /* Parses the userinfo part of the URI (if it exists). The userinfo field of
1036 * a URI can consist of "username:password@", or just "username@".
1039 * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
1042 * 1) If there is more than one ':' in the userinfo part of the URI Windows
1043 * uses the first occurence of ':' to delimit the username and password
1047 * ftp://user:pass:word@winehq.org
1049 * Would yield, "user" as the username and "pass:word" as the password.
1051 * 2) Windows allows any character to appear in the "userinfo" part of
1052 * a URI, as long as it's not an authority delimeter character set.
1054 static void parse_userinfo(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1055 data
->userinfo
= *ptr
;
1056 data
->userinfo_split
= -1;
1058 while(**ptr
!= '@') {
1059 if(**ptr
== ':' && data
->userinfo_split
== -1)
1060 data
->userinfo_split
= *ptr
- data
->userinfo
;
1061 else if(**ptr
== '%') {
1062 /* If it's a known scheme type, it has to be a valid percent
1065 if(!check_pct_encoded(ptr
)) {
1066 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1067 *ptr
= data
->userinfo
;
1068 data
->userinfo
= NULL
;
1069 data
->userinfo_split
= -1;
1071 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr
, data
, flags
);
1076 } else if(is_auth_delim(**ptr
, data
->scheme_type
!= URL_SCHEME_UNKNOWN
))
1083 *ptr
= data
->userinfo
;
1084 data
->userinfo
= NULL
;
1085 data
->userinfo_split
= -1;
1087 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr
, data
, flags
);
1091 data
->userinfo_len
= *ptr
- data
->userinfo
;
1092 TRACE("(%p %p %x): Found userinfo=%s userinfo_len=%d split=%d.\n", ptr
, data
, flags
,
1093 debugstr_wn(data
->userinfo
, data
->userinfo_len
), data
->userinfo_len
, data
->userinfo_split
);
1097 /* Attempts to parse a port from the URI.
1100 * Windows seems to have a cap on what the maximum value
1101 * for a port can be. The max value is USHORT_MAX.
1105 static BOOL
parse_port(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1109 while(!is_auth_delim(**ptr
, data
->scheme_type
!= URL_SCHEME_UNKNOWN
)) {
1110 if(!is_num(**ptr
)) {
1116 port
= port
*10 + (**ptr
-'0');
1118 if(port
> USHORT_MAX
) {
1127 data
->port_value
= port
;
1128 data
->port_len
= *ptr
- data
->port
;
1130 TRACE("(%p %p %x): Found port %s len=%d value=%u\n", ptr
, data
, flags
,
1131 debugstr_wn(data
->port
, data
->port_len
), data
->port_len
, data
->port_value
);
1135 /* Attempts to parse a IPv4 address from the URI.
1138 * Window's normalizes IPv4 addresses, This means there's three
1139 * possibilities for the URI to contain an IPv4 address.
1140 * 1) A well formed address (ex. 192.2.2.2).
1141 * 2) A partially formed address. For example "192.0" would
1142 * normalize to "192.0.0.0" during canonicalization.
1143 * 3) An implicit IPv4 address. For example "256" would
1144 * normalize to "0.0.1.0" during canonicalization. Also
1145 * note that the maximum value for an implicit IP address
1146 * is UINT_MAX, if the value in the URI exceeds this then
1147 * it is not considered an IPv4 address.
1149 static BOOL
parse_ipv4address(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1150 const BOOL is_unknown
= data
->scheme_type
== URL_SCHEME_UNKNOWN
;
1153 if(!check_ipv4address(ptr
, FALSE
)) {
1154 if(!check_implicit_ipv4(ptr
, &data
->implicit_ipv4
)) {
1155 TRACE("(%p %p %x): URI didn't contain anything looking like an IPv4 address.\n",
1161 data
->has_implicit_ip
= TRUE
;
1164 /* Check if what we found is the only part of the host name (if it isn't
1165 * we don't have an IPv4 address).
1169 if(!parse_port(ptr
, data
, flags
)) {
1174 } else if(!is_auth_delim(**ptr
, !is_unknown
)) {
1175 /* Found more data which belongs the host, so this isn't an IPv4. */
1178 data
->has_implicit_ip
= FALSE
;
1182 data
->host_len
= *ptr
- data
->host
;
1183 data
->host_type
= Uri_HOST_IPV4
;
1185 TRACE("(%p %p %x): IPv4 address found. host=%s host_len=%d host_type=%d\n",
1186 ptr
, data
, flags
, debugstr_wn(data
->host
, data
->host_len
),
1187 data
->host_len
, data
->host_type
);
1191 /* Attempts to parse the reg-name from the URI.
1193 * Because of the way Windows handles ':' this function also
1194 * handles parsing the port.
1196 * reg-name = *( unreserved / pct-encoded / sub-delims )
1199 * Windows allows everything, but, the characters in "auth_delims" and ':'
1200 * to appear in a reg-name, unless it's an unknown scheme type then ':' is
1201 * allowed to appear (even if a valid port isn't after it).
1203 * Windows doesn't like host names which start with '[' and end with ']'
1204 * and don't contain a valid IP literal address in between them.
1206 * On Windows if an '[' is encountered in the host name the ':' no longer
1207 * counts as a delimiter until you reach the next ']' or an "authority delimeter".
1209 * A reg-name CAN be empty.
1211 static BOOL
parse_reg_name(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1212 const BOOL has_start_bracket
= **ptr
== '[';
1213 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1214 BOOL inside_brackets
= has_start_bracket
;
1215 BOOL ignore_col
= FALSE
;
1217 /* We have to be careful with file schemes. */
1218 if(data
->scheme_type
== URL_SCHEME_FILE
) {
1219 /* This is because an implicit file scheme could be "C:\\test" and it
1220 * would trick this function into thinking the host is "C", when after
1221 * canonicalization the host would end up being an empty string.
1223 if(is_alpha(**ptr
) && *(*ptr
+1) == ':') {
1224 /* Regular old drive paths don't have a host type (or host name). */
1225 data
->host_type
= Uri_HOST_UNKNOWN
;
1229 } else if(**ptr
== '\\' && *(*ptr
+1) == '\\')
1230 /* Skip past the "\\" of a UNC path. */
1236 while(!is_auth_delim(**ptr
, known_scheme
)) {
1237 if(**ptr
== ':' && !ignore_col
) {
1238 /* We can ignore ':' if were inside brackets.*/
1239 if(!inside_brackets
) {
1240 const WCHAR
*tmp
= (*ptr
)++;
1242 /* Attempt to parse the port. */
1243 if(!parse_port(ptr
, data
, flags
)) {
1244 /* Windows expects there to be a valid port for known scheme types. */
1245 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1248 TRACE("(%p %p %x): Expected valid port\n", ptr
, data
, flags
);
1251 /* Windows gives up on trying to parse a port when it
1252 * encounters 1 invalid port.
1256 data
->host_len
= tmp
- data
->host
;
1260 } else if(**ptr
== '%' && known_scheme
) {
1261 /* Has to be a legit % encoded value. */
1262 if(!check_pct_encoded(ptr
)) {
1268 } else if(**ptr
== ']')
1269 inside_brackets
= FALSE
;
1270 else if(**ptr
== '[')
1271 inside_brackets
= TRUE
;
1276 if(has_start_bracket
) {
1277 /* Make sure the last character of the host wasn't a ']'. */
1278 if(*(*ptr
-1) == ']') {
1279 TRACE("(%p %p %x): Expected an IP literal inside of the host\n",
1287 /* Don't overwrite our length if we found a port earlier. */
1289 data
->host_len
= *ptr
- data
->host
;
1291 /* If the host is empty, then it's an unknown host type. */
1292 if(data
->host_len
== 0)
1293 data
->host_type
= Uri_HOST_UNKNOWN
;
1295 data
->host_type
= Uri_HOST_DNS
;
1297 TRACE("(%p %p %x): Parsed reg-name. host=%s len=%d\n", ptr
, data
, flags
,
1298 debugstr_wn(data
->host
, data
->host_len
), data
->host_len
);
1302 /* Attempts to parse an IPv6 address out of the URI.
1304 * IPv6address = 6( h16 ":" ) ls32
1305 * / "::" 5( h16 ":" ) ls32
1306 * / [ h16 ] "::" 4( h16 ":" ) ls32
1307 * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1308 * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1309 * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1310 * / [ *4( h16 ":" ) h16 ] "::" ls32
1311 * / [ *5( h16 ":" ) h16 ] "::" h16
1312 * / [ *6( h16 ":" ) h16 ] "::"
1314 * ls32 = ( h16 ":" h16 ) / IPv4address
1315 * ; least-significant 32 bits of address.
1318 * ; 16 bits of address represented in hexadecimal.
1320 * Modeled after google-url's 'DoParseIPv6' function.
1322 static BOOL
parse_ipv6address(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1323 const WCHAR
*start
, *cur_start
;
1326 start
= cur_start
= *ptr
;
1327 memset(&ip
, 0, sizeof(ipv6_address
));
1330 /* Check if we're on the last character of the host. */
1331 BOOL is_end
= (is_auth_delim(**ptr
, data
->scheme_type
!= URL_SCHEME_UNKNOWN
)
1334 BOOL is_split
= (**ptr
== ':');
1335 BOOL is_elision
= (is_split
&& !is_end
&& *(*ptr
+1) == ':');
1337 /* Check if we're at the end of of the a component, or
1338 * if we're at the end of the IPv6 address.
1340 if(is_split
|| is_end
) {
1343 cur_len
= *ptr
- cur_start
;
1345 /* h16 can't have a length > 4. */
1349 TRACE("(%p %p %x): h16 component to long.\n",
1355 /* An h16 component can't have the length of 0 unless
1356 * the elision is at the beginning of the address, or
1357 * at the end of the address.
1359 if(!((*ptr
== start
&& is_elision
) ||
1360 (is_end
&& (*ptr
-2) == ip
.elision
))) {
1362 TRACE("(%p %p %x): IPv6 component can not have a length of 0.\n",
1369 /* An IPv6 address can have no more than 8 h16 components. */
1370 if(ip
.h16_count
>= 8) {
1372 TRACE("(%p %p %x): Not a IPv6 address, to many h16 components.\n",
1377 ip
.components
[ip
.h16_count
].str
= cur_start
;
1378 ip
.components
[ip
.h16_count
].len
= cur_len
;
1380 TRACE("(%p %p %x): Found h16 component %s, len=%d, h16_count=%d\n",
1381 ptr
, data
, flags
, debugstr_wn(cur_start
, cur_len
), cur_len
,
1391 /* A IPv6 address can only have 1 elision ('::'). */
1395 TRACE("(%p %p %x): IPv6 address cannot have 2 elisions.\n",
1407 if(!check_ipv4address(ptr
, TRUE
)) {
1408 if(!is_hexdigit(**ptr
)) {
1409 /* Not a valid character for an IPv6 address. */
1414 /* Found an IPv4 address. */
1415 ip
.ipv4
= cur_start
;
1416 ip
.ipv4_len
= *ptr
- cur_start
;
1418 TRACE("(%p %p %x): Found an attached IPv4 address %s len=%d.\n",
1419 ptr
, data
, flags
, debugstr_wn(ip
.ipv4
, ip
.ipv4_len
),
1422 /* IPv4 addresses can only appear at the end of a IPv6. */
1428 compute_ipv6_comps_size(&ip
);
1430 /* Make sure the IPv6 address adds up to 16 bytes. */
1431 if(ip
.components_size
+ ip
.elision_size
!= 16) {
1433 TRACE("(%p %p %x): Invalid IPv6 address, did not add up to 16 bytes.\n",
1438 if(ip
.elision_size
== 2) {
1439 /* For some reason on Windows if an elision that represents
1440 * only 1 h16 component is encountered at the very begin or
1441 * end of an IPv6 address, Windows does not consider it a
1442 * valid IPv6 address.
1444 * Ex: [::2:3:4:5:6:7] is not valid, even though the sum
1445 * of all the components == 128bits.
1447 if(ip
.elision
< ip
.components
[0].str
||
1448 ip
.elision
> ip
.components
[ip
.h16_count
-1].str
) {
1450 TRACE("(%p %p %x): Invalid IPv6 address. Detected elision of 2 bytes at the beginning or end of the address.\n",
1456 data
->host_type
= Uri_HOST_IPV6
;
1457 data
->has_ipv6
= TRUE
;
1458 data
->ipv6_address
= ip
;
1460 TRACE("(%p %p %x): Found valid IPv6 literal %s len=%d\n",
1461 ptr
, data
, flags
, debugstr_wn(start
, *ptr
-start
),
1466 /* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) */
1467 static BOOL
parse_ipvfuture(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1468 const WCHAR
*start
= *ptr
;
1470 /* IPvFuture has to start with a 'v' or 'V'. */
1471 if(**ptr
!= 'v' && **ptr
!= 'V')
1474 /* Following the v their must be atleast 1 hexdigit. */
1476 if(!is_hexdigit(**ptr
)) {
1482 while(is_hexdigit(**ptr
))
1485 /* End of the hexdigit sequence must be a '.' */
1492 if(!is_unreserved(**ptr
) && !is_subdelim(**ptr
) && **ptr
!= ':') {
1498 while(is_unreserved(**ptr
) || is_subdelim(**ptr
) || **ptr
== ':')
1501 data
->host_type
= Uri_HOST_UNKNOWN
;
1503 TRACE("(%p %p %x): Parsed IPvFuture address %s len=%d\n", ptr
, data
, flags
,
1504 debugstr_wn(start
, *ptr
-start
), *ptr
-start
);
1509 /* IP-literal = "[" ( IPv6address / IPvFuture ) "]" */
1510 static BOOL
parse_ip_literal(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1519 if(!parse_ipv6address(ptr
, data
, flags
)) {
1520 if(!parse_ipvfuture(ptr
, data
, flags
)) {
1536 /* If a valid port is not found, then let it trickle down to
1539 if(!parse_port(ptr
, data
, flags
)) {
1545 data
->host_len
= *ptr
- data
->host
;
1550 /* Parses the host information from the URI.
1552 * host = IP-literal / IPv4address / reg-name
1554 static BOOL
parse_host(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1555 if(!parse_ip_literal(ptr
, data
, flags
)) {
1556 if(!parse_ipv4address(ptr
, data
, flags
)) {
1557 if(!parse_reg_name(ptr
, data
, flags
)) {
1558 TRACE("(%p %p %x): Malformed URI, Unknown host type.\n",
1568 /* Parses the authority information from the URI.
1570 * authority = [ userinfo "@" ] host [ ":" port ]
1572 static BOOL
parse_authority(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1573 parse_userinfo(ptr
, data
, flags
);
1575 /* Parsing the port will happen during one of the host parsing
1576 * routines (if the URI has a port).
1578 if(!parse_host(ptr
, data
, flags
))
1584 /* Attempts to parse the path information of a hierarchical URI. */
1585 static BOOL
parse_path_hierarchical(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1586 const WCHAR
*start
= *ptr
;
1587 static const WCHAR slash
[] = {'/',0};
1589 if(is_path_delim(**ptr
)) {
1590 if(data
->scheme_type
== URL_SCHEME_WILDCARD
) {
1591 /* Wildcard schemes don't get a '/' attached if their path is
1596 } else if(!(flags
& Uri_CREATE_NO_CANONICALIZE
)) {
1597 /* If the path component is empty, then a '/' is added. */
1602 while(!is_path_delim(**ptr
)) {
1603 if(**ptr
== '%' && data
->scheme_type
!= URL_SCHEME_UNKNOWN
&&
1604 data
->scheme_type
!= URL_SCHEME_FILE
) {
1605 if(!check_pct_encoded(ptr
)) {
1610 } else if(**ptr
== '\\') {
1611 /* Not allowed to have a backslash if NO_CANONICALIZE is set
1612 * and the scheme is known type (but not a file scheme).
1614 if(flags
& Uri_CREATE_NO_CANONICALIZE
) {
1615 if(data
->scheme_type
!= URL_SCHEME_FILE
&&
1616 data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1626 /* The only time a URI doesn't have a path is when
1627 * the NO_CANONICALIZE flag is set and the raw URI
1628 * didn't contain one.
1635 data
->path_len
= *ptr
- start
;
1640 TRACE("(%p %p %x): Parsed path %s len=%d\n", ptr
, data
, flags
,
1641 debugstr_wn(data
->path
, data
->path_len
), data
->path_len
);
1643 TRACE("(%p %p %x): The URI contained no path\n", ptr
, data
, flags
);
1648 /* Parses the path of a opaque URI (much less strict then the parser
1649 * for a hierarchical URI).
1652 * Windows allows invalid % encoded data to appear in opaque URI paths
1653 * for unknown scheme types.
1655 static BOOL
parse_path_opaque(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1656 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1660 while(!is_path_delim(**ptr
)) {
1661 if(**ptr
== '%' && known_scheme
) {
1662 if(!check_pct_encoded(ptr
)) {
1673 data
->path_len
= *ptr
- data
->path
;
1674 TRACE("(%p %p %x): Parsed opaque URI path %s len=%d\n", ptr
, data
, flags
,
1675 debugstr_wn(data
->path
, data
->path_len
), data
->path_len
);
1679 /* Determines how the URI should be parsed after the scheme information.
1681 * If the scheme is followed, by "//" then, it is treated as an hierarchical URI
1682 * which then the authority and path information will be parsed out. Otherwise, the
1683 * URI will be treated as an opaque URI which the authority information is not parsed
1686 * RFC 3896 definition of hier-part:
1688 * hier-part = "//" authority path-abempty
1693 * MSDN opaque URI definition:
1694 * scheme ":" path [ "#" fragment ]
1697 * If the URI is of an unknown scheme type and has a "//" following the scheme then it
1698 * is treated as a hierarchical URI, but, if the CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is
1699 * set then it is considered an opaque URI reguardless of what follows the scheme information
1700 * (per MSDN documentation).
1702 static BOOL
parse_hierpart(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1703 const WCHAR
*start
= *ptr
;
1705 /* Checks if the authority information needs to be parsed.
1707 * Relative URI's aren't hierarchical URI's, but, they could trick
1708 * "check_hierarchical" into thinking it is, so we need to explicitly
1709 * make sure it's not relative. Also, if the URI is an implicit file
1710 * scheme it might not contain a "//", but, it's considered hierarchical
1711 * anyways. Wildcard Schemes are always considered hierarchical
1713 if(data
->scheme_type
== URL_SCHEME_WILDCARD
||
1714 data
->scheme_type
== URL_SCHEME_FILE
||
1715 (!data
->is_relative
&& check_hierarchical(ptr
))) {
1716 /* Only treat it as a hierarchical URI if the scheme_type is known or
1717 * the Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is not set.
1719 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
||
1720 !(flags
& Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES
)) {
1721 TRACE("(%p %p %x): Treating URI as an hierarchical URI.\n", ptr
, data
, flags
);
1722 data
->is_opaque
= FALSE
;
1724 if(data
->scheme_type
== URL_SCHEME_FILE
)
1725 /* Skip past the "//" after the scheme (if any). */
1726 check_hierarchical(ptr
);
1728 /* TODO: Handle hierarchical URI's, parse authority then parse the path. */
1729 if(!parse_authority(ptr
, data
, flags
))
1732 return parse_path_hierarchical(ptr
, data
, flags
);
1734 /* Reset ptr to it's starting position so opaque path parsing
1735 * begins at the correct location.
1740 /* If it reaches here, then the URI will be treated as an opaque
1744 TRACE("(%p %p %x): Treating URI as an opaque URI.\n", ptr
, data
, flags
);
1746 data
->is_opaque
= TRUE
;
1747 if(!parse_path_opaque(ptr
, data
, flags
))
1753 /* Attempts to parse the query string from the URI.
1756 * If NO_DECODE_EXTRA_INFO flag is set, then invalid percent encoded
1757 * data is allowed appear in the query string. For unknown scheme types
1758 * invalid percent encoded data is allowed to appear reguardless.
1760 static BOOL
parse_query(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1761 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1764 TRACE("(%p %p %x): URI didn't contain a query string.\n", ptr
, data
, flags
);
1771 while(**ptr
&& **ptr
!= '#') {
1772 if(**ptr
== '%' && known_scheme
&&
1773 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
1774 if(!check_pct_encoded(ptr
)) {
1785 data
->query_len
= *ptr
- data
->query
;
1787 TRACE("(%p %p %x): Parsed query string %s len=%d\n", ptr
, data
, flags
,
1788 debugstr_wn(data
->query
, data
->query_len
), data
->query_len
);
1792 /* Attempts to parse the fragment from the URI.
1795 * If NO_DECODE_EXTRA_INFO flag is set, then invalid percent encoded
1796 * data is allowed appear in the query string. For unknown scheme types
1797 * invalid percent encoded data is allowed to appear reguardless.
1799 static BOOL
parse_fragment(const WCHAR
**ptr
, parse_data
*data
, DWORD flags
) {
1800 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1803 TRACE("(%p %p %x): URI didn't contain a fragment.\n", ptr
, data
, flags
);
1807 data
->fragment
= *ptr
;
1811 if(**ptr
== '%' && known_scheme
&&
1812 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
1813 if(!check_pct_encoded(ptr
)) {
1814 *ptr
= data
->fragment
;
1815 data
->fragment
= NULL
;
1824 data
->fragment_len
= *ptr
- data
->fragment
;
1826 TRACE("(%p %p %x): Parsed fragment %s len=%d\n", ptr
, data
, flags
,
1827 debugstr_wn(data
->fragment
, data
->fragment_len
), data
->fragment_len
);
1831 /* Parses and validates the components of the specified by data->uri
1832 * and stores the information it parses into 'data'.
1834 * Returns TRUE if it successfully parsed the URI. False otherwise.
1836 static BOOL
parse_uri(parse_data
*data
, DWORD flags
) {
1843 TRACE("(%p %x): BEGINNING TO PARSE URI %s.\n", data
, flags
, debugstr_w(data
->uri
));
1845 if(!parse_scheme(pptr
, data
, flags
))
1848 if(!parse_hierpart(pptr
, data
, flags
))
1851 if(!parse_query(pptr
, data
, flags
))
1854 if(!parse_fragment(pptr
, data
, flags
))
1857 TRACE("(%p %x): FINISHED PARSING URI.\n", data
, flags
);
1861 /* Canonicalizes the userinfo of the URI represented by the parse_data.
1863 * Canonicalization of the userinfo is a simple process. If there are any percent
1864 * encoded characters that fall in the "unreserved" character set, they are decoded
1865 * to their actual value. If a character is not in the "unreserved" or "reserved" sets
1866 * then it is percent encoded. Other than that the characters are copied over without
1869 static BOOL
canonicalize_userinfo(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
1872 uri
->userinfo_start
= uri
->userinfo_split
= -1;
1873 uri
->userinfo_len
= 0;
1876 /* URI doesn't have userinfo, so nothing to do here. */
1879 uri
->userinfo_start
= uri
->canon_len
;
1881 while(i
< data
->userinfo_len
) {
1882 if(data
->userinfo
[i
] == ':' && uri
->userinfo_split
== -1)
1883 /* Windows only considers the first ':' as the delimiter. */
1884 uri
->userinfo_split
= uri
->canon_len
- uri
->userinfo_start
;
1885 else if(data
->userinfo
[i
] == '%') {
1886 /* Only decode % encoded values for known scheme types. */
1887 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
1888 /* See if the value really needs decoded. */
1889 WCHAR val
= decode_pct_val(data
->userinfo
+ i
);
1890 if(is_unreserved(val
)) {
1892 uri
->canon_uri
[uri
->canon_len
] = val
;
1896 /* Move pass the hex characters. */
1901 } else if(!is_reserved(data
->userinfo
[i
]) && !is_unreserved(data
->userinfo
[i
]) &&
1902 data
->userinfo
[i
] != '\\') {
1903 /* Only percent encode forbidden characters if the NO_ENCODE_FORBIDDEN_CHARACTERS flag
1906 if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
)) {
1908 pct_encode_val(data
->userinfo
[i
], uri
->canon_uri
+ uri
->canon_len
);
1910 uri
->canon_len
+= 3;
1917 /* Nothing special, so just copy the character over. */
1918 uri
->canon_uri
[uri
->canon_len
] = data
->userinfo
[i
];
1924 uri
->userinfo_len
= uri
->canon_len
- uri
->userinfo_start
;
1926 TRACE("(%p %p %x %d): Canonicalized userinfo, userinfo_start=%d, userinfo=%s, userinfo_split=%d userinfo_len=%d.\n",
1927 data
, uri
, flags
, computeOnly
, uri
->userinfo_start
, debugstr_wn(uri
->canon_uri
+ uri
->userinfo_start
, uri
->userinfo_len
),
1928 uri
->userinfo_split
, uri
->userinfo_len
);
1930 /* Now insert the '@' after the userinfo. */
1932 uri
->canon_uri
[uri
->canon_len
] = '@';
1938 /* Attempts to canonicalize a reg_name.
1940 * Things that happen:
1941 * 1) If Uri_CREATE_NO_CANONICALIZE flag is not set, then the reg_name is
1942 * lower cased. Unless it's an unknown scheme type, which case it's
1943 * no lower cased reguardless.
1945 * 2) Unreserved % encoded characters are decoded for known
1948 * 3) Forbidden characters are % encoded as long as
1949 * Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS flag is not set and
1950 * it isn't an unknown scheme type.
1952 * 4) If it's a file scheme and the host is "localhost" it's removed.
1954 static BOOL
canonicalize_reg_name(const parse_data
*data
, Uri
*uri
,
1955 DWORD flags
, BOOL computeOnly
) {
1956 static const WCHAR localhostW
[] =
1957 {'l','o','c','a','l','h','o','s','t',0};
1959 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
1961 uri
->host_start
= uri
->canon_len
;
1963 if(data
->scheme_type
== URL_SCHEME_FILE
&&
1964 data
->host_len
== lstrlenW(localhostW
)) {
1965 if(!StrCmpNIW(data
->host
, localhostW
, data
->host_len
)) {
1966 uri
->host_start
= -1;
1968 uri
->host_type
= Uri_HOST_UNKNOWN
;
1973 for(ptr
= data
->host
; ptr
< data
->host
+data
->host_len
; ++ptr
) {
1974 if(*ptr
== '%' && known_scheme
) {
1975 WCHAR val
= decode_pct_val(ptr
);
1976 if(is_unreserved(val
)) {
1977 /* If NO_CANONICALZE is not set, then windows lower cases the
1980 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
) && isupperW(val
)) {
1982 uri
->canon_uri
[uri
->canon_len
] = tolowerW(val
);
1985 uri
->canon_uri
[uri
->canon_len
] = val
;
1989 /* Skip past the % encoded character. */
1993 /* Just copy the % over. */
1995 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
1998 } else if(*ptr
== '\\') {
1999 /* Only unknown scheme types could have made it here with a '\\' in the host name. */
2001 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2003 } else if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) &&
2004 !is_unreserved(*ptr
) && !is_reserved(*ptr
) && known_scheme
) {
2006 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2008 /* The percent encoded value gets lower cased also. */
2009 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
)) {
2010 uri
->canon_uri
[uri
->canon_len
+1] = tolowerW(uri
->canon_uri
[uri
->canon_len
+1]);
2011 uri
->canon_uri
[uri
->canon_len
+2] = tolowerW(uri
->canon_uri
[uri
->canon_len
+2]);
2015 uri
->canon_len
+= 3;
2018 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
) && known_scheme
)
2019 uri
->canon_uri
[uri
->canon_len
] = tolowerW(*ptr
);
2021 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2028 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2031 TRACE("(%p %p %x %d): Canonicalize reg_name=%s len=%d\n", data
, uri
, flags
,
2032 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2036 find_domain_name(uri
->canon_uri
+uri
->host_start
, uri
->host_len
,
2037 &(uri
->domain_offset
));
2042 /* Attempts to canonicalize an implicit IPv4 address. */
2043 static BOOL
canonicalize_implicit_ipv4address(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2044 uri
->host_start
= uri
->canon_len
;
2046 TRACE("%u\n", data
->implicit_ipv4
);
2047 /* For unknown scheme types Window's doesn't convert
2048 * the value into an IP address, but, it still considers
2049 * it an IPv4 address.
2051 if(data
->scheme_type
== URL_SCHEME_UNKNOWN
) {
2053 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2054 uri
->canon_len
+= data
->host_len
;
2057 uri
->canon_len
+= ui2ipv4(uri
->canon_uri
+uri
->canon_len
, data
->implicit_ipv4
);
2059 uri
->canon_len
+= ui2ipv4(NULL
, data
->implicit_ipv4
);
2062 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2063 uri
->host_type
= Uri_HOST_IPV4
;
2066 TRACE("%p %p %x %d): Canonicalized implicit IP address=%s len=%d\n",
2067 data
, uri
, flags
, computeOnly
,
2068 debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2074 /* Attempts to canonicalize an IPv4 address.
2076 * If the parse_data represents a URI that has an implicit IPv4 address
2077 * (ex. http://256/, this function will convert 256 into 0.0.1.0). If
2078 * the implicit IP address exceeds the value of UINT_MAX (maximum value
2079 * for an IPv4 address) it's canonicalized as if were a reg-name.
2081 * If the parse_data contains a partial or full IPv4 address it normalizes it.
2082 * A partial IPv4 address is something like "192.0" and would be normalized to
2083 * "192.0.0.0". With a full (or partial) IPv4 address like "192.002.01.003" would
2084 * be normalized to "192.2.1.3".
2087 * Window's ONLY normalizes IPv4 address for known scheme types (one that isn't
2088 * URL_SCHEME_UNKNOWN). For unknown scheme types, it simply copies the data from
2089 * the original URI into the canonicalized URI, but, it still recognizes URI's
2090 * host type as HOST_IPV4.
2092 static BOOL
canonicalize_ipv4address(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2093 if(data
->has_implicit_ip
)
2094 return canonicalize_implicit_ipv4address(data
, uri
, flags
, computeOnly
);
2096 uri
->host_start
= uri
->canon_len
;
2098 /* Windows only normalizes for known scheme types. */
2099 if(data
->scheme_type
!= URL_SCHEME_UNKNOWN
) {
2100 /* parse_data contains a partial or full IPv4 address, so normalize it. */
2101 DWORD i
, octetDigitCount
= 0, octetCount
= 0;
2102 BOOL octetHasDigit
= FALSE
;
2104 for(i
= 0; i
< data
->host_len
; ++i
) {
2105 if(data
->host
[i
] == '0' && !octetHasDigit
) {
2106 /* Can ignore leading zeros if:
2107 * 1) It isn't the last digit of the octet.
2108 * 2) i+1 != data->host_len
2111 if(octetDigitCount
== 2 ||
2112 i
+1 == data
->host_len
||
2113 data
->host
[i
+1] == '.') {
2115 uri
->canon_uri
[uri
->canon_len
] = data
->host
[i
];
2117 TRACE("Adding zero\n");
2119 } else if(data
->host
[i
] == '.') {
2121 uri
->canon_uri
[uri
->canon_len
] = data
->host
[i
];
2124 octetDigitCount
= 0;
2125 octetHasDigit
= FALSE
;
2129 uri
->canon_uri
[uri
->canon_len
] = data
->host
[i
];
2133 octetHasDigit
= TRUE
;
2137 /* Make sure the canonicalized IP address has 4 dec-octets.
2138 * If doesn't add "0" ones until there is 4;
2140 for( ; octetCount
< 3; ++octetCount
) {
2142 uri
->canon_uri
[uri
->canon_len
] = '.';
2143 uri
->canon_uri
[uri
->canon_len
+1] = '0';
2146 uri
->canon_len
+= 2;
2149 /* Windows doesn't normalize addresses in unknown schemes. */
2151 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2152 uri
->canon_len
+= data
->host_len
;
2155 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2157 TRACE("(%p %p %x %d): Canonicalized IPv4 address, ip=%s len=%d\n",
2158 data
, uri
, flags
, computeOnly
,
2159 debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2166 /* Attempts to canonicalize the IPv6 address of the URI.
2168 * Multiple things happen during the canonicalization of an IPv6 address:
2169 * 1) Any leading zero's in an h16 component are removed.
2170 * Ex: [0001:0022::] -> [1:22::]
2172 * 2) The longest sequence of zero h16 components are compressed
2173 * into a "::" (elision). If there's a tie, the first is choosen.
2175 * Ex: [0:0:0:0:1:6:7:8] -> [::1:6:7:8]
2176 * [0:0:0:0:1:2::] -> [::1:2:0:0]
2177 * [0:0:1:2:0:0:7:8] -> [::1:2:0:0:7:8]
2179 * 3) If an IPv4 address is attached to the IPv6 address, it's
2181 * Ex: [::001.002.022.000] -> [::1.2.22.0]
2183 * 4) If an elision is present, but, only represents 1 h16 component
2186 * Ex: [1::2:3:4:5:6:7] -> [1:0:2:3:4:5:6:7]
2188 * 5) If the IPv6 address contains an IPv4 address and there exists
2189 * at least 1 non-zero h16 component the IPv4 address is converted
2190 * into two h16 components, otherwise it's normalized and kept as is.
2192 * Ex: [::192.200.003.4] -> [::192.200.3.4]
2193 * [ffff::192.200.003.4] -> [ffff::c0c8:3041]
2196 * For unknown scheme types Windows simply copies the address over without any
2199 * IPv4 address can be included in an elision if all its components are 0's.
2201 static BOOL
canonicalize_ipv6address(const parse_data
*data
, Uri
*uri
,
2202 DWORD flags
, BOOL computeOnly
) {
2203 uri
->host_start
= uri
->canon_len
;
2205 if(data
->scheme_type
== URL_SCHEME_UNKNOWN
) {
2207 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2208 uri
->canon_len
+= data
->host_len
;
2212 DWORD i
, elision_len
;
2214 if(!ipv6_to_number(&(data
->ipv6_address
), values
)) {
2215 TRACE("(%p %p %x %d): Failed to compute numerical value for IPv6 address.\n",
2216 data
, uri
, flags
, computeOnly
);
2221 uri
->canon_uri
[uri
->canon_len
] = '[';
2224 /* Find where the elision should occur (if any). */
2225 compute_elision_location(&(data
->ipv6_address
), values
, &elision_start
, &elision_len
);
2227 TRACE("%p %p %x %d): Elision starts at %d, len=%u\n", data
, uri
, flags
,
2228 computeOnly
, elision_start
, elision_len
);
2230 for(i
= 0; i
< 8; ++i
) {
2231 BOOL in_elision
= (elision_start
> -1 && i
>= elision_start
&&
2232 i
< elision_start
+elision_len
);
2233 BOOL do_ipv4
= (i
== 6 && data
->ipv6_address
.ipv4
&& !in_elision
&&
2234 data
->ipv6_address
.h16_count
== 0);
2236 if(i
== elision_start
) {
2238 uri
->canon_uri
[uri
->canon_len
] = ':';
2239 uri
->canon_uri
[uri
->canon_len
+1] = ':';
2241 uri
->canon_len
+= 2;
2244 /* We can ignore the current component if we're in the elision. */
2248 /* We only add a ':' if we're not at i == 0, or when we're at
2249 * the very end of elision range since the ':' colon was handled
2250 * earlier. Otherwise we would end up with ":::" after elision.
2252 if(i
!= 0 && !(elision_start
> -1 && i
== elision_start
+elision_len
)) {
2254 uri
->canon_uri
[uri
->canon_len
] = ':';
2262 /* Combine the two parts of the IPv4 address values. */
2268 len
= ui2ipv4(uri
->canon_uri
+uri
->canon_len
, val
);
2270 len
= ui2ipv4(NULL
, val
);
2272 uri
->canon_len
+= len
;
2275 /* Write a regular h16 component to the URI. */
2277 /* Short circuit for the trivial case. */
2278 if(values
[i
] == 0) {
2280 uri
->canon_uri
[uri
->canon_len
] = '0';
2283 static const WCHAR formatW
[] = {'%','x',0};
2286 uri
->canon_len
+= sprintfW(uri
->canon_uri
+uri
->canon_len
,
2287 formatW
, values
[i
]);
2290 uri
->canon_len
+= sprintfW(tmp
, formatW
, values
[i
]);
2296 /* Add the closing ']'. */
2298 uri
->canon_uri
[uri
->canon_len
] = ']';
2302 uri
->host_len
= uri
->canon_len
- uri
->host_start
;
2305 TRACE("(%p %p %x %d): Canonicalized IPv6 address %s, len=%d\n", data
, uri
, flags
,
2306 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->host_start
, uri
->host_len
),
2312 /* Attempts to canonicalize the host of the URI (if any). */
2313 static BOOL
canonicalize_host(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2314 uri
->host_start
= -1;
2316 uri
->domain_offset
= -1;
2319 switch(data
->host_type
) {
2321 uri
->host_type
= Uri_HOST_DNS
;
2322 if(!canonicalize_reg_name(data
, uri
, flags
, computeOnly
))
2327 uri
->host_type
= Uri_HOST_IPV4
;
2328 if(!canonicalize_ipv4address(data
, uri
, flags
, computeOnly
))
2333 if(!canonicalize_ipv6address(data
, uri
, flags
, computeOnly
))
2336 uri
->host_type
= Uri_HOST_IPV6
;
2338 case Uri_HOST_UNKNOWN
:
2339 if(data
->host_len
> 0 || data
->scheme_type
!= URL_SCHEME_FILE
) {
2340 uri
->host_start
= uri
->canon_len
;
2342 /* Nothing happens to unknown host types. */
2344 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->host
, data
->host_len
*sizeof(WCHAR
));
2345 uri
->canon_len
+= data
->host_len
;
2346 uri
->host_len
= data
->host_len
;
2349 uri
->host_type
= Uri_HOST_UNKNOWN
;
2352 FIXME("(%p %p %x %d): Canonicalization for host type %d not supported.\n", data
,
2353 uri
, flags
, computeOnly
, data
->host_type
);
2361 static BOOL
canonicalize_port(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2362 BOOL has_default_port
= FALSE
;
2363 USHORT default_port
= 0;
2366 uri
->has_port
= FALSE
;
2368 /* Check if the scheme has a default port. */
2369 for(i
= 0; i
< sizeof(default_ports
)/sizeof(default_ports
[0]); ++i
) {
2370 if(default_ports
[i
].scheme
== data
->scheme_type
) {
2371 has_default_port
= TRUE
;
2372 default_port
= default_ports
[i
].port
;
2377 if(data
->port
|| has_default_port
)
2378 uri
->has_port
= TRUE
;
2381 * 1) Has a port which is the default port.
2382 * 2) Has a port (not the default).
2383 * 3) Doesn't have a port, but, scheme has a default port.
2386 if(has_default_port
&& data
->port
&& data
->port_value
== default_port
) {
2387 /* If it's the default port and this flag isn't set, don't do anything. */
2388 if(flags
& Uri_CREATE_NO_CANONICALIZE
) {
2389 /* Copy the original port over. */
2391 uri
->canon_uri
[uri
->canon_len
] = ':';
2392 memcpy(uri
->canon_uri
+uri
->canon_len
+1, data
->port
, data
->port_len
*sizeof(WCHAR
));
2394 uri
->canon_len
+= data
->port_len
+1;
2397 uri
->port
= default_port
;
2398 } else if(data
->port
) {
2400 uri
->canon_uri
[uri
->canon_len
] = ':';
2403 if(flags
& Uri_CREATE_NO_CANONICALIZE
) {
2404 /* Copy the original over without changes. */
2406 memcpy(uri
->canon_uri
+uri
->canon_len
, data
->port
, data
->port_len
*sizeof(WCHAR
));
2407 uri
->canon_len
+= data
->port_len
;
2409 const WCHAR formatW
[] = {'%','u',0};
2412 len
= sprintfW(uri
->canon_uri
+uri
->canon_len
, formatW
, data
->port_value
);
2415 len
= sprintfW(tmp
, formatW
, data
->port_value
);
2417 uri
->canon_len
+= len
;
2420 uri
->port
= data
->port_value
;
2421 } else if(has_default_port
)
2422 uri
->port
= default_port
;
2427 /* Canonicalizes the authority of the URI represented by the parse_data. */
2428 static BOOL
canonicalize_authority(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2429 uri
->authority_start
= uri
->canon_len
;
2430 uri
->authority_len
= 0;
2432 if(!canonicalize_userinfo(data
, uri
, flags
, computeOnly
))
2435 if(!canonicalize_host(data
, uri
, flags
, computeOnly
))
2438 if(!canonicalize_port(data
, uri
, flags
, computeOnly
))
2441 if(uri
->host_start
!= -1)
2442 uri
->authority_len
= uri
->canon_len
- uri
->authority_start
;
2444 uri
->authority_start
= -1;
2449 /* Attempts to canonicalize the path of a hierarchical URI.
2451 * Things that happen:
2452 * 1). Forbidden characters are percent encoded, unless the NO_ENCODE_FORBIDDEN
2453 * flag is set or it's a file URI. Forbidden characters are always encoded
2454 * for file schemes reguardless and forbidden characters are never encoded
2455 * for unknown scheme types.
2457 * 2). For known scheme types '\\' are changed to '/'.
2459 * 3). Percent encoded, unreserved characters are decoded to their actual values.
2460 * Unless the scheme type is unknown. For file schemes any percent encoded
2461 * character in the unreserved or reserved set is decoded.
2463 * 4). For File schemes if the path is starts with a drive letter and doesn't
2464 * start with a '/' then one is appended.
2465 * Ex: file://c:/test.mp3 -> file:///c:/test.mp3
2467 * 5). Dot segments are removed from the path for all scheme types
2468 * unless NO_CANONICALIZE flag is set. Dot segments aren't removed
2469 * for wildcard scheme types.
2472 * file://c:/test%20test -> file:///c:/test%2520test
2473 * file://c:/test%3Etest -> file:///c:/test%253Etest
2474 * file:///c:/test%20test -> file:///c:/test%20test
2475 * file:///c:/test%test -> file:///c:/test%25test
2477 static BOOL
canonicalize_path_hierarchical(const parse_data
*data
, Uri
*uri
,
2478 DWORD flags
, BOOL computeOnly
) {
2480 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2481 const BOOL is_file
= data
->scheme_type
== URL_SCHEME_FILE
;
2483 BOOL escape_pct
= FALSE
;
2486 uri
->path_start
= -1;
2491 uri
->path_start
= uri
->canon_len
;
2493 /* Check if a '/' needs to be appended for the file scheme. */
2495 if(data
->path_len
> 1 && is_alpha(*(data
->path
)) &&
2496 *(data
->path
+1) == ':') {
2498 uri
->canon_uri
[uri
->canon_len
] = '/';
2504 for(ptr
= data
->path
; ptr
< data
->path
+data
->path_len
; ++ptr
) {
2506 const WCHAR
*tmp
= ptr
;
2509 /* Check if the % represents a valid encoded char, or if it needs encoded. */
2510 BOOL force_encode
= !check_pct_encoded(&tmp
) && is_file
;
2511 val
= decode_pct_val(ptr
);
2513 if(force_encode
|| escape_pct
) {
2514 /* Escape the percent sign in the file URI. */
2516 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2517 uri
->canon_len
+= 3;
2518 } else if((is_unreserved(val
) && known_scheme
) ||
2519 (is_file
&& (is_unreserved(val
) || is_reserved(val
)))) {
2521 uri
->canon_uri
[uri
->canon_len
] = val
;
2528 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2531 } else if(*ptr
== '\\' && known_scheme
) {
2533 uri
->canon_uri
[uri
->canon_len
] = '/';
2535 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
) &&
2536 (!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) || is_file
)) {
2537 /* Escape the forbidden character. */
2539 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2540 uri
->canon_len
+= 3;
2543 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2548 uri
->path_len
= uri
->canon_len
- uri
->path_start
;
2550 /* Removing the dot segments only happens when it's not in
2551 * computeOnly mode and it's not a wildcard scheme.
2553 if(!computeOnly
&& data
->scheme_type
!= URL_SCHEME_WILDCARD
) {
2554 if(!(flags
& Uri_CREATE_NO_CANONICALIZE
)) {
2555 /* Remove the dot segments (if any) and reset everything to the new
2558 DWORD new_len
= remove_dot_segments(uri
->canon_uri
+uri
->path_start
, uri
->path_len
);
2559 uri
->canon_len
-= uri
->path_len
-new_len
;
2560 uri
->path_len
= new_len
;
2565 TRACE("Canonicalized path %s len=%d\n",
2566 debugstr_wn(uri
->canon_uri
+uri
->path_start
, uri
->path_len
),
2572 /* Attempts to canonicalize the path for an opaque URI.
2574 * For known scheme types:
2575 * 1) forbidden characters are percent encoded if
2576 * NO_ENCODE_FORBIDDEN_CHARACTERS isn't set.
2578 * 2) Percent encoded, unreserved characters are decoded
2579 * to their actual values, for known scheme types.
2581 * 3) '\\' are changed to '/' for known scheme types
2582 * except for mailto schemes.
2584 static BOOL
canonicalize_path_opaque(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2586 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2589 uri
->path_start
= -1;
2594 uri
->path_start
= uri
->canon_len
;
2596 /* Windows doesn't allow a "//" to appear after the scheme
2597 * of a URI, if it's an opaque URI.
2599 if(data
->scheme
&& *(data
->path
) == '/' && *(data
->path
+1) == '/') {
2600 /* So it inserts a "/." before the "//" if it exists. */
2602 uri
->canon_uri
[uri
->canon_len
] = '/';
2603 uri
->canon_uri
[uri
->canon_len
+1] = '.';
2606 uri
->canon_len
+= 2;
2609 for(ptr
= data
->path
; ptr
< data
->path
+data
->path_len
; ++ptr
) {
2610 if(*ptr
== '%' && known_scheme
) {
2611 WCHAR val
= decode_pct_val(ptr
);
2613 if(is_unreserved(val
)) {
2615 uri
->canon_uri
[uri
->canon_len
] = val
;
2622 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2625 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
) &&
2626 !(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
)) {
2628 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2629 uri
->canon_len
+= 3;
2632 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2637 uri
->path_len
= uri
->canon_len
- uri
->path_start
;
2639 TRACE("(%p %p %x %d): Canonicalized opaque URI path %s len=%d\n", data
, uri
, flags
, computeOnly
,
2640 debugstr_wn(uri
->canon_uri
+uri
->path_start
, uri
->path_len
), uri
->path_len
);
2644 /* Determines how the URI represented by the parse_data should be canonicalized.
2646 * Essentially, if the parse_data represents an hierarchical URI then it calls
2647 * canonicalize_authority and the canonicalization functions for the path. If the
2648 * URI is opaque it canonicalizes the path of the URI.
2650 static BOOL
canonicalize_hierpart(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2651 if(!data
->is_opaque
) {
2652 /* "//" is only added for non-wildcard scheme types. */
2653 if(data
->scheme_type
!= URL_SCHEME_WILDCARD
) {
2655 INT pos
= uri
->canon_len
;
2657 uri
->canon_uri
[pos
] = '/';
2658 uri
->canon_uri
[pos
+1] = '/';
2660 uri
->canon_len
+= 2;
2663 if(!canonicalize_authority(data
, uri
, flags
, computeOnly
))
2666 /* TODO: Canonicalize the path of the URI. */
2667 if(!canonicalize_path_hierarchical(data
, uri
, flags
, computeOnly
))
2671 /* Opaque URI's don't have an authority. */
2672 uri
->userinfo_start
= uri
->userinfo_split
= -1;
2673 uri
->userinfo_len
= 0;
2674 uri
->host_start
= -1;
2676 uri
->host_type
= Uri_HOST_UNKNOWN
;
2677 uri
->has_port
= FALSE
;
2678 uri
->authority_start
= -1;
2679 uri
->authority_len
= 0;
2680 uri
->domain_offset
= -1;
2682 if(!canonicalize_path_opaque(data
, uri
, flags
, computeOnly
))
2686 if(uri
->path_start
> -1 && !computeOnly
)
2687 /* Finding file extensions happens for both types of URIs. */
2688 uri
->extension_offset
= find_file_extension(uri
->canon_uri
+uri
->path_start
, uri
->path_len
);
2690 uri
->extension_offset
= -1;
2695 /* Attempts to canonicalize the query string of the URI.
2697 * Things that happen:
2698 * 1) For known scheme types forbidden characters
2699 * are percent encoded, unless the NO_DECODE_EXTRA_INFO flag is set
2700 * or NO_ENCODE_FORBIDDEN_CHARACTERS is set.
2702 * 2) For known scheme types, percent encoded, unreserved characters
2703 * are decoded as long as the NO_DECODE_EXTRA_INFO flag isn't set.
2705 static BOOL
canonicalize_query(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2706 const WCHAR
*ptr
, *end
;
2707 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2710 uri
->query_start
= -1;
2715 uri
->query_start
= uri
->canon_len
;
2717 end
= data
->query
+data
->query_len
;
2718 for(ptr
= data
->query
; ptr
< end
; ++ptr
) {
2720 if(known_scheme
&& !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
2721 WCHAR val
= decode_pct_val(ptr
);
2722 if(is_unreserved(val
)) {
2724 uri
->canon_uri
[uri
->canon_len
] = val
;
2731 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
)) {
2732 if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) &&
2733 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
2735 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2736 uri
->canon_len
+= 3;
2742 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2746 uri
->query_len
= uri
->canon_len
- uri
->query_start
;
2749 TRACE("(%p %p %x %d): Canonicalized query string %s len=%d\n", data
, uri
, flags
,
2750 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->query_start
, uri
->query_len
),
2755 static BOOL
canonicalize_fragment(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2756 const WCHAR
*ptr
, *end
;
2757 const BOOL known_scheme
= data
->scheme_type
!= URL_SCHEME_UNKNOWN
;
2759 if(!data
->fragment
) {
2760 uri
->fragment_start
= -1;
2761 uri
->fragment_len
= 0;
2765 uri
->fragment_start
= uri
->canon_len
;
2767 end
= data
->fragment
+ data
->fragment_len
;
2768 for(ptr
= data
->fragment
; ptr
< end
; ++ptr
) {
2770 if(known_scheme
&& !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
2771 WCHAR val
= decode_pct_val(ptr
);
2772 if(is_unreserved(val
)) {
2774 uri
->canon_uri
[uri
->canon_len
] = val
;
2781 } else if(known_scheme
&& !is_unreserved(*ptr
) && !is_reserved(*ptr
)) {
2782 if(!(flags
& Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS
) &&
2783 !(flags
& Uri_CREATE_NO_DECODE_EXTRA_INFO
)) {
2785 pct_encode_val(*ptr
, uri
->canon_uri
+uri
->canon_len
);
2786 uri
->canon_len
+= 3;
2792 uri
->canon_uri
[uri
->canon_len
] = *ptr
;
2796 uri
->fragment_len
= uri
->canon_len
- uri
->fragment_start
;
2799 TRACE("(%p %p %x %d): Canonicalized fragment %s len=%d\n", data
, uri
, flags
,
2800 computeOnly
, debugstr_wn(uri
->canon_uri
+uri
->fragment_start
, uri
->fragment_len
),
2805 /* Canonicalizes the scheme information specified in the parse_data using the specified flags. */
2806 static BOOL
canonicalize_scheme(const parse_data
*data
, Uri
*uri
, DWORD flags
, BOOL computeOnly
) {
2807 uri
->scheme_start
= -1;
2808 uri
->scheme_len
= 0;
2811 /* The only type of URI that doesn't have to have a scheme is a relative
2814 if(!data
->is_relative
) {
2815 FIXME("(%p %p %x): Unable to determine the scheme type of %s.\n", data
,
2816 uri
, flags
, debugstr_w(data
->uri
));
2822 INT pos
= uri
->canon_len
;
2824 for(i
= 0; i
< data
->scheme_len
; ++i
) {
2825 /* Scheme name must be lower case after canonicalization. */
2826 uri
->canon_uri
[i
+ pos
] = tolowerW(data
->scheme
[i
]);
2829 uri
->canon_uri
[i
+ pos
] = ':';
2830 uri
->scheme_start
= pos
;
2832 TRACE("(%p %p %x): Canonicalized scheme=%s, len=%d.\n", data
, uri
, flags
,
2833 debugstr_wn(uri
->canon_uri
, uri
->scheme_len
), data
->scheme_len
);
2836 /* This happens in both computation modes. */
2837 uri
->canon_len
+= data
->scheme_len
+ 1;
2838 uri
->scheme_len
= data
->scheme_len
;
2843 /* Compute's what the length of the URI specified by the parse_data will be
2844 * after canonicalization occurs using the specified flags.
2846 * This function will return a non-zero value indicating the length of the canonicalized
2847 * URI, or -1 on error.
2849 static int compute_canonicalized_length(const parse_data
*data
, DWORD flags
) {
2852 memset(&uri
, 0, sizeof(Uri
));
2854 TRACE("(%p %x): Beginning to compute canonicalized length for URI %s\n", data
, flags
,
2855 debugstr_w(data
->uri
));
2857 if(!canonicalize_scheme(data
, &uri
, flags
, TRUE
)) {
2858 ERR("(%p %x): Failed to compute URI scheme length.\n", data
, flags
);
2862 if(!canonicalize_hierpart(data
, &uri
, flags
, TRUE
)) {
2863 ERR("(%p %x): Failed to compute URI hierpart length.\n", data
, flags
);
2867 if(!canonicalize_query(data
, &uri
, flags
, TRUE
)) {
2868 ERR("(%p %x): Failed to compute query string length.\n", data
, flags
);
2872 if(!canonicalize_fragment(data
, &uri
, flags
, TRUE
)) {
2873 ERR("(%p %x): Failed to compute fragment length.\n", data
, flags
);
2877 TRACE("(%p %x): Finished computing canonicalized URI length. length=%d\n", data
, flags
, uri
.canon_len
);
2879 return uri
.canon_len
;
2882 /* Canonicalizes the URI data specified in the parse_data, using the given flags. If the
2883 * canonicalization succeededs it will store all the canonicalization information
2884 * in the pointer to the Uri.
2886 * To canonicalize a URI this function first computes what the length of the URI
2887 * specified by the parse_data will be. Once this is done it will then perfom the actual
2888 * canonicalization of the URI.
2890 static HRESULT
canonicalize_uri(const parse_data
*data
, Uri
*uri
, DWORD flags
) {
2893 uri
->canon_uri
= NULL
;
2894 len
= uri
->canon_size
= uri
->canon_len
= 0;
2896 TRACE("(%p %p %x): beginning to canonicalize URI %s.\n", data
, uri
, flags
, debugstr_w(data
->uri
));
2898 /* First try to compute the length of the URI. */
2899 len
= compute_canonicalized_length(data
, flags
);
2901 ERR("(%p %p %x): Could not compute the canonicalized length of %s.\n", data
, uri
, flags
,
2902 debugstr_w(data
->uri
));
2903 return E_INVALIDARG
;
2906 uri
->canon_uri
= heap_alloc((len
+1)*sizeof(WCHAR
));
2908 return E_OUTOFMEMORY
;
2910 uri
->canon_size
= len
;
2911 if(!canonicalize_scheme(data
, uri
, flags
, FALSE
)) {
2912 ERR("(%p %p %x): Unable to canonicalize the scheme of the URI.\n", data
, uri
, flags
);
2913 heap_free(uri
->canon_uri
);
2914 return E_INVALIDARG
;
2916 uri
->scheme_type
= data
->scheme_type
;
2918 if(!canonicalize_hierpart(data
, uri
, flags
, FALSE
)) {
2919 ERR("(%p %p %x): Unable to canonicalize the heirpart of the URI\n", data
, uri
, flags
);
2920 heap_free(uri
->canon_uri
);
2921 return E_INVALIDARG
;
2924 if(!canonicalize_query(data
, uri
, flags
, FALSE
)) {
2925 ERR("(%p %p %x): Unable to canonicalize query string of the URI.\n",
2927 return E_INVALIDARG
;
2930 if(!canonicalize_fragment(data
, uri
, flags
, FALSE
)) {
2931 ERR("(%p %p %x): Unable to canonicalize fragment of the URI.\n",
2933 return E_INVALIDARG
;
2936 /* There's a possibility we didn't use all the space we allocated
2939 if(uri
->canon_len
< uri
->canon_size
) {
2940 /* This happens if the URI is hierarchical and dot
2941 * segments were removed from it's path.
2943 WCHAR
*tmp
= heap_realloc(uri
->canon_uri
, (uri
->canon_len
+1)*sizeof(WCHAR
));
2945 return E_OUTOFMEMORY
;
2947 uri
->canon_uri
= tmp
;
2948 uri
->canon_size
= uri
->canon_len
;
2951 uri
->canon_uri
[uri
->canon_len
] = '\0';
2952 TRACE("(%p %p %x): finished canonicalizing the URI. uri=%s\n", data
, uri
, flags
, debugstr_w(uri
->canon_uri
));
2957 #define URI(x) ((IUri*) &(x)->lpIUriVtbl)
2958 #define URIBUILDER(x) ((IUriBuilder*) &(x)->lpIUriBuilderVtbl)
2960 #define URI_THIS(iface) DEFINE_THIS(Uri, IUri, iface)
2962 static HRESULT WINAPI
Uri_QueryInterface(IUri
*iface
, REFIID riid
, void **ppv
)
2964 Uri
*This
= URI_THIS(iface
);
2966 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
2967 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
2969 }else if(IsEqualGUID(&IID_IUri
, riid
)) {
2970 TRACE("(%p)->(IID_IUri %p)\n", This
, ppv
);
2973 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
2975 return E_NOINTERFACE
;
2978 IUnknown_AddRef((IUnknown
*)*ppv
);
2982 static ULONG WINAPI
Uri_AddRef(IUri
*iface
)
2984 Uri
*This
= URI_THIS(iface
);
2985 LONG ref
= InterlockedIncrement(&This
->ref
);
2987 TRACE("(%p) ref=%d\n", This
, ref
);
2992 static ULONG WINAPI
Uri_Release(IUri
*iface
)
2994 Uri
*This
= URI_THIS(iface
);
2995 LONG ref
= InterlockedDecrement(&This
->ref
);
2997 TRACE("(%p) ref=%d\n", This
, ref
);
3000 SysFreeString(This
->raw_uri
);
3001 heap_free(This
->canon_uri
);
3008 static HRESULT WINAPI
Uri_GetPropertyBSTR(IUri
*iface
, Uri_PROPERTY uriProp
, BSTR
*pbstrProperty
, DWORD dwFlags
)
3010 Uri
*This
= URI_THIS(iface
);
3012 TRACE("(%p)->(%d %p %x)\n", This
, uriProp
, pbstrProperty
, dwFlags
);
3017 if(uriProp
> Uri_PROPERTY_STRING_LAST
) {
3018 /* Windows allocates an empty BSTR for invalid Uri_PROPERTY's. */
3019 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3020 if(!(*pbstrProperty
))
3021 return E_OUTOFMEMORY
;
3023 /* It only returns S_FALSE for the ZONE property... */
3024 if(uriProp
== Uri_PROPERTY_ZONE
)
3030 /* Don't have support for flags yet. */
3032 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pbstrProperty
, dwFlags
);
3037 case Uri_PROPERTY_ABSOLUTE_URI
:
3038 *pbstrProperty
= SysAllocString(This
->canon_uri
);
3040 if(!(*pbstrProperty
))
3041 hres
= E_OUTOFMEMORY
;
3046 case Uri_PROPERTY_AUTHORITY
:
3047 if(This
->authority_start
> -1) {
3048 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->authority_start
, This
->authority_len
);
3051 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3055 if(!(*pbstrProperty
))
3056 hres
= E_OUTOFMEMORY
;
3059 case Uri_PROPERTY_DISPLAY_URI
:
3060 /* The Display URI contains everything except for the userinfo for known
3063 if(This
->scheme_type
!= URL_SCHEME_UNKNOWN
&& This
->userinfo_start
> -1) {
3064 *pbstrProperty
= SysAllocStringLen(NULL
, This
->canon_len
-This
->userinfo_len
);
3066 if(*pbstrProperty
) {
3067 /* Copy everything before the userinfo over. */
3068 memcpy(*pbstrProperty
, This
->canon_uri
, This
->userinfo_start
*sizeof(WCHAR
));
3069 /* Copy everything after the userinfo over. */
3070 memcpy(*pbstrProperty
+This
->userinfo_start
,
3071 This
->canon_uri
+This
->userinfo_start
+This
->userinfo_len
+1,
3072 (This
->canon_len
-(This
->userinfo_start
+This
->userinfo_len
+1))*sizeof(WCHAR
));
3075 *pbstrProperty
= SysAllocString(This
->canon_uri
);
3077 if(!(*pbstrProperty
))
3078 hres
= E_OUTOFMEMORY
;
3083 case Uri_PROPERTY_DOMAIN
:
3084 if(This
->domain_offset
> -1) {
3085 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->host_start
+This
->domain_offset
,
3086 This
->host_len
-This
->domain_offset
);
3089 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3093 if(!(*pbstrProperty
))
3094 hres
= E_OUTOFMEMORY
;
3097 case Uri_PROPERTY_EXTENSION
:
3098 if(This
->extension_offset
> -1) {
3099 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->path_start
+This
->extension_offset
,
3100 This
->path_len
-This
->extension_offset
);
3103 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3107 if(!(*pbstrProperty
))
3108 hres
= E_OUTOFMEMORY
;
3111 case Uri_PROPERTY_FRAGMENT
:
3112 if(This
->fragment_start
> -1) {
3113 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->fragment_start
, This
->fragment_len
);
3116 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3120 if(!(*pbstrProperty
))
3121 hres
= E_OUTOFMEMORY
;
3124 case Uri_PROPERTY_HOST
:
3125 if(This
->host_start
> -1) {
3126 /* The '[' and ']' aren't included for IPv6 addresses. */
3127 if(This
->host_type
== Uri_HOST_IPV6
)
3128 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->host_start
+1, This
->host_len
-2);
3130 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->host_start
, This
->host_len
);
3134 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3138 if(!(*pbstrProperty
))
3139 hres
= E_OUTOFMEMORY
;
3142 case Uri_PROPERTY_PASSWORD
:
3143 if(This
->userinfo_split
> -1) {
3144 *pbstrProperty
= SysAllocStringLen(
3145 This
->canon_uri
+This
->userinfo_start
+This
->userinfo_split
+1,
3146 This
->userinfo_len
-This
->userinfo_split
-1);
3149 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3153 if(!(*pbstrProperty
))
3154 return E_OUTOFMEMORY
;
3157 case Uri_PROPERTY_PATH
:
3158 if(This
->path_start
> -1) {
3159 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->path_start
, This
->path_len
);
3162 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3166 if(!(*pbstrProperty
))
3167 hres
= E_OUTOFMEMORY
;
3170 case Uri_PROPERTY_PATH_AND_QUERY
:
3171 if(This
->path_start
> -1) {
3172 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->path_start
, This
->path_len
+This
->query_len
);
3174 } else if(This
->query_start
> -1) {
3175 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->query_start
, This
->query_len
);
3178 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3182 if(!(*pbstrProperty
))
3183 hres
= E_OUTOFMEMORY
;
3186 case Uri_PROPERTY_QUERY
:
3187 if(This
->query_start
> -1) {
3188 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->query_start
, This
->query_len
);
3191 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3195 if(!(*pbstrProperty
))
3196 hres
= E_OUTOFMEMORY
;
3199 case Uri_PROPERTY_RAW_URI
:
3200 *pbstrProperty
= SysAllocString(This
->raw_uri
);
3201 if(!(*pbstrProperty
))
3202 hres
= E_OUTOFMEMORY
;
3206 case Uri_PROPERTY_SCHEME_NAME
:
3207 if(This
->scheme_start
> -1) {
3208 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+ This
->scheme_start
, This
->scheme_len
);
3211 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3215 if(!(*pbstrProperty
))
3216 hres
= E_OUTOFMEMORY
;
3219 case Uri_PROPERTY_USER_INFO
:
3220 if(This
->userinfo_start
> -1) {
3221 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+This
->userinfo_start
, This
->userinfo_len
);
3224 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3228 if(!(*pbstrProperty
))
3229 hres
= E_OUTOFMEMORY
;
3232 case Uri_PROPERTY_USER_NAME
:
3233 if(This
->userinfo_start
> -1) {
3234 /* If userinfo_split is set, that means a password exists
3235 * so the username is only from userinfo_start to userinfo_split.
3237 if(This
->userinfo_split
> -1) {
3238 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+ This
->userinfo_start
, This
->userinfo_split
);
3241 *pbstrProperty
= SysAllocStringLen(This
->canon_uri
+ This
->userinfo_start
, This
->userinfo_len
);
3245 *pbstrProperty
= SysAllocStringLen(NULL
, 0);
3249 if(!(*pbstrProperty
))
3250 return E_OUTOFMEMORY
;
3254 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pbstrProperty
, dwFlags
);
3261 static HRESULT WINAPI
Uri_GetPropertyLength(IUri
*iface
, Uri_PROPERTY uriProp
, DWORD
*pcchProperty
, DWORD dwFlags
)
3263 Uri
*This
= URI_THIS(iface
);
3265 TRACE("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3268 return E_INVALIDARG
;
3270 /* Can only return a length for a property if it's a string. */
3271 if(uriProp
> Uri_PROPERTY_STRING_LAST
)
3272 return E_INVALIDARG
;
3274 /* Don't have support for flags yet. */
3276 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3281 case Uri_PROPERTY_ABSOLUTE_URI
:
3282 *pcchProperty
= This
->canon_len
;
3285 case Uri_PROPERTY_AUTHORITY
:
3286 *pcchProperty
= This
->authority_len
;
3287 hres
= (This
->authority_start
> -1) ? S_OK
: S_FALSE
;
3289 case Uri_PROPERTY_DISPLAY_URI
:
3290 if(This
->scheme_type
!= URL_SCHEME_UNKNOWN
&& This
->userinfo_start
> -1)
3291 *pcchProperty
= This
->canon_len
-This
->userinfo_len
-1;
3293 *pcchProperty
= This
->canon_len
;
3297 case Uri_PROPERTY_DOMAIN
:
3298 if(This
->domain_offset
> -1)
3299 *pcchProperty
= This
->host_len
- This
->domain_offset
;
3303 hres
= (This
->domain_offset
> -1) ? S_OK
: S_FALSE
;
3305 case Uri_PROPERTY_EXTENSION
:
3306 if(This
->extension_offset
> -1) {
3307 *pcchProperty
= This
->path_len
- This
->extension_offset
;
3315 case Uri_PROPERTY_FRAGMENT
:
3316 *pcchProperty
= This
->fragment_len
;
3317 hres
= (This
->fragment_start
> -1) ? S_OK
: S_FALSE
;
3319 case Uri_PROPERTY_HOST
:
3320 *pcchProperty
= This
->host_len
;
3322 /* '[' and ']' aren't included in the length. */
3323 if(This
->host_type
== Uri_HOST_IPV6
)
3326 hres
= (This
->host_start
> -1) ? S_OK
: S_FALSE
;
3328 case Uri_PROPERTY_PASSWORD
:
3329 *pcchProperty
= (This
->userinfo_split
> -1) ? This
->userinfo_len
-This
->userinfo_split
-1 : 0;
3330 hres
= (This
->userinfo_split
> -1) ? S_OK
: S_FALSE
;
3332 case Uri_PROPERTY_PATH
:
3333 *pcchProperty
= This
->path_len
;
3334 hres
= (This
->path_start
> -1) ? S_OK
: S_FALSE
;
3336 case Uri_PROPERTY_PATH_AND_QUERY
:
3337 *pcchProperty
= This
->path_len
+This
->query_len
;
3338 hres
= (This
->path_start
> -1 || This
->query_start
> -1) ? S_OK
: S_FALSE
;
3340 case Uri_PROPERTY_QUERY
:
3341 *pcchProperty
= This
->query_len
;
3342 hres
= (This
->query_start
> -1) ? S_OK
: S_FALSE
;
3344 case Uri_PROPERTY_RAW_URI
:
3345 *pcchProperty
= SysStringLen(This
->raw_uri
);
3348 case Uri_PROPERTY_SCHEME_NAME
:
3349 *pcchProperty
= This
->scheme_len
;
3350 hres
= (This
->scheme_start
> -1) ? S_OK
: S_FALSE
;
3352 case Uri_PROPERTY_USER_INFO
:
3353 *pcchProperty
= This
->userinfo_len
;
3354 hres
= (This
->userinfo_start
> -1) ? S_OK
: S_FALSE
;
3356 case Uri_PROPERTY_USER_NAME
:
3357 *pcchProperty
= (This
->userinfo_split
> -1) ? This
->userinfo_split
: This
->userinfo_len
;
3358 hres
= (This
->userinfo_start
> -1) ? S_OK
: S_FALSE
;
3361 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3368 static HRESULT WINAPI
Uri_GetPropertyDWORD(IUri
*iface
, Uri_PROPERTY uriProp
, DWORD
*pcchProperty
, DWORD dwFlags
)
3370 Uri
*This
= URI_THIS(iface
);
3373 TRACE("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3376 return E_INVALIDARG
;
3378 /* Microsoft's implementation for the ZONE property of a URI seems to be lacking...
3379 * From what I can tell, instead of checking which URLZONE the URI belongs to it
3380 * simply assigns URLZONE_INVALID and returns E_NOTIMPL. This also applies to the GetZone
3383 if(uriProp
== Uri_PROPERTY_ZONE
) {
3384 *pcchProperty
= URLZONE_INVALID
;
3388 if(uriProp
< Uri_PROPERTY_DWORD_START
) {
3390 return E_INVALIDARG
;
3394 case Uri_PROPERTY_HOST_TYPE
:
3395 *pcchProperty
= This
->host_type
;
3398 case Uri_PROPERTY_PORT
:
3399 if(!This
->has_port
) {
3403 *pcchProperty
= This
->port
;
3408 case Uri_PROPERTY_SCHEME
:
3409 *pcchProperty
= This
->scheme_type
;
3413 FIXME("(%p)->(%d %p %x)\n", This
, uriProp
, pcchProperty
, dwFlags
);
3420 static HRESULT WINAPI
Uri_HasProperty(IUri
*iface
, Uri_PROPERTY uriProp
, BOOL
*pfHasProperty
)
3422 Uri
*This
= URI_THIS(iface
);
3423 TRACE("(%p)->(%d %p)\n", This
, uriProp
, pfHasProperty
);
3426 return E_INVALIDARG
;
3429 case Uri_PROPERTY_ABSOLUTE_URI
:
3430 *pfHasProperty
= TRUE
;
3432 case Uri_PROPERTY_AUTHORITY
:
3433 *pfHasProperty
= This
->authority_start
> -1;
3435 case Uri_PROPERTY_DISPLAY_URI
:
3436 *pfHasProperty
= TRUE
;
3438 case Uri_PROPERTY_DOMAIN
:
3439 *pfHasProperty
= This
->domain_offset
> -1;
3441 case Uri_PROPERTY_EXTENSION
:
3442 *pfHasProperty
= This
->extension_offset
> -1;
3444 case Uri_PROPERTY_FRAGMENT
:
3445 *pfHasProperty
= This
->fragment_start
> -1;
3447 case Uri_PROPERTY_HOST
:
3448 *pfHasProperty
= This
->host_start
> -1;
3450 case Uri_PROPERTY_PASSWORD
:
3451 *pfHasProperty
= This
->userinfo_split
> -1;
3453 case Uri_PROPERTY_PATH
:
3454 *pfHasProperty
= This
->path_start
> -1;
3456 case Uri_PROPERTY_PATH_AND_QUERY
:
3457 *pfHasProperty
= (This
->path_start
> -1 || This
->query_start
> -1);
3459 case Uri_PROPERTY_QUERY
:
3460 *pfHasProperty
= This
->query_start
> -1;
3462 case Uri_PROPERTY_RAW_URI
:
3463 *pfHasProperty
= TRUE
;
3465 case Uri_PROPERTY_SCHEME_NAME
:
3466 *pfHasProperty
= This
->scheme_start
> -1;
3468 case Uri_PROPERTY_USER_INFO
:
3469 case Uri_PROPERTY_USER_NAME
:
3470 *pfHasProperty
= This
->userinfo_start
> -1;
3472 case Uri_PROPERTY_HOST_TYPE
:
3473 *pfHasProperty
= TRUE
;
3475 case Uri_PROPERTY_PORT
:
3476 *pfHasProperty
= This
->has_port
;
3478 case Uri_PROPERTY_SCHEME
:
3479 *pfHasProperty
= TRUE
;
3481 case Uri_PROPERTY_ZONE
:
3482 *pfHasProperty
= FALSE
;
3485 FIXME("(%p)->(%d %p): Unsupported property type.\n", This
, uriProp
, pfHasProperty
);
3492 static HRESULT WINAPI
Uri_GetAbsoluteUri(IUri
*iface
, BSTR
*pstrAbsoluteUri
)
3494 TRACE("(%p)->(%p)\n", iface
, pstrAbsoluteUri
);
3495 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_ABSOLUTE_URI
, pstrAbsoluteUri
, 0);
3498 static HRESULT WINAPI
Uri_GetAuthority(IUri
*iface
, BSTR
*pstrAuthority
)
3500 TRACE("(%p)->(%p)\n", iface
, pstrAuthority
);
3501 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_AUTHORITY
, pstrAuthority
, 0);
3504 static HRESULT WINAPI
Uri_GetDisplayUri(IUri
*iface
, BSTR
*pstrDisplayUri
)
3506 TRACE("(%p)->(%p)\n", iface
, pstrDisplayUri
);
3507 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_DISPLAY_URI
, pstrDisplayUri
, 0);
3510 static HRESULT WINAPI
Uri_GetDomain(IUri
*iface
, BSTR
*pstrDomain
)
3512 TRACE("(%p)->(%p)\n", iface
, pstrDomain
);
3513 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_DOMAIN
, pstrDomain
, 0);
3516 static HRESULT WINAPI
Uri_GetExtension(IUri
*iface
, BSTR
*pstrExtension
)
3518 TRACE("(%p)->(%p)\n", iface
, pstrExtension
);
3519 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_EXTENSION
, pstrExtension
, 0);
3522 static HRESULT WINAPI
Uri_GetFragment(IUri
*iface
, BSTR
*pstrFragment
)
3524 TRACE("(%p)->(%p)\n", iface
, pstrFragment
);
3525 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_FRAGMENT
, pstrFragment
, 0);
3528 static HRESULT WINAPI
Uri_GetHost(IUri
*iface
, BSTR
*pstrHost
)
3530 TRACE("(%p)->(%p)\n", iface
, pstrHost
);
3531 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_HOST
, pstrHost
, 0);
3534 static HRESULT WINAPI
Uri_GetPassword(IUri
*iface
, BSTR
*pstrPassword
)
3536 TRACE("(%p)->(%p)\n", iface
, pstrPassword
);
3537 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_PASSWORD
, pstrPassword
, 0);
3540 static HRESULT WINAPI
Uri_GetPath(IUri
*iface
, BSTR
*pstrPath
)
3542 TRACE("(%p)->(%p)\n", iface
, pstrPath
);
3543 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_PATH
, pstrPath
, 0);
3546 static HRESULT WINAPI
Uri_GetPathAndQuery(IUri
*iface
, BSTR
*pstrPathAndQuery
)
3548 TRACE("(%p)->(%p)\n", iface
, pstrPathAndQuery
);
3549 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_PATH_AND_QUERY
, pstrPathAndQuery
, 0);
3552 static HRESULT WINAPI
Uri_GetQuery(IUri
*iface
, BSTR
*pstrQuery
)
3554 TRACE("(%p)->(%p)\n", iface
, pstrQuery
);
3555 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_QUERY
, pstrQuery
, 0);
3558 static HRESULT WINAPI
Uri_GetRawUri(IUri
*iface
, BSTR
*pstrRawUri
)
3560 Uri
*This
= URI_THIS(iface
);
3561 TRACE("(%p)->(%p)\n", This
, pstrRawUri
);
3563 /* Just forward the call to GetPropertyBSTR. */
3564 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_RAW_URI
, pstrRawUri
, 0);
3567 static HRESULT WINAPI
Uri_GetSchemeName(IUri
*iface
, BSTR
*pstrSchemeName
)
3569 Uri
*This
= URI_THIS(iface
);
3570 TRACE("(%p)->(%p)\n", This
, pstrSchemeName
);
3571 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_SCHEME_NAME
, pstrSchemeName
, 0);
3574 static HRESULT WINAPI
Uri_GetUserInfo(IUri
*iface
, BSTR
*pstrUserInfo
)
3576 TRACE("(%p)->(%p)\n", iface
, pstrUserInfo
);
3577 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_USER_INFO
, pstrUserInfo
, 0);
3580 static HRESULT WINAPI
Uri_GetUserName(IUri
*iface
, BSTR
*pstrUserName
)
3582 TRACE("(%p)->(%p)\n", iface
, pstrUserName
);
3583 return Uri_GetPropertyBSTR(iface
, Uri_PROPERTY_USER_NAME
, pstrUserName
, 0);
3586 static HRESULT WINAPI
Uri_GetHostType(IUri
*iface
, DWORD
*pdwHostType
)
3588 TRACE("(%p)->(%p)\n", iface
, pdwHostType
);
3589 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_HOST_TYPE
, pdwHostType
, 0);
3592 static HRESULT WINAPI
Uri_GetPort(IUri
*iface
, DWORD
*pdwPort
)
3594 TRACE("(%p)->(%p)\n", iface
, pdwPort
);
3595 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_PORT
, pdwPort
, 0);
3598 static HRESULT WINAPI
Uri_GetScheme(IUri
*iface
, DWORD
*pdwScheme
)
3600 Uri
*This
= URI_THIS(iface
);
3601 TRACE("(%p)->(%p)\n", This
, pdwScheme
);
3602 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_SCHEME
, pdwScheme
, 0);
3605 static HRESULT WINAPI
Uri_GetZone(IUri
*iface
, DWORD
*pdwZone
)
3607 TRACE("(%p)->(%p)\n", iface
, pdwZone
);
3608 return Uri_GetPropertyDWORD(iface
, Uri_PROPERTY_ZONE
,pdwZone
, 0);
3611 static HRESULT WINAPI
Uri_GetProperties(IUri
*iface
, DWORD
*pdwProperties
)
3613 Uri
*This
= URI_THIS(iface
);
3614 TRACE("(%p)->(%p)\n", This
, pdwProperties
);
3617 return E_INVALIDARG
;
3619 /* All URIs have these. */
3620 *pdwProperties
= Uri_HAS_ABSOLUTE_URI
|Uri_HAS_DISPLAY_URI
|Uri_HAS_RAW_URI
|
3621 Uri_HAS_SCHEME
|Uri_HAS_HOST_TYPE
;
3623 if(This
->scheme_start
> -1)
3624 *pdwProperties
|= Uri_HAS_SCHEME_NAME
;
3626 if(This
->authority_start
> -1) {
3627 *pdwProperties
|= Uri_HAS_AUTHORITY
;
3628 if(This
->userinfo_start
> -1)
3629 *pdwProperties
|= Uri_HAS_USER_INFO
|Uri_HAS_USER_NAME
;
3630 if(This
->userinfo_split
> -1)
3631 *pdwProperties
|= Uri_HAS_PASSWORD
;
3632 if(This
->host_start
> -1)
3633 *pdwProperties
|= Uri_HAS_HOST
;
3634 if(This
->domain_offset
> -1)
3635 *pdwProperties
|= Uri_HAS_DOMAIN
;
3637 *pdwProperties
|= Uri_HAS_PORT
;
3640 if(This
->path_start
> -1)
3641 *pdwProperties
|= Uri_HAS_PATH
|Uri_HAS_PATH_AND_QUERY
;
3642 if(This
->query_start
> -1)
3643 *pdwProperties
|= Uri_HAS_QUERY
|Uri_HAS_PATH_AND_QUERY
;
3645 if(This
->extension_offset
> -1)
3646 *pdwProperties
|= Uri_HAS_EXTENSION
;
3648 if(This
->fragment_start
> -1)
3649 *pdwProperties
|= Uri_HAS_FRAGMENT
;
3654 static HRESULT WINAPI
Uri_IsEqual(IUri
*iface
, IUri
*pUri
, BOOL
*pfEqual
)
3656 Uri
*This
= URI_THIS(iface
);
3657 TRACE("(%p)->(%p %p)\n", This
, pUri
, pfEqual
);
3665 /* For some reason Windows returns S_OK here... */
3669 FIXME("(%p)->(%p %p)\n", This
, pUri
, pfEqual
);
3675 static const IUriVtbl UriVtbl
= {
3679 Uri_GetPropertyBSTR
,
3680 Uri_GetPropertyLength
,
3681 Uri_GetPropertyDWORD
,
3692 Uri_GetPathAndQuery
,
3706 /***********************************************************************
3707 * CreateUri (urlmon.@)
3709 HRESULT WINAPI
CreateUri(LPCWSTR pwzURI
, DWORD dwFlags
, DWORD_PTR dwReserved
, IUri
**ppURI
)
3715 TRACE("(%s %x %x %p)\n", debugstr_w(pwzURI
), dwFlags
, (DWORD
)dwReserved
, ppURI
);
3718 return E_INVALIDARG
;
3722 return E_INVALIDARG
;
3725 ret
= heap_alloc(sizeof(Uri
));
3727 return E_OUTOFMEMORY
;
3729 ret
->lpIUriVtbl
= &UriVtbl
;
3732 /* Create a copy of pwzURI and store it as the raw_uri. */
3733 ret
->raw_uri
= SysAllocString(pwzURI
);
3736 return E_OUTOFMEMORY
;
3739 memset(&data
, 0, sizeof(parse_data
));
3740 data
.uri
= ret
->raw_uri
;
3742 /* Validate and parse the URI into it's components. */
3743 if(!parse_uri(&data
, dwFlags
)) {
3744 /* Encountered an unsupported or invalid URI */
3745 SysFreeString(ret
->raw_uri
);
3748 return E_INVALIDARG
;
3751 /* Canonicalize the URI. */
3752 hr
= canonicalize_uri(&data
, ret
, dwFlags
);
3754 SysFreeString(ret
->raw_uri
);
3764 #define URIBUILDER_THIS(iface) DEFINE_THIS(UriBuilder, IUriBuilder, iface)
3766 static HRESULT WINAPI
UriBuilder_QueryInterface(IUriBuilder
*iface
, REFIID riid
, void **ppv
)
3768 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3770 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
3771 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
3772 *ppv
= URIBUILDER(This
);
3773 }else if(IsEqualGUID(&IID_IUriBuilder
, riid
)) {
3774 TRACE("(%p)->(IID_IUri %p)\n", This
, ppv
);
3775 *ppv
= URIBUILDER(This
);
3777 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
3779 return E_NOINTERFACE
;
3782 IUnknown_AddRef((IUnknown
*)*ppv
);
3786 static ULONG WINAPI
UriBuilder_AddRef(IUriBuilder
*iface
)
3788 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3789 LONG ref
= InterlockedIncrement(&This
->ref
);
3791 TRACE("(%p) ref=%d\n", This
, ref
);
3796 static ULONG WINAPI
UriBuilder_Release(IUriBuilder
*iface
)
3798 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3799 LONG ref
= InterlockedDecrement(&This
->ref
);
3801 TRACE("(%p) ref=%d\n", This
, ref
);
3809 static HRESULT WINAPI
UriBuilder_CreateUriSimple(IUriBuilder
*iface
,
3810 DWORD dwAllowEncodingPropertyMask
,
3811 DWORD_PTR dwReserved
,
3814 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3815 FIXME("(%p)->(%d %d %p)\n", This
, dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
3819 static HRESULT WINAPI
UriBuilder_CreateUri(IUriBuilder
*iface
,
3820 DWORD dwCreateFlags
,
3821 DWORD dwAllowEncodingPropertyMask
,
3822 DWORD_PTR dwReserved
,
3825 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3826 FIXME("(%p)->(0x%08x %d %d %p)\n", This
, dwCreateFlags
, dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
3830 static HRESULT WINAPI
UriBuilder_CreateUriWithFlags(IUriBuilder
*iface
,
3831 DWORD dwCreateFlags
,
3832 DWORD dwUriBuilderFlags
,
3833 DWORD dwAllowEncodingPropertyMask
,
3834 DWORD_PTR dwReserved
,
3837 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3838 FIXME("(%p)->(0x%08x 0x%08x %d %d %p)\n", This
, dwCreateFlags
, dwUriBuilderFlags
,
3839 dwAllowEncodingPropertyMask
, (DWORD
)dwReserved
, ppIUri
);
3843 static HRESULT WINAPI
UriBuilder_GetIUri(IUriBuilder
*iface
, IUri
**ppIUri
)
3845 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3846 FIXME("(%p)->(%p)\n", This
, ppIUri
);
3850 static HRESULT WINAPI
UriBuilder_SetIUri(IUriBuilder
*iface
, IUri
*pIUri
)
3852 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3853 FIXME("(%p)->(%p)\n", This
, pIUri
);
3857 static HRESULT WINAPI
UriBuilder_GetFragment(IUriBuilder
*iface
, DWORD
*pcchFragment
, LPCWSTR
*ppwzFragment
)
3859 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3860 FIXME("(%p)->(%p %p)\n", This
, pcchFragment
, ppwzFragment
);
3864 static HRESULT WINAPI
UriBuilder_GetHost(IUriBuilder
*iface
, DWORD
*pcchHost
, LPCWSTR
*ppwzHost
)
3866 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3867 FIXME("(%p)->(%p %p)\n", This
, pcchHost
, ppwzHost
);
3871 static HRESULT WINAPI
UriBuilder_GetPassword(IUriBuilder
*iface
, DWORD
*pcchPassword
, LPCWSTR
*ppwzPassword
)
3873 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3874 FIXME("(%p)->(%p %p)\n", This
, pcchPassword
, ppwzPassword
);
3878 static HRESULT WINAPI
UriBuilder_GetPath(IUriBuilder
*iface
, DWORD
*pcchPath
, LPCWSTR
*ppwzPath
)
3880 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3881 FIXME("(%p)->(%p %p)\n", This
, pcchPath
, ppwzPath
);
3885 static HRESULT WINAPI
UriBuilder_GetPort(IUriBuilder
*iface
, BOOL
*pfHasPort
, DWORD
*pdwPort
)
3887 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3888 FIXME("(%p)->(%p %p)\n", This
, pfHasPort
, pdwPort
);
3892 static HRESULT WINAPI
UriBuilder_GetQuery(IUriBuilder
*iface
, DWORD
*pcchQuery
, LPCWSTR
*ppwzQuery
)
3894 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3895 FIXME("(%p)->(%p %p)\n", This
, pcchQuery
, ppwzQuery
);
3899 static HRESULT WINAPI
UriBuilder_GetSchemeName(IUriBuilder
*iface
, DWORD
*pcchSchemeName
, LPCWSTR
*ppwzSchemeName
)
3901 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3902 FIXME("(%p)->(%p %p)\n", This
, pcchSchemeName
, ppwzSchemeName
);
3906 static HRESULT WINAPI
UriBuilder_GetUserName(IUriBuilder
*iface
, DWORD
*pcchUserName
, LPCWSTR
*ppwzUserName
)
3908 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3909 FIXME("(%p)->(%p %p)\n", This
, pcchUserName
, ppwzUserName
);
3913 static HRESULT WINAPI
UriBuilder_SetFragment(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3915 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3916 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3920 static HRESULT WINAPI
UriBuilder_SetHost(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3922 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3923 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3927 static HRESULT WINAPI
UriBuilder_SetPassword(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3929 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3930 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3934 static HRESULT WINAPI
UriBuilder_SetPath(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3936 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3937 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3941 static HRESULT WINAPI
UriBuilder_SetPort(IUriBuilder
*iface
, BOOL fHasPort
, DWORD dwNewValue
)
3943 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3944 FIXME("(%p)->(%d %d)\n", This
, fHasPort
, dwNewValue
);
3948 static HRESULT WINAPI
UriBuilder_SetQuery(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3950 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3951 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3955 static HRESULT WINAPI
UriBuilder_SetSchemeName(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3957 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3958 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3962 static HRESULT WINAPI
UriBuilder_SetUserName(IUriBuilder
*iface
, LPCWSTR pwzNewValue
)
3964 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3965 FIXME("(%p)->(%s)\n", This
, debugstr_w(pwzNewValue
));
3969 static HRESULT WINAPI
UriBuilder_RemoveProperties(IUriBuilder
*iface
, DWORD dwPropertyMask
)
3971 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3972 FIXME("(%p)->(0x%08x)\n", This
, dwPropertyMask
);
3976 static HRESULT WINAPI
UriBuilder_HasBeenModified(IUriBuilder
*iface
, BOOL
*pfModified
)
3978 UriBuilder
*This
= URIBUILDER_THIS(iface
);
3979 FIXME("(%p)->(%p)\n", This
, pfModified
);
3983 #undef URIBUILDER_THIS
3985 static const IUriBuilderVtbl UriBuilderVtbl
= {
3986 UriBuilder_QueryInterface
,
3989 UriBuilder_CreateUriSimple
,
3990 UriBuilder_CreateUri
,
3991 UriBuilder_CreateUriWithFlags
,
3994 UriBuilder_GetFragment
,
3996 UriBuilder_GetPassword
,
3999 UriBuilder_GetQuery
,
4000 UriBuilder_GetSchemeName
,
4001 UriBuilder_GetUserName
,
4002 UriBuilder_SetFragment
,
4004 UriBuilder_SetPassword
,
4007 UriBuilder_SetQuery
,
4008 UriBuilder_SetSchemeName
,
4009 UriBuilder_SetUserName
,
4010 UriBuilder_RemoveProperties
,
4011 UriBuilder_HasBeenModified
,
4014 /***********************************************************************
4015 * CreateIUriBuilder (urlmon.@)
4017 HRESULT WINAPI
CreateIUriBuilder(IUri
*pIUri
, DWORD dwFlags
, DWORD_PTR dwReserved
, IUriBuilder
**ppIUriBuilder
)
4021 TRACE("(%p %x %x %p)\n", pIUri
, dwFlags
, (DWORD
)dwReserved
, ppIUriBuilder
);
4023 ret
= heap_alloc(sizeof(UriBuilder
));
4025 return E_OUTOFMEMORY
;
4027 ret
->lpIUriBuilderVtbl
= &UriBuilderVtbl
;
4030 *ppIUriBuilder
= URIBUILDER(ret
);