Jacek Caban : wininet: Pass domain to get_cookie_domain as a substring.

Alexandre Julliard julliard at wine.codeweavers.com
Tue May 17 11:19:37 CDT 2016


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon May 16 22:42:25 2016 +0200

wininet: Pass domain to get_cookie_domain as a substring.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wininet/cookie.c   | 19 ++++++++++---------
 dlls/wininet/internet.h | 16 ++++++++++++++++
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c
index 36346d5..6734c1f 100644
--- a/dlls/wininet/cookie.c
+++ b/dlls/wininet/cookie.c
@@ -92,19 +92,20 @@ static CRITICAL_SECTION_DEBUG cookie_cs_debug =
 static CRITICAL_SECTION cookie_cs = { &cookie_cs_debug, -1, 0, 0, 0, 0 };
 static struct list domain_list = LIST_INIT(domain_list);
 
-static cookie_domain_t *get_cookie_domain(const WCHAR *domain, BOOL create)
+static cookie_domain_t *get_cookie_domain(substr_t domain, BOOL create)
 {
-    const WCHAR *ptr = domain + strlenW(domain), *ptr_end, *subdomain_ptr;
+    const WCHAR *ptr = domain.str + domain.len, *ptr_end, *subdomain_ptr;
     cookie_domain_t *iter, *current_domain, *prev_domain = NULL;
     struct list *current_list = &domain_list;
 
     while(1) {
-        for(ptr_end = ptr--; ptr > domain && *ptr != '.'; ptr--);
+        for(ptr_end = ptr--; ptr > domain.str && *ptr != '.'; ptr--);
         subdomain_ptr = *ptr == '.' ? ptr+1 : ptr;
 
         current_domain = NULL;
         LIST_FOR_EACH_ENTRY(iter, current_list, cookie_domain_t, entry) {
-            if(ptr_end-subdomain_ptr == iter->subdomain_len && !memcmp(subdomain_ptr, iter->domain, iter->subdomain_len)) {
+            if(ptr_end-subdomain_ptr == iter->subdomain_len
+                    && !memcmp(subdomain_ptr, iter->domain, iter->subdomain_len*sizeof(WCHAR))) {
                 current_domain = iter;
                 break;
             }
@@ -118,7 +119,7 @@ static cookie_domain_t *get_cookie_domain(const WCHAR *domain, BOOL create)
             if(!current_domain)
                 return NULL;
 
-            current_domain->domain = heap_strdupW(subdomain_ptr);
+            current_domain->domain = heap_strndupW(subdomain_ptr, domain.str + domain.len - subdomain_ptr);
             if(!current_domain->domain) {
                 heap_free(current_domain);
                 return NULL;
@@ -133,7 +134,7 @@ static cookie_domain_t *get_cookie_domain(const WCHAR *domain, BOOL create)
             list_add_tail(current_list, &current_domain->entry);
         }
 
-        if(ptr == domain)
+        if(ptr == domain.str)
             return current_domain;
 
         prev_domain = current_domain;
@@ -147,7 +148,7 @@ static cookie_container_t *get_cookie_container(const WCHAR *domain, const WCHAR
     cookie_container_t *cookie_container, *iter;
     size_t path_len, len;
 
-    cookie_domain = get_cookie_domain(domain, create);
+    cookie_domain = get_cookie_domain(substrz(domain), create);
     if(!cookie_domain)
         return NULL;
 
@@ -592,13 +593,13 @@ static DWORD get_cookie(const WCHAR *host, const WCHAR *path, DWORD flags, cooki
         while(ptr>subpath && ptr[-1]!='/') ptr--;
     }while(ptr != subpath);
 
-    domain = get_cookie_domain(host, FALSE);
+    domain = get_cookie_domain(substrz(host), FALSE);
     if(!domain) {
         TRACE("Unknown host %s\n", debugstr_w(host));
         return ERROR_NO_MORE_ITEMS;
     }
 
-    for(domain = get_cookie_domain(host, FALSE); domain; domain = domain->parent) {
+    for(domain = get_cookie_domain(substrz(host), FALSE); domain; domain = domain->parent) {
         TRACE("Trying %s domain...\n", debugstr_w(domain->domain));
 
         LIST_FOR_EACH_ENTRY(container, &domain->path_list, cookie_container_t, entry) {
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index eb3a023..7a01cdc 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -215,6 +215,22 @@ static inline char *heap_strdupWtoA(LPCWSTR str)
     return ret;
 }
 
+typedef struct {
+    const WCHAR *str;
+    size_t len;
+} substr_t;
+
+static inline substr_t substr(const WCHAR *str, size_t len)
+{
+    substr_t r = {str, len};
+    return r;
+}
+
+static inline substr_t substrz(const WCHAR *str)
+{
+    return substr(str, strlenW(str));
+}
+
 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
 {
     dataA->dwFileAttributes = dataW->dwFileAttributes;




More information about the wine-cvs mailing list