Jacek Caban : wininet: Use set_cookie directly in HTTP_ProcessCookies.

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


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

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

wininet: Use set_cookie directly in HTTP_ProcessCookies.

---

 dlls/wininet/cookie.c   |    2 +-
 dlls/wininet/http.c     |   43 ++++++++++++++++++++++++++-----------------
 dlls/wininet/internet.h |    1 +
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c
index d3c6232..77e22ac 100644
--- a/dlls/wininet/cookie.c
+++ b/dlls/wininet/cookie.c
@@ -414,7 +414,7 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
     return r;
 }
 
-static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cookie_data)
+BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cookie_data)
 {
     cookie_domain *thisCookieDomain = NULL;
     cookie *thisCookie;
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 53bbde2..883e574 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -720,26 +720,35 @@ static void HTTP_ProcessCookies( http_request_t *request )
     int numCookies = 0;
     LPHTTPHEADERW setCookieHeader;
 
-    while((HeaderIndex = HTTP_GetCustomHeaderIndex(request, szSet_Cookie, numCookies, FALSE)) != -1)
+    if(request->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES)
+        return;
+
+    while((HeaderIndex = HTTP_GetCustomHeaderIndex(request, szSet_Cookie, numCookies++, FALSE)) != -1)
     {
+        HTTPHEADERW *host;
+        const WCHAR *data;
+        WCHAR *name;
+
         setCookieHeader = &request->custHeaders[HeaderIndex];
 
-        if (!(request->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && setCookieHeader->lpszValue)
-        {
-            int len;
-            static const WCHAR szFmt[] = { 'h','t','t','p',':','/','/','%','s','%','s',0};
-            LPWSTR buf_url;
-            LPHTTPHEADERW Host;
+        if (!setCookieHeader->lpszValue)
+            continue;
 
-            Host = HTTP_GetHeader(request, hostW);
-            len = lstrlenW(Host->lpszValue) + 9 + lstrlenW(request->path);
-            buf_url = heap_alloc(len*sizeof(WCHAR));
-            sprintfW(buf_url, szFmt, Host->lpszValue, request->path);
-            InternetSetCookieW(buf_url, NULL, setCookieHeader->lpszValue);
+        host = HTTP_GetHeader(request, hostW);
+        if(!host)
+            continue;
 
-            HeapFree(GetProcessHeap(), 0, buf_url);
-        }
-        numCookies++;
+        data = strchrW(setCookieHeader->lpszValue, '=');
+        if(!data)
+            continue;
+
+        name = heap_strndupW(setCookieHeader->lpszValue, data-setCookieHeader->lpszValue);
+        if(!name)
+            continue;
+
+        data++;
+        set_cookie(host->lpszValue, request->path, name, data);
+        heap_free(name);
     }
 }
 
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index f94942a..aedb265 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -498,6 +498,7 @@ 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;
+BOOL set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
 
 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list