cookie cleanup, phase #2. landing for dwitte@stanford.edu. bug 195908. r=darin sr=alecf

This commit is contained in:
cathleen%netscape.com 2003-03-21 22:51:18 +00:00
Родитель 18028df7d2
Коммит 483de04f4b
7 изменённых файлов: 1879 добавлений и 1833 удалений

Просмотреть файл

@ -38,8 +38,6 @@
#include "nsCookie.h"
#include "nsString.h"
#include "nsCRT.h"
#include "prmem.h"
// nsCookie Implementation
@ -96,15 +94,11 @@ NS_IMETHODIMP nsCookie::GetIsDomain(PRBool *aIsDomain) {
}
NS_IMETHODIMP nsCookie::GetHost(nsACString& aHost) {
//NS_IMETHODIMP nsCookie::GetHost(nsAUTF8String& aHost) {
// using nsACString above instead of nsAUTF8String because the latter doesn't exist yet
aHost = cookieHost;
return NS_OK;
}
NS_IMETHODIMP nsCookie::GetPath(nsACString& aPath) {
//NS_IMETHODIMP nsCookie::GetPath(nsAUTF8String& aPath) {
// using nsACString above instead of nsAUTF8String because the latter doesn't exist yet
aPath = cookiePath;
return NS_OK;
}

Просмотреть файл

@ -36,79 +36,77 @@
*
* ***** END LICENSE BLOCK ***** */
#include "plstr.h"
#include "prmem.h"
#include "nsIServiceManager.h"
#include "nsCookieManager.h"
#include "nsCRT.h"
#include "nsCookies.h"
#include "nsCookie.h"
#include "nsIGenericFactory.h"
#include "nsXPIDLString.h"
#include "nsIScriptGlobalObject.h"
#include "nsReadableUtils.h"
////////////////////////////////////////////////////////////////////////////////
// used in logging via ::Add(), to indicate origin of cookie
#ifdef PR_LOGGING
#define kCookieHeader "(added via cookiemanager interface)"
#else
#define kCookieHeader ""
#endif
////////////////////////////////////////////////////////////////////////////////
class nsCookieEnumerator : public nsISimpleEnumerator
{
public:
public:
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
// note: mCookieCount is initialized just once in the ctor. While it might
// appear that the cookie list can change while the cookiemanager is running,
// the cookieservice is actually on the same thread, so it can't. Note that
// a new nsCookieEnumerator is created each time the cookiemanager is loaded.
// So we only need to get the count once. If we ever change the cookieservice to
// run on a different thread, then something to the effect of a lock will be
// required. see bug 191682 for details.
// note also that COOKIE_Count() removes expired cookies from the list before
// returning the count, so that they're not displayed in the cookiemanager.
nsCookieEnumerator() : mCookieIndex(0),
mCookieCount(COOKIE_Count())
{
}
// note: mCookieCount is initialized just once in the ctor. While it might
// appear that the cookie list can change while the cookiemanager is running,
// the cookieservice is actually on the same thread, so it can't. Note that
// a new nsCookieEnumerator is created each time the cookiemanager is loaded.
// So we only need to get the count once. If we ever change the cookieservice to
// run on a different thread, then something to the effect of a lock will be
// required. see bug 191682 for details.
nsCookieEnumerator() :
mCookieIndex(0)
{
PRInt32 temp;
COOKIE_RemoveExpiredCookies(nsTime() / PR_USEC_PER_SEC, temp);
mCookieCount = sCookieList->Count();
}
NS_IMETHOD HasMoreElements(PRBool *result)
{
*result = mCookieCount > mCookieIndex;
return NS_OK;
}
NS_IMETHOD HasMoreElements(PRBool *result)
{
*result = mCookieIndex < mCookieCount;
return NS_OK;
}
NS_IMETHOD GetNext(nsISupports **result)
{
nsCAutoString name;
nsCAutoString value;
PRBool isDomain;
nsCAutoString host;
nsCAutoString path;
PRBool isSecure;
PRUint64 expires;
nsCookieStatus status;
nsCookiePolicy policy;
nsresult rv = COOKIE_Enumerate
(mCookieIndex++, name, value, isDomain, host, path, isSecure, expires,
status, policy);
if (NS_SUCCEEDED(rv)) {
nsICookie *cookie =
new nsCookie(name, value, isDomain, host, path, isSecure, expires,
status, policy);
*result = cookie;
NS_ADDREF(*result);
} else {
*result = nsnull;
}
return rv;
}
NS_IMETHOD GetNext(nsISupports **result)
{
if (mCookieIndex >= mCookieCount) {
*result = nsnull;
NS_ERROR("bad cookie index");
return NS_ERROR_UNEXPECTED;
}
virtual ~nsCookieEnumerator()
{
}
cookie_CookieStruct *cookieInList = NS_STATIC_CAST(cookie_CookieStruct*, sCookieList->ElementAt(mCookieIndex++));
NS_ASSERTION(cookieInList, "corrupt cookie list");
// create a new nsICookie and copy the cookie data
if (!(*result = COOKIE_ChangeFormat(cookieInList).get())) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
virtual ~nsCookieEnumerator()
{
}
protected:
PRInt32 mCookieIndex;
PRInt32 mCookieCount;
protected:
PRInt32 mCookieIndex;
PRInt32 mCookieCount;
};
NS_IMPL_ISUPPORTS1(nsCookieEnumerator, nsISimpleEnumerator);
@ -123,7 +121,7 @@ nsCookieManager::nsCookieManager()
{
}
nsCookieManager::~nsCookieManager(void)
nsCookieManager::~nsCookieManager()
{
}
@ -133,45 +131,64 @@ nsresult nsCookieManager::Init()
return NS_OK;
}
NS_IMETHODIMP nsCookieManager::RemoveAll(void) {
NS_IMETHODIMP nsCookieManager::RemoveAll()
{
::COOKIE_RemoveAll();
::COOKIE_Write();
return NS_OK;
}
NS_IMETHODIMP nsCookieManager::GetEnumerator(nsISimpleEnumerator * *entries)
NS_IMETHODIMP nsCookieManager::GetEnumerator(nsISimpleEnumerator **entries)
{
*entries = nsnull;
*entries = nsnull;
nsCookieEnumerator* cookieEnum = new nsCookieEnumerator();
if (cookieEnum == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(cookieEnum);
*entries = cookieEnum;
return NS_OK;
nsCookieEnumerator* cookieEnum = new nsCookieEnumerator();
if (!cookieEnum) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(cookieEnum);
*entries = cookieEnum;
return NS_OK;
}
NS_IMETHODIMP nsCookieManager::Add(const nsACString &aDomain,
const nsACString &aPath,
const nsACString &aName,
const nsACString &aValue,
PRBool aSecure,
PRInt32 aExpires)
PRBool aIsSecure,
PRInt32 aExpires)
{
// nice COOKIE method doesn't require caller to hand off ownership of strings.
/* nulls aren't allowed (cookie code is full of checks as if they were
but see COOKIE_Write) */
cookie_CookieStruct *cookie = new cookie_CookieStruct;
if (!cookie) {
return NS_ERROR_OUT_OF_MEMORY;
}
return ::COOKIE_AddCookie(aDomain, aPath, aName, aValue,
aSecure, PR_TRUE, aExpires,
nsICookie::STATUS_UNKNOWN, nsICookie::POLICY_UNKNOWN);
nsInt64 currentTime = nsTime() / PR_USEC_PER_SEC;
cookie->host = aDomain;
cookie->path = aPath;
cookie->name = aName;
cookie->cookie = aValue;
cookie->expires = nsInt64(aExpires);
cookie->lastAccessed = currentTime;
cookie->isSession = PR_FALSE;
cookie->isSecure = aIsSecure;
cookie->isDomain = PR_TRUE;
cookie->status = nsICookie::STATUS_UNKNOWN;
cookie->policy = nsICookie::POLICY_UNKNOWN;
nsresult rv = COOKIE_Add(cookie, currentTime, nsnull, kCookieHeader);
if (NS_FAILED(rv)) {
delete cookie;
}
return NS_OK;
}
NS_IMETHODIMP nsCookieManager::Remove
(const nsACString& host, const nsACString& name, const nsACString& path, PRBool blocked) {
// (const nsAUTF8String& host, const nsACString& name, const nsAUTF8String& path, PRBool blocked) {
// using nsACString above instead of nsAUTF8String because the latter doesn't exist yet
NS_IMETHODIMP nsCookieManager::Remove(const nsACString& host,
const nsACString& name,
const nsACString& path,
PRBool blocked)
{
::COOKIE_Remove(host, name, path, blocked);
return NS_OK;
}

Просмотреть файл

@ -47,19 +47,21 @@
#include "nsIDOMWindowInternal.h"
#include "nsIPrompt.h"
#include "nsIObserverService.h"
#include "nsIObserver.h"
#include "nsIDocumentLoader.h"
#include "nsIWebProgress.h"
#include "nsCURILoader.h"
#include "nsNetCID.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h"
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
static const PRUint32 kLazyWriteLoadingTimeout = 10000; //msec
static const PRUint32 kLazyWriteFinishedTimeout = 1000; //msec
////////////////////////////////////////////////////////////////////////////////
// sadly, we need this multiple definition until everything is in one file
static const char kCookieFileName2[] = "cookies.txt";
////////////////////////////////////////////////////////////////////////////////
// nsCookieService Implementation
@ -70,44 +72,69 @@ NS_IMPL_ISUPPORTS4(nsCookieService, nsICookieService,
PRBool gCookieIconVisible = PR_FALSE;
nsCookieService::nsCookieService() :
mCookieFile(nsnull),
mObserverService(nsnull),
mLoadCount(0),
mWritePending(PR_FALSE)
{
gCookiePrefObserver = nsnull;
sCookieList = nsnull;
}
nsCookieService::~nsCookieService(void)
nsCookieService::~nsCookieService()
{
if (mWriteTimer)
mWriteTimer->Cancel();
// clean up memory
COOKIE_RemoveAll();
if (gCookiePrefObserver) {
delete gCookiePrefObserver;
}
if (sCookieList) {
delete sCookieList;
}
}
nsresult nsCookieService::Init()
{
COOKIE_RegisterPrefCallbacks();
// install the main cookie pref observer (defined in nsCookieService.h)
// this will be integrated into nsCookieService when nsCookies is removed.
gCookiePrefObserver = new nsCookiePrefObserver();
// create sCookieList
sCookieList = new nsVoidArray();
// if we can't create them, return an error so do_GetService() fails
if (!gCookiePrefObserver || !sCookieList) {
return NS_ERROR_OUT_OF_MEMORY;
}
// cache mCookieFile
nsresult rv;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mCookieFile));
if (NS_SUCCEEDED(rv)) {
rv = mCookieFile->AppendNative(NS_LITERAL_CSTRING(kCookieFileName2));
}
COOKIE_Read();
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (observerService) {
observerService->AddObserver(this, "profile-before-change", PR_TRUE);
observerService->AddObserver(this, "profile-do-change", PR_TRUE);
observerService->AddObserver(this, "cookieIcon", PR_FALSE);
mObserverService = do_GetService("@mozilla.org/observer-service;1", &rv);
if (mObserverService) {
mObserverService->AddObserver(this, "profile-before-change", PR_TRUE);
mObserverService->AddObserver(this, "profile-do-change", PR_TRUE);
mObserverService->AddObserver(this, "cookieIcon", PR_TRUE);
}
// Register as an observer for the document loader
nsCOMPtr<nsIDocumentLoader> docLoaderService =
do_GetService(kDocLoaderServiceCID, &rv);
nsCOMPtr<nsIDocumentLoader> docLoaderService = do_GetService(kDocLoaderServiceCID, &rv);
if (NS_SUCCEEDED(rv) && docLoaderService) {
nsCOMPtr<nsIWebProgress> progress(do_QueryInterface(docLoaderService));
if (progress)
(void) progress->AddProgressListener((nsIWebProgressListener*)this,
nsIWebProgress::NOTIFY_STATE_DOCUMENT |
nsIWebProgress::NOTIFY_STATE_NETWORK);
nsIWebProgress::NOTIFY_STATE_DOCUMENT |
nsIWebProgress::NOTIFY_STATE_NETWORK);
} else {
NS_ASSERTION(PR_FALSE, "Could not get nsIDocumentLoader");
NS_ERROR("Couldn't get nsIDocumentLoader");
}
return NS_OK;
@ -152,8 +179,8 @@ nsCookieService::OnProgressChange(nsIWebProgress *aProgress,
PRInt32 curTotalProgress,
PRInt32 maxTotalProgress)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
@ -166,16 +193,18 @@ nsCookieService::OnStateChange(nsIWebProgress* aWebProgress,
if (progressStateFlags & STATE_START)
++mLoadCount;
if (progressStateFlags & STATE_STOP) {
if (mLoadCount > 0) // in case we missed STATE_START
if (mLoadCount > 0) // needed because at startup we may miss initial STATE_START
--mLoadCount;
if (mLoadCount == 0)
LazyWrite(PR_FALSE);
}
}
if ((progressStateFlags & STATE_IS_DOCUMENT) &&
(progressStateFlags & STATE_STOP))
COOKIE_Notify();
if (mObserverService &&
(progressStateFlags & STATE_IS_DOCUMENT) &&
(progressStateFlags & STATE_STOP)) {
mObserverService->NotifyObservers(nsnull, "cookieChanged", NS_LITERAL_STRING("cookies").get());
}
return NS_OK;
}
@ -186,64 +215,74 @@ NS_IMETHODIMP nsCookieService::OnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *location)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::OnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const PRUnichar* aMessage)
nsIRequest* aRequest,
nsresult aStatus,
const PRUnichar* aMessage)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 state)
nsIRequest *aRequest,
PRUint32 state)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::GetCookieString(nsIURI *aURL, char ** aCookie) {
*aCookie = COOKIE_GetCookie(aURL);
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::GetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, char ** aCookie) {
if (!aURL) {
return NS_ERROR_FAILURE;
nsCookieService::GetCookieString(nsIURI *aHostURI, char ** aCookie) {
*aCookie = COOKIE_GetCookie(aHostURI, nsnull);
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::GetCookieStringFromHttp(nsIURI *aHostURI, nsIURI *aFirstURI, char ** aCookie) {
*aCookie = COOKIE_GetCookie(aHostURI, aFirstURI);
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::SetCookieString(nsIURI *aHostURI, nsIPrompt *aPrompt, const char *aCookieHeader, nsIHttpChannel *aHttpChannel)
{
nsCOMPtr<nsIURI> firstURI;
nsresult rv;
if (aHttpChannel) {
nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(aHttpChannel);
if (!httpInternal) {
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader, "unable to QueryInterface httpInternal");
return rv;
}
rv = httpInternal->GetDocumentURI(getter_AddRefs(firstURI));
if (NS_FAILED(rv)) {
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader, "unable to determine first URL");
return rv;
}
}
*aCookie = COOKIE_GetCookieFromHttp(aURL, aFirstURL);
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::SetCookieString(nsIURI *aURL, nsIPrompt* aPrompt, const char * aCookie, nsIHttpChannel* aHttpChannel) {
COOKIE_SetCookieString(aURL, aPrompt, aCookie, aHttpChannel);
COOKIE_SetCookie(aHostURI, firstURI, aPrompt, aCookieHeader, nsnull, aHttpChannel);
LazyWrite(PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::SetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, nsIPrompt *aPrompter, const char *aCookie, const char *aExpires, nsIHttpChannel* aHttpChannel)
nsCookieService::SetCookieStringFromHttp(nsIURI *aHostURI, nsIURI *aFirstURI, nsIPrompt *aPrompt, const char *aCookieHeader, const char *aServerTime, nsIHttpChannel* aHttpChannel)
{
nsCOMPtr<nsIURI> firstURL = aFirstURL;
if (!firstURL) {
firstURL = aURL;
nsCOMPtr<nsIURI> firstURI = aFirstURI;
if (!firstURI) {
firstURI = aHostURI;
}
COOKIE_SetCookieStringFromHttp(
aURL, firstURL, aPrompter, aCookie, (char *)aExpires, aHttpChannel);
COOKIE_SetCookie(aHostURI, firstURI, aPrompt, aCookieHeader, aServerTime, aHttpChannel);
LazyWrite(PR_TRUE);
return NS_OK;
}
@ -254,27 +293,39 @@ nsCookieService::GetCookieIconIsVisible(PRBool *aIsVisible) {
return NS_OK;
}
NS_IMETHODIMP nsCookieService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
NS_IMETHODIMP nsCookieService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
// The profile is about to change,
// or is going away because the application is shutting down.
if (mWriteTimer)
mWriteTimer->Cancel();
COOKIE_Write();
COOKIE_RemoveAll();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
COOKIE_DeletePersistentUserData();
if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
COOKIE_RemoveAll();
// delete the cookie file
if (mCookieFile) {
mCookieFile->Remove(PR_FALSE);
}
} else {
COOKIE_Write();
COOKIE_RemoveAll();
}
} else if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
// The profile has aleady changed.
// The profile has already changed.
// Now just read them from the new profile location.
// we also need to update the cached cookie file location
nsresult rv;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mCookieFile));
if (NS_SUCCEEDED(rv)) {
rv = mCookieFile->AppendNative(NS_LITERAL_CSTRING(kCookieFileName2));
}
COOKIE_Read();
} else if (!nsCRT::strcmp(aTopic, "cookieIcon")) {
gCookieIconVisible = (!nsCRT::strcmp(someData, NS_LITERAL_STRING("on").get()));
// this is an evil trick to avoid the blatant inefficiency of
// (!nsCRT::strcmp(aData, NS_LITERAL_STRING("on").get()))
gCookieIconVisible = (aData[0] == 'o' && aData[1] == 'n' && aData[2] == '\0');
}
return rv;
return NS_OK;
}

