mshtml(2/2): Support getting the proxy settings from the environment

Juan Lang juan.lang at gmail.com
Fri Aug 21 12:35:48 CDT 2009


Fixes bug 5625.
--Juan
-------------- next part --------------
From 0ffff8990bbfba38dcc596cedf5f7d13f172f86b Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Fri, 21 Aug 2009 10:36:51 -0700
Subject: [PATCH 4/4] Support getting the proxy settings from the environment

---
 dlls/mshtml/nsembed.c |   55 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index 1ce5607..fcdf75e 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -366,7 +366,7 @@ static void set_proxy_host_and_port(nsIPrefBranch *pref, const char *proxy,
 static void set_proxy(nsIPrefBranch *pref)
 {
     char proxy[512];
-    char * proxy_port;
+    char * proxy_port, *envproxy;
     int proxy_port_num;
     DWORD enabled = 0, res, size, type;
     HKEY hkey;
@@ -380,29 +380,74 @@ static void set_proxy(nsIPrefBranch *pref)
 
     res = RegOpenKeyW(HKEY_CURRENT_USER, proxy_keyW, &hkey);
     if(res != ERROR_SUCCESS)
-        return;
+        goto get_from_env;
 
     size = sizeof(enabled);
     res = RegQueryValueExA(hkey, "ProxyEnable", 0, &type, (LPBYTE)&enabled, &size);
     if(res != ERROR_SUCCESS || type != REG_DWORD || enabled == 0)
     {
         RegCloseKey(hkey);
-        return;
+        goto get_from_env;
     }
 
     size = sizeof(proxy);
     res = RegQueryValueExA(hkey, "ProxyServer", 0, &type, (LPBYTE)proxy, &size);
     RegCloseKey(hkey);
     if(res != ERROR_SUCCESS || type != REG_SZ)
-        return;
+        goto get_from_env;
 
     proxy_port = strchr(proxy, ':');
     if (!proxy_port)
-        return;
+        goto get_from_env;
 
     *proxy_port = 0;
     proxy_port_num = atoi(proxy_port + 1);
     set_proxy_host_and_port(pref, proxy, proxy_port_num);
+    return;
+
+get_from_env:
+    if ((envproxy = getenv("http_proxy")))
+    {
+        char *colon, *http_proxy;
+
+        if ((colon = strchr(envproxy, ':')))
+        {
+            if (*(colon + 1) == '/' && *(colon + 2) == '/')
+            {
+                static const char http[] = "http://";
+
+                /* It's a scheme, check that it's http */
+                if (!strncmp(envproxy, http, strlen(http)))
+                    http_proxy = envproxy + strlen(http);
+                else
+                {
+                    WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
+                    http_proxy = NULL;
+                }
+            }
+            else
+                http_proxy = envproxy;
+        }
+        else
+            http_proxy = envproxy;
+        if (http_proxy)
+        {
+            if (strlen(http_proxy) >= sizeof(proxy))
+            {
+                WARN("proxy too long: %s\n", debugstr_a(http_proxy));
+                return;
+            }
+            strcpy(proxy, http_proxy);
+            if ((proxy_port = strchr(proxy, ':')))
+            {
+                *proxy_port = 0;
+                proxy_port_num = atoi(proxy_port + 1);
+            }
+            else
+                proxy_port_num = 80; /* use default port */
+            set_proxy_host_and_port(pref, proxy, proxy_port_num);
+        }
+    }
 }
 
 static void set_preferences(void)
-- 
1.6.3.2


More information about the wine-patches mailing list