From e9875f87c548cb34f514202c77559fa1ed6a3eb8 Mon Sep 17 00:00:00 2001 From: "morse%netscape.com" Date: Fri, 4 Jun 1999 21:51:57 +0000 Subject: [PATCH] reimplement cookie viewer git-svn-id: svn://10.0.0.236/trunk@33787 18797224-902f-48f8-a5cc-f745e15eee43 --- .../extensions/wallet/src/CookieViewer.html | 351 +++ mozilla/extensions/wallet/src/Makefile.in | 2 + .../extensions/wallet/src/cookie.properties | 24 + mozilla/extensions/wallet/src/makefile.win | 2 + mozilla/include/net.h | 19 - mozilla/network/module/nsINetService.h | 21 +- mozilla/network/module/nsNetService.cpp | 72 +- mozilla/network/module/nsNetService.h | 21 +- mozilla/network/protocol/http/Makefile.in | 4 + mozilla/network/protocol/http/makefile.win | 5 + mozilla/network/protocol/http/mkaccess.c | 1232 ++++---- mozilla/network/protocol/http/nsCookie.cpp | 2556 +++++++++++++++++ .../webshell/tests/viewer/nsBrowserWindow.cpp | 2 +- mozilla/xpfe/AppCores/idl/BrowserAppCore.idl | 1 - mozilla/xpfe/AppCores/idl/CookieCore.idl | 15 + mozilla/xpfe/AppCores/idl/makefile.win | 1 + mozilla/xpfe/AppCores/public/Makefile.in | 1 + mozilla/xpfe/AppCores/public/makefile.win | 1 + mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h | 5 + .../AppCores/public/nsIDOMBrowserAppCore.h | 4 - .../xpfe/AppCores/public/nsIDOMCookieCore.h | 78 + mozilla/xpfe/AppCores/src/nsCookieCore.cpp | 295 ++ mozilla/xpfe/AppCores/src/nsCookieCore.h | 67 + .../xpfe/AppCores/src/nsCookieCoreFactory.cpp | 118 + .../xpfe/AppCores/src/nsCookieCoreFactory.h | 47 + mozilla/xpfe/AppCores/src/nsJSCookieCore.cpp | 592 ++++ mozilla/xpfe/AppCores/xul/CookieWindow.js | 50 + mozilla/xpfe/AppCores/xul/Makefile.in | 1 + mozilla/xpfe/browser/src/navigator.js | 14 +- 29 files changed, 4890 insertions(+), 711 deletions(-) create mode 100644 mozilla/extensions/wallet/src/CookieViewer.html create mode 100644 mozilla/extensions/wallet/src/cookie.properties create mode 100644 mozilla/network/protocol/http/nsCookie.cpp create mode 100644 mozilla/xpfe/AppCores/idl/CookieCore.idl create mode 100644 mozilla/xpfe/AppCores/public/nsIDOMCookieCore.h create mode 100644 mozilla/xpfe/AppCores/src/nsCookieCore.cpp create mode 100644 mozilla/xpfe/AppCores/src/nsCookieCore.h create mode 100644 mozilla/xpfe/AppCores/src/nsCookieCoreFactory.cpp create mode 100644 mozilla/xpfe/AppCores/src/nsCookieCoreFactory.h create mode 100644 mozilla/xpfe/AppCores/src/nsJSCookieCore.cpp create mode 100644 mozilla/xpfe/AppCores/xul/CookieWindow.js diff --git a/mozilla/extensions/wallet/src/CookieViewer.html b/mozilla/extensions/wallet/src/CookieViewer.html new file mode 100644 index 00000000000..35ecca23ae3 --- /dev/null +++ b/mozilla/extensions/wallet/src/CookieViewer.html @@ -0,0 +1,351 @@ + + + Cookies + + + + + + + + + + + + + + + + + + <BODY> <P> </BODY> + + diff --git a/mozilla/extensions/wallet/src/Makefile.in b/mozilla/extensions/wallet/src/Makefile.in index a4d23cc3c18..c40c2208dc9 100644 --- a/mozilla/extensions/wallet/src/Makefile.in +++ b/mozilla/extensions/wallet/src/Makefile.in @@ -44,4 +44,6 @@ include $(topsrcdir)/config/rules.mk install:: $(INSTALL) $(srcdir)/WalletPreview.html $(DIST)/bin/res/samples $(INSTALL) $(srcdir)/SignonViewer.html $(DIST)/bin/res/samples + $(INSTALL) $(srcdir)/CookieViewer.html $(DIST)/bin/res/samples + $(INSTALL) $(srcdir)/cookie.properties $(DIST)/bin/res $(INSTALL) $(srcdir)/wallet.properties $(DIST)/bin/res diff --git a/mozilla/extensions/wallet/src/cookie.properties b/mozilla/extensions/wallet/src/cookie.properties new file mode 100644 index 00000000000..2a4eab164dc --- /dev/null +++ b/mozilla/extensions/wallet/src/cookie.properties @@ -0,0 +1,24 @@ +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# +Domain = Domain +Host = Host +Yes = Yes +No = No +AtEndOfSession = at end of session +PermissionToSetACookie = The site %1$s \nwants permission to set a cookie. +PermissionToSetSecondCookie = The site %1$s \nwants permission to set another cookie. You currently have a cookies from this site. +PermissionToSetAnotherCookie = The site %1$s \nwants permission to set another cookie. You currently have %2$d cookies from this site. +PermissionToModifyCookie = The site %1$s \nwants permission to modify an existing cookie. +RememberThisDecision = Remember this decision diff --git a/mozilla/extensions/wallet/src/makefile.win b/mozilla/extensions/wallet/src/makefile.win index 205d828ce24..6e95978229a 100644 --- a/mozilla/extensions/wallet/src/makefile.win +++ b/mozilla/extensions/wallet/src/makefile.win @@ -79,4 +79,6 @@ install:: $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components $(MAKE_INSTALL) WalletPreview.html $(DIST)\bin\res\samples $(MAKE_INSTALL) SignonViewer.html $(DIST)\bin\res\samples + $(MAKE_INSTALL) CookieViewer.html $(DIST)\bin\res\samples + $(MAKE_INSTALL) cookie.properties $(DIST)\bin\res $(MAKE_INSTALL) wallet.properties $(DIST)\bin\res diff --git a/mozilla/include/net.h b/mozilla/include/net.h index a3774a2ebcb..bf4346b0a1a 100644 --- a/mozilla/include/net.h +++ b/mozilla/include/net.h @@ -26,11 +26,6 @@ executed. */ -#if defined(CookieManagement) -/* #define TRUST_LABELS 1 */ -#endif - - /* make sure we only include this once */ #ifndef _NET_PROTO_H_ #define _NET_PROTO_H_ @@ -1060,23 +1055,9 @@ extern void NET_RegisterCookiePrefCallbacks(void); */ extern int NET_SaveCookies(char *filename); -/* Start an anonymous list of cookies */ -extern void NET_AnonymizeCookies(); - -/* Restore original list of cookies */ -extern void NET_UnanonymizeCookies(); - /* Should referer by supressed for anonymity sake */ extern Bool NET_SupressRefererForAnonymity(); -#if defined(CookieManagement) -extern void NET_DisplayCookieInfoAsHTML(MWContext *context); -extern void NET_CookieViewerReturn(); -extern void NET_DisplayCookieInfoOfSiteAsHTML(MWContext *context, char * URLName); -extern int NET_CookiePermission(char* URLName); -extern int NET_CookieCount(char * URLName); -#endif - #if defined(SingleSignon) extern void SI_DisplaySignonInfoAsHTML(MWContext *context); #endif diff --git a/mozilla/network/module/nsINetService.h b/mozilla/network/module/nsINetService.h index 7f9bdbeb484..ce534dc5f56 100644 --- a/mozilla/network/module/nsINetService.h +++ b/mozilla/network/module/nsINetService.h @@ -19,6 +19,7 @@ #ifndef nsINetService_h___ #define nsINetService_h___ +#include "nsString.h" #include "nscore.h" #include "nsISupports.h" #include "nsIURL.h" @@ -107,22 +108,10 @@ struct nsINetService : public nsISupports */ NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie)=0; -#ifdef CookieManagement - NS_IMETHOD NET_DisplayCookieInfoAsHTML()=0; -#ifndef HTMLDialogs - NS_IMETHOD NET_CookieViewerReturn()=0; -#endif -#ifdef PrivacySiteInfo - NS_IMETHOD NET_DisplayCookieInfoOfSiteAsHTML(char * URLName)=0; - NS_IMETHOD NET_CookiePermission(char* URLName, PRInt32* permission)=0; - NS_IMETHOD NET_CookieCount(char* URLName, PRInt32* count)=0; -#endif -#endif - - NS_IMETHOD NET_AnonymizeCookies()=0; - NS_IMETHOD NET_UnanonymizeCookies()=0; - NS_IMETHOD SI_AnonymizeSignons()=0; - NS_IMETHOD SI_UnanonymizeSignons()=0; + NS_IMETHOD Cookie_DisplayCookieInfoAsHTML()=0; + NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results)=0; + NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList)=0; + NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList)=0; /** * Get the http proxy used for http transactions. diff --git a/mozilla/network/module/nsNetService.cpp b/mozilla/network/module/nsNetService.cpp index 05defd6386d..d4985ea2bcd 100644 --- a/mozilla/network/module/nsNetService.cpp +++ b/mozilla/network/module/nsNetService.cpp @@ -759,72 +759,40 @@ nsNetlibService::SetCookieString(nsIURL *aURL, const nsString& aCookie) return NS_OK; } -#ifdef CookieManagement +extern void +COOKIE_DisplayCookieInfoAsHTML(); + +extern void +COOKIE_GetCookieListForViewer (nsString& aCookieList); + +extern void +COOKIE_GetPermissionListForViewer (nsString& aPermissionList); + +extern void +COOKIE_CookieViewerReturn(nsAutoString results); + NS_IMETHODIMP -nsNetlibService::NET_DisplayCookieInfoAsHTML(){ - ::NET_DisplayCookieInfoAsHTML(NULL); +nsNetlibService::Cookie_DisplayCookieInfoAsHTML(){ + ::COOKIE_DisplayCookieInfoAsHTML(); return NS_OK; } -#ifndef HTMLDialogs -NS_IMETHODIMP nsNetlibService::NET_CookieViewerReturn(){ - ::NET_CookieViewerReturn(); - return NS_OK; -} -#endif - -#ifdef PrivacySiteInfo -NS_IMETHODIMP -nsNetlibService::NET_DisplayCookieInfoOfSiteAsHTML(char * URLName){ - ::NET_DisplayCookieInfoOfSiteAsHTML(NULL, URLName); - return NS_OK; -} -NS_IMETHODIMP -nsNetlibService::NET_CookiePermission(char* URLName, PRInt32* permission){ - *permission = ::NET_CookiePermission(URLName); +NS_IMETHODIMP nsNetlibService::Cookie_CookieViewerReturn(nsAutoString results){ + ::COOKIE_CookieViewerReturn(results); return NS_OK; } -NS_IMETHODIMP -nsNetlibService::NET_CookieCount(char* URLName, PRInt32* count){ - *count = ::NET_CookieCount(URLName); +NS_IMETHODIMP nsNetlibService::Cookie_GetCookieListForViewer(nsString& aCookieList){ + ::COOKIE_GetCookieListForViewer(aCookieList); return NS_OK; } -#endif -#endif - -NS_IMETHODIMP -nsNetlibService::NET_AnonymizeCookies(){ -#ifdef CookieManagement - ::NET_AnonymizeCookies(); -#endif +NS_IMETHODIMP nsNetlibService::Cookie_GetPermissionListForViewer(nsString& aPermissionList){ + ::COOKIE_GetPermissionListForViewer(aPermissionList); return NS_OK; } -NS_IMETHODIMP -nsNetlibService::NET_UnanonymizeCookies(){ -#ifdef CookieManagement - ::NET_UnanonymizeCookies(); -#endif - return NS_OK; -} -NS_IMETHODIMP -nsNetlibService::SI_AnonymizeSignons(){ -#ifdef SingleSignon - ::SI_AnonymizeSignons(); -#endif - return NS_OK; -} - -NS_IMETHODIMP -nsNetlibService::SI_UnanonymizeSignons(){ -#ifdef SingleSignon - ::SI_UnanonymizeSignons(); -#endif - return NS_OK; -} NS_IMETHODIMP nsNetlibService::GetProxyHTTP(nsString& aProxyHTTP) { diff --git a/mozilla/network/module/nsNetService.h b/mozilla/network/module/nsNetService.h index f9263d642cf..1646e9941de 100644 --- a/mozilla/network/module/nsNetService.h +++ b/mozilla/network/module/nsNetService.h @@ -20,6 +20,7 @@ #ifndef nsNetService_h___ #define nsNetService_h___ +#include "nsString.h" #include "nspr.h" #include "nsIPref.h" #include "nsITransport.h" @@ -53,22 +54,10 @@ public: NS_IMETHOD GetCookieString(nsIURL *aURL, nsString& aCookie); NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie); -#ifdef CookieManagement - NS_IMETHOD NET_DisplayCookieInfoAsHTML(); -#ifndef HTMLDialogs - NS_IMETHOD NET_CookieViewerReturn(); -#endif -#ifdef PrivacySiteInfo - NS_IMETHOD NET_DisplayCookieInfoOfSiteAsHTML(char * URLName); - NS_IMETHOD NET_CookiePermission(char* URLName, PRInt32* permission); - NS_IMETHOD NET_CookieCount(char* URLName, PRInt32* count); -#endif -#endif - - NS_IMETHOD NET_AnonymizeCookies(); - NS_IMETHOD NET_UnanonymizeCookies(); - NS_IMETHOD SI_AnonymizeSignons(); - NS_IMETHOD SI_UnanonymizeSignons(); + NS_IMETHOD Cookie_DisplayCookieInfoAsHTML(); + NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results); + NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList); + NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList); NS_IMETHOD GetProxyHTTP(nsString& aProxyHTTP); NS_IMETHOD SetProxyHTTP(nsString& aProxyHTTP); diff --git a/mozilla/network/protocol/http/Makefile.in b/mozilla/network/protocol/http/Makefile.in index e1c8aedc720..36d8132efcb 100644 --- a/mozilla/network/protocol/http/Makefile.in +++ b/mozilla/network/protocol/http/Makefile.in @@ -30,6 +30,10 @@ CSRCS = \ mkaccess.c \ $(NULL) +CPPSRCS = \ + nsCookie.cpp \ + $(NULL) + ifdef MOZ_BRPROF CPPSRCS += nsGetBrowsingProfile.cpp endif diff --git a/mozilla/network/protocol/http/makefile.win b/mozilla/network/protocol/http/makefile.win index a3db1ef296d..2920bbcb940 100644 --- a/mozilla/network/protocol/http/makefile.win +++ b/mozilla/network/protocol/http/makefile.win @@ -47,6 +47,7 @@ OBJS= \ CPP_OBJS= \ .\$(OBJDIR)\nsGetBrowsingProfile.obj \ + .\$(OBJDIR)\nsCookie.obj \ $(NULL) CSRCS = \ @@ -56,6 +57,7 @@ CSRCS = \ CPPSRCS = \ nsGetBrowsingProfile.cpp \ + nsCookie.cpp \ $(NULL) LIBRARY_NAME=httpurl @@ -89,6 +91,9 @@ LINCS= \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\brprof \ -I$(PUBLIC)\raptor \ + -I$(PUBLIC)\netlib \ + -I$(PUBLIC)\intl \ + -I$(PUBLIC)\locale \ $(NULL) #!endif diff --git a/mozilla/network/protocol/http/mkaccess.c b/mozilla/network/protocol/http/mkaccess.c index e1b9c4e9d5c..804fa43faef 100644 --- a/mozilla/network/protocol/http/mkaccess.c +++ b/mozilla/network/protocol/http/mkaccess.c @@ -44,7 +44,7 @@ #include "mkparse.h" #include "mkaccess.h" #include "net_xp_file.h" -#include "cookies.h" +//#include "cookies.h" #include "httpauth.h" #include "prefapi.h" #include "shist.h" @@ -76,6 +76,7 @@ extern int XP_UNIDENTIFIED_PROXY_SERVER; extern int XP_PROXY_AUTH_REQUIRED_FOR; extern int XP_CONNECT_PLEASE_ENTER_PASSWORD_FOR_PROXY; extern int XP_FORTEZZA_PROXY_AUTH; +/* extern int MK_ACCESS_COOKIES_THE_SERVER; extern int MK_ACCESS_COOKIES_WISHES; #if defined(CookieManagement) @@ -137,8 +138,8 @@ extern int MK_ACCESS_TL_RPH3; #define MAX_NUMBER_OF_COOKIES 300 #define MAX_COOKIES_PER_SERVER 20 -#define MAX_BYTES_PER_COOKIE 4096 /* must be at least 1 */ - +#define MAX_BYTES_PER_COOKIE 4096 // must be at least 1 +*/ /* * Authentication information for servers and proxies is kept * on separate lists, but both lists consist of net_AuthStruct's. @@ -148,7 +149,7 @@ HG73943 PRIVATE XP_List * net_auth_list = NULL; PRIVATE XP_List * net_proxy_auth_list = NULL; - +/* PRIVATE Bool cookies_changed = FALSE; #if defined(CookieManagement) PRIVATE Bool cookie_permissions_changed = FALSE; @@ -158,7 +159,7 @@ PRIVATE Bool cookie_remember_checked = FALSE; PRIVATE NET_CookieBehaviorEnum net_CookieBehavior = NET_Accept; PRIVATE Bool net_WarnAboutCookies = FALSE; PRIVATE char *net_scriptName = (char *)0; - +*/ /* * Different schemes supported by the client. * Order means the order of preference between authentication schemes. @@ -1015,7 +1016,7 @@ NET_AskForAuthString(MWContext *context, * The following routines support the * Set-Cookie: / Cookie: headers */ - +/* PRIVATE XP_List * net_cookie_list=0; #if defined(CookieManagement) PRIVATE XP_List * net_cookie_permission_list=0; @@ -1030,25 +1031,29 @@ typedef struct _net_CookieStruct { time_t expires; time_t last_accessed; HG26237 - Bool is_domain; /* is it a domain instead of an absolute host? */ + Bool is_domain; // is it a domain instead of an absolute host? } net_CookieStruct; +*/ +/* #if defined(CookieManagement) typedef struct _net_CookiePermissionStruct { char * host; Bool permission; #ifdef TRUST_LABELS - XP_List * TrustList; /* a list of trust label entries */ + XP_List * TrustList; // a list of trust label entries #endif } net_CookiePermissionStruct; - +*/ +/* typedef struct _net_DeferCookieStruct { MWContext * context; char * cur_url; char * set_cookie_header; time_t timeToExpire; } net_DeferCookieStruct; - +*/ +/* #ifdef TRUST_LABELS void ParseTrustLabelInfo (char *Buf, net_CookiePermissionStruct * cookie_permission); @@ -1059,20 +1064,20 @@ void AddTrustLabelInfo( char *CookieName, TrustLabel *trustlabel ); typedef struct { char * CookieName; - int purpose; /* the purpose rating has a series of bits set */ - int recipient; /* the recipient value */ - Bool bIdentifiable; /* true if the related cookie puts to identifiable information */ - char * by; /* the by field from the trust label */ - char * CookieSet; /* when the cookie was set into cookies.txt */ + int purpose; // the purpose rating has a series of bits set + int recipient; // the recipient value + Bool bIdentifiable; // true if the related cookie puts to identifiable information + char * by; // the by field from the trust label + char * CookieSet; // when the cookie was set into cookies.txt } TrustEntry; #endif #endif - +*/ /* Routines and data to protect the cookie list so it ** can be accessed by mulitple threads */ - +/* #include "prthread.h" #include "prmon.h" @@ -1090,7 +1095,7 @@ net_lock_cookie_list(void) while(TRUE) { - /* no current owner or owned by this thread */ + // no current owner or owned by this thread PRThread * t = PR_CurrentThread(); if(cookie_lock_owner == NULL || cookie_lock_owner == t) { cookie_lock_owner = t; @@ -1100,19 +1105,21 @@ net_lock_cookie_list(void) return; } - /* owned by someone else -- wait till we can get it */ + // owned by someone else -- wait till we can get it PR_Wait(cookie_lock_monitor, PR_INTERVAL_NO_TIMEOUT); } } +*/ +/* PRIVATE void net_unlock_cookie_list(void) { PR_EnterMonitor(cookie_lock_monitor); #ifdef DEBUG - /* make sure someone doesn't try to free a lock they don't own */ + // make sure someone doesn't try to free a lock they don't own PR_ASSERT(cookie_lock_owner == PR_CurrentThread()); #endif @@ -1125,7 +1132,9 @@ net_unlock_cookie_list(void) PR_ExitMonitor(cookie_lock_monitor); } +*/ +/* #if defined(CookieManagement) static PRMonitor * defer_cookie_lock_monitor = NULL; static PRThread * defer_cookie_lock_owner = NULL; @@ -1142,7 +1151,7 @@ net_lock_defer_cookie_list(void) while(TRUE) { - /* no current owner or owned by this thread */ + // no current owner or owned by this thread PRThread * t = PR_CurrentThread(); if(defer_cookie_lock_owner == NULL || defer_cookie_lock_owner == t) { defer_cookie_lock_owner = t; @@ -1152,19 +1161,20 @@ net_lock_defer_cookie_list(void) return; } - /* owned by someone else -- wait till we can get it */ + // owned by someone else -- wait till we can get it PR_Wait(defer_cookie_lock_monitor, PR_INTERVAL_NO_TIMEOUT); } } - +*/ +/* PRIVATE void net_unlock_defer_cookie_list(void) { PR_EnterMonitor(defer_cookie_lock_monitor); #ifdef DEBUG - /* make sure someone doesn't try to free a lock they don't own */ + // make sure someone doesn't try to free a lock they don't own PR_ASSERT(defer_cookie_lock_owner == PR_CurrentThread()); #endif @@ -1177,7 +1187,9 @@ net_unlock_defer_cookie_list(void) PR_ExitMonitor(defer_cookie_lock_monitor); } +*/ +/* static PRMonitor * cookie_permission_lock_monitor = NULL; static PRThread * cookie_permission_lock_owner = NULL; static int cookie_permission_lock_count = 0; @@ -1193,7 +1205,7 @@ net_lock_cookie_permission_list(void) while(TRUE) { - /* no current owner or owned by this thread */ + // no current owner or owned by this thread PRThread * t = PR_CurrentThread(); if(cookie_permission_lock_owner == NULL || cookie_permission_lock_owner == t) { cookie_permission_lock_owner = t; @@ -1203,19 +1215,21 @@ net_lock_cookie_permission_list(void) return; } - /* owned by someone else -- wait till we can get it */ + // owned by someone else -- wait till we can get it PR_Wait(cookie_permission_lock_monitor, PR_INTERVAL_NO_TIMEOUT); } } +*/ +/* PRIVATE void net_unlock_cookie_permission_list(void) { PR_EnterMonitor(cookie_permission_lock_monitor); #ifdef DEBUG - /* make sure someone doesn't try to free a lock they don't own */ + // make sure someone doesn't try to free a lock they don't own PR_ASSERT(cookie_permission_lock_owner == PR_CurrentThread()); #endif @@ -1228,7 +1242,9 @@ net_unlock_cookie_permission_list(void) PR_ExitMonitor(cookie_permission_lock_monitor); } +*/ +/* PRIVATE int net_SaveCookiePermissions(char * filename); @@ -1237,10 +1253,9 @@ net_FreeCookiePermission (net_CookiePermissionStruct * cookie_permission, Bool save) { - /* - * This routine should only be called while holding the - * cookie permission list lock - */ + // This routine should only be called while holding the + // cookie permission list lock + if(!cookie_permission) { return; @@ -1249,7 +1264,7 @@ net_FreeCookiePermission PR_FREEIF(cookie_permission->host); #ifdef TRUST_LABELS - /* free the entries on the trust list */ + // free the entries on the trust list if ( cookie_permission->TrustList ) { TrustEntry * TEntry; XP_List *Tptr = cookie_permission->TrustList; @@ -1257,7 +1272,7 @@ net_FreeCookiePermission PR_FREEIF(TEntry->CookieName); PR_FREEIF(TEntry->by); PR_FREEIF(TEntry->CookieSet); - /* before removing the current entry get the ptr to the next one */ + // before removing the current entry get the ptr to the next one Tptr = Tptr->prev; XP_ListRemoveObject(cookie_permission->TrustList, TEntry); } @@ -1271,15 +1286,16 @@ net_FreeCookiePermission net_SaveCookiePermissions(NULL); } } - +*/ /* blows away all cookie permissions currently in the list */ +/* PRIVATE void net_RemoveAllCookiePermissions() { net_CookiePermissionStruct * victim; XP_List * cookiePermissionList; - /* check for NULL or empty list */ + // check for NULL or empty list net_lock_cookie_permission_list(); cookiePermissionList = net_cookie_permission_list; @@ -1298,11 +1314,12 @@ net_RemoveAllCookiePermissions() net_unlock_cookie_permission_list(); } #endif - +*/ /* This should only get called while holding the cookie-lock ** */ +/* PRIVATE void net_FreeCookie(net_CookieStruct * cookie) { @@ -1310,10 +1327,9 @@ net_FreeCookie(net_CookieStruct * cookie) if(!cookie) return; #ifdef TRUST_LABELS - /* - * delete the reference to the cookie in the cookie permission list - * which contains the trust label for the cookie - */ + // delete the reference to the cookie in the cookie permission list + //which contains the trust label for the cookie + DeleteCookieFromPermissions(cookie->host, cookie->name ); #endif XP_ListRemoveObject(net_cookie_list, cookie); @@ -1327,8 +1343,8 @@ net_FreeCookie(net_CookieStruct * cookie) cookies_changed = TRUE; } - - +*/ +/* PUBLIC void NET_DeleteCookie(char* cookieURL) { @@ -1353,18 +1369,19 @@ NET_DeleteCookie(char* cookieURL) PR_FREEIF(cookieURL2); net_unlock_cookie_list(); } - +*/ /* blows away all cookies currently in the list, then blows away the list itself * nulling it after it's free'd */ +/* PRIVATE void net_RemoveAllCookies() { net_CookieStruct * victim; XP_List * cookieList; - /* check for NULL or empty list */ + // check for NULL or empty list net_lock_cookie_list(); cookieList = net_cookie_list; if(XP_ListIsEmpty(cookieList)) { @@ -1380,7 +1397,9 @@ net_RemoveAllCookies() net_cookie_list = NULL; net_unlock_cookie_list(); } +*/ +/* PUBLIC void NET_RemoveAllCookies() { @@ -1421,10 +1440,12 @@ net_remove_oldest_cookie(void) } net_unlock_cookie_list(); } +*/ /* Remove any expired cookies from memory ** This routine should only be called while holding the cookie list lock */ +/* PRIVATE void net_remove_expired_cookies(void) { @@ -1437,21 +1458,23 @@ net_remove_expired_cookies(void) while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) { - /* Don't get rid of expire time 0 because these need to last for - * the entire session. They'll get cleared on exit. - */ + // Don't get rid of expire time 0 because these need to last for + // the entire session. They'll get cleared on exit. + // if( cookie_s->expires && (cookie_s->expires < cur_time) ) { net_FreeCookie(cookie_s); - /* Reset the list_ptr to the beginning of the list. - * Do this because list_ptr's object was just freed - * by the call to net_FreeCookie struct, even - * though it's inefficient. - */ + // Reset the list_ptr to the beginning of the list. + // Do this because list_ptr's object was just freed + // by the call to net_FreeCookie struct, even + // though it's inefficient. + list_ptr = net_cookie_list; } } } +*/ +/* PRIVATE XP_List * net_dormant_cookie_list=0; Bool net_anonymous = FALSE; @@ -1467,6 +1490,8 @@ NET_AnonymizeCookies() } } + + PUBLIC void NET_UnanonymizeCookies() { @@ -1479,26 +1504,17 @@ NET_UnanonymizeCookies() net_anonymous = FALSE; } } - +*/ /* * Determine whether or not to suppress the referer field for anonymity. * The first time this function is called on behalf of a given window * after a mode change (into or out of anonymous mode), the returned value is * true. */ + PUBLIC Bool NET_SupressRefererForAnonymity(MWContext *window_id) { - MWContext *outermost_window = window_id; - Bool result; - if (!window_id) { - return FALSE; - } - while (outermost_window->grid_parent) { - outermost_window = outermost_window->grid_parent; - } - result = (window_id->anonymous != net_anonymous); - window_id->anonymous = net_anonymous; - return result; + return FALSE; } /* checks to see if the maximum number of cookies per host @@ -1506,6 +1522,7 @@ NET_SupressRefererForAnonymity(MWContext *window_id) { * case * This routine should only be called while holding the cookie lock */ +/* PRIVATE void net_CheckForMaxCookiesFromHost(const char * cur_host) { @@ -1534,11 +1551,12 @@ net_CheckForMaxCookiesFromHost(const char * cur_host) net_FreeCookie(oldest_cookie); } } - +*/ /* search for previous exact match ** This routine should only be called while holding the cookie lock */ +/* PRIVATE net_CookieStruct * net_CheckForPrevCookie(char * path, char * hostname, @@ -1557,8 +1575,9 @@ net_CheckForPrevCookie(char * path, } return(NULL); } - +*/ /* cookie utility functions */ +/* PRIVATE void NET_SetCookieBehaviorPref(NET_CookieBehaviorEnum x) { @@ -1572,7 +1591,8 @@ NET_SetCookieBehaviorPref(NET_CookieBehaviorEnum x) #endif } } - +*/ +/* PRIVATE void NET_SetCookieWarningPref(Bool x) { @@ -1639,18 +1659,18 @@ NET_CookieScriptPrefChanged(const char * newpref, void * data) NET_SetCookieScriptPref(s); return PREF_NOERROR; } - +*/ +/* #if defined(CookieManagement) -/* - * search if permission already exists - */ + // search if permission already exists + PRIVATE net_CookiePermissionStruct * net_CheckForCookiePermission(char * hostname) { XP_List * list_ptr; net_CookiePermissionStruct * cookie_s; - /* ignore leading period in host name */ + // ignore leading period in host name while (hostname && (*hostname == '.')) { hostname++; } @@ -1667,6 +1687,7 @@ net_CheckForCookiePermission(char * hostname) { net_unlock_cookie_permission_list(); return(NULL); } +*/ /* * return: @@ -1674,6 +1695,7 @@ net_CheckForCookiePermission(char * hostname) { * 0 if cookie permission does not exist for host * -1 if cookie permission exists for host and indicates host can't set cookies */ +/* PUBLIC int NET_CookiePermission(char* URLName) { net_CookiePermissionStruct * cookiePermission; @@ -1684,10 +1706,10 @@ NET_CookiePermission(char* URLName) { return 0; } - /* remove protocol from URL name */ + // remove protocol from URL name host = NET_ParseURL(URLName, GET_HOST_PART); - /* remove port number from URL name */ + // remove port number from URL name colon = PL_strchr(host, ':'); if(colon) { *colon = '\0'; @@ -1707,9 +1729,10 @@ NET_CookiePermission(char* URLName) { } #endif - +*/ /* called from mkgeturl.c, NET_InitNetLib(). This sets the module local cookie pref variables and registers the callbacks */ +/* PUBLIC void NET_RegisterCookiePrefCallbacks(void) { @@ -1736,13 +1759,14 @@ NET_RegisterCookiePrefCallbacks(void) NET_SetCookieScriptPref(s); PREF_RegisterCallback(pref_scriptName, NET_CookieScriptPrefChanged, NULL); } - +*/ /* returns TRUE if authorization is required ** ** ** IMPORTANT: Now that this routine is mutli-threaded it is up ** to the caller to free any returned string */ +/* PUBLIC char * NET_GetCookie(MWContext * context, char * address) { @@ -1757,18 +1781,18 @@ NET_GetCookie(MWContext * context, char * address) int host_length; int domain_length; - /* return string to build */ + // return string to build char * rv=0; - /* disable cookie's if the user's prefs say so - */ + // disable cookie's if the user's prefs say so + if(NET_GetCookieBehaviorPref() == NET_DontUse) return NULL; HG98476 - /* search for all cookies - */ + // search for all cookies + net_lock_cookie_list(); list_ptr = net_cookie_list; while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) @@ -1776,19 +1800,19 @@ NET_GetCookie(MWContext * context, char * address) if(!cookie_s->host) continue; - /* check the host or domain first - */ + // check the host or domain first + if(cookie_s->is_domain) { char *cp; domain_length = PL_strlen(cookie_s->host); - /* calculate the host length by looking at all characters up to - * a colon or '\0'. That way we won't include port numbers - * in domains - */ + // calculate the host length by looking at all characters up to + // a colon or '\0'. That way we won't include port numbers + //in domains + for(cp=host; *cp != '\0' && *cp != ':'; cp++) - ; /* null body */ + ; // null body host_length = cp - host; if(domain_length > host_length @@ -1797,47 +1821,47 @@ NET_GetCookie(MWContext * context, char * address) domain_length)) { HG20476 - /* no match. FAIL - */ + //no match. FAIL + continue; } } else if(PL_strcasecmp(host, cookie_s->host)) { - /* hostname matchup failed. FAIL - */ + //hostname matchup failed. FAIL + continue; } - /* shorter strings always come last so there can be no - * ambiquity - */ + // shorter strings always come last so there can be no + // ambiquity + if(cookie_s->path && !PL_strncmp(path, cookie_s->path, PL_strlen(cookie_s->path))) { - /* if the cookie is secure and the path isn't - * dont send it - */ + // if the cookie is secure and the path isn't + // dont send it + HG83764 - /* check for expired cookies - */ + // check for expired cookies + // if( cookie_s->expires && (cookie_s->expires < cur_time) ) { - /* expire and remove the cookie - */ + //expire and remove the cookie + net_FreeCookie(cookie_s); - /* start the list parsing over :( - * we must also start the string over - */ + // start the list parsing over :( + //we must also start the string over + PR_FREEIF(rv); rv = NULL; list_ptr = net_cookie_list; - first = TRUE; /* reset first */ + first = TRUE; // reset first continue; } @@ -1853,9 +1877,9 @@ NET_GetCookie(MWContext * context, char * address) StrAllocCat(name, "="); #ifdef PREVENT_DUPLICATE_NAMES - /* make sure we don't have a previous - * name mapping already in the string - */ + // make sure we don't have a previous + // name mapping already in the string + // if(!rv || !PL_strstr(rv, name)) { StrAllocCat(rv, name); @@ -1864,7 +1888,7 @@ NET_GetCookie(MWContext * context, char * address) #else StrAllocCat(rv, name); StrAllocCat(rv, cookie_s->cookie); -#endif /* PREVENT_DUPLICATE_NAMES */ +#endif // PREVENT_DUPLICATE_NAMES } else { @@ -1874,19 +1898,19 @@ NET_GetCookie(MWContext * context, char * address) } #if defined(MOZ_BRPROF) - /* - * Okay, this is a horrible hack. It looks for a URL with - * 'iiop/BRPROF' in it (our little browsing profile reader), and - * if it finds it, it uploads the browsing profile cookie. - * - * The _real_ way to do this would be to - * - * 1) See if the user has enabled the preference to even allow us - * to send out the cookie to _anyone_. - * - * 2) See if the specific site has asked for and received - * permission to be sent the cookie. - */ + + // Okay, this is a horrible hack. It looks for a URL with + // 'iiop/BRPROF' in it (our little browsing profile reader), and + //if it finds it, it uploads the browsing profile cookie. + // + // The _real_ way to do this would be to + // + // 1) See if the user has enabled the preference to even allow us + // to send out the cookie to _anyone_. + // + // 2) See if the specific site has asked for and received + // permission to be sent the cookie. + // if (PL_strstr(address, "iiop/BRPROF")) { extern PRBool BP_GetProfile(char* *aProfileCookie); char* profile; @@ -1905,19 +1929,19 @@ NET_GetCookie(MWContext * context, char * address) PR_Free(path); PR_Free(host); - /* may be NULL */ + // may be NULL return(rv); } - +*/ +/* #if defined(CookieManagement) void net_AddCookiePermission (net_CookiePermissionStruct * cookie_permission, Bool save ) { - /* - * This routine should only be called while holding the - * cookie permission list lock - */ + // This routine should only be called while holding the + // cookie permission list lock + // if (cookie_permission) { XP_List * list_ptr = net_cookie_permission_list; if(!net_cookie_permission_list) { @@ -1931,7 +1955,7 @@ net_AddCookiePermission } #ifdef alphabetize - /* add it to the list in alphabetical order */ + // add it to the list in alphabetical order { net_CookiePermissionStruct * tmp_cookie_permission; Bool permissionAdded = FALSE; @@ -1953,7 +1977,7 @@ net_AddCookiePermission } } #else - /* add it to the end of the list */ + // add it to the end of the list XP_ListAddObjectToEnd (net_cookie_permission_list, cookie_permission); #endif @@ -1963,7 +1987,9 @@ net_AddCookiePermission } } } +*/ +/* MODULE_PRIVATE PRBool net_CookieIsFromHost(net_CookieStruct *cookie_s, char *host) { if (!cookie_s || !(cookie_s->host)) { @@ -1975,16 +2001,16 @@ net_CookieIsFromHost(net_CookieStruct *cookie_s, char *host) { domain_length = PL_strlen(cookie_s->host); - /* calculate the host length by looking at all characters up to - * a colon or '\0'. That way we won't include port numbers - * in domains - */ + // calculate the host length by looking at all characters up to + // a colon or '\0'. That way we won't include port numbers + // in domains + // for(cp=host; *cp != '\0' && *cp != ':'; cp++) { - ; /* null body */ + ; // null body } host_length = cp - host; - /* compare the tail end of host to cook_s->host */ + // compare the tail end of host to cook_s->host return (domain_length <= host_length && PL_strncasecmp(cookie_s->host, &host[host_length - domain_length], @@ -1993,8 +2019,10 @@ net_CookieIsFromHost(net_CookieStruct *cookie_s, char *host) { return PL_strcasecmp(host, cookie_s->host) == 0; } } +*/ /* find out how many cookies this host has already set */ +/* PRIVATE int net_CookieCount(char * host) { int count = 0; @@ -2012,7 +2040,8 @@ net_CookieCount(char * host) { return count; } - +*/ +/* PUBLIC int NET_CookieCount(char * URLName) { char * host; @@ -2023,26 +2052,27 @@ NET_CookieCount(char * URLName) { return 0; } - /* remove protocol from URL name */ + // remove protocol from URL name host = NET_ParseURL(URLName, GET_HOST_PART); - /* remove port number from URL name */ + // remove port number from URL name colon = PL_strchr(host, ':'); if(colon) { *colon = '\0'; } - /* get count */ + // get count count = net_CookieCount(host); - /* free up allocated string and return */ + // free up allocated string and return if(colon) { *colon = ':'; } PR_Free(host); return count; } - +*/ +/* PRBool net_IntSetCookieStringInUse = FALSE; PRIVATE void @@ -2070,7 +2100,8 @@ net_DeferCookie( XP_ListAddObject(net_defer_cookie_list, defer_cookie); net_unlock_defer_cookie_list(); } - +*/ +/* PRIVATE void net_IntSetCookieString(MWContext * context, char * cur_url, @@ -2097,11 +2128,11 @@ net_UndeferCookies() { PR_Free(defer_cookie); } #endif - +*/ /* Java script is calling NET_SetCookieString, netlib is calling ** this via NET_SetCookieStringFromHttp. */ - +/* PRIVATE void net_IntSetCookieString(MWContext * context, char * cur_url, @@ -2127,9 +2158,9 @@ net_IntSetCookieString(MWContext * context, return; } - /* Only allow cookies to be set in the listed contexts. We - * don't want cookies being set in html mail. - */ + // Only allow cookies to be set in the listed contexts. We + // don't want cookies being set in html mail. + type = context->type; if(!( (type == MWContextBrowser) || (type == MWContextHTMLHelp) @@ -2146,10 +2177,10 @@ net_IntSetCookieString(MWContext * context, } #if defined(CookieManagement) - /* Don't enter this routine if it is already in use by another - thread. Otherwise the "remember this decision" result of the - other cookie (which came first) won't get applied to this cookie. - */ + // Don't enter this routine if it is already in use by another + // thread. Otherwise the "remember this decision" result of the + // other cookie (which came first) won't get applied to this cookie. + if (net_IntSetCookieStringInUse) { PR_Free(cur_path); PR_Free(cur_host); @@ -2160,37 +2191,37 @@ net_IntSetCookieString(MWContext * context, #endif HG87358 - /* terminate at any carriage return or linefeed */ + // terminate at any carriage return or linefeed for(ptr=set_cookie_header; *ptr; ptr++) if(*ptr == LF || *ptr == CR) { *ptr = '\0'; break; } - /* parse path and expires attributes from header if - * present - */ + // parse path and expires attributes from header if + //present + // semi_colon = PL_strchr(set_cookie_header, ';'); if(semi_colon) { - /* truncate at semi-colon and advance - */ + // truncate at semi-colon and advance + // *semi_colon++ = '\0'; - /* there must be some attributes. (hopefully) - */ + // there must be some attributes. (hopefully) + // HG83476 - /* look for the path attribute - */ + // look for the path attribute + // ptr = PL_strcasestr(semi_colon, "path="); if(ptr) { - /* allocate more than we need */ + // allocate more than we need StrAllocCopy(path_from_header, XP_StripLine(ptr+5)); - /* terminate at first space or semi-colon - */ + // terminate at first space or semi-colon + // for(ptr=path_from_header; *ptr != '\0'; ptr++) if(NET_IS_SPACE(*ptr) || *ptr == ';' || *ptr == ',') { *ptr = '\0'; @@ -2198,13 +2229,13 @@ net_IntSetCookieString(MWContext * context, } } - /* look for the URI or URL attribute - * - * This might be a security hole so I'm removing - * it for now. - */ + // look for the URI or URL attribute + + // This might be a security hole so I'm removing + // it for now. + - /* look for a domain */ + // look for a domain ptr = PL_strcasestr(semi_colon, "domain="); if(ptr) { @@ -2212,34 +2243,34 @@ net_IntSetCookieString(MWContext * context, char *dot, *colon; int domain_length, cur_host_length; - /* allocate more than we need */ + // allocate more than we need StrAllocCopy(domain_from_header, XP_StripLine(ptr+7)); - /* terminate at first space or semi-colon - */ + // terminate at first space or semi-colon + // for(ptr=domain_from_header; *ptr != '\0'; ptr++) if(NET_IS_SPACE(*ptr) || *ptr == ';' || *ptr == ',') { *ptr = '\0'; break; } - /* verify that this host has the authority to set for - * this domain. We do this by making sure that the - * host is in the domain - * We also require that a domain have at least two - * periods to prevent domains of the form ".com" - * and ".edu" - * - * Also make sure that there is more stuff after - * the second dot to prevent ".com." - */ + // verify that this host has the authority to set for + // this domain. We do this by making sure that the + // host is in the domain + // We also require that a domain have at least two + // periods to prevent domains of the form ".com" + // and ".edu" + // + // Also make sure that there is more stuff after + // the second dot to prevent ".com." + dot = PL_strchr(domain_from_header, '.'); if(dot) dot = PL_strchr(dot+1, '.'); if(!dot || *(dot+1) == '\0') { - /* did not pass two dot test. FAIL - */ + // did not pass two dot test. FAIL + PR_Free(domain_from_header); PR_Free(cur_path); PR_Free(cur_host); @@ -2251,9 +2282,9 @@ net_IntSetCookieString(MWContext * context, return; } - /* strip port numbers from the current host - * for the domain test - */ + // strip port numbers from the current host + // for the domain test + colon = PL_strchr(cur_host, ':'); if(colon) *colon = '\0'; @@ -2261,8 +2292,8 @@ net_IntSetCookieString(MWContext * context, domain_length = PL_strlen(domain_from_header); cur_host_length = PL_strlen(cur_host); - /* check to see if the host is in the domain - */ + // check to see if the host is in the domain + // if(domain_length > cur_host_length || PL_strcasecmp(domain_from_header, &cur_host[cur_host_length-domain_length])) @@ -2279,15 +2310,15 @@ net_IntSetCookieString(MWContext * context, return; } -/* - * check that portion of host not in domain does not contain a dot - * This satisfies the fourth requirement in section 4.3.2 of the cookie - * spec rfc 2109 (see www.cis.ohio-state.edu/htbin/rfc/rfc2109.html). - * It prevents host of the form x.y.co.nz from setting cookies in the - * entire .co.nz domain. Note that this doesn't really solve the problem, - * it justs makes it more unlikely. Sites such as y.co.nz can still set - * cookies for the entire .co.nz domain. - */ + + // check that portion of host not in domain does not contain a dot + // This satisfies the fourth requirement in section 4.3.2 of the cookie + // spec rfc 2109 (see www.cis.ohio-state.edu/htbin/rfc/rfc2109.html). + // It prevents host of the form x.y.co.nz from setting cookies in the + // entire .co.nz domain. Note that this doesn't really solve the problem, + // it justs makes it more unlikely. Sites such as y.co.nz can still set + // cookies for the entire .co.nz domain. + // cur_host[cur_host_length-domain_length] = '\0'; dot = XP_STRCHR(cur_host, '.'); @@ -2305,8 +2336,8 @@ net_IntSetCookieString(MWContext * context, return; } - /* all tests passed, copy in domain to hostname field - */ + // all tests passed, copy in domain to hostname field + StrAllocCopy(host_from_header, domain_from_header); is_domain = TRUE; @@ -2315,16 +2346,16 @@ net_IntSetCookieString(MWContext * context, PR_Free(domain_from_header); } - /* now search for the expires header - * NOTE: that this part of the parsing - * destroys the original part of the string - */ + // now search for the expires header + // NOTE: that this part of the parsing + // destroys the original part of the string + // ptr = PL_strcasestr(semi_colon, "expires="); if(ptr) { char *date = ptr+8; - /* terminate the string at the next semi-colon - */ + // terminate the string at the next semi-colon + for(ptr=date; *ptr != '\0'; ptr++) if(*ptr == ';') { *ptr = '\0'; @@ -2340,9 +2371,9 @@ net_IntSetCookieString(MWContext * context, } if(!path_from_header) { - /* strip down everything after the last slash - * to get the path. - */ + // strip down everything after the last slash + // to get the path. + char * slash = PL_strrchr(cur_path, '/'); if(slash) *slash = '\0'; @@ -2357,11 +2388,11 @@ net_IntSetCookieString(MWContext * context, else PR_Free(cur_host); - /* keep cookies under the max bytes limit */ + // keep cookies under the max bytes limit if(PL_strlen(set_cookie_header) > MAX_BYTES_PER_COOKIE) set_cookie_header[MAX_BYTES_PER_COOKIE-1] = '\0'; - /* separate the name from the cookie */ + // separate the name from the cookie equal = PL_strchr(set_cookie_header, '='); if(equal) { @@ -2374,7 +2405,7 @@ net_IntSetCookieString(MWContext * context, StrAllocCopy(name_from_header, ""); } - /* If there's a script, call it now */ + // If there's a script, call it now script_name = NET_GetCookieScriptPref(); if( (const char *)0 != script_name ) { JSCFCookieData *cd; @@ -2387,8 +2418,8 @@ net_IntSetCookieString(MWContext * context, PR_FREEIF(host_from_header); PR_FREEIF(name_from_header); PR_FREEIF(cookie_from_header); - /* FREEIF(cur_path); */ - /* FREEIF(cur_host); */ + // FREEIF(cur_path); + // FREEIF(cur_host); #if defined(CookieManagement) net_IntSetCookieStringInUse = FALSE; net_UndeferCookies(); @@ -2407,12 +2438,11 @@ net_IntSetCookieString(MWContext * context, cd->prompt = NET_GetCookieWarningPref(); cd->preference = NET_GetCookieBehaviorPref(); - /* - * This is only safe to do from the mozilla thread - * since it might do file I/O and uses the preferences - * global context + objects. - */ - /* XXX: This is probably not correct, but it will fix the build for now... */ + //This is only safe to do from the mozilla thread + // since it might do file I/O and uses the preferences + // global context + objects. + // + // XXX: This is probably not correct, but it will fix the build for now... result= JSCF_Execute(context, script_name, cd, &changed); if( result != JSCF_error) { if( changed ) { @@ -2435,7 +2465,7 @@ net_IntSetCookieString(MWContext * context, if( cd->expires != expires ) expires = cd->expires; if( cd->domain != is_domain ) - /* lets hope the luser remembered to change the domain field */ + //lets hope the luser remembered to change the domain field is_domain = cd->domain; HG27398 } @@ -2446,8 +2476,8 @@ net_IntSetCookieString(MWContext * context, PR_FREEIF(name_from_header); PR_FREEIF(cookie_from_header); PR_Free(cd); - /* FREEIF(cur_path); */ - /* FREEIF(cur_host); */ + // FREEIF(cur_path); + // FREEIF(cur_host); #if defined(CookieManagement) net_IntSetCookieStringInUse = FALSE; net_UndeferCookies(); @@ -2485,10 +2515,10 @@ net_IntSetCookieString(MWContext * context, if( (NET_GetCookieWarningPref() || ask) && !accept ) { - /* the user wants to know about cookies so let them - * know about every one that is set and give them - * the choice to accept it or not - */ + // the user wants to know about cookies so let them + // know about every one that is set and give them + //the choice to accept it or not + // char * new_string=0; #if defined(CookieManagement) int count; @@ -2496,7 +2526,7 @@ net_IntSetCookieString(MWContext * context, StrAllocCopy (remember_string, XP_GetString(MK_ACCESS_COOKIES_REMEMBER)); - /* find out how many cookies this host has already set */ + // find out how many cookies this host has already set count = net_CookieCount(host_from_header); net_lock_cookie_list(); prev_cookie = net_CheckForPrevCookie @@ -2549,10 +2579,10 @@ net_IntSetCookieString(MWContext * context, StrAllocCat(new_string, XP_GetString(MK_ACCESS_COOKIES_SET_IT)); #endif - /* - * Who knows what thread we are on. Only the mozilla thread - * is allowed to post dialogs so, if need be, go over there - */ + // + // Who knows what thread we are on. Only the mozilla thread + // is allowed to post dialogs so, if need be, go over there + // #if defined(CookieManagement) { @@ -2571,11 +2601,11 @@ net_IntSetCookieString(MWContext * context, if (cookie_permission) { net_lock_cookie_permission_list(); StrAllocCopy(host_from_header2, host_from_header); - /* ignore leading periods in host name */ + //ignore leading periods in host name while (host_from_header2 && (*host_from_header2 == '.')) { host_from_header2++; } - cookie_permission->host = host_from_header2; /* set host string */ + cookie_permission->host = host_from_header2; // set host string cookie_permission->permission = userHasAccepted; #ifdef TRUST_LABELS cookie_permission->TrustList = NULL; @@ -2611,13 +2641,12 @@ net_IntSetCookieString(MWContext * context, TRACEMSG(("mkaccess.c: Setting cookie: %s for host: %s for path: %s", cookie_from_header, host_from_header, path_from_header)); - /* - * We have decided we are going to insert a cookie into the list - * Get the cookie lock so that we can munge on the list - */ + // We have decided we are going to insert a cookie into the list + // Get the cookie lock so that we can munge on the list + // net_lock_cookie_list(); - /* limit the number of cookies from a specific host or domain */ + // limit the number of cookies from a specific host or domain net_CheckForMaxCookiesFromHost(host_from_header); if(XP_ListCount(net_cookie_list) > MAX_NUMBER_OF_COOKIES-1) @@ -2645,8 +2674,8 @@ net_IntSetCookieString(MWContext * context, net_CookieStruct * tmp_cookie_ptr; size_t new_len; - /* construct a new cookie_struct - */ + // construct a new cookie_struct + // prev_cookie = PR_NEW(net_CookieStruct); if(!prev_cookie) { PR_FREEIF(path_from_header); @@ -2661,8 +2690,8 @@ net_IntSetCookieString(MWContext * context, return; } - /* copy - */ + //copy + // prev_cookie->cookie = cookie_from_header; prev_cookie->name = name_from_header; prev_cookie->path = path_from_header; @@ -2689,9 +2718,9 @@ net_IntSetCookieString(MWContext * context, } } - /* add it to the list so that it is before any strings of - * smaller length - */ + // add it to the list so that it is before any strings of + // smaller length + // bCookieAdded = FALSE; new_len = PL_strlen(prev_cookie->path); while((tmp_cookie_ptr = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) { @@ -2702,34 +2731,32 @@ net_IntSetCookieString(MWContext * context, } } if ( !bCookieAdded ) { - /* no shorter strings found in list */ + // no shorter strings found in list XP_ListAddObjectToEnd(net_cookie_list, prev_cookie); } } - /* At this point we know a cookie has changed. Write the cookies to file. */ + //At this point we know a cookie has changed. Write the cookies to file. cookies_changed = TRUE; NET_SaveCookies(NULL); net_unlock_cookie_list(); #ifdef TRUST_LABELS { TrustLabel *trustlabel; - /* - * At this point the cookie was added to - * the cookie list. So see if there is a trust label that - * matches the cookie and if so add the trust label to the - * cookie permission list. Existing trust label entries in - * the permission list replaced with this latest entry. - */ + // At this point the cookie was added to + // the cookie list. So see if there is a trust label that + // matches the cookie and if so add the trust label to the + // cookie permission list. Existing trust label entries in + // the permission list replaced with this latest entry. + // if ( MatchCookieToLabel2( cur_url, prev_cookie->name, prev_cookie->path, prev_cookie->host, &trustlabel ) ) { - /* - * found a match - add the trust info to the proper - * entry in the cookie permission list - */ + // found a match - add the trust info to the proper + // entry in the cookie permission list + // AddTrustLabelInfo( prev_cookie->name, trustlabel ); - /* update the disk file */ + // update the disk file // cookie_permissions_changed = TRUE; net_SaveCookiePermissions(NULL); } @@ -2741,21 +2768,27 @@ net_IntSetCookieString(MWContext * context, #endif return; } +*/ +/* PUBLIC void NET_SetCookieString(MWContext * context, char * cur_url, char * set_cookie_header) { net_IntSetCookieString(context, cur_url, set_cookie_header, 0); } +*/ /* Determines whether the inlineHost is in the same domain as the currentHost. For use with rfc 2109 * compliance/non-compliance. */ +/* #ifdef TRUST_LABELS PUBLIC int #else PRIVATE int #endif +*/ +/* NET_SameDomain(char * currentHost, char * inlineHost) { char * dot = 0; @@ -2765,7 +2798,7 @@ NET_SameDomain(char * currentHost, char * inlineHost) if(!currentHost || !inlineHost) return 0; - /* case insensitive compare */ + // case insensitive compare if(PL_strcasecmp(currentHost, inlineHost) == 0) return 1; @@ -2775,16 +2808,16 @@ NET_SameDomain(char * currentHost, char * inlineHost) if(!currentDomain || !inlineDomain) return 0; - /* check for at least two dots before continuing, if there are - not two dots we don't have enough information to determine - whether or not the inlineDomain is within the currentDomain */ + // check for at least two dots before continuing, if there are + // not two dots we don't have enough information to determine + // whether or not the inlineDomain is within the currentDomain dot = PL_strchr(inlineDomain, '.'); if(dot) dot = PL_strchr(dot+1, '.'); else return 0; - /* handle .com. case */ + // handle .com. case if(!dot || (*(dot+1) == '\0') ) return 0; @@ -2792,7 +2825,7 @@ NET_SameDomain(char * currentHost, char * inlineHost) return 1; return 0; } - +*/ /* This function wrapper wraps NET_SetCookieString for the purposes of ** determining whether or not a cookie is inline (we need the URL struct, ** and outputFormat to do so). this is called from NET_ParseMimeHeaders @@ -2800,6 +2833,7 @@ NET_SameDomain(char * currentHost, char * inlineHost) ** This routine does not need to worry about the cookie lock since all of ** the work is handled by sub-routines */ +/* PUBLIC void NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, URL_Struct * URL_s, @@ -2807,11 +2841,11 @@ NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, char * cur_url, char * set_cookie_header) { - /* If the outputFormat is not PRESENT (the url is not going to the screen), and not - * SAVE AS (shift-click) then - * the cookie being set is defined as inline so we need to do what the user wants us - * to based on his preference to deal with foreign cookies. If it's not inline, just set - * the cookie. */ + // If the outputFormat is not PRESENT (the url is not going to the screen), and not + // SAVE AS (shift-click) then + // the cookie being set is defined as inline so we need to do what the user wants us + // to based on his preference to deal with foreign cookies. If it's not inline, just set + // the cookie. char *ptr=NULL, *date=NULL; time_t gmtCookieExpires=0, expires=0; @@ -2819,7 +2853,7 @@ NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, { if (NET_GetCookieBehaviorPref() == NET_DontAcceptForeign) { - /* the user doesn't want foreign cookies, check to see if its foreign */ + // the user doesn't want foreign cookies, check to see if its foreign char * curSessionHistHost = 0; char * theColon = 0; char * curHost = NET_ParseURL(cur_url, GET_HOST_PART); @@ -2834,7 +2868,7 @@ NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, return; } - /* strip ports */ + // strip ports theColon = PL_strchr(curHost, ':'); if(theColon) *theColon = '\0'; @@ -2842,7 +2876,7 @@ NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, if(theColon) *theColon = '\0'; - /* if it's foreign, get out of here after a little clean up */ + // if it's foreign, get out of here after a little clean up if(!NET_SameDomain(curHost, curSessionHistHost)) { PR_FREEIF(curHost); @@ -2854,12 +2888,12 @@ NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, } } - /* Determine when the cookie should expire. This is done by taking the difference between - the server time and the time the server wants the cookie to expire, and adding that - difference to the client time. This localizes the client time regardless of whether or - not the TZ environment variable was set on the client. */ + //Determine when the cookie should expire. This is done by taking the difference between + //the server time and the time the server wants the cookie to expire, and adding that + // difference to the client time. This localizes the client time regardless of whether or + // not the TZ environment variable was set on the client. - /* Get the time the cookie is supposed to expire according to the attribute*/ + // Get the time the cookie is supposed to expire according to the attribute ptr = PL_strcasestr(set_cookie_header, "expires="); if(ptr) { @@ -2884,20 +2918,22 @@ NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, else { gmtCookieExpires = expires - URL_s->server_date + time(NULL); - /* if overflow */ + // if overflow if( gmtCookieExpires < time(NULL) ) - gmtCookieExpires = (((unsigned) (~0) << 1) >> 1); /* max int */ + gmtCookieExpires = (((unsigned) (~0) << 1) >> 1); // max int } } net_IntSetCookieString(context, cur_url, set_cookie_header, gmtCookieExpires); } +*/ #if defined(CookieManagement) /* saves the HTTP cookies permissions to disk * the parameter passed in on entry is ignored * returns 0 on success -1 on failure. */ +/* PRIVATE int net_SaveCookiePermissions(char * filename) { @@ -2937,9 +2973,9 @@ net_SaveCookiePermissions(char * filename) return -1; } - /* format shall be: - * host \t permission - */ + // format shall be: + // host \t permission + // while((cookie_permission_s = (net_CookiePermissionStruct *) XP_ListNextObject(list_ptr)) != NULL) { len = NET_XP_FileWrite(cookie_permission_s->host, -1, fp); @@ -2958,7 +2994,7 @@ net_SaveCookiePermissions(char * filename) } #ifdef TRUST_LABELS - /* save the trust label information */ + // save the trust label information SaveTrustLabelData( cookie_permission_s, fp ); #endif len = NET_XP_FileWrite(LINEBREAK, -1, fp); @@ -2969,7 +3005,7 @@ net_SaveCookiePermissions(char * filename) } } - /* save current state of cookie nag-box's checkmark */ + // save current state of cookie nag-box's checkmark NET_XP_FileWrite("@@@@", -1, fp); NET_XP_FileWrite("\t", 1, fp); if (cookie_remember_checked) { @@ -2984,14 +3020,14 @@ net_SaveCookiePermissions(char * filename) net_unlock_cookie_permission_list(); return(0); } - +*/ /* reads the HTTP cookies permission from disk * the parameter passed in on entry is ignored * returns 0 on success -1 on failure. * */ -#define PERMISSION_LINE_BUFFER_SIZE 4096 - +//#define PERMISSION_LINE_BUFFER_SIZE 4096 +/* PRIVATE int net_ReadCookiePermissions(char * filename) { @@ -3005,10 +3041,10 @@ net_ReadCookiePermissions(char * filename) if(!(fp = NET_XP_FileOpen(filename, xpHTTPCookiePermission, XP_FILE_READ))) return(-1); - /* format is: - * host \t permission - * if this format isn't respected we move onto the next line in the file. - */ + // format is: + // host \t permission + // if this format isn't respected we move onto the next line in the file. + // net_lock_cookie_permission_list(); while(NET_XP_FileReadLine(buffer, PERMISSION_LINE_BUFFER_SIZE, fp)) { @@ -3016,37 +3052,35 @@ net_ReadCookiePermissions(char * filename) continue; } - XP_StripLine(buffer); /* remove '\n' from end of the line */ + XP_StripLine(buffer); // remove '\n' from end of the line host = buffer; - /* isolate the host field which is the first field on the line */ + // isolate the host field which is the first field on the line if( !(p = PL_strchr(host, '\t')) ) { - continue; /* no permission field */ + continue; /* no permission field } *p++ = '\0'; if(*p == CR || *p == LF || *p == 0) { - continue; /* no permission field */ + continue; // no permission field } - /* ignore leading periods in host name */ + // ignore leading periods in host name while (host && (*host == '.')) { host++; } - /* - * the first part of the permission file is valid - - * allocate a new permission struct and fill it in - */ + // the first part of the permission file is valid - + // allocate a new permission struct and fill it in + // cookie_permission = PR_NEW(net_CookiePermissionStruct); if (cookie_permission) { host_from_header2 = PL_strdup(host); cookie_permission->host = host_from_header2; - /* - * Now handle the permission field. - * a host value of "@@@@" is a special code designating the - * state of the cookie nag-box's checkmark - */ + // Now handle the permission field. + // a host value of "@@@@" is a special code designating the + // state of the cookie nag-box's checkmark + // permission_value = (!PL_strncmp(p, "TRUE", sizeof("TRUE")-1)); if (!PL_strcmp(host, "@@@@")) { cookie_remember_checked = permission_value; @@ -3054,26 +3088,25 @@ net_ReadCookiePermissions(char * filename) cookie_permission->permission = permission_value; #ifdef TRUST_LABELS - /* - * pick up the trust label information from the line - * and add it to the permission struct - */ + // pick up the trust label information from the line + // and add it to the permission struct + // cookie_permission->TrustList = NULL; ParseTrustLabelInfo(p, cookie_permission); #endif - /* add the permission entry */ + // add the permission entry net_AddCookiePermission( cookie_permission, FALSE ); } - } /* end if (cookie_permission) */ - } /* while(NET_XP_FileReadLine( */ + } // end if (cookie_permission) + } // while(NET_XP_FileReadLine( net_unlock_cookie_permission_list(); NET_XP_FileClose(fp); cookie_permissions_changed = FALSE; return(0); } - +*/ #endif /* saves out the HTTP cookies to disk @@ -3083,6 +3116,8 @@ net_ReadCookiePermissions(char * filename) * returns 0 on success -1 on failure. * */ + +/* PUBLIC int NET_SaveCookies(char * filename) { @@ -3127,21 +3162,19 @@ NET_SaveCookies(char * filename) return -1; } - /* format shall be: - * - * host \t is_domain \t path \t secure \t expires \t name \t cookie - * - * is_domain is TRUE or FALSE - * secure is TRUE or FALSE - * expires is a time_t integer - * cookie can have tabs - */ + // format shall be: + // host \t is_domain \t path \t secure \t expires \t name \t cookie + //is_domain is TRUE or FALSE + // secure is TRUE or FALSE + // expires is a time_t integer + // cookie can have tabs + // while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr)) != NULL) { if(cookie_s->expires < cur_date) - continue; /* don't write entry if cookie has expired - * or has no expiration date - */ + continue; // don't write entry if cookie has expired + // or has no expiration date + // len = NET_XP_FileWrite(cookie_s->host, -1, fp); if (len < 0) @@ -3188,13 +3221,14 @@ NET_SaveCookies(char * filename) net_unlock_cookie_list(); return(0); } - +*/ /* This isn't needed any more */ +/* PRIVATE void NET_InitRDFCookieResources (void) { } - +*/ /* reads HTTP cookies from disk * * on entry pass in the name of the file to read @@ -3203,8 +3237,8 @@ NET_InitRDFCookieResources (void) * * */ -#define LINE_BUFFER_SIZE 4096 - +//#define LINE_BUFFER_SIZE 4096 +/* PUBLIC int NET_ReadCookies(char * filename) { @@ -3226,16 +3260,16 @@ NET_ReadCookies(char * filename) net_lock_cookie_list(); list_ptr = net_cookie_list; - /* format is: - * - * host \t is_domain \t path \t xxx \t expires \t name \t cookie - * - * if this format isn't respected we move onto the next line in the file. - * is_domain is TRUE or FALSE -- defaulting to FALSE - * xxx is TRUE or FALSE -- should default to TRUE - * expires is a time_t integer - * cookie can have tabs - */ + // format is: + // + // host \t is_domain \t path \t xxx \t expires \t name \t cookie + // + // if this format isn't respected we move onto the next line in the file. + // is_domain is TRUE or FALSE -- defaulting to FALSE + // xxx is TRUE or FALSE -- should default to TRUE + // expires is a time_t integer + // cookie can have tabs + // while(NET_XP_FileReadLine(buffer, LINE_BUFFER_SIZE, fp)) { added_to_list = FALSE; @@ -3281,11 +3315,11 @@ NET_ReadCookies(char * filename) if(*cookie == CR || *cookie == LF || *cookie == 0) continue; - /* remove the '\n' from the end of the cookie */ + // remove the '\n' from the end of the cookie XP_StripLine(cookie); - /* construct a new cookie_struct - */ + // construct a new cookie_struct + // new_cookie = PR_NEW(net_CookieStruct); if(!new_cookie) { @@ -3295,8 +3329,8 @@ NET_ReadCookies(char * filename) memset(new_cookie, 0, sizeof(net_CookieStruct)); - /* copy - */ + //copy + // StrAllocCopy(new_cookie->cookie, cookie); StrAllocCopy(new_cookie->name, name); StrAllocCopy(new_cookie->path, path); @@ -3320,9 +3354,9 @@ NET_ReadCookies(char * filename) } } - /* add it to the list so that it is before any strings of - * smaller length - */ + // add it to the list so that it is before any strings of + // smaller length + // new_len = PL_strlen(new_cookie->path); while((tmp_cookie_ptr = (net_CookieStruct *) XP_ListNextObject(list_ptr)) != NULL) { @@ -3334,7 +3368,7 @@ NET_ReadCookies(char * filename) } } - /* no shorter strings found in list */ + // no shorter strings found in list if(!added_to_list) XP_ListAddObjectToEnd(net_cookie_list, new_cookie); } @@ -3346,7 +3380,7 @@ NET_ReadCookies(char * filename) return(0); } - +*/ /* --- New stuff: General auth utils (currently used only by proxy auth) --- */ @@ -3853,12 +3887,12 @@ NET_AskForProxyAuth(MWContext * context, #if defined(CookieManagement) - +/* #include "htmldlgs.h" extern int XP_CERT_PAGE_STRINGS; extern int SA_REMOVE_BUTTON_LABEL; -/* return TRUE if "number" is in sequence of comma-separated numbers */ +// return TRUE if "number" is in sequence of comma-separated numbers Bool net_InSequence(char* sequence, int number) { char* ptr; char* endptr; @@ -3866,34 +3900,34 @@ Bool net_InSequence(char* sequence, int number) { Bool retval = FALSE; int i; - /* not necessary -- routine will work even with null sequence */ + // not necessary -- routine will work even with null sequence if (!*sequence) { return FALSE; } for (ptr = sequence ; ptr ; ptr = endptr) { - /* get to next comma */ + // get to next comma endptr = PL_strchr(ptr, ','); - /* if comma found, process it */ + // if comma found, process it if (endptr) { - /* restore last comma-to-null back to comma */ + // restore last comma-to-null back to comma if (undo) { *undo = ','; } - /* set the comma to a null */ + // set the comma to a null undo = endptr; *endptr++ = '\0'; - /* compare the number before the comma with "number" */ + // compare the number before the comma with "number" if (*ptr) { i = atoi(ptr); if (i == number) { - /* "number" was in the sequence so return TRUE */ + // "number" was in the sequence so return TRUE retval = TRUE; break; } @@ -3901,13 +3935,15 @@ Bool net_InSequence(char* sequence, int number) { } } - /* restore last comma-to-null back to comma */ + // restore last comma-to-null back to comma if (undo) { *undo = ','; } return retval; } +*/ +/* PR_STATIC_CALLBACK(PRBool) net_AboutCookiesDialogDone(XPDialogState* state, char** argv, int argc, unsigned int button) @@ -3924,24 +3960,23 @@ net_AboutCookiesDialogDone(XPDialogState* state, char** argv, int argc, buttonName = XP_FindValueInArgs("button", argv, argc); if (button != XP_DIALOG_OK_BUTTON) { - /* OK button not pressed (must be cancel button that was pressed) */ + // OK button not pressed (must be cancel button that was pressed) return PR_FALSE; } - /* OK was pressed, do the deletions */ + // OK was pressed, do the deletions - /* get the comma-separated sequence of cookies to be deleted */ + // get the comma-separated sequence of cookies to be deleted gone = XP_FindValueInArgs("goneC", argv, argc); PR_ASSERT(gone); if (!gone) { return PR_FALSE; } - /* - * walk through the cookie list, deleting the designated cookies - * Note: we can't delete cookie while "list" is pointing to it because - * that would destroy "list". So we do a lazy deletion - */ + // walk through the cookie list, deleting the designated cookies + // Note: we can't delete cookie while "list" is pointing to it because + // that would destroy "list". So we do a lazy deletion + // net_lock_cookie_list(); list = net_cookie_list; cookieNumber = 0; @@ -3962,18 +3997,17 @@ net_AboutCookiesDialogDone(XPDialogState* state, char** argv, int argc, } net_unlock_cookie_list(); - /* get the comma-separated sequence of permissions to be deleted */ + // get the comma-separated sequence of permissions to be deleted gone = XP_FindValueInArgs("goneP", argv, argc); PR_ASSERT(gone); if (!gone) { return PR_FALSE; } - /* - * walk through the cookie permission list, deleting the designated permissions - * Note: we can't delete permissions while "list" is pointing to it because - * that would destroy "list". So we do a lazy deletion - */ + // walk through the cookie permission list, deleting the designated permissions + // Note: we can't delete permissions while "list" is pointing to it because + // that would destroy "list". So we do a lazy deletion + // net_lock_cookie_permission_list(); list = net_cookie_permission_list; cookieNumber = 0; @@ -3996,13 +4030,15 @@ net_AboutCookiesDialogDone(XPDialogState* state, char** argv, int argc, net_unlock_cookie_permission_list(); return PR_FALSE; } +*/ +/* PRIVATE Bool CookieCompare (net_CookieStruct * cookie1, net_CookieStruct * cookie2) { char * host1 = cookie1->host; char * host2 = cookie2->host; - /* get rid of leading period on host name, if any */ + // get rid of leading period on host name, if any if (*host1 == '.') { host1++; } @@ -4010,7 +4046,7 @@ CookieCompare (net_CookieStruct * cookie1, net_CookieStruct * cookie2) { host2++; } - /* make decision based on host name if they are unequal */ + // make decision based on host name if they are unequal if (PL_strcmp (host1, host2) < 0) { return -1; } @@ -4018,15 +4054,17 @@ CookieCompare (net_CookieStruct * cookie1, net_CookieStruct * cookie2) { return 1; } - /* if host names are equal, make decision based on cookie name */ + // if host names are equal, make decision based on cookie name return (PL_strcmp (cookie1->name, cookie2->name)); } +*/ /* * find the next cookie that is alphabetically after the specified cookie * ordering is based on hostname and the cookie name * if specified cookie is NULL, find the first cookie alphabetically */ +/* PRIVATE net_CookieStruct * NextCookieAfter(net_CookieStruct * cookie, int * cookieNum) { XP_List *cookie_list=net_cookie_list; @@ -4049,7 +4087,8 @@ NextCookieAfter(net_CookieStruct * cookie, int * cookieNum) { *cookieNum = lowestCookieNum; return lowestCookie; } - +*/ +/* typedef struct _CookieViewerDialog CookieViewerDialog; struct _CookieViewerDialog { @@ -4058,7 +4097,7 @@ struct _CookieViewerDialog { PRBool dialogUp; XPDialogState *state; }; - +*/ #ifdef TRUST_LABELS /* Purpose: given a cookie name look in the list containing the cookperm.txt * file and locate a matching trust label. If a matching trust label @@ -4071,6 +4110,7 @@ struct _CookieViewerDialog { * History: * 9/9/98 Paul Chek - switch recipient from a range to a single value */ +/* char *GetTrustLabelString(char *CookieName) { XP_List * list_ptr, *Tptr; @@ -4082,22 +4122,20 @@ char *GetTrustLabelString(char *CookieName) char *szBy = NULL; int i, j; -/* - * here's how we would like to write the code but it doesn't compile on the mac - * - * int PurposeIds[] = {MK_ACCESS_TL_PPH0, MK_ACCESS_TL_PPH1, - * MK_ACCESS_TL_PPH2, MK_ACCESS_TL_PPH3, - * MK_ACCESS_TL_PPH4, MK_ACCESS_TL_PPH5}; - * int RecpIds[] = { MK_ACCESS_TL_RPH0, MK_ACCESS_TL_RPH1, - * MK_ACCESS_TL_RPH2, MK_ACCESS_TL_RPH3}; -*/ +// here's how we would like to write the code but it doesn't compile on the mac + // +// int PurposeIds[] = {MK_ACCESS_TL_PPH0, MK_ACCESS_TL_PPH1, + // MK_ACCESS_TL_PPH2, MK_ACCESS_TL_PPH3, + // MK_ACCESS_TL_PPH4, MK_ACCESS_TL_PPH5}; + // int RecpIds[] = { MK_ACCESS_TL_RPH0, MK_ACCESS_TL_RPH1, + // MK_ACCESS_TL_RPH2, MK_ACCESS_TL_RPH3}; +// -#define NumPurposeBits 6 /* number of bits in the recipient value */ - /* array of msg Ids for the purpose values */ +#define NumPurposeBits 6 // number of bits in the recipient value int PurposeIds[NumPurposeBits]; -#define NumRecpBits 4 /* number of bits in the recipient value */ - /* the list of msg Ids for the recipient value. */ +#define NumRecpBits 4 // number of bits in the recipient value + // the list of msg Ids for the recipient value. int RecpIds[NumRecpBits]; #if NumPurposeBits > NumRecpBits @@ -4105,7 +4143,7 @@ char *GetTrustLabelString(char *CookieName) #else #define NumStrs NumRecpBits #endif - /* this array holds strings used in formatting the message */ + // this array holds strings used in formatting the message char *szTempStrs[ NumStrs ]; PurposeIds[0] = MK_ACCESS_TL_PPH0; @@ -4123,18 +4161,18 @@ char *GetTrustLabelString(char *CookieName) if( CookieName ) { - /* look thru the cookie permission list for a matching trust label */ + //look thru the cookie permission list for a matching trust label // net_lock_cookie_permission_list(); list_ptr = net_cookie_permission_list; while( szTemp == NULL && (cookperm = (net_CookiePermissionStruct *) XP_ListNextObject(list_ptr))!=0) { - /* look thru the trust list for this cookie */ + //look thru the trust list for this cookie // if (cookperm->TrustList ) { Tptr = cookperm->TrustList; while( (TEntry = (TrustEntry *)XP_ListNextObject(Tptr))) { if( TEntry->CookieName && !PL_strcmp(CookieName, TEntry->CookieName)) { - /* this permission entry matches the given cookie */ + // this permission entry matches the given cookie// szTemp = (char*)PR_Malloc(BUFLEN); break; } @@ -4143,29 +4181,27 @@ char *GetTrustLabelString(char *CookieName) } net_unlock_cookie_permission_list(); - /* was a match found?? */ + // was a match found?? if (szTemp) { - /* yes convert the ratings info into user strings */ + // yes convert the ratings info into user strings // for( j=0; jpurpose>>i) & 1) { - /* this bit is set get the associated phrase */ + //this bit is set get the associated phrase szTempStrs[j++] = PL_strdup( XP_GetString( PurposeIds[i] ) ); } } - /* - * build the purpose string - * For translation purposes I am using strings - * of the form "This information is used for %1$s, %2$s and %3$s." - * and inserting the additional phrases in the formating.*/ + // build the purpose string + // For translation purposes I am using strings + // of the form "This information is used for %1$s, %2$s and %3$s." + // and inserting the additional phrases in the formating. switch ( j ) { case 1: PR_snprintf(szTemp, BUFLEN, @@ -4223,18 +4259,18 @@ char *GetTrustLabelString(char *CookieName) ); break; - } /* switch ( j ) */ - /* I did things this way to avoid buffer overflow problems */ + } // switch ( j ) + // I did things this way to avoid buffer overflow problems szPurpose = PL_strdup( szTemp ); - /* free the temporary strings */ + // free the temporary strings for( j=0; jrecipient] ) ); PR_snprintf(szTemp, BUFLEN, @@ -4244,14 +4280,14 @@ char *GetTrustLabelString(char *CookieName) PR_FREEIF(szTempStrs[0]); szRecipient = PL_strdup( szTemp ); #else - /* is just a single bit set and is that bit 0 ?*/ - /* if RECIPIENT_RANGE is defined you will need to - * include these lines in allxpstr.h - * ResDef(MK_ACCESS_TL_RECP2, (TRUST_LABEL_BASE + 17), - * "It is %1$s and %2$s." ) - * ResDef(MK_ACCESS_TL_RECP3, (TRUST_LABEL_BASE + 18), - * "It is %1$s, %2$s and %3$s." ) - */ + // is just a single bit set and is that bit 0 ? + // if RECIPIENT_RANGE is defined you will need to + // include these lines in allxpstr.h + // ResDef(MK_ACCESS_TL_RECP2, (TRUST_LABEL_BASE + 17), + // "It is %1$s and %2$s." ) + // ResDef(MK_ACCESS_TL_RECP3, (TRUST_LABEL_BASE + 18), + // "It is %1$s, %2$s and %3$s." ) + /// if ( TEntry->recipient == 1 ) { szTempStrs[0] = PL_strdup( XP_GetString( MK_ACCESS_TL_RPH0 ) ); PR_snprintf(szTemp, BUFLEN, @@ -4259,23 +4295,21 @@ char *GetTrustLabelString(char *CookieName) szTempStrs[0] ); } else { - /* - * if bits other than bit 0 are set then dont - * output the "used only by this site" text - * - * count the number of purpose bits set AND - * make a list of the phrases to use - */ + // if bits other than bit 0 are set then dont + // output the "used only by this site" text + // + // count the number of purpose bits set AND + // make a list of the phrases to use + /// for (j=0,i=1; irecipient>>i) & 1) { - /* this bit is set get the associated phrase */ + // this bit is set get the associated phrase szTempStrs[j++] = PL_strdup( XP_GetString( RecpIds[i] ) ); } } - /* - * format the recipient string according to the - * number of bits set - */ + // format the recipient string according to the + // number of bits set + // switch ( j ) { case 1: PR_snprintf(szTemp, BUFLEN, @@ -4301,18 +4335,18 @@ char *GetTrustLabelString(char *CookieName) ); break; - } /* switch ( j ) */ + } // switch ( j ) } - /* I did things this way to avoid buffer overflow problems */ + // I did things this way to avoid buffer overflow problems szRecipient = PL_strdup( szTemp ); - /* free the temporary strings */ + // free the temporary strings for( j=0; jby) { PR_snprintf(szTemp, BUFLEN, XP_GetString(MK_ACCESS_TL_BY), TEntry->by); szBy = PL_strdup( szTemp ); @@ -4320,16 +4354,15 @@ char *GetTrustLabelString(char *CookieName) szBy = PL_strdup( " " ); } - /* - * construct the entire trust label statement. - * WATCHOUT: you can only execute four XP_GetString calls - * in this format string. - */ + // construct the entire trust label statement. + // WATCHOUT: you can only execute four XP_GetString calls + // in this format string. + // PR_snprintf(szTemp, BUFLEN, - "%s " /* identifiable text */ - "%s " /* purpose string */ - "%s " /* receipent */ - "%s", /* by string */ + "%s " // identifiable text + "%s " // purpose string + "%s " /// receipent + "%s", // by string (TEntry->bIdentifiable ? XP_GetString(MK_ACCESS_TL_ID1) : XP_GetString(MK_ACCESS_TL_ID0)), @@ -4342,18 +4375,18 @@ char *GetTrustLabelString(char *CookieName) return szTemp; } - - +*/ +/* #define STR_TRUST_LABEL "(TrustLabel" -/* these structures describe the layout of the trust label information in - * the cookperm.txt. The structures are used for both reading and writing the - * file. - */ +// these structures describe the layout of the trust label information in + // the cookperm.txt. The structures are used for both reading and writing the +// file. +// enum {TYPE_QUOTED_STRING, TYPE_INT}; typedef struct { - char *szMatchStr; /* the string to look for coming in */ - int ValueType; /* what kind of thing the value is */ - int DataOffset; /* where in the TrustEntry struct to store the value */ + char *szMatchStr; // the string to look for coming in + int ValueType; // what kind of thing the value is + int DataOffset; // where in the TrustEntry struct to store the value } ParseItem; static ParseItem ParseData[] = { @@ -4362,20 +4395,21 @@ static ParseItem ParseData[] = { {"id", TYPE_INT, offsetof(TrustEntry, bIdentifiable)}, {"recipient", TYPE_INT, offsetof(TrustEntry, recipient)}, {"by", TYPE_QUOTED_STRING, offsetof(TrustEntry, by)}, - /* the timestamp is the date and time when the cookie was set. - * It is in the form "14 Apr 89 03:20 GMT". Use PR_ParseTimeString - * to parse it into a PR_Exploded time. - */ + //the timestamp is the date and time when the cookie was set. + // It is in the form "14 Apr 89 03:20 GMT". Use PR_ParseTimeString + // to parse it into a PR_Exploded time. + // {"timestamp", TYPE_QUOTED_STRING, offsetof(TrustEntry, CookieSet)} }; #define NUM_ITEMS sizeof(ParseData) / sizeof( ParseItem) - +*/ /****************************************************** * Purpose: parse all the trust label string from a line in * cookperm.txt and store the result in a net_CookiePermissionStruct. * * This is a simple table driven parser. ******************************************************/ +/* PRIVATE void ParseTrustLabelInfo (char *Buf, net_CookiePermissionStruct * cookie_permission) @@ -4387,38 +4421,36 @@ void ParseTrustLabelInfo char *pCopy = NULL; TrustEntry *TEntry; - /* - * Look for the trust label information which is in the form - * "(TrustLabel" - must be the first token - * "cookie:" - * "purpose:" - * "id:"<"0"|"1"> - * "recipient:" - * "by:" - * "timestamp:" - * ")" - must be the last token - * purpose value == a hex value corresponding to the purpose value to set - * recipient value == a hex value corresponding to the recipient value to set - * by value == a text string enclosed in double quotes - * timestamp == time when the cookie was set: format is quoted string in any of the - * formats that PR_Time will accept. - * cookie name == the name of the cookie enclosed in quotes - * - * The middle tokens can be in any order. - */ + // Look for the trust label information which is in the form + // "(TrustLabel" - must be the first token + // "cookie:" + // "purpose:" + // "id:"<"0"|"1"> + // "recipient:" + // "by:" + // "timestamp:" + // ")" - must be the last token + // purpose value == a hex value corresponding to the purpose value to set + // recipient value == a hex value corresponding to the recipient value to set + // by value == a text string enclosed in double quotes + // timestamp == time when the cookie was set: format is quoted string in any of the + // formats that PR_Time will accept. + // cookie name == the name of the cookie enclosed in quotes + // + // The middle tokens can be in any order. + /// - /* - * Do I have a well formed trust label string ?? - * - can I find a beginning and an end?? - */ + // Do I have a well formed trust label string ?? + // - can I find a beginning and an end?? + // p = Buf; while ((p=strcasestr(p, (char *)STR_TRUST_LABEL)) && (pEnd=strchr(p,')'))) { p += PL_strlen(STR_TRUST_LABEL); - /* Allocate a new trust Entry */ + // Allocate a new trust Entry TEntry = PR_NEW(TrustEntry); if (TEntry) { - /* init the elements */ + // init the elements TEntry->CookieName = NULL; TEntry->purpose = 0; TEntry->recipient = 0; @@ -4426,40 +4458,38 @@ void ParseTrustLabelInfo TEntry->by = NULL; TEntry->CookieSet = NULL; - /* - * isolate this trust label string for parsing, I must make a copy - * of the incoming string because the tokenizer will add nulls to it. - * Also allocate one more byte than I really need so that the tokenizer - * can write an extra Null at the end. - */ + // isolate this trust label string for parsing, I must make a copy + // of the incoming string because the tokenizer will add nulls to it. + // Also allocate one more byte than I really need so that the tokenizer + // can write an extra Null at the end. + // len = pEnd-p+1; pCopy = XP_ALLOC(len + 1); if (!pCopy) return; XP_MEMCPY(pCopy, p, len-1); pCopy[len] = '\0'; - /* get the first token from the copy */ + // get the first token from the copy pToken = XP_STRTOK_R(pCopy, " :", &pSub); while (pToken) { if (pToken != ")") { for ( i=0; iTrustList) { cookie_permission->TrustList = XP_ListNew(); if(!cookie_permission->TrustList) { @@ -4504,15 +4533,16 @@ void ParseTrustLabelInfo } } - /* add the entry to the list in the permission entry */ + // add the entry to the list in the permission entry XP_ListAddObjectToEnd( cookie_permission->TrustList, TEntry ); - } /* end if (TEntry) */ - /* set up for the next entry */ + } //end if (TEntry) + // set up for the next entry p = ++pEnd; - } /* end while ((p=strcasestr( */ + } // end while ((p=strcasestr( return; } +*/ /**************************************************************** * Purpose: Write the trust label information from the permission @@ -4521,6 +4551,7 @@ void ParseTrustLabelInfo * History: * Paul Chek - initial creation ****************************************************************/ +/* PRIVATE void SaveTrustLabelData ( net_CookiePermissionStruct * cookie_permission, XP_File fp ) @@ -4534,26 +4565,25 @@ void SaveTrustLabelData int T2Size = 50; int len, i; - /* - * do an initial allocation for szTemp2. Whenever a quoted string - * is processed the size of szTemp2 is tested to make sure it is big enough, - * if it is not it is resized. - */ + // do an initial allocation for szTemp2. Whenever a quoted string + // is processed the size of szTemp2 is tested to make sure it is big enough, + // if it is not it is resized. + // szTemp2 = XP_ALLOC( T2Size ); if ( fp && cookie_permission && cookie_permission->TrustList && szTemp2 ) { - /* there is trust label information, write it */ + // there is trust label information, write it Tptr = cookie_permission->TrustList; while( (TEntry = (TrustEntry *)XP_ListNextObject(Tptr))) { - /* build the string up one piece at a time, its slower but safer */ + // build the string up one piece at a time, its slower but safer szTemp = NULL; StrAllocCopy( szTemp, " "STR_TRUST_LABEL); - /* march thru the Parsing table and output the TrustLabel information */ + // march thru the Parsing table and output the TrustLabel information for ( i=0; iCookieName) == 0) { - /* the entry was found */ + // the entry was found *TheEntry = TEntry; Status = TRUE; break; @@ -4615,13 +4646,14 @@ Bool FindTrustEntry( char *CookieName, XP_List *TList, TrustEntry **TheEntry ) } return Status; } - +*/ /**************************************************************** * Purpose: given a TrustLabel struct sat up the corresponding TrustEntry * * History: * Paul Chek - initial creation ****************************************************************/ +/* PRIVATE void CopyTrustEntry( char *CookieName, TrustEntry *TEntry, TrustLabel *trustlabel ) { @@ -4638,16 +4670,15 @@ void CopyTrustEntry( char *CookieName, TrustEntry *TEntry, TrustLabel *trustlabe TEntry->bIdentifiable = trustlabel->ID; TEntry->by = PL_strdup( trustlabel->szBy ); - /* - * format an ASCII timestamp for when the cookie was set. Use a - *format that PR_ParseTimeString supports. "22-AUG-1993 10:59 PM" - */ + // format an ASCII timestamp for when the cookie was set. Use a + //format that PR_ParseTimeString supports. "22-AUG-1993 10:59 PM" + // PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now); PR_FormatTimeUSEnglish(line, 400, "%d-%b-%Y %I:%M %p", &now); TEntry->CookieSet = PL_strdup( line ); } } - +*/ /**************************************************************** * Purpose: look in the permissions list to see if there is * trust label information for the cookie. If so delete it. @@ -4655,6 +4686,7 @@ void CopyTrustEntry( char *CookieName, TrustEntry *TEntry, TrustLabel *trustlabe * History: * Paul Chek - initial creation ****************************************************************/ +/* PRIVATE void DeleteCookieFromPermissions( char *CookieHost, char *CookieName ) { @@ -4662,29 +4694,29 @@ void DeleteCookieFromPermissions( char *CookieHost, char *CookieName ) TrustEntry *TEntry; net_CookiePermissionStruct * cookie_permission; - /* lock the permission list */ + // lock the permission list TmpList=net_cookie_permission_list; net_lock_cookie_permission_list(); while ( (cookie_permission=(net_CookiePermissionStruct *)XP_ListNextObject(TmpList)) ) { - /* is this the corect host for the cookie */ + // is this the corect host for the cookie */ if (PL_strcasecmp(CookieHost, cookie_permission->host) == 0) { - /* yes - see if there is a trust label entry for the cookie */ + // yes - see if there is a trust label entry for the cookie if ( FindTrustEntry( CookieName, cookie_permission->TrustList, &TEntry ) ) { - /* yes there is - delete it */ + // yes there is - delete it */ XP_ListRemoveObject( cookie_permission->TrustList, TEntry); - /* free the strings in the entry */ + // free the strings in the entry PR_FREEIF(TEntry->CookieName); PR_FREEIF(TEntry->by); PR_FREEIF(TEntry->CookieSet); } - /* dont need to look in the list anymore cause there is only one entry per host */ + // dont need to look in the list anymore cause there is only one entry per host break; } } net_unlock_cookie_permission_list(); } - +*/ /**************************************************************** * Purpose: given a TrustLabel struct containing the trust label * info that matches a particular cookie add the trust @@ -4693,32 +4725,33 @@ void DeleteCookieFromPermissions( char *CookieHost, char *CookieName ) * History: * Paul Chek - initial creation ****************************************************************/ +/* PRIVATE void AddTrustLabelInfo( char *CookieName, TrustLabel *trustlabel ) { XP_List *TmpList; TrustEntry *TEntry; net_CookiePermissionStruct * cookie_permission; - /* lock the permission list */ + // lock the permission list // TmpList=net_cookie_permission_list; net_lock_cookie_permission_list(); while ( (cookie_permission=(net_CookiePermissionStruct *)XP_ListNextObject(TmpList)) ) { - /* is this the corect host for the cookie */ + // is this the corect host for the cookie if (PL_strcasecmp(trustlabel->domainName, cookie_permission->host) == 0) { - /* OK - we have found the entry for this host. Look thru the trust list - to see if we have an existing entry for this cookie. If so replace it. - If not add a new entry - */ + // OK - we have found the entry for this host. Look thru the trust list + // to see if we have an existing entry for this cookie. If so replace it. + // If not add a new entry + // if ( FindTrustEntry( CookieName, cookie_permission->TrustList, &TEntry ) ) { - /* the entry exists modify it */ + //the entry exists modify it CopyTrustEntry( CookieName, TEntry, trustlabel ); } else { - /* the entry does NOT exist - add a new one */ + // the entry does NOT exist - add a new one TEntry = PR_NEWZAP( TrustEntry ); if ( TEntry ) { - /* yes - build the entry for the cookie */ + // yes - build the entry for the cookie CopyTrustEntry( CookieName, TEntry, trustlabel ); - /* Does the trust list exist in this entry, if not create it */ + // Does the trust list exist in this entry, if not create it if(!cookie_permission->TrustList) { cookie_permission->TrustList = XP_ListNew(); if(!cookie_permission->TrustList) { @@ -4726,22 +4759,23 @@ void AddTrustLabelInfo( char *CookieName, TrustLabel *trustlabel ) } } - /* add it to the list */ + // add it to the list XP_ListAddObjectToEnd(cookie_permission->TrustList, TEntry); - break; /* all done */ + break; // all done } } } } net_unlock_cookie_permission_list(); } - +*/ #endif /* * return a string that has each " of the argument sting * replaced with \" so it can be used inside a quoted string */ + PRIVATE char* net_FixQuoted(char* s) { char * result; @@ -4767,7 +4801,7 @@ net_FixQuoted(char* s) { /* pinkerton - if we don't do this, it won't compile because it runs out of registers */ #pragma global_optimizer on #endif - +/* PRIVATE void net_DisplayCookieInfoAsHTML(MWContext *context, char* host) { @@ -4803,7 +4837,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) StrAllocCopy (view_cookies, XP_GetString(MK_ACCESS_VIEW_COOKIES)); StrAllocCopy (view_sites, XP_GetString(MK_ACCESS_VIEW_SITES)); - /* generate initial section of html file */ + // generate initial section of html file g += PR_snprintf(buffer+g, BUFLEN-g, "\n" "\n" @@ -4826,7 +4860,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) FLUSH_BUFFER - /* fill in initial 0's for deleted_cookies and deleted_sites arrays */ + //fill in initial 0's for deleted_cookies and deleted_sites arrays count = XP_ListCount(net_cookie_list); for (i=1; iname ); if ( szTrustLabel ) { g += PR_snprintf(buffer+g, BUFLEN-g, @@ -5019,7 +5053,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) FLUSH_BUFFER } - /* generate next section of html file */ + // generate next section of html file g += PR_snprintf(buffer+g, BUFLEN-g, " }\n" " top.frames[prop_frame].document.close();\n" @@ -5030,7 +5064,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) ); FLUSH_BUFFER - /* generate index frame only if full viewer */ + // generate index frame only if full viewer if (!host) { g += PR_snprintf(buffer+g, BUFLEN-g, @@ -5062,7 +5096,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) FLUSH_BUFFER } - /* generate next section of html file */ + // generate next section of html file if (!host) { StrAllocCopy (heading, XP_GetString(MK_ACCESS_COOKIES_ACCEPTED)); } else { @@ -5092,7 +5126,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) FLUSH_BUFFER PR_FREEIF(heading); - /* generate the html for the list of cookies in alphabetical order */ + // generate the html for the list of cookies in alphabetical order cookie_list=net_cookie_list; cookie = NULL; while (cookie = NextCookieAfter(cookie, &cookieNum)) { @@ -5116,7 +5150,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) } net_unlock_cookie_list(); - /* generate next section of html file */ + // generate next section of html file StrAllocCopy (heading, XP_GetString(MK_ACCESS_COOKIES_PERMISSION)); g += PR_snprintf(buffer+g, BUFLEN-g, " top.frames[list_frame].document.write(\n" @@ -5180,7 +5214,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) PR_FREEIF(heading); FLUSH_BUFFER - /* generate the html for the list of cookie permissions */ + // generate the html for the list of cookie permissions cookieNum = 0; cookie_permission_list=net_cookie_permission_list; net_lock_cookie_permission_list(); @@ -5203,7 +5237,7 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) } net_unlock_cookie_permission_list(); - /* generate next section of html file */ + // generate next section of html file g += PR_snprintf(buffer+g, BUFLEN-g, " top.frames[list_frame].document.write(\n" " \"\" +\n" @@ -5238,15 +5272,15 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) ); FLUSH_BUFFER - /* transfer what we have so far into strings->args[0] */ + // transfer what we have so far into strings->args[0] if (buffer2) { XP_SetDialogString(strings, 0, buffer2); buffer2 = NULL; } - /* Note: strings->args[1] will later be filled in with value of handle */ + //Note: strings->args[1] will later be filled in with value of handle - /* generate remainder of html, it will go into strings->arg[2] */ + // generate remainder of html, it will go into strings->arg[2] g += PR_snprintf(buffer+g, BUFLEN-g, ">\" +\n" " \"\" +\n" @@ -5343,12 +5377,12 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) ); FLUSH_BUFFER - /* free some strings that are no longer needed */ + // free some strings that are no longer needed // PR_FREEIF(view_cookies); PR_FREEIF(view_sites); PR_FREEIF(buffer); - /* put html just generated into strings->arg[2] and invoke HTML dialog */ + // put html just generated into strings->arg[2] and invoke HTML dialog // if (buffer2) { XP_SetDialogString(strings, 2, buffer2); buffer2 = NULL; @@ -5364,21 +5398,23 @@ net_DisplayCookieInfoAsHTML(MWContext *context, char* host) return; } - +*/ +/* PUBLIC void NET_CookieViewerReturn() { } - +*/ +/* PUBLIC void NET_DisplayCookieInfoOfSiteAsHTML(MWContext * context, char * URLName) { char * host; char * colon; - /* remove protocol from URL name */ + // remove protocol from URL name host = NET_ParseURL(URLName, GET_HOST_PART); - /* remove port number from URL name */ + // remove port number from URL name colon = PL_strchr(host, ':'); if(colon) { *colon = '\0'; @@ -5386,17 +5422,17 @@ NET_DisplayCookieInfoOfSiteAsHTML(MWContext * context, char * URLName) net_DisplayCookieInfoAsHTML(context, host); - /* free up allocated string and return */ + // free up allocated string and return if(colon) { *colon = ':'; } PR_Free(host); } +*/ PUBLIC void NET_DisplayCookieInfoAsHTML(MWContext * context) { - net_DisplayCookieInfoAsHTML(context, NULL); } @@ -5406,9 +5442,11 @@ NET_DisplayCookieInfoAsHTML(MWContext * context) #endif #else +/* PUBLIC void NET_DisplayCookieInfoAsHTML(MWContext * context) { } +*/ #endif diff --git a/mozilla/network/protocol/http/nsCookie.cpp b/mozilla/network/protocol/http/nsCookie.cpp new file mode 100644 index 00000000000..ac059747f36 --- /dev/null +++ b/mozilla/network/protocol/http/nsCookie.cpp @@ -0,0 +1,2556 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * + * Designed and Implemented by Lou Montulli '94 + * Heavily modified by Judson Valeski '97 + * Yada yada yada... Gagan Saksena '98 + * + * This file implements HTTP access authorization + * and HTTP cookies + */ + +#define alphabetize 1 +#include "nsString.h" +#include "nsINetService.h" +#include "nsIServiceManager.h" +#include "nsIStringBundle.h" + +extern "C" { +#include "xp.h" +#include "mkprefs.h" +#include "netutils.h" +#include "httpauth.h" +#include "prefapi.h" +#include "prmon.h" +} +extern "C" { +#ifdef XP_MAC +#include "prpriv.h" /* for NewNamedMonitor */ +#else +#include "private/prpriv.h" +#endif +} + +extern "C" { +#include "cookies.h" +#include "sechash.h" +#include "rosetta.h" +#include "libevent.h" +#include "mkparse.h" +#include "net_xp_file.h" +} + +extern "C" { +#include "xpgetstr.h" /* for XP_GetString() */ +extern int MK_ACCESS_COOKIES_WISHES0; +extern int MK_ACCESS_COOKIES_WISHES1; +extern int MK_ACCESS_COOKIES_WISHESN; +extern int MK_ACCESS_COOKIES_WISHES_MODIFY; +extern int MK_ACCESS_COOKIES_REMEMBER; +} + +static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); +static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); + +static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); +static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); + +#define MAX_NUMBER_OF_COOKIES 300 +#define MAX_COOKIES_PER_SERVER 20 +#define MAX_BYTES_PER_COOKIE 4096 /* must be at least 1 */ + +PRIVATE Bool cookies_changed = FALSE; +PRIVATE Bool cookie_permissions_changed = FALSE; +PRIVATE Bool cookie_remember_checked = FALSE; + +PRIVATE NET_CookieBehaviorEnum net_CookieBehavior = NET_Accept; +PRIVATE Bool net_WarnAboutCookies = FALSE; + + +/*-------------------------------------------------- + * The following routines support the + * Set-Cookie: / Cookie: headers + */ + +PRIVATE XP_List * net_cookie_list=0; +PRIVATE XP_List * net_cookie_permission_list=0; +PRIVATE XP_List * net_defer_cookie_list=0; + +typedef struct _net_CookieStruct { + char * path; + char * host; + char * name; + char * cookie; + time_t expires; + time_t last_accessed; + HG26237 + Bool is_domain; /* is it a domain instead of an absolute host? */ +} net_CookieStruct; + +typedef struct _net_CookiePermissionStruct { + char * host; + Bool permission; +} net_CookiePermissionStruct; + +typedef struct _net_DeferCookieStruct { + MWContext * context; + char * cur_url; + char * set_cookie_header; + time_t timeToExpire; +} net_DeferCookieStruct; + +/* Routines and data to protect the cookie list so it +** can be accessed by mulitple threads +*/ + +#include "prthread.h" +#include "prmon.h" + +static PRMonitor * cookie_lock_monitor = NULL; +static PRThread * cookie_lock_owner = NULL; +static int cookie_lock_count = 0; + +#define TEST_URL "resource:/res/cookie.properties" + +PRIVATE char* +cookie_Localize(char* genericString) { + nsresult ret; + nsAutoString v(""); + + /* create a URL for the string resource file */ + nsINetService* pNetService = nsnull; + ret = nsServiceManager::GetService(kNetServiceCID, kINetServiceIID, + (nsISupports**) &pNetService); + if (NS_FAILED(ret)) { + printf("cannot get net service\n"); + return v.ToNewCString(); + } + nsIURL *url = nsnull; + ret = pNetService->CreateURL(&url, nsString(TEST_URL), nsnull, nsnull, + nsnull); + if (NS_FAILED(ret)) { + printf("cannot create URL\n"); + nsServiceManager::ReleaseService(kNetServiceCID, pNetService); + return v.ToNewCString(); + } + nsServiceManager::ReleaseService(kNetServiceCID, pNetService); + + /* create a bundle for the localization */ + nsIStringBundleService* pStringService = nsnull; + ret = nsServiceManager::GetService(kStringBundleServiceCID, + kIStringBundleServiceIID, (nsISupports**) &pStringService); + if (NS_FAILED(ret)) { + printf("cannot get string service\n"); + return v.ToNewCString(); + } + nsILocale* locale = nsnull; + nsIStringBundle* bundle = nsnull; + ret = pStringService->CreateBundle(url, locale, &bundle); + if (NS_FAILED(ret)) { + printf("cannot create instance\n"); + nsServiceManager::ReleaseService(kStringBundleServiceCID, pStringService); + return v.ToNewCString(); + } + nsServiceManager::ReleaseService(kStringBundleServiceCID, pStringService); + + /* localize the given string */ + ret = bundle->GetStringFromName(nsString(genericString), v); + PR_Free(bundle); + if (NS_FAILED(ret)) { + printf("cannot get string from name\n"); + return v.ToNewCString(); + } + return v.ToNewCString(); +} + +PRIVATE void +net_lock_cookie_list(void) +{ + if(!cookie_lock_monitor) + cookie_lock_monitor = PR_NewNamedMonitor("cookie-lock"); + + PR_EnterMonitor(cookie_lock_monitor); + + while(TRUE) { + + /* no current owner or owned by this thread */ + PRThread * t = PR_CurrentThread(); + if(cookie_lock_owner == NULL || cookie_lock_owner == t) { + cookie_lock_owner = t; + cookie_lock_count++; + + PR_ExitMonitor(cookie_lock_monitor); + return; + } + + /* owned by someone else -- wait till we can get it */ + PR_Wait(cookie_lock_monitor, PR_INTERVAL_NO_TIMEOUT); + + } +} + +PRIVATE void +net_unlock_cookie_list(void) +{ + PR_EnterMonitor(cookie_lock_monitor); + +#ifdef DEBUG + /* make sure someone doesn't try to free a lock they don't own */ + PR_ASSERT(cookie_lock_owner == PR_CurrentThread()); +#endif + + cookie_lock_count--; + + if(cookie_lock_count == 0) { + cookie_lock_owner = NULL; + PR_Notify(cookie_lock_monitor); + } + PR_ExitMonitor(cookie_lock_monitor); + +} + +static PRMonitor * defer_cookie_lock_monitor = NULL; +static PRThread * defer_cookie_lock_owner = NULL; +static int defer_cookie_lock_count = 0; + +PRIVATE void +net_lock_defer_cookie_list(void) +{ + if(!defer_cookie_lock_monitor) + defer_cookie_lock_monitor = + PR_NewNamedMonitor("defer_cookie-lock"); + + PR_EnterMonitor(defer_cookie_lock_monitor); + + while(TRUE) { + + /* no current owner or owned by this thread */ + PRThread * t = PR_CurrentThread(); + if(defer_cookie_lock_owner == NULL || defer_cookie_lock_owner == t) { + defer_cookie_lock_owner = t; + defer_cookie_lock_count++; + + PR_ExitMonitor(defer_cookie_lock_monitor); + return; + } + + /* owned by someone else -- wait till we can get it */ + PR_Wait(defer_cookie_lock_monitor, PR_INTERVAL_NO_TIMEOUT); + + } +} + +PRIVATE void +net_unlock_defer_cookie_list(void) +{ + PR_EnterMonitor(defer_cookie_lock_monitor); + +#ifdef DEBUG + /* make sure someone doesn't try to free a lock they don't own */ + PR_ASSERT(defer_cookie_lock_owner == PR_CurrentThread()); +#endif + + defer_cookie_lock_count--; + + if(defer_cookie_lock_count == 0) { + defer_cookie_lock_owner = NULL; + PR_Notify(defer_cookie_lock_monitor); + } + PR_ExitMonitor(defer_cookie_lock_monitor); + +} + +static PRMonitor * cookie_permission_lock_monitor = NULL; +static PRThread * cookie_permission_lock_owner = NULL; +static int cookie_permission_lock_count = 0; + +PRIVATE void +net_lock_cookie_permission_list(void) +{ + if(!cookie_permission_lock_monitor) + cookie_permission_lock_monitor = + PR_NewNamedMonitor("cookie_permission-lock"); + + PR_EnterMonitor(cookie_permission_lock_monitor); + + while(TRUE) { + + /* no current owner or owned by this thread */ + PRThread * t = PR_CurrentThread(); + if(cookie_permission_lock_owner == NULL || cookie_permission_lock_owner == t) { + cookie_permission_lock_owner = t; + cookie_permission_lock_count++; + + PR_ExitMonitor(cookie_permission_lock_monitor); + return; + } + + /* owned by someone else -- wait till we can get it */ + PR_Wait(cookie_permission_lock_monitor, PR_INTERVAL_NO_TIMEOUT); + + } +} + +PRIVATE void +net_unlock_cookie_permission_list(void) +{ + PR_EnterMonitor(cookie_permission_lock_monitor); + +#ifdef DEBUG + /* make sure someone doesn't try to free a lock they don't own */ + PR_ASSERT(cookie_permission_lock_owner == PR_CurrentThread()); +#endif + + cookie_permission_lock_count--; + + if(cookie_permission_lock_count == 0) { + cookie_permission_lock_owner = NULL; + PR_Notify(cookie_permission_lock_monitor); + } + PR_ExitMonitor(cookie_permission_lock_monitor); + +} + +PRIVATE int +net_SaveCookiePermissions(char * filename); + +PRIVATE void +net_FreeCookiePermission + (net_CookiePermissionStruct * cookie_permission, Bool save) +{ + + /* + * This routine should only be called while holding the + * cookie permission list lock + */ + + if(!cookie_permission) { + return; + } + XP_ListRemoveObject(net_cookie_permission_list, cookie_permission); + PR_FREEIF(cookie_permission->host); + + PR_Free(cookie_permission); + if (save) { + cookie_permissions_changed = TRUE; + net_SaveCookiePermissions(NULL); + } +} + +/* blows away all cookie permissions currently in the list */ +PRIVATE void +net_RemoveAllCookiePermissions() +{ + net_CookiePermissionStruct * victim; + XP_List * cookiePermissionList; + + /* check for NULL or empty list */ + net_lock_cookie_permission_list(); + cookiePermissionList = net_cookie_permission_list; + + if(XP_ListIsEmpty(cookiePermissionList)) { + net_unlock_cookie_permission_list(); + return; + } + while((victim = + (net_CookiePermissionStruct *) + XP_ListNextObject(cookiePermissionList)) != 0) { + net_FreeCookiePermission(victim, FALSE); + cookiePermissionList = net_cookie_permission_list; + } + XP_ListDestroy(net_cookie_permission_list); + net_cookie_permission_list = NULL; + net_unlock_cookie_permission_list(); +} + +/* This should only get called while holding the cookie-lock +** +*/ +PRIVATE void +net_FreeCookie(net_CookieStruct * cookie) +{ + + if(!cookie) + return; + XP_ListRemoveObject(net_cookie_list, cookie); + + PR_FREEIF(cookie->path); + PR_FREEIF(cookie->host); + PR_FREEIF(cookie->name); + PR_FREEIF(cookie->cookie); + + PR_Free(cookie); + + cookies_changed = TRUE; +} + + +PUBLIC void +NET_DeleteCookie(char* cookieURL) +{ + net_CookieStruct * cookie; + XP_List * list_ptr; + char * cookieURL2 = 0; + + net_lock_cookie_list(); + list_ptr = net_cookie_list; + while((cookie = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) { + StrAllocCopy(cookieURL2, "cookie:"); + StrAllocCat(cookieURL2, cookie->host); + StrAllocCat(cookieURL2, "!"); + StrAllocCat(cookieURL2, cookie->path); + StrAllocCat(cookieURL2, "!"); + StrAllocCat(cookieURL2, cookie->name); + if (PL_strcmp(cookieURL, cookieURL2)==0) { + net_FreeCookie(cookie); + break; + } + } + PR_FREEIF(cookieURL2); + net_unlock_cookie_list(); +} + + +/* blows away all cookies currently in the list, then blows away the list itself + * nulling it after it's free'd + */ +PRIVATE void +net_RemoveAllCookies() +{ + net_CookieStruct * victim; + XP_List * cookieList; + + /* check for NULL or empty list */ + net_lock_cookie_list(); + cookieList = net_cookie_list; + if(XP_ListIsEmpty(cookieList)) { + net_unlock_cookie_list(); + return; + } + + while((victim = (net_CookieStruct *) XP_ListNextObject(cookieList)) != 0) { + net_FreeCookie(victim); + cookieList=net_cookie_list; + } + XP_ListDestroy(net_cookie_list); + net_cookie_list = NULL; + net_unlock_cookie_list(); +} + +PUBLIC void +NET_RemoveAllCookies() +{ + + net_RemoveAllCookiePermissions(); + net_RemoveAllCookies(); +} + +PRIVATE void +net_remove_oldest_cookie(void) +{ + XP_List * list_ptr; + net_CookieStruct * cookie_s; + net_CookieStruct * oldest_cookie; + + net_lock_cookie_list(); + list_ptr = net_cookie_list; + + if(XP_ListIsEmpty(list_ptr)) { + net_unlock_cookie_list(); + return; + } + + oldest_cookie = (net_CookieStruct*) list_ptr->next->object; + + while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) + { + if(cookie_s->last_accessed < oldest_cookie->last_accessed) + oldest_cookie = cookie_s; + } + + if(oldest_cookie) + { + TRACEMSG(("Freeing cookie because global max cookies has been exceeded")); + net_FreeCookie(oldest_cookie); + } + net_unlock_cookie_list(); +} + +/* Remove any expired cookies from memory +** This routine should only be called while holding the cookie list lock +*/ +PRIVATE void +net_remove_expired_cookies(void) +{ + XP_List * list_ptr = net_cookie_list; + net_CookieStruct * cookie_s; + time_t cur_time = time(NULL); + + if(XP_ListIsEmpty(list_ptr)) + return; + + while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) + { + /* Don't get rid of expire time 0 because these need to last for + * the entire session. They'll get cleared on exit. + */ + if( cookie_s->expires && (cookie_s->expires < cur_time) ) { + net_FreeCookie(cookie_s); + /* Reset the list_ptr to the beginning of the list. + * Do this because list_ptr's object was just freed + * by the call to net_FreeCookie struct, even + * though it's inefficient. + */ + list_ptr = net_cookie_list; + } + } +} + +/* checks to see if the maximum number of cookies per host + * is being exceeded and deletes the oldest one in that + * case + * This routine should only be called while holding the cookie lock + */ +PRIVATE void +net_CheckForMaxCookiesFromHost(const char * cur_host) +{ + XP_List * list_ptr = net_cookie_list; + net_CookieStruct * cookie_s; + net_CookieStruct * oldest_cookie = 0; + int cookie_count = 0; + + if(XP_ListIsEmpty(list_ptr)) + return; + + while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) + { + if(!PL_strcasecmp(cookie_s->host, cur_host)) + { + cookie_count++; + if(!oldest_cookie + || oldest_cookie->last_accessed > cookie_s->last_accessed) + oldest_cookie = cookie_s; + } + } + + if(cookie_count >= MAX_COOKIES_PER_SERVER && oldest_cookie) + { + TRACEMSG(("Freeing cookie because max cookies per server has been exceeded")); + net_FreeCookie(oldest_cookie); + } +} + + +/* search for previous exact match +** This routine should only be called while holding the cookie lock +*/ +PRIVATE net_CookieStruct * +net_CheckForPrevCookie(char * path, + char * hostname, + char * name) +{ + + XP_List * list_ptr = net_cookie_list; + net_CookieStruct * cookie_s; + + while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) { + if(path && hostname && cookie_s->path && cookie_s->host && cookie_s->name + && !PL_strcmp(name, cookie_s->name) + && !PL_strcmp(path, cookie_s->path) + && !PL_strcasecmp(hostname, cookie_s->host)) + return(cookie_s); + } + return(NULL); +} + +/* cookie utility functions */ +PRIVATE void +NET_SetCookieBehaviorPref(NET_CookieBehaviorEnum x) +{ + net_CookieBehavior = x; + + HG83330 + if(net_CookieBehavior == NET_DontUse) { + NET_XP_FileRemove("", xpHTTPCookie); + NET_XP_FileRemove("", xpHTTPCookiePermission); + } +} + +PRIVATE void +NET_SetCookieWarningPref(Bool x) +{ + net_WarnAboutCookies = x; +} + +PRIVATE NET_CookieBehaviorEnum +NET_GetCookieBehaviorPref(void) +{ + return net_CookieBehavior; +} + +PRIVATE Bool +NET_GetCookieWarningPref(void) +{ + return net_WarnAboutCookies; +} + +MODULE_PRIVATE int PR_CALLBACK +NET_CookieBehaviorPrefChanged(const char * newpref, void * data) +{ + PRInt32 n; + if ( (PREF_OK != PREF_GetIntPref(pref_cookieBehavior, &n)) ) { + n = DEF_COOKIE_BEHAVIOR; + } + NET_SetCookieBehaviorPref((NET_CookieBehaviorEnum)n); + return PREF_NOERROR; +} + +MODULE_PRIVATE int PR_CALLBACK +NET_CookieWarningPrefChanged(const char * newpref, void * data) +{ + PRBool x; + if ( (PREF_OK != PREF_GetBoolPref(pref_warnAboutCookies, &x)) ) { + x = FALSE; + } + NET_SetCookieWarningPref(x); + return PREF_NOERROR; +} + +/* + * search if permission already exists + */ +PRIVATE net_CookiePermissionStruct * +net_CheckForCookiePermission(char * hostname) { + XP_List * list_ptr; + net_CookiePermissionStruct * cookie_s; + + /* ignore leading period in host name */ + while (hostname && (*hostname == '.')) { + hostname++; + } + + net_lock_cookie_permission_list(); + list_ptr = net_cookie_permission_list; + while((cookie_s = (net_CookiePermissionStruct *) XP_ListNextObject(list_ptr))!=0) { + if(hostname && cookie_s->host + && !PL_strcasecmp(hostname, cookie_s->host)) { + net_unlock_cookie_permission_list(); + return(cookie_s); + } + } + net_unlock_cookie_permission_list(); + return(NULL); +} + +/* + * return: + * +1 if cookie permission exists for host and indicates host can set cookies + * 0 if cookie permission does not exist for host + * -1 if cookie permission exists for host and indicates host can't set cookies + */ +PUBLIC int +NET_CookiePermission(char* URLName) { + net_CookiePermissionStruct * cookiePermission; + char * host; + char * colon; + + if (!URLName || !(*URLName)) { + return 0; + } + + /* remove protocol from URL name */ + host = NET_ParseURL(URLName, GET_HOST_PART); + + /* remove port number from URL name */ + colon = PL_strchr(host, ':'); + if(colon) { + *colon = '\0'; + } + cookiePermission = net_CheckForCookiePermission(host); + if(colon) { + *colon = ':'; + } + PR_Free(host); + if (cookiePermission == NULL) { + return 0; + } + if (cookiePermission->permission) { + return 1; + } + return -1; +} + +/* called from mkgeturl.c, NET_InitNetLib(). This sets the module local cookie pref variables + and registers the callbacks */ +PUBLIC void +NET_RegisterCookiePrefCallbacks(void) +{ + PRInt32 n; + PRBool x; + + if ( (PREF_OK != PREF_GetIntPref(pref_cookieBehavior, &n)) ) { + n = DEF_COOKIE_BEHAVIOR; + } + NET_SetCookieBehaviorPref((NET_CookieBehaviorEnum)n); + PREF_RegisterCallback(pref_cookieBehavior, NET_CookieBehaviorPrefChanged, NULL); + + if ( (PREF_OK != PREF_GetBoolPref(pref_warnAboutCookies, &x)) ) { + x = FALSE; + } + NET_SetCookieWarningPref(x); + PREF_RegisterCallback(pref_warnAboutCookies, NET_CookieWarningPrefChanged, NULL); +} + +/* returns TRUE if authorization is required +** +** +** IMPORTANT: Now that this routine is mutli-threaded it is up +** to the caller to free any returned string +*/ +PUBLIC char * +NET_GetCookie(MWContext * context, char * address) +{ + char *name=0; + char *host = NET_ParseURL(address, GET_HOST_PART); + char *path = NET_ParseURL(address, GET_PATH_PART); + XP_List * list_ptr; + net_CookieStruct * cookie_s; + Bool first=TRUE; + HG26748 + time_t cur_time = time(NULL); + int host_length; + int domain_length; + + /* return string to build */ + char * rv=0; + + /* disable cookie's if the user's prefs say so + */ + if(NET_GetCookieBehaviorPref() == NET_DontUse) + return NULL; + + HG98476 + + /* search for all cookies + */ + net_lock_cookie_list(); + list_ptr = net_cookie_list; + while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) + { + if(!cookie_s->host) + continue; + + /* check the host or domain first + */ + if(cookie_s->is_domain) + { + char *cp; + domain_length = PL_strlen(cookie_s->host); + + /* calculate the host length by looking at all characters up to + * a colon or '\0'. That way we won't include port numbers + * in domains + */ + for(cp=host; *cp != '\0' && *cp != ':'; cp++) + ; /* null body */ + + host_length = cp - host; + if(domain_length > host_length + || PL_strncasecmp(cookie_s->host, + &host[host_length - domain_length], + domain_length)) + { + HG20476 + /* no match. FAIL + */ + continue; + } + + } + else if(PL_strcasecmp(host, cookie_s->host)) + { + /* hostname matchup failed. FAIL + */ + continue; + } + + /* shorter strings always come last so there can be no + * ambiquity + */ + if(cookie_s->path && !PL_strncmp(path, + cookie_s->path, + PL_strlen(cookie_s->path))) + { + + /* if the cookie is secure and the path isn't + * dont send it + */ + HG83764 + + /* check for expired cookies + */ + if( cookie_s->expires && (cookie_s->expires < cur_time) ) + { + /* expire and remove the cookie + */ + net_FreeCookie(cookie_s); + + /* start the list parsing over :( + * we must also start the string over + */ + PR_FREEIF(rv); + rv = NULL; + list_ptr = net_cookie_list; + first = TRUE; /* reset first */ + continue; + } + + if(first) + first = FALSE; + else + StrAllocCat(rv, "; "); + + if(cookie_s->name && *cookie_s->name != '\0') + { + cookie_s->last_accessed = cur_time; + StrAllocCopy(name, cookie_s->name); + StrAllocCat(name, "="); + +#ifdef PREVENT_DUPLICATE_NAMES + /* make sure we don't have a previous + * name mapping already in the string + */ + if(!rv || !PL_strstr(rv, name)) + { + StrAllocCat(rv, name); + StrAllocCat(rv, cookie_s->cookie); + } +#else + StrAllocCat(rv, name); + StrAllocCat(rv, cookie_s->cookie); +#endif /* PREVENT_DUPLICATE_NAMES */ + } + else + { + StrAllocCat(rv, cookie_s->cookie); + } + } + } + + net_unlock_cookie_list(); + PR_FREEIF(name); + PR_Free(path); + PR_Free(host); + + /* may be NULL */ + return(rv); +} + +void +net_AddCookiePermission + (net_CookiePermissionStruct * cookie_permission, Bool save ) { + + /* + * This routine should only be called while holding the + * cookie permission list lock + */ + if (cookie_permission) { + XP_List * list_ptr = net_cookie_permission_list; + if(!net_cookie_permission_list) { + net_cookie_permission_list = XP_ListNew(); + if(!net_cookie_permission_list) { + PR_Free(cookie_permission->host); + PR_Free(cookie_permission); + return; + } + list_ptr = net_cookie_permission_list; + } + +#ifdef alphabetize + /* add it to the list in alphabetical order */ + { + net_CookiePermissionStruct * tmp_cookie_permission; + Bool permissionAdded = FALSE; + while((tmp_cookie_permission = (net_CookiePermissionStruct *) + XP_ListNextObject(list_ptr))!=0) { + if (PL_strcasecmp + (cookie_permission->host,tmp_cookie_permission->host)<0) { + XP_ListInsertObject + (net_cookie_permission_list, + tmp_cookie_permission, + cookie_permission); + permissionAdded = TRUE; + break; + } + } + if (!permissionAdded) { + XP_ListAddObjectToEnd + (net_cookie_permission_list, cookie_permission); + } + } +#else + /* add it to the end of the list */ + XP_ListAddObjectToEnd (net_cookie_permission_list, cookie_permission); +#endif + + if (save) { + cookie_permissions_changed = TRUE; + net_SaveCookiePermissions(NULL); + } + } +} + +MODULE_PRIVATE PRBool +net_CookieIsFromHost(net_CookieStruct *cookie_s, char *host) { + if (!cookie_s || !(cookie_s->host)) { + return FALSE; + } + if (cookie_s->is_domain) { + char *cp; + int domain_length, host_length; + + domain_length = PL_strlen(cookie_s->host); + + /* calculate the host length by looking at all characters up to + * a colon or '\0'. That way we won't include port numbers + * in domains + */ + for(cp=host; *cp != '\0' && *cp != ':'; cp++) { + ; /* null body */ + } + host_length = cp - host; + + /* compare the tail end of host to cook_s->host */ + return (domain_length <= host_length && + PL_strncasecmp(cookie_s->host, + &host[host_length - domain_length], + domain_length) == 0); + } else { + return PL_strcasecmp(host, cookie_s->host) == 0; + } +} + +/* find out how many cookies this host has already set */ +PRIVATE int +net_CookieCount(char * host) { + int count = 0; + XP_List * list_ptr; + net_CookieStruct * cookie; + + net_lock_cookie_list(); + list_ptr = net_cookie_list; + while((cookie = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) { + if (host && net_CookieIsFromHost(cookie, host)) { + count++; + } + } + net_unlock_cookie_list(); + + return count; +} + +PUBLIC int +NET_CookieCount(char * URLName) { + char * host; + char * colon; + int count = 0; + + if (!URLName || !(*URLName)) { + return 0; + } + + /* remove protocol from URL name */ + host = NET_ParseURL(URLName, GET_HOST_PART); + + /* remove port number from URL name */ + colon = PL_strchr(host, ':'); + if(colon) { + *colon = '\0'; + } + + /* get count */ + count = net_CookieCount(host); + + /* free up allocated string and return */ + if(colon) { + *colon = ':'; + } + PR_Free(host); + return count; +} + +PRBool net_IntSetCookieStringInUse = FALSE; + +PRIVATE void +net_DeferCookie( + MWContext * context, + char * cur_url, + char * set_cookie_header, + time_t timeToExpire) { + net_DeferCookieStruct * defer_cookie = PR_NEW(net_DeferCookieStruct); + defer_cookie->context = context; + defer_cookie->cur_url = NULL; + StrAllocCopy(defer_cookie->cur_url, cur_url); + defer_cookie->set_cookie_header = NULL; + StrAllocCopy(defer_cookie->set_cookie_header, set_cookie_header); + defer_cookie->timeToExpire = timeToExpire; + net_lock_defer_cookie_list(); + if (!net_defer_cookie_list) { + net_defer_cookie_list = XP_ListNew(); + if (!net_cookie_list) { + PR_FREEIF(defer_cookie->cur_url); + PR_FREEIF(defer_cookie->set_cookie_header); + PR_Free(defer_cookie); + } + } + XP_ListAddObject(net_defer_cookie_list, defer_cookie); + net_unlock_defer_cookie_list(); +} + +PRIVATE void +net_IntSetCookieString(MWContext * context, + char * cur_url, + char * set_cookie_header, + time_t timeToExpire ); + +PRIVATE void +net_UndeferCookies() { + net_DeferCookieStruct * defer_cookie; + net_lock_defer_cookie_list(); + if(XP_ListIsEmpty(net_defer_cookie_list)) { + net_unlock_defer_cookie_list(); + return; + } + defer_cookie = (net_DeferCookieStruct*)XP_ListRemoveEndObject(net_defer_cookie_list); + net_unlock_defer_cookie_list(); + net_IntSetCookieString ( + defer_cookie->context, + defer_cookie->cur_url, + defer_cookie->set_cookie_header, + defer_cookie->timeToExpire); + PR_FREEIF(defer_cookie->cur_url); + PR_FREEIF(defer_cookie->set_cookie_header); + PR_Free(defer_cookie); +} + +/* Java script is calling NET_SetCookieString, netlib is calling +** this via NET_SetCookieStringFromHttp. +*/ + +PRIVATE void +net_IntSetCookieString(MWContext * context, + char * cur_url, + char * set_cookie_header, + time_t timeToExpire ) +{ + net_CookieStruct * prev_cookie; + char *path_from_header=NULL, *host_from_header=NULL; + char *host_from_header2=NULL; + char *name_from_header=NULL, *cookie_from_header=NULL; + time_t expires=0; + char *cur_path = NET_ParseURL(cur_url, GET_PATH_PART); + char *cur_host = NET_ParseURL(cur_url, GET_HOST_PART); + char *semi_colon, *ptr, *equal; + PRBool HG83744 is_domain=FALSE, accept=FALSE; + MWContextType type; + Bool bCookieAdded; + + if(!context) { + PR_Free(cur_path); + PR_Free(cur_host); + return; + } + + /* Only allow cookies to be set in the listed contexts. We + * don't want cookies being set in html mail. + */ + type = context->type; + if(!( (type == MWContextBrowser) + || (type == MWContextHTMLHelp) + || (type == MWContextPane) )) { + PR_Free(cur_path); + PR_Free(cur_host); + return; + } + + if(NET_GetCookieBehaviorPref() == NET_DontUse) { + PR_Free(cur_path); + PR_Free(cur_host); + return; + } + + /* Don't enter this routine if it is already in use by another + thread. Otherwise the "remember this decision" result of the + other cookie (which came first) won't get applied to this cookie. + */ + if (net_IntSetCookieStringInUse) { + PR_Free(cur_path); + PR_Free(cur_host); + net_DeferCookie(context, cur_url, set_cookie_header, timeToExpire); + return; + } + net_IntSetCookieStringInUse = TRUE; + + HG87358 + /* terminate at any carriage return or linefeed */ + for(ptr=set_cookie_header; *ptr; ptr++) + if(*ptr == LF || *ptr == CR) { + *ptr = '\0'; + break; + } + + /* parse path and expires attributes from header if + * present + */ + semi_colon = PL_strchr(set_cookie_header, ';'); + + if(semi_colon) + { + /* truncate at semi-colon and advance + */ + *semi_colon++ = '\0'; + + /* there must be some attributes. (hopefully) + */ + HG83476 + + /* look for the path attribute + */ + ptr = PL_strcasestr(semi_colon, "path="); + + if(ptr) { + /* allocate more than we need */ + StrAllocCopy(path_from_header, XP_StripLine(ptr+5)); + /* terminate at first space or semi-colon + */ + for(ptr=path_from_header; *ptr != '\0'; ptr++) + if(NET_IS_SPACE(*ptr) || *ptr == ';' || *ptr == ',') { + *ptr = '\0'; + break; + } + } + + /* look for the URI or URL attribute + * + * This might be a security hole so I'm removing + * it for now. + */ + + /* look for a domain */ + ptr = PL_strcasestr(semi_colon, "domain="); + + if(ptr) { + char *domain_from_header=NULL; + char *dot, *colon; + int domain_length, cur_host_length; + + /* allocate more than we need */ + StrAllocCopy(domain_from_header, XP_StripLine(ptr+7)); + + /* terminate at first space or semi-colon + */ + for(ptr=domain_from_header; *ptr != '\0'; ptr++) + if(NET_IS_SPACE(*ptr) || *ptr == ';' || *ptr == ',') { + *ptr = '\0'; + break; + } + + /* verify that this host has the authority to set for + * this domain. We do this by making sure that the + * host is in the domain + * We also require that a domain have at least two + * periods to prevent domains of the form ".com" + * and ".edu" + * + * Also make sure that there is more stuff after + * the second dot to prevent ".com." + */ + dot = PL_strchr(domain_from_header, '.'); + if(dot) + dot = PL_strchr(dot+1, '.'); + + if(!dot || *(dot+1) == '\0') { + /* did not pass two dot test. FAIL + */ + PR_Free(domain_from_header); + PR_Free(cur_path); + PR_Free(cur_host); + TRACEMSG(("DOMAIN failed two dot test")); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; + } + + /* strip port numbers from the current host + * for the domain test + */ + colon = PL_strchr(cur_host, ':'); + if(colon) + *colon = '\0'; + + domain_length = PL_strlen(domain_from_header); + cur_host_length = PL_strlen(cur_host); + + /* check to see if the host is in the domain + */ + if(domain_length > cur_host_length + || PL_strcasecmp(domain_from_header, + &cur_host[cur_host_length-domain_length])) + { + TRACEMSG(("DOMAIN failed host within domain test." + " Domain: %s, Host: %s", domain_from_header, cur_host)); + PR_Free(domain_from_header); + PR_Free(cur_path); + PR_Free(cur_host); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; + } + +/* + * check that portion of host not in domain does not contain a dot + * This satisfies the fourth requirement in section 4.3.2 of the cookie + * spec rfc 2109 (see www.cis.ohio-state.edu/htbin/rfc/rfc2109.html). + * It prevents host of the form x.y.co.nz from setting cookies in the + * entire .co.nz domain. Note that this doesn't really solve the problem, + * it justs makes it more unlikely. Sites such as y.co.nz can still set + * cookies for the entire .co.nz domain. + */ + + cur_host[cur_host_length-domain_length] = '\0'; + dot = XP_STRCHR(cur_host, '.'); + cur_host[cur_host_length-domain_length] = '.'; + if (dot) { + TRACEMSG(("host minus domain failed no-dot test." + " Domain: %s, Host: %s", domain_from_header, cur_host)); + PR_Free(domain_from_header); + PR_Free(cur_path); + PR_Free(cur_host); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; + } + + /* all tests passed, copy in domain to hostname field + */ + StrAllocCopy(host_from_header, domain_from_header); + is_domain = TRUE; + + TRACEMSG(("Accepted domain: %s", host_from_header)); + + PR_Free(domain_from_header); + } + + /* now search for the expires header + * NOTE: that this part of the parsing + * destroys the original part of the string + */ + ptr = PL_strcasestr(semi_colon, "expires="); + + if(ptr) { + char *date = ptr+8; + /* terminate the string at the next semi-colon + */ + for(ptr=date; *ptr != '\0'; ptr++) + if(*ptr == ';') { + *ptr = '\0'; + break; + } + if(timeToExpire) + expires = timeToExpire; + else + expires = NET_ParseDate(date); + + TRACEMSG(("Have expires date: %ld", expires)); + } + } + + if(!path_from_header) { + /* strip down everything after the last slash + * to get the path. + */ + char * slash = PL_strrchr(cur_path, '/'); + if(slash) + *slash = '\0'; + + path_from_header = cur_path; + } else { + PR_Free(cur_path); + } + + if(!host_from_header) + host_from_header = cur_host; + else + PR_Free(cur_host); + + /* keep cookies under the max bytes limit */ + if(PL_strlen(set_cookie_header) > MAX_BYTES_PER_COOKIE) + set_cookie_header[MAX_BYTES_PER_COOKIE-1] = '\0'; + + /* separate the name from the cookie */ + equal = PL_strchr(set_cookie_header, '='); + + if(equal) { + *equal = '\0'; + StrAllocCopy(name_from_header, XP_StripLine(set_cookie_header)); + StrAllocCopy(cookie_from_header, XP_StripLine(equal+1)); + } else { + TRACEMSG(("Warning: no name found for cookie")); + StrAllocCopy(cookie_from_header, XP_StripLine(set_cookie_header)); + StrAllocCopy(name_from_header, ""); + } + + net_CookiePermissionStruct * cookie_permission; + cookie_permission = net_CheckForCookiePermission(host_from_header); + if (cookie_permission != NULL) { + if (cookie_permission->permission == FALSE) { + PR_FREEIF(path_from_header); + PR_FREEIF(host_from_header); + PR_FREEIF(name_from_header); + PR_FREEIF(cookie_from_header); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; + } else { + accept = TRUE; + } + } + + + if( (NET_GetCookieWarningPref() ) && !accept ) { + /* the user wants to know about cookies so let them + * know about every one that is set and give them + * the choice to accept it or not + */ + char * new_string=0; + int count; + +// ??? char * remember_string = cookie_Localize("RememberThisDecision"); + char * remember_string = 0; + StrAllocCopy + (remember_string, XP_GetString(MK_ACCESS_COOKIES_REMEMBER)); + + /* find out how many cookies this host has already set */ + count = net_CookieCount(host_from_header); + net_lock_cookie_list(); + prev_cookie = net_CheckForPrevCookie + (path_from_header, host_from_header, name_from_header); + net_unlock_cookie_list(); + char * message; + if (prev_cookie) { +// ??? message = cookie_Localize("PermissionToModifyCookie"); + message = XP_GetString(MK_ACCESS_COOKIES_WISHES_MODIFY); + new_string = PR_smprintf(message, + host_from_header ? host_from_header : ""); + } else if (count>1) { +// ??? message = cookie_Localize("PermissionToSetAnotherCookie"); + message = XP_GetString(MK_ACCESS_COOKIES_WISHESN); + new_string = PR_smprintf(message, + host_from_header ? host_from_header : "", + count); + } else if (count==1){ +// ??? message = cookie_Localize("PermissionToSetSecondCookie"); + message = XP_GetString(MK_ACCESS_COOKIES_WISHES1); + new_string = PR_smprintf(message, + host_from_header ? host_from_header : ""); + } else { +// ??? message = cookie_Localize("PermissionToSetACookie"); + message = XP_GetString(MK_ACCESS_COOKIES_WISHES0); + new_string = PR_smprintf(message, + host_from_header ? host_from_header : ""); + } +// ??? PR_FREEIF(message); + + + /* + * Who knows what thread we are on. Only the mozilla thread + * is allowed to post dialogs so, if need be, go over there + */ + + { + Bool old_cookie_remember_checked = cookie_remember_checked; + XP_Bool userHasAccepted = ET_PostCheckConfirmBox + (context, + new_string, + remember_string, + 0,0, + &cookie_remember_checked); + PR_FREEIF(new_string); + PR_FREEIF(remember_string); + if (cookie_remember_checked) { + net_CookiePermissionStruct * cookie_permission; + cookie_permission = PR_NEW(net_CookiePermissionStruct); + if (cookie_permission) { + net_lock_cookie_permission_list(); + StrAllocCopy(host_from_header2, host_from_header); + /* ignore leading periods in host name */ + while (host_from_header2 && (*host_from_header2 == '.')) { + host_from_header2++; + } + cookie_permission->host = host_from_header2; /* set host string */ + cookie_permission->permission = userHasAccepted; + net_AddCookiePermission(cookie_permission, TRUE); + net_unlock_cookie_permission_list(); + } + } + + if (old_cookie_remember_checked != cookie_remember_checked) { + cookie_permissions_changed = TRUE; + net_SaveCookiePermissions(NULL); + } + + + if (!userHasAccepted) { + return; + } + } + } + + TRACEMSG(("mkaccess.c: Setting cookie: %s for host: %s for path: %s", + cookie_from_header, host_from_header, path_from_header)); + + /* + * We have decided we are going to insert a cookie into the list + * Get the cookie lock so that we can munge on the list + */ + net_lock_cookie_list(); + + /* limit the number of cookies from a specific host or domain */ + net_CheckForMaxCookiesFromHost(host_from_header); + + if(XP_ListCount(net_cookie_list) > MAX_NUMBER_OF_COOKIES-1) + net_remove_oldest_cookie(); + + + prev_cookie = net_CheckForPrevCookie + (path_from_header, host_from_header, name_from_header); + + if(prev_cookie) { + prev_cookie->expires = expires; + PR_FREEIF(prev_cookie->cookie); + PR_FREEIF(prev_cookie->path); + PR_FREEIF(prev_cookie->host); + PR_FREEIF(prev_cookie->name); + prev_cookie->cookie = cookie_from_header; + prev_cookie->path = path_from_header; + prev_cookie->host = host_from_header; + prev_cookie->name = name_from_header; + HG83263 + prev_cookie->is_domain = is_domain; + prev_cookie->last_accessed = time(NULL); + } else { + XP_List * list_ptr = net_cookie_list; + net_CookieStruct * tmp_cookie_ptr; + size_t new_len; + + /* construct a new cookie_struct + */ + prev_cookie = PR_NEW(net_CookieStruct); + if(!prev_cookie) { + PR_FREEIF(path_from_header); + PR_FREEIF(host_from_header); + PR_FREEIF(name_from_header); + PR_FREEIF(cookie_from_header); + net_unlock_cookie_list(); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; + } + + /* copy + */ + prev_cookie->cookie = cookie_from_header; + prev_cookie->name = name_from_header; + prev_cookie->path = path_from_header; + prev_cookie->host = host_from_header; + prev_cookie->expires = expires; + HG22730 + prev_cookie->is_domain = is_domain; + prev_cookie->last_accessed = time(NULL); + + if(!net_cookie_list) { + net_cookie_list = XP_ListNew(); + if(!net_cookie_list) { + PR_FREEIF(path_from_header); + PR_FREEIF(name_from_header); + PR_FREEIF(host_from_header); + PR_FREEIF(cookie_from_header); + PR_Free(prev_cookie); + net_unlock_cookie_list(); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; + } + } + + /* add it to the list so that it is before any strings of + * smaller length + */ + bCookieAdded = FALSE; + new_len = PL_strlen(prev_cookie->path); + while((tmp_cookie_ptr = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) { + if(new_len > PL_strlen(tmp_cookie_ptr->path)) { + XP_ListInsertObject(net_cookie_list, tmp_cookie_ptr, prev_cookie); + bCookieAdded = TRUE; + break; + } + } + if ( !bCookieAdded ) { + /* no shorter strings found in list */ + XP_ListAddObjectToEnd(net_cookie_list, prev_cookie); + } + } + + /* At this point we know a cookie has changed. Write the cookies to file. */ + cookies_changed = TRUE; + NET_SaveCookies(NULL); + net_unlock_cookie_list(); + net_IntSetCookieStringInUse = FALSE; + net_UndeferCookies(); + return; +} + +PUBLIC void +NET_SetCookieString(MWContext * context, + char * cur_url, + char * set_cookie_header) { + net_IntSetCookieString(context, cur_url, set_cookie_header, 0); +} + +/* Determines whether the inlineHost is in the same domain as the currentHost. For use with rfc 2109 + * compliance/non-compliance. */ +PRIVATE int +NET_SameDomain(char * currentHost, char * inlineHost) +{ + char * dot = 0; + char * currentDomain = 0; + char * inlineDomain = 0; + + if(!currentHost || !inlineHost) + return 0; + + /* case insensitive compare */ + if(PL_strcasecmp(currentHost, inlineHost) == 0) + return 1; + + currentDomain = PL_strchr(currentHost, '.'); + inlineDomain = PL_strchr(inlineHost, '.'); + + if(!currentDomain || !inlineDomain) + return 0; + + /* check for at least two dots before continuing, if there are + not two dots we don't have enough information to determine + whether or not the inlineDomain is within the currentDomain */ + dot = PL_strchr(inlineDomain, '.'); + if(dot) + dot = PL_strchr(dot+1, '.'); + else + return 0; + + /* handle .com. case */ + if(!dot || (*(dot+1) == '\0') ) + return 0; + + if(!PL_strcasecmp(inlineDomain, currentDomain)) + return 1; + return 0; +} + +/* This function wrapper wraps NET_SetCookieString for the purposes of +** determining whether or not a cookie is inline (we need the URL struct, +** and outputFormat to do so). this is called from NET_ParseMimeHeaders +** in mkhttp.c +** This routine does not need to worry about the cookie lock since all of +** the work is handled by sub-routines +*/ +PUBLIC void +NET_SetCookieStringFromHttp(FO_Present_Types outputFormat, + URL_Struct * URL_s, + MWContext * context, + char * cur_url, + char * set_cookie_header) +{ + /* If the outputFormat is not PRESENT (the url is not going to the screen), and not + * SAVE AS (shift-click) then + * the cookie being set is defined as inline so we need to do what the user wants us + * to based on his preference to deal with foreign cookies. If it's not inline, just set + * the cookie. */ + char *ptr=NULL, *date=NULL; + time_t gmtCookieExpires=0, expires=0; + + if(CLEAR_CACHE_BIT(outputFormat) != FO_PRESENT && CLEAR_CACHE_BIT(outputFormat) != FO_SAVE_AS) + { + if (NET_GetCookieBehaviorPref() == NET_DontAcceptForeign) + { + /* the user doesn't want foreign cookies, check to see if its foreign */ + char * curSessionHistHost = 0; + char * theColon = 0; + char * curHost = NET_ParseURL(cur_url, GET_HOST_PART); + History_entry * shistEntry = SHIST_GetCurrent(&context->hist); + if (shistEntry) { + curSessionHistHost = NET_ParseURL(shistEntry->address, GET_HOST_PART); + } + if(!curHost || !curSessionHistHost) + { + PR_FREEIF(curHost); + PR_FREEIF(curSessionHistHost); + return; + } + + /* strip ports */ + theColon = PL_strchr(curHost, ':'); + if(theColon) + *theColon = '\0'; + theColon = PL_strchr(curSessionHistHost, ':'); + if(theColon) + *theColon = '\0'; + + /* if it's foreign, get out of here after a little clean up */ + if(!NET_SameDomain(curHost, curSessionHistHost)) + { + PR_FREEIF(curHost); + PR_FREEIF(curSessionHistHost); + return; + } + PR_FREEIF(curHost); + PR_FREEIF(curSessionHistHost); + } + } + + /* Determine when the cookie should expire. This is done by taking the difference between + the server time and the time the server wants the cookie to expire, and adding that + difference to the client time. This localizes the client time regardless of whether or + not the TZ environment variable was set on the client. */ + + /* Get the time the cookie is supposed to expire according to the attribute*/ + ptr = PL_strcasestr(set_cookie_header, "expires="); + if(ptr) + { + char *date = ptr+8; + char origLast = '\0'; + for(ptr=date; *ptr != '\0'; ptr++) + if(*ptr == ';') + { + origLast = ';'; + *ptr = '\0'; + break; + } + expires = NET_ParseDate(date); + *ptr=origLast; + } + if( URL_s->server_date && expires ) + { + if( expires < URL_s->server_date ) + { + gmtCookieExpires=1; + } + else + { + gmtCookieExpires = expires - URL_s->server_date + time(NULL); + /* if overflow */ + if( gmtCookieExpires < time(NULL) ) + gmtCookieExpires = (((unsigned) (~0) << 1) >> 1); /* max int */ + } + } + + net_IntSetCookieString(context, cur_url, set_cookie_header, gmtCookieExpires); +} + +/* saves the HTTP cookies permissions to disk + * the parameter passed in on entry is ignored + * returns 0 on success -1 on failure. + */ +PRIVATE int +net_SaveCookiePermissions(char * filename) +{ + XP_List * list_ptr; + net_CookiePermissionStruct * cookie_permission_s; + XP_File fp; + int32 len = 0; + + if(NET_GetCookieBehaviorPref() == NET_DontUse) { + return(-1); + } + + if(!cookie_permissions_changed) { + return(-1); + } + + net_lock_cookie_permission_list(); + list_ptr = net_cookie_permission_list; + + if(!(net_cookie_permission_list)) { + net_unlock_cookie_permission_list(); + return(-1); + } + + if(!(fp = NET_XP_FileOpen(filename, xpHTTPCookiePermission, XP_FILE_WRITE))) { + net_unlock_cookie_permission_list(); + return(-1); + } + len = NET_XP_FileWrite("# Netscape HTTP Cookie Permission File" LINEBREAK + "# http://www.netscape.com/newsref/std/cookie_spec.html" + LINEBREAK "# This is a generated file! Do not edit." + LINEBREAK LINEBREAK, -1, fp); + + if (len < 0) { + NET_XP_FileClose(fp); + net_unlock_cookie_permission_list(); + return -1; + } + + /* format shall be: + * host \t permission + */ + while((cookie_permission_s = (net_CookiePermissionStruct *) + XP_ListNextObject(list_ptr)) != NULL) { + len = NET_XP_FileWrite(cookie_permission_s->host, -1, fp); + if (len < 0) { + NET_XP_FileClose(fp); + net_unlock_cookie_permission_list(); + return -1; + } + + NET_XP_FileWrite("\t", 1, fp); + + if(cookie_permission_s->permission) { + NET_XP_FileWrite("TRUE", -1, fp); + } else { + NET_XP_FileWrite("FALSE", -1, fp); + } + + len = NET_XP_FileWrite(LINEBREAK, -1, fp); + if (len < 0) { + NET_XP_FileClose(fp); + net_unlock_cookie_permission_list(); + return -1; + } + } + + /* save current state of cookie nag-box's checkmark */ + NET_XP_FileWrite("@@@@", -1, fp); + NET_XP_FileWrite("\t", 1, fp); + if (cookie_remember_checked) { + NET_XP_FileWrite("TRUE", -1, fp); + } else { + NET_XP_FileWrite("FALSE", -1, fp); + } + NET_XP_FileWrite(LINEBREAK, -1, fp); + + cookie_permissions_changed = FALSE; + NET_XP_FileClose(fp); + net_unlock_cookie_permission_list(); + return(0); +} + +/* reads the HTTP cookies permission from disk + * the parameter passed in on entry is ignored + * returns 0 on success -1 on failure. + * + */ +#define PERMISSION_LINE_BUFFER_SIZE 4096 + +PRIVATE int +net_ReadCookiePermissions(char * filename) +{ + XP_File fp; + char buffer[PERMISSION_LINE_BUFFER_SIZE]; + char *host, *p; + Bool permission_value; + net_CookiePermissionStruct * cookie_permission; + char *host_from_header2; + + if(!(fp = NET_XP_FileOpen(filename, xpHTTPCookiePermission, XP_FILE_READ))) + return(-1); + + /* format is: + * host \t permission + * if this format isn't respected we move onto the next line in the file. + */ + + net_lock_cookie_permission_list(); + while(NET_XP_FileReadLine(buffer, PERMISSION_LINE_BUFFER_SIZE, fp)) { + if (*buffer == '#' || *buffer == CR || *buffer == LF || *buffer == 0) { + continue; + } + + XP_StripLine(buffer); /* remove '\n' from end of the line */ + + host = buffer; + /* isolate the host field which is the first field on the line */ + if( !(p = PL_strchr(host, '\t')) ) { + continue; /* no permission field */ + } + *p++ = '\0'; + if(*p == CR || *p == LF || *p == 0) { + continue; /* no permission field */ + } + + /* ignore leading periods in host name */ + while (host && (*host == '.')) { + host++; + } + + /* + * the first part of the permission file is valid - + * allocate a new permission struct and fill it in + */ + cookie_permission = PR_NEW(net_CookiePermissionStruct); + if (cookie_permission) { + host_from_header2 = PL_strdup(host); + cookie_permission->host = host_from_header2; + + /* + * Now handle the permission field. + * a host value of "@@@@" is a special code designating the + * state of the cookie nag-box's checkmark + */ + permission_value = (!PL_strncmp(p, "TRUE", sizeof("TRUE")-1)); + if (!PL_strcmp(host, "@@@@")) { + cookie_remember_checked = permission_value; + } else { + cookie_permission->permission = permission_value; + + + /* add the permission entry */ + net_AddCookiePermission( cookie_permission, FALSE ); + } + } /* end if (cookie_permission) */ + } /* while(NET_XP_FileReadLine( */ + + net_unlock_cookie_permission_list(); + NET_XP_FileClose(fp); + cookie_permissions_changed = FALSE; + return(0); +} + +/* saves out the HTTP cookies to disk + * + * on entry pass in the name of the file to save + * + * returns 0 on success -1 on failure. + * + */ +PUBLIC int +NET_SaveCookies(char * filename) +{ + XP_List * list_ptr; + net_CookieStruct * cookie_s; + time_t cur_date = time(NULL); + XP_File fp; + int32 len = 0; + char date_string[36]; + + if(NET_GetCookieBehaviorPref() == NET_DontUse) + return(-1); + + if(!cookies_changed) + return(-1); + + net_lock_cookie_list(); + list_ptr = net_cookie_list; + if(!(list_ptr)) { + net_unlock_cookie_list(); + return(-1); + } + + if(!(fp = NET_XP_FileOpen(filename, xpHTTPCookie, XP_FILE_WRITE))) { + net_unlock_cookie_list(); + return(-1); + } + + len = NET_XP_FileWrite("# Netscape HTTP Cookie File" LINEBREAK + "# http://www.netscape.com/newsref/std/cookie_spec.html" + LINEBREAK "# This is a generated file! Do not edit." + LINEBREAK LINEBREAK, + -1, fp); + if (len < 0) + { + NET_XP_FileClose(fp); + net_unlock_cookie_list(); + return -1; + } + + /* format shall be: + * + * host \t is_domain \t path \t secure \t expires \t name \t cookie + * + * is_domain is TRUE or FALSE + * secure is TRUE or FALSE + * expires is a time_t integer + * cookie can have tabs + */ + while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr)) != NULL) + { + if(cookie_s->expires < cur_date) + continue; /* don't write entry if cookie has expired + * or has no expiration date + */ + + len = NET_XP_FileWrite(cookie_s->host, -1, fp); + if (len < 0) + { + NET_XP_FileClose(fp); + net_unlock_cookie_list(); + return -1; + } + NET_XP_FileWrite("\t", 1, fp); + + if(cookie_s->is_domain) + NET_XP_FileWrite("TRUE", -1, fp); + else + NET_XP_FileWrite("FALSE", -1, fp); + NET_XP_FileWrite("\t", 1, fp); + + NET_XP_FileWrite(cookie_s->path, -1, fp); + NET_XP_FileWrite("\t", 1, fp); + + HG74640 + NET_XP_FileWrite("FALSE", -1, fp); + NET_XP_FileWrite("\t", 1, fp); + + PR_snprintf(date_string, sizeof(date_string), "%lu", cookie_s->expires); + NET_XP_FileWrite(date_string, -1, fp); + NET_XP_FileWrite("\t", 1, fp); + + NET_XP_FileWrite(cookie_s->name, -1, fp); + NET_XP_FileWrite("\t", 1, fp); + + NET_XP_FileWrite(cookie_s->cookie, -1, fp); + len = NET_XP_FileWrite(LINEBREAK, -1, fp); + if (len < 0) + { + NET_XP_FileClose(fp); + net_unlock_cookie_list(); + return -1; + } + } + + cookies_changed = FALSE; + + NET_XP_FileClose(fp); + net_unlock_cookie_list(); + return(0); +} + +/* reads HTTP cookies from disk + * + * on entry pass in the name of the file to read + * + * returns 0 on success -1 on failure. + * + * + */ +#define LINE_BUFFER_SIZE 4096 + +PUBLIC int +NET_ReadCookies(char * filename) +{ + XP_List * list_ptr; + net_CookieStruct *new_cookie, *tmp_cookie_ptr; + size_t new_len; + XP_File fp; + char buffer[LINE_BUFFER_SIZE]; + char *host, *is_domain, *path, *xxx, *expires, *name, *cookie; + Bool added_to_list; + + net_ReadCookiePermissions(NULL); + + if(!(fp = NET_XP_FileOpen(filename, xpHTTPCookie, XP_FILE_READ))) + return(-1); + + net_lock_cookie_list(); + list_ptr = net_cookie_list; + + /* format is: + * + * host \t is_domain \t path \t xxx \t expires \t name \t cookie + * + * if this format isn't respected we move onto the next line in the file. + * is_domain is TRUE or FALSE -- defaulting to FALSE + * xxx is TRUE or FALSE -- should default to TRUE + * expires is a time_t integer + * cookie can have tabs + */ + while(NET_XP_FileReadLine(buffer, LINE_BUFFER_SIZE, fp)) + { + added_to_list = FALSE; + + if (*buffer == '#' || *buffer == CR || *buffer == LF || *buffer == 0) + continue; + + host = buffer; + + if( !(is_domain = PL_strchr(host, '\t')) ) + continue; + *is_domain++ = '\0'; + if(*is_domain == CR || *is_domain == LF || *is_domain == 0) + continue; + + if( !(path = PL_strchr(is_domain, '\t')) ) + continue; + *path++ = '\0'; + if(*path == CR || *path == LF || *path == 0) + continue; + + if( !(xxx = PL_strchr(path, '\t')) ) + continue; + *xxx++ = '\0'; + if(*xxx == CR || *xxx == LF || *xxx == 0) + continue; + + if( !(expires = PL_strchr(xxx, '\t')) ) + continue; + *expires++ = '\0'; + if(*expires == CR || *expires == LF || *expires == 0) + continue; + + if( !(name = PL_strchr(expires, '\t')) ) + continue; + *name++ = '\0'; + if(*name == CR || *name == LF || *name == 0) + continue; + + if( !(cookie = PL_strchr(name, '\t')) ) + continue; + *cookie++ = '\0'; + if(*cookie == CR || *cookie == LF || *cookie == 0) + continue; + + /* remove the '\n' from the end of the cookie */ + XP_StripLine(cookie); + + /* construct a new cookie_struct + */ + new_cookie = PR_NEW(net_CookieStruct); + if(!new_cookie) + { + net_unlock_cookie_list(); + return(-1); + } + + memset(new_cookie, 0, sizeof(net_CookieStruct)); + + /* copy + */ + StrAllocCopy(new_cookie->cookie, cookie); + StrAllocCopy(new_cookie->name, name); + StrAllocCopy(new_cookie->path, path); + StrAllocCopy(new_cookie->host, host); + new_cookie->expires = atol(expires); + + HG87365 + + if(!PL_strcmp(is_domain, "TRUE")) + new_cookie->is_domain = TRUE; + else + new_cookie->is_domain = FALSE; + + if(!net_cookie_list) + { + net_cookie_list = XP_ListNew(); + if(!net_cookie_list) + { + net_unlock_cookie_list(); + return(-1); + } + } + + /* add it to the list so that it is before any strings of + * smaller length + */ + new_len = PL_strlen(new_cookie->path); + while((tmp_cookie_ptr = (net_CookieStruct *) XP_ListNextObject(list_ptr)) != NULL) + { + if(new_len > PL_strlen(tmp_cookie_ptr->path)) + { + XP_ListInsertObject(net_cookie_list, tmp_cookie_ptr, new_cookie); + added_to_list = TRUE; + break; + } + } + + /* no shorter strings found in list */ + if(!added_to_list) + XP_ListAddObjectToEnd(net_cookie_list, new_cookie); + } + + NET_XP_FileClose(fp); + net_unlock_cookie_list(); + + cookies_changed = FALSE; + + return(0); +} + +#include "htmldlgs.h" + +extern "C" { +extern int XP_CERT_PAGE_STRINGS; +} +extern int SA_REMOVE_BUTTON_LABEL; + +/* return TRUE if "number" is in sequence of comma-separated numbers */ +Bool net_InSequence(char* sequence, int number) { + char* ptr; + char* endptr; + char* undo = NULL; + Bool retval = FALSE; + int i; + + /* not necessary -- routine will work even with null sequence */ + if (!*sequence) { + return FALSE; + } + + for (ptr = sequence ; ptr ; ptr = endptr) { + + /* get to next comma */ + endptr = PL_strchr(ptr, ','); + + /* if comma found, process it */ + if (endptr) { + + /* restore last comma-to-null back to comma */ + if (undo) { + *undo = ','; + } + + /* set the comma to a null */ + undo = endptr; + *endptr++ = '\0'; + + /* compare the number before the comma with "number" */ + if (*ptr) { + i = atoi(ptr); + if (i == number) { + + /* "number" was in the sequence so return TRUE */ + retval = TRUE; + break; + } + } + } + } + + /* restore last comma-to-null back to comma */ + if (undo) { + *undo = ','; + } + return retval; +} + +PR_STATIC_CALLBACK(PRBool) +net_AboutCookiesDialogDone(XPDialogState* state, char** argv, int argc, + unsigned int button) +{ + XP_List *list; + net_CookieStruct *cookie; + net_CookiePermissionStruct *cookiePermission; + char *buttonName; + int cookieNumber; + net_CookieStruct *cookieToDelete = 0; + net_CookiePermissionStruct *cookiePermissionToDelete = 0; + + char* gone; + + buttonName = XP_FindValueInArgs("button", argv, argc); + if (button != XP_DIALOG_OK_BUTTON) { + /* OK button not pressed (must be cancel button that was pressed) */ + return PR_FALSE; + } + + /* OK was pressed, do the deletions */ + + /* get the comma-separated sequence of cookies to be deleted */ + gone = XP_FindValueInArgs("goneC", argv, argc); + PR_ASSERT(gone); + if (!gone) { + return PR_FALSE; + } + + /* + * walk through the cookie list, deleting the designated cookies + * Note: we can't delete cookie while "list" is pointing to it because + * that would destroy "list". So we do a lazy deletion + */ + net_lock_cookie_list(); + list = net_cookie_list; + cookieNumber = 0; + while ( (cookie=(net_CookieStruct *) XP_ListNextObject(list)) ) { + if (net_InSequence(gone, cookieNumber)) { + if (cookieToDelete) { + net_FreeCookie(cookieToDelete); + } + cookieToDelete = cookie; + } + cookieNumber++; + } + + if (cookieToDelete) { + net_FreeCookie(cookieToDelete); + cookies_changed = TRUE; + NET_SaveCookies(NULL); + } + net_unlock_cookie_list(); + + /* get the comma-separated sequence of permissions to be deleted */ + gone = XP_FindValueInArgs("goneP", argv, argc); + PR_ASSERT(gone); + if (!gone) { + return PR_FALSE; + } + + /* + * walk through the cookie permission list, deleting the designated permissions + * Note: we can't delete permissions while "list" is pointing to it because + * that would destroy "list". So we do a lazy deletion + */ + net_lock_cookie_permission_list(); + list = net_cookie_permission_list; + cookieNumber = 0; + while ( (cookiePermission=(net_CookiePermissionStruct *) XP_ListNextObject(list)) ) { + if (net_InSequence(gone, cookieNumber)) { + if (cookiePermissionToDelete) { + net_FreeCookiePermission(cookiePermissionToDelete, TRUE); + } + cookiePermissionToDelete = cookiePermission; + } + cookieNumber++; + } + + if (cookiePermissionToDelete) { + net_FreeCookiePermission(cookiePermissionToDelete, TRUE); + cookie_permissions_changed = TRUE; + net_SaveCookiePermissions(NULL); + } + + net_unlock_cookie_permission_list(); + return PR_FALSE; +} + +PRIVATE Bool +CookieCompare (net_CookieStruct * cookie1, net_CookieStruct * cookie2) { + char * host1 = cookie1->host; + char * host2 = cookie2->host; + + /* get rid of leading period on host name, if any */ + if (*host1 == '.') { + host1++; + } + if (*host2 == '.') { + host2++; + } + + /* make decision based on host name if they are unequal */ + if (PL_strcmp (host1, host2) < 0) { + return -1; + } + if (PL_strcmp (host1, host2) > 0) { + return 1; + } + + /* if host names are equal, make decision based on cookie name */ + return (PL_strcmp (cookie1->name, cookie2->name)); +} + +/* + * find the next cookie that is alphabetically after the specified cookie + * ordering is based on hostname and the cookie name + * if specified cookie is NULL, find the first cookie alphabetically + */ +PRIVATE net_CookieStruct * +NextCookieAfter(net_CookieStruct * cookie, int * cookieNum) { + XP_List *cookie_list=net_cookie_list; + net_CookieStruct *cookie_ptr; + net_CookieStruct *lowestCookie = NULL; + int localCookieNum = 0; + int lowestCookieNum; + + while ( (cookie_ptr=(net_CookieStruct *) XP_ListNextObject(cookie_list)) ) { + if (!cookie || (CookieCompare(cookie_ptr, cookie) > 0)) { + if (!lowestCookie || + (CookieCompare(cookie_ptr, lowestCookie) < 0)) { + lowestCookie = cookie_ptr; + lowestCookieNum = localCookieNum; + } + } + localCookieNum++; + } + + *cookieNum = lowestCookieNum; + return lowestCookie; +} + +typedef struct _CookieViewerDialog CookieViewerDialog; + +struct _CookieViewerDialog { + void *window; + void *parent_window; + PRBool dialogUp; + XPDialogState *state; +}; + +/* + * return a string that has each " of the argument sting + * replaced with \" so it can be used inside a quoted string + */ +PRIVATE char* +net_FixQuoted(char* s) { + char * result; + int count = PL_strlen(s); + char *quote = s; + unsigned int i, j; + while (quote = PL_strchr(quote, '"')) { + count = count++; + quote++; + } + result = (char*)XP_ALLOC(count + 1); + for (i=0, j=0; i= 0); + if (start < 0) { + return nsAutoString("").ToNewCString(); + } + start += PL_strlen(name); /* get passed the |name| part */ + length = results.Find('|', start) - start; + results.Mid(value, start, length); + return value.ToNewCString(); +} + +PUBLIC void +COOKIE_CookieViewerReturn(nsAutoString results) +{ + XP_List *cookie_ptr; + XP_List *permission_ptr; + net_CookieStruct * cookie; + net_CookieStruct * cookieToDelete = 0; + net_CookiePermissionStruct * permission; + net_CookiePermissionStruct * permissionToDelete = 0; + int cookieNumber; + int permissionNumber; + + /* step through all cookies and delete those that are in the sequence + * Note: we can't delete cookie while "cookie_ptr" is pointing to it because + * that would destroy "cookie_ptr". So we do a lazy deletion + */ + char * gone = cookie_FindValueInArgs(results, "|goneC|"); + cookieNumber = 0; + net_lock_cookie_list(); + cookie_ptr = net_cookie_list; + while ((cookie = (net_CookieStruct *) XP_ListNextObject(cookie_ptr))) { + if (cookie_InSequence(gone, cookieNumber)) { + if (cookieToDelete) { + net_FreeCookie(cookieToDelete); + } + cookieToDelete = cookie; + } + cookieNumber++; + } + if (cookieToDelete) { + net_FreeCookie(cookieToDelete); + NET_SaveCookies(NULL); + } + net_unlock_cookie_list(); + delete[] gone; + + /* step through all permissions and delete those that are in the sequence + * Note: we can't delete permission while "permission_ptr" is pointing to it because + * that would destroy "permission_ptr". So we do a lazy deletion + */ + gone = cookie_FindValueInArgs(results, "|goneP|"); + permissionNumber = 0; + net_lock_cookie_permission_list(); + permission_ptr = net_cookie_permission_list; + while ((permission = (net_CookiePermissionStruct *) XP_ListNextObject(permission_ptr))) { + if (cookie_InSequence(gone, permissionNumber)) { + if (permissionToDelete) { + net_FreeCookiePermission(permissionToDelete, PR_FALSE); + } + permissionToDelete = permission; + } + permissionNumber++; + } + if (permissionToDelete) { + net_FreeCookiePermission(permissionToDelete, PR_TRUE); + } + net_unlock_cookie_permission_list(); + delete[] gone; +} + +#define BUFLEN2 5000 +#define BREAK '\001' + +PUBLIC void +COOKIE_GetCookieListForViewer(nsString& aCookieList) +{ + char *buffer = (char*)XP_ALLOC(BUFLEN2); + int g = 0, cookieNum; + XP_List *cookie_ptr; + net_CookieStruct * cookie; + + net_lock_cookie_list(); + buffer[0] = '\0'; + cookie_ptr = net_cookie_list; + cookieNum = 0; + + /* generate the list of cookies in alphabetical order */ + cookie = NULL; + while (cookie = NextCookieAfter(cookie, &cookieNum)) { + char *fixed_name = net_FixQuoted(cookie->name); + char *fixed_value = net_FixQuoted(cookie->cookie); + char *fixed_domain_or_host = net_FixQuoted(cookie->host); + char *fixed_path = net_FixQuoted(cookie->path); + char * Domain = cookie_Localize("Domain"); + char * Host = cookie_Localize("Host"); + char * Yes = cookie_Localize("Yes"); + char * No = cookie_Localize("No"); + char * AtEnd = cookie_Localize("AtEndOfSession"); + + g += PR_snprintf(buffer+g, BUFLEN2-g, + "%c%d%c%s%c%s%c%s%c%s%c%s%c%s%c%s", + BREAK, cookieNum, + BREAK, fixed_name, + BREAK, fixed_value, + BREAK, cookie->is_domain ? Domain : Host, + BREAK, fixed_domain_or_host, + BREAK, fixed_path, + BREAK, HG78111 ? Yes : No, + BREAK, cookie->expires ? ctime(&(cookie->expires)) : AtEnd + ); + cookieNum++; + PR_FREEIF(fixed_name); + PR_FREEIF(fixed_value); + PR_FREEIF(fixed_domain_or_host); + PR_FREEIF(fixed_path); + PR_FREEIF(Domain); + PR_FREEIF(Host); + PR_FREEIF(Yes); + PR_FREEIF(No); + PR_FREEIF(AtEnd); + } + aCookieList = buffer; + PR_FREEIF(buffer); + net_unlock_cookie_list(); +} + +PUBLIC void +COOKIE_GetPermissionListForViewer(nsString& aPermissionList) +{ + char *buffer = (char*)XP_ALLOC(BUFLEN2); + int g = 0, permissionNum; + XP_List *permission_ptr; + net_CookiePermissionStruct * permission; + + net_lock_cookie_permission_list(); + buffer[0] = '\0'; + permission_ptr = net_cookie_permission_list; + permissionNum = 0; + while ( (permission=(net_CookiePermissionStruct *) XP_ListNextObject(permission_ptr)) ) { + g += PR_snprintf(buffer+g, BUFLEN2-g, + "%c%d%c%c%s", + BREAK, + permissionNum, + BREAK, + permission->permission ? '+' : '-', + permission->host + ); + permissionNum++; + } + aPermissionList = buffer; + PR_FREEIF(buffer); + net_unlock_cookie_permission_list(); +} diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index 1e81dc405be..b04d40fb8ea 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -641,7 +641,7 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID) kINetServiceIID, (nsISupports **)&netservice); if ((NS_OK == res) && (nsnull != netservice)) { - res = netservice->NET_DisplayCookieInfoAsHTML(); + res = netservice->Cookie_DisplayCookieInfoAsHTML(); NS_RELEASE(netservice); } break; diff --git a/mozilla/xpfe/AppCores/idl/BrowserAppCore.idl b/mozilla/xpfe/AppCores/idl/BrowserAppCore.idl index 1fa02501a02..89686fa0bc2 100644 --- a/mozilla/xpfe/AppCores/idl/BrowserAppCore.idl +++ b/mozilla/xpfe/AppCores/idl/BrowserAppCore.idl @@ -15,7 +15,6 @@ interface BrowserAppCore : BaseAppCore void walletChangePassword(); void walletQuickFillin(in Window win); void walletSamples(); - void cookieViewer(); void setToolbarWindow(in Window win); void setContentWindow(in Window win); diff --git a/mozilla/xpfe/AppCores/idl/CookieCore.idl b/mozilla/xpfe/AppCores/idl/CookieCore.idl new file mode 100644 index 00000000000..4779ae89c93 --- /dev/null +++ b/mozilla/xpfe/AppCores/idl/CookieCore.idl @@ -0,0 +1,15 @@ +interface CookieCore : BaseAppCore +{ + void CookieCore(); + + void ShowWindow(in Window currentFrontWin); + + void ChangePanel(in wstring url); + void PanelLoaded(in Window win); + + void SaveCookie(in wstring results); + void CancelCookie(); + + wstring GetCookieList(); + wstring GetPermissionList(); +}; diff --git a/mozilla/xpfe/AppCores/idl/makefile.win b/mozilla/xpfe/AppCores/idl/makefile.win index c6a9aab1748..88373875fb3 100644 --- a/mozilla/xpfe/AppCores/idl/makefile.win +++ b/mozilla/xpfe/AppCores/idl/makefile.win @@ -36,6 +36,7 @@ IDLSRCS= \ EditorAppCore.idl \ PrefsCore.idl \ SignonCore.idl \ + CookieCore.idl \ WalletCore.idl \ RDFCore.idl \ Toolbar.idl \ diff --git a/mozilla/xpfe/AppCores/public/Makefile.in b/mozilla/xpfe/AppCores/public/Makefile.in index fcc9ba6c808..cdfce29d111 100644 --- a/mozilla/xpfe/AppCores/public/Makefile.in +++ b/mozilla/xpfe/AppCores/public/Makefile.in @@ -30,6 +30,7 @@ EXPORTS = \ nsIDOMEditorAppCore.h \ nsIDOMPrefsCore.h \ nsIDOMSignonCore.h \ + nsIDOMCookieCore.h \ nsIDOMWalletCore.h \ nsIDOMProfileCore.h \ nsIDOMRDFCore.h \ diff --git a/mozilla/xpfe/AppCores/public/makefile.win b/mozilla/xpfe/AppCores/public/makefile.win index 785c8399a41..104536702cf 100644 --- a/mozilla/xpfe/AppCores/public/makefile.win +++ b/mozilla/xpfe/AppCores/public/makefile.win @@ -27,6 +27,7 @@ EXPORTS= \ nsIDOMDOMPropsCore.h \ nsIDOMPrefsCore.h \ nsIDOMSignonCore.h \ + nsIDOMCookieCore.h \ nsIDOMWalletCore.h \ nsIDOMProfileCore.h \ nsIDOMRDFCore.h \ diff --git a/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h b/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h index 9d80b3fd277..a3d8659c88a 100644 --- a/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h +++ b/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h @@ -31,6 +31,11 @@ 0x96a79e90, 0xe30, 0x11d3, { 0xab, 0x9f, 0x0, 0x80, 0xc7, 0x87, 0xad, 0x96} \ } +#define NS_COOKIECORE_CID \ +{ /* {76C2DCD0-191F-11d3-ABA7-0080C787AD96 */ \ + 0x76c2dcd0, 0x191f, 0x11d3, { 0xab, 0xa7, 0x0, 0x80, 0xc7, 0x87, 0xad, 0x96} \ +} + #define NS_WALLETCORE_CID \ { /* {9D6E2541-108B-11d3-ABA3-0080C787AD96 */ \ 0x9d6e2541, 0x108b, 0x11d3, { 0xab, 0xa3, 0x0, 0x80, 0xc7, 0x87, 0xad, 0x96} \ diff --git a/mozilla/xpfe/AppCores/public/nsIDOMBrowserAppCore.h b/mozilla/xpfe/AppCores/public/nsIDOMBrowserAppCore.h index f59e859df35..db2c3b60c03 100644 --- a/mozilla/xpfe/AppCores/public/nsIDOMBrowserAppCore.h +++ b/mozilla/xpfe/AppCores/public/nsIDOMBrowserAppCore.h @@ -53,8 +53,6 @@ public: NS_IMETHOD WalletSamples()=0; - NS_IMETHOD CookieViewer()=0; - NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin)=0; NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin)=0; @@ -91,7 +89,6 @@ public: NS_IMETHOD WalletChangePassword(); \ NS_IMETHOD WalletQuickFillin(nsIDOMWindow* aWin); \ NS_IMETHOD WalletSamples(); \ - NS_IMETHOD CookieViewer(); \ NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \ NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \ NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin); \ @@ -117,7 +114,6 @@ public: NS_IMETHOD WalletChangePassword() { return _to WalletChangePassword(); } \ NS_IMETHOD WalletQuickFillin(nsIDOMWindow* aWin) { return _to WalletQuickFillin(aWin); } \ NS_IMETHOD WalletSamples() { return _to WalletSamples(); } \ - NS_IMETHOD CookieViewer() { return _to CookieViewer(); } \ NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to SetToolbarWindow(aWin); } \ NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to SetContentWindow(aWin); } \ NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin) { return _to SetWebShellWindow(aWin); } \ diff --git a/mozilla/xpfe/AppCores/public/nsIDOMCookieCore.h b/mozilla/xpfe/AppCores/public/nsIDOMCookieCore.h new file mode 100644 index 00000000000..5aca828d398 --- /dev/null +++ b/mozilla/xpfe/AppCores/public/nsIDOMCookieCore.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMCookieCore_h__ +#define nsIDOMCookieCore_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" +#include "nsIDOMBaseAppCore.h" + +class nsIDOMWindow; + +#define NS_IDOMCOOKIECORE_IID \ +{ 0x7ef693b0, 0x1929, 0x11d3, { 0xab, 0xa8, 0x0, 0x80, 0xc7, 0x87, 0xad, 0x96 } } + +class nsIDOMCookieCore : public nsIDOMBaseAppCore { +public: + static const nsIID& GetIID() { static nsIID iid = NS_IDOMCOOKIECORE_IID; return iid; } + + NS_IMETHOD ShowWindow(nsIDOMWindow* aCurrentFrontWin)=0; + + NS_IMETHOD ChangePanel(const nsString& aUrl)=0; + + NS_IMETHOD PanelLoaded(nsIDOMWindow* aWin)=0; + + NS_IMETHOD SaveCookie(const nsString& aResults)=0; + + NS_IMETHOD CancelCookie()=0; + + NS_IMETHOD GetCookieList(nsString& aReturn)=0; + + NS_IMETHOD GetPermissionList(nsString& aReturn)=0; +}; + + +#define NS_DECL_IDOMCOOKIECORE \ + NS_IMETHOD ShowWindow(nsIDOMWindow* aCurrentFrontWin); \ + NS_IMETHOD ChangePanel(const nsString& aUrl); \ + NS_IMETHOD PanelLoaded(nsIDOMWindow* aWin); \ + NS_IMETHOD SaveCookie(const nsString& aResults); \ + NS_IMETHOD CancelCookie(); \ + NS_IMETHOD GetCookieList(nsString& aReturn); \ + NS_IMETHOD GetPermissionList(nsString& aReturn); \ + + + +#define NS_FORWARD_IDOMCOOKIECORE(_to) \ + NS_IMETHOD ShowWindow(nsIDOMWindow* aCurrentFrontWin) { return _to ShowWindow(aCurrentFrontWin); } \ + NS_IMETHOD ChangePanel(const nsString& aUrl) { return _to ChangePanel(aUrl); } \ + NS_IMETHOD PanelLoaded(nsIDOMWindow* aWin) { return _to PanelLoaded(aWin); } \ + NS_IMETHOD SaveCookie(const nsString& aResults) { return _to SaveCookie(aResults); } \ + NS_IMETHOD CancelCookie() { return _to CancelCookie(); } \ + NS_IMETHOD GetCookieList(nsString& aReturn) { return _to GetCookieList(aReturn); } \ + NS_IMETHOD GetPermissionList(nsString& aReturn) { return _to GetPermissionList(aReturn); } \ + + +extern "C" NS_DOM nsresult NS_InitCookieCoreClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM nsresult NS_NewScriptCookieCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMCookieCore_h__ diff --git a/mozilla/xpfe/AppCores/src/nsCookieCore.cpp b/mozilla/xpfe/AppCores/src/nsCookieCore.cpp new file mode 100644 index 00000000000..7ad11d4eba1 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsCookieCore.cpp @@ -0,0 +1,295 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsCookieCore.h" +#include "nsINetService.h" +#include "nsIURL.h" +#include "nsIFileLocator.h" +#include "nsFileLocations.h" +#include "nsFileSpec.h" +#include "nsFileStream.h" +#include "nsIBrowserWindow.h" +#include "nsIWebShell.h" +#include "pratom.h" +#include "nsIComponentManager.h" +#include "nsAppCores.h" +#include "nsAppCoresCIDs.h" +#include "nsAppShellCIDs.h" +#include "nsAppCoresManager.h" +#include "nsIAppShellService.h" +#include "nsIServiceManager.h" + +#include "nsIScriptGlobalObject.h" + +#include "nsIScriptContext.h" +#include "nsIScriptContextOwner.h" +#include "nsIDOMWindow.h" +#include "nsIWebShellWindow.h" + +#include "plstr.h" +#include "prmem.h" + +#include + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID); +static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); +static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); + +static void DOMWindowToWebShellWindow(nsIDOMWindow *DOMWindow, nsCOMPtr *webWindow); + +//---------------------------------------------------------------------------------------- +nsCookieCore::nsCookieCore() +//---------------------------------------------------------------------------------------- +: mPanelWindow(nsnull) +{ + printf("Created nsCookieCore\n"); +} + +//---------------------------------------------------------------------------------------- +nsCookieCore::~nsCookieCore() +//---------------------------------------------------------------------------------------- +{ + NS_IF_RELEASE(mPanelWindow); +} + + +NS_IMPL_ISUPPORTS_INHERITED(nsCookieCore, nsBaseAppCore, nsIDOMCookieCore) + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) +//---------------------------------------------------------------------------------------- +{ + NS_PRECONDITION(nsnull != aScriptObject, "null arg"); + nsresult res = NS_OK; + if (nsnull == mScriptObject) + { + res = NS_NewScriptCookieCore(aContext, + (nsISupports *)(nsIDOMCookieCore*)this, + nsnull, + &mScriptObject); + } + + *aScriptObject = mScriptObject; + return res; +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::Init(const nsString& aId) +//---------------------------------------------------------------------------------------- +{ + nsresult rv = nsBaseAppCore::Init(aId); + return rv; +} // nsCookieCore::Init + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::ShowWindow(nsIDOMWindow* aCurrentFrontWin) +//---------------------------------------------------------------------------------------- +{ + nsINetService *netservice; + nsresult res; + res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&netservice); + if ((NS_OK == res) && (nsnull != netservice)) { + res = netservice->Cookie_DisplayCookieInfoAsHTML(); + nsServiceManager::ReleaseService(kNetServiceCID, netservice); + } + + // (code adapted from nsToolkitCore::ShowModal. yeesh.) + nsresult rv; + nsIAppShellService *appShell; + nsIWebShellWindow *window; + + window = nsnull; + + nsCOMPtr urlObj; + rv = NS_NewURL(getter_AddRefs(urlObj), "resource://res/samples/CookieViewer.html"); + if (NS_FAILED(rv)) + return rv; + + rv = nsServiceManager::GetService(kAppShellServiceCID, kIAppShellServiceIID, + (nsISupports**) &appShell); + if (NS_FAILED(rv)) + return rv; + + // Create "save to disk" nsIXULCallbacks... + //nsIXULWindowCallbacks *cb = new nsFindDialogCallbacks( aURL, aContentType ); + nsIXULWindowCallbacks *cb = nsnull; + + nsCOMPtr parent; + DOMWindowToWebShellWindow(aCurrentFrontWin, &parent); + appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, window, + nsnull, cb, 504, 436); + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); + + if (window != nsnull) { + nsCOMPtr parentWindowWidgetThing; + nsresult gotParent; + gotParent = parent ? parent->GetWidget(*getter_AddRefs(parentWindowWidgetThing)) : + NS_ERROR_FAILURE; + // Windows OS is the only one that needs the parent disabled, or cares + // arguably this should be done by the new window, within ShowModal... + if (NS_SUCCEEDED(gotParent)) + parentWindowWidgetThing->Enable(PR_FALSE); + window->ShowModal(); + if (NS_SUCCEEDED(gotParent)) + parentWindowWidgetThing->Enable(PR_TRUE); + } + + return rv; +} // nsCookieCore::ShowWindow + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::ChangePanel(const nsString& aURL) +// Start loading of a new cookie panel. +//---------------------------------------------------------------------------------------- +{ + NS_ASSERTION(mPanelWindow, "panel window is null"); + if (!mPanelWindow) + return NS_OK; + + nsCOMPtr globalScript(do_QueryInterface(mPanelWindow)); + if (!globalScript) + return NS_ERROR_FAILURE; + nsCOMPtr webshell; + globalScript->GetWebShell(getter_AddRefs(webshell)); + if (!webshell) + return NS_ERROR_FAILURE; + webshell->LoadURL(aURL.GetUnicode()); + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::PanelLoaded(nsIDOMWindow* aWin) +// Callback after loading of a new cookie panel. +//---------------------------------------------------------------------------------------- +{ + // Out with the old! + + if (mPanelWindow != aWin) + { + NS_IF_RELEASE(mPanelWindow); + mPanelWindow = aWin; + NS_IF_ADDREF(mPanelWindow); + } + return NS_OK; +} + + +//---------------------------------------------------------------------------------------- +static void DOMWindowToWebShellWindow( + nsIDOMWindow *DOMWindow, + nsCOMPtr *webWindow) +//---------------------------------------------------------------------------------------- +{ + if (!DOMWindow) + return; // with webWindow unchanged -- its constructor gives it a null ptr + + nsCOMPtr globalScript(do_QueryInterface(DOMWindow)); + nsCOMPtr webshell, rootWebshell; + if (globalScript) + globalScript->GetWebShell(getter_AddRefs(webshell)); + if (webshell) + webshell->GetRootWebShellEvenIfChrome(*getter_AddRefs(rootWebshell)); + if (rootWebshell) { + nsCOMPtr webshellContainer; + rootWebshell->GetContainer(*getter_AddRefs(webshellContainer)); + *webWindow = do_QueryInterface(webshellContainer); + } +} + + +//---------------------------------------------------------------------------------------- +static nsresult Close(nsIDOMWindow*& dw) +//---------------------------------------------------------------------------------------- +{ + if (!dw) + return NS_ERROR_FAILURE; + nsIDOMWindow* top; + dw->GetTop(&top); + if (!top) + return NS_ERROR_FAILURE; + nsCOMPtr parent; + DOMWindowToWebShellWindow(top, &parent); + if (parent) + parent->Close(); + NS_IF_RELEASE(dw); + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::SaveCookie(const nsString& results) +//---------------------------------------------------------------------------------------- +{ + nsINetService *netservice; + nsresult res; + res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&netservice); + if ((NS_OK == res) && (nsnull != netservice)) { + res = netservice->Cookie_CookieViewerReturn (results); + nsServiceManager::ReleaseService(kNetServiceCID, netservice); + } + + return Close(mPanelWindow); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::CancelCookie() +//---------------------------------------------------------------------------------------- +{ + return Close(mPanelWindow); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::GetCookieList(nsString& aCookieList) +//---------------------------------------------------------------------------------------- +{ + nsINetService *netservice; + nsresult res; + res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&netservice); + if ((NS_OK == res) && (nsnull != netservice)) { + res = netservice->Cookie_GetCookieListForViewer(aCookieList); + nsServiceManager::ReleaseService(kNetServiceCID, netservice); + } + + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCore::GetPermissionList(nsString& aPermissionList) +//---------------------------------------------------------------------------------------- +{ + nsINetService *netservice; + nsresult res; + res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&netservice); + if ((NS_OK == res) && (nsnull != netservice)) { + res = netservice->Cookie_GetPermissionListForViewer(aPermissionList); + nsServiceManager::ReleaseService(kNetServiceCID, netservice); + } + + return NS_OK; +} + diff --git a/mozilla/xpfe/AppCores/src/nsCookieCore.h b/mozilla/xpfe/AppCores/src/nsCookieCore.h new file mode 100644 index 00000000000..68d5693e2e8 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsCookieCore.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsCookieCorePrivate_h___ +#define nsCookieCorePrivate_h___ + +//#include "nsAppCores.h" + +#include "nscore.h" +#include "nsISupports.h" + +#include "nsIDOMCookieCore.h" +#include "nsBaseAppCore.h" +#include "prtypes.h" + +class nsIBrowserWindow; +class nsIWebShell; +class nsIScriptContext; +class nsIDOMWindow; +class nsICookie; +class nsString; + +//======================================================================================== +class nsCookieCore +//======================================================================================== + : public nsBaseAppCore + , public nsIDOMCookieCore +{ + public: + + nsCookieCore(); + virtual ~nsCookieCore(); + + + NS_DECL_ISUPPORTS_INHERITED + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD Init(const nsString& aId); + NS_IMETHOD GetId(nsString& aId) + { + return nsBaseAppCore::GetId(aId); + } + NS_IMETHOD SetDocumentCharset(const nsString& aCharset) + { + return nsBaseAppCore::SetDocumentCharset(aCharset); + } + + NS_DECL_IDOMCOOKIECORE + + protected: + nsIDOMWindow* mPanelWindow; +}; + +#endif // nsCookieCore_h___ diff --git a/mozilla/xpfe/AppCores/src/nsCookieCoreFactory.cpp b/mozilla/xpfe/AppCores/src/nsCookieCoreFactory.cpp new file mode 100644 index 00000000000..e503acb79a5 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsCookieCoreFactory.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsCookieCoreFactory.h" + +#include "nsAppCores.h" +#include "nsCookieCore.h" +#include "pratom.h" +#include "nsISupportsUtils.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + +//---------------------------------------------------------------------------------------- +nsCookieCoreFactory::nsCookieCoreFactory() +//---------------------------------------------------------------------------------------- +{ + NS_INIT_REFCNT(); + IncInstanceCount(); +} + +//---------------------------------------------------------------------------------------- +nsCookieCoreFactory::~nsCookieCoreFactory() +//---------------------------------------------------------------------------------------- +{ + DecInstanceCount(); +} + +NS_IMPL_ADDREF(nsCookieCoreFactory) +NS_IMPL_RELEASE(nsCookieCoreFactory) + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCoreFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr) +//---------------------------------------------------------------------------------------- +{ + if (aInstancePtr == NULL) + return NS_ERROR_NULL_POINTER; + + // Always NULL result, in case of failure + *aInstancePtr = NULL; + + if ( aIID.Equals(kISupportsIID) ) + *aInstancePtr = (void*) this; + else if ( aIID.Equals(kIFactoryIID) ) + *aInstancePtr = (void*) this; + + if (aInstancePtr == NULL) + return NS_ERROR_NO_INTERFACE; + + AddRef(); + return NS_OK; +} // nsCookieCoreFactory::QueryInterface + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCoreFactory::CreateInstance( + nsISupports* aOuter, + REFNSIID aIID, + void **aResult) +//---------------------------------------------------------------------------------------- +{ + if (aResult == NULL) + return NS_ERROR_NULL_POINTER; + + *aResult = NULL; + +#if 0 + // There is a stupid bug that I don't feel competent to fix. Basically, the + // AppCore Manager is a waste of time (the manager gets created, an app core is + // added to the list, and then the app core manager is deleted, along with its list). + // I want to insist that + // there is always one instance of the Cookie app core. Hence this HACK. + static nsCookieCore* inst = nsnull; + PRBool firstTime = (inst == nsnull); + if (firstTime) + { + inst = new nsCookieCore(); + if (!inst) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(inst); + } + nsresult result = inst->QueryInterface(aIID, aResult); + if (result != NS_OK && firstTime) + NS_RELEASE(inst); +#else + static nsCookieCore* inst = new nsCookieCore(); + if (!inst) + return NS_ERROR_OUT_OF_MEMORY; + nsresult result = inst->QueryInterface(aIID, aResult); +#endif + return result; +} // nsCookieCoreFactory::CreateInstance + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsCookieCoreFactory::LockFactory(PRBool aLock) +//---------------------------------------------------------------------------------------- +{ + if (aLock) + IncLockCount(); + else + DecLockCount(); + return NS_OK; +} // nsCookieCoreFactory::LockFactory diff --git a/mozilla/xpfe/AppCores/src/nsCookieCoreFactory.h b/mozilla/xpfe/AppCores/src/nsCookieCoreFactory.h new file mode 100644 index 00000000000..a456f5fa5f1 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsCookieCoreFactory.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsCookieCoreFactory_h___ +#define nsCookieCoreFactory_h___ + +//#include "nscore.h" +//#include "nsString.h" +#include "nsIFactory.h" +#include "nsISupports.h" + +//======================================================================================== +class nsCookieCoreFactory : public nsIFactory +//======================================================================================== +{ + public: + + nsCookieCoreFactory(); + virtual ~nsCookieCoreFactory(); + + PRBool CanUnload(void); + + NS_DECL_ISUPPORTS + + NS_IMETHOD CreateInstance(nsISupports *aOuter, + REFNSIID aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock); + +}; + +#endif // nsCookieCoreFactory_h___ diff --git a/mozilla/xpfe/AppCores/src/nsJSCookieCore.cpp b/mozilla/xpfe/AppCores/src/nsJSCookieCore.cpp new file mode 100644 index 00000000000..4a12ed7bbf1 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsJSCookieCore.cpp @@ -0,0 +1,592 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMCookieCore.h" +#include "nsIDOMWindow.h" +#include "nsIScriptNameSpaceManager.h" +#include "nsIComponentManager.h" +#include "nsIJSNativeInitializer.h" +#include "nsDOMCID.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kICookieCoreIID, NS_IDOMCOOKIECORE_IID); +static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID); + +NS_DEF_PTR(nsIDOMCookieCore); +NS_DEF_PTR(nsIDOMWindow); + + +/***********************************************************************/ +// +// CookieCore Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetCookieCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMCookieCore *a = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// CookieCore Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetCookieCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMCookieCore *a = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); + } + + return PR_TRUE; +} + + +// +// CookieCore finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeCookieCore(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// CookieCore enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateCookieCore(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// CookieCore resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveCookieCore(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method ShowWindow +// +PR_STATIC_CALLBACK(JSBool) +CookieCoreShowWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMWindowPtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIWindowIID, + "Window", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ShowWindow(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function ShowWindow requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ChangePanel +// +PR_STATIC_CALLBACK(JSBool) +CookieCoreChangePanel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + if (NS_OK != nativeThis->ChangePanel(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function ChangePanel requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method PanelLoaded +// +PR_STATIC_CALLBACK(JSBool) +CookieCorePanelLoaded(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMWindowPtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIWindowIID, + "Window", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->PanelLoaded(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function PanelLoaded requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method SaveCookie +// +PR_STATIC_CALLBACK(JSBool) +CookieCoreSaveCookie(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + if (NS_OK != nativeThis->SaveCookie(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function SaveCookie requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method CancelCookie +// +PR_STATIC_CALLBACK(JSBool) +CookieCoreCancelCookie(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->CancelCookie()) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function CancelCookie requires 0 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetCookieList +// +PR_STATIC_CALLBACK(JSBool) +CookieCoreGetCookieList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetCookieList(nativeRet)) { + return JS_FALSE; + } + + nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval); + } + else { + JS_ReportError(cx, "Function GetCookieList requires 0 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetPermissionList +// +PR_STATIC_CALLBACK(JSBool) +CookieCoreGetPermissionList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCookieCore *nativeThis = (nsIDOMCookieCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetPermissionList(nativeRet)) { + return JS_FALSE; + } + + nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval); + } + else { + JS_ReportError(cx, "Function GetPermissionList requires 0 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for CookieCore +// +JSClass CookieCoreClass = { + "CookieCore", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JS_PropertyStub, + JS_PropertyStub, + GetCookieCoreProperty, + SetCookieCoreProperty, + EnumerateCookieCore, + ResolveCookieCore, + JS_ConvertStub, + FinalizeCookieCore +}; + + +// +// CookieCore class properties +// +static JSPropertySpec CookieCoreProperties[] = +{ + {0} +}; + + +// +// CookieCore class methods +// +static JSFunctionSpec CookieCoreMethods[] = +{ + {"ShowWindow", CookieCoreShowWindow, 1}, + {"ChangePanel", CookieCoreChangePanel, 1}, + {"PanelLoaded", CookieCorePanelLoaded, 1}, + {"SaveCookie", CookieCoreSaveCookie, 1}, + {"CancelCookie", CookieCoreCancelCookie, 0}, + {"GetCookieList", CookieCoreGetCookieList, 0}, + {"GetPermissionList", CookieCoreGetPermissionList, 0}, + {0} +}; + + +// +// CookieCore constructor +// +PR_STATIC_CALLBACK(JSBool) +CookieCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsresult result; + nsIID classID; + nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx); + nsIScriptNameSpaceManager* manager; + nsIDOMCookieCore *nativeThis; + nsIScriptObjectOwner *owner = nsnull; + nsIJSNativeInitializer* initializer = nsnull; + + static NS_DEFINE_IID(kIDOMCookieCoreIID, NS_IDOMCOOKIECORE_IID); + static NS_DEFINE_IID(kIJSNativeInitializerIID, NS_IJSNATIVEINITIALIZER_IID); + + result = context->GetNameSpaceManager(&manager); + if (NS_OK != result) { + return JS_FALSE; + } + + result = manager->LookupName("CookieCore", PR_TRUE, classID); + NS_RELEASE(manager); + if (NS_OK != result) { + return JS_FALSE; + } + + result = nsComponentManager::CreateInstance(classID, + nsnull, + kIDOMCookieCoreIID, + (void **)&nativeThis); + if (NS_OK != result) { + return JS_FALSE; + } + + result = nativeThis->QueryInterface(kIJSNativeInitializerIID, (void **)&initializer); + if (NS_OK == result) { + result = initializer->Initialize(cx, argc, argv); + NS_RELEASE(initializer); + + if (NS_OK != result) { + NS_RELEASE(nativeThis); + return JS_FALSE; + } + } + + result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner); + if (NS_OK != result) { + NS_RELEASE(nativeThis); + return JS_FALSE; + } + + owner->SetScriptObject((void *)obj); + JS_SetPrivate(cx, obj, nativeThis); + + NS_RELEASE(owner); + return JS_TRUE; +} + +// +// CookieCore class initialization +// +extern "C" NS_DOM nsresult NS_InitCookieCoreClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "CookieCore", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitBaseAppCoreClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &CookieCoreClass, // JSClass + CookieCore, // JSNative ctor + 0, // ctor args + CookieCoreProperties, // proto props + CookieCoreMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new CookieCore JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptCookieCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptCookieCore"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMCookieCore *aCookieCore; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitCookieCoreClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kICookieCoreIID, (void **)&aCookieCore); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &CookieCoreClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aCookieCore); + } + else { + NS_RELEASE(aCookieCore); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/xpfe/AppCores/xul/CookieWindow.js b/mozilla/xpfe/AppCores/xul/CookieWindow.js new file mode 100644 index 00000000000..89595999314 --- /dev/null +++ b/mozilla/xpfe/AppCores/xul/CookieWindow.js @@ -0,0 +1,50 @@ +var cookieCore; + +function StartUp(windowName) +{ + dump("\nDoing " + windowName + " startup...\n"); + cookieCore = XPAppCoresManager.Find("CookieCore"); + dump("Looking up CookieCore...\n"); + if (cookieCore == null) + { + dump("Creating CookieCore...\n"); + cookieCore = new CookieCore(); + if (cookieCore != null) + { + dump("CookieCore has been created.\n"); + cookieCore.Init("CookieCore"); + } + else + { + dump("CookieCore was not created"); + } + } + else + { + dump("CookieCore has already been created! Hurrah!\n"); + } + if (cookieCore != null && windowName != "Top" && windowName != "Bottom") + { + cookieCore.PanelLoaded(window); + } +} + +function DoGetCookieList() +{ + return cookieCore.GetCookieList(); +} + +function DoGetPermissionList() +{ + return cookieCore.GetPermissionList(); +} + +function DoSave(results) +{ + cookieCore.SaveCookie(results); +} + +function DoCancel() +{ + cookieCore.CancelCookie(); +} diff --git a/mozilla/xpfe/AppCores/xul/Makefile.in b/mozilla/xpfe/AppCores/xul/Makefile.in index edc2f0959a2..4baa3892c54 100644 --- a/mozilla/xpfe/AppCores/xul/Makefile.in +++ b/mozilla/xpfe/AppCores/xul/Makefile.in @@ -45,6 +45,7 @@ EXPORT_RESOURCE_SAMPLES = \ $(srcdir)/PrefsWindow.html \ $(srcdir)/PrefsWindow.js \ $(srcdir)/SignonWindow.js \ + $(srcdir)/CookieWindow.js \ $(srcdir)/WalletWindow.js \ $(srcdir)/preftree.css \ $(srcdir)/preftree.xul \ diff --git a/mozilla/xpfe/browser/src/navigator.js b/mozilla/xpfe/browser/src/navigator.js index 8eeaa6b11b3..130f08c3b5f 100644 --- a/mozilla/xpfe/browser/src/navigator.js +++ b/mozilla/xpfe/browser/src/navigator.js @@ -571,11 +571,15 @@ function CookieViewer() { - if (appCore != null) { - dump("CookieViewer\n"); - appCore.cookieViewer(); - } else { - dump("BrowserAppCore has not been created!\n"); + var cookieCore = XPAppCoresManager.Find("CookieCore"); + if (!cookieCore) { + cookieCore = new CookieCore(); + if (cookieCore) { + cookieCore.Init("CookieCore"); + } + } + if (cookieCore) { + cookieCore.ShowWindow(window); } }