[PATCH 0/2] MR10482: urlmon: Implement IsValidURL().
From: Nello De Gregoris <bluechxindv@gmail.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=59552 --- dlls/urlmon/session.c | 21 +++++++++++++++++++++ dlls/urlmon/urlmon_main.c | 6 ++---- dlls/urlmon/urlmon_main.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dlls/urlmon/session.c b/dlls/urlmon/session.c index 660fab54570..3e2cd7721d0 100644 --- a/dlls/urlmon/session.c +++ b/dlls/urlmon/session.c @@ -157,6 +157,27 @@ static HRESULT unregister_namespace(IClassFactory *cf, LPCWSTR protocol) return S_OK; } +BOOL is_known_protocol(LPCWSTR url) +{ + WCHAR schema[64]; + DWORD schema_len; + HRESULT hres; + BOOL found; + + hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, ARRAY_SIZE(schema), &schema_len, 0); + if(FAILED(hres) || !schema_len) + return FALSE; + + EnterCriticalSection(&session_cs); + found = find_name_space(schema) != NULL; + LeaveCriticalSection(&session_cs); + + if(!found) + found = get_protocol_cf(schema, schema_len, NULL, NULL) == S_OK; + + return found; +} + BOOL is_registered_protocol(LPCWSTR url) { DWORD schema_len; diff --git a/dlls/urlmon/urlmon_main.c b/dlls/urlmon/urlmon_main.c index 806a893d7d1..bcc1314d773 100644 --- a/dlls/urlmon/urlmon_main.c +++ b/dlls/urlmon/urlmon_main.c @@ -511,17 +511,15 @@ HRESULT WINAPI DllRegisterServerEx(void) * Failure: S_FALSE. * returns E_INVALIDARG if one or more of the args is invalid. * - * TODO: - * test functionality against windows to see what a valid URL is. */ HRESULT WINAPI IsValidURL(LPBC pBC, LPCWSTR szURL, DWORD dwReserved) { - FIXME("(%p, %s, %ld): stub\n", pBC, debugstr_w(szURL), dwReserved); + TRACE("(%p, %s, %ld)\n", pBC, debugstr_w(szURL), dwReserved); if (dwReserved || !szURL) return E_INVALIDARG; - return S_OK; + return is_known_protocol(szURL) ? S_OK : S_FALSE; } /************************************************************************** diff --git a/dlls/urlmon/urlmon_main.h b/dlls/urlmon/urlmon_main.h index ceb3e09b761..e30a4da9aa2 100644 --- a/dlls/urlmon/urlmon_main.h +++ b/dlls/urlmon/urlmon_main.h @@ -68,6 +68,7 @@ IInternetProtocolInfo *get_protocol_info(LPCWSTR); HRESULT get_protocol_handler(IUri*,CLSID*,IClassFactory**); IInternetProtocol *get_mime_filter(LPCWSTR); BOOL is_registered_protocol(LPCWSTR); +BOOL is_known_protocol(LPCWSTR); HRESULT register_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL); HINTERNET get_internet_session(IInternetBindInfo*); WCHAR *get_useragent(void); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10482
From: Nello De Gregoris <bluechxindv@gmail.com> --- dlls/urlmon/tests/misc.c | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/dlls/urlmon/tests/misc.c b/dlls/urlmon/tests/misc.c index 2a61b892930..10ccee72f61 100644 --- a/dlls/urlmon/tests/misc.c +++ b/dlls/urlmon/tests/misc.c @@ -1768,13 +1768,64 @@ static void test_IsValidURL(void) hr = IsValidURL(NULL, 0, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr); + CreateBindCtx(0, &bctx); + + hr = IsValidURL(bctx, NULL, 0); + ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr); + + /* valid schemas */ + hr = IsValidURL(NULL, wszHttpWineHQ, 0); - ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr); + ok(hr == S_OK, "Expected S_OK for http URL, got %08lx\n", hr); - CreateBindCtx(0, &bctx); + hr = IsValidURL(NULL, url3, 0); + ok(hr == S_OK, "Expected S_OK for file URL, got %08lx\n", hr); + + hr = IsValidURL(NULL, url6, 0); + ok(hr == S_OK, "Expected S_OK for about URL, got %08lx\n", hr); + + hr = IsValidURL(NULL, url7, 0); + ok(hr == S_OK, "Expected S_OK for ftp URL, got %08lx\n", hr); + + hr = IsValidURL(NULL, url1, 0); + ok(hr == S_OK, "Expected S_OK for res URL, got %08lx\n", hr); + + hr = IsValidURL(NULL, L"https://www.winehq.org", 0); + ok(hr == S_OK, "Expected S_OK for https URL, got %08lx\n", hr); + + /* unregistered schemas */ + + hr = IsValidURL(NULL, url8, 0); + ok(hr == S_FALSE, "Expected S_FALSE for unknown schema 'test:', got %08lx\n", hr); + + hr = IsValidURL(NULL, L"xxxxxxxxunknown://foo", 0); + ok(hr == S_FALSE, "Expected S_FALSE for unknown schema, got %08lx\n", hr); + + /* no schema */ + + hr = IsValidURL(NULL, url2, 0); + ok(hr == S_FALSE, "Expected S_FALSE for relative URL, got %08lx\n", hr); + + hr = IsValidURL(NULL, L"", 0); + ok(hr == S_FALSE, "Expected S_FALSE for empty string, got %08lx\n", hr); + + hr = IsValidURL(NULL, L"not a url at all", 0); + ok(hr == S_FALSE, "Expected S_FALSE for non-URL string, got %08lx\n", hr); + + hr = IsValidURL(NULL, L"://missingschema", 0); + ok(hr == S_FALSE, "Expected S_FALSE for missing schema, got %08lx\n", hr); hr = IsValidURL(bctx, wszHttpWineHQ, 0); - ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr); + ok(hr == S_OK, "Expected S_OK for http URL with bctx, got %08lx\n", hr); + + hr = IsValidURL(bctx, url8, 0); + ok(hr == S_FALSE, "Expected S_FALSE for unknown schema with bctx, got %08lx\n", hr); + + hr = IsValidURL(bctx, url2, 0); + ok(hr == S_FALSE, "Expected S_FALSE for relative URL with bctx, got %08lx\n", hr); + + hr = IsValidURL(bctx, L"", 0); + ok(hr == S_FALSE, "Expected S_FALSE for empty string with bctx, got %08lx\n", hr); IBindCtx_Release(bctx); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10482
participants (2)
-
Nello De Gregoris -
Nello De Gregoris (@bluechxin)