2003-06-21 01:26:56 +02:00
|
|
|
/*
|
|
|
|
* Wininet - cookie handling stuff
|
|
|
|
*
|
|
|
|
* Copyright 2002 TransGaming Technologies Inc.
|
|
|
|
*
|
|
|
|
* David Hammerton
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2004-09-03 20:30:28 +02:00
|
|
|
#include "wine/port.h"
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-06-21 01:26:56 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-08-08 23:07:23 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "internet.h"
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
#include "wine/list.h"
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
#define RESPONSE_TIMEOUT 30 /* FROM internet.c */
|
|
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
|
|
|
|
|
|
|
/* FIXME
|
|
|
|
* Cookies are currently memory only.
|
|
|
|
* Cookies are NOT THREAD SAFE
|
|
|
|
* Cookies could use ALOT OF MEMORY. We need some kind of memory management here!
|
|
|
|
* Cookies should care about the expiry time
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _cookie_domain cookie_domain;
|
|
|
|
typedef struct _cookie cookie;
|
|
|
|
|
|
|
|
struct _cookie
|
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
struct list entry;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
struct _cookie_domain *parent;
|
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
LPWSTR lpCookieName;
|
|
|
|
LPWSTR lpCookieData;
|
2003-06-21 01:26:56 +02:00
|
|
|
time_t expiry; /* FIXME: not used */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _cookie_domain
|
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
struct list entry;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
LPWSTR lpCookieDomain;
|
|
|
|
LPWSTR lpCookiePath;
|
2004-07-21 21:36:53 +02:00
|
|
|
struct list cookie_list;
|
2003-06-21 01:26:56 +02:00
|
|
|
};
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
static struct list domain_list = LIST_INIT(domain_list);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
static cookie *COOKIE_addCookie(cookie_domain *domain, LPCWSTR name, LPCWSTR data);
|
|
|
|
static cookie *COOKIE_findCookie(cookie_domain *domain, LPCWSTR lpszCookieName);
|
2003-06-21 01:26:56 +02:00
|
|
|
static void COOKIE_deleteCookie(cookie *deadCookie, BOOL deleteDomain);
|
2004-03-30 22:38:08 +02:00
|
|
|
static cookie_domain *COOKIE_addDomain(LPCWSTR domain, LPCWSTR path);
|
2003-06-21 01:26:56 +02:00
|
|
|
static void COOKIE_deleteDomain(cookie_domain *deadDomain);
|
|
|
|
|
|
|
|
|
|
|
|
/* adds a cookie to the domain */
|
2004-03-30 22:38:08 +02:00
|
|
|
static cookie *COOKIE_addCookie(cookie_domain *domain, LPCWSTR name, LPCWSTR data)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
|
|
|
cookie *newCookie = HeapAlloc(GetProcessHeap(), 0, sizeof(cookie));
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
list_init(&newCookie->entry);
|
2003-06-21 01:26:56 +02:00
|
|
|
newCookie->lpCookieName = NULL;
|
|
|
|
newCookie->lpCookieData = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
newCookie->lpCookieName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1)*sizeof(WCHAR));
|
|
|
|
lstrcpyW(newCookie->lpCookieName, name);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
newCookie->lpCookieData = HeapAlloc(GetProcessHeap(), 0, (strlenW(data) + 1)*sizeof(WCHAR));
|
|
|
|
lstrcpyW(newCookie->lpCookieData, data);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("added cookie %p (data is %s)\n", newCookie, debugstr_w(data) );
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
list_add_tail(&domain->cookie_list, &newCookie->entry);
|
2003-06-21 01:26:56 +02:00
|
|
|
newCookie->parent = domain;
|
|
|
|
return newCookie;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* finds a cookie in the domain matching the cookie name */
|
2004-03-30 22:38:08 +02:00
|
|
|
static cookie *COOKIE_findCookie(cookie_domain *domain, LPCWSTR lpszCookieName)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
struct list * cursor;
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("(%p, %s)\n", domain, debugstr_w(lpszCookieName));
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
LIST_FOR_EACH(cursor, &domain->cookie_list)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
cookie *searchCookie = LIST_ENTRY(cursor, cookie, entry);
|
2003-06-21 01:26:56 +02:00
|
|
|
BOOL candidate = TRUE;
|
|
|
|
if (candidate && lpszCookieName)
|
|
|
|
{
|
|
|
|
if (candidate && !searchCookie->lpCookieName)
|
|
|
|
candidate = FALSE;
|
2004-03-30 22:38:08 +02:00
|
|
|
if (candidate && strcmpW(lpszCookieName, searchCookie->lpCookieName) != 0)
|
2003-06-21 01:26:56 +02:00
|
|
|
candidate = FALSE;
|
|
|
|
}
|
|
|
|
if (candidate)
|
|
|
|
return searchCookie;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* removes a cookie from the list, if its the last cookie we also remove the domain */
|
|
|
|
static void COOKIE_deleteCookie(cookie *deadCookie, BOOL deleteDomain)
|
|
|
|
{
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, deadCookie->lpCookieName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, deadCookie->lpCookieData);
|
2004-07-21 21:36:53 +02:00
|
|
|
list_remove(&deadCookie->entry);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
/* special case: last cookie, lets remove the domain to save memory */
|
|
|
|
if (list_empty(&deadCookie->parent->cookie_list) && deleteDomain)
|
|
|
|
COOKIE_deleteDomain(deadCookie->parent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, deadCookie);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocates a domain and adds it to the end */
|
2004-03-30 22:38:08 +02:00
|
|
|
static cookie_domain *COOKIE_addDomain(LPCWSTR domain, LPCWSTR path)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
|
|
|
cookie_domain *newDomain = HeapAlloc(GetProcessHeap(), 0, sizeof(cookie_domain));
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
list_init(&newDomain->entry);
|
|
|
|
list_init(&newDomain->cookie_list);
|
2003-06-21 01:26:56 +02:00
|
|
|
newDomain->lpCookieDomain = NULL;
|
|
|
|
newDomain->lpCookiePath = NULL;
|
|
|
|
|
|
|
|
if (domain)
|
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
newDomain->lpCookieDomain = HeapAlloc(GetProcessHeap(), 0, (strlenW(domain) + 1)*sizeof(WCHAR));
|
|
|
|
strcpyW(newDomain->lpCookieDomain, domain);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
if (path)
|
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
newDomain->lpCookiePath = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1)*sizeof(WCHAR));
|
|
|
|
lstrcpyW(newDomain->lpCookiePath, path);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
list_add_tail(&domain_list, &newDomain->entry);
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
TRACE("Adding domain: %p\n", newDomain);
|
|
|
|
return newDomain;
|
|
|
|
}
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
static void COOKIE_crackUrlSimple(LPCWSTR lpszUrl, LPWSTR hostName, int hostNameLen, LPWSTR path, int pathLen)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
URL_COMPONENTSW UrlComponents;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
UrlComponents.lpszExtraInfo = NULL;
|
|
|
|
UrlComponents.lpszPassword = NULL;
|
|
|
|
UrlComponents.lpszScheme = NULL;
|
|
|
|
UrlComponents.lpszUrlPath = path;
|
|
|
|
UrlComponents.lpszUserName = NULL;
|
|
|
|
UrlComponents.lpszHostName = hostName;
|
2004-07-21 21:36:53 +02:00
|
|
|
UrlComponents.dwHostNameLength = hostNameLen;
|
|
|
|
UrlComponents.dwUrlPathLength = pathLen;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
InternetCrackUrlW(lpszUrl, 0, 0, &UrlComponents);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
/* match a domain. domain must match if the domain is not NULL. path must match if the path is not NULL */
|
|
|
|
static BOOL COOKIE_matchDomain(LPCWSTR lpszCookieDomain, LPCWSTR lpszCookiePath,
|
|
|
|
cookie_domain *searchDomain, BOOL allow_partial)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
TRACE("searching on domain %p\n", searchDomain);
|
|
|
|
if (lpszCookieDomain)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
if (!searchDomain->lpCookieDomain)
|
|
|
|
return FALSE;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("comparing domain %s with %s\n",
|
2004-07-21 21:36:53 +02:00
|
|
|
debugstr_w(lpszCookieDomain),
|
|
|
|
debugstr_w(searchDomain->lpCookieDomain));
|
|
|
|
|
|
|
|
if (allow_partial && !strstrW(lpszCookieDomain, searchDomain->lpCookieDomain))
|
|
|
|
return FALSE;
|
|
|
|
else if (!allow_partial && lstrcmpW(lpszCookieDomain, searchDomain->lpCookieDomain) != 0)
|
|
|
|
return FALSE;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
2004-07-21 21:36:53 +02:00
|
|
|
if (lpszCookiePath)
|
|
|
|
{
|
|
|
|
TRACE("comparing paths: %s with %s\n", debugstr_w(lpszCookiePath), debugstr_w(searchDomain->lpCookiePath));
|
|
|
|
if (!searchDomain->lpCookiePath)
|
|
|
|
return FALSE;
|
|
|
|
if (strcmpW(lpszCookiePath, searchDomain->lpCookiePath))
|
|
|
|
return FALSE;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
2004-07-21 21:36:53 +02:00
|
|
|
return TRUE;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove a domain from the list and delete it */
|
|
|
|
static void COOKIE_deleteDomain(cookie_domain *deadDomain)
|
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
struct list * cursor;
|
|
|
|
while ((cursor = list_tail(&deadDomain->cookie_list)))
|
|
|
|
{
|
|
|
|
COOKIE_deleteCookie(LIST_ENTRY(cursor, cookie, entry), FALSE);
|
|
|
|
list_remove(cursor);
|
|
|
|
}
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, deadDomain->lpCookieDomain);
|
|
|
|
HeapFree(GetProcessHeap(), 0, deadDomain->lpCookiePath);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
list_remove(&deadDomain->entry);
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, deadDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 22:38:08 +02:00
|
|
|
* InternetGetCookieW (WININET.@)
|
2003-06-21 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Retrieve cookie from the specified url
|
|
|
|
*
|
|
|
|
* It should be noted that on windows the lpszCookieName parameter is "not implemented".
|
|
|
|
* So it won't be implemented here.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 22:38:08 +02:00
|
|
|
BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
|
|
|
|
LPWSTR lpCookieData, LPDWORD lpdwSize)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
struct list * cursor;
|
2003-06-21 01:26:56 +02:00
|
|
|
int cnt = 0, domain_count = 0;
|
2004-07-21 21:36:53 +02:00
|
|
|
int cookie_count = 0;
|
|
|
|
WCHAR hostName[2048], path[2048];
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("(%s, %s, %p, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName),
|
2003-06-21 01:26:56 +02:00
|
|
|
lpCookieData, lpdwSize);
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
LIST_FOR_EACH(cursor, &domain_list)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
cookie_domain *cookiesDomain = LIST_ENTRY(cursor, cookie_domain, entry);
|
|
|
|
if (COOKIE_matchDomain(hostName, NULL /* FIXME: path */, cookiesDomain, TRUE))
|
|
|
|
{
|
|
|
|
struct list * cursor;
|
|
|
|
domain_count++;
|
|
|
|
TRACE("found domain %p\n", cookiesDomain);
|
|
|
|
|
|
|
|
LIST_FOR_EACH(cursor, &cookiesDomain->cookie_list)
|
|
|
|
{
|
|
|
|
cookie *thisCookie = LIST_ENTRY(cursor, cookie, entry);
|
|
|
|
if (lpCookieData == NULL) /* return the size of the buffer required to lpdwSize */
|
|
|
|
{
|
|
|
|
if (cookie_count != 0)
|
|
|
|
cnt += 2; /* '; ' */
|
|
|
|
cnt += strlenW(thisCookie->lpCookieName);
|
|
|
|
cnt += 1; /* = */
|
|
|
|
cnt += strlenW(thisCookie->lpCookieData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const WCHAR szsc[] = { ';',' ',0 };
|
|
|
|
static const WCHAR szpseq[] = { '%','s','=','%','s',0 };
|
|
|
|
if (cookie_count != 0)
|
|
|
|
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szsc);
|
|
|
|
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szpseq,
|
|
|
|
thisCookie->lpCookieName,
|
|
|
|
thisCookie->lpCookieData);
|
|
|
|
TRACE("Cookie: %s=%s\n", debugstr_w(thisCookie->lpCookieName), debugstr_w(thisCookie->lpCookieData));
|
|
|
|
}
|
|
|
|
cookie_count++;
|
|
|
|
}
|
|
|
|
}
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
if (lpCookieData == NULL)
|
|
|
|
{
|
|
|
|
cnt += 1; /* NULL */
|
2004-07-19 21:32:36 +02:00
|
|
|
*lpdwSize = cnt*sizeof(WCHAR);
|
2003-06-21 01:26:56 +02:00
|
|
|
TRACE("returning\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!domain_count)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-07-19 21:32:36 +02:00
|
|
|
*lpdwSize = (cnt + 1)*sizeof(WCHAR);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("Returning %i (from %i domains): %s\n", cnt, domain_count,
|
|
|
|
debugstr_w(lpCookieData));
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
return (cnt ? TRUE : FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 22:38:08 +02:00
|
|
|
* InternetGetCookieA (WININET.@)
|
2003-06-21 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Retrieve cookie from the specified url
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 22:38:08 +02:00
|
|
|
BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
|
|
|
|
LPSTR lpCookieData, LPDWORD lpdwSize)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
DWORD len;
|
|
|
|
LPWSTR szCookieData = NULL, szUrl = NULL, szCookieName = NULL;
|
|
|
|
BOOL r;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
|
2003-06-21 01:26:56 +02:00
|
|
|
lpCookieData);
|
2004-03-30 22:38:08 +02:00
|
|
|
|
|
|
|
if( lpszUrl )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpszUrl, -1, NULL, 0 );
|
|
|
|
szUrl = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpszUrl, -1, szUrl, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lpszCookieName )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpszCookieName, -1, NULL, 0 );
|
|
|
|
szCookieName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpszCookieName, -1, szCookieName, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
r = InternetGetCookieW( szUrl, szCookieName, NULL, &len );
|
|
|
|
if( r )
|
|
|
|
{
|
|
|
|
szCookieData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
if( !szCookieData )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
r = InternetGetCookieW( szUrl, szCookieName, szCookieData, &len );
|
|
|
|
|
|
|
|
*lpdwSize = WideCharToMultiByte( CP_ACP, 0, szCookieData, len,
|
|
|
|
lpCookieData, *lpdwSize, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, szCookieData );
|
|
|
|
HeapFree( GetProcessHeap(), 0, szCookieName );
|
|
|
|
HeapFree( GetProcessHeap(), 0, szUrl );
|
2004-03-30 22:38:08 +02:00
|
|
|
|
|
|
|
return r;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 22:38:08 +02:00
|
|
|
* InternetSetCookieW (WININET.@)
|
2003-06-21 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Sets cookie for the specified url
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 22:38:08 +02:00
|
|
|
BOOL WINAPI InternetSetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
|
|
|
|
LPCWSTR lpCookieData)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-07-21 21:36:53 +02:00
|
|
|
cookie_domain *thisCookieDomain = NULL;
|
2003-06-21 01:26:56 +02:00
|
|
|
cookie *thisCookie;
|
2004-07-21 21:36:53 +02:00
|
|
|
WCHAR hostName[2048], path[2048];
|
|
|
|
struct list * cursor;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("(%s,%s,%s)\n", debugstr_w(lpszUrl),
|
|
|
|
debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 22:38:08 +02:00
|
|
|
if (!lpCookieData || !strlenW(lpCookieData))
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
|
|
|
TRACE("no cookie data, not adding\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!lpszCookieName)
|
|
|
|
{
|
|
|
|
/* some apps (or is it us??) try to add a cookie with no cookie name, but
|
|
|
|
* the cookie data in the form of name=data. */
|
|
|
|
/* FIXME, probably a bug here, for now I don't care */
|
2004-03-30 22:38:08 +02:00
|
|
|
WCHAR *ourCookieName, *ourCookieData;
|
2003-06-21 01:26:56 +02:00
|
|
|
int ourCookieNameSize;
|
|
|
|
BOOL ret;
|
2004-03-30 22:38:08 +02:00
|
|
|
if (!(ourCookieData = strchrW(lpCookieData, '=')))
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("something terribly wrong with cookie data %s\n",
|
|
|
|
debugstr_w(ourCookieData));
|
2003-06-21 01:26:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ourCookieNameSize = ourCookieData - lpCookieData;
|
|
|
|
ourCookieData += 1;
|
2004-03-30 22:38:08 +02:00
|
|
|
ourCookieName = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(ourCookieNameSize + 1)*sizeof(WCHAR));
|
|
|
|
strncpyW(ourCookieName, ourCookieData, ourCookieNameSize);
|
2003-06-21 01:26:56 +02:00
|
|
|
ourCookieName[ourCookieNameSize] = '\0';
|
2004-03-30 22:38:08 +02:00
|
|
|
TRACE("setting (hacked) cookie of %s, %s\n",
|
|
|
|
debugstr_w(ourCookieName), debugstr_w(ourCookieData));
|
|
|
|
ret = InternetSetCookieW(lpszUrl, ourCookieName, ourCookieData);
|
2003-06-21 01:26:56 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ourCookieName);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-07-21 21:36:53 +02:00
|
|
|
COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
|
|
|
|
|
|
|
|
LIST_FOR_EACH(cursor, &domain_list)
|
|
|
|
{
|
|
|
|
thisCookieDomain = LIST_ENTRY(cursor, cookie_domain, entry);
|
|
|
|
if (COOKIE_matchDomain(hostName, NULL /* FIXME: path */, thisCookieDomain, FALSE))
|
|
|
|
break;
|
|
|
|
thisCookieDomain = NULL;
|
|
|
|
}
|
|
|
|
if (!thisCookieDomain)
|
|
|
|
thisCookieDomain = COOKIE_addDomain(hostName, path);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
if ((thisCookie = COOKIE_findCookie(thisCookieDomain, lpszCookieName)))
|
|
|
|
COOKIE_deleteCookie(thisCookie, FALSE);
|
|
|
|
|
|
|
|
thisCookie = COOKIE_addCookie(thisCookieDomain, lpszCookieName, lpCookieData);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 22:38:08 +02:00
|
|
|
* InternetSetCookieA (WININET.@)
|
2003-06-21 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Sets cookie for the specified url
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 22:38:08 +02:00
|
|
|
BOOL WINAPI InternetSetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
|
|
|
|
LPCSTR lpCookieData)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-03-30 22:38:08 +02:00
|
|
|
DWORD len;
|
|
|
|
LPWSTR szCookieData = NULL, szUrl = NULL, szCookieName = NULL;
|
|
|
|
BOOL r;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
|
|
|
|
debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
|
|
|
|
|
|
|
|
if( lpszUrl )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpszUrl, -1, NULL, 0 );
|
|
|
|
szUrl = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpszUrl, -1, szUrl, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lpszCookieName )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpszCookieName, -1, NULL, 0 );
|
|
|
|
szCookieName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpszCookieName, -1, szCookieName, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lpCookieData )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpCookieData, -1, NULL, 0 );
|
|
|
|
szCookieData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpCookieData, -1, szCookieData, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
r = InternetSetCookieW( szUrl, szCookieName, szCookieData );
|
|
|
|
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, szCookieData );
|
|
|
|
HeapFree( GetProcessHeap(), 0, szCookieName );
|
|
|
|
HeapFree( GetProcessHeap(), 0, szUrl );
|
2004-03-30 22:38:08 +02:00
|
|
|
|
|
|
|
return r;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|