URLMON: Added MapUrlToZone implementation

Jacek Caban jack at itma.pwr.wroc.pl
Wed Sep 28 13:57:15 CDT 2005


Changelog:
    Added MapUrlToZone implementation
-------------- next part --------------
Index: dlls/urlmon/sec_mgr.c
===================================================================
RCS file: /home/wine/wine/dlls/urlmon/sec_mgr.c,v
retrieving revision 1.9
diff -u -p -r1.9 sec_mgr.c
--- dlls/urlmon/sec_mgr.c	7 Sep 2005 09:23:18 -0000	1.9
+++ dlls/urlmon/sec_mgr.c	28 Sep 2005 16:40:01 -0000
@@ -27,6 +27,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winuser.h"
+#include "winreg.h"
 #include "wine/debug.h"
 #include "ole2.h"
 #include "wine/unicode.h"
@@ -50,6 +51,70 @@ typedef struct {
 
 #define SECMGR_THIS(iface) DEFINE_THIS(SecManagerImpl, InternetSecurityManager, iface)
 
+static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone)
+{
+    WCHAR schema[64];
+    DWORD res, size=0;
+    HKEY hkey;
+    HRESULT hres;
+
+    static const WCHAR wszZoneMapProtocolKey[] =
+        {'S','o','f','t','w','a','r','e','\\',
+                    'M','i','c','r','o','s','o','f','t','\\',
+                    'W','i','n','d','o','w','s','\\',
+                    'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+                    'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
+                    'Z','o','n','e','M','a','p','\\',
+                    'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
+    static const WCHAR wszFile[] = {'f','i','l','e',0};
+
+    hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(WCHAR), &size, 0);
+    if(FAILED(hres))
+        return hres;
+    if(!*schema)
+        return 0x80041001;
+
+    /* file protocol is a special case */
+    if(!strcmpW(schema, wszFile)) {
+        WCHAR path[MAX_PATH];
+
+        hres = CoInternetParseUrl(url, PARSE_PATH_FROM_URL, 0, path,
+                sizeof(path)/sizeof(WCHAR), &size, 0);
+
+        if(SUCCEEDED(hres) && strchrW(path, '\\')) {
+            *zone = 0;
+            return S_OK;
+        }
+    }
+
+    WARN("domains are not yet implemented\n");
+
+    res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapProtocolKey, &hkey);
+    if(res != ERROR_SUCCESS) {
+        ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
+        return E_UNEXPECTED;
+    }
+
+    size = sizeof(DWORD);
+    res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
+    if(res == ERROR_SUCCESS)
+        return S_OK;
+
+    res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapProtocolKey, &hkey);
+    if(res != ERROR_SUCCESS) {
+        ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
+        return E_UNEXPECTED;
+    }
+
+    size = sizeof(DWORD);
+    res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
+    if(res == ERROR_SUCCESS)
+                            return S_OK;
+
+    *zone = 3;
+    return S_OK;
+}
+
 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
 {
     SecManagerImpl *This = SECMGR_THIS(iface);
@@ -169,6 +234,8 @@ static HRESULT WINAPI SecManagerImpl_Map
                                                   DWORD dwFlags)
 {
     SecManagerImpl *This = SECMGR_THIS(iface);
+    LPWSTR url;
+    DWORD size;
     HRESULT hres;
 
     TRACE("(%p)->(%s %p %08lx)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
@@ -180,8 +247,24 @@ static HRESULT WINAPI SecManagerImpl_Map
             return hres;
     }
 
-    FIXME("Default action is not implemented\n");
-    return E_NOTIMPL;
+    if(!pwszUrl)
+        return E_INVALIDARG;
+
+    if(dwFlags)
+        FIXME("not supported flags: %08lx\n", dwFlags);
+
+    size = (strlenW(pwszUrl)+16) * sizeof(WCHAR);
+    url = HeapAlloc(GetProcessHeap(), 0, size);
+
+    hres = CoInternetParseUrl(pwszUrl, PARSE_SECURITY_URL, 0, url, size/sizeof(WCHAR), &size, 0);
+    if(FAILED(hres))
+        memcpy(url, pwszUrl, size);
+
+    hres = map_url_to_zone(url, pdwZone);
+
+    HeapFree(GetProcessHeap(), 0, url);
+
+    return hres;
 }
 
 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface, 
Index: dlls/urlmon/tests/misc.c
===================================================================
RCS file: /home/wine/wine/dlls/urlmon/tests/misc.c,v
retrieving revision 1.6
diff -u -p -r1.6 misc.c
--- dlls/urlmon/tests/misc.c	12 Sep 2005 20:12:40 -0000	1.6
+++ dlls/urlmon/tests/misc.c	28 Sep 2005 16:40:02 -0000
@@ -409,10 +409,53 @@ static void test_FindMimeFromData(void)
     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
 }
 
+static struct secmgr_test {
+    LPCWSTR url;
+    DWORD zone;
+    HRESULT zone_hres;
+} secmgr_tests[] = {
+    {url1, 0,   S_OK},
+    {url2, 100, 0x80041001},
+    {url3, 0,   S_OK},
+    {url4, 3,   S_OK},
+    {url5, 3,   S_OK},
+    {url6, 3,   S_OK},
+    {url7, 3,   S_OK}
+};
+
+static void test_SecurityManager(void)
+{
+    int i;
+    IInternetSecurityManager *secmgr = NULL;
+    DWORD zone;
+    HRESULT hres;
+
+    hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
+    ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08lx\n", hres);
+    if(FAILED(hres))
+        return;
+
+    for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
+        zone = 100;
+        hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url, &zone, 0);
+        ok(hres == secmgr_tests[i].zone_hres, "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
+                i, hres, secmgr_tests[i].zone_hres);
+        ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
+                secmgr_tests[i].zone);
+    }
+
+    zone = 100;
+    hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
+    ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
+
+    IInternetSecurityManager_Release(secmgr);
+}
+
 START_TEST(misc)
 {
     test_CreateFormatEnum();
     test_RegisterFormatEnumerator();
     test_CoInternetParseUrl();
     test_FindMimeFromData();
+    test_SecurityManager();
 }


More information about the wine-patches mailing list