ReactOS  0.4.15-dev-2701-g34593d9
cookie.c File Reference
#include "ws2tcpip.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <wchar.h>
#include "windef.h"
#include "winbase.h"
#include "wininet.h"
#include "lmcons.h"
#include "winerror.h"
#include "wine/debug.h"
#include "internet.h"
Include dependency graph for cookie.c:

Go to the source code of this file.

Classes

struct  _cookie_t
 
struct  _cookie_container_t
 
struct  _cookie_domain_t
 
struct  cookie_set_t
 

Macros

#define RESPONSE_TIMEOUT   30 /* FROM internet.c */
 

Typedefs

typedef struct _cookie_t cookie_t
 
typedef struct _cookie_container_t cookie_container_t
 
typedef struct _cookie_domain_t cookie_domain_t
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wininet)
 
static cookie_domain_tget_cookie_domain (substr_t domain, BOOL create)
 
static WCHARcreate_cookie_url (substr_t domain, substr_t path, substr_t *ret_path)
 
static cookie_container_tget_cookie_container (substr_t domain, substr_t path, BOOL create)
 
static void delete_cookie (cookie_t *cookie)
 
static cookie_talloc_cookie (substr_t name, substr_t data, FILETIME expiry, FILETIME create_time, DWORD flags)
 
static cookie_tfind_cookie (cookie_container_t *container, substr_t name)
 
static void add_cookie (cookie_container_t *container, cookie_t *new_cookie)
 
static void replace_cookie (cookie_container_t *container, cookie_t *new_cookie)
 
static BOOL cookie_match_path (cookie_container_t *container, substr_t path)
 
static BOOL load_persistent_cookie (substr_t domain, substr_t path)
 
static BOOL save_persistent_cookie (cookie_container_t *container)
 
static BOOL cookie_parse_url (const WCHAR *url, substr_t *host, substr_t *path)
 
static DWORD get_cookie (substr_t host, substr_t path, DWORD flags, cookie_set_t *res)
 
static void cookie_set_to_string (const cookie_set_t *cookie_set, WCHAR *str)
 
DWORD get_cookie_header (const WCHAR *host, const WCHAR *path, WCHAR **ret)
 
static void free_cookie_domain_list (struct list *list)
 
BOOL WINAPI InternetGetCookieExW (LPCWSTR lpszUrl, LPCWSTR lpszCookieName, LPWSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved)
 
BOOL WINAPI InternetGetCookieW (const WCHAR *url, const WCHAR *name, WCHAR *data, DWORD *size)
 
BOOL WINAPI InternetGetCookieExA (LPCSTR lpszUrl, LPCSTR lpszCookieName, LPSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved)
 
BOOL WINAPI InternetGetCookieA (const char *url, const char *name, char *data, DWORD *size)
 
static BOOL is_domain_legal_for_cookie (substr_t domain, substr_t full_domain)
 
BOOL WINAPI IsDomainLegalCookieDomainW (const WCHAR *domain, const WCHAR *full_domain)
 
static void substr_skip (substr_t *str, size_t len)
 
DWORD set_cookie (substr_t domain, substr_t path, substr_t name, substr_t data, DWORD flags)
 
DWORD WINAPI InternetSetCookieExW (LPCWSTR lpszUrl, LPCWSTR lpszCookieName, LPCWSTR lpCookieData, DWORD flags, DWORD_PTR reserved)
 
BOOL WINAPI InternetSetCookieW (const WCHAR *url, const WCHAR *name, const WCHAR *data)
 
BOOL WINAPI InternetSetCookieA (LPCSTR lpszUrl, LPCSTR lpszCookieName, LPCSTR lpCookieData)
 
DWORD WINAPI InternetSetCookieExA (LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData, DWORD dwFlags, DWORD_PTR dwReserved)
 
BOOL WINAPI InternetClearAllPerSiteCookieDecisions (VOID)
 
BOOL WINAPI InternetEnumPerSiteCookieDecisionA (LPSTR pszSiteName, ULONG *pcSiteNameSize, ULONG *pdwDecision, ULONG dwIndex)
 
BOOL WINAPI InternetEnumPerSiteCookieDecisionW (LPWSTR pszSiteName, ULONG *pcSiteNameSize, ULONG *pdwDecision, ULONG dwIndex)
 
BOOL WINAPI InternetGetPerSiteCookieDecisionA (LPCSTR pwchHostName, ULONG *pResult)
 
BOOL WINAPI InternetGetPerSiteCookieDecisionW (LPCWSTR pwchHostName, ULONG *pResult)
 
BOOL WINAPI InternetSetPerSiteCookieDecisionA (LPCSTR pchHostName, DWORD dwDecision)
 
BOOL WINAPI InternetSetPerSiteCookieDecisionW (LPCWSTR pchHostName, DWORD dwDecision)
 
void free_cookie (void)
 

Variables

