Hans Leidekker : wininet: Support http_proxy environment variable.

Alexandre Julliard julliard at winehq.org
Mon Mar 31 09:15:28 CDT 2008


Module: wine
Branch: master
Commit: c7f93666c3bceb11abf5bb020e84ceb09dd57048
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c7f93666c3bceb11abf5bb020e84ceb09dd57048

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Sun Mar 30 19:16:11 2008 +0100

wininet: Support http_proxy environment variable.

Based on a patch by Mike Hearn.

---

 dlls/wininet/internet.c |  104 +++++++++++++++++++++++++++-------------------
 1 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index be2fa9c..3495b5c 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -336,67 +336,85 @@ BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
 
 
 /***********************************************************************
- *           INTERNET_ConfigureProxyFromReg
+ *           INTERNET_ConfigureProxy
  *
  * FIXME:
  * The proxy may be specified in the form 'http=proxy.my.org'
  * Presumably that means there can be ftp=ftpproxy.my.org too.
  */
-static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
+static BOOL INTERNET_ConfigureProxy( LPWININETAPPINFOW lpwai )
 {
     HKEY key;
-    DWORD r, keytype, len, enabled;
-    LPCSTR lpszInternetSettings =
-        "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
+    DWORD type, len, enabled = 0;
+    LPCSTR envproxy;
+    static const WCHAR szInternetSettings[] =
+        { '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',0 };
     static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
+    static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
 
-    r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
-    if ( r != ERROR_SUCCESS )
-        return FALSE;
+    if (RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )) return FALSE;
 
     len = sizeof enabled;
-    r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
-                          (BYTE*)&enabled, &len);
-    if( (r == ERROR_SUCCESS) && enabled )
+    if (!RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&enabled, &len ) &&
+        (type == REG_DWORD))
     {
-        TRACE("Proxy is enabled.\n");
-
-        /* figure out how much memory the proxy setting takes */
-        r = RegQueryValueExW( key, szProxyServer, NULL, &keytype, 
-                              NULL, &len);
-        if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
+        if (enabled)
         {
-            LPWSTR szProxy, p;
-            static const WCHAR szHttp[] = {'h','t','t','p','=',0};
-
-            szProxy=HeapAlloc( GetProcessHeap(), 0, len );
-            RegQueryValueExW( key, szProxyServer, NULL, &keytype,
-                              (BYTE*)szProxy, &len);
+            TRACE("Proxy is enabled.\n");
 
-            /* find the http proxy, and strip away everything else */
-            p = strstrW( szProxy, szHttp );
-            if( p )
+            /* figure out how much memory the proxy setting takes */
+            if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) &&
+                len && (type == REG_SZ))
             {
-                 p += lstrlenW(szHttp);
-                 lstrcpyW( szProxy, p );
-            }
-            p = strchrW( szProxy, ' ' );
-            if( p )
-                *p = 0;
+                LPWSTR szProxy, p;
+                static const WCHAR szHttp[] = {'h','t','t','p','=',0};
+
+                if (!(szProxy = HeapAlloc( GetProcessHeap(), 0, len )))
+                {
+                    RegCloseKey( key );
+                    return FALSE;
+                }
+                RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
+
+                /* find the http proxy, and strip away everything else */
+                p = strstrW( szProxy, szHttp );
+                if (p)
+                {
+                    p += lstrlenW( szHttp );
+                    lstrcpyW( szProxy, p );
+                }
+                p = strchrW( szProxy, ' ' );
+                if (p) *p = 0;
 
-            lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
-            lpwai->lpszProxy = szProxy;
+                lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
+                lpwai->lpszProxy = szProxy;
 
-            TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
+                TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
+            }
+            else
+                ERR("Couldn't read proxy server settings from registry.\n");
         }
-        else
-            ERR("Couldn't read proxy server settings.\n");
     }
-    else
-        TRACE("Proxy is not enabled.\n");
-    RegCloseKey(key);
+    else if ((envproxy = getenv( "http_proxy" )))
+    {
+        WCHAR *envproxyW;
+
+        len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
+        if (!(envproxyW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
+        MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
+
+        lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
+        lpwai->lpszProxy = envproxyW;
+
+        TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwai->lpszProxy));
+        enabled = 1;
+    }
+    if (!enabled) TRACE("Proxy is not enabled.\n");
 
-    return enabled;
+    RegCloseKey( key );
+    return (enabled > 0);
 }
 
 /***********************************************************************
@@ -582,7 +600,7 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
             lstrcpyW( lpwai->lpszAgent, lpszAgent );
     }
     if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
-        INTERNET_ConfigureProxyFromReg( lpwai );
+        INTERNET_ConfigureProxy( lpwai );
     else if (NULL != lpszProxy)
     {
         lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
@@ -1922,7 +1940,7 @@ static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD d
             {
                 TRACE("Getting global proxy info\n");
                 memset(&wai, 0, sizeof(WININETAPPINFOW));
-                INTERNET_ConfigureProxyFromReg( &wai );
+                INTERNET_ConfigureProxy( &wai );
                 lpwai = &wai;
             }
 




More information about the wine-cvs mailing list