wininet: Make a function for resolving the server name for an HTTP request and sending the appropriate callbacks and use it to remove some duplicated code.

Robert Shearman rob at codeweavers.com
Wed Dec 6 18:52:50 CST 2006


---
  dlls/wininet/http.c |   63 
++++++++++++++++++++++-----------------------------
  1 files changed, 27 insertions(+), 36 deletions(-)
-------------- next part --------------
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 36c85da..8a5b57a 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -964,6 +964,31 @@ static BOOL HTTP_DealWithProxy( LPWININE
     return TRUE;
 }
 
+static BOOL HTTP_ResolveName(LPWININETHTTPREQW lpwhr)
+{
+    char szaddr[32];
+    LPWININETHTTPSESSIONW lpwhs = lpwhr->lpHttpSession;
+
+    INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
+                          INTERNET_STATUS_RESOLVING_NAME,
+                          lpwhs->lpszServerName,
+                          strlenW(lpwhs->lpszServerName)+1);
+    
+    if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
+                    &lpwhs->socketAddress))
+    {
+        INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
+        return FALSE;
+    }
+    
+    inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr,
+              szaddr, sizeof(szaddr));
+    INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
+                          INTERNET_STATUS_NAME_RESOLVED,
+                          szaddr, strlen(szaddr)+1);
+    return TRUE;
+}
+
 /***********************************************************************
  *           HTTP_HttpOpenRequestW (internal)
  *
@@ -988,7 +1013,6 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(L
     static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0};
     DWORD len;
     LPHTTPHEADERW Host;
-    char szaddr[32];
 
     TRACE("-->\n");
 
@@ -1135,29 +1159,12 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(L
      * A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows
      */
 
-    /*
-     * According to my tests. The name is not resolved until a request is Opened
-     */
-    INTERNET_SendCallback(&lpwhr->hdr, dwContext,
-                          INTERNET_STATUS_RESOLVING_NAME,
-                          lpwhs->lpszServerName,
-                          strlenW(lpwhs->lpszServerName)+1);
-
-    if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
-                    &lpwhs->socketAddress))
+    if (!HTTP_ResolveName(lpwhr))
     {
-        INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
         InternetCloseHandle( handle );
         handle = NULL;
-        goto lend;
     }
 
-    inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr,
-              szaddr, sizeof(szaddr));
-    INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
-                          INTERNET_STATUS_NAME_RESOLVED,
-                          szaddr, strlen(szaddr)+1);
-
 lend:
     if( lpwhr )
         WININET_Release( &lpwhr->hdr );
@@ -1935,7 +1942,6 @@ static BOOL HTTP_HandleRedirect(LPWININE
     LPWININETHTTPSESSIONW lpwhs = lpwhr->lpHttpSession;
     LPWININETAPPINFOW hIC = lpwhs->lpAppInfo;
     WCHAR path[2048];
-    char szaddr[32];
 
     if(lpszUrl[0]=='/')
     {
@@ -2092,23 +2098,8 @@ #endif
             lpwhs->lpszUserName = WININET_strdupW(userName);
         lpwhs->nServerPort = urlComponents.nPort;
 
-        INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
-                              INTERNET_STATUS_RESOLVING_NAME,
-                              lpwhs->lpszServerName,
-                              strlenW(lpwhs->lpszServerName)+1);
-
-        if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
-                    &lpwhs->socketAddress))
-        {
-            INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
+        if (!HTTP_ResolveName(lpwhr))
             return FALSE;
-        }
-
-        inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr,
-              szaddr, sizeof(szaddr));
-        INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
-                              INTERNET_STATUS_NAME_RESOLVED,
-                              szaddr, strlen(szaddr)+1);
 
         NETCON_close(&lpwhr->netConnection);
 


More information about the wine-patches mailing list