static CRITICAL_SECTION cookie_cs = { &cookie_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG cookie_cs_debug
 
static struct list domain_list = LIST_INIT(domain_list)
 

Macro Definition Documentation

◆ RESPONSE_TIMEOUT

#define RESPONSE_TIMEOUT   30 /* FROM internet.c */

Definition at line 45 of file cookie.c.

Typedef Documentation

◆ cookie_container_t

◆ cookie_domain_t

◆ cookie_t

Function Documentation

◆ add_cookie()

static void add_cookie ( cookie_container_t container,
cookie_t new_cookie 
)
static

Definition at line 283 of file cookie.c.

284 {
285  TRACE("Adding %s=%s to %s\n", debugstr_w(new_cookie->name), debugstr_w(new_cookie->data),
286  debugstr_w(container->cookie_url));
287 
288  list_add_tail(&container->cookie_list, &new_cookie->entry);
289  new_cookie->container = container;
290 }
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
struct container container
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by replace_cookie(), and set_cookie().

◆ alloc_cookie()

static cookie_t* alloc_cookie ( substr_t  name,
substr_t  data,
FILETIME  expiry,
FILETIME  create_time,
DWORD  flags 
)
static

Definition at line 245 of file cookie.c.

246 {
247  cookie_t *new_cookie;
248 
249  new_cookie = heap_alloc_zero(sizeof(*new_cookie));
250  if(!new_cookie)
251  return NULL;
252 
253  new_cookie->expiry = expiry;
254  new_cookie->create = create_time;
255  new_cookie->flags = flags;
256  list_init(&new_cookie->entry);
257 
258  if(name.str && !(new_cookie->name = heap_strndupW(name.str, name.len))) {
259  delete_cookie(new_cookie);
260  return NULL;
261  }
262 
263  if(data.str && !(new_cookie->data = heap_strndupW(data.str, data.len))) {
264  delete_cookie(new_cookie);
265  return NULL;
266  }
267 
268  return new_cookie;
269 }
static LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
static time_t create_time
Definition: mkdosfs.c:525
static void delete_cookie(cookie_t *cookie)
Definition: cookie.c:236
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
#define NULL
Definition: types.h:112
Definition: name.c:38
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149

Referenced by load_persistent_cookie(), and set_cookie().

◆ cookie_match_path()

static BOOL cookie_match_path ( cookie_container_t container,
substr_t  path 
)
static

Definition at line 303 of file cookie.c.

304 {
305  return path.len >= container->path.len && !wcsnicmp(container->path.str, path.str, container->path.len);
306 }
#define wcsnicmp
Definition: compat.h:14

Referenced by get_cookie().

◆ cookie_parse_url()

static BOOL cookie_parse_url ( const WCHAR url,
substr_t host,
substr_t path 
)
static

Definition at line 508 of file cookie.c.

509 {
510  URL_COMPONENTSW comp = { sizeof(comp) };
511 
512  comp.dwHostNameLength = 1;
513  comp.dwUrlPathLength = 1;
514 
515  if(!InternetCrackUrlW(url, 0, 0, &comp) || !comp.dwHostNameLength)
516  return FALSE;
517 
518  /* discard the webpage off the end of the path */
519  while(comp.dwUrlPathLength && comp.lpszUrlPath[comp.dwUrlPathLength-1] != '/')
520  comp.dwUrlPathLength--;
521 
522  *host = substr(comp.lpszHostName, comp.dwHostNameLength);
523  *path = comp.dwUrlPathLength ? substr(comp.lpszUrlPath, comp.dwUrlPathLength) : substr(L"/", 1);
524  return TRUE;
525 }
#define TRUE
Definition: types.h:120
char * host
Definition: whois.c:55
LPWSTR lpszHostName
Definition: wininet.h:215
#define FALSE
Definition: types.h:117
static const WCHAR url[]
Definition: encode.c:1432
DWORD dwHostNameLength
Definition: wininet.h:216
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpszUrlPath
Definition: wininet.h:222
DWORD dwUrlPathLength
Definition: wininet.h:223
BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
Definition: internet.c:1625
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203

Referenced by InternetGetCookieExW(), and InternetSetCookieExW().

◆ cookie_set_to_string()

static void cookie_set_to_string ( const cookie_set_t cookie_set,
WCHAR str 
)
static

Definition at line 619 of file cookie.c.

620 {
621  WCHAR *ptr = str;
622  unsigned i, len;
623 
624  for(i=0; i<cookie_set->cnt; i++) {
625  if(i) {
626  *ptr++ = ';';
627  *ptr++ = ' ';
628  }
629 
630  len = lstrlenW(cookie_set->cookies[i]->name);
631  memcpy(ptr, cookie_set->cookies[i]->name, len*sizeof(WCHAR));
632  ptr += len;
633 
634  if(*cookie_set->cookies[i]->data) {
635  *ptr++ = '=';
636  len = lstrlenW(cookie_set->cookies[i]->data);
637  memcpy(ptr, cookie_set->cookies[i]->data, len*sizeof(WCHAR));
638  ptr += len;
639  }
640  }
641 
642  assert(ptr-str == cookie_set->string_len);
643  TRACE("%s\n", debugstr_wn(str, ptr-str));
644 }
#define assert(x)
Definition: debug.h:53
#define lstrlenW
Definition: compat.h:609
static PVOID ptr
Definition: dispmode.c:27
const WCHAR * str
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
cookie_t ** cookies
Definition: cookie.c:528
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_wn
Definition: kernel32.h:33
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned string_len
Definition: cookie.c:532
unsigned cnt
Definition: cookie.c:529

Referenced by get_cookie_header(), and InternetGetCookieExW().

◆ create_cookie_url()

static WCHAR* create_cookie_url ( substr_t  domain,
substr_t  path,
substr_t ret_path 
)
static

Definition at line 152 of file cookie.c.

153 {
154  WCHAR *p, *url;
155  DWORD len, user_len, i;
156 
157  static const WCHAR cookie_prefix[] = {'C','o','o','k','i','e',':'};
158 
159  user_len = 0;
161  return NULL;
162 
163  /* user_len already accounts for terminating NULL */
164  len = ARRAY_SIZE(cookie_prefix) + user_len + 1 /* @ */ + domain.len + path.len;
165  url = heap_alloc(len * sizeof(WCHAR));
166  if(!url)
167  return NULL;
168 
169  memcpy(url, cookie_prefix, sizeof(cookie_prefix));
170  p = url + ARRAY_SIZE(cookie_prefix);
171 
172  if(!GetUserNameW(p, &user_len)) {
173  heap_free(url);
174  return NULL;
175  }
176  p += user_len;
177 
178  *(p - 1) = '@';
179 
180  memcpy(p, domain.str, domain.len*sizeof(WCHAR));
181  p += domain.len;
182 
183  for(i=0; i < path.len; i++)
184  p[i] = towlower(path.str[i]);
185  p[path.len] = 0;
186 
187  ret_path->str = p;
188  ret_path->len = path.len;
189  return url;
190 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
Definition: cookie.c:41
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR url[]
Definition: encode.c:1432
unsigned long DWORD
Definition: ntddk_ex.h:95
const WCHAR * str
Definition: internet.h:199
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
size_t len
Definition: internet.h:200
#define towlower(c)
Definition: wctype.h:97
GLfloat GLfloat p
Definition: glext.h:8902
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by get_cookie_container().

◆ delete_cookie()

static void delete_cookie ( cookie_t cookie)
static

Definition at line 236 of file cookie.c.

237 {
239 
241  heap_free(cookie->data);
242  heap_free(cookie);
243 }
WCHAR * name
Definition: cookie.c:36
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
Definition: cookie.c:33
struct list entry
Definition: cookie.c:35
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by alloc_cookie(), free_cookie_domain_list(), get_cookie(), replace_cookie(), save_persistent_cookie(), and set_cookie().

◆ find_cookie()

static cookie_t* find_cookie ( cookie_container_t container,
substr_t  name 
)
static

Definition at line 271 of file cookie.c.

272 {
273  cookie_t *iter;
274 
275  LIST_FOR_EACH_ENTRY(iter, &container->cookie_list, cookie_t, entry) {
276  if(lstrlenW(iter->name) == name.len && !wcsnicmp(iter->name, name.str, name.len))
277  return iter;
278  }
279 
280  return NULL;
281 }
#define lstrlenW
Definition: compat.h:609
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define wcsnicmp
Definition: compat.h:14
uint32_t entry
Definition: isohybrid.c:63
#define NULL
Definition: types.h:112
Definition: name.c:38

Referenced by replace_cookie(), and set_cookie().

◆ free_cookie()

void free_cookie ( void  )

Definition at line 1269 of file cookie.c.

1270 {
1272 
1274 
1276 }
static void free_cookie_domain_list(struct list *list)
Definition: cookie.c:689
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static CRITICAL_SECTION cookie_cs
Definition: cookie.c:92
static struct list domain_list
Definition: cookie.c:100
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ free_cookie_domain_list()

static void free_cookie_domain_list ( struct list list)
static

Definition at line 689 of file cookie.c.

690 {
693 
694  while(!list_empty(list)) {
696 
697  free_cookie_domain_list(&domain->subdomain_list);
698 
699  while(!list_empty(&domain->path_list)) {
701 
702  while(!list_empty(&container->cookie_list))
704 
705  heap_free(container->cookie_url);
708  }
709 
710  heap_free(domain->domain);
712  heap_free(domain);
713  }
714 }
struct list entry
Definition: metafile.c:154
static void free_cookie_domain_list(struct list *list)
Definition: cookie.c:689
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
Definition: cookie.c:41
struct container container
static void delete_cookie(cookie_t *cookie)
Definition: cookie.c:236
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
uint32_t entry
Definition: isohybrid.c:63
Definition: _list.h:228
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
struct list entry
Definition: cookie.c:43
#define LIST_ENTRY(type)
Definition: queue.h:175
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by free_cookie().

◆ get_cookie()

static DWORD get_cookie ( substr_t  host,
substr_t  path,
DWORD  flags,
cookie_set_t res 
)
static

Definition at line 535 of file cookie.c.

536 {
537  const WCHAR *p;
540  FILETIME tm;
541 
543 
544  p = host.str + host.len;
545  while(p > host.str && p[-1] != '.') p--;
546  while(p != host.str) {
547  p--;
548  while(p > host.str && p[-1] != '.') p--;
549  if(p == host.str) break;
550 
551  load_persistent_cookie(substr(p, host.str+host.len-p), substr(L"/", 1));
552  }
553 
554  p = path.str + path.len;
555  do {
557 
558  p--;
559  while(p > path.str && p[-1] != '/') p--;
560  }while(p != path.str);
561 
563  if(!domain) {
564  TRACE("Unknown host %s\n", debugstr_wn(host.str, host.len));
565  return ERROR_NO_MORE_ITEMS;
566  }
567 
568  for(domain = get_cookie_domain(host, FALSE); domain; domain = domain->parent) {
570  struct list *cursor, *cursor2;
571 
573  continue;
574 
575  LIST_FOR_EACH_SAFE(cursor, cursor2, &container->cookie_list) {
576  cookie_t *cookie_iter = LIST_ENTRY(cursor, cookie_t, entry);
577 
578  /* check for expiry */
579  if((cookie_iter->expiry.dwLowDateTime != 0 || cookie_iter->expiry.dwHighDateTime != 0)
580  && CompareFileTime(&tm, &cookie_iter->expiry) > 0) {
581  TRACE("Found expired cookie. deleting\n");
582  delete_cookie(cookie_iter);
583  continue;
584  }
585 
586  if((cookie_iter->flags & INTERNET_COOKIE_HTTPONLY) && !(flags & INTERNET_COOKIE_HTTPONLY))
587  continue;
588 
589  if(!res->size) {
590  res->cookies = heap_alloc(4*sizeof(*res->cookies));
591  if(!res->cookies)
592  continue;
593  res->size = 4;
594  }else if(res->cnt == res->size) {
595  cookie_t **new_cookies = heap_realloc(res->cookies, res->size*2*sizeof(*res->cookies));
596  if(!new_cookies)
597  continue;
598  res->cookies = new_cookies;
599  res->size *= 2;
600  }
601 
602  TRACE("%s = %s domain %s path %s\n", debugstr_w(cookie_iter->name), debugstr_w(cookie_iter->data),
603  debugstr_w(domain->domain), debugstr_wn(container->path.str, container->path.len));
604 
605  if(res->cnt)
606  res->string_len += 2; /* '; ' */
607  res->cookies[res->cnt++] = cookie_iter;
608 
609  res->string_len += lstrlenW(cookie_iter->name);
610  if(*cookie_iter->data)
611  res->string_len += 1 /* = */ + lstrlenW(cookie_iter->data);
612  }
613  }
614  }
615 
616  return ERROR_SUCCESS;
617 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
#define LIST_FOR_EACH_SAFE(cursor, cursor2, list)
Definition: list.h:192
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
char * host
Definition: whois.c:55
#define lstrlenW
Definition: compat.h:609
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
Definition: cookie.c:41
struct container container
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
static BOOL cookie_match_path(cookie_container_t *container, substr_t path)
Definition: cookie.c:303
#define FALSE
Definition: types.h:117
#define debugstr_w
Definition: kernel32.h:32
static cookie_domain_t * get_cookie_domain(substr_t domain, BOOL create)
Definition: cookie.c:102
static void delete_cookie(cookie_t *cookie)
Definition: cookie.c:236
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLbitfield flags
Definition: glext.h:7161
static const WCHAR L[]
Definition: oid.c:1250
uint32_t entry
Definition: isohybrid.c:63
Definition: _list.h:228
Definition: time.h:76
#define debugstr_wn
Definition: kernel32.h:33
const char cursor[]
Definition: icontest.c:13
static BOOL load_persistent_cookie(substr_t domain, substr_t path)
Definition: cookie.c:308
GLuint res
Definition: glext.h:9613
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203
#define INTERNET_COOKIE_HTTPONLY
Definition: wininet.h:1828
GLfloat GLfloat p
Definition: glext.h:8902
#define LIST_ENTRY(type)
Definition: queue.h:175
DWORD dwLowDateTime
Definition: mapidefs.h:65

Referenced by get_cookie_header(), and InternetGetCookieExW().

◆ get_cookie_container()

static cookie_container_t* get_cookie_container ( substr_t  domain,
substr_t  path,
BOOL  create 
)
static

Definition at line 192 of file cookie.c.

193 {
194  cookie_domain_t *cookie_domain;
195  cookie_container_t *cookie_container, *iter;
196 
197  cookie_domain = get_cookie_domain(domain, create);
198  if(!cookie_domain)
199  return NULL;
200 
201  LIST_FOR_EACH_ENTRY(cookie_container, &cookie_domain->path_list, cookie_container_t, entry) {
202  if(cookie_container->path.len < path.len)
203  break;
204 
205  if(path.len == cookie_container->path.len && !wcsnicmp(cookie_container->path.str, path.str, path.len))
206  return cookie_container;
207  }
208 
209  if(!create)
210  return NULL;
211 
212  cookie_container = heap_alloc(sizeof(*cookie_container));
213  if(!cookie_container)
214  return NULL;
215 
216  cookie_container->cookie_url = create_cookie_url(substrz(cookie_domain->domain), path, &cookie_container->path);
217  if(!cookie_container->cookie_url) {
218  heap_free(cookie_container);
219  return NULL;
220  }
221 
222  cookie_container->domain = cookie_domain;
223  list_init(&cookie_container->cookie_list);
224 
225  LIST_FOR_EACH_ENTRY(iter, &cookie_domain->path_list, cookie_container_t, entry) {
226  if(iter->path.len <= path.len) {
227  list_add_before(&iter->entry, &cookie_container->entry);
228  return cookie_container;
229  }
230  }
231 
232  list_add_tail(&cookie_domain->path_list, &cookie_container->entry);
233  return cookie_container;
234 }
static substr_t substrz(const WCHAR *str)
Definition: internet.h:209
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
Definition: cookie.c:41
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
static cookie_domain_t * get_cookie_domain(substr_t domain, BOOL create)
Definition: cookie.c:102
static WCHAR * create_cookie_url(substr_t domain, substr_t path, substr_t *ret_path)
Definition: cookie.c:152
#define wcsnicmp
Definition: compat.h:14
const WCHAR * str
Definition: internet.h:199
uint32_t entry
Definition: isohybrid.c:63
#define NULL
Definition: types.h:112
__WINE_SERVER_LIST_INLINE void list_add_before(struct list *elem, struct list *to_add)
Definition: list.h:87
size_t len
Definition: internet.h:200
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
static const struct access_res create[16]
Definition: package.c:7720
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by load_persistent_cookie(), and set_cookie().

◆ get_cookie_domain()

static cookie_domain_t* get_cookie_domain ( substr_t  domain,
BOOL  create 
)
static

Definition at line 102 of file cookie.c.

103 {
104  const WCHAR *ptr = domain.str + domain.len, *ptr_end, *subdomain_ptr;
105  cookie_domain_t *iter, *current_domain, *prev_domain = NULL;
106  struct list *current_list = &domain_list;
107 
108  while(1) {
109  for(ptr_end = ptr--; ptr > domain.str && *ptr != '.'; ptr--);
110  subdomain_ptr = *ptr == '.' ? ptr+1 : ptr;
111 
112  current_domain = NULL;
113  LIST_FOR_EACH_ENTRY(iter, current_list, cookie_domain_t, entry) {
114  if(ptr_end-subdomain_ptr == iter->subdomain_len
115  && !memcmp(subdomain_ptr, iter->domain, iter->subdomain_len*sizeof(WCHAR))) {
116  current_domain = iter;
117  break;
118  }
119  }
120 
121  if(!current_domain) {
122  if(!create)
123  return prev_domain;
124 
125  current_domain = heap_alloc(sizeof(*current_domain));
126  if(!current_domain)
127  return NULL;
128 
129  current_domain->domain = heap_strndupW(subdomain_ptr, domain.str + domain.len - subdomain_ptr);
130  if(!current_domain->domain) {
131  heap_free(current_domain);
132  return NULL;
133  }
134 
135  current_domain->subdomain_len = ptr_end-subdomain_ptr;
136 
137  current_domain->parent = prev_domain;
138  list_init(&current_domain->path_list);
139  list_init(&current_domain->subdomain_list);
140 
141  list_add_tail(current_list, &current_domain->entry);
142  }
143 
144  if(ptr == domain.str)
145  return current_domain;
146 
147  prev_domain = current_domain;
148  current_list = &current_domain->subdomain_list;
149  }
150 }
static LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
Definition: cookie.c:41
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
static PVOID ptr
Definition: dispmode.c:27
static struct list domain_list
Definition: cookie.c:100
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint32_t entry
Definition: isohybrid.c:63
Definition: _list.h:228
#define NULL
Definition: types.h:112
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
static const struct access_res create[16]
Definition: package.c:7720
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by get_cookie(), and get_cookie_container().

◆ get_cookie_header()

DWORD get_cookie_header ( const WCHAR host,
const WCHAR path,
WCHAR **  ret 
)

Definition at line 646 of file cookie.c.

647 {
648  cookie_set_t cookie_set = {0};
649  DWORD res;
650 
651  static const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' '};
652 
654 
656  if(res != ERROR_SUCCESS) {
658  return res;
659  }
660 
661  if(cookie_set.cnt) {
662  WCHAR *header, *ptr;
663 
664  ptr = header = heap_alloc(sizeof(cookieW) + (cookie_set.string_len + 3 /* crlf0 */) * sizeof(WCHAR));
665  if(header) {
666  memcpy(ptr, cookieW, sizeof(cookieW));
667  ptr += ARRAY_SIZE(cookieW);
668 
669  cookie_set_to_string(&cookie_set, ptr);
670  heap_free(cookie_set.cookies);
671  ptr += cookie_set.string_len;
672 
673  *ptr++ = '\r';
674  *ptr++ = '\n';
675  *ptr++ = 0;
676 
677  *ret = header;
678  }else {
680  }
681  }else {
682  *ret = NULL;
683  }
684 
686  return res;
687 }
#define ERROR_SUCCESS
Definition: deptool.c:10
static substr_t substrz(const WCHAR *str)
Definition: internet.h:209
char * host
Definition: whois.c:55
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static DWORD get_cookie(substr_t host, substr_t path, DWORD flags, cookie_set_t *res)
Definition: cookie.c:535
static void cookie_set_to_string(const cookie_set_t *cookie_set, WCHAR *str)
Definition: cookie.c:619
static PVOID ptr
Definition: dispmode.c:27
static CRITICAL_SECTION cookie_cs
Definition: cookie.c:92
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
cookie_t ** cookies
Definition: cookie.c:528
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
unsigned string_len
Definition: cookie.c:532
GLuint res
Definition: glext.h:9613
unsigned cnt
Definition: cookie.c:529
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define INTERNET_COOKIE_HTTPONLY
Definition: wininet.h:1828
struct CFHEADER header
Definition: fdi.c:101
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_InsertCookies().

◆ InternetClearAllPerSiteCookieDecisions()

BOOL WINAPI InternetClearAllPerSiteCookieDecisions ( VOID  )

Definition at line 1196 of file cookie.c.

1197 {
1198  FIXME("stub\n");
1199  return TRUE;
1200 }
#define TRUE
Definition: types.h:120
#define FIXME(fmt,...)
Definition: debug.h:111

◆ InternetEnumPerSiteCookieDecisionA()

BOOL WINAPI InternetEnumPerSiteCookieDecisionA ( LPSTR  pszSiteName,
ULONG pcSiteNameSize,
ULONG pdwDecision,
ULONG  dwIndex 
)

Definition at line 1207 of file cookie.c.

1209 {
1210  FIXME("(%s, %p, %p, 0x%08x) stub\n",
1211  debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
1212  return FALSE;
1213 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
#define debugstr_a
Definition: kernel32.h:31

◆ InternetEnumPerSiteCookieDecisionW()

BOOL WINAPI InternetEnumPerSiteCookieDecisionW ( LPWSTR  pszSiteName,
ULONG pcSiteNameSize,
ULONG pdwDecision,
ULONG  dwIndex 
)

Definition at line 1225 of file cookie.c.

1227 {
1228  FIXME("(%s, %p, %p, 0x%08x) stub\n",
1229  debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
1230  return FALSE;
1231 }
#define FALSE
Definition: types.h:117
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111

◆ InternetGetCookieA()

BOOL WINAPI InternetGetCookieA ( const char url,
const char name,
char data,
DWORD size 
)

Definition at line 862 of file cookie.c.

863 {
864  TRACE("(%s, %s, %p, %p)\n", debugstr_a(url), debugstr_a(name), data, size);
865 
866  return InternetGetCookieExA(url, name, data, size, 0, NULL);
867 }
BOOL WINAPI InternetGetCookieExA(LPCSTR lpszUrl, LPCSTR lpszCookieName, LPSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved)
Definition: cookie.c:809
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define debugstr_a
Definition: kernel32.h:31
static const WCHAR url[]
Definition: encode.c:1432
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define NULL
Definition: types.h:112
Definition: name.c:38

Referenced by test_complicated_cookie(), test_cookie_attrs(), test_cookie_url(), test_end_browser_session(), and test_get_cookie().

◆ InternetGetCookieExA()

BOOL WINAPI InternetGetCookieExA ( LPCSTR  lpszUrl,
LPCSTR  lpszCookieName,
LPSTR  lpCookieData,
LPDWORD  lpdwSize,
DWORD  flags,
void reserved 
)

Definition at line 809 of file cookie.c.

811 {
812  WCHAR *url, *name;
813  DWORD len, size = 0;
814  BOOL r;
815 
816  TRACE("(%s %s %p %p(%u) %x %p)\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
817  lpCookieData, lpdwSize, lpdwSize ? *lpdwSize : 0, flags, reserved);
818 
819  url = heap_strdupAtoW(lpszUrl);
820  name = heap_strdupAtoW(lpszCookieName);
821 
823  if( r )
824  {
825  WCHAR *szCookieData;
826 
827  szCookieData = heap_alloc(len * sizeof(WCHAR));
828  if( !szCookieData )
829  {
830  r = FALSE;
831  }
832  else
833  {
834  r = InternetGetCookieExW( url, name, szCookieData, &len, flags, reserved );
835 
836  if(r) {
837  size = WideCharToMultiByte( CP_ACP, 0, szCookieData, len, NULL, 0, NULL, NULL);
838  if(lpCookieData) {
839  if(*lpdwSize >= size) {
840  WideCharToMultiByte( CP_ACP, 0, szCookieData, len, lpCookieData, *lpdwSize, NULL, NULL);
841  }else {
843  r = FALSE;
844  }
845  }
846  }
847 
848  heap_free( szCookieData );
849  }
850  }
851  *lpdwSize = size;
852  heap_free( name );
853  heap_free( url );
854  return r;
855 }
BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, LPWSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved)
Definition: cookie.c:729
#define WideCharToMultiByte
Definition: compat.h:111
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define CP_ACP
Definition: compat.h:109
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
r reserved
Definition: btrfs.c:2940
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:80
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
static const WCHAR url[]
Definition: encode.c:1432
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
static DWORD LPSTR PDWORD lpdwSize
Definition: process.c:72
#define NULL
Definition: types.h:112
Definition: name.c:38
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by InternetGetCookieA(), and test_cookie_attrs().

◆ InternetGetCookieExW()

BOOL WINAPI InternetGetCookieExW ( LPCWSTR  lpszUrl,
LPCWSTR  lpszCookieName,
LPWSTR  lpCookieData,
LPDWORD  lpdwSize,
DWORD  flags,
void reserved 
)

Definition at line 729 of file cookie.c.

731 {
732  cookie_set_t cookie_set = {0};
733  substr_t host, path;
734  DWORD res;
735  BOOL ret;
736 
737  TRACE("(%s, %s, %p, %p, %x, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName), lpCookieData, lpdwSize, flags, reserved);
738 
740  FIXME("flags 0x%08x not supported\n", flags);
741 
742  if (!lpszUrl)
743  {
745  return FALSE;
746  }
747 
748  ret = cookie_parse_url(lpszUrl, &host, &path);
749  if (!ret) {
751  return FALSE;
752  }
753 
755 
756  res = get_cookie(host, path, flags, &cookie_set);
757  if(res != ERROR_SUCCESS) {
759  SetLastError(res);
760  return FALSE;
761  }
762 
763  if(cookie_set.cnt) {
764  if(!lpCookieData || cookie_set.string_len+1 > *lpdwSize) {
765  *lpdwSize = (cookie_set.string_len + 1) * sizeof(WCHAR);
766  TRACE("returning %u\n", *lpdwSize);
767  if(lpCookieData) {
769  ret = FALSE;
770  }
771  }else {
772  *lpdwSize = cookie_set.string_len + 1;
773  cookie_set_to_string(&cookie_set, lpCookieData);
774  lpCookieData[cookie_set.string_len] = 0;
775  }
776  }else {
777  TRACE("no cookies found for %s\n", debugstr_wn(host.str, host.len));
779  ret = FALSE;
780  }
781 
782  heap_free(cookie_set.cookies);
784  return ret;
785 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
GLsizei const GLchar ** path
Definition: glext.h:7234
char * host
Definition: whois.c:55
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static DWORD get_cookie(substr_t host, substr_t path, DWORD flags, cookie_set_t *res)
Definition: cookie.c:535
static void cookie_set_to_string(const cookie_set_t *cookie_set, WCHAR *str)
Definition: cookie.c:619
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
r reserved
Definition: btrfs.c:2940
static CRITICAL_SECTION cookie_cs
Definition: cookie.c:92
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
cookie_t ** cookies
Definition: cookie.c:528
GLbitfield flags
Definition: glext.h:7161
static BOOL cookie_parse_url(const WCHAR *url, substr_t *host, substr_t *path)
Definition: cookie.c:508
int ret
#define debugstr_wn
Definition: kernel32.h:33
static DWORD LPSTR PDWORD lpdwSize
Definition: process.c:72
unsigned string_len
Definition: cookie.c:532
GLuint res
Definition: glext.h:9613
unsigned cnt
Definition: cookie.c:529
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define INTERNET_COOKIE_HTTPONLY
Definition: wininet.h:1828
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by HTMLDocument_get_cookie(), InternetGetCookieExA(), and InternetGetCookieW().

◆ InternetGetCookieW()

BOOL WINAPI InternetGetCookieW ( const WCHAR url,
const WCHAR name,
WCHAR data,
DWORD size 
)

Definition at line 792 of file cookie.c.

793 {
794  TRACE("(%s, %s, %s, %p)\n", debugstr_w(url), debugstr_w(name), debugstr_w(data), size);
795 
796  return InternetGetCookieExW(url, name, data, size, 0, NULL);
797 }
BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, LPWSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved)
Definition: cookie.c:729
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
static const WCHAR url[]
Definition: encode.c:1432
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define NULL
Definition: types.h:112
Definition: name.c:38

Referenced by test_complicated_cookie(), test_cookie_url(), test_cookies(), and test_null().

◆ InternetGetPerSiteCookieDecisionA()

BOOL WINAPI InternetGetPerSiteCookieDecisionA ( LPCSTR  pwchHostName,
ULONG pResult 
)

Definition at line 1236 of file cookie.c.

1237 {
1238  FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
1239  return FALSE;
1240 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
#define debugstr_a
Definition: kernel32.h:31

◆ InternetGetPerSiteCookieDecisionW()

BOOL WINAPI InternetGetPerSiteCookieDecisionW ( LPCWSTR  pwchHostName,
ULONG pResult 
)

Definition at line 1245 of file cookie.c.

1246 {
1247  FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
1248  return FALSE;
1249 }
#define FALSE
Definition: types.h:117
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111

◆ InternetSetCookieA()

BOOL WINAPI InternetSetCookieA ( LPCSTR  lpszUrl,
LPCSTR  lpszCookieName,
LPCSTR  lpCookieData 
)

Definition at line 1139 of file cookie.c.

1141 {
1142  LPWSTR data, url, name;
1143  BOOL r;
1144 
1145  TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1146  debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
1147 
1148  url = heap_strdupAtoW(lpszUrl);
1149  name = heap_strdupAtoW(lpszCookieName);
1150  data = heap_strdupAtoW(lpCookieData);
1151 
1152  r = InternetSetCookieW( url, name, data );
1153 
1154  heap_free( data );
1155  heap_free( name );
1156  heap_free( url );
1157  return r;
1158 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
unsigned int BOOL
Definition: ntddk_ex.h:94
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:80
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
static const WCHAR url[]
Definition: encode.c:1432
BOOL WINAPI InternetSetCookieW(const WCHAR *url, const WCHAR *name, const WCHAR *data)
Definition: cookie.c:1122
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: name.c:38
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by test_complicated_cookie(), test_cookie_attrs(), test_cookie_header(), test_cookie_url(), test_end_browser_session(), and test_header_override().

◆ InternetSetCookieExA()

DWORD WINAPI InternetSetCookieExA ( LPCSTR  lpszURL,
LPCSTR  lpszCookieName,
LPCSTR  lpszCookieData,
DWORD  dwFlags,
DWORD_PTR  dwReserved 
)

Definition at line 1165 of file cookie.c.

1167 {
1168  WCHAR *data, *url, *name;
1169  DWORD r;
1170 
1171  TRACE("(%s, %s, %s, %x, %lx)\n", debugstr_a(lpszURL), debugstr_a(lpszCookieName),
1172  debugstr_a(lpszCookieData), dwFlags, dwReserved);
1173 
1174  url = heap_strdupAtoW(lpszURL);
1175  name = heap_strdupAtoW(lpszCookieName);
1176  data = heap_strdupAtoW(lpszCookieData);
1177 
1179 
1180  heap_free( data );
1181  heap_free( name );
1182  heap_free( url );
1183  return r;
1184 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
DWORD WINAPI InternetSetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, LPCWSTR lpCookieData, DWORD flags, DWORD_PTR reserved)
Definition: cookie.c:1077
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:90
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:80
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
static const WCHAR url[]
Definition: encode.c:1432
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
Definition: name.c:38
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by test_cookie_attrs().

◆ InternetSetCookieExW()

DWORD WINAPI InternetSetCookieExW ( LPCWSTR  lpszUrl,
LPCWSTR  lpszCookieName,
LPCWSTR  lpCookieData,
DWORD  flags,
DWORD_PTR  reserved 
)

Definition at line 1077 of file cookie.c.

1079 {
1080  substr_t host, path, name, data;
1081  BOOL ret;
1082 
1083  TRACE("(%s, %s, %s, %x, %lx)\n", debugstr_w(lpszUrl), debugstr_w(lpszCookieName),
1084  debugstr_w(lpCookieData), flags, reserved);
1085 
1087  FIXME("flags %x not supported\n", flags);
1088 
1089  if (!lpszUrl || !lpCookieData)
1090  {
1092  return COOKIE_STATE_UNKNOWN;
1093  }
1094 
1095  ret = cookie_parse_url(lpszUrl, &host, &path);
1096  if (!ret || !host.len) return COOKIE_STATE_UNKNOWN;
1097 
1098  if (!lpszCookieName) {
1099  const WCHAR *ptr;
1100 
1101  /* some apps (or is it us??) try to add a cookie with no cookie name, but
1102  * the cookie data in the form of name[=data].
1103  */
1104  if (!(ptr = wcschr(lpCookieData, '=')))
1105  ptr = lpCookieData + lstrlenW(lpCookieData);
1106 
1107  name = substr(lpCookieData, ptr - lpCookieData);
1108  data = substrz(*ptr == '=' ? ptr+1 : ptr);
1109  }else {
1110  name = substrz(lpszCookieName);
1111  data = substrz(lpCookieData);
1112  }
1113 
1114  return set_cookie(host, path, name, data, flags);
1115 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static substr_t substrz(const WCHAR *str)
Definition: internet.h:209
GLsizei const GLchar ** path
Definition: glext.h:7234
char * host
Definition: whois.c:55
#define lstrlenW
Definition: compat.h:609
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
static PVOID ptr
Definition: dispmode.c:27
r reserved
Definition: btrfs.c:2940
#define TRACE(s)
Definition: solgame.cpp:4
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:611
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
static BOOL cookie_parse_url(const WCHAR *url, substr_t *host, substr_t *path)
Definition: cookie.c:508
int ret
DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, DWORD flags)
Definition: cookie.c:912
Definition: name.c:38
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203
#define INTERNET_COOKIE_HTTPONLY
Definition: wininet.h:1828
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by HTMLDocument_put_cookie(), InternetSetCookieExA(), and InternetSetCookieW().

◆ InternetSetCookieW()

BOOL WINAPI InternetSetCookieW ( const WCHAR url,
const WCHAR name,
const WCHAR data 
)

Definition at line 1122 of file cookie.c.

1123 {
1124  TRACE("(%s, %s, %s)\n", debugstr_w(url), debugstr_w(name), debugstr_w(data));
1125 
1127 }
DWORD WINAPI InternetSetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, LPCWSTR lpCookieData, DWORD flags, DWORD_PTR reserved)
Definition: cookie.c:1077
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR url[]
Definition: encode.c:1432
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: name.c:38

Referenced by InternetSetCookieA(), set_auth_cookie(), and test_null().

◆ InternetSetPerSiteCookieDecisionA()

BOOL WINAPI InternetSetPerSiteCookieDecisionA ( LPCSTR  pchHostName,
DWORD  dwDecision 
)

Definition at line 1254 of file cookie.c.

1255 {
1256  FIXME("(%s, 0x%08x) stub\n", debugstr_a(pchHostName), dwDecision);
1257  return FALSE;
1258 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
#define debugstr_a
Definition: kernel32.h:31

◆ InternetSetPerSiteCookieDecisionW()

BOOL WINAPI InternetSetPerSiteCookieDecisionW ( LPCWSTR  pchHostName,
DWORD  dwDecision 
)

Definition at line 1263 of file cookie.c.

1264 {
1265  FIXME("(%s, 0x%08x) stub\n", debugstr_w(pchHostName), dwDecision);
1266  return FALSE;
1267 }
#define FALSE
Definition: types.h:117
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111

◆ is_domain_legal_for_cookie()

static BOOL is_domain_legal_for_cookie ( substr_t  domain,
substr_t  full_domain 
)
static

Definition at line 869 of file cookie.c.

870 {
871  const WCHAR *ptr;
872 
873  if(!domain.len || *domain.str == '.' || !full_domain.len || *full_domain.str == '.') {
875  return FALSE;
876  }
877 
878  if(domain.len > full_domain.len || !wmemchr(domain.str, '.', domain.len) || !wmemchr(full_domain.str, '.', full_domain.len))
879  return FALSE;
880 
881  ptr = full_domain.str + full_domain.len - domain.len;
882  if (wcsnicmp(domain.str, ptr, domain.len) || (full_domain.len > domain.len && ptr[-1] != '.')) {
884  return FALSE;
885  }
886 
887  return TRUE;
888 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRUE
Definition: types.h:120
_CONST_RETURN wchar_t *__cdecl wmemchr(_In_reads_(_N) const wchar_t *_S, _In_ wchar_t _C, _In_ size_t _N)
Definition: wchar.h:2537
Definition: cookie.c:41
#define FALSE
Definition: types.h:117
static PVOID ptr
Definition: dispmode.c:27
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:611
#define wcsnicmp
Definition: compat.h:14
const WCHAR * str
Definition: internet.h:199
size_t len
Definition: internet.h:200
#define ERROR_INVALID_NAME
Definition: compat.h:103

Referenced by IsDomainLegalCookieDomainW(), and set_cookie().

◆ IsDomainLegalCookieDomainW()

BOOL WINAPI IsDomainLegalCookieDomainW ( const WCHAR domain,
const WCHAR full_domain 
)

Definition at line 893 of file cookie.c.

894 {
895  FIXME("(%s, %s) semi-stub\n", debugstr_w(domain), debugstr_w(full_domain));
896 
897  if (!domain || !full_domain) {
899  return FALSE;
900  }
901 
902  return is_domain_legal_for_cookie(substrz(domain), substrz(full_domain));
903 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static BOOL is_domain_legal_for_cookie(substr_t domain, substr_t full_domain)
Definition: cookie.c:869
static substr_t substrz(const WCHAR *str)
Definition: internet.h:209
Definition: cookie.c:41
#define FALSE
Definition: types.h:117
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
#define SetLastError(x)
Definition: compat.h:611

◆ load_persistent_cookie()

static BOOL load_persistent_cookie ( substr_t  domain,
substr_t  path 
)
static

Definition at line 308 of file cookie.c.

309 {
311  cookie_container_t *cookie_container;
312  cookie_t *new_cookie;
313  HANDLE cookie;
314  char *str = NULL, *pbeg, *pend;
315  DWORD size, flags;
316  WCHAR *name, *data;
317  FILETIME expiry, create, time;
318 
319  cookie_container = get_cookie_container(domain, path, TRUE);
320  if(!cookie_container)
321  return FALSE;
322 
323  size = 0;
324  RetrieveUrlCacheEntryStreamW(cookie_container->cookie_url, NULL, &size, FALSE, 0);
326  return TRUE;
327  info = heap_alloc(size);
328  if(!info)
329  return FALSE;
330  cookie = RetrieveUrlCacheEntryStreamW(cookie_container->cookie_url, info, &size, FALSE, 0);
331  size = info->dwSizeLow;
332  heap_free(info);
333  if(!cookie)
334  return FALSE;
335 
336  if(!(str = heap_alloc(size+1)) || !ReadUrlCacheEntryStream(cookie, 0, str, &size, 0)) {
338  heap_free(str);
339  return FALSE;
340  }
341  str[size] = 0;
343 
345  for(pbeg=str; pbeg && *pbeg; name=data=NULL) {
346  pend = strchr(pbeg, '\n');
347  if(!pend)
348  break;
349  *pend = 0;
350  name = heap_strdupAtoW(pbeg);
351 
352  pbeg = pend+1;
353  pend = strchr(pbeg, '\n');
354  if(!pend)
355  break;
356  *pend = 0;
357  data = heap_strdupAtoW(pbeg);
358 
359  pbeg = strchr(pend+1, '\n');
360  if(!pbeg)
361  break;
362  sscanf(pbeg, "%u %u %u %u %u", &flags, &expiry.dwLowDateTime, &expiry.dwHighDateTime,
363  &create.dwLowDateTime, &create.dwHighDateTime);
364 
365  /* skip "*\n" */
366  pbeg = strchr(pbeg, '*');
367  if(pbeg) {
368  pbeg++;
369  if(*pbeg)
370  pbeg++;
371  }
372 
373  if(!name || !data)
374  break;
375 
376  if(CompareFileTime(&time, &expiry) <= 0) {
377  new_cookie = alloc_cookie(substr(NULL, 0), substr(NULL, 0), expiry, create, flags);
378  if(!new_cookie)
379  break;
380 
381  new_cookie->name = name;
382  new_cookie->data = data;
383 
384  replace_cookie(cookie_container, new_cookie);
385  }else {
386  heap_free(name);
387  heap_free(data);
388  }
389  }
390  heap_free(str);
391  heap_free(name);
392  heap_free(data);
393 
394  return TRUE;
395 }
static cookie_container_t * get_cookie_container(substr_t domain, substr_t path, BOOL create)
Definition: cookie.c:192
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
__u16 time
Definition: mkdosfs.c:366
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
Definition: cookie.c:41
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define FALSE
Definition: types.h:117
static void replace_cookie(cookie_container_t *container, cookie_t *new_cookie)
Definition: cookie.c:292
BOOL WINAPI ReadUrlCacheEntryStream(IN HANDLE hUrlCacheStream, IN DWORD dwLocation, IN OUT LPVOID lpBuffer, IN OUT LPDWORD lpdwLen, IN DWORD dwReserved)
Definition: urlcache.c:3133
const WCHAR * str
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:80
GLsizeiptr size
Definition: glext.h:5919
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
BOOL WINAPI UnlockUrlCacheEntryStream(IN HANDLE hUrlCacheStream, IN DWORD dwReserved)
Definition: urlcache.c:3265
__wchar_t WCHAR
Definition: xmlstorage.h:180
HANDLE WINAPI RetrieveUrlCacheEntryStreamW(LPCWSTR lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOW lpCacheEntryInfo, LPDWORD lpdwCacheEntryInfoBufferSize, BOOL fRandomRead, DWORD dwReserved)
Definition: urlcache.c:3211
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
struct _test_info info[]
Definition: SetCursorPos.c:19
Definition: cookie.c:33
#define NULL
Definition: types.h:112
char * strchr(const char *String, int ch)
Definition: utclib.c:501
Definition: name.c:38
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203
static const struct access_res create[16]
Definition: package.c:7720
static cookie_t * alloc_cookie(substr_t name, substr_t data, FILETIME expiry, FILETIME create_time, DWORD flags)
Definition: cookie.c:245
DWORD dwLowDateTime
Definition: mapidefs.h:65
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
GLuint const GLchar * name
Definition: glext.h:6031
Definition: wininet.h:2127

Referenced by get_cookie(), and set_cookie().

◆ replace_cookie()

static void replace_cookie ( cookie_container_t container,
cookie_t new_cookie 
)
static

Definition at line 292 of file cookie.c.

293 {
294  cookie_t *old_cookie;
295 
296  old_cookie = find_cookie(container, substrz(new_cookie->name));
297  if(old_cookie)
298  delete_cookie(old_cookie);
299 
300  add_cookie(container, new_cookie);
301 }
static substr_t substrz(const WCHAR *str)
Definition: internet.h:209
static void delete_cookie(cookie_t *cookie)
Definition: cookie.c:236
static cookie_t * find_cookie(cookie_container_t *container, substr_t name)
Definition: cookie.c:271
static void add_cookie(cookie_container_t *container, cookie_t *new_cookie)
Definition: cookie.c:283

Referenced by load_persistent_cookie().

◆ save_persistent_cookie()

static BOOL save_persistent_cookie ( cookie_container_t container)
static

Definition at line 397 of file cookie.c.

398 {
399  WCHAR cookie_file[MAX_PATH];
400  HANDLE cookie_handle;
401  cookie_t *cookie_container = NULL, *cookie_iter;
402  BOOL do_save = FALSE;
403  char buf[64], *dyn_buf;
404  FILETIME time;
405  DWORD bytes_written;
406  size_t len;
407 
408  /* check if there's anything to save */
410  LIST_FOR_EACH_ENTRY_SAFE(cookie_container, cookie_iter, &container->cookie_list, cookie_t, entry)
411  {
412  if((cookie_container->expiry.dwLowDateTime || cookie_container->expiry.dwHighDateTime)
413  && CompareFileTime(&time, &cookie_container->expiry) > 0) {
414  delete_cookie(cookie_container);
415  continue;
416  }
417 
418  if(!(cookie_container->flags & INTERNET_COOKIE_IS_SESSION)) {
419  do_save = TRUE;
420  break;
421  }
422  }
423 
424  if(!do_save) {
425  DeleteUrlCacheEntryW(container->cookie_url);
426  return TRUE;
427  }
428 
429  if(!CreateUrlCacheEntryW(container->cookie_url, 0, L"txt", cookie_file, 0))
430  return FALSE;
431 
432  cookie_handle = CreateFileW(cookie_file, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
433  if(cookie_handle == INVALID_HANDLE_VALUE) {
434  DeleteFileW(cookie_file);
435  return FALSE;
436  }
437 
438  LIST_FOR_EACH_ENTRY(cookie_container, &container->cookie_list, cookie_t, entry)
439  {
440  if(cookie_container->flags & INTERNET_COOKIE_IS_SESSION)
441  continue;
442 
443  dyn_buf = heap_strdupWtoA(cookie_container->name);
444  if(!dyn_buf || !WriteFile(cookie_handle, dyn_buf, strlen(dyn_buf), &bytes_written, NULL)) {
445  heap_free(dyn_buf);
446  do_save = FALSE;
447  break;
448  }
449  heap_free(dyn_buf);
450  if(!WriteFile(cookie_handle, "\n", 1, &bytes_written, NULL)) {
451  do_save = FALSE;
452  break;
453  }
454 
455  dyn_buf = heap_strdupWtoA(cookie_container->data);
456  if(!dyn_buf || !WriteFile(cookie_handle, dyn_buf, strlen(dyn_buf), &bytes_written, NULL)) {
457  heap_free(dyn_buf);
458  do_save = FALSE;
459  break;
460  }
461  heap_free(dyn_buf);
462  if(!WriteFile(cookie_handle, "\n", 1, &bytes_written, NULL)) {
463  do_save = FALSE;
464  break;
465  }
466 
467  dyn_buf = heap_strdupWtoA(container->domain->domain);
468  if(!dyn_buf || !WriteFile(cookie_handle, dyn_buf, strlen(dyn_buf), &bytes_written, NULL)) {
469  heap_free(dyn_buf);
470  do_save = FALSE;
471  break;
472  }
473  heap_free(dyn_buf);
474 
475  len = WideCharToMultiByte(CP_ACP, 0, container->path.str, container->path.len, NULL, 0, NULL, NULL);
476  dyn_buf = heap_alloc(len+1);
477  if(dyn_buf) {
478  WideCharToMultiByte(CP_ACP, 0, container->path.str, container->path.len, dyn_buf, len, NULL, NULL);
479  dyn_buf[len] = 0;
480  }
481  if(!dyn_buf || !WriteFile(cookie_handle, dyn_buf, strlen(dyn_buf), &bytes_written, NULL)) {
482  heap_free(dyn_buf);
483  do_save = FALSE;
484  break;
485  }
486  heap_free(dyn_buf);
487 
488  sprintf(buf, "\n%u\n%u\n%u\n%u\n%u\n*\n", cookie_container->flags,
489  cookie_container->expiry.dwLowDateTime, cookie_container->expiry.dwHighDateTime,
490  cookie_container->create.dwLowDateTime, cookie_container->create.dwHighDateTime);
491  if(!WriteFile(cookie_handle, buf, strlen(buf), &bytes_written, NULL)) {
492  do_save = FALSE;
493  break;
494  }
495  }
496 
497  CloseHandle(cookie_handle);
498  if(!do_save) {
499  ERR("error saving cookie file\n");
500  DeleteFileW(cookie_file);
501  return FALSE;
502  }
503 
504  memset(&time, 0, sizeof(time));
505  return CommitUrlCacheEntryW(container->cookie_url, cookie_file, time, time, 0, NULL, 0, L"txt", 0);
506 }
BOOL WINAPI CreateUrlCacheEntryW(LPCWSTR lpszUrlName, DWORD dwExpectedFileSize, LPCWSTR lpszFileExtension, LPWSTR lpszFileName, DWORD dwReserved)
Definition: urlcache.c:2815
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
#define CloseHandle
Definition: compat.h:598
#define INTERNET_COOKIE_IS_SESSION
Definition: wininet.h:1819
#define WideCharToMultiByte
Definition: compat.h:111
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
#define CP_ACP
Definition: compat.h:109
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
__u16 time
Definition: mkdosfs.c:366
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
static void delete_cookie(cookie_t *cookie)
Definition: cookie.c:236
#define OPEN_EXISTING
Definition: compat.h:634
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
BOOL WINAPI CommitUrlCacheEntryW(LPCWSTR lpszUrlName, LPCWSTR lpszLocalFileName, FILETIME ExpireTime, FILETIME LastModifiedTime, DWORD CacheEntryType, LPWSTR lpHeaderInfo, DWORD dwHeaderSize, LPCWSTR lpszFileExtension, LPCWSTR lpszOriginalUrl)
Definition: urlcache.c:3085
__wchar_t WCHAR
Definition: xmlstorage.h:180
static char * heap_strdupWtoA(const WCHAR *str)
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
uint32_t entry
Definition: isohybrid.c:63
GLenum GLsizei len
Definition: glext.h:6722
#define ERR(fmt,...)
Definition: debug.h:110
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600
#define memset(x, y, z)
Definition: compat.h:39
DWORD dwLowDateTime
Definition: mapidefs.h:65
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName)
Definition: urlcache.c:3344

Referenced by set_cookie().

◆ set_cookie()

DWORD set_cookie ( substr_t  domain,
substr_t  path,
substr_t  name,
substr_t  data,
DWORD  flags 
)

Definition at line 912 of file cookie.c.

913 {
915  cookie_t *thisCookie;
916  substr_t value;
917  const WCHAR *end_ptr;
918  FILETIME expiry, create;
919  BOOL expired = FALSE, update_persistent = FALSE;
920  DWORD cookie_flags = 0, len;
921 
922  TRACE("%s %s %s=%s %x\n", debugstr_wn(domain.str, domain.len), debugstr_wn(path.str, path.len),
923  debugstr_wn(name.str, name.len), debugstr_wn(data.str, data.len), flags);
924 
925  memset(&expiry,0,sizeof(expiry));
927 
928  /* lots of information can be parsed out of the cookie value */
929 
930  if(!(end_ptr = wmemchr(data.str, ';', data.len)))
931  end_ptr = data.str + data.len;
932  value = substr(data.str, end_ptr-data.str);
933  data.str += value.len;
934  data.len -= value.len;
935 
936  for(;;) {
937  static const WCHAR szDomain[] = {'d','o','m','a','i','n','='};
938  static const WCHAR szPath[] = {'p','a','t','h','='};
939  static const WCHAR szExpires[] = {'e','x','p','i','r','e','s','='};
940  static const WCHAR szSecure[] = {'s','e','c','u','r','e'};
941  static const WCHAR szHttpOnly[] = {'h','t','t','p','o','n','l','y'};
942  static const WCHAR szVersion[] = {'v','e','r','s','i','o','n','='};
943  static const WCHAR max_ageW[] = {'m','a','x','-','a','g','e','='};
944 
945  /* Skip ';' */
946  if(data.len)
947  substr_skip(&data, 1);
948 
949  while(data.len && *data.str == ' ')
950  substr_skip(&data, 1);
951 
952  if(!data.len)
953  break;
954 
955  if(!(end_ptr = wmemchr(data.str, ';', data.len)))
956  end_ptr = data.str + data.len;
957 
958  if(data.len >= (len = ARRAY_SIZE(szDomain)) && !wcsnicmp(data.str, szDomain, len)) {
959  substr_skip(&data, len);
960 
961  if(data.len && *data.str == '.')
962  substr_skip(&data, 1);
963 
964  if(!is_domain_legal_for_cookie(substr(data.str, end_ptr-data.str), domain))
965  return COOKIE_STATE_UNKNOWN;
966 
967  domain = substr(data.str, end_ptr-data.str);
968  TRACE("Parsing new domain %s\n", debugstr_wn(domain.str, domain.len));
969  }else if(data.len >= (len = ARRAY_SIZE(szPath)) && !wcsnicmp(data.str, szPath, len)) {
970  substr_skip(&data, len);
971  path = substr(data.str, end_ptr - data.str);
972  TRACE("Parsing new path %s\n", debugstr_wn(path.str, path.len));
973  }else if(data.len >= (len = ARRAY_SIZE(szExpires)) && !wcsnicmp(data.str, szExpires, len)) {
974  SYSTEMTIME st;
975  WCHAR buf[128];
976 
977  substr_skip(&data, len);
978 
979  if(end_ptr > data.str && (end_ptr - data.str < ARRAY_SIZE(buf) - 1)) {
980  memcpy(buf, data.str, data.len*sizeof(WCHAR));
981  buf[data.len] = 0;
982 
983  if (InternetTimeToSystemTimeW(data.str, &st, 0)) {
984  SystemTimeToFileTime(&st, &expiry);
985 
986  if (CompareFileTime(&create,&expiry) > 0) {
987  TRACE("Cookie already expired.\n");
988  expired = TRUE;
989  }
990  }
991  }
992  }else if(data.len >= (len = ARRAY_SIZE(szSecure)) && !wcsnicmp(data.str, szSecure, len)) {
993  substr_skip(&data, len);
994  FIXME("secure not handled\n");
995  }else if(data.len >= (len = ARRAY_SIZE(szHttpOnly)) && !wcsnicmp(data.str, szHttpOnly, len)) {
996  substr_skip(&data, len);
997 
999  WARN("HTTP only cookie added without INTERNET_COOKIE_HTTPONLY flag\n");
1001  return COOKIE_STATE_REJECT;
1002  }
1003 
1004  cookie_flags |= INTERNET_COOKIE_HTTPONLY;
1005  }else if(data.len >= (len = ARRAY_SIZE(szVersion)) && !wcsnicmp(data.str, szVersion, len)) {
1006  substr_skip(&data, len);
1007 
1008  FIXME("version not handled (%s)\n",debugstr_wn(data.str, data.len));
1009  }else if(data.len >= (len = ARRAY_SIZE(max_ageW)) && !wcsnicmp(data.str, max_ageW, len)) {
1010  /* Native doesn't support Max-Age attribute. */
1011  WARN("Max-Age ignored\n");
1012  }else if(data.len) {
1013  FIXME("Unknown additional option %s\n", debugstr_wn(data.str, data.len));
1014  }
1015 
1016  substr_skip(&data, end_ptr - data.str);
1017  }
1018 
1020 
1022 
1023  container = get_cookie_container(domain, path, !expired);
1024  if(!container) {
1026  return COOKIE_STATE_ACCEPT;
1027  }
1028 
1029  if(!expiry.dwLowDateTime && !expiry.dwHighDateTime)
1030  cookie_flags |= INTERNET_COOKIE_IS_SESSION;
1031  else
1032  update_persistent = TRUE;
1033 
1034  if ((thisCookie = find_cookie(container, name))) {
1035  if ((thisCookie->flags & INTERNET_COOKIE_HTTPONLY) && !(flags & INTERNET_COOKIE_HTTPONLY)) {
1036  WARN("An attempt to override httponly cookie\n");
1039  return COOKIE_STATE_REJECT;
1040  }
1041 
1042  if (!(thisCookie->flags & INTERNET_COOKIE_IS_SESSION))
1043  update_persistent = TRUE;
1044  delete_cookie(thisCookie);
1045  }
1046 
1047  TRACE("setting cookie %s=%s for domain %s path %s\n", debugstr_wn(name.str, name.len),
1048  debugstr_wn(value.str, value.len), debugstr_w(container->domain->domain),
1049  debugstr_wn(container->path.str, container->path.len));
1050 
1051  if (!expired) {
1052  cookie_t *new_cookie;
1053 
1054  new_cookie = alloc_cookie(name, value, expiry, create, cookie_flags);
1055  if(!new_cookie) {
1057  return COOKIE_STATE_UNKNOWN;
1058  }
1059 
1060  add_cookie(container, new_cookie);
1061  }
1062 
1063  if (!update_persistent || save_persistent_cookie(container))
1064  {
1066  return COOKIE_STATE_ACCEPT;
1067  }
1069  return COOKIE_STATE_UNKNOWN;
1070 }
static cookie_container_t * get_cookie_container(substr_t domain, substr_t path, BOOL create)
Definition: cookie.c:192
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
Definition: pdh_main.c:93
#define INTERNET_COOKIE_IS_SESSION
Definition: wininet.h:1819
static BOOL is_domain_legal_for_cookie(substr_t domain, substr_t full_domain)
Definition: cookie.c:869
static void substr_skip(substr_t *str, size_t len)
Definition: cookie.c:905
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_CONST_RETURN wchar_t *__cdecl wmemchr(_In_reads_(_N) const wchar_t *_S, _In_ wchar_t _C, _In_ size_t _N)
Definition: wchar.h:2537
Definition: cookie.c:41
struct container container
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
static BOOL save_persistent_cookie(cookie_container_t *container)
Definition: cookie.c:397
static void delete_cookie(cookie_t *cookie)
Definition: cookie.c:236
static CRITICAL_SECTION cookie_cs
Definition: cookie.c:92
static cookie_t * find_cookie(cookie_container_t *container, substr_t name)
Definition: cookie.c:271
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
static LPCWSTR szVersion
Definition: asmcache.c:748
#define wcsnicmp
Definition: compat.h:14
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLsizei const GLfloat * value
Definition: glext.h:6069
#define debugstr_wn
Definition: kernel32.h:33
static void add_cookie(cookie_container_t *container, cookie_t *new_cookie)
Definition: cookie.c:283
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
LPCWSTR szPath
Definition: env.c:37
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ERROR_INVALID_OPERATION
Definition: winerror.h:1261
static BOOL load_persistent_cookie(substr_t domain, substr_t path)
Definition: cookie.c:308
Definition: name.c:38
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define INTERNET_COOKIE_HTTPONLY
Definition: wininet.h:1828
BOOL WINAPI InternetTimeToSystemTimeW(LPCWSTR string, SYSTEMTIME *time, DWORD reserved)
Definition: internet.c:3378
#define memset(x, y, z)
Definition: compat.h:39
static const struct access_res create[16]
Definition: package.c:7720
static cookie_t * alloc_cookie(substr_t name, substr_t data, FILETIME expiry, FILETIME create_time, DWORD flags)
Definition: cookie.c:245
DWORD dwLowDateTime
Definition: mapidefs.h:65

Referenced by HTTP_ProcessCookies(), InternetSetCookieExW(), and record_cookies().

◆ substr_skip()

static void substr_skip ( substr_t str,
size_t  len 
)
static

Definition at line 905 of file cookie.c.

906 {
907  assert(str->len >= len);
908  str->str += len;
909  str->len -= len;
910 }
#define assert(x)
Definition: debug.h:53
const WCHAR * str
GLenum GLsizei len
Definition: glext.h:6722

Referenced by set_cookie().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wininet  )

Variable Documentation

◆ cookie_cs

static CRITICAL_SECTION cookie_cs = { &cookie_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 92 of file cookie.c.

Referenced by free_cookie(), get_cookie_header(), InternetGetCookieExW(), and set_cookie().

◆ cookie_cs_debug

CRITICAL_SECTION_DEBUG cookie_cs_debug
static
Initial value:
=
{
0, 0, &cookie_cs,
0, 0, { (DWORD_PTR)(__FILE__ ": cookie_cs") }
}
#define DWORD_PTR
Definition: treelist.c:76
static CRITICAL_SECTION cookie_cs
Definition: cookie.c:92
LIST_ENTRY ProcessLocksList
Definition: winbase.h:877
static CRITICAL_SECTION_DEBUG cookie_cs_debug
Definition: cookie.c:93

Definition at line 93 of file cookie.c.

◆ domain_list

struct list domain_list = LIST_INIT(domain_list)
static

Definition at line 100 of file cookie.c.

Referenced by free_cookie(), and get_cookie_domain().