[PATCH v2 3/6] urlmon: Return the currently set user agent when 'version' is invalid.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon Apr 11 10:58:49 CDT 2022


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: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/urlmon/session.c    | 14 +++++++++-----
 dlls/urlmon/tests/misc.c | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/dlls/urlmon/session.c b/dlls/urlmon/session.c
index e5dd26c..d533ee8 100644
--- a/dlls/urlmon/session.c
+++ b/dlls/urlmon/session.c
@@ -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) {
diff --git a/dlls/urlmon/tests/misc.c b/dlls/urlmon/tests/misc.c
index c67b1d5..638dcae 100644
--- a/dlls/urlmon/tests/misc.c
+++ b/dlls/urlmon/tests/misc.c
@@ -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);
 
-- 
2.34.1




More information about the wine-devel mailing list