Thomas Mullaly : urlmon: Some IUri's don' t display the default port in the authority.
Alexandre Julliard
julliard at winehq.org
Wed Nov 3 11:37:05 CDT 2010
Module: wine
Branch: master
Commit: 4561a03ea840f4e67a125d92f258457e671f9f2c
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4561a03ea840f4e67a125d92f258457e671f9f2c
Author: Thomas Mullaly <thomas.mullaly at gmail.com>
Date: Fri Oct 29 21:30:00 2010 -0400
urlmon: Some IUri's don't display the default port in the authority.
---
dlls/urlmon/tests/uri.c | 33 +++++++++++++++++++++++++++++++
dlls/urlmon/uri.c | 49 +++++++++++++++++++++++++++++++++++++---------
2 files changed, 72 insertions(+), 10 deletions(-)
diff --git a/dlls/urlmon/tests/uri.c b/dlls/urlmon/tests/uri.c
index 681ad21..5a45632 100644
--- a/dlls/urlmon/tests/uri.c
+++ b/dlls/urlmon/tests/uri.c
@@ -4324,6 +4324,38 @@ static const uri_properties uri_tests[] = {
{URL_SCHEME_FILE,S_OK,FALSE},
{URLZONE_INVALID,E_NOTIMPL,FALSE}
}
+ },
+ /* When CreateUri generates an IUri, it still displays the default port in the
+ * authority.
+ */
+ { "http://google.com:80/", Uri_CREATE_NO_CANONICALIZE, S_OK, FALSE,
+ Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|
+ Uri_HAS_HOST|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|
+ Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
+ FALSE,
+ {
+ {"http://google.com:80/",S_OK,FALSE},
+ {"google.com:80",S_OK,FALSE},
+ {"http://google.com:80/",S_OK,FALSE},
+ {"google.com",S_OK,FALSE},
+ {"",S_FALSE,FALSE},
+ {"",S_FALSE,FALSE},
+ {"google.com",S_OK,FALSE},
+ {"",S_FALSE,FALSE},
+ {"/",S_OK,FALSE},
+ {"/",S_OK,FALSE},
+ {"",S_FALSE,FALSE},
+ {"http://google.com:80/",S_OK,FALSE},
+ {"http",S_OK,FALSE},
+ {"",S_FALSE,FALSE},
+ {"",S_FALSE,FALSE}
+ },
+ {
+ {Uri_HOST_DNS,S_OK,FALSE},
+ {80,S_OK,FALSE},
+ {URL_SCHEME_HTTP,S_OK,FALSE},
+ {URLZONE_INVALID,E_NOTIMPL,FALSE}
+ }
}
};
@@ -5745,6 +5777,7 @@ static const uri_combine_test uri_combine_tests[] = {
URL_DONT_SIMPLIFY,S_OK,TRUE,
{
{"http://winehq.org:80/test/testing/abc/../test",S_OK},
+ /* Default port is hidden in the authority. */
{"winehq.org",S_OK},
{"http://winehq.org:80/test/testing/abc/../test",S_OK},
{"winehq.org",S_OK},
diff --git a/dlls/urlmon/uri.c b/dlls/urlmon/uri.c
index 8ebc694..9b25f69 100644
--- a/dlls/urlmon/uri.c
+++ b/dlls/urlmon/uri.c
@@ -26,6 +26,9 @@
#define UINT_MAX 0xffffffff
#define USHORT_MAX 0xffff
+#define URI_DISPLAY_NO_ABSOLUTE_URI 0x1
+#define URI_DISPLAY_NO_DEFAULT_PORT_AUTH 0x2
+
#define ALLOW_NULL_TERM_SCHEME 0x01
#define ALLOW_NULL_TERM_USER_NAME 0x02
#define ALLOW_NULL_TERM_PASSWORD 0x04
@@ -49,7 +52,7 @@ typedef struct {
WCHAR *canon_uri;
DWORD canon_size;
DWORD canon_len;
- BOOL display_absolute;
+ BOOL display_modifiers;
DWORD create_flags;
INT scheme_start;
@@ -64,6 +67,7 @@ typedef struct {
DWORD host_len;
Uri_HOST_TYPE host_type;
+ INT port_offset;
DWORD port;
BOOL has_port;
@@ -339,6 +343,17 @@ static inline BOOL is_path_delim(WCHAR val) {
return (!val || val == '#' || val == '?');
}
+static BOOL is_default_port(URL_SCHEME scheme, DWORD port) {
+ DWORD i;
+
+ for(i = 0; i < sizeof(default_ports)/sizeof(default_ports[0]); ++i) {
+ if(default_ports[i].scheme == scheme && default_ports[i].port)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/* List of schemes types Windows seems to expect to be hierarchical. */
static inline BOOL is_hierarchical_scheme(URL_SCHEME type) {
return(type == URL_SCHEME_HTTP || type == URL_SCHEME_FTP ||
@@ -2775,6 +2790,8 @@ static BOOL canonicalize_port(const parse_data *data, Uri *uri, DWORD flags, BOO
USHORT default_port = 0;
DWORD i;
+ uri->port_offset = -1;
+
/* Check if the scheme has a default port. */
for(i = 0; i < sizeof(default_ports)/sizeof(default_ports[0]); ++i) {
if(default_ports[i].scheme == data->scheme_type) {
@@ -2795,6 +2812,7 @@ static BOOL canonicalize_port(const parse_data *data, Uri *uri, DWORD flags, BOO
if(has_default_port && data->has_port && data->port_value == default_port) {
/* If it's the default port and this flag isn't set, don't do anything. */
if(flags & Uri_CREATE_NO_CANONICALIZE) {
+ uri->port_offset = uri->canon_len-uri->authority_start;
if(!computeOnly)
uri->canon_uri[uri->canon_len] = ':';
++uri->canon_len;
@@ -2814,6 +2832,7 @@ static BOOL canonicalize_port(const parse_data *data, Uri *uri, DWORD flags, BOO
uri->port = default_port;
} else if(data->has_port) {
+ uri->port_offset = uri->canon_len-uri->authority_start;
if(!computeOnly)
uri->canon_uri[uri->canon_len] = ':';
++uri->canon_len;
@@ -3146,8 +3165,6 @@ static BOOL canonicalize_path_opaque(const parse_data *data, Uri *uri, DWORD fla
* URI is opaque it canonicalizes the path of the URI.
*/
static BOOL canonicalize_hierpart(const parse_data *data, Uri *uri, DWORD flags, BOOL computeOnly) {
- uri->display_absolute = TRUE;
-
if(!data->is_opaque || (data->is_relative && (data->password || data->username))) {
/* "//" is only added for non-wildcard scheme types.
*
@@ -3187,6 +3204,7 @@ static BOOL canonicalize_hierpart(const parse_data *data, Uri *uri, DWORD flags,
uri->authority_start = -1;
uri->authority_len = 0;
uri->domain_offset = -1;
+ uri->port_offset = -1;
if(is_hierarchical_scheme(data->scheme_type)) {
DWORD i;
@@ -3194,7 +3212,7 @@ static BOOL canonicalize_hierpart(const parse_data *data, Uri *uri, DWORD flags,
/* Absolute URIs aren't displayed for known scheme types
* which should be hierarchical URIs.
*/
- uri->display_absolute = FALSE;
+ uri->display_modifiers |= URI_DISPLAY_NO_ABSOLUTE_URI;
/* Windows also sets the port for these (if they have one). */
for(i = 0; i < sizeof(default_ports)/sizeof(default_ports[0]); ++i) {
@@ -4140,7 +4158,7 @@ static HRESULT WINAPI Uri_GetPropertyBSTR(IUri *iface, Uri_PROPERTY uriProp, BST
switch(uriProp) {
case Uri_PROPERTY_ABSOLUTE_URI:
- if(!This->display_absolute) {
+ if(This->display_modifiers & URI_DISPLAY_NO_ABSOLUTE_URI) {
*pbstrProperty = SysAllocStringLen(NULL, 0);
hres = S_FALSE;
} else {
@@ -4182,7 +4200,12 @@ static HRESULT WINAPI Uri_GetPropertyBSTR(IUri *iface, Uri_PROPERTY uriProp, BST
break;
case Uri_PROPERTY_AUTHORITY:
if(This->authority_start > -1) {
- *pbstrProperty = SysAllocStringLen(This->canon_uri+This->authority_start, This->authority_len);
+ if(This->port_offset > -1 && is_default_port(This->scheme_type, This->port) &&
+ This->display_modifiers & URI_DISPLAY_NO_DEFAULT_PORT_AUTH)
+ /* Don't include the port in the authority component. */
+ *pbstrProperty = SysAllocStringLen(This->canon_uri+This->authority_start, This->port_offset);
+ else
+ *pbstrProperty = SysAllocStringLen(This->canon_uri+This->authority_start, This->authority_len);
hres = S_OK;
} else {
*pbstrProperty = SysAllocStringLen(NULL, 0);
@@ -4416,7 +4439,7 @@ static HRESULT WINAPI Uri_GetPropertyLength(IUri *iface, Uri_PROPERTY uriProp, D
switch(uriProp) {
case Uri_PROPERTY_ABSOLUTE_URI:
- if(!This->display_absolute) {
+ if(This->display_modifiers & URI_DISPLAY_NO_ABSOLUTE_URI) {
*pcchProperty = 0;
hres = S_FALSE;
} else {
@@ -4438,7 +4461,13 @@ static HRESULT WINAPI Uri_GetPropertyLength(IUri *iface, Uri_PROPERTY uriProp, D
break;
case Uri_PROPERTY_AUTHORITY:
- *pcchProperty = This->authority_len;
+ if(This->port_offset > -1 &&
+ This->display_modifiers & URI_DISPLAY_NO_DEFAULT_PORT_AUTH &&
+ is_default_port(This->scheme_type, This->port))
+ /* Only count up until the port in the authority. */
+ *pcchProperty = This->port_offset;
+ else
+ *pcchProperty = This->authority_len;
hres = (This->authority_start > -1) ? S_OK : S_FALSE;
break;
case Uri_PROPERTY_DISPLAY_URI:
@@ -4585,7 +4614,7 @@ static HRESULT WINAPI Uri_HasProperty(IUri *iface, Uri_PROPERTY uriProp, BOOL *p
switch(uriProp) {
case Uri_PROPERTY_ABSOLUTE_URI:
- *pfHasProperty = This->display_absolute;
+ *pfHasProperty = !(This->display_modifiers & URI_DISPLAY_NO_ABSOLUTE_URI);
break;
case Uri_PROPERTY_AUTHORITY:
*pfHasProperty = This->authority_start > -1;
@@ -4778,7 +4807,7 @@ static HRESULT WINAPI Uri_GetProperties(IUri *iface, DWORD *pdwProperties)
/* All URIs have these. */
*pdwProperties = Uri_HAS_DISPLAY_URI|Uri_HAS_RAW_URI|Uri_HAS_SCHEME|Uri_HAS_HOST_TYPE;
- if(This->display_absolute)
+ if(!(This->display_modifiers & URI_DISPLAY_NO_ABSOLUTE_URI))
*pdwProperties |= Uri_HAS_ABSOLUTE_URI;
if(This->scheme_start > -1)
More information about the wine-cvs
mailing list