Commit 98d5dfb8 authored by Thomas Mullaly's avatar Thomas Mullaly Committed by Alexandre Julliard

urlmon: Added basic MapUrlToZoneEx2 implementation.

parent e0dfbd6a
......@@ -57,6 +57,11 @@ static const WCHAR wszZoneMapDomainsKey[] = {'S','o','f','t','w','a','r','e','\\
'Z','o','n','e','M','a','p','\\',
'D','o','m','a','i','n','s',0};
static inline BOOL is_drive_path(const WCHAR *path)
{
return isalphaW(*path) && *(path+1) == ':';
}
/********************************************************************
* get_string_from_reg [internal]
*
......@@ -501,45 +506,37 @@ static HRESULT get_zone_from_domains(LPCWSTR url, LPCWSTR schema, DWORD *zone)
return hres;
}
static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
static HRESULT map_security_uri_to_zone(IUri *uri, DWORD *zone)
{
LPWSTR secur_url;
WCHAR schema[64];
DWORD size=0;
HRESULT hres;
BSTR scheme;
*zone = URLZONE_INVALID;
hres = CoInternetGetSecurityUrl(url, &secur_url, PSU_SECURITY_URL_ONLY, 0);
if(hres != S_OK) {
size = strlenW(url)*sizeof(WCHAR);
secur_url = CoTaskMemAlloc(size);
if(!secur_url)
return E_OUTOFMEMORY;
memcpy(secur_url, url, size);
}
hres = IUri_GetSchemeName(uri, &scheme);
if(FAILED(hres))
return hres;
hres = CoInternetParseUrl(secur_url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(WCHAR), &size, 0);
if(FAILED(hres) || !*schema) {
CoTaskMemFree(secur_url);
return E_INVALIDARG;
}
if(!strcmpiW(scheme, fileW)) {
BSTR path;
WCHAR *ptr, *path_start, root[20];
/* file protocol is a special case */
if(!strcmpW(schema, fileW)) {
WCHAR path[MAX_PATH], root[20];
WCHAR *ptr;
hres = IUri_GetPath(uri, &path);
if(FAILED(hres)) {
SysFreeString(scheme);
return hres;
}
hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path,
sizeof(path)/sizeof(WCHAR), &size, 0);
if(*path == '/' && is_drive_path(path+1))
path_start = path+1;
else
path_start = path;
if(SUCCEEDED(hres) && (ptr = strchrW(path, '\\')) && ptr-path < sizeof(root)/sizeof(WCHAR)) {
if(((ptr = strchrW(path_start, '\\')) || (ptr = strchrW(path_start, '/'))) && ptr-path_start < sizeof(root)/sizeof(WCHAR)) {
UINT type;
memcpy(root, path, (ptr-path)*sizeof(WCHAR));
root[ptr-path] = 0;
memcpy(root, path_start, (ptr-path_start)*sizeof(WCHAR));
root[ptr-path_start] = 0;
type = GetDriveTypeW(root);
......@@ -562,14 +559,56 @@ static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
FIXME("unsupported drive type %d\n", type);
}
}
SysFreeString(path);
}
if(*zone == URLZONE_INVALID) {
hres = get_zone_from_domains(secur_url, schema, zone);
BSTR secur_url;
hres = IUri_GetDisplayUri(uri, &secur_url);
if(FAILED(hres)) {
SysFreeString(scheme);
return hres;
}
hres = get_zone_from_domains(secur_url, scheme, zone);
SysFreeString(secur_url);
if(hres == S_FALSE)
hres = get_zone_from_reg(schema, zone);
hres = get_zone_from_reg(scheme, zone);
}
SysFreeString(scheme);
return hres;
}
static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
{
IUri *secur_uri;
LPWSTR secur_url;
HRESULT hres;
*zone = URLZONE_INVALID;
hres = CoInternetGetSecurityUrl(url, &secur_url, PSU_SECURITY_URL_ONLY, 0);
if(hres != S_OK) {
DWORD size = strlenW(url)*sizeof(WCHAR);
secur_url = CoTaskMemAlloc(size);
if(!secur_url)
return E_OUTOFMEMORY;
memcpy(secur_url, url, size);
}
hres = CreateUri(secur_url, 0, 0, &secur_uri);
if(FAILED(hres)) {
CoTaskMemFree(secur_url);
return hres;
}
hres = map_security_uri_to_zone(secur_uri, zone);
IUri_Release(secur_uri);
if(FAILED(hres) || !ret_url)
CoTaskMemFree(secur_url);
else
......@@ -578,6 +617,21 @@ static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
return hres;
}
static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone)
{
HRESULT hres;
IUri *secur_uri;
hres = CoInternetGetSecurityUrlEx(uri, &secur_uri, PSU_SECURITY_URL_ONLY, 0);
if(FAILED(hres))
return hres;
hres = map_security_uri_to_zone(secur_uri, zone);
IUri_Release(secur_uri);
return hres;
}
static HRESULT open_zone_key(HKEY parent_key, DWORD zone, HKEY *hkey)
{
static const WCHAR wszFormat[] = {'%','s','%','u',0};
......@@ -1033,8 +1087,21 @@ static HRESULT WINAPI SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2
IUri *pUri, DWORD *pdwZone, DWORD dwFlags, LPWSTR *ppwszMappedUrl, DWORD *pdwOutFlags)
{
SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
FIXME("(%p)->(%p %p %08x %p %p) stub\n", This, pUri, pdwZone, dwFlags, ppwszMappedUrl, pdwOutFlags);
return E_NOTIMPL;
TRACE("(%p)->(%p %p %08x %p %p)\n", This, pUri, pdwZone, dwFlags, ppwszMappedUrl, pdwOutFlags);
if(!pdwZone)
return E_INVALIDARG;
if(!pUri) {
*pdwZone = URLZONE_INVALID;
return E_INVALIDARG;
}
if(dwFlags)
FIXME("Unsupported flags: %08x\n", dwFlags);
return map_uri_to_zone(pUri, pdwZone);
}
static HRESULT WINAPI SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2 *iface,
......
......@@ -1620,12 +1620,16 @@ static const struct {
DWORD zone;
BOOL map_todo;
} sec_mgr_ex2_tests[] = {
{"res://mshtml.dll/blank.htm",0,S_OK,URLZONE_LOCAL_MACHINE,TRUE},
{"index.htm",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,TRUE},
{"file://c:\\Index.html",0,0,URLZONE_LOCAL_MACHINE,TRUE},
{"http://www.zone3.winetest/",0,0,URLZONE_INTERNET,TRUE},
{"about:blank",0,0,URLZONE_INTERNET,TRUE},
{"ftp://zone3.winetest/file.test",0,0,URLZONE_INTERNET,TRUE}
{"res://mshtml.dll/blank.htm",0,S_OK,URLZONE_LOCAL_MACHINE},
{"index.htm",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET},
{"file://c:\\Index.html",0,0,URLZONE_LOCAL_MACHINE},
{"http://www.zone3.winetest/",0,0,URLZONE_INTERNET},
{"about:blank",0,0,URLZONE_INTERNET},
{"ftp://zone3.winetest/file.test",0,0,URLZONE_INTERNET},
{"/file/testing/test.test",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET},
{"file/testing/test.test",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET},
{"zip://testing.com/",0,0,URLZONE_INTERNET},
{"zip:testing.com",0,0,URLZONE_INTERNET}
};
static void test_SecurityManagerEx2(void)
......@@ -1652,14 +1656,14 @@ static void test_SecurityManagerEx2(void)
zone = 0xdeadbeef;
hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, NULL, &zone, 0, NULL, NULL);
todo_wine ok(hres == E_INVALIDARG, "MapUrlToZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
todo_wine ok(zone == URLZONE_INVALID, "zone was %d\n", zone);
ok(hres == E_INVALIDARG, "MapUrlToZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
ok(zone == URLZONE_INVALID, "zone was %d\n", zone);
hres = pCreateUri(url5, 0, 0, &uri);
ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, NULL, 0, NULL, NULL);
todo_wine ok(hres == E_INVALIDARG, "MapToUrlZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
ok(hres == E_INVALIDARG, "MapToUrlZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
IUri_Release(uri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment