winhttp(4/12): Implement WinHttpSetDefaultProxyConfiguration

Juan Lang juan.lang at gmail.com
Mon Jul 13 15:09:42 CDT 2009


This isn't strictly necessary to implement proxy support, it's just
nice and symmetric with WinHttpGetDefaultProxyConfiguration.
--Juan
-------------- next part --------------
From 3755a2bc6229a6bc8eb07e6a212ff2b98d519bd5 Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Fri, 10 Jul 2009 12:37:58 -0700
Subject: [PATCH 04/12] Implement WinHttpSetDefaultProxyConfiguration

---
 dlls/winhttp/session.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c
index 716642e..5105f9b 100644
--- a/dlls/winhttp/session.c
+++ b/dlls/winhttp/session.c
@@ -844,9 +844,60 @@ BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTO
  */
 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
 {
-    FIXME("%p [%u, %s, %s]\n", info, info->dwAccessType, debugstr_w(info->lpszProxy),
+    LONG l;
+    HKEY key;
+    BOOL ret = FALSE;
+
+    TRACE("%p [%u, %s, %s]\n", info, info->dwAccessType, debugstr_w(info->lpszProxy),
           debugstr_w(info->lpszProxyBypass));
-    return TRUE;
+
+    l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
+        KEY_WRITE, NULL, &key, NULL );
+    if (!l)
+    {
+        DWORD size = 5 * sizeof(DWORD);
+        BYTE *buf;
+
+        if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
+        {
+            size += strlenW( info->lpszProxy );
+            size += strlenW( info->lpszProxyBypass );
+        }
+        buf = HeapAlloc( GetProcessHeap(), 0, size );
+        if (buf)
+        {
+            DWORD *pdw = (DWORD *)buf;
+
+            *pdw++ = WINHTTPSETTINGS_MAGIC;
+            *pdw++ = 0;
+            if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
+            {
+                const WCHAR *src;
+                BYTE *dst;
+
+                *pdw++ = WINHTTP_PROXY_TYPE_PROXY;
+                *pdw++ = strlenW( info->lpszProxy );
+                for (dst = (BYTE *)pdw, src = info->lpszProxy; *src; src++, dst++)
+                    *dst = *src;
+                pdw = (DWORD *)dst;
+                *pdw++ = strlenW( info->lpszProxyBypass );
+                for (dst = (BYTE *)pdw, src = info->lpszProxyBypass; *src; src++, dst++)
+                    *dst = *src;
+            }
+            else
+            {
+                *pdw++ = WINHTTP_PROXY_TYPE_DIRECT;
+                *pdw++ = 0;
+                *pdw++ = 0;
+            }
+            l = RegSetValueExW( key, WinHttpSettings, 0, REG_BINARY, buf, size );
+            if (!l)
+                ret = TRUE;
+            HeapFree( GetProcessHeap(), 0, buf );
+        }
+        RegCloseKey( key );
+    }
+    return ret;
 }
 
 /***********************************************************************
-- 
1.6.3.2


More information about the wine-patches mailing list