Commit 6843cecb authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

urlmon: Return the currently set user agent when 'version' is invalid.

ObtainUserAgentString returns the currently set (custom) user agent unless the version requested is a valid one (7, 8, ... 11, or 7 | UAS_EXACTLEGACY), in which case it uses that version to build the user agent. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 0badd67e
......@@ -508,9 +508,9 @@ static BOOL user_agent_set;
static size_t obtain_user_agent(unsigned int version, WCHAR *ret, size_t size)
{
BOOL is_wow, quirks = FALSE, use_current = FALSE;
OSVERSIONINFOW info = {sizeof(info)};
const WCHAR *os_type, *is_nt;
BOOL is_wow, quirks = FALSE;
DWORD res;
size_t len = 0;
HKEY key;
......@@ -519,17 +519,18 @@ static size_t obtain_user_agent(unsigned int version, WCHAR *ret, size_t size)
version &= ~UAS_EXACTLEGACY;
if(version == 7)
quirks = TRUE;
else
else {
use_current = TRUE;
version = 7;
}else if(version < 7) {
version = 7;
}
}
if(version > 11) {
FIXME("Unsupported version %u\n", version);
version = 11;
}
if(version < 7 || (version == 7 && !quirks)) {
if(version < 7 || use_current) {
EnterCriticalSection(&session_cs);
if(user_agent) {
len = wcslen(user_agent) + 1;
......@@ -539,6 +540,9 @@ static size_t obtain_user_agent(unsigned int version, WCHAR *ret, size_t size)
if(len) return len;
}
if(version < 7)
version = 7;
swprintf(ret, size, L"Mozilla/%s (", version < 9 ? L"4.0" : L"5.0");
len = lstrlenW(ret);
if(version < 11) {
......
......@@ -1635,6 +1635,26 @@ static void test_user_agent(void)
ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08lx\n", hres);
ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
for(i = 0; i < 12; i++) {
size = sizeof(ua);
hres = pObtainUserAgentString(i, ua, &size);
ok(hres == S_OK, "[%u] ObtainUserAgentString failed: %08lx\n", i, hres);
ok(size == strlen(ua) + 1, "[%u] unexpected size %lu, expected %Iu\n", i, size, strlen(ua) + 1);
if(i >= 7)
ok(strcmp(ua, test_str), "[%u] unexpected UA, did not expect \"test\"\n", i);
else
ok(!strcmp(ua, test_str), "[%u] unexpected UA %s, expected \"test\"\n", i, wine_dbgstr_a(ua));
size = sizeof(ua);
hres = pObtainUserAgentString(i | UAS_EXACTLEGACY, ua, &size);
ok(hres == S_OK, "[%u] ObtainUserAgentString failed: %08lx\n", i, hres);
ok(size == strlen(ua) + 1, "[%u] unexpected size %lu, expected %Iu\n", i, size, strlen(ua) + 1);
if(i == 7)
ok(strcmp(ua, test_str), "[%u] unexpected UA, did not expect \"test\"\n", i);
else
ok(!strcmp(ua, test_str), "[%u] unexpected UA %s, expected \"test\"\n", i, wine_dbgstr_a(ua));
}
hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test2_str, sizeof(test2_str), 0);
ok(hres == S_OK, "UrlMkSetSessionOption failed: %08lx\n", hres);
......
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