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 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
29 const IUriVtbl *lpIUriVtbl;
33 /* Information about the canonicalized URI's buffer. */
40 URL_SCHEME scheme_type;
48 const IUriBuilderVtbl *lpIUriBuilderVtbl;
57 BOOL has_implicit_scheme;
61 URL_SCHEME scheme_type;
63 const WCHAR *userinfo;
68 static const CHAR hexDigits[] = "0123456789ABCDEF";
70 /* List of scheme types/scheme names that are recognized by the IUri interface as of IE 7. */
73 WCHAR scheme_name[16];
74 } recognized_schemes[] = {
75 {URL_SCHEME_FTP, {'f','t','p',0}},
76 {URL_SCHEME_HTTP, {'h','t','t','p',0}},
77 {URL_SCHEME_GOPHER, {'g','o','p','h','e','r',0}},
78 {URL_SCHEME_MAILTO, {'m','a','i','l','t','o',0}},
79 {URL_SCHEME_NEWS, {'n','e','w','s',0}},
80 {URL_SCHEME_NNTP, {'n','n','t','p',0}},
81 {URL_SCHEME_TELNET, {'t','e','l','n','e','t',0}},
82 {URL_SCHEME_WAIS, {'w','a','i','s',0}},
83 {URL_SCHEME_FILE, {'f','i','l','e',0}},
84 {URL_SCHEME_MK, {'m','k',0}},
85 {URL_SCHEME_HTTPS, {'h','t','t','p','s',0}},
86 {URL_SCHEME_SHELL, {'s','h','e','l','l',0}},
87 {URL_SCHEME_SNEWS, {'s','n','e','w','s',0}},
88 {URL_SCHEME_LOCAL, {'l','o','c','a','l',0}},
89 {URL_SCHEME_JAVASCRIPT, {'j','a','v','a','s','c','r','i','p','t',0}},
90 {URL_SCHEME_VBSCRIPT, {'v','b','s','c','r','i','p','t',0}},
91 {URL_SCHEME_ABOUT, {'a','b','o','u','t',0}},
92 {URL_SCHEME_RES, {'r','e','s',0}},
93 {URL_SCHEME_MSSHELLROOTED, {'m','s','-','s','h','e','l','l','-','r','o','o','t','e','d',0}},
94 {URL_SCHEME_MSSHELLIDLIST, {'m','s','-','s','h','e','l','l','-','i','d','l','i','s','t',0}},
95 {URL_SCHEME_MSHELP, {'h','c','p',0}},
96 {URL_SCHEME_WILDCARD, {'*',0}}
99 static inline BOOL is_alpha(WCHAR val) {
100 return ((val >= 'a' && val <= 'z') || (val >= 'A' && val <= 'Z'));
103 static inline BOOL is_num(WCHAR val) {
104 return (val >= '0' && val <= '9');
107 /* A URI is implicitly a file path if it begins with
108 * a drive letter (eg X:) or starts with "\\" (UNC path).
110 static inline BOOL is_implicit_file_path(const WCHAR *str) {
111 if(is_alpha(str[0]) && str[1] == ':')
113 else if(str[0] == '\\' && str[1] == '\\')
119 /* Checks if the URI is a hierarchical URI. A hierarchical
120 * URI is one that has "//" after the scheme.
122 static BOOL check_hierarchical(const WCHAR **ptr) {
123 const WCHAR *start = *ptr;
138 /* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" */
139 static inline BOOL is_unreserved(WCHAR val) {
140 return (is_alpha(val) || is_num(val) || val == '-' || val == '.' ||
141 val == '_' || val == '~');
144 /* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
145 * / "*" / "+" / "," / ";" / "="
147 static inline BOOL is_subdelim(WCHAR val) {
148 return (val == '!' || val == '$' || val == '&' ||
149 val == '\'' || val == '(' || val == ')' ||
150 val == '*' || val == '+' || val == ',' ||
151 val == ';' || val == '=');
154 /* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" */
155 static inline BOOL is_gendelim(WCHAR val) {
156 return (val == ':' || val == '/' || val == '?' ||
157 val == '#' || val == '[' || val == ']' ||
161 /* Characters that delimit the end of the authority
162 * section of a URI. Sometimes a '\\' is considered
163 * an authority delimeter.
165 static inline BOOL is_auth_delim(WCHAR val, BOOL acceptSlash) {
166 return (val == '#' || val == '/' || val == '?' ||
167 val == '\0' || (acceptSlash && val == '\\'));
170 /* reserved = gen-delims / sub-delims */
171 static inline BOOL is_reserved(WCHAR val) {
172 return (is_subdelim(val) || is_gendelim(val));
175 static inline BOOL is_hexdigit(WCHAR val) {
176 return ((val >= 'a' && val <= 'f') ||
177 (val >= 'A' && val <= 'F') ||
178 (val >= '0' && val <= '9'));
181 /* Taken from dlls/jscript/lex.c */
182 static int hex_to_int(WCHAR val) {
183 if(val >= '0' && val <= '9')
185 else if(val >= 'a' && val <= 'f')
186 return val - 'a' + 10;
187 else if(val >= 'A' && val <= 'F')
188 return val - 'A' + 10;
193 /* Helper function for converting a percent encoded string
194 * representation of a WCHAR value into its actual WCHAR value. If
195 * the two characters following the '%' aren't valid hex values then
196 * this function returns the NULL character.
199 * "%2E" will result in '.' being returned by this function.
201 static WCHAR decode_pct_val(const WCHAR *ptr) {
204 if(*ptr == '%' && is_hexdigit(*(ptr + 1)) && is_hexdigit(*(ptr + 2))) {
205 INT a = hex_to_int(*(ptr + 1));
206 INT b = hex_to_int(*(ptr + 2));
215 /* Helper function for percent encoding a given character
216 * and storing the encoded value into a given buffer (dest).
218 * It's up to the calling function to ensure that there is
219 * at least enough space in 'dest' for the percent encoded
220 * value to be stored (so dest + 3 spaces available).
222 static inline void pct_encode_val(WCHAR val, WCHAR *dest) {
224 dest[1] = hexDigits[(val >> 4) & 0xf];
225 dest[2] = hexDigits[val & 0xf];
228 /* Checks if the characters pointed to by 'ptr' are
229 * a percent encoded data octet.
231 * pct-encoded = "%" HEXDIG HEXDIG
233 static BOOL check_pct_encoded(const WCHAR **ptr) {
234 const WCHAR *start = *ptr;
240 if(!is_hexdigit(**ptr)) {
246 if(!is_hexdigit(**ptr)) {
255 /* Tries to parse the scheme name of the URI.
257 * scheme = ALPHA *(ALPHA | NUM | '+' | '-' | '.') as defined by RFC 3896.
258 * NOTE: Windows accepts a number as the first character of a scheme.
260 static BOOL parse_scheme_name(const WCHAR **ptr, parse_data *data) {
261 const WCHAR *start = *ptr;
264 data->scheme_len = 0;
267 if(**ptr == '*' && *ptr == start) {
268 /* Might have found a wildcard scheme. If it is the next
269 * char has to be a ':' for it to be a valid URI
273 } else if(!is_num(**ptr) && !is_alpha(**ptr) && **ptr != '+' &&
274 **ptr != '-' && **ptr != '.')
283 /* Schemes must end with a ':' */
289 data->scheme = start;
290 data->scheme_len = *ptr - start;
296 /* Tries to deduce the corresponding URL_SCHEME for the given URI. Stores
297 * the deduced URL_SCHEME in data->scheme_type.
299 static BOOL parse_scheme_type(parse_data *data) {
300 /* If there's scheme data then see if it's a recognized scheme. */
301 if(data->scheme && data->scheme_len) {
304 for(i = 0; i < sizeof(recognized_schemes)/sizeof(recognized_schemes[0]); ++i) {
305 if(lstrlenW(recognized_schemes[i].scheme_name) == data->scheme_len) {
306 /* Has to be a case insensitive compare. */
307 if(!StrCmpNIW(recognized_schemes[i].scheme_name, data->scheme, data->scheme_len)) {
308 data->scheme_type = recognized_schemes[i].scheme;
314 /* If we get here it means it's not a recognized scheme. */
315 data->scheme_type = URL_SCHEME_UNKNOWN;
317 } else if(data->is_relative) {
318 /* Relative URI's have no scheme. */
319 data->scheme_type = URL_SCHEME_UNKNOWN;
322 /* Should never reach here! what happened... */
323 FIXME("(%p): Unable to determine scheme type for URI %s\n", data, debugstr_w(data->uri));
328 /* Tries to parse (or deduce) the scheme_name of a URI. If it can't
329 * parse a scheme from the URI it will try to deduce the scheme_name and scheme_type
330 * using the flags specified in 'flags' (if any). Flags that affect how this function
331 * operates are the Uri_CREATE_ALLOW_* flags.
333 * All parsed/deduced information will be stored in 'data' when the function returns.
335 * Returns TRUE if it was able to successfully parse the information.
337 static BOOL parse_scheme(const WCHAR **ptr, parse_data *data, DWORD flags) {
338 static const WCHAR fileW[] = {'f','i','l','e',0};
339 static const WCHAR wildcardW[] = {'*',0};
341 /* First check to see if the uri could implicitly be a file path. */
342 if(is_implicit_file_path(*ptr)) {
343 if(flags & Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME) {
344 data->scheme = fileW;
345 data->scheme_len = lstrlenW(fileW);
346 data->has_implicit_scheme = TRUE;
348 TRACE("(%p %p %x): URI is an implicit file path.\n", ptr, data, flags);
350 /* Window's does not consider anything that can implicitly be a file
351 * path to be a valid URI if the ALLOW_IMPLICIT_FILE_SCHEME flag is not set...
353 TRACE("(%p %p %x): URI is implicitly a file path, but, the ALLOW_IMPLICIT_FILE_SCHEME flag wasn't set.\n",
357 } else if(!parse_scheme_name(ptr, data)) {
358 /* No Scheme was found, this means it could be:
359 * a) an implicit Wildcard scheme
363 if(flags & Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME) {
364 data->scheme = wildcardW;
365 data->scheme_len = lstrlenW(wildcardW);
366 data->has_implicit_scheme = TRUE;
368 TRACE("(%p %p %x): URI is an implicit wildcard scheme.\n", ptr, data, flags);
369 } else if (flags & Uri_CREATE_ALLOW_RELATIVE) {
370 data->is_relative = TRUE;
371 TRACE("(%p %p %x): URI is relative.\n", ptr, data, flags);
373 TRACE("(%p %p %x): Malformed URI found. Unable to deduce scheme name.\n", ptr, data, flags);
378 if(!data->is_relative)
379 TRACE("(%p %p %x): Found scheme=%s scheme_len=%d\n", ptr, data, flags,
380 debugstr_wn(data->scheme, data->scheme_len), data->scheme_len);
382 if(!parse_scheme_type(data))
385 TRACE("(%p %p %x): Assigned %d as the URL_SCHEME.\n", ptr, data, flags, data->scheme_type);
389 /* Parses the userinfo part of the URI (if it exists). The userinfo field of
390 * a URI can consist of "username:password@", or just "username@".
393 * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
396 * 1) If there is more than one ':' in the userinfo part of the URI Windows
397 * uses the first occurence of ':' to delimit the username and password
401 * ftp://user:pass:word@winehq.org
403 * Would yield, "user" as the username and "pass:word" as the password.
405 * 2) Windows allows any character to appear in the "userinfo" part of
406 * a URI, as long as it's not an authority delimeter character set.
408 static void parse_userinfo(const WCHAR **ptr, parse_data *data, DWORD flags) {
409 data->userinfo = *ptr;
410 data->userinfo_split = -1;
412 while(**ptr != '@') {
413 if(**ptr == ':' && data->userinfo_split == -1)
414 data->userinfo_split = *ptr - data->userinfo;
415 else if(**ptr == '%') {
416 /* If it's a known scheme type, it has to be a valid percent
419 if(!check_pct_encoded(ptr)) {
420 if(data->scheme_type != URL_SCHEME_UNKNOWN) {
421 *ptr = data->userinfo;
422 data->userinfo = NULL;
423 data->userinfo_split = -1;
425 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr, data, flags);
430 } else if(is_auth_delim(**ptr, data->scheme_type != URL_SCHEME_UNKNOWN))
437 *ptr = data->userinfo;
438 data->userinfo = NULL;
439 data->userinfo_split = -1;
441 TRACE("(%p %p %x): URI contained no userinfo.\n", ptr, data, flags);
445 data->userinfo_len = *ptr - data->userinfo;
446 TRACE("(%p %p %x): Found userinfo=%s userinfo_len=%d split=%d.\n", ptr, data, flags,
447 debugstr_wn(data->userinfo, data->userinfo_len), data->userinfo_len, data->userinfo_split);
451 /* Parses the authority information from the URI.
453 * authority = [ userinfo "@" ] host [ ":" port ]
455 static BOOL parse_authority(const WCHAR **ptr, parse_data *data, DWORD flags) {
456 parse_userinfo(ptr, data, flags);
458 /* TODO: Parse host and port information. */
463 /* Determines how the URI should be parsed after the scheme information.
465 * If the scheme is followed, by "//" then, it is treated as an hierarchical URI
466 * which then the authority and path information will be parsed out. Otherwise, the
467 * URI will be treated as an opaque URI which the authority information is not parsed
470 * RFC 3896 definition of hier-part:
472 * hier-part = "//" authority path-abempty
477 * MSDN opaque URI definition:
478 * scheme ":" path [ "#" fragment ]
481 * If the URI is of an unknown scheme type and has a "//" following the scheme then it
482 * is treated as a hierarchical URI, but, if the CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is
483 * set then it is considered an opaque URI reguardless of what follows the scheme information
484 * (per MSDN documentation).
486 static BOOL parse_hierpart(const WCHAR **ptr, parse_data *data, DWORD flags) {
487 /* Checks if the authority information needs to be parsed.
489 * Relative URI's aren't hierarchical URI's, but, they could trick
490 * "check_hierarchical" into thinking it is, so we need to explicitly
491 * make sure it's not relative. Also, if the URI is an implicit file
492 * scheme it might not contain a "//", but, it's considered hierarchical
493 * anyways. Wildcard Schemes are always considered hierarchical
495 if(data->scheme_type == URL_SCHEME_WILDCARD ||
496 data->scheme_type == URL_SCHEME_FILE ||
497 (!data->is_relative && check_hierarchical(ptr))) {
498 /* Only treat it as a hierarchical URI if the scheme_type is known or
499 * the Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES flag is not set.
501 if(data->scheme_type != URL_SCHEME_UNKNOWN ||
502 !(flags & Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES)) {
503 TRACE("(%p %p %x): Treating URI as an hierarchical URI.\n", ptr, data, flags);
504 data->is_opaque = FALSE;
506 /* TODO: Handle hierarchical URI's, parse authority then parse the path. */
507 if(!parse_authority(ptr, data, flags))
514 /* If it reaches here, then the URI will be treated as an opaque
518 TRACE("(%p %p %x): Treating URI as an opaque URI.\n", ptr, data, flags);
520 data->is_opaque = TRUE;
521 /* TODO: Handle opaque URI's, parse path. */
525 /* Parses and validates the components of the specified by data->uri
526 * and stores the information it parses into 'data'.
528 * Returns TRUE if it successfully parsed the URI. False otherwise.
530 static BOOL parse_uri(parse_data *data, DWORD flags) {
537 TRACE("(%p %x): BEGINNING TO PARSE URI %s.\n", data, flags, debugstr_w(data->uri));
539 if(!parse_scheme(pptr, data, flags))
542 if(!parse_hierpart(pptr, data, flags))
545 TRACE("(%p %x): FINISHED PARSING URI.\n", data, flags);
549 /* Canonicalizes the userinfo of the URI represented by the parse_data.
551 * Canonicalization of the userinfo is a simple process. If there are any percent
552 * encoded characters that fall in the "unreserved" character set, they are decoded
553 * to their actual value. If a character is not in the "unreserved" or "reserved" sets
554 * then it is percent encoded. Other than that the characters are copied over without
557 static BOOL canonicalize_userinfo(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
560 uri->userinfo_start = uri->userinfo_split = -1;
561 uri->userinfo_len = 0;
564 /* URI doesn't have userinfo, so nothing to do here. */
567 uri->userinfo_start = uri->canon_len;
569 while(i < data->userinfo_len) {
570 if(data->userinfo[i] == ':' && uri->userinfo_split == -1)
571 /* Windows only considers the first ':' as the delimiter. */
572 uri->userinfo_split = uri->canon_len - uri->userinfo_start;
573 else if(data->userinfo[i] == '%') {
574 /* Only decode % encoded values for known scheme types. */
575 if(data->scheme_type != URL_SCHEME_UNKNOWN) {
576 /* See if the value really needs decoded. */
577 WCHAR val = decode_pct_val(data->userinfo + i);
578 if(is_unreserved(val)) {
580 uri->canon_uri[uri->canon_len] = val;
584 /* Move pass the hex characters. */
589 } else if(!is_reserved(data->userinfo[i]) && !is_unreserved(data->userinfo[i]) &&
590 data->userinfo[i] != '\\') {
591 /* Only percent encode forbidden characters if the NO_ENCODE_FORBIDDEN_CHARACTERS flag
594 if(!(flags & Uri_CREATE_NO_ENCODE_FORBIDDEN_CHARACTERS)) {
596 pct_encode_val(data->userinfo[i], uri->canon_uri + uri->canon_len);
605 /* Nothing special, so just copy the character over. */
606 uri->canon_uri[uri->canon_len] = data->userinfo[i];
612 uri->userinfo_len = uri->canon_len - uri->userinfo_start;
614 TRACE("(%p %p %x %d): Canonicalized userinfo, userinfo_start=%d, userinfo=%s, userinfo_split=%d userinfo_len=%d.\n",
615 data, uri, flags, computeOnly, uri->userinfo_start, debugstr_wn(uri->canon_uri + uri->userinfo_start, uri->userinfo_len),
616 uri->userinfo_split, uri->userinfo_len);
618 /* Now insert the '@' after the userinfo. */
620 uri->canon_uri[uri->canon_len] = '@';
626 /* Canonicalizes the authority of the URI represented by the parse_data. */
627 static BOOL canonicalize_authority(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
628 if(!canonicalize_userinfo(data, uri, flags, computeOnly))
631 /* TODO: canonicalize the host and port information. */
636 /* Determines how the URI represented by the parse_data should be canonicalized.
638 * Essentially, if the parse_data represents an hierarchical URI then it calls
639 * canonicalize_authority and the canonicalization functions for the path. If the
640 * URI is opaque it canonicalizes the path of the URI.
642 static BOOL canonicalize_hierpart(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
643 if(!data->is_opaque) {
644 /* "//" is only added for non-wildcard scheme types. */
645 if(data->scheme_type != URL_SCHEME_WILDCARD) {
647 INT pos = uri->canon_len;
649 uri->canon_uri[pos] = '/';
650 uri->canon_uri[pos+1] = '/';
655 if(!canonicalize_authority(data, uri, flags, computeOnly))
658 /* TODO: Canonicalize the path of the URI. */
661 /* Opaque URI's don't have userinfo. */
662 uri->userinfo_start = uri->userinfo_split = -1;
663 uri->userinfo_len = 0;
669 /* Canonicalizes the scheme information specified in the parse_data using the specified flags. */
670 static BOOL canonicalize_scheme(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
671 uri->scheme_start = -1;
675 /* The only type of URI that doesn't have to have a scheme is a relative
678 if(!data->is_relative) {
679 FIXME("(%p %p %x): Unable to determine the scheme type of %s.\n", data,
680 uri, flags, debugstr_w(data->uri));
686 INT pos = uri->canon_len;
688 for(i = 0; i < data->scheme_len; ++i) {
689 /* Scheme name must be lower case after canonicalization. */
690 uri->canon_uri[i + pos] = tolowerW(data->scheme[i]);
693 uri->canon_uri[i + pos] = ':';
694 uri->scheme_start = pos;
696 TRACE("(%p %p %x): Canonicalized scheme=%s, len=%d.\n", data, uri, flags,
697 debugstr_wn(uri->canon_uri, uri->scheme_len), data->scheme_len);
700 /* This happens in both computation modes. */
701 uri->canon_len += data->scheme_len + 1;
702 uri->scheme_len = data->scheme_len;
707 /* Compute's what the length of the URI specified by the parse_data will be
708 * after canonicalization occurs using the specified flags.
710 * This function will return a non-zero value indicating the length of the canonicalized
711 * URI, or -1 on error.
713 static int compute_canonicalized_length(const parse_data *data, DWORD flags) {
716 memset(&uri, 0, sizeof(Uri));
718 TRACE("(%p %x): Beginning to compute canonicalized length for URI %s\n", data, flags,
719 debugstr_w(data->uri));
721 if(!canonicalize_scheme(data, &uri, flags, TRUE)) {
722 ERR("(%p %x): Failed to compute URI scheme length.\n", data, flags);
726 if(!canonicalize_hierpart(data, &uri, flags, TRUE)) {
727 ERR("(%p %x): Failed to compute URI hierpart length.\n", data, flags);
731 TRACE("(%p %x): Finished computing canonicalized URI length. length=%d\n", data, flags, uri.canon_len);
733 return uri.canon_len;
736 /* Canonicalizes the URI data specified in the parse_data, using the given flags. If the
737 * canonicalization succeededs it will store all the canonicalization information
738 * in the pointer to the Uri.
740 * To canonicalize a URI this function first computes what the length of the URI
741 * specified by the parse_data will be. Once this is done it will then perfom the actual
742 * canonicalization of the URI.
744 static HRESULT canonicalize_uri(const parse_data *data, Uri *uri, DWORD flags) {
747 uri->canon_uri = NULL;
748 len = uri->canon_size = uri->canon_len = 0;
750 TRACE("(%p %p %x): beginning to canonicalize URI %s.\n", data, uri, flags, debugstr_w(data->uri));
752 /* First try to compute the length of the URI. */
753 len = compute_canonicalized_length(data, flags);
755 ERR("(%p %p %x): Could not compute the canonicalized length of %s.\n", data, uri, flags,
756 debugstr_w(data->uri));
760 uri->canon_uri = heap_alloc((len+1)*sizeof(WCHAR));
762 return E_OUTOFMEMORY;
764 if(!canonicalize_scheme(data, uri, flags, FALSE)) {
765 ERR("(%p %p %x): Unable to canonicalize the scheme of the URI.\n", data, uri, flags);
766 heap_free(uri->canon_uri);
769 uri->scheme_type = data->scheme_type;
771 if(!canonicalize_hierpart(data, uri, flags, FALSE)) {
772 ERR("(%p %p %x): Unable to canonicalize the heirpart of the URI\n", data, uri, flags);
773 heap_free(uri->canon_uri);
777 uri->canon_uri[uri->canon_len] = '\0';
778 TRACE("(%p %p %x): finished canonicalizing the URI.\n", data, uri, flags);
783 #define URI(x) ((IUri*) &(x)->lpIUriVtbl)
784 #define URIBUILDER(x) ((IUriBuilder*) &(x)->lpIUriBuilderVtbl)
786 #define URI_THIS(iface) DEFINE_THIS(Uri, IUri, iface)
788 static HRESULT WINAPI Uri_QueryInterface(IUri *iface, REFIID riid, void **ppv)
790 Uri *This = URI_THIS(iface);
792 if(IsEqualGUID(&IID_IUnknown, riid)) {
793 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
795 }else if(IsEqualGUID(&IID_IUri, riid)) {
796 TRACE("(%p)->(IID_IUri %p)\n", This, ppv);
799 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
801 return E_NOINTERFACE;
804 IUnknown_AddRef((IUnknown*)*ppv);
808 static ULONG WINAPI Uri_AddRef(IUri *iface)
810 Uri *This = URI_THIS(iface);
811 LONG ref = InterlockedIncrement(&This->ref);
813 TRACE("(%p) ref=%d\n", This, ref);
818 static ULONG WINAPI Uri_Release(IUri *iface)
820 Uri *This = URI_THIS(iface);
821 LONG ref = InterlockedDecrement(&This->ref);
823 TRACE("(%p) ref=%d\n", This, ref);
826 SysFreeString(This->raw_uri);
827 heap_free(This->canon_uri);
834 static HRESULT WINAPI Uri_GetPropertyBSTR(IUri *iface, Uri_PROPERTY uriProp, BSTR *pbstrProperty, DWORD dwFlags)
836 Uri *This = URI_THIS(iface);
838 TRACE("(%p)->(%d %p %x)\n", This, uriProp, pbstrProperty, dwFlags);
843 if(uriProp > Uri_PROPERTY_STRING_LAST) {
844 /* Windows allocates an empty BSTR for invalid Uri_PROPERTY's. */
845 *pbstrProperty = SysAllocStringLen(NULL, 0);
846 if(!(*pbstrProperty))
847 return E_OUTOFMEMORY;
849 /* It only returns S_FALSE for the ZONE property... */
850 if(uriProp == Uri_PROPERTY_ZONE)
856 /* Don't have support for flags yet. */
858 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pbstrProperty, dwFlags);
863 case Uri_PROPERTY_RAW_URI:
864 *pbstrProperty = SysAllocString(This->raw_uri);
865 if(!(*pbstrProperty))
866 hres = E_OUTOFMEMORY;
870 case Uri_PROPERTY_SCHEME_NAME:
871 if(This->scheme_start > -1) {
872 *pbstrProperty = SysAllocStringLen(This->canon_uri + This->scheme_start, This->scheme_len);
875 *pbstrProperty = SysAllocStringLen(NULL, 0);
879 if(!(*pbstrProperty))
880 hres = E_OUTOFMEMORY;
883 case Uri_PROPERTY_USER_INFO:
884 if(This->userinfo_start > -1) {
885 *pbstrProperty = SysAllocStringLen(This->canon_uri+This->userinfo_start, This->userinfo_len);
888 *pbstrProperty = SysAllocStringLen(NULL, 0);
892 if(!(*pbstrProperty))
893 hres = E_OUTOFMEMORY;
896 case Uri_PROPERTY_USER_NAME:
897 if(This->userinfo_start > -1) {
898 /* If userinfo_split is set, that means a password exists
899 * so the username is only from userinfo_start to userinfo_split.
901 if(This->userinfo_split > -1) {
902 *pbstrProperty = SysAllocStringLen(This->canon_uri + This->userinfo_start, This->userinfo_split);
905 *pbstrProperty = SysAllocStringLen(This->canon_uri + This->userinfo_start, This->userinfo_len);
909 *pbstrProperty = SysAllocStringLen(NULL, 0);
913 if(!(*pbstrProperty))
914 return E_OUTOFMEMORY;
918 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pbstrProperty, dwFlags);
925 static HRESULT WINAPI Uri_GetPropertyLength(IUri *iface, Uri_PROPERTY uriProp, DWORD *pcchProperty, DWORD dwFlags)
927 Uri *This = URI_THIS(iface);
929 TRACE("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
934 /* Can only return a length for a property if it's a string. */
935 if(uriProp > Uri_PROPERTY_STRING_LAST)
938 /* Don't have support for flags yet. */
940 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
945 case Uri_PROPERTY_RAW_URI:
946 *pcchProperty = SysStringLen(This->raw_uri);
949 case Uri_PROPERTY_SCHEME_NAME:
950 *pcchProperty = This->scheme_len;
951 hres = (This->scheme_start > -1) ? S_OK : S_FALSE;
953 case Uri_PROPERTY_USER_INFO:
954 *pcchProperty = This->userinfo_len;
955 hres = (This->userinfo_start > -1) ? S_OK : S_FALSE;
957 case Uri_PROPERTY_USER_NAME:
958 *pcchProperty = (This->userinfo_split > -1) ? This->userinfo_split : This->userinfo_len;
959 hres = (This->userinfo_start > -1) ? S_OK : S_FALSE;
962 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
969 static HRESULT WINAPI Uri_GetPropertyDWORD(IUri *iface, Uri_PROPERTY uriProp, DWORD *pcchProperty, DWORD dwFlags)
971 Uri *This = URI_THIS(iface);
974 TRACE("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
979 /* Microsoft's implementation for the ZONE property of a URI seems to be lacking...
980 * From what I can tell, instead of checking which URLZONE the URI belongs to it
981 * simply assigns URLZONE_INVALID and returns E_NOTIMPL. This also applies to the GetZone
984 if(uriProp == Uri_PROPERTY_ZONE) {
985 *pcchProperty = URLZONE_INVALID;
989 if(uriProp < Uri_PROPERTY_DWORD_START) {
995 case Uri_PROPERTY_SCHEME:
996 *pcchProperty = This->scheme_type;
1000 FIXME("(%p)->(%d %p %x)\n", This, uriProp, pcchProperty, dwFlags);
1007 static HRESULT WINAPI Uri_HasProperty(IUri *iface, Uri_PROPERTY uriProp, BOOL *pfHasProperty)
1009 Uri *This = URI_THIS(iface);
1010 FIXME("(%p)->(%d %p)\n", This, uriProp, pfHasProperty);
1013 return E_INVALIDARG;
1018 static HRESULT WINAPI Uri_GetAbsoluteUri(IUri *iface, BSTR *pstrAbsoluteUri)
1020 Uri *This = URI_THIS(iface);
1021 FIXME("(%p)->(%p)\n", This, pstrAbsoluteUri);
1023 if(!pstrAbsoluteUri)
1029 static HRESULT WINAPI Uri_GetAuthority(IUri *iface, BSTR *pstrAuthority)
1031 Uri *This = URI_THIS(iface);
1032 FIXME("(%p)->(%p)\n", This, pstrAuthority);
1040 static HRESULT WINAPI Uri_GetDisplayUri(IUri *iface, BSTR *pstrDisplayUri)
1042 Uri *This = URI_THIS(iface);
1043 FIXME("(%p)->(%p)\n", This, pstrDisplayUri);
1051 static HRESULT WINAPI Uri_GetDomain(IUri *iface, BSTR *pstrDomain)
1053 Uri *This = URI_THIS(iface);
1054 FIXME("(%p)->(%p)\n", This, pstrDomain);
1062 static HRESULT WINAPI Uri_GetExtension(IUri *iface, BSTR *pstrExtension)
1064 Uri *This = URI_THIS(iface);
1065 FIXME("(%p)->(%p)\n", This, pstrExtension);
1073 static HRESULT WINAPI Uri_GetFragment(IUri *iface, BSTR *pstrFragment)
1075 Uri *This = URI_THIS(iface);
1076 FIXME("(%p)->(%p)\n", This, pstrFragment);
1084 static HRESULT WINAPI Uri_GetHost(IUri *iface, BSTR *pstrHost)
1086 Uri *This = URI_THIS(iface);
1087 FIXME("(%p)->(%p)\n", This, pstrHost);
1095 static HRESULT WINAPI Uri_GetPassword(IUri *iface, BSTR *pstrPassword)
1097 Uri *This = URI_THIS(iface);
1098 FIXME("(%p)->(%p)\n", This, pstrPassword);
1106 static HRESULT WINAPI Uri_GetPath(IUri *iface, BSTR *pstrPath)
1108 Uri *This = URI_THIS(iface);
1109 FIXME("(%p)->(%p)\n", This, pstrPath);
1117 static HRESULT WINAPI Uri_GetPathAndQuery(IUri *iface, BSTR *pstrPathAndQuery)
1119 Uri *This = URI_THIS(iface);
1120 FIXME("(%p)->(%p)\n", This, pstrPathAndQuery);
1122 if(!pstrPathAndQuery)
1128 static HRESULT WINAPI Uri_GetQuery(IUri *iface, BSTR *pstrQuery)
1130 Uri *This = URI_THIS(iface);
1131 FIXME("(%p)->(%p)\n", This, pstrQuery);
1139 static HRESULT WINAPI Uri_GetRawUri(IUri *iface, BSTR *pstrRawUri)
1141 Uri *This = URI_THIS(iface);
1142 TRACE("(%p)->(%p)\n", This, pstrRawUri);
1144 /* Just forward the call to GetPropertyBSTR. */
1145 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_RAW_URI, pstrRawUri, 0);
1148 static HRESULT WINAPI Uri_GetSchemeName(IUri *iface, BSTR *pstrSchemeName)
1150 Uri *This = URI_THIS(iface);
1151 TRACE("(%p)->(%p)\n", This, pstrSchemeName);
1152 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_SCHEME_NAME, pstrSchemeName, 0);
1155 static HRESULT WINAPI Uri_GetUserInfo(IUri *iface, BSTR *pstrUserInfo)
1157 TRACE("(%p)->(%p)\n", iface, pstrUserInfo);
1158 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_USER_INFO, pstrUserInfo, 0);
1161 static HRESULT WINAPI Uri_GetUserName(IUri *iface, BSTR *pstrUserName)
1163 TRACE("(%p)->(%p)\n", iface, pstrUserName);
1164 return Uri_GetPropertyBSTR(iface, Uri_PROPERTY_USER_NAME, pstrUserName, 0);
1167 static HRESULT WINAPI Uri_GetHostType(IUri *iface, DWORD *pdwHostType)
1169 Uri *This = URI_THIS(iface);
1170 FIXME("(%p)->(%p)\n", This, pdwHostType);
1173 return E_INVALIDARG;
1178 static HRESULT WINAPI Uri_GetPort(IUri *iface, DWORD *pdwPort)
1180 Uri *This = URI_THIS(iface);
1181 FIXME("(%p)->(%p)\n", This, pdwPort);
1184 return E_INVALIDARG;
1189 static HRESULT WINAPI Uri_GetScheme(IUri *iface, DWORD *pdwScheme)
1191 Uri *This = URI_THIS(iface);
1192 TRACE("(%p)->(%p)\n", This, pdwScheme);
1193 return Uri_GetPropertyDWORD(iface, Uri_PROPERTY_SCHEME, pdwScheme, 0);
1196 static HRESULT WINAPI Uri_GetZone(IUri *iface, DWORD *pdwZone)
1198 Uri *This = URI_THIS(iface);
1199 FIXME("(%p)->(%p)\n", This, pdwZone);
1202 return E_INVALIDARG;
1204 /* Microsoft doesn't seem to have this implemented yet... See
1205 * the comment in Uri_GetPropertyDWORD for more about this.
1207 *pdwZone = URLZONE_INVALID;
1211 static HRESULT WINAPI Uri_GetProperties(IUri *iface, DWORD *pdwProperties)
1213 Uri *This = URI_THIS(iface);
1214 FIXME("(%p)->(%p)\n", This, pdwProperties);
1217 return E_INVALIDARG;
1222 static HRESULT WINAPI Uri_IsEqual(IUri *iface, IUri *pUri, BOOL *pfEqual)
1224 Uri *This = URI_THIS(iface);
1225 TRACE("(%p)->(%p %p)\n", This, pUri, pfEqual);
1233 /* For some reason Windows returns S_OK here... */
1237 FIXME("(%p)->(%p %p)\n", This, pUri, pfEqual);
1243 static const IUriVtbl UriVtbl = {
1247 Uri_GetPropertyBSTR,
1248 Uri_GetPropertyLength,
1249 Uri_GetPropertyDWORD,
1260 Uri_GetPathAndQuery,
1274 /***********************************************************************
1275 * CreateUri (urlmon.@)
1277 HRESULT WINAPI CreateUri(LPCWSTR pwzURI, DWORD dwFlags, DWORD_PTR dwReserved, IUri **ppURI)
1283 TRACE("(%s %x %x %p)\n", debugstr_w(pwzURI), dwFlags, (DWORD)dwReserved, ppURI);
1286 return E_INVALIDARG;
1290 return E_INVALIDARG;
1293 ret = heap_alloc(sizeof(Uri));
1295 return E_OUTOFMEMORY;
1297 ret->lpIUriVtbl = &UriVtbl;
1300 /* Create a copy of pwzURI and store it as the raw_uri. */
1301 ret->raw_uri = SysAllocString(pwzURI);
1304 return E_OUTOFMEMORY;
1307 memset(&data, 0, sizeof(parse_data));
1308 data.uri = ret->raw_uri;
1310 /* Validate and parse the URI into it's components. */
1311 if(!parse_uri(&data, dwFlags)) {
1312 /* Encountered an unsupported or invalid URI */
1313 SysFreeString(ret->raw_uri);
1316 return E_INVALIDARG;
1319 /* Canonicalize the URI. */
1320 hr = canonicalize_uri(&data, ret, dwFlags);
1322 SysFreeString(ret->raw_uri);
1332 #define URIBUILDER_THIS(iface) DEFINE_THIS(UriBuilder, IUriBuilder, iface)
1334 static HRESULT WINAPI UriBuilder_QueryInterface(IUriBuilder *iface, REFIID riid, void **ppv)
1336 UriBuilder *This = URIBUILDER_THIS(iface);
1338 if(IsEqualGUID(&IID_IUnknown, riid)) {
1339 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1340 *ppv = URIBUILDER(This);
1341 }else if(IsEqualGUID(&IID_IUriBuilder, riid)) {
1342 TRACE("(%p)->(IID_IUri %p)\n", This, ppv);
1343 *ppv = URIBUILDER(This);
1345 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1347 return E_NOINTERFACE;
1350 IUnknown_AddRef((IUnknown*)*ppv);
1354 static ULONG WINAPI UriBuilder_AddRef(IUriBuilder *iface)
1356 UriBuilder *This = URIBUILDER_THIS(iface);
1357 LONG ref = InterlockedIncrement(&This->ref);
1359 TRACE("(%p) ref=%d\n", This, ref);
1364 static ULONG WINAPI UriBuilder_Release(IUriBuilder *iface)
1366 UriBuilder *This = URIBUILDER_THIS(iface);
1367 LONG ref = InterlockedDecrement(&This->ref);
1369 TRACE("(%p) ref=%d\n", This, ref);
1377 static HRESULT WINAPI UriBuilder_CreateUriSimple(IUriBuilder *iface,
1378 DWORD dwAllowEncodingPropertyMask,
1379 DWORD_PTR dwReserved,
1382 UriBuilder *This = URIBUILDER_THIS(iface);
1383 FIXME("(%p)->(%d %d %p)\n", This, dwAllowEncodingPropertyMask, (DWORD)dwReserved, ppIUri);
1387 static HRESULT WINAPI UriBuilder_CreateUri(IUriBuilder *iface,
1388 DWORD dwCreateFlags,
1389 DWORD dwAllowEncodingPropertyMask,
1390 DWORD_PTR dwReserved,
1393 UriBuilder *This = URIBUILDER_THIS(iface);
1394 FIXME("(%p)->(0x%08x %d %d %p)\n", This, dwCreateFlags, dwAllowEncodingPropertyMask, (DWORD)dwReserved, ppIUri);
1398 static HRESULT WINAPI UriBuilder_CreateUriWithFlags(IUriBuilder *iface,
1399 DWORD dwCreateFlags,
1400 DWORD dwUriBuilderFlags,
1401 DWORD dwAllowEncodingPropertyMask,
1402 DWORD_PTR dwReserved,
1405 UriBuilder *This = URIBUILDER_THIS(iface);
1406 FIXME("(%p)->(0x%08x 0x%08x %d %d %p)\n", This, dwCreateFlags, dwUriBuilderFlags,
1407 dwAllowEncodingPropertyMask, (DWORD)dwReserved, ppIUri);
1411 static HRESULT WINAPI UriBuilder_GetIUri(IUriBuilder *iface, IUri **ppIUri)
1413 UriBuilder *This = URIBUILDER_THIS(iface);
1414 FIXME("(%p)->(%p)\n", This, ppIUri);
1418 static HRESULT WINAPI UriBuilder_SetIUri(IUriBuilder *iface, IUri *pIUri)
1420 UriBuilder *This = URIBUILDER_THIS(iface);
1421 FIXME("(%p)->(%p)\n", This, pIUri);
1425 static HRESULT WINAPI UriBuilder_GetFragment(IUriBuilder *iface, DWORD *pcchFragment, LPCWSTR *ppwzFragment)
1427 UriBuilder *This = URIBUILDER_THIS(iface);
1428 FIXME("(%p)->(%p %p)\n", This, pcchFragment, ppwzFragment);
1432 static HRESULT WINAPI UriBuilder_GetHost(IUriBuilder *iface, DWORD *pcchHost, LPCWSTR *ppwzHost)
1434 UriBuilder *This = URIBUILDER_THIS(iface);
1435 FIXME("(%p)->(%p %p)\n", This, pcchHost, ppwzHost);
1439 static HRESULT WINAPI UriBuilder_GetPassword(IUriBuilder *iface, DWORD *pcchPassword, LPCWSTR *ppwzPassword)
1441 UriBuilder *This = URIBUILDER_THIS(iface);
1442 FIXME("(%p)->(%p %p)\n", This, pcchPassword, ppwzPassword);
1446 static HRESULT WINAPI UriBuilder_GetPath(IUriBuilder *iface, DWORD *pcchPath, LPCWSTR *ppwzPath)
1448 UriBuilder *This = URIBUILDER_THIS(iface);
1449 FIXME("(%p)->(%p %p)\n", This, pcchPath, ppwzPath);
1453 static HRESULT WINAPI UriBuilder_GetPort(IUriBuilder *iface, BOOL *pfHasPort, DWORD *pdwPort)
1455 UriBuilder *This = URIBUILDER_THIS(iface);
1456 FIXME("(%p)->(%p %p)\n", This, pfHasPort, pdwPort);
1460 static HRESULT WINAPI UriBuilder_GetQuery(IUriBuilder *iface, DWORD *pcchQuery, LPCWSTR *ppwzQuery)
1462 UriBuilder *This = URIBUILDER_THIS(iface);
1463 FIXME("(%p)->(%p %p)\n", This, pcchQuery, ppwzQuery);
1467 static HRESULT WINAPI UriBuilder_GetSchemeName(IUriBuilder *iface, DWORD *pcchSchemeName, LPCWSTR *ppwzSchemeName)
1469 UriBuilder *This = URIBUILDER_THIS(iface);
1470 FIXME("(%p)->(%p %p)\n", This, pcchSchemeName, ppwzSchemeName);
1474 static HRESULT WINAPI UriBuilder_GetUserName(IUriBuilder *iface, DWORD *pcchUserName, LPCWSTR *ppwzUserName)
1476 UriBuilder *This = URIBUILDER_THIS(iface);
1477 FIXME("(%p)->(%p %p)\n", This, pcchUserName, ppwzUserName);
1481 static HRESULT WINAPI UriBuilder_SetFragment(IUriBuilder *iface, LPCWSTR pwzNewValue)
1483 UriBuilder *This = URIBUILDER_THIS(iface);
1484 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1488 static HRESULT WINAPI UriBuilder_SetHost(IUriBuilder *iface, LPCWSTR pwzNewValue)
1490 UriBuilder *This = URIBUILDER_THIS(iface);
1491 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1495 static HRESULT WINAPI UriBuilder_SetPassword(IUriBuilder *iface, LPCWSTR pwzNewValue)
1497 UriBuilder *This = URIBUILDER_THIS(iface);
1498 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1502 static HRESULT WINAPI UriBuilder_SetPath(IUriBuilder *iface, LPCWSTR pwzNewValue)
1504 UriBuilder *This = URIBUILDER_THIS(iface);
1505 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1509 static HRESULT WINAPI UriBuilder_SetPort(IUriBuilder *iface, BOOL fHasPort, DWORD dwNewValue)
1511 UriBuilder *This = URIBUILDER_THIS(iface);
1512 FIXME("(%p)->(%d %d)\n", This, fHasPort, dwNewValue);
1516 static HRESULT WINAPI UriBuilder_SetQuery(IUriBuilder *iface, LPCWSTR pwzNewValue)
1518 UriBuilder *This = URIBUILDER_THIS(iface);
1519 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1523 static HRESULT WINAPI UriBuilder_SetSchemeName(IUriBuilder *iface, LPCWSTR pwzNewValue)
1525 UriBuilder *This = URIBUILDER_THIS(iface);
1526 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1530 static HRESULT WINAPI UriBuilder_SetUserName(IUriBuilder *iface, LPCWSTR pwzNewValue)
1532 UriBuilder *This = URIBUILDER_THIS(iface);
1533 FIXME("(%p)->(%s)\n", This, debugstr_w(pwzNewValue));
1537 static HRESULT WINAPI UriBuilder_RemoveProperties(IUriBuilder *iface, DWORD dwPropertyMask)
1539 UriBuilder *This = URIBUILDER_THIS(iface);
1540 FIXME("(%p)->(0x%08x)\n", This, dwPropertyMask);
1544 static HRESULT WINAPI UriBuilder_HasBeenModified(IUriBuilder *iface, BOOL *pfModified)
1546 UriBuilder *This = URIBUILDER_THIS(iface);
1547 FIXME("(%p)->(%p)\n", This, pfModified);
1551 #undef URIBUILDER_THIS
1553 static const IUriBuilderVtbl UriBuilderVtbl = {
1554 UriBuilder_QueryInterface,
1557 UriBuilder_CreateUriSimple,
1558 UriBuilder_CreateUri,
1559 UriBuilder_CreateUriWithFlags,
1562 UriBuilder_GetFragment,
1564 UriBuilder_GetPassword,
1567 UriBuilder_GetQuery,
1568 UriBuilder_GetSchemeName,
1569 UriBuilder_GetUserName,
1570 UriBuilder_SetFragment,
1572 UriBuilder_SetPassword,
1575 UriBuilder_SetQuery,
1576 UriBuilder_SetSchemeName,
1577 UriBuilder_SetUserName,
1578 UriBuilder_RemoveProperties,
1579 UriBuilder_HasBeenModified,
1582 /***********************************************************************
1583 * CreateIUriBuilder (urlmon.@)
1585 HRESULT WINAPI CreateIUriBuilder(IUri *pIUri, DWORD dwFlags, DWORD_PTR dwReserved, IUriBuilder **ppIUriBuilder)
1589 TRACE("(%p %x %x %p)\n", pIUri, dwFlags, (DWORD)dwReserved, ppIUriBuilder);
1591 ret = heap_alloc(sizeof(UriBuilder));
1593 return E_OUTOFMEMORY;
1595 ret->lpIUriBuilderVtbl = &UriBuilderVtbl;
1598 *ppIUriBuilder = URIBUILDER(ret);