Просмотреть файл

@ -44,10 +44,56 @@
#include "nsIWebProgressListener.h"
#include "nsWeakReference.h"
#include "nsIIOService.h"
#include "nsIFile.h"
#include "nsITimer.h"
#include "nsIObserverService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranchInternal.h"
#include "nsPermissions.h"
////////////////////////////////////////////////////////////////////////////////
// nsCookiePrefObserver
class nsCookiePrefObserver : public nsIObserver
, public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
nsCookiePrefObserver();
virtual ~nsCookiePrefObserver();
nsresult Init();
nsresult Install();
nsresult ReadPrefs();
nsresult Remove();
// member variables for caching prefs
#ifdef MOZ_PHOENIX
// unfortunately, we require this #ifdef for now, since Phoenix uses different
// (more optimized) prefs to Mozilla. This will be fixed shortly.
// the following variables are Phoenix hacks to reduce ifdefs in the code.
PRPackedBool mCookiesEnabled_temp, // These two prefs are collapsed
mCookiesForDomainOnly_temp, // into mCookiesPermissions.
mCookiesDisabledForMailNews; // Disable cookies in mailnews
#else
PRInt32 mCookiesLifetimeSec; // Lifetime limit specified in seconds
PRPackedBool mCookiesDisabledForMailNews; // Disable cookies in mailnews
#endif
PRPackedBool mCookiesAskPermission, // Ask user permission before storing cookie
mCookiesLifetimeEnabled, // Cookie lifetime limit enabled
mCookiesLifetimeCurrentSession; // Limit cookie lifetime to current session
PRBool mCookiesStrictDomains; // Optional pref to apply stricter domain checks
PERMISSION_BehaviorEnum mCookiesPermissions; // PERMISSION_{Accept, DontAcceptForeign, DontUse, P3P}
nsXPIDLCString mCookiesP3PString; // P3P settings
private:
nsCOMPtr<nsIPrefBranch> mPrefBranch;
};
extern nsCookiePrefObserver *gCookiePrefObserver;
// nsCookieService
class nsCookieService : public nsICookieService,
public nsIObserver,
public nsIWebProgressListener,
@ -65,6 +111,10 @@ public:
nsresult Init();
protected:
// cached things
nsCOMPtr<nsIFile> mCookieFile;
nsCOMPtr<nsIObserverService> mObserverService;
// Use LazyWrite to save the cookies file on a timer. It will write
// the file only once if repeatedly hammered quickly.
void LazyWrite(PRBool aForce);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -39,61 +39,71 @@
#ifndef COOKIES_H
#define COOKIES_H
#include "nsString.h"
#include "nsCookie.h"
#include "nsIIOService.h"
#include "nsString.h"
#include "nsTime.h"
#include "nsVoidArray.h"
#include "nsIURI.h"
#include "nsIHttpChannel.h"
#include "nsIDOMWindowInternal.h"
#include <time.h>
class nsIPrompt;
class nsIHttpChannel;
extern nsresult COOKIE_Read();
extern nsresult COOKIE_Write();
extern nsresult COOKIE_Notify();
//XXX these should operate on |const char*|
extern char * COOKIE_GetCookie(nsIURI * address);
extern char * COOKIE_GetCookieFromHttp(nsIURI * address, nsIURI * firstAddress);
extern void COOKIE_SetCookieString(nsIURI * cur_url, nsIPrompt * aPrompter, const char * set_cookie_header, nsIHttpChannel* aHttpChannel);
extern void COOKIE_SetCookieStringFromHttp(nsIURI * cur_url, nsIURI * first_url, nsIPrompt *aPrompter, const char * set_cookie_header, char * server_date, nsIHttpChannel* aHttpChannel);
extern void COOKIE_RegisterPrefCallbacks(void);
extern void COOKIE_RemoveSessionCookies();
extern void COOKIE_RemoveAll(void);
extern void COOKIE_DeletePersistentUserData(void);
extern PRInt32 COOKIE_Count();
extern nsresult COOKIE_Enumerate
(PRInt32 count,
nsACString &name,
nsACString &value,
PRBool &isDomain,
nsACString &host,
nsACString &path,
PRBool &isSecure,
PRUint64 &expires,
nsCookieStatus &status,
nsCookiePolicy &policy);
extern void COOKIE_Remove
(const nsACString &host, const nsACString &name, const nsACString &path, const PRBool blocked);
extern nsresult COOKIE_AddCookie(const nsACString &aDomain, const nsACString &aPath,
const nsACString &aName, const nsACString &aValue,
PRBool aSecure, PRBool aIsDomain,
time_t aExpires,
nsCookieStatus aStatus, nsCookiePolicy aPolicy);
// main cookie storage struct
typedef struct _cookie_CookieStruct {
nsCString path;
nsCString host;
nsCString name;
nsCString cookie;
time_t expires;
time_t lastAccessed;
PRBool isSecure;
PRBool isDomain; /* is it a domain instead of an absolute host? */
PRInt64 expires;
PRInt64 lastAccessed;
PRPackedBool isSession;
PRPackedBool isSecure;
PRPackedBool isDomain;
nsCookieStatus status;
nsCookiePolicy policy;
} cookie_CookieStruct;
// define logging macros for convenience
#define SET_COOKIE PR_TRUE
#define GET_COOKIE PR_FALSE
// logging handlers
#ifdef MOZ_LOGGING
// in order to do logging, the following environment variables need to be set:
//
// set NSPR_LOG_MODULES=cookie:3 -- shows rejected cookies
// set NSPR_LOG_MODULES=cookie:4 -- shows accepted and rejected cookies
// set NSPR_LOG_FILE=c:\cookie.log
//
// this next define has to appear before the include of prlog.h
#define FORCE_PR_LOG /* Allow logging in the release build */
#include "prlog.h"
#endif
#ifdef PR_LOGGING
#define COOKIE_LOGFAILURE(a, b, c, d) cookie_LogFailure(a, b, c, d)
#define COOKIE_LOGSUCCESS(a, b, c, d) cookie_LogSuccess(a, b, c, d)
extern void cookie_LogFailure(PRBool aSetCookie, nsIURI *aHostURI, const char *aCookieString, const char *aReason);
extern void cookie_LogSuccess(PRBool aSetCookie, nsIURI *aHostURI, const char *aCookieString, cookie_CookieStruct *aCookie);
extern inline void cookie_LogFailure(PRBool aSetCookie, nsIURI *aHostURI, const nsAFlatCString &aCookieString, const char *aReason);
extern inline void cookie_LogSuccess(PRBool aSetCookie, nsIURI *aHostURI, const nsAFlatCString &aCookieString, cookie_CookieStruct *aCookie);
#else
#define COOKIE_LOGFAILURE(a, b, c, d) /* nothing */
#define COOKIE_LOGSUCCESS(a, b, c, d) /* nothing */
#endif
// function prototypes
extern nsresult COOKIE_Read();
extern nsresult COOKIE_Write();
extern void COOKIE_RemoveExpiredCookies(nsInt64 aCurrentTime, PRInt32 &aOldestPosition);
extern char * COOKIE_GetCookie(nsIURI *aHostURI, nsIURI *aFirstURI);
extern void COOKIE_SetCookie(nsIURI *aHostURI, nsIURI *aFirstURI, nsIPrompt *aPrompt, const char *aCookieHeader, const char *aServerTime, nsIHttpChannel *aHttpChannel);
extern void COOKIE_RemoveAll();
extern void COOKIE_Remove(const nsACString &host, const nsACString &name, const nsACString &path, PRBool blocked);
extern nsresult COOKIE_Add(cookie_CookieStruct *aCookie, nsInt64 aCurrentTime, nsIURI *aHostURI, const char *aCookieHeader);
extern already_AddRefed<nsICookie> COOKIE_ChangeFormat(cookie_CookieStruct *aCookie);
// constants & variables
extern nsVoidArray *sCookieList;
#endif /* COOKIES_H */

Просмотреть файл

@ -54,7 +54,7 @@ void SetACookie(nsICookieService *cookieService, const char* aSpec, const char*
NS_ASSERTION(uri, "malformed uri");
printf("setting cookie for \"%s\" : ", aSpec);
nsresult rv = cookieService->SetCookieString(uri, nsnull, (char *)aCookieString,0);
nsresult rv = cookieService->SetCookieStringFromHttp(uri, uri, nsnull, (char *)aCookieString, nsnull, nsnull);
if (NS_FAILED(rv)) {
printf("NOT-SET\n");
} else {
@ -70,7 +70,7 @@ void GetACookie(nsICookieService *cookieService, const char* aSpec, char* *aCook
char * cookieString;
printf("retrieving cookie(s) for \"%s\" : ", aSpec);
nsresult rv = cookieService->GetCookieString(uri, &cookieString);
nsresult rv = cookieService->GetCookieStringFromHttp(uri, uri, &cookieString);
if (NS_FAILED(rv)) printf("XXX GetCookieString() failed!\n");
if (!cookieString) {