winhttp(2/13): Implement WinHttpSetDefaultProxyConfiguration

Juan Lang juan.lang at gmail.com
Tue Jul 14 15:21:51 CDT 2009


--Juan
-------------- next part --------------
From d535becfe80e31058525d0d9abbb94a7515b753a Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Tue, 14 Jul 2009 12:53:14 -0700
Subject: [PATCH 02/13] Implement WinHttpSetDefaultProxyConfiguration

---
 dlls/winhttp/Makefile.in     |    2 +-
 dlls/winhttp/session.c       |  123 +++++++++++++++++++++++++++++++++++++++++-
 dlls/winhttp/tests/winhttp.c |    5 --
 3 files changed, 122 insertions(+), 8 deletions(-)

diff --git a/dlls/winhttp/Makefile.in b/dlls/winhttp/Makefile.in
index 78d3814..7a61dc9 100644
--- a/dlls/winhttp/Makefile.in
+++ b/dlls/winhttp/Makefile.in
@@ -5,7 +5,7 @@ VPATH     = @srcdir@
 MODULE    = winhttp.dll
 IMPORTLIB = winhttp
 IMPORTS   = shlwapi kernel32
-DELAYIMPORTS = crypt32
+DELAYIMPORTS = crypt32 advapi32
 EXTRALIBS = @SOCKETLIBS@
 
 C_SRCS = \
diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c
index e8c1677..863b226 100644
--- a/dlls/winhttp/session.c
+++ b/dlls/winhttp/session.c
@@ -26,6 +26,7 @@
 #include "winbase.h"
 #include "winhttp.h"
 #include "wincrypt.h"
+#include "winreg.h"
 
 #include "winhttp_private.h"
 
@@ -648,6 +649,26 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
     return FALSE;
 }
 
+static const WCHAR Connections[] = {
+    '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','\\',
+    'C','o','n','n','e','c','t','i','o','n','s',0 };
+static const WCHAR WinHttpSettings[] = {
+    'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
+static const DWORD WINHTTPSETTINGS_MAGIC = 0x18;
+static const DWORD WINHTTP_PROXY_TYPE_DIRECT = 1;
+static const DWORD WINHTTP_PROXY_TYPE_PROXY = 2;
+
+struct winhttp_settings_header
+{
+    DWORD magic;
+    DWORD unknown; /* always zero? */
+    DWORD flags;   /* one of WINHTTP_PROXY_TYPE_* */
+};
+
 /***********************************************************************
  *          WinHttpGetDefaultProxyConfiguration (winhttp.@)
  */
@@ -703,8 +724,106 @@ BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTO
  */
 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
 {
-    FIXME("%p\n", info);
-    return TRUE;
+    LONG l;
+    HKEY key;
+    BOOL ret = FALSE;
+    const WCHAR *src;
+
+    TRACE("%p\n", info);
+
+    if (!info)
+    {
+        set_last_error( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+    switch (info->dwAccessType)
+    {
+    case WINHTTP_ACCESS_TYPE_NO_PROXY:
+        break;
+    case WINHTTP_ACCESS_TYPE_NAMED_PROXY:
+        if (!info->lpszProxy)
+        {
+            set_last_error( ERROR_INVALID_PARAMETER );
+            return FALSE;
+        }
+        /* Only ASCII characters are allowed */
+        for (src = info->lpszProxy; *src; src++)
+            if (*src > 0x7f)
+            {
+                set_last_error( ERROR_INVALID_PARAMETER );
+                return FALSE;
+            }
+        if (info->lpszProxyBypass)
+        {
+            for (src = info->lpszProxyBypass; *src; src++)
+                if (*src > 0x7f)
+                {
+                    set_last_error( ERROR_INVALID_PARAMETER );
+                    return FALSE;
+                }
+        }
+        break;
+    default:
+        set_last_error( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+
+    l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
+        KEY_WRITE, NULL, &key, NULL );
+    if (!l)
+    {
+        DWORD size = sizeof(struct winhttp_settings_header) + 2 * sizeof(DWORD);
+        BYTE *buf;
+
+        if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
+        {
+            size += strlenW( info->lpszProxy );
+            if (info->lpszProxyBypass)
+                size += strlenW( info->lpszProxyBypass );
+        }
+        buf = heap_alloc( size );
+        if (buf)
+        {
+            struct winhttp_settings_header *hdr =
+                (struct winhttp_settings_header *)buf;
+            DWORD *len = (DWORD *)(hdr + 1);
+
+            hdr->magic = WINHTTPSETTINGS_MAGIC;
+            hdr->unknown = 0;
+            if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
+            {
+                BYTE *dst;
+
+                hdr->flags = WINHTTP_PROXY_TYPE_PROXY;
+                *len++ = strlenW( info->lpszProxy );
+                for (dst = (BYTE *)len, src = info->lpszProxy; *src;
+                    src++, dst++)
+                    *dst = *src;
+                len = (DWORD *)dst;
+                if (info->lpszProxyBypass)
+                {
+                    *len++ = strlenW( info->lpszProxyBypass );
+                    for (dst = (BYTE *)len, src = info->lpszProxyBypass; *src;
+                        src++, dst++)
+                        *dst = *src;
+                }
+                else
+                    *len++ = 0;
+            }
+            else
+            {
+                hdr->flags = WINHTTP_PROXY_TYPE_DIRECT;
+                *len++ = 0;
+                *len++ = 0;
+            }
+            l = RegSetValueExW( key, WinHttpSettings, 0, REG_BINARY, buf, size );
+            if (!l)
+                ret = TRUE;
+            heap_free( buf );
+        }
+        RegCloseKey( key );
+    }
+    return ret;
 }
 
 /***********************************************************************
diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c
index 9dced9d..5a1db48 100644
--- a/dlls/winhttp/tests/winhttp.c
+++ b/dlls/winhttp/tests/winhttp.c
@@ -902,7 +902,6 @@ static void test_set_default_proxy_config(void)
 
     SetLastError(0xdeadbeef);
     ret = WinHttpSetDefaultProxyConfiguration(NULL);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
         "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
@@ -911,7 +910,6 @@ static void test_set_default_proxy_config(void)
     info.lpszProxy = info.lpszProxyBypass = NULL;
     SetLastError(0xdeadbeef);
     ret = WinHttpSetDefaultProxyConfiguration(&info);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
         "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
@@ -920,13 +918,11 @@ static void test_set_default_proxy_config(void)
     info.lpszProxy = info.lpszProxyBypass = NULL;
     SetLastError(0xdeadbeef);
     ret = WinHttpSetDefaultProxyConfiguration(&info);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
         "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     info.lpszProxyBypass = normalString;
     SetLastError(0xdeadbeef);
     ret = WinHttpSetDefaultProxyConfiguration(&info);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
         "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
@@ -934,7 +930,6 @@ static void test_set_default_proxy_config(void)
     info.lpszProxy = wideString;
     SetLastError(0xdeadbeef);
     ret = WinHttpSetDefaultProxyConfiguration(&info);
-    todo_wine
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
         "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
-- 
1.6.3.2


More information about the wine-patches mailing list