Implement proxies in wininet

Dominik Strasser Dominik.Strasser at t-online.de
Sat Apr 12 12:38:13 CDT 2003


The attached patch implements proxies in wininet to an extent that at 
least IE6 install works behind a firewall.

ChangeLog:
    partially implement proxy support in wininet

This is the third time I am sending this patch. Is anything wrong with it ?

Regards

Dominik
-------------- next part --------------
Index: dlls/wininet//Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/wininet/Makefile.in,v
retrieving revision 1.19
diff -u -3 -p -r1.19 Makefile.in
--- dlls/wininet//Makefile.in	12 Nov 2002 02:13:04 -0000	1.19
+++ dlls/wininet//Makefile.in	12 Apr 2003 17:34:56 -0000
@@ -4,7 +4,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = wininet.dll
-IMPORTS   = shlwapi user32 kernel32
+IMPORTS   = shlwapi advapi32 user32 kernel32
 EXTRALIBS = $(LIBUNICODE)
 
 LDDLLFLAGS = @LDDLLFLAGS@
Index: dlls/wininet//http.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/http.c,v
retrieving revision 1.33
diff -u -3 -p -r1.33 http.c
--- dlls/wininet//http.c	25 Feb 2003 03:57:59 -0000	1.33
+++ dlls/wininet//http.c	12 Apr 2003 17:34:57 -0000
@@ -382,6 +382,40 @@ HINTERNET WINAPI HTTP_HttpOpenRequestA(H
         InternetCrackUrlA(lpszReferrer, 0, 0, &UrlComponents);
         if (strlen(UrlComponents.lpszHostName))
             lpwhr->lpszHostName = HTTP_strdup(UrlComponents.lpszHostName);
+    } else if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0) {
+        char buf[MAXHOSTNAME];
+        char proxy[MAXHOSTNAME + 13]; /* 13 == "http://" + sizeof(port#) + ":/\0" */
+        URL_COMPONENTSA UrlComponents;
+
+        UrlComponents.lpszExtraInfo = NULL;
+        UrlComponents.lpszPassword = NULL;
+        UrlComponents.lpszScheme = NULL;
+        UrlComponents.lpszUrlPath = NULL;
+        UrlComponents.lpszUserName = NULL;
+        UrlComponents.lpszHostName = buf;
+        UrlComponents.dwHostNameLength = MAXHOSTNAME;
+
+        sprintf(proxy, "http://%s/", hIC->lpszProxy);
+        InternetCrackUrlA(proxy, 0, 0, &UrlComponents);
+        if (strlen(UrlComponents.lpszHostName)) {
+			 /* for constant 13 see above */
+             char* url = HeapAlloc(GetProcessHeap(), 0, strlen(lpwhr->lpszHostName) + strlen(lpwhr->lpszPath) + 13);
+
+             if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
+                 UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
+			
+            if(lpwhr->lpszHostName != 0) {
+                HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
+                lpwhr->lpszHostName = 0;
+            }
+            sprintf(url, "http://%s:%d/%s", lpwhs->lpszServerName, lpwhs->nServerPort, lpwhr->lpszPath);
+            if(lpwhr->lpszPath)
+                HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
+            lpwhr->lpszPath = url;
+            /* FIXME: Do I have to free lpwhs->lpszServerName here ? */
+            lpwhs->lpszServerName = HTTP_strdup(UrlComponents.lpszHostName);
+            lpwhs->nServerPort = UrlComponents.nPort;
+        }
     } else {
         lpwhr->lpszHostName = HTTP_strdup(lpwhs->lpszServerName);
     }
@@ -910,7 +944,8 @@ BOOL WINAPI HTTP_HttpSendRequestA(HINTER
     if (NULL == lpwhr->lpszPath)
         lpwhr->lpszPath = HTTP_strdup("/");
 
-    if(lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */
+    if(strncmp(lpwhr->lpszPath, "http://", sizeof("http://") -1) != 0
+    	&& lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */
     {
         char *fixurl = HeapAlloc(GetProcessHeap(), 0, strlen(lpwhr->lpszPath) + 2);
         *fixurl = '/';
@@ -1100,7 +1135,7 @@ HINTERNET HTTP_Connect(HINTERNET hIntern
 
     hIC = (LPWININETAPPINFOA) hInternet;
     hIC->hdr.dwContext = dwContext;
-
+    
     lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPSESSIONA));
     if (NULL == lpwhs)
     {
@@ -1119,6 +1154,12 @@ HINTERNET HTTP_Connect(HINTERNET hIntern
     lpwhs->hdr.lpwhparent = (LPWININETHANDLEHEADER)hInternet;
     lpwhs->hdr.dwFlags = dwFlags;
     lpwhs->hdr.dwContext = dwContext;
+    if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
+        if(strchr(hIC->lpszProxy, ' '))
+            FIXME("Several proxies not implemented.\n");
+        if(hIC->lpszProxyBypass)
+            FIXME("Proxy bypass is ignored.\n");
+    }
     if (NULL != lpszServerName)
         lpwhs->lpszServerName = HTTP_strdup(lpszServerName);
     if (NULL != lpszUserName)
Index: dlls/wininet//internet.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/internet.c,v
retrieving revision 1.53
diff -u -3 -p -r1.53 internet.c
--- dlls/wininet//internet.c	28 Mar 2003 19:30:55 -0000	1.53
+++ dlls/wininet//internet.c	12 Apr 2003 17:34:58 -0000
@@ -224,7 +224,31 @@ HINTERNET WINAPI InternetOpenA(LPCSTR lp
             if ((lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,strlen(lpszAgent)+1)))
                 strcpy( lpwai->lpszAgent, lpszAgent );
         }
-        if (NULL != lpszProxy)
+        if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
+        {
+            HKEY key;
+            if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &key))
+            {
+                DWORD keytype, len, enabled;
+                RegQueryValueExA(key, "ProxyEnable", NULL, NULL, (BYTE*)&enabled, NULL);
+                if(enabled)
+                {
+                    if(!RegQueryValueExA(key, "ProxyServer", NULL, &keytype, NULL, &len) && len && keytype == REG_SZ)
+                    {
+                        lpwai->lpszProxy=HeapAlloc( GetProcessHeap(), 0, len+1 );
+                        RegQueryValueExA(key, "ProxyServer", NULL, &keytype, (BYTE*)lpwai->lpszProxy, &len);
+						TRACE("Proxy = %s\n", lpwai->lpszProxy);
+                        dwAccessType = INTERNET_OPEN_TYPE_PROXY;
+                    }
+                }
+                else
+                {
+                    TRACE("Proxy is not enabled.\n");
+                }
+                RegCloseKey(key);
+            }
+        }
+        else if (NULL != lpszProxy)
         {
             if ((lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxy)+1 )))
                 strcpy( lpwai->lpszProxy, lpszProxy );
@@ -641,7 +665,7 @@ BOOL WINAPI InternetCloseHandle(HINTERNE
 /***********************************************************************
  *           ConvertUrlComponentValue (Internal)
  *
- * Helper function for InternetCrackUrlA
+ * Helper function for InternetCrackUrlW
  *
  */
 void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,


More information about the wine-patches mailing list