Jacek Caban : wininet: Use get_cookie directly in HTTP_InsertCookies.

Alexandre Julliard julliard at winehq.org
Thu May 19 13:32:12 CDT 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu May 19 16:11:30 2011 +0200

wininet: Use get_cookie directly in HTTP_InsertCookies.

---

 dlls/wininet/cookie.c   |    2 +-
 dlls/wininet/http.c     |   42 ++++++++++++++++++++----------------------
 dlls/wininet/internet.h |    2 ++
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c
index 683776b..d3c6232 100644
--- a/dlls/wininet/cookie.c
+++ b/dlls/wininet/cookie.c
@@ -260,7 +260,7 @@ static void COOKIE_deleteDomain(cookie_domain *deadDomain)
     HeapFree(GetProcessHeap(), 0, deadDomain);
 }
 
-static BOOL get_cookie(const WCHAR *host, const WCHAR *path, WCHAR *cookie_data, DWORD *size)
+BOOL get_cookie(const WCHAR *host, const WCHAR *path, WCHAR *cookie_data, DWORD *size)
 {
     unsigned cnt = 0, len, domain_count = 0, cookie_count = 0;
     cookie_domain *domain;
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index c6542a8..53bbde2 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -3957,32 +3957,30 @@ static DWORD HTTP_SecureProxyConnect(http_request_t *request)
 
 static void HTTP_InsertCookies(http_request_t *request)
 {
-    static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
-    LPWSTR lpszCookies, lpszUrl = NULL;
-    DWORD nCookieSize, size;
-    LPHTTPHEADERW Host = HTTP_GetHeader(request, hostW);
+    DWORD cookie_size, size, cnt = 0;
+    HTTPHEADERW *host;
+    WCHAR *cookies;
 
-    size = (strlenW(Host->lpszValue) + strlenW(szUrlForm) + strlenW(request->path)) * sizeof(WCHAR);
-    if (!(lpszUrl = heap_alloc(size))) return;
-    sprintfW( lpszUrl, szUrlForm, Host->lpszValue, request->path);
+    static const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' ',0};
 
-    if (InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize))
-    {
-        int cnt = 0;
-        static const WCHAR szCookie[] = {'C','o','o','k','i','e',':',' ',0};
+    host = HTTP_GetHeader(request, hostW);
+    if(!host)
+        return;
 
-        size = sizeof(szCookie) + nCookieSize * sizeof(WCHAR) + sizeof(szCrLf);
-        if ((lpszCookies = heap_alloc(size)))
-        {
-            cnt += sprintfW(lpszCookies, szCookie);
-            InternetGetCookieW(lpszUrl, NULL, lpszCookies + cnt, &nCookieSize);
-            strcatW(lpszCookies, szCrLf);
+    if(!get_cookie(host->lpszValue, request->path, NULL, &cookie_size))
+        return;
 
-            HTTP_HttpAddRequestHeadersW(request, lpszCookies, strlenW(lpszCookies), HTTP_ADDREQ_FLAG_REPLACE);
-            HeapFree(GetProcessHeap(), 0, lpszCookies);
-        }
-    }
-    HeapFree(GetProcessHeap(), 0, lpszUrl);
+    size = sizeof(cookieW) + cookie_size * sizeof(WCHAR) + sizeof(szCrLf);
+    if(!(cookies = heap_alloc(size)))
+        return;
+
+    cnt += sprintfW(cookies, cookieW);
+    get_cookie(host->lpszValue, request->path, cookies+cnt, &cookie_size);
+    strcatW(cookies, szCrLf);
+
+    HTTP_HttpAddRequestHeadersW(request, cookies, strlenW(cookies), HTTP_ADDREQ_FLAG_REPLACE);
+
+    heap_free(cookies);
 }
 
 static WORD HTTP_ParseDay(LPCWSTR day)
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index c83e617..f94942a 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -497,6 +497,8 @@ DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
 	struct sockaddr *psa, socklen_t *sa_len) DECLSPEC_HIDDEN;
 
+BOOL get_cookie(const WCHAR*,const WCHAR*,WCHAR*,DWORD*) DECLSPEC_HIDDEN;
+
 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list