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;
67 const IUriBuilderVtbl *lpIUriBuilderVtbl;
77 /* IPv6 addresses can hold up to 8 h16 components. */
81 /* An IPv6 can have 1 elision ("::"). */
84 /* An IPv6 can contain 1 IPv4 address as the last 32bits of the address. */
97 BOOL has_implicit_scheme;
103 URL_SCHEME scheme_type;
105 const WCHAR *userinfo;
111 Uri_HOST_TYPE host_type;
114 ipv6_address ipv6_address;
124 static const CHAR hexDigits[] = "0123456789ABCDEF";
126 /* List of scheme types/scheme names that are recognized by the IUri interface as of IE 7. */
127 static const struct {
129 WCHAR scheme_name[16];
130 } recognized_schemes[] = {
131 {URL_SCHEME_FTP, {'f','t','p',0}},
132 {URL_SCHEME_HTTP, {'h','t','t','p',0}},
133 {URL_SCHEME_GOPHER, {'g','o','p','h','e','r',0}},
134 {URL_SCHEME_MAILTO, {'m','a','i','l','t','o',0}},
135 {URL_SCHEME_NEWS, {'n','e','w','s',0}},
136 {URL_SCHEME_NNTP, {'n','n','t','p',0}},
137 {URL_SCHEME_TELNET, {'t','e','l','n','e','t',0}},
138 {URL_SCHEME_WAIS, {'w','a','i','s',0}},
139 {URL_SCHEME_FILE, {'f','i','l','e',0}},
140 {URL_SCHEME_MK, {'m','k',0}},
141 {URL_SCHEME_HTTPS, {'h','t','t','p','s',0}},
142 {URL_SCHEME_SHELL, {'s','h','e','l','l',0}},
143 {URL_SCHEME_SNEWS, {'s','n','e','w','s',0}},
144 {URL_SCHEME_LOCAL, {'l','o','c','a','l',0}},
145 {URL_SCHEME_JAVASCRIPT, {'j','a','v','a','s','c','r','i','p','t',0}},
146 {URL_SCHEME_VBSCRIPT, {'v','b','s','c','r','i','p','t',0}},
147 {URL_SCHEME_ABOUT, {'a','b','o','u','t',0}},
148 {URL_SCHEME_RES, {'r','e','s',0}},
149 {URL_SCHEME_MSSHELLROOTED, {'m','s','-','s','h','e','l','l','-','r','o','o','t','e','d',0}},
150 {URL_SCHEME_MSSHELLIDLIST, {'m','s','-','s','h','e','l','l','-','i','d','l','i','s','t',0}},
151 {URL_SCHEME_MSHELP, {'h','c','p',0}},
152 {URL_SCHEME_WILDCARD, {'*',0}}
155 /* List of default ports Windows recognizes. */
156 static const struct {
159 } default_ports[] = {
160 {URL_SCHEME_FTP, 21},
161 {URL_SCHEME_HTTP, 80},
162 {URL_SCHEME_GOPHER, 70},
163 {URL_SCHEME_NNTP, 119},
164 {URL_SCHEME_TELNET, 23},
165 {URL_SCHEME_WAIS, 210},
166 {URL_SCHEME_HTTPS, 443},
169 /* List of 3 character top level domain names Windows seems to recognize.
170 * There might be more, but, these are the only ones I've found so far.
172 static const struct {
174 } recognized_tlds[] = {
184 static inline BOOL is_alpha(WCHAR val) {
185 return ((val >= 'a' && val <= 'z') || (val >= 'A' && val <= 'Z'));
188 static inline BOOL is_num(WCHAR val) {
189 return (val >= '0' && val <= '9');
192 /* A URI is implicitly a file path if it begins with
193 * a drive letter (eg X:) or starts with "\\" (UNC path).
195 static inline BOOL is_implicit_file_path(const WCHAR *str) {
196 if(is_alpha(str[0]) && str[1] == ':')
198 else if(str[0] == '\\' && str[1] == '\\')
204 /* Checks if the URI is a hierarchical URI. A hierarchical
205 * URI is one that has "//" after the scheme.
207 static BOOL check_hierarchical(const WCHAR **ptr) {
208 const WCHAR *start = *ptr;
223 /* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" */
224 static inline BOOL is_unreserved(WCHAR val) {
225 return (is_alpha(val) || is_num(val) || val == '-' || val == '.' ||
226 val == '_' || val == '~');
229 /* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
230 * / "*" / "+" / "," / ";" / "="
232 static inline BOOL is_subdelim(WCHAR val) {
233 return (val == '!' || val == '$' || val == '&' ||
234 val == '\'' || val == '(' || val == ')' ||
235 val == '*' || val == '+' || val == ',' ||
236 val == ';' || val == '=');
239 /* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" */
240 static inline BOOL is_gendelim(WCHAR val) {
241 return (val == ':' || val == '/' || val == '?' ||
242 val == '#' || val == '[' || val == ']' ||
246 /* Characters that delimit the end of the authority
247 * section of a URI. Sometimes a '\\' is considered
248 * an authority delimeter.
250 static inline BOOL is_auth_delim(WCHAR val, BOOL acceptSlash) {
251 return (val == '#' || val == '/' || val == '?' ||
252 val == '\0' || (acceptSlash && val == '\\'));
255 /* reserved = gen-delims / sub-delims */
256 static inline BOOL is_reserved(WCHAR val) {
257 return (is_subdelim(val) || is_gendelim(val));
260 static inline BOOL is_hexdigit(WCHAR val) {
261 return ((val >= 'a' && val <= 'f') ||
262 (val >= 'A' && val <= 'F') ||
263 (val >= '0' && val <= '9'));
266 static inline BOOL is_path_delim(WCHAR val) {
267 return (!val || val == '#' || val == '?');
270 /* Computes the size of the given IPv6 address.
271 * Each h16 component is 16bits, if there is an IPv4 address, it's
272 * 32bits. If there's an elision it can be 16bits to 128bits, depending
273 * on the number of other components.
275 * Modeled after google-url's CheckIPv6ComponentsSize function
277 static void compute_ipv6_comps_size(ipv6_address *address) {
278 address->components_size = address->h16_count * 2;
281 /* IPv4 address is 4 bytes. */
282 address->components_size += 4;
284 if(address->elision) {
285 /* An elision can be anywhere from 2 bytes up to 16 bytes.
286 * It size depends on the size of the h16 and IPv4 components.
288 address->elision_size = 16 - address->components_size;
289 if(address->elision_size < 2)
290 address->elision_size = 2;
292 address->elision_size = 0;
295 /* Taken from dlls/jscript/lex.c */
296 static int hex_to_int(WCHAR val) {
297 if(val >= '0' && val <= '9')
299 else if(val >= 'a' && val <= 'f')
300 return val - 'a' + 10;
301 else if(val >= 'A' && val <= 'F')
302 return val - 'A' + 10;
307 /* Helper function for converting a percent encoded string
308 * representation of a WCHAR value into its actual WCHAR value. If
309 * the two characters following the '%' aren't valid hex values then
310 * this function returns the NULL character.
313 * "%2E" will result in '.' being returned by this function.
315 static WCHAR decode_pct_val(const WCHAR *ptr) {
318 if(*ptr == '%' && is_hexdigit(*(ptr + 1)) && is_hexdigit(*(ptr + 2))) {
319 INT a = hex_to_int(*(ptr + 1));
320 INT b = hex_to_int(*(ptr + 2));
329 /* Helper function for percent encoding a given character
330 * and storing the encoded value into a given buffer (dest).
332 * It's up to the calling function to ensure that there is
333 * at least enough space in 'dest' for the percent encoded
334 * value to be stored (so dest + 3 spaces available).
336 static inline void pct_encode_val(WCHAR val, WCHAR *dest) {
338 dest[1] = hexDigits[(val >> 4) & 0xf];
339 dest[2] = hexDigits[val & 0xf];
342 /* Scans the range of characters [str, end] and returns the last occurence
343 * of 'ch' or returns NULL.
345 static const WCHAR *str_last_of(const WCHAR *str, const WCHAR *end, WCHAR ch) {
346 const WCHAR *ptr = end;
357 /* Attempts to parse the domain name from the host.
359 * This function also includes the Top-level Domain (TLD) name
360 * of the host when it tries to find the domain name. If it finds
361 * a valid domain name it will assign 'domain_start' the offset
362 * into 'host' where the domain name starts.
364 * It's implied that if a domain name its range is implied to be
365 * [host+domain_start, host+host_len).
367 static void find_domain_name(const WCHAR *host, DWORD host_len,
369 const WCHAR *last_tld, *sec_last_tld, *end;
371 end = host+host_len-1;
375 /* There has to be at least enough room for a '.' followed by a
376 * 3 character TLD for a domain to even exist in the host name.
381 last_tld = str_last_of(host, end, '.');
383 /* http://hostname -> has no domain name. */
386 sec_last_tld = str_last_of(host, last_tld-1, '.');
388 /* If the '.' is at the beginning of the host there
389 * has to be at least 3 characters in the TLD for it
391 * Ex: .com -> .com as the domain name.
392 * .co -> has no domain name.
394 if(last_tld-host == 0) {
395 if(end-(last_tld-1) < 3)
397 } else if(last_tld-host == 3) {
400 /* If there's three characters in front of last_tld and
401 * they are on the list of recognized TLDs, then this
402 * host doesn't have a domain (since the host only contains
404 * Ex: edu.uk -> has no domain name.
405 * foo.uk -> foo.uk as the domain name.
407 for(i = 0; i < sizeof(recognized_tlds)/sizeof(recognized_tlds[0]); ++i) {
408 if(!StrCmpNIW(host, recognized_tlds[i].tld_name, 3))
411 } else if(last_tld-host < 3)
412 /* Anything less then 3 characters is considered part
414 * Ex: ak.uk -> Has no domain name.
418 /* Otherwise the domain name is the whole host name. */
420 } else if(end+1-last_tld > 3) {
421 /* If the last_tld has more then 3 characters then it's automatically
422 * considered the TLD of the domain name.
423 * Ex: www.winehq.org.uk.test -> uk.test as the domain name.
425 *domain_start = (sec_last_tld+1)-host;
426 } else if(last_tld - (sec_last_tld+1) < 4) {
428 /* If the sec_last_tld is 3 characters long it HAS to be on the list of
429 * recognized to still be considered part of the TLD name, otherwise
430 * its considered the domain name.
431 * Ex: www.google.com.uk -> google.com.uk as the domain name.
432 * www.google.foo.uk -> foo.uk as the domain name.
434 if(last_tld - (sec_last_tld+1) == 3) {
435 for(i = 0; i < sizeof(recognized_tlds)/sizeof(recognized_tlds[0]); ++i) {
436 if(!StrCmpNIW(sec_last_tld+1, recognized_tlds[i].tld_name, 3)) {
437 const WCHAR *domain = str_last_of(host, sec_last_tld-1, '.');
442 *domain_start = (domain+1) - host;
443 TRACE("Found domain name %s\n", debugstr_wn(host+*domain_start,
444 (host+host_len)-(host+*domain_start)));
449 *domain_start = (sec_last_tld+1)-host;
451 /* Since the sec_last_tld is less then 3 characters it's considered
453 * Ex: www.google.fo.uk -> google.fo.uk as the domain name.
455 const WCHAR *domain = str_last_of(host, sec_last_tld-1, '.');
460 *domain_start = (domain+1) - host;
463 /* The second to last TLD has more then 3 characters making it
465 * Ex: www.google.test.us -> test.us as the domain name.
467 *domain_start = (sec_last_tld+1)-host;
470 TRACE("Found domain name %s\n", debugstr_wn(host+*domain_start,
471 (host+host_len)-(host+*domain_start)));
474 /* Computes the location where the elision should occur in the IPv6
475 * address using the numerical values of each component stored in
476 * 'values'. If the address shouldn't contain an elision then 'index'
477 * is assigned -1 as it's value. Otherwise 'index' will contain the
478 * starting index (into values) where the elision should be, and 'count'
479 * will contain the number of cells the elision covers.
482 * Windows will expand an elision if the elision only represents 1 h16
483 * component of the URI.
485 * Ex: [1::2:3:4:5:6:7] -> [1:0:2:3:4:5:6:7]
487 * If the IPv6 address contains an IPv4 address, the IPv4 address is also
488 * considered for being included as part of an elision if all it's components
491 * Ex: [1:2:3:4:5:6:0.0.0.0] -> [1:2:3:4:5:6::]
493 static void compute_elision_location(const ipv6_address *address, const USHORT values[8],
494 INT *index, DWORD *count) {
495 DWORD i, max_len, cur_len;
496 INT max_index, cur_index;
498 max_len = cur_len = 0;
499 max_index = cur_index = -1;
500 for(i = 0; i < 8; ++i) {
501 BOOL check_ipv4 = (address->ipv4 && i == 6);
502 BOOL is_end = (check_ipv4 || i == 7);
505 /* Check if the IPv4 address contains only zeros. */
506 if(values[i] == 0 && values[i+1] == 0) {
513 } else if(values[i] == 0) {
520 if(is_end || values[i] != 0) {
521 /* We only consider it for an elision if it's
522 * more then 1 component long.
524 if(cur_len > 1 && cur_len > max_len) {
525 /* Found the new elision location. */
527 max_index = cur_index;
530 /* Reset the current range for the next range of zeros. */
540 /* Converts the specified IPv4 address into an uint value.
542 * This function assumes that the IPv4 address has already been validated.
544 static UINT ipv4toui(const WCHAR *ip, DWORD len) {
546 DWORD comp_value = 0;
549 for(ptr = ip; ptr < ip+len; ++ptr) {
555 comp_value = comp_value*10 + (*ptr-'0');
564 /* Converts an IPv4 address in numerical form into it's fully qualified
565 * string form. This function returns the number of characters written
566 * to 'dest'. If 'dest' is NULL this function will return the number of
567 * characters that would have been written.
569 * It's up to the caller to ensure there's enough space in 'dest' for the
572 static DWORD ui2ipv4(WCHAR *dest, UINT address) {
573 static const WCHAR formatW[] =
574 {'%','u','.','%','u','.','%','u','.','%','u',0};
578 digits[0] = (address >> 24) & 0xff;
579 digits[1] = (address >> 16) & 0xff;
580 digits[2] = (address >> 8) & 0xff;
581 digits[3] = address & 0xff;
585 ret = sprintfW(tmp, formatW, digits[0], digits[1], digits[2], digits[3]);
587 ret = sprintfW(dest, formatW, digits[0], digits[1], digits[2], digits[3]);
592 /* Converts an h16 component (from an IPv6 address) into it's
595 * This function assumes that the h16 component has already been validated.
597 static USHORT h16tous(h16 component) {
601 for(i = 0; i < component.len; ++i) {
603 ret += hex_to_int(component.str[i]);
609 /* Converts an IPv6 address into it's 128 bits (16 bytes) numerical value.
611 * This function assumes that the ipv6_address has already been validated.
613 static BOOL ipv6_to_number(const ipv6_address *address, USHORT number[8]) {
614 DWORD i, cur_component = 0;
615 BOOL already_passed_elision = FALSE;
617 for(i = 0; i < address->h16_count; ++i) {
618 if(address->elision) {
619 if(address->components[i].str > address->elision && !already_passed_elision) {
620 /* Means we just passed the elision and need to add it's values to
621 * 'number' before we do anything else.
624 for(j = 0; j < address->elision_size; j+=2)
625 number[cur_component++] = 0;
627 already_passed_elision = TRUE;
631 number[cur_component++] = h16tous(address->components[i]);
634 /* Case when the elision appears after the h16 components. */
635 if(!already_passed_elision && address->elision) {
636 for(i = 0; i < address->elision_size; i+=2)
637 number[cur_component++] = 0;
638 already_passed_elision = TRUE;
642 UINT value = ipv4toui(address->ipv4, address->ipv4_len);
644 if(cur_component != 6) {
645 ERR("(%p %p): Failed sanity check with %d\n", address, number, cur_component);
649 number[cur_component++] = (value >> 16) & 0xffff;
650 number[cur_component] = value & 0xffff;
656 /* Checks if the characters pointed to by 'ptr' are
657 * a percent encoded data octet.
659 * pct-encoded = "%" HEXDIG HEXDIG
661 static BOOL check_pct_encoded(const WCHAR **ptr) {
662 const WCHAR *start = *ptr;
668 if(!is_hexdigit(**ptr)) {
674 if(!is_hexdigit(**ptr)) {
683 /* dec-octet = DIGIT ; 0-9
684 * / %x31-39 DIGIT ; 10-99
685 * / "1" 2DIGIT ; 100-199
686 * / "2" %x30-34 DIGIT ; 200-249
687 * / "25" %x30-35 ; 250-255
689 static BOOL check_dec_octet(const WCHAR **ptr) {
690 const WCHAR *c1, *c2, *c3;
693 /* A dec-octet must be at least 1 digit long. */
694 if(*c1 < '0' || *c1 > '9')
700 /* Since the 1 digit requirment was meet, it doesn't
701 * matter if this is a DIGIT value, it's considered a
704 if(*c2 < '0' || *c2 > '9')
710 /* Same explanation as above. */
711 if(*c3 < '0' || *c3 > '9')
714 /* Anything > 255 isn't a valid IP dec-octet. */
715 if(*c1 >= '2' && *c2 >= '5' && *c3 >= '5') {
724 /* Checks if there is an implicit IPv4 address in the host component of the URI.
725 * The max value of an implicit IPv4 address is UINT_MAX.
728 * "234567" would be considered an implicit IPv4 address.
730 static BOOL check_implicit_ipv4(const WCHAR **ptr, UINT *val) {
731 const WCHAR *start = *ptr;
735 while(is_num(**ptr)) {
736 ret = ret*10 + (**ptr - '0');
752 /* Checks if the string contains an IPv4 address.
754 * This function has a strict mode or a non-strict mode of operation
755 * When 'strict' is set to FALSE this function will return TRUE if
756 * the string contains at least 'dec-octet "." dec-octet' since partial
757 * IPv4 addresses will be normalized out into full IPv4 addresses. When
758 * 'strict' is set this function expects there to be a full IPv4 address.
760 * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
762 static BOOL check_ipv4address(const WCHAR **ptr, BOOL strict) {
763 const WCHAR *start = *ptr;
765 if(!check_dec_octet(ptr)) {
776 if(!check_dec_octet(ptr)) {
790 if(!check_dec_octet(ptr)) {
804 if(!check_dec_octet(ptr)) {
809 /* Found a four digit ip address. */
812 /* Tries to parse the scheme name of the URI.
814 * scheme = ALPHA *(ALPHA | NUM | '+' | '-' | '.') as defined by RFC 3896.
815 * NOTE: Windows accepts a number as the first character of a scheme.
817 static BOOL parse_scheme_name(const WCHAR **ptr, parse_data *data) {
818 const WCHAR *start = *ptr;
821 data->scheme_len = 0;
824 if(**ptr == '*' && *ptr == start) {
825 /* Might have found a wildcard scheme. If it is the next
826 * char has to be a ':' for it to be a valid URI
830 } else if(!is_num(**ptr) && !is_alpha(**ptr) && **ptr != '+' &&
831 **ptr != '-' && **ptr != '.')
840 /* Schemes must end with a ':' */
846 data->scheme = start;
847 data->scheme_len = *ptr - start;
853 /* Tries to deduce the corresponding URL_SCHEME for the given URI. Stores
854 * the deduced URL_SCHEME in data->scheme_type.
856 static BOOL parse_scheme_type(parse_data *data) {
857 /* If there's scheme data then see if it's a recognized scheme. */
858 if(data->scheme && data->scheme_len) {
861 for(i = 0; i < sizeof(recognized_schemes)/sizeof(recognized_schemes[0]); ++i) {
862 if(lstrlenW(recognized_schemes[i].scheme_name) == data->scheme_len) {
863 /* Has to be a case insensitive compare. */
864 if(!StrCmpNIW(recognized_schemes[i].scheme_name, data->scheme, data->scheme_len)) {
865 data->scheme_type = recognized_schemes[i].scheme;
871 /* If we get here it means it's not a recognized scheme. */
872 data->scheme_type = URL_SCHEME_UNKNOWN;
874 } else if(data->is_relative) {
875 /* Relative URI's have no scheme. */
876 data->scheme_type = URL_SCHEME_UNKNOWN;
879 /* Should never reach here! what happened... */
880 FIXME("(%p): Unable to determine scheme type for URI %s\n", data, debugstr_w(data->uri));
885 /* Tries to parse (or deduce) the scheme_name of a URI. If it can't
886 * parse a scheme from the URI it will try to deduce the scheme_name and scheme_type
887 * using the flags specified in 'flags' (if any). Flags that affect how this function
888 * operates are the Uri_CREATE_ALLOW_* flags.
890 * All parsed/deduced information will be stored in 'data' when the function returns.
892 * Returns TRUE if it was able to successfully parse the information.
894 static BOOL parse_scheme(const WCHAR **ptr, parse_data *data, DWORD flags) {
895 static const WCHAR fileW[] = {'f','i','l','e',0};
896 static const WCHAR wildcardW[] = {'*',0};
898 /* First check to see if the uri could implicitly be a file path. */
899 if(is_implicit_file_path(*ptr)) {
900 if(flags & Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME) {
901 data->scheme = fileW;
902 data->scheme_len = lstrlenW(fileW);
903 data->has_implicit_scheme = TRUE;
905 TRACE("(%p %p %x): URI is an implicit file path.\n", ptr, data, flags);
907 /* Window's does not consider anything that can implicitly be a file
908 * path to be a valid URI if the ALLOW_IMPLICIT_FILE_SCHEME flag is not set...
910 TRACE("(%p %p %x): URI is implicitly a file path, but, the ALLOW_IMPLICIT_FILE_SCHEME flag wasn't set.\n",
914 } else if(!parse_scheme_name(ptr, data)) {
915 /* No Scheme was found, this means it could be:
916 * a) an implicit Wildcard scheme
920 if(flags & Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME) {
921 data->scheme = wildcardW;
922 data->scheme_len = lstrlenW(wildcardW);
923 data->has_implicit_scheme = TRUE;
925 TRACE("(%p %p %x): URI is an implicit wildcard scheme.\n", ptr, data, flags);
926 } else if (flags & Uri_CREATE_ALLOW_RELATIVE) {
927 data->is_relative = TRUE;
928 TRACE("(%p %p %x): URI is relative.\n", ptr, data, flags);
930 TRACE("(%p %p %x): Malformed URI found. Unable to deduce scheme name.\n", ptr, data, flags);
935 if(!data->is_relative)
936 TRACE("(%p %p %x): Found scheme=%s scheme_len=%d\n", ptr, data, flags,
937 debugstr_wn(data->scheme, data->scheme_len), data->scheme_len);
939 if(!parse_scheme_type(data))
942 TRACE("(%p %p %x): Assigned %d as the URL_SCHEME.\n", ptr, data, flags, data->scheme_type);
946 /* Parses the userinfo part of the URI (if it exists). The userinfo field of
947 * a URI can consist of "username:password@", or just "username@".
950 * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
953 * 1) If there is more than one ':' in the userinfo part of the URI Windows
954 * uses the first occurence of ':' to delimit the username and password
958 * ftp://user:pass:word@winehq.org
960 * Would yield, "user" as the username and "pass:word" as the password.
962 * 2) Windows allows any character to appear in the "userinfo" part of
963 * a URI, as long as it's not an authority delimeter character set.
965 static void parse_userinfo(const WCHAR **ptr, parse_data *data, DWORD flags) {
966 data->userinfo = *ptr;
967 data->userinfo_split = -1;
969 while(**ptr != '@') {
970 if(**ptr == ':' && data->userinfo_split == -1)
971 data->userinfo_split = *ptr - data->userinfo;
972 else if(**ptr == '%') {
973 /* If it's a known scheme type, it has to be a valid percent
976 if(!check_pct_encoded(ptr)) {
977 if(data->scheme_type != URL_SCHEME_UNKNOWN) {
978 *ptr = data->userinfo;
979 data->userinfo = NULL;
980 data->userinfo_split = -1;
982 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr, data, flags);
987 } else if(is_auth_delim(**ptr, data->scheme_type != URL_SCHEME_UNKNOWN))
994 *ptr = data->userinfo;
995 data->userinfo = NULL;
996 data->userinfo_split = -1;
998 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr, data, flags);
1002 data->userinfo_len = *ptr - data->userinfo;
1003 TRACE("(%p %p %x): Found userinfo=%s userinfo_len=%d split=%d.\n", ptr, data, flags,
1004 debugstr_wn(data->userinfo, data->userinfo_len), data->userinfo_len, data->userinfo_split);
1008 /* Attempts to parse a port from the URI.
1011 * Windows seems to have a cap on what the maximum value
1012 * for a port can be. The max value is USHORT_MAX.
1016 static BOOL parse_port(const WCHAR **ptr, parse_data *data, DWORD flags) {
1020 while(!is_auth_delim(**ptr, data->scheme_type != URL_SCHEME_UNKNOWN)) {
1021 if(!is_num(**ptr)) {
1027 port = port*10 + (**ptr-'0');
1029 if(port > USHORT_MAX) {
1038 data->port_value = port;
1039 data->port_len = *ptr - data->port;
1041 TRACE("(%p %p %x): Found port %s len=%d value=%u\n", ptr, data, flags,
1042 debugstr_wn(data->port, data->port_len), data->port_len, data->port_value);
1046 /* Attempts to parse a IPv4 address from the URI.
1049 * Window's normalizes IPv4 addresses, This means there's three
1050 * possibilities for the URI to contain an IPv4 address.
1051 * 1) A well formed address (ex. 192.2.2.2).
1052 * 2) A partially formed address. For example "192.0" would
1053 * normalize to "192.0.0.0" during canonicalization.
1054 * 3) An implicit IPv4 address. For example "256" would
1055 * normalize to "0.0.1.0" during canonicalization. Also
1056 * note that the maximum value for an implicit IP address
1057 * is UINT_MAX, if the value in the URI exceeds this then
1058 * it is not considered an IPv4 address.
1060 static BOOL parse_ipv4address(const WCHAR **ptr, parse_data *data, DWORD flags) {
1061 const BOOL is_unknown = data->scheme_type == URL_SCHEME_UNKNOWN;
1064 if(!check_ipv4address(ptr, FALSE)) {
1065 if(!check_implicit_ipv4(ptr, &data->implicit_ipv4)) {
1066 TRACE("(%p %p %x): URI didn't contain anything looking like an IPv4 address.\n",
1072 data->has_implicit_ip = TRUE;
1075 /* Check if what we found is the only part of the host name (if it isn't
1076 * we don't have an IPv4 address).
1080 if(!parse_port(ptr, data, flags)) {
1085 } else if(!is_auth_delim(**ptr, !is_unknown)) {
1086 /* Found more data which belongs the host, so this isn't an IPv4. */
1089 data->has_implicit_ip = FALSE;
1093 data->host_len = *ptr - data->host;
1094 data->host_type = Uri_HOST_IPV4;
1096 TRACE("(%p %p %x): IPv4 address found. host=%s host_len=%d host_type=%d\n",
1097 ptr, data, flags, debugstr_wn(data->host, data->host_len),
1098 data->host_len, data->host_type);
1102 /* Attempts to parse the reg-name from the URI.
1104 * Because of the way Windows handles ':' this function also
1105 * handles parsing the port.
1107 * reg-name = *( unreserved / pct-encoded / sub-delims )
1110 * Windows allows everything, but, the characters in "auth_delims" and ':'
1111 * to appear in a reg-name, unless it's an unknown scheme type then ':' is
1112 * allowed to appear (even if a valid port isn't after it).
1114 * Windows doesn't like host names which start with '[' and end with ']'
1115 * and don't contain a valid IP literal address in between them.
1117 * On Windows if an '[' is encountered in the host name the ':' no longer
1118 * counts as a delimiter until you reach the next ']' or an "authority delimeter".
1120 * A reg-name CAN be empty.
1122 static BOOL parse_reg_name(const WCHAR **ptr, parse_data *data, DWORD flags) {
1123 const BOOL has_start_bracket = **ptr == '[';
1124 const BOOL known_scheme = data->scheme_type != URL_SCHEME_UNKNOWN;
1125 BOOL inside_brackets = has_start_bracket;
1126 BOOL ignore_col = FALSE;
1128 /* We have to be careful with file schemes. */
1129 if(data->scheme_type == URL_SCHEME_FILE) {
1130 /* This is because an implicit file scheme could be "C:\\test" and it
1131 * would trick this function into thinking the host is "C", when after
1132 * canonicalization the host would end up being an empty string.
1134 if(is_alpha(**ptr) && *(*ptr+1) == ':') {
1135 /* Regular old drive paths don't have a host type (or host name). */
1136 data->host_type = Uri_HOST_UNKNOWN;
1140 } else if(**ptr == '\\' && *(*ptr+1) == '\\')
1141 /* Skip past the "\\" of a UNC path. */
1147 while(!is_auth_delim(**ptr, known_scheme)) {
1148 if(**ptr == ':' && !ignore_col) {
1149 /* We can ignore ':' if were inside brackets.*/
1150 if(!inside_brackets) {
1151 const WCHAR *tmp = (*ptr)++;
1153 /* Attempt to parse the port. */
1154 if(!parse_port(ptr, data, flags)) {
1155 /* Windows expects there to be a valid port for known scheme types. */
1156 if(data->scheme_type != URL_SCHEME_UNKNOWN) {
1159 TRACE("(%p %p %x): Expected valid port\n", ptr, data, flags);
1162 /* Windows gives up on trying to parse a port when it
1163 * encounters 1 invalid port.
1167 data->host_len = tmp - data->host;
1171 } else if(**ptr == '%' && known_scheme) {
1172 /* Has to be a legit % encoded value. */
1173 if(!check_pct_encoded(ptr)) {
1179 } else if(**ptr == ']')
1180 inside_brackets = FALSE;
1181 else if(**ptr == '[')
1182 inside_brackets = TRUE;
1187 if(has_start_bracket) {
1188 /* Make sure the last character of the host wasn't a ']'. */
1189 if(*(*ptr-1) == ']') {
1190 TRACE("(%p %p %x): Expected an IP literal inside of the host\n",
1198 /* Don't overwrite our length if we found a port earlier. */
1200 data->host_len = *ptr - data->host;
1202 /* If the host is empty, then it's an unknown host type. */
1203 if(data->host_len == 0)
1204 data->host_type = Uri_HOST_UNKNOWN;
1206 data->host_type = Uri_HOST_DNS;
1208 TRACE("(%p %p %x): Parsed reg-name. host=%s len=%d\n", ptr, data, flags,
1209 debugstr_wn(data->host, data->host_len), data->host_len);
1213 /* Attempts to parse an IPv6 address out of the URI.
1215 * IPv6address = 6( h16 ":" ) ls32
1216 * / "::" 5( h16 ":" ) ls32
1217 * / [ h16 ] "::" 4( h16 ":" ) ls32
1218 * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1219 * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1220 * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1221 * / [ *4( h16 ":" ) h16 ] "::" ls32
1222 * / [ *5( h16 ":" ) h16 ] "::" h16
1223 * / [ *6( h16 ":" ) h16 ] "::"
1225 * ls32 = ( h16 ":" h16 ) / IPv4address
1226 * ; least-significant 32 bits of address.
1229 * ; 16 bits of address represented in hexadecimal.
1231 * Modeled after google-url's 'DoParseIPv6' function.
1233 static BOOL parse_ipv6address(const WCHAR **ptr, parse_data *data, DWORD flags) {
1234 const WCHAR *start, *cur_start;
1237 start = cur_start = *ptr;
1238 memset(&ip, 0, sizeof(ipv6_address));
1241 /* Check if we're on the last character of the host. */
1242 BOOL is_end = (is_auth_delim(**ptr, data->scheme_type != URL_SCHEME_UNKNOWN)
1245 BOOL is_split = (**ptr == ':');
1246 BOOL is_elision = (is_split && !is_end && *(*ptr+1) == ':');
1248 /* Check if we're at the end of of the a component, or
1249 * if we're at the end of the IPv6 address.
1251 if(is_split || is_end) {
1254 cur_len = *ptr - cur_start;
1256 /* h16 can't have a length > 4. */
1260 TRACE("(%p %p %x): h16 component to long.\n",
1266 /* An h16 component can't have the length of 0 unless
1267 * the elision is at the beginning of the address, or
1268 * at the end of the address.
1270 if(!((*ptr == start && is_elision) ||
1271 (is_end && (*ptr-2) == ip.elision))) {
1273 TRACE("(%p %p %x): IPv6 component can not have a length of 0.\n",
1280 /* An IPv6 address can have no more than 8 h16 components. */
1281 if(ip.h16_count >= 8) {
1283 TRACE("(%p %p %x): Not a IPv6 address, to many h16 components.\n",
1288 ip.components[ip.h16_count].str = cur_start;
1289 ip.components[ip.h16_count].len = cur_len;
1291 TRACE("(%p %p %x): Found h16 component %s, len=%d, h16_count=%d\n",
1292 ptr, data, flags, debugstr_wn(cur_start, cur_len), cur_len,
1302 /* A IPv6 address can only have 1 elision ('::'). */
1306 TRACE("(%p %p %x): IPv6 address cannot have 2 elisions.\n",
1318 if(!check_ipv4address(ptr, TRUE)) {
1319 if(!is_hexdigit(**ptr)) {
1320 /* Not a valid character for an IPv6 address. */
1325 /* Found an IPv4 address. */
1326 ip.ipv4 = cur_start;
1327 ip.ipv4_len = *ptr - cur_start;
1329 TRACE("(%p %p %x): Found an attached IPv4 address %s len=%d.\n",
1330 ptr, data, flags, debugstr_wn(ip.ipv4, ip.ipv4_len),
1333 /* IPv4 addresses can only appear at the end of a IPv6. */
1339 compute_ipv6_comps_size(&ip);
1341 /* Make sure the IPv6 address adds up to 16 bytes. */
1342 if(ip.components_size + ip.elision_size != 16) {
1344 TRACE("(%p %p %x): Invalid IPv6 address, did not add up to 16 bytes.\n",
1349 if(ip.elision_size == 2) {
1350 /* For some reason on Windows if an elision that represents
1351 * only 1 h16 component is encountered at the very begin or
1352 * end of an IPv6 address, Windows does not consider it a
1353 * valid IPv6 address.
1355 * Ex: [::2:3:4:5:6:7] is not valid, even though the sum
1356 * of all the components == 128bits.
1358 if(ip.elision < ip.components[0].str ||
1359 ip.elision > ip.components[ip.h16_count-1].str) {
1361 TRACE("(%p %p %x): Invalid IPv6 address. Detected elision of 2 bytes at the beginning or end of the address.\n",
1367 data->host_type = Uri_HOST_IPV6;
1368 data->has_ipv6 = TRUE;
1369 data->ipv6_address = ip;
1371 TRACE("(%p %p %x): Found valid IPv6 literal %s len=%d\n",
1372 ptr, data, flags, debugstr_wn(start, *ptr-start),
1377 /* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) */
1378 static BOOL parse_ipvfuture(const WCHAR **ptr, parse_data *data, DWORD flags) {
1379 const WCHAR *start = *ptr;
1381 /* IPvFuture has to start with a 'v' or 'V'. */
1382 if(**ptr != 'v' && **ptr != 'V')
1385 /* Following the v their must be atleast 1 hexdigit. */
1387 if(!is_hexdigit(**ptr)) {
1393 while(is_hexdigit(**ptr))
1396 /* End of the hexdigit sequence must be a '.' */
1403 if(!is_unreserved(**ptr) && !is_subdelim(**ptr) && **ptr != ':') {
1409 while(is_unreserved(**ptr) || is_subdelim(**ptr) || **ptr == ':')
1412 data->host_type = Uri_HOST_UNKNOWN;
1414 TRACE("(%p %p %x): Parsed IPvFuture address %s len=%d\n", ptr, data, flags,
1415 debugstr_wn(start, *ptr-start), *ptr-start);
1420 /* IP-literal = "[" ( IPv6address / IPvFuture ) "]" */
1421 static BOOL parse_ip_literal(const WCHAR **ptr, parse_data *data, DWORD flags) {
1430 if(!parse_ipv6address(ptr, data, flags)) {
1431 if(!parse_ipvfuture(ptr, data, flags)) {
1447 /* If a valid port is not found, then let it trickle down to
1450 if(!parse_port(ptr, data, flags)) {
1456 data->host_len = *ptr - data->host;
1461 /* Parses the host information from the URI.
1463 * host = IP-literal / IPv4address / reg-name
1465 static BOOL parse_host(const WCHAR **ptr, parse_data *data, DWORD flags) {
1466 if(!parse_ip_literal(ptr, data, flags)) {
1467 if(!parse_ipv4address(ptr, data, flags)) {
1468 if(!parse_reg_name(ptr, data, flags)) {
1469 TRACE("(%p %p %x): Malformed URI, Unknown host type.\n",
1479 /* Parses the authority information from the URI.
1481 * authority = [ userinfo "@" ] host [ ":" port ]
1483 static BOOL parse_authority(const WCHAR **ptr, parse_data *data, DWORD flags) {
1484 parse_userinfo(ptr, data, flags);
1486 /* Parsing the port will happen during one of the host parsing
1487 * routines (if the URI has a port).
1489 if(!parse_host(ptr, data, flags))
1495 /* Attempts to parse the path information of a hierarchical URI. */
1496 static BOOL parse_path_hierarchical(const WCHAR **ptr, parse_data *data, DWORD flags) {
1497 const WCHAR *start = *ptr;
1498 static const WCHAR slash[] = {'/',0};
1500 if(is_path_delim(**ptr)) {
1501 if(data->scheme_type == URL_SCHEME_WILDCARD) {
1502 /* Wildcard schemes don't get a '/' attached if their path is
1507 } else if(!(flags & Uri_CREATE_NO_CANONICALIZE)) {
1508 /* If the path component is empty, then a '/' is added. */
1513 while(!is_path_delim(**ptr)) {
1514 if(**ptr == '%' && data->scheme_type != URL_SCHEME_UNKNOWN &&
1515 data->scheme_type != URL_SCHEME_FILE) {
1516 if(!check_pct_encoded(ptr)) {
1521 } else if(**ptr == '\\') {
1522 /* Not allowed to have a backslash if NO_CANONICALIZE is set
1523 * and the scheme is known type (but not a file scheme).
1525 if(flags & Uri_CREATE_NO_CANONICALIZE) {
1526 if(data->scheme_type != URL_SCHEME_FILE &&
1527 data->scheme_type != URL_SCHEME_UNKNOWN) {
1537 /* The only time a URI doesn't have a path is when
1538 * the NO_CANONICALIZE flag is set and the raw URI
1539 * didn't contain one.
1546 data->path_len = *ptr - start;
1551 TRACE("(%p %p %x): Parsed path %s len=%d\n", ptr, data, flags,
1552 debugstr_wn(data->path, data->path_len), data->path_len);
1554 TRACE("(%p %p %x): The URI contained no path\n", ptr, data, flags);
1559 /* Parses the path of a opaque URI (much less strict then the parser
1560 * for a hierarchical URI).
1563 * Windows allows invalid % encoded data to appear in opaque URI paths
1564 * for unknown scheme types.
1566 static BOOL parse_path_opaque(const WCHAR **ptr, parse_data *data, DWORD flags) {
1567 const BOOL known_scheme = data->scheme_type != URL_SCHEME_UNKNOWN;
1571 while(!is_path_delim(**ptr)) {
1572 if(**ptr == '%' && known_scheme) {
1573 if(!check_pct_encoded(ptr)) {
1584 data->path_len = *ptr - data->path;
1585 TRACE("(%p %p %x): Parsed opaque URI path %s len=%d\n", ptr, data, flags,
1586 debugstr_wn(data->path, data->path_len), data->path_len);
1590 /* Determines how the URI should be parsed after the scheme information.
1592 * If the scheme is followed, by "//" then, it is treated as an hierarchical URI
1593 * which then the authority and path information will be parsed out. Otherwise, the
1594 * URI will be treated as an opaque URI which the authority information is not parsed
1597 * RFC 3896 definition of hier-part:
1599 * hier-part = "//" authority path-abempty
1604 * MSDN opaque URI definition:
1605 * scheme ":" path [ "#" fragment ]
1608 * If the URI is of an unknown scheme type and has a "//" following the scheme then it
1609 * is treated as a hierarchical URI, but, if the CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is
1610 * set then it is considered an opaque URI reguardless of what follows the scheme information
1611 * (per MSDN documentation).
1613 static BOOL parse_hierpart(const WCHAR **ptr, parse_data *data, DWORD flags) {
1614 /* Checks if the authority information needs to be parsed.
1616 * Relative URI's aren't hierarchical URI's, but, they could trick
1617 * "check_hierarchical" into thinking it is, so we need to explicitly
1618 * make sure it's not relative. Also, if the URI is an implicit file
1619 * scheme it might not contain a "//", but, it's considered hierarchical
1620 * anyways. Wildcard Schemes are always considered hierarchical
1622 if(data->scheme_type == URL_SCHEME_WILDCARD ||
1623 data->scheme_type == URL_SCHEME_FILE ||
1624 (!data->is_relative && check_hierarchical(ptr))) {
1625 /* Only treat it as a hierarchical URI if the scheme_type is known or
1626 * the Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is not set.
1628 if(data->scheme_type != URL_SCHEME_UNKNOWN ||
1629 !(flags & Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES)) {
1630 TRACE("(%p %p %x): Treating URI as an hierarchical URI.\n", ptr, data, flags);
1631 data->is_opaque = FALSE;
1633 if(data->scheme_type == URL_SCHEME_FILE)
1634 /* Skip past the "//" after the scheme (if any). */
1635 check_hierarchical(ptr);
1637 /* TODO: Handle hierarchical URI's, parse authority then parse the path. */
1638 if(!parse_authority(ptr, data, flags))
1641 return parse_path_hierarchical(ptr, data, flags);
1645 /* If it reaches here, then the URI will be treated as an opaque
1649 TRACE("(%p %p %x): Treating URI as an opaque URI.\n", ptr, data, flags);
1651 data->is_opaque = TRUE;
1652 if(!parse_path_opaque(ptr, data, flags))
1658 /* Parses and validates the components of the specified by data->uri
1659 * and stores the information it parses into 'data'.
1661 * Returns TRUE if it successfully parsed the URI. False otherwise.
1663 static BOOL parse_uri(parse_data *data, DWORD flags) {
1670 TRACE("(%p %x): BEGINNING TO PARSE URI %s.\n", data, flags, debugstr_w(data->uri));
1672 if(!parse_scheme(pptr, data, flags))
1675 if(!parse_hierpart(pptr, data, flags))
1678 /* TODO: Parse query and fragment (if the URI has one). */
1680 TRACE("(%p %x): FINISHED PARSING URI.\n", data, flags);
1684 /* Canonicalizes the userinfo of the URI represented by the parse_data.
1686 * Canonicalization of the userinfo is a simple process. If there are any percent
1687 * encoded characters that fall in the "unreserved" character set, they are decoded
1688 * to their actual value. If a character is not in the "unreserved" or "reserved" sets
1689 * then it is percent encoded. Other than that the characters are copied over without
1692 static BOOL canonicalize_userinfo(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
1695 uri->userinfo_start = uri->userinfo_split = -1;
1696 uri->userinfo_len = 0;
1699 /* URI doesn't have userinfo, so nothing to do here. */
1702 uri->userinfo_start = uri->canon_len;
1704 while(i < data->userinfo_len) {
1705 if(data->userinfo[i] == ':' && uri->userinfo_split == -1)
1706 /* Windows only considers the first ':' as the delimiter. */
1707 uri->userinfo_split = uri->canon_len - uri->userinfo_start;
1708 else if(data->userinfo[i] == '%') {
1709 /* Only decode % encoded values for known scheme types. */
1710 if(data->scheme_type != URL_SCHEME_UNKNOWN) {
1711 /* See if the value really needs decoded. */
1712 WCHAR val = decode_pct_val(data->userinfo + i);
1713 if(is_unreserved(val)) {
1715 uri->canon_uri[uri->canon_len] = val;
1719 /* Move pass the hex characters. */
1724 } else if(!is_reserved(data->userinfo[i]) && !is_unreserved(data->userinfo[i]) &&
1725 data->userinfo[i] != '\\') {
1726 /* Only percent encode forbidden characters if the NO_ENCODE_FORBIDDEN_CHARACTERS flag
1729 if(!(flags & Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS)) {
1731 pct_encode_val(data->userinfo[i], uri->canon_uri + uri->canon_len);
1733 uri->canon_len += 3;
1740 /* Nothing special, so just copy the character over. */
1741 uri->canon_uri[uri->canon_len] = data->userinfo[i];
1747 uri->userinfo_len = uri->canon_len - uri->userinfo_start;
1749 TRACE("(%p %p %x %d): Canonicalized userinfo, userinfo_start=%d, userinfo=%s, userinfo_split=%d userinfo_len=%d.\n",
1750 data, uri, flags, computeOnly, uri->userinfo_start, debugstr_wn(uri->canon_uri + uri->userinfo_start, uri->userinfo_len),
1751 uri->userinfo_split, uri->userinfo_len);
1753 /* Now insert the '@' after the userinfo. */
1755 uri->canon_uri[uri->canon_len] = '@';
1761 /* Attempts to canonicalize a reg_name.
1763 * Things that happen:
1764 * 1) If Uri_CREATE_NO_CANONICALIZE flag is not set, then the reg_name is
1765 * lower cased. Unless it's an unknown scheme type, which case it's
1766 * no lower cased reguardless.
1768 * 2) Unreserved % encoded characters are decoded for known
1771 * 3) Forbidden characters are % encoded as long as
1772 * Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS flag is not set and
1773 * it isn't an unknown scheme type.
1775 * 4) If it's a file scheme and the host is "localhost" it's removed.
1777 static BOOL canonicalize_reg_name(const parse_data *data, Uri *uri,
1778 DWORD flags, BOOL computeOnly) {
1779 static const WCHAR localhostW[] =
1780 {'l','o','c','a','l','h','o','s','t',0};
1782 const BOOL known_scheme = data->scheme_type != URL_SCHEME_UNKNOWN;
1784 uri->host_start = uri->canon_len;
1786 if(data->scheme_type == URL_SCHEME_FILE &&
1787 data->host_len == lstrlenW(localhostW)) {
1788 if(!StrCmpNIW(data->host, localhostW, data->host_len)) {
1789 uri->host_start = -1;
1791 uri->host_type = Uri_HOST_UNKNOWN;
1796 for(ptr = data->host; ptr < data->host+data->host_len; ++ptr) {
1797 if(*ptr == '%' && known_scheme) {
1798 WCHAR val = decode_pct_val(ptr);
1799 if(is_unreserved(val)) {
1800 /* If NO_CANONICALZE is not set, then windows lower cases the
1803 if(!(flags & Uri_CREATE_NO_CANONICALIZE) && isupperW(val)) {
1805 uri->canon_uri[uri->canon_len] = tolowerW(val);
1808 uri->canon_uri[uri->canon_len] = val;
1812 /* Skip past the % encoded character. */
1816 /* Just copy the % over. */
1818 uri->canon_uri[uri->canon_len] = *ptr;
1821 } else if(*ptr == '\\') {
1822 /* Only unknown scheme types could have made it here with a '\\' in the host name. */
1824 uri->canon_uri[uri->canon_len] = *ptr;
1826 } else if(!(flags & Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS) &&
1827 !is_unreserved(*ptr) && !is_reserved(*ptr) && known_scheme) {
1829 pct_encode_val(*ptr, uri->canon_uri+uri->canon_len);
1831 /* The percent encoded value gets lower cased also. */
1832 if(!(flags & Uri_CREATE_NO_CANONICALIZE)) {
1833 uri->canon_uri[uri->canon_len+1] = tolowerW(uri->canon_uri[uri->canon_len+1]);
1834 uri->canon_uri[uri->canon_len+2] = tolowerW(uri->canon_uri[uri->canon_len+2]);
1838 uri->canon_len += 3;
1841 if(!(flags & Uri_CREATE_NO_CANONICALIZE) && known_scheme)
1842 uri->canon_uri[uri->canon_len] = tolowerW(*ptr);
1844 uri->canon_uri[uri->canon_len] = *ptr;
1851 uri->host_len = uri->canon_len - uri->host_start;
1854 TRACE("(%p %p %x %d): Canonicalize reg_name=%s len=%d\n", data, uri, flags,
1855 computeOnly, debugstr_wn(uri->canon_uri+uri->host_start, uri->host_len),
1859 find_domain_name(uri->canon_uri+uri->host_start, uri->host_len,
1860 &(uri->domain_offset));
1865 /* Attempts to canonicalize an implicit IPv4 address. */
1866 static BOOL canonicalize_implicit_ipv4address(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
1867 uri->host_start = uri->canon_len;
1869 TRACE("%u\n", data->implicit_ipv4);
1870 /* For unknown scheme types Window's doesn't convert
1871 * the value into an IP address, but, it still considers
1872 * it an IPv4 address.
1874 if(data->scheme_type == URL_SCHEME_UNKNOWN) {
1876 memcpy(uri->canon_uri+uri->canon_len, data->host, data->host_len*sizeof(WCHAR));
1877 uri->canon_len += data->host_len;
1880 uri->canon_len += ui2ipv4(uri->canon_uri+uri->canon_len, data->implicit_ipv4);
1882 uri->canon_len += ui2ipv4(NULL, data->implicit_ipv4);
1885 uri->host_len = uri->canon_len - uri->host_start;
1886 uri->host_type = Uri_HOST_IPV4;
1889 TRACE("%p %p %x %d): Canonicalized implicit IP address=%s len=%d\n",
1890 data, uri, flags, computeOnly,
1891 debugstr_wn(uri->canon_uri+uri->host_start, uri->host_len),
1897 /* Attempts to canonicalize an IPv4 address.
1899 * If the parse_data represents a URI that has an implicit IPv4 address
1900 * (ex. http://256/, this function will convert 256 into 0.0.1.0). If
1901 * the implicit IP address exceeds the value of UINT_MAX (maximum value
1902 * for an IPv4 address) it's canonicalized as if were a reg-name.
1904 * If the parse_data contains a partial or full IPv4 address it normalizes it.
1905 * A partial IPv4 address is something like "192.0" and would be normalized to
1906 * "192.0.0.0". With a full (or partial) IPv4 address like "192.002.01.003" would
1907 * be normalized to "192.2.1.3".
1910 * Window's ONLY normalizes IPv4 address for known scheme types (one that isn't
1911 * URL_SCHEME_UNKNOWN). For unknown scheme types, it simply copies the data from
1912 * the original URI into the canonicalized URI, but, it still recognizes URI's
1913 * host type as HOST_IPV4.
1915 static BOOL canonicalize_ipv4address(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
1916 if(data->has_implicit_ip)
1917 return canonicalize_implicit_ipv4address(data, uri, flags, computeOnly);
1919 uri->host_start = uri->canon_len;
1921 /* Windows only normalizes for known scheme types. */
1922 if(data->scheme_type != URL_SCHEME_UNKNOWN) {
1923 /* parse_data contains a partial or full IPv4 address, so normalize it. */
1924 DWORD i, octetDigitCount = 0, octetCount = 0;
1925 BOOL octetHasDigit = FALSE;
1927 for(i = 0; i < data->host_len; ++i) {
1928 if(data->host[i] == '0' && !octetHasDigit) {
1929 /* Can ignore leading zeros if:
1930 * 1) It isn't the last digit of the octet.
1931 * 2) i+1 != data->host_len
1934 if(octetDigitCount == 2 ||
1935 i+1 == data->host_len ||
1936 data->host[i+1] == '.') {
1938 uri->canon_uri[uri->canon_len] = data->host[i];
1940 TRACE("Adding zero\n");
1942 } else if(data->host[i] == '.') {
1944 uri->canon_uri[uri->canon_len] = data->host[i];
1947 octetDigitCount = 0;
1948 octetHasDigit = FALSE;
1952 uri->canon_uri[uri->canon_len] = data->host[i];
1956 octetHasDigit = TRUE;
1960 /* Make sure the canonicalized IP address has 4 dec-octets.
1961 * If doesn't add "0" ones until there is 4;
1963 for( ; octetCount < 3; ++octetCount) {
1965 uri->canon_uri[uri->canon_len] = '.';
1966 uri->canon_uri[uri->canon_len+1] = '0';
1969 uri->canon_len += 2;
1972 /* Windows doesn't normalize addresses in unknown schemes. */
1974 memcpy(uri->canon_uri+uri->canon_len, data->host, data->host_len*sizeof(WCHAR));
1975 uri->canon_len += data->host_len;
1978 uri->host_len = uri->canon_len - uri->host_start;
1980 TRACE("(%p %p %x %d): Canonicalized IPv4 address, ip=%s len=%d\n",
1981 data, uri, flags, computeOnly,
1982 debugstr_wn(uri->canon_uri+uri->host_start, uri->host_len),
1989 /* Attempts to canonicalize the IPv6 address of the URI.
1991 * Multiple things happen during the canonicalization of an IPv6 address:
1992 * 1) Any leading zero's in an h16 component are removed.
1993 * Ex: [0001:0022::] -> [1:22::]
1995 * 2) The longest sequence of zero h16 components are compressed
1996 * into a "::" (elision). If there's a tie, the first is choosen.
1998 * Ex: [0:0:0:0:1:6:7:8] -> [::1:6:7:8]
1999 * [0:0:0:0:1:2::] -> [::1:2:0:0]
2000 * [0:0:1:2:0:0:7:8] -> [::1:2:0:0:7:8]
2002 * 3) If an IPv4 address is attached to the IPv6 address, it's
2004 * Ex: [::001.002.022.000] -> [::1.2.22.0]
2006 * 4) If an elision is present, but, only represents 1 h16 component
2009 * Ex: [1::2:3:4:5:6:7] -> [1:0:2:3:4:5:6:7]
2011 * 5) If the IPv6 address contains an IPv4 address and there exists
2012 * at least 1 non-zero h16 component the IPv4 address is converted
2013 * into two h16 components, otherwise it's normalized and kept as is.
2015 * Ex: [::192.200.003.4] -> [::192.200.3.4]
2016 * [ffff::192.200.003.4] -> [ffff::c0c8:3041]
2019 * For unknown scheme types Windows simply copies the address over without any
2022 * IPv4 address can be included in an elision if all its components are 0's.
2024 static BOOL canonicalize_ipv6address(const parse_data *data, Uri *uri,
2025 DWORD flags, BOOL computeOnly) {
2026 uri->host_start = uri->canon_len;
2028 if(data->scheme_type == URL_SCHEME_UNKNOWN) {
2030 memcpy(uri->canon_uri+uri->canon_len, data->host, data->host_len*sizeof(WCHAR));
2031 uri->canon_len += data->host_len;
2035 DWORD i, elision_len;
2037 if(!ipv6_to_number(&(data->ipv6_address), values)) {
2038 TRACE("(%p %p %x %d): Failed to compute numerical value for IPv6 address.\n",
2039 data, uri, flags, computeOnly);
2044 uri->canon_uri[uri->canon_len] = '[';
2047 /* Find where the elision should occur (if any). */
2048 compute_elision_location(&(data->ipv6_address), values, &elision_start, &elision_len);
2050 TRACE("%p %p %x %d): Elision starts at %d, len=%u\n", data, uri, flags,
2051 computeOnly, elision_start, elision_len);
2053 for(i = 0; i < 8; ++i) {
2054 BOOL in_elision = (elision_start > -1 && i >= elision_start &&
2055 i < elision_start+elision_len);
2056 BOOL do_ipv4 = (i == 6 && data->ipv6_address.ipv4 && !in_elision &&
2057 data->ipv6_address.h16_count == 0);
2059 if(i == elision_start) {
2061 uri->canon_uri[uri->canon_len] = ':';
2062 uri->canon_uri[uri->canon_len+1] = ':';
2064 uri->canon_len += 2;
2067 /* We can ignore the current component if we're in the elision. */
2071 /* We only add a ':' if we're not at i == 0, or when we're at
2072 * the very end of elision range since the ':' colon was handled
2073 * earlier. Otherwise we would end up with ":::" after elision.
2075 if(i != 0 && !(elision_start > -1 && i == elision_start+elision_len)) {
2077 uri->canon_uri[uri->canon_len] = ':';
2085 /* Combine the two parts of the IPv4 address values. */
2091 len = ui2ipv4(uri->canon_uri+uri->canon_len, val);
2093 len = ui2ipv4(NULL, val);
2095 uri->canon_len += len;
2098 /* Write a regular h16 component to the URI. */
2100 /* Short circuit for the trivial case. */
2101 if(values[i] == 0) {
2103 uri->canon_uri[uri->canon_len] = '0';
2106 static const WCHAR formatW[] = {'%','x',0};
2109 uri->canon_len += sprintfW(uri->canon_uri+uri->canon_len,
2110 formatW, values[i]);
2113 uri->canon_len += sprintfW(tmp, formatW, values[i]);
2119 /* Add the closing ']'. */
2121 uri->canon_uri[uri->canon_len] = ']';
2125 uri->host_len = uri->canon_len - uri->host_start;
2128 TRACE("(%p %p %x %d): Canonicalized IPv6 address %s, len=%d\n", data, uri, flags,
2129 computeOnly, debugstr_wn(uri->canon_uri+uri->host_start, uri->host_len),
2135 /* Attempts to canonicalize the host of the URI (if any). */
2136 static BOOL canonicalize_host(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
2137 uri->host_start = -1;
2139 uri->domain_offset = -1;
2142 switch(data->host_type) {
2144 uri->host_type = Uri_HOST_DNS;
2145 if(!canonicalize_reg_name(data, uri, flags, computeOnly))
2150 uri->host_type = Uri_HOST_IPV4;
2151 if(!canonicalize_ipv4address(data, uri, flags, computeOnly))
2156 if(!canonicalize_ipv6address(data, uri, flags, computeOnly))
2159 uri->host_type = Uri_HOST_IPV6;
2161 case Uri_HOST_UNKNOWN:
2162 if(data->host_len > 0 || data->scheme_type != URL_SCHEME_FILE) {
2163 uri->host_start = uri->canon_len;
2165 /* Nothing happens to unknown host types. */
2167 memcpy(uri->canon_uri+uri->canon_len, data->host, data->host_len*sizeof(WCHAR));
2168 uri->canon_len += data->host_len;
2169 uri->host_len = data->host_len;
2172 uri->host_type = Uri_HOST_UNKNOWN;
2175 FIXME("(%p %p %x %d): Canonicalization for host type %d not supported.\n", data,
2176 uri, flags, computeOnly, data->host_type);
2184 static BOOL canonicalize_port(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
2185 BOOL has_default_port = FALSE;
2186 USHORT default_port = 0;
2189 uri->has_port = FALSE;
2191 /* Check if the scheme has a default port. */
2192 for(i = 0; i < sizeof(default_ports)/sizeof(default_ports[0]); ++i) {
2193 if(default_ports[i].scheme == data->scheme_type) {
2194 has_default_port = TRUE;
2195 default_port = default_ports[i].port;
2200 if(data->port || has_default_port)
2201 uri->has_port = TRUE;
2204 * 1) Has a port which is the default port.
2205 * 2) Has a port (not the default).
2206 * 3) Doesn't have a port, but, scheme has a default port.
2209 if(has_default_port && data->port && data->port_value == default_port) {
2210 /* If it's the default port and this flag isn't set, don't do anything. */
2211 if(flags & Uri_CREATE_NO_CANONICALIZE) {
2212 /* Copy the original port over. */
2214 uri->canon_uri[uri->canon_len] = ':';
2215 memcpy(uri->canon_uri+uri->canon_len+1, data->port, data->port_len*sizeof(WCHAR));
2217 uri->canon_len += data->port_len+1;
2220 uri->port = default_port;
2221 } else if(data->port) {
2223 uri->canon_uri[uri->canon_len] = ':';
2226 if(flags & Uri_CREATE_NO_CANONICALIZE) {
2227 /* Copy the original over without changes. */
2229 memcpy(uri->canon_uri+uri->canon_len, data->port, data->port_len*sizeof(WCHAR));
2230 uri->canon_len += data->port_len;
2232 const WCHAR formatW[] = {'%','u',0};
2235 len = sprintfW(uri->canon_uri+uri->canon_len, formatW, data->port_value);
2238 len = sprintfW(tmp, formatW, data->port_value);
2240 uri->canon_len += len;
2243 uri->port = data->port_value;
2244 } else if(has_default_port)
2245 uri->port = default_port;
2250 /* Canonicalizes the authority of the URI represented by the parse_data. */
2251 static BOOL canonicalize_authority(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
2252 uri->authority_start = uri->canon_len;
2253 uri->authority_len = 0;
2255 if(!canonicalize_userinfo(data, uri, flags, computeOnly))
2258 if(!canonicalize_host(data, uri, flags, computeOnly))
2261 if(!canonicalize_port(data, uri, flags, computeOnly))
2264 if(uri->host_start != -1)
2265 uri->authority_len = uri->canon_len - uri->authority_start;
2267 uri->authority_start = -1;
2272 /* Attempts to canonicalize the path of a hierarchical URI.
2274 * Things that happen:
2275 * 1). Forbidden characters are percent encoded, unless the NO_ENCODE_FORBIDDEN
2276 * flag is set or it's a file URI. Forbidden characters are always encoded
2277 * for file schemes reguardless and forbidden characters are never encoded
2278 * for unknown scheme types.
2280 * 2). For known scheme types '\\' are changed to '/'.
2282 * 3). Percent encoded, unreserved characters are decoded to their actual values.
2283 * Unless the scheme type is unknown. For file schemes any percent encoded
2284 * character in the unreserved or reserved set is decoded.
2286 * 4). For File schemes if the path is starts with a drive letter and doesn't
2287 * start with a '/' then one is appended.
2288 * Ex: file://c:/test.mp3 -> file:///c:/test.mp3
2290 * 5). Dot segments are removed from the path for all scheme types
2291 * unless NO_CANONICALIZE flag is set. Dot segments aren't removed
2292 * for wildcard scheme types.
2295 * file://c:/test%20test -> file:///c:/test%2520test
2296 * file://c:/test%3Etest -> file:///c:/test%253Etest
2297 * file:///c:/test%20test -> file:///c:/test%20test
2298 * file:///c:/test%test -> file:///c:/test%25test
2300 static BOOL canonicalize_path_hierarchical(const parse_data *data, Uri *uri,
2301 DWORD flags, BOOL computeOnly) {
2303 const BOOL known_scheme = data->scheme_type != URL_SCHEME_UNKNOWN;
2304 const BOOL is_file = data->scheme_type == URL_SCHEME_FILE;
2306 BOOL escape_pct = FALSE;
2309 uri->path_start = -1;
2314 uri->path_start = uri->canon_len;
2316 /* Check if a '/' needs to be appended for the file scheme. */
2318 if(data->path_len > 1 && is_alpha(*(data->path)) &&
2319 *(data->path+1) == ':') {
2321 uri->canon_uri[uri->canon_len] = '/';
2327 for(ptr = data->path; ptr < data->path+data->path_len; ++ptr) {
2329 const WCHAR *tmp = ptr;
2332 /* Check if the % represents a valid encoded char, or if it needs encoded. */
2333 BOOL force_encode = !check_pct_encoded(&tmp) && is_file;
2334 val = decode_pct_val(ptr);
2336 if(force_encode || escape_pct) {
2337 /* Escape the percent sign in the file URI. */
2339 pct_encode_val(*ptr, uri->canon_uri+uri->canon_len);
2340 uri->canon_len += 3;
2341 } else if((is_unreserved(val) && known_scheme) ||
2342 (is_file && (is_unreserved(val) || is_reserved(val)))) {
2344 uri->canon_uri[uri->canon_len] = val;
2351 uri->canon_uri[uri->canon_len] = *ptr;
2354 } else if(*ptr == '\\' && known_scheme) {
2356 uri->canon_uri[uri->canon_len] = '/';
2358 } else if(known_scheme && !is_unreserved(*ptr) && !is_reserved(*ptr) &&
2359 (!(flags & Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS) || is_file)) {
2360 /* Escape the forbidden character. */
2362 pct_encode_val(*ptr, uri->canon_uri+uri->canon_len);
2363 uri->canon_len += 3;
2366 uri->canon_uri[uri->canon_len] = *ptr;
2371 uri->path_len = uri->canon_len - uri->path_start;
2374 TRACE("Canonicalized path %s len=%d\n",
2375 debugstr_wn(uri->canon_uri+uri->path_start, uri->path_len),
2381 /* Determines how the URI represented by the parse_data should be canonicalized.
2383 * Essentially, if the parse_data represents an hierarchical URI then it calls
2384 * canonicalize_authority and the canonicalization functions for the path. If the
2385 * URI is opaque it canonicalizes the path of the URI.
2387 static BOOL canonicalize_hierpart(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
2388 if(!data->is_opaque) {
2389 /* "//" is only added for non-wildcard scheme types. */
2390 if(data->scheme_type != URL_SCHEME_WILDCARD) {
2392 INT pos = uri->canon_len;
2394 uri->canon_uri[pos] = '/';
2395 uri->canon_uri[pos+1] = '/';
2397 uri->canon_len += 2;
2400 if(!canonicalize_authority(data, uri, flags, computeOnly))
2403 /* TODO: Canonicalize the path of the URI. */
2404 if(!canonicalize_path_hierarchical(data, uri, flags, computeOnly))
2408 /* Opaque URI's don't have an authority. */
2409 uri->userinfo_start = uri->userinfo_split = -1;
2410 uri->userinfo_len = 0;
2411 uri->host_start = -1;
2413 uri->host_type = Uri_HOST_UNKNOWN;
2414 uri->has_port = FALSE;
2415 uri->authority_start = -1;
2416 uri->authority_len = 0;
2417 uri->domain_offset = -1;
2423 /* Canonicalizes the scheme information specified in the parse_data using the specified flags. */
2424 static BOOL canonicalize_scheme(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
2425 uri->scheme_start = -1;
2426 uri->scheme_len = 0;
2429 /* The only type of URI that doesn't have to have a scheme is a relative
2432 if(!data->is_relative) {
2433 FIXME("(%p %p %x): Unable to determine the scheme type of %s.\n", data,
2434 uri, flags, debugstr_w(data->uri));
2440 INT pos = uri->canon_len;
2442 for(i = 0; i < data->scheme_len; ++i) {
2443 /* Scheme name must be lower case after canonicalization. */
2444 uri->canon_uri[i + pos] = tolowerW(data->scheme[i]);
2447 uri->canon_uri[i + pos] = ':';
2448 uri->scheme_start = pos;
2450 TRACE("(%p %p %x): Canonicalized scheme=%s, len=%d.\n", data, uri, flags,
2451 debugstr_wn(uri->canon_uri, uri->scheme_len), data->scheme_len);
2454 /* This happens in both computation modes. */
2455 uri->canon_len += data->scheme_len + 1;
2456 uri->scheme_len = data->scheme_len;
2461 /* Compute's what the length of the URI specified by the parse_data will be
2462 * after canonicalization occurs using the specified flags.
2464 * This function will return a non-zero value indicating the length of the canonicalized
2465 * URI, or -1 on error.
2467 static int compute_canonicalized_length(const parse_data *data, DWORD flags) {
2470 memset(&uri, 0, sizeof(Uri));
2472 TRACE("(%p %x): Beginning to compute canonicalized length for URI %s\n", data, flags,
2473 debugstr_w(data->uri));
2475 if(!canonicalize_scheme(data, &uri, flags, TRUE)) {
2476 ERR("(%p %x): Failed to compute URI scheme length.\n", data, flags);
2480 if(!canonicalize_hierpart(data, &uri, flags, TRUE)) {
2481 ERR("(%p %x): Failed to compute URI hierpart length.\n", data, flags);
2485 TRACE("(%p %x): Finished computing canonicalized URI length. length=%d\n", data, flags, uri.canon_len);
2487 return uri.canon_len;
2490 /* Canonicalizes the URI data specified in the parse_data, using the given flags. If the
2491 * canonicalization succeededs it will store all the canonicalization information
2492 * in the pointer to the Uri.
2494 * To canonicalize a URI this function first computes what the length of the URI
2495 * specified by the parse_data will be. Once this is done it will then perfom the actual
2496 * canonicalization of the URI.
2498 static HRESULT canonicalize_uri(const parse_data *data, Uri *uri, DWORD flags) {
2501 uri->canon_uri = NULL;
2502 len = uri->canon_size = uri->canon_len = 0;
2504 TRACE("(%p %p %x): beginning to canonicalize URI %s.\n", data, uri, flags, debugstr_w(data->uri));
2506 /* First try to compute the length of the URI. */
2507 len = compute_canonicalized_length(data, flags);
2509 ERR("(%p %p %x): Could not compute the canonicalized length of %s.\n", data, uri, flags,
2510 debugstr_w(data->uri));
2511 return E_INVALIDARG;
2514 uri->canon_uri = heap_alloc((len+1)*sizeof(WCHAR));
2516 return E_OUTOFMEMORY;
2518 if(!canonicalize_scheme(data, uri, flags, FALSE)) {
2519 ERR("(%p %p %x): Unable to canonicalize the scheme of the URI.\n", data, uri, flags);
2520 heap_free(uri->canon_uri);
2521 return E_INVALIDARG;
2523 uri->scheme_type = data->scheme_type;
2525 if(!canonicalize_hierpart(data, uri, flags, FALSE)) {
2526 ERR("(%p %p %x): Unable to canonicalize the heirpart of the URI\n", data, uri, flags);
2527 heap_free(uri->canon_uri);
2528 return E_INVALIDARG;
2531 uri->canon_uri[uri->canon_len] = '\0';
2532 TRACE("(%p %p %x): finished canonicalizing the URI. uri=%s\n", data, uri, flags, debugstr_w(uri->canon_uri));
2537 #define URI(x) ((IUri*) &(x)->lpIUriVtbl)
2538 #define URIBUILDER(x) ((IUriBuilder*) &(x)->lpIUriBuilderVtbl)
2540 #define URI_THIS(iface) DEFINE_THIS(Uri, IUri, iface)
2542 static HRESULT WINAPI Uri_QueryInterface(IUri *iface, REFIID riid, void **ppv)
2544 Uri *This = URI_THIS(iface);
2546 if(IsEqualGUID(&IID_IUnknown, riid)) {
2547 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2549 }else if(IsEqualGUID(&IID_IUri, riid)) {
2550 TRACE("(%p)->(IID_IUri %p)\n", This, ppv);
2553 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2555 return E_NOINTERFACE;
2558 IUnknown_AddRef((IUnknown*)*ppv);
2562 static ULONG WINAPI Uri_AddRef(IUri *iface)
2564 Uri *This = URI_THIS(iface);
2565 LONG ref = InterlockedIncrement(&This->ref);
2567 TRACE("(%p) ref=%d\n", This, ref);
2572 static ULONG WINAPI Uri_Release(IUri *iface)
2574 Uri *This = URI_THIS(iface);
2575 LONG ref = InterlockedDecrement(&This->ref);
2577 TRACE("(%p) ref=%d\n", This, ref);
2580 SysFreeString(This->raw_uri);
2581 heap_free(This->canon_uri);
2588 static HRESULT WINAPI Uri_GetPropertyBSTR(IUri *iface, Uri_PROPERTY uriProp, BSTR *pbstrProperty, DWORD dwFlags)
2590 Uri *This = URI_THIS(iface);
2592 TRACE("(%p)->(%d %p %x)\n", This, uriProp, pbstrProperty, dwFlags);
2597 if(uriProp > Uri_PROPERTY_STRING_LAST) {
2598 /* Windows allocates an empty BSTR for invalid Uri_PROPERTY's. */
2599 *pbstrProperty = SysAllocStringLen(NULL, 0);
2600 if(!(*pbstrProperty))
2601 return E_OUTOFMEMORY;
2603 /* It only returns S_FALSE for the ZONE property... */
2604 if(uriProp == Uri_PROPERTY_ZONE)
2610 /* Don't have support for flags yet. */
2612 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pbstrProperty, dwFlags);
2617 case Uri_PROPERTY_AUTHORITY:
2618 if(This->authority_start > -1) {
2619 *pbstrProperty = SysAllocStringLen(This->canon_uri+This->authority_start, This->authority_len);
2622 *pbstrProperty = SysAllocStringLen(NULL, 0);
2626 if(!(*pbstrProperty))
2627 hres = E_OUTOFMEMORY;
2630 case Uri_PROPERTY_DOMAIN:
2631 if(This->domain_offset > -1) {
2632 *pbstrProperty = SysAllocStringLen(This->canon_uri+This->host_start+This->domain_offset,
2633 This->host_len-This->domain_offset);
2636 *pbstrProperty = SysAllocStringLen(NULL, 0);
2640 if(!(*pbstrProperty))
2641 hres = E_OUTOFMEMORY;
2644 case Uri_PROPERTY_HOST:
2645 if(This->host_start > -1) {
2646 /* The '[' and ']' aren't included for IPv6 addresses. */
2647 if(This->host_type == Uri_HOST_IPV6)
2648 *pbstrProperty = SysAllocStringLen(This->canon_uri+This->host_start+1, This->host_len-2);
2650 *pbstrProperty = SysAllocStringLen(This->canon_uri+This->host_start, This->host_len);
2654 *pbstrProperty = SysAllocStringLen(NULL, 0);
2658 if(!(*pbstrProperty))
2659 hres = E_OUTOFMEMORY;
2662 case Uri_PROPERTY_PASSWORD:
2663 if(This->userinfo_split > -1) {
2664 *pbstrProperty = SysAllocStringLen(
2665 This->canon_uri+This->userinfo_start+This->userinfo_split+1,
2666 This->userinfo_len-This->userinfo_split-1);
2669 *pbstrProperty = SysAllocStringLen(NULL, 0);
2673 if(!(*pbstrProperty))
2674 return E_OUTOFMEMORY;
2677 case Uri_PROPERTY_RAW_URI:
2678 *pbstrProperty = SysAllocString(This->raw_uri);
2679 if(!(*pbstrProperty))
2680 hres = E_OUTOFMEMORY;
2684 case Uri_PROPERTY_SCHEME_NAME:
2685 if(This->scheme_start > -1) {
2686 *pbstrProperty = SysAllocStringLen(This->canon_uri + This->scheme_start, This->scheme_len);
2689 *pbstrProperty = SysAllocStringLen(NULL, 0);
2693 if(!(*pbstrProperty))
2694 hres = E_OUTOFMEMORY;
2697 case Uri_PROPERTY_USER_INFO:
2698 if(This->userinfo_start > -1) {
2699 *pbstrProperty = SysAllocStringLen(This->canon_uri+This->userinfo_start, This->userinfo_len);
2702 *pbstrProperty = SysAllocStringLen(NULL, 0);
2706 if(!(*pbstrProperty))
2707 hres = E_OUTOFMEMORY;
2710 case Uri_PROPERTY_USER_NAME:
2711 if(This->userinfo_start > -1) {
2712 /* If userinfo_split is set, that means a password exists
2713 * so the username is only from userinfo_start to userinfo_split.
2715 if(This->userinfo_split > -1) {
2716 *pbstrProperty = SysAllocStringLen(This->canon_uri + This->userinfo_start, This->userinfo_split);
2719 *pbstrProperty = SysAllocStringLen(This->canon_uri + This->userinfo_start, This->userinfo_len);
2723 *pbstrProperty = SysAllocStringLen(NULL, 0);
2727 if(!(*pbstrProperty))
2728 return E_OUTOFMEMORY;
2732 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pbstrProperty, dwFlags);
2739 static HRESULT WINAPI Uri_GetPropertyLength(IUri *iface, Uri_PROPERTY uriProp, DWORD *pcchProperty, DWORD dwFlags)
2741 Uri *This = URI_THIS(iface);
2743 TRACE("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
2746 return E_INVALIDARG;
2748 /* Can only return a length for a property if it's a string. */
2749 if(uriProp > Uri_PROPERTY_STRING_LAST)
2750 return E_INVALIDARG;
2752 /* Don't have support for flags yet. */
2754 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
2759 case Uri_PROPERTY_AUTHORITY:
2760 *pcchProperty = This->authority_len;
2761 hres = (This->authority_start > -1) ? S_OK : S_FALSE;
2763 case Uri_PROPERTY_DOMAIN:
2764 if(This->domain_offset > -1)
2765 *pcchProperty = This->host_len - This->domain_offset;
2769 hres = (This->domain_offset > -1) ? S_OK : S_FALSE;
2771 case Uri_PROPERTY_HOST:
2772 *pcchProperty = This->host_len;
2774 /* '[' and ']' aren't included in the length. */
2775 if(This->host_type == Uri_HOST_IPV6)
2778 hres = (This->host_start > -1) ? S_OK : S_FALSE;
2780 case Uri_PROPERTY_PASSWORD:
2781 *pcchProperty = (This->userinfo_split > -1) ? This->userinfo_len-This->userinfo_split-1 : 0;
2782 hres = (This->userinfo_split > -1) ? S_OK : S_FALSE;
2784 case Uri_PROPERTY_RAW_URI:
2785 *pcchProperty = SysStringLen(This->raw_uri);
2788 case Uri_PROPERTY_SCHEME_NAME:
2789 *pcchProperty = This->scheme_len;
2790 hres = (This->scheme_start > -1) ? S_OK : S_FALSE;
2792 case Uri_PROPERTY_USER_INFO:
2793 *pcchProperty = This->userinfo_len;
2794 hres = (This->userinfo_start > -1) ? S_OK : S_FALSE;
2796 case Uri_PROPERTY_USER_NAME:
2797 *pcchProperty = (This->userinfo_split > -1) ? This->userinfo_split : This->userinfo_len;
2798 hres = (This->userinfo_start > -1) ? S_OK : S_FALSE;
2801 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
2808 static HRESULT WINAPI Uri_GetPropertyDWORD(IUri *iface, Uri_PROPERTY uriProp, DWORD *pcchProperty, DWORD dwFlags)
2810 Uri *This = URI_THIS(iface);
2813 TRACE("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
2816 return E_INVALIDARG;
2818 /* Microsoft's implementation for the ZONE property of a URI seems to be lacking...
2819 * From what I can tell, instead of checking which URLZONE the URI belongs to it
2820 * simply assigns URLZONE_INVALID and returns E_NOTIMPL. This also applies to the GetZone
2823 if(uriProp == Uri_PROPERTY_ZONE) {
2824 *pcchProperty = URLZONE_INVALID;
2828 if(uriProp < Uri_PROPERTY_DWORD_START) {
2830 return E_INVALIDARG;
2834 case Uri_PROPERTY_HOST_TYPE:
2835 *pcchProperty = This->host_type;
2838 case Uri_PROPERTY_PORT:
2839 if(!This->has_port) {
2843 *pcchProperty = This->port;
2848 case Uri_PROPERTY_SCHEME:
2849 *pcchProperty = This->scheme_type;
2853 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
2860 static HRESULT WINAPI Uri_HasProperty(IUri *iface, Uri_PROPERTY uriProp, BOOL *pfHasProperty)
2862 Uri *This = URI_THIS(iface);
2863 FIXME("(%p)->(%d %p)\n", This, uriProp, pfHasProperty);
2866 return E_INVALIDARG;
2871 static HRESULT WINAPI Uri_GetAbsoluteUri(IUri *iface, BSTR *pstrAbsoluteUri)
2873 Uri *This = URI_THIS(iface);
2874 FIXME("(%p)->(%p)\n", This, pstrAbsoluteUri);
2876 if(!pstrAbsoluteUri)
2882 static HRESULT WINAPI Uri_GetAuthority(IUri *iface, BSTR *pstrAuthority)
2884 TRACE("(%p)->(%p)\n", iface, pstrAuthority);
2885 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_AUTHORITY, pstrAuthority, 0);
2888 static HRESULT WINAPI Uri_GetDisplayUri(IUri *iface, BSTR *pstrDisplayUri)
2890 Uri *This = URI_THIS(iface);
2891 FIXME("(%p)->(%p)\n", This, pstrDisplayUri);
2899 static HRESULT WINAPI Uri_GetDomain(IUri *iface, BSTR *pstrDomain)
2901 TRACE("(%p)->(%p)\n", iface, pstrDomain);
2902 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_DOMAIN, pstrDomain, 0);
2905 static HRESULT WINAPI Uri_GetExtension(IUri *iface, BSTR *pstrExtension)
2907 Uri *This = URI_THIS(iface);
2908 FIXME("(%p)->(%p)\n", This, pstrExtension);
2916 static HRESULT WINAPI Uri_GetFragment(IUri *iface, BSTR *pstrFragment)
2918 Uri *This = URI_THIS(iface);
2919 FIXME("(%p)->(%p)\n", This, pstrFragment);
2927 static HRESULT WINAPI Uri_GetHost(IUri *iface, BSTR *pstrHost)
2929 TRACE("(%p)->(%p)\n", iface, pstrHost);
2930 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_HOST, pstrHost, 0);
2933 static HRESULT WINAPI Uri_GetPassword(IUri *iface, BSTR *pstrPassword)
2935 TRACE("(%p)->(%p)\n", iface, pstrPassword);
2936 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_PASSWORD, pstrPassword, 0);
2939 static HRESULT WINAPI Uri_GetPath(IUri *iface, BSTR *pstrPath)
2941 Uri *This = URI_THIS(iface);
2942 FIXME("(%p)->(%p)\n", This, pstrPath);
2950 static HRESULT WINAPI Uri_GetPathAndQuery(IUri *iface, BSTR *pstrPathAndQuery)
2952 Uri *This = URI_THIS(iface);
2953 FIXME("(%p)->(%p)\n", This, pstrPathAndQuery);
2955 if(!pstrPathAndQuery)
2961 static HRESULT WINAPI Uri_GetQuery(IUri *iface, BSTR *pstrQuery)
2963 Uri *This = URI_THIS(iface);
2964 FIXME("(%p)->(%p)\n", This, pstrQuery);
2972 static HRESULT WINAPI Uri_GetRawUri(IUri *iface, BSTR *pstrRawUri)
2974 Uri *This = URI_THIS(iface);
2975 TRACE("(%p)->(%p)\n", This, pstrRawUri);
2977 /* Just forward the call to GetPropertyBSTR. */
2978 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_RAW_URI, pstrRawUri, 0);
2981 static HRESULT WINAPI Uri_GetSchemeName(IUri *iface, BSTR *pstrSchemeName)
2983 Uri *This = URI_THIS(iface);
2984 TRACE("(%p)->(%p)\n", This, pstrSchemeName);
2985 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_SCHEME_NAME, pstrSchemeName, 0);
2988 static HRESULT WINAPI Uri_GetUserInfo(IUri *iface, BSTR *pstrUserInfo)
2990 TRACE("(%p)->(%p)\n", iface, pstrUserInfo);
2991 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_USER_INFO, pstrUserInfo, 0);
2994 static HRESULT WINAPI Uri_GetUserName(IUri *iface, BSTR *pstrUserName)
2996 TRACE("(%p)->(%p)\n", iface, pstrUserName);
2997 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_USER_NAME, pstrUserName, 0);
3000 static HRESULT WINAPI Uri_GetHostType(IUri *iface, DWORD *pdwHostType)
3002 TRACE("(%p)->(%p)\n", iface, pdwHostType);
3003 return Uri_GetPropertyDWORD(iface, Uri_PROPERTY_HOST_TYPE, pdwHostType, 0);
3006 static HRESULT WINAPI Uri_GetPort(IUri *iface, DWORD *pdwPort)
3008 TRACE("(%p)->(%p)\n", iface, pdwPort);
3009 return Uri_GetPropertyDWORD(iface, Uri_PROPERTY_PORT, pdwPort, 0);
3012 static HRESULT WINAPI Uri_GetScheme(IUri *iface, DWORD *pdwScheme)
3014 Uri *This = URI_THIS(iface);
3015 TRACE("(%p)->(%p)\n", This, pdwScheme);
3016 return Uri_GetPropertyDWORD(iface, Uri_PROPERTY_SCHEME, pdwScheme, 0);
3019 static HRESULT WINAPI Uri_GetZone(IUri *iface, DWORD *pdwZone)
3021 TRACE("(%p)->(%p)\n", iface, pdwZone);
3022 return Uri_GetPropertyDWORD(iface, Uri_PROPERTY_ZONE,pdwZone, 0);
3025 static HRESULT WINAPI Uri_GetProperties(IUri *iface, DWORD *pdwProperties)
3027 Uri *This = URI_THIS(iface);
3028 FIXME("(%p)->(%p)\n", This, pdwProperties);
3031 return E_INVALIDARG;
3036 static HRESULT WINAPI Uri_IsEqual(IUri *iface, IUri *pUri, BOOL *pfEqual)
3038 Uri *This = URI_THIS(iface);
3039 TRACE("(%p)->(%p %p)\n", This, pUri, pfEqual);
3047 /* For some reason Windows returns S_OK here... */
3051 FIXME("(%p)->(%p %p)\n", This, pUri, pfEqual);
3057 static const IUriVtbl UriVtbl = {
3061 Uri_GetPropertyBSTR,
3062 Uri_GetPropertyLength,
3063 Uri_GetPropertyDWORD,
3074 Uri_GetPathAndQuery,
3088 /***********************************************************************
3089 * CreateUri (urlmon.@)
3091 HRESULT WINAPI CreateUri(LPCWSTR pwzURI, DWORD dwFlags, DWORD_PTR dwReserved, IUri **ppURI)
3097 TRACE("(%s %x %x %p)\n", debugstr_w(pwzURI), dwFlags, (DWORD)dwReserved, ppURI);
3100 return E_INVALIDARG;
3104 return E_INVALIDARG;
3107 ret = heap_alloc(sizeof(Uri));
3109 return E_OUTOFMEMORY;
3111 ret->lpIUriVtbl = &UriVtbl;
3114 /* Create a copy of pwzURI and store it as the raw_uri. */
3115 ret->raw_uri = SysAllocString(pwzURI);
3118 return E_OUTOFMEMORY;
3121 memset(&data, 0, sizeof(parse_data));
3122 data.uri = ret->raw_uri;
3124 /* Validate and parse the URI into it's components. */
3125 if(!parse_uri(&data, dwFlags)) {
3126 /* Encountered an unsupported or invalid URI */
3127 SysFreeString(ret->raw_uri);
3130 return E_INVALIDARG;
3133 /* Canonicalize the URI. */
3134 hr = canonicalize_uri(&data, ret, dwFlags);
3136 SysFreeString(ret->raw_uri);
3146 #define URIBUILDER_THIS(iface) DEFINE_THIS(UriBuilder, IUriBuilder, iface)
3148 static HRESULT WINAPI UriBuilder_QueryInterface(IUriBuilder *iface, REFIID riid, void **ppv)
3150 UriBuilder *This = URIBUILDER_THIS(iface);
3152 if(IsEqualGUID(&IID_IUnknown, riid)) {
3153 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
3154 *ppv = URIBUILDER(This);
3155 }else if(IsEqualGUID(&IID_IUriBuilder, riid)) {
3156 TRACE("(%p)->(IID_IUri %p)\n", This, ppv);
3157 *ppv = URIBUILDER(This);
3159 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
3161 return E_NOINTERFACE;
3164 IUnknown_AddRef((IUnknown*)*ppv);
3168 static ULONG WINAPI UriBuilder_AddRef(IUriBuilder *iface)
3170 UriBuilder *This = URIBUILDER_THIS(iface);
3171 LONG ref = InterlockedIncrement(&This->ref);
3173 TRACE("(%p) ref=%d\n", This, ref);
3178 static ULONG WINAPI UriBuilder_Release(IUriBuilder *iface)
3180 UriBuilder *This = URIBUILDER_THIS(iface);
3181 LONG ref = InterlockedDecrement(&This->ref);
3183 TRACE("(%p) ref=%d\n", This, ref);
3191 static HRESULT WINAPI UriBuilder_CreateUriSimple(IUriBuilder *iface,
3192 DWORD dwAllowEncodingPropertyMask,
3193 DWORD_PTR dwReserved,
3196 UriBuilder *This = URIBUILDER_THIS(iface);
3197 FIXME("(%p)->(%d %d %p)\n", This, dwAllowEncodingPropertyMask, (DWORD)dwReserved, ppIUri);
3201 static HRESULT WINAPI UriBuilder_CreateUri(IUriBuilder *iface,
3202 DWORD dwCreateFlags,
3203 DWORD dwAllowEncodingPropertyMask,
3204 DWORD_PTR dwReserved,
3207 UriBuilder *This = URIBUILDER_THIS(iface);
3208 FIXME("(%p)->(0x%08x %d %d %p)\n", This, dwCreateFlags, dwAllowEncodingPropertyMask, (DWORD)dwReserved, ppIUri);
3212 static HRESULT WINAPI UriBuilder_CreateUriWithFlags(IUriBuilder *iface,
3213 DWORD dwCreateFlags,
3214 DWORD dwUriBuilderFlags,
3215 DWORD dwAllowEncodingPropertyMask,
3216 DWORD_PTR dwReserved,
3219 UriBuilder *This = URIBUILDER_THIS(iface);
3220 FIXME("(%p)->(0x%08x 0x%08x %d %d %p)\n", This, dwCreateFlags, dwUriBuilderFlags,
3221 dwAllowEncodingPropertyMask, (DWORD)dwReserved, ppIUri);
3225 static HRESULT WINAPI UriBuilder_GetIUri(IUriBuilder *iface, IUri **ppIUri)
3227 UriBuilder *This = URIBUILDER_THIS(iface);
3228 FIXME("(%p)->(%p)\n", This, ppIUri);
3232 static HRESULT WINAPI UriBuilder_SetIUri(IUriBuilder *iface, IUri *pIUri)
3234 UriBuilder *This = URIBUILDER_THIS(iface);
3235 FIXME("(%p)->(%p)\n", This, pIUri);
3239 static HRESULT WINAPI UriBuilder_GetFragment(IUriBuilder *iface, DWORD *pcchFragment, LPCWSTR *ppwzFragment)
3241 UriBuilder *This = URIBUILDER_THIS(iface);
3242 FIXME("(%p)->(%p %p)\n", This, pcchFragment, ppwzFragment);
3246 static HRESULT WINAPI UriBuilder_GetHost(IUriBuilder *iface, DWORD *pcchHost, LPCWSTR *ppwzHost)
3248 UriBuilder *This = URIBUILDER_THIS(iface);
3249 FIXME("(%p)->(%p %p)\n", This, pcchHost, ppwzHost);
3253 static HRESULT WINAPI UriBuilder_GetPassword(IUriBuilder *iface, DWORD *pcchPassword, LPCWSTR *ppwzPassword)
3255 UriBuilder *This = URIBUILDER_THIS(iface);
3256 FIXME("(%p)->(%p %p)\n", This, pcchPassword, ppwzPassword);
3260 static HRESULT WINAPI UriBuilder_GetPath(IUriBuilder *iface, DWORD *pcchPath, LPCWSTR *ppwzPath)
3262 UriBuilder *This = URIBUILDER_THIS(iface);
3263 FIXME("(%p)->(%p %p)\n", This, pcchPath, ppwzPath);
3267 static HRESULT WINAPI UriBuilder_GetPort(IUriBuilder *iface, BOOL *pfHasPort, DWORD *pdwPort)
3269 UriBuilder *This = URIBUILDER_THIS(iface);
3270 FIXME("(%p)->(%p %p)\n", This, pfHasPort, pdwPort);
3274 static HRESULT WINAPI UriBuilder_GetQuery(IUriBuilder *iface, DWORD *pcchQuery, LPCWSTR *ppwzQuery)
3276 UriBuilder *This = URIBUILDER_THIS(iface);
3277 FIXME("(%p)->(%p %p)\n", This, pcchQuery, ppwzQuery);
3281 static HRESULT WINAPI UriBuilder_GetSchemeName(IUriBuilder *iface, DWORD *pcchSchemeName, LPCWSTR *ppwzSchemeName)
3283 UriBuilder *This = URIBUILDER_THIS(iface);
3284 FIXME("(%p)->(%p %p)\n", This, pcchSchemeName, ppwzSchemeName);
3288 static HRESULT WINAPI UriBuilder_GetUserName(IUriBuilder *iface, DWORD *pcchUserName, LPCWSTR *ppwzUserName)
3290 UriBuilder *This = URIBUILDER_THIS(iface);
3291 FIXME("(%p)->(%p %p)\n", This, pcchUserName, ppwzUserName);
3295 static HRESULT WINAPI UriBuilder_SetFragment(IUriBuilder *iface, LPCWSTR pwzNewValue)
3297 UriBuilder *This = URIBUILDER_THIS(iface);
3298 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3302 static HRESULT WINAPI UriBuilder_SetHost(IUriBuilder *iface, LPCWSTR pwzNewValue)
3304 UriBuilder *This = URIBUILDER_THIS(iface);
3305 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3309 static HRESULT WINAPI UriBuilder_SetPassword(IUriBuilder *iface, LPCWSTR pwzNewValue)
3311 UriBuilder *This = URIBUILDER_THIS(iface);
3312 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3316 static HRESULT WINAPI UriBuilder_SetPath(IUriBuilder *iface, LPCWSTR pwzNewValue)
3318 UriBuilder *This = URIBUILDER_THIS(iface);
3319 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3323 static HRESULT WINAPI UriBuilder_SetPort(IUriBuilder *iface, BOOL fHasPort, DWORD dwNewValue)
3325 UriBuilder *This = URIBUILDER_THIS(iface);
3326 FIXME("(%p)->(%d %d)\n", This, fHasPort, dwNewValue);
3330 static HRESULT WINAPI UriBuilder_SetQuery(IUriBuilder *iface, LPCWSTR pwzNewValue)
3332 UriBuilder *This = URIBUILDER_THIS(iface);
3333 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3337 static HRESULT WINAPI UriBuilder_SetSchemeName(IUriBuilder *iface, LPCWSTR pwzNewValue)
3339 UriBuilder *This = URIBUILDER_THIS(iface);
3340 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3344 static HRESULT WINAPI UriBuilder_SetUserName(IUriBuilder *iface, LPCWSTR pwzNewValue)
3346 UriBuilder *This = URIBUILDER_THIS(iface);
3347 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
3351 static HRESULT WINAPI UriBuilder_RemoveProperties(IUriBuilder *iface, DWORD dwPropertyMask)
3353 UriBuilder *This = URIBUILDER_THIS(iface);
3354 FIXME("(%p)->(0x%08x)\n", This, dwPropertyMask);
3358 static HRESULT WINAPI UriBuilder_HasBeenModified(IUriBuilder *iface, BOOL *pfModified)
3360 UriBuilder *This = URIBUILDER_THIS(iface);
3361 FIXME("(%p)->(%p)\n", This, pfModified);
3365 #undef URIBUILDER_THIS
3367 static const IUriBuilderVtbl UriBuilderVtbl = {
3368 UriBuilder_QueryInterface,
3371 UriBuilder_CreateUriSimple,
3372 UriBuilder_CreateUri,
3373 UriBuilder_CreateUriWithFlags,
3376 UriBuilder_GetFragment,
3378 UriBuilder_GetPassword,
3381 UriBuilder_GetQuery,
3382 UriBuilder_GetSchemeName,
3383 UriBuilder_GetUserName,
3384 UriBuilder_SetFragment,
3386 UriBuilder_SetPassword,
3389 UriBuilder_SetQuery,
3390 UriBuilder_SetSchemeName,
3391 UriBuilder_SetUserName,
3392 UriBuilder_RemoveProperties,
3393 UriBuilder_HasBeenModified,
3396 /***********************************************************************
3397 * CreateIUriBuilder (urlmon.@)
3399 HRESULT WINAPI CreateIUriBuilder(IUri *pIUri, DWORD dwFlags, DWORD_PTR dwReserved, IUriBuilder **ppIUriBuilder)
3403 TRACE("(%p %x %x %p)\n", pIUri, dwFlags, (DWORD)dwReserved, ppIUriBuilder);
3405 ret = heap_alloc(sizeof(UriBuilder));
3407 return E_OUTOFMEMORY;
3409 ret->lpIUriBuilderVtbl = &UriBuilderVtbl;
3412 *ppIUriBuilder = URIBUILDER(ret);