diff --git a/mozilla/build/mac/NGLayoutBuildList.pm b/mozilla/build/mac/NGLayoutBuildList.pm index 52477b91674..3e271c8fce7 100644 --- a/mozilla/build/mac/NGLayoutBuildList.pm +++ b/mozilla/build/mac/NGLayoutBuildList.pm @@ -883,6 +883,9 @@ sub BuildMailNewsProjects() sub BuildProjects() { + # activate Toolserver + ActivateApplication('MPSX'); + # activate CodeWarrior ActivateApplication('CWIE'); diff --git a/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp b/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp index 37be6ae5cb3..7a49118e926 100644 --- a/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp +++ b/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp @@ -441,10 +441,10 @@ int main() // has the ability to take nsnull as a parameter. Once that happens, // prefs will do the work of figuring out which prefs file to load... NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &result); - if (NS_SUCCEEDED(result) && prefs) - { - prefs->Startup("prefs50.js"); - } +// if (NS_SUCCEEDED(result) && prefs) +// { +// prefs->Startup("prefs50.js"); +// } // Create the Event Queue for this thread... nsIEventQueueService* pEventQService; diff --git a/mozilla/mailnews/local/tests/pop3/pop3Test.cpp b/mozilla/mailnews/local/tests/pop3/pop3Test.cpp index 59a9f8e7f74..2928f5efaff 100644 --- a/mozilla/mailnews/local/tests/pop3/pop3Test.cpp +++ b/mozilla/mailnews/local/tests/pop3/pop3Test.cpp @@ -468,11 +468,13 @@ int main() // mscott - this is just a bad bad bad hack right now until prefs // has the ability to take nsnull as a parameter. Once that happens, // prefs will do the work of figuring out which prefs file to load... + // jrm - You don't even need to call this now. Just using the service + // should do the trick. NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &result); - if (NS_SUCCEEDED(result) && prefs) - { - prefs->Startup("prefs50.js"); - } +// if (NS_SUCCEEDED(result) && prefs) +// { +// prefs->StartUp(); +// } // Create the Event Queue for this thread... nsIEventQueueService* pEventQService; diff --git a/mozilla/modules/libpref/public/nsIPref.h b/mozilla/modules/libpref/public/nsIPref.h index 06031294830..b00924a1664 100644 --- a/mozilla/modules/libpref/public/nsIPref.h +++ b/mozilla/modules/libpref/public/nsIPref.h @@ -22,6 +22,8 @@ #include "jsapi.h" #include "nsISupports.h" +class nsFileSpec; + /* Temporarily conditionally compile PrefChangedFunc typedef. ** During migration from old libpref to nsIPref we need it in ** both header files. Eventually prefapi.h will become a private @@ -59,24 +61,48 @@ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPREF_IID) - // Initialize/shutdown - NS_IMETHOD Startup(const char *filename) = 0; - NS_IMETHOD Shutdown() = 0; +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + nsresult Shutdown() { return ShutDown(); } + nsresult Startup(void*) { return StartUp(); } + NS_IMETHOD ReadUserJSFile(const char *filename) = 0; // deprecated + NS_IMETHOD ReadLIJSFile(const char *filename) = 0; // deprecated + NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length, + const char* filename, + PRBool bGlobalContext, + PRBool bCallbacks) = 0; // deprecated + NS_IMETHOD SavePrefFileAs(const char *filename) = 0; + NS_IMETHOD SaveLIPrefFile(const char *filename) = 0; + + // Path prefs + NS_IMETHOD CopyPathPref(const char *pref, char ** return_buf) = 0; + NS_IMETHOD SetPathPref(const char *pref_name, + const char *path, PRBool set_default) = 0; +#endif + // Initialize/shut down + NS_IMETHOD StartUp() = 0; + NS_IMETHOD StartUpWith(const nsFileSpec& inSpec) = 0; + NS_IMETHOD ShutDown() = 0; // Config file input - NS_IMETHOD ReadUserJSFile(const char *filename) = 0; - NS_IMETHOD ReadLIJSFile(const char *filename) = 0; + NS_IMETHOD ReadUserJSFile(const nsFileSpec& inSpec) = 0; + NS_IMETHOD ReadLIJSFile(const nsFileSpec& inSpec) = 0; + + NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length, + PRBool bGlobalContext, + PRBool bCallbacks) = 0; + NS_IMETHOD EvaluateConfigScriptFile(const char * js_buffer, size_t length, + const nsFileSpec& inSpec, + PRBool bGlobalContext, + PRBool bCallbacks) = 0; + + NS_IMETHOD SavePrefFileAs(const nsFileSpec& inSpec) = 0; + NS_IMETHOD SaveLIPrefFile(const nsFileSpec& inSpec) = 0; // JS stuff NS_IMETHOD GetConfigContext(JSContext **js_context) = 0; NS_IMETHOD GetGlobalConfigObject(JSObject **js_object) = 0; NS_IMETHOD GetPrefConfigObject(JSObject **js_object) = 0; - NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length, - const char* filename, - PRBool bGlobalContext, - PRBool bCallbacks) = 0; - // Getters NS_IMETHOD GetCharPref(const char *pref, char * return_buf, int * buf_length) = 0; @@ -140,18 +166,15 @@ public: NS_IMETHOD CopyDefaultBinaryPref(const char *pref, void ** return_val, int * size) = 0; - // Path prefs - NS_IMETHOD CopyPathPref(const char *pref, char ** return_buf) = 0; - NS_IMETHOD SetPathPref(const char *pref_name, - const char *path, PRBool set_default) = 0; + NS_IMETHOD GetFilePref(const char* pref, nsFileSpec* value) = 0; + NS_IMETHOD SetFilePref( + const char* pref, const nsFileSpec* value, PRBool setDefault) = 0; // Pref info NS_IMETHOD PrefIsLocked(const char *pref_name, PRBool *res) = 0; // Save pref files - NS_IMETHOD SavePrefFile(void) = 0; - NS_IMETHOD SavePrefFileAs(const char *filename) = 0; - NS_IMETHOD SaveLIPrefFile(const char *filename) = 0; + NS_IMETHOD SavePrefFile() = 0; // Callbacks NS_IMETHOD RegisterCallback( const char* domain, diff --git a/mozilla/modules/libpref/src/Makefile.in b/mozilla/modules/libpref/src/Makefile.in index 2c47ef7fb54..31e3b8e30b6 100644 --- a/mozilla/modules/libpref/src/Makefile.in +++ b/mozilla/modules/libpref/src/Makefile.in @@ -25,7 +25,7 @@ include $(DEPTH)/config/autoconf.mk MODULE = pref LIBRARY_NAME = pref -REQUIRES = js pref dbm security ldap img layer xpcom util +REQUIRES = js raptorbase pref dbm security ldap img layer xpcom util ifneq ($(subst /,_,$(shell uname -s)),OS2) CSRCS = unix/unixpref.c diff --git a/mozilla/modules/libpref/src/makefile.win b/mozilla/modules/libpref/src/makefile.win index 1f931453791..0dd34d9561f 100644 --- a/mozilla/modules/libpref/src/makefile.win +++ b/mozilla/modules/libpref/src/makefile.win @@ -80,6 +80,7 @@ LLIBS = \ $(DIST)\lib\plc3.lib \ $(LIBNSPR) \ $(DIST)\lib\js$(MOZ_BITS)$(VERSION_NUMBER).lib \ + $(DIST)\lib\raptorbase.lib \ $(DIST)\lib\xpcom32.lib \ $(HASHLIBS) diff --git a/mozilla/modules/libpref/src/nsPref.cpp b/mozilla/modules/libpref/src/nsPref.cpp index e25cef3e038..51e4a884be2 100644 --- a/mozilla/modules/libpref/src/nsPref.cpp +++ b/mozilla/modules/libpref/src/nsPref.cpp @@ -2,7 +2,7 @@ * * 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 + * 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, @@ -11,284 +11,545 @@ * 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 + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +#include "nsIPref.h" + #include "pratom.h" #include "prefapi.h" #include "nsIFactory.h" #include "nsIComponentManager.h" -#include "nsIPref.h" #ifdef XP_MAC #include "nsINetSupport.h" #include "nsIStreamListener.h" #endif #include "nsIServiceManager.h" +#include "nsIFileLocator.h" #include "nsCOMPtr.h" +#include "nsFileSpec.h" +#include "nsFileLocations.h" +#include "nsFileStream.h" -#ifdef PREF_USE_SYSDIR -#include "nsSpecialSystemDirectory.h" // For exe dir -#endif /* PREF_USE_SYSDIR */ +#include "plhash.h" +#include "prmem.h" +#include "plstr.h" + +#include "jsapi.h" + +#ifdef _WIN32 + #include "windows.h" +#endif /* _WIN32 */ + + +#if defined(XP_MAC) || defined(XP_UNIX) +#include "fe_proto.h" +#endif +#if defined(XP_PC) || defined(XP_OS2) +#define LINEBREAK "\n" +#endif + +#define XP_QSORT qsort + +#include "prefapi_private_data.h" static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); +static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID); + static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); - static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); +static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID); -class nsPref: public nsIPref { - NS_DECL_ISUPPORTS - -private: - nsPref(); - virtual ~nsPref(); - - static void useDefaultPrefFile(nsPref *aPrefInst); - static nsPref *mInstance; +//======================================================================================== +class nsPref: public nsIPref +//======================================================================================== +{ + NS_DECL_ISUPPORTS public: - static nsPref *GetInstance(); + static nsPref *GetInstance(); - // Initialize/shutdown - NS_IMETHOD Startup(const char *filename); - NS_IMETHOD Shutdown(); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + NS_IMETHOD ReadUserJSFile(const char *filename); // deprecated + NS_IMETHOD ReadLIJSFile(const char *filename); // deprecated + NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length, + const char* filename, + PRBool bGlobalContext, + PRBool bCallbacks); // deprecated + NS_IMETHOD SavePrefFileAs(const char *filename); + NS_IMETHOD SaveLIPrefFile(const char *filename); - // Config file input - NS_IMETHOD ReadUserJSFile(const char *filename); - NS_IMETHOD ReadLIJSFile(const char *filename); + // Path prefs + NS_IMETHOD CopyPathPref(const char *pref, char ** return_buf); + NS_IMETHOD SetPathPref(const char *pref, + const char *path, PRBool set_default); +#endif + // Initialize/shutdown + NS_IMETHOD StartUp(); + NS_IMETHOD StartUpWith(const nsFileSpec& inSpec); + NS_IMETHOD ShutDown(); - // JS stuff - NS_IMETHOD GetConfigContext(JSContext **js_context); - NS_IMETHOD GetGlobalConfigObject(JSObject **js_object); - NS_IMETHOD GetPrefConfigObject(JSObject **js_object); + // Config file input + NS_IMETHOD ReadUserJSFile(const nsFileSpec& inSpec); + NS_IMETHOD ReadLIJSFile(const nsFileSpec& inSpec); - NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length, - const char* filename, - PRBool bGlobalContext, - PRBool bCallbacks); + NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length, + PRBool bGlobalContext, + PRBool bCallbacks); + NS_IMETHOD EvaluateConfigScriptFile(const char * js_buffer, size_t length, + const nsFileSpec& inSpec, + PRBool bGlobalContext, + PRBool bCallbacks); - // Getters - NS_IMETHOD GetCharPref(const char *pref, + NS_IMETHOD SavePrefFileAs(const nsFileSpec& inSpec); + NS_IMETHOD SaveLIPrefFile(const nsFileSpec& inSpec); + + // JS stuff + NS_IMETHOD GetConfigContext(JSContext **js_context); + NS_IMETHOD GetGlobalConfigObject(JSObject **js_object); + NS_IMETHOD GetPrefConfigObject(JSObject **js_object); + + // Getters + NS_IMETHOD GetCharPref(const char *pref, char * return_buf, int * buf_length); - NS_IMETHOD GetIntPref(const char *pref, PRInt32 * return_int); - NS_IMETHOD GetBoolPref(const char *pref, PRBool * return_val); - NS_IMETHOD GetBinaryPref(const char *pref, - void * return_val, int * buf_length); - NS_IMETHOD GetColorPref(const char *pref, - uint8 *red, uint8 *green, uint8 *blue); - NS_IMETHOD GetColorPrefDWord(const char *pref, PRUint32 *colorref); - NS_IMETHOD GetRectPref(const char *pref, + NS_IMETHOD GetIntPref(const char *pref, PRInt32 * return_int); + NS_IMETHOD GetBoolPref(const char *pref, PRBool * return_val); + NS_IMETHOD GetBinaryPref(const char *pref, + void * return_val, int * buf_length); + NS_IMETHOD GetColorPref(const char *pref, + uint8 *red, uint8 *green, uint8 *blue); + NS_IMETHOD GetColorPrefDWord(const char *pref, PRUint32 *colorref); + NS_IMETHOD GetRectPref(const char *pref, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom); - // Setters - NS_IMETHOD SetCharPref(const char *pref,const char* value); - NS_IMETHOD SetIntPref(const char *pref,PRInt32 value); - NS_IMETHOD SetBoolPref(const char *pref,PRBool value); - NS_IMETHOD SetBinaryPref(const char *pref,void * value, long size); - NS_IMETHOD SetColorPref(const char *pref, - uint8 red, uint8 green, uint8 blue); - NS_IMETHOD SetColorPrefDWord(const char *pref, PRUint32 colorref); - NS_IMETHOD SetRectPref(const char *pref, + // Setters + NS_IMETHOD SetCharPref(const char *pref,const char* value); + NS_IMETHOD SetIntPref(const char *pref,PRInt32 value); + NS_IMETHOD SetBoolPref(const char *pref,PRBool value); + NS_IMETHOD SetBinaryPref(const char *pref,void * value, long size); + NS_IMETHOD SetColorPref(const char *pref, + uint8 red, uint8 green, uint8 blue); + NS_IMETHOD SetColorPrefDWord(const char *pref, PRUint32 colorref); + NS_IMETHOD SetRectPref(const char *pref, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom); - - NS_IMETHOD ClearUserPref(const char *pref); + + NS_IMETHOD ClearUserPref(const char *pref); - // Get Defaults - NS_IMETHOD GetDefaultCharPref(const char *pref, + // Get Defaults + NS_IMETHOD GetDefaultCharPref(const char *pref, char * return_buf, int * buf_length); - NS_IMETHOD GetDefaultIntPref(const char *pref, PRInt32 * return_int); - NS_IMETHOD GetDefaultBoolPref(const char *pref, PRBool * return_val); - NS_IMETHOD GetDefaultBinaryPref(const char *pref, - void * return_val, int * buf_length); - NS_IMETHOD GetDefaultColorPref(const char *pref, + NS_IMETHOD GetDefaultIntPref(const char *pref, PRInt32 * return_int); + NS_IMETHOD GetDefaultBoolPref(const char *pref, PRBool * return_val); + NS_IMETHOD GetDefaultBinaryPref(const char *pref, + void * return_val, int * buf_length); + NS_IMETHOD GetDefaultColorPref(const char *pref, uint8 *red, uint8 *green, uint8 *blue); - NS_IMETHOD GetDefaultColorPrefDWord(const char *pref, - PRUint32 *colorref); - NS_IMETHOD GetDefaultRectPref(const char *pref, + NS_IMETHOD GetDefaultColorPrefDWord(const char *pref, + PRUint32 *colorref); + NS_IMETHOD GetDefaultRectPref(const char *pref, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom); - // Set defaults - NS_IMETHOD SetDefaultCharPref(const char *pref,const char* value); - NS_IMETHOD SetDefaultIntPref(const char *pref,PRInt32 value); - NS_IMETHOD SetDefaultBoolPref(const char *pref,PRBool value); - NS_IMETHOD SetDefaultBinaryPref(const char *pref, - void * value, long size); - NS_IMETHOD SetDefaultColorPref(const char *pref, + // Set defaults + NS_IMETHOD SetDefaultCharPref(const char *pref,const char* value); + NS_IMETHOD SetDefaultIntPref(const char *pref,PRInt32 value); + NS_IMETHOD SetDefaultBoolPref(const char *pref,PRBool value); + NS_IMETHOD SetDefaultBinaryPref(const char *pref, + void * value, long size); + NS_IMETHOD SetDefaultColorPref(const char *pref, uint8 red, uint8 green, uint8 blue); - NS_IMETHOD SetDefaultRectPref(const char *pref, + NS_IMETHOD SetDefaultRectPref(const char *pref, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom); - - // Copy prefs - NS_IMETHOD CopyCharPref(const char *pref, char ** return_buf); - NS_IMETHOD CopyBinaryPref(const char *pref, - void ** return_value, int *size); + + // Copy prefs + NS_IMETHOD CopyCharPref(const char *pref, char ** return_buf); + NS_IMETHOD CopyBinaryPref(const char *pref, + void ** return_value, int *size); - NS_IMETHOD CopyDefaultCharPref( const char - *pref, char ** return_buffer ); - NS_IMETHOD CopyDefaultBinaryPref(const char *pref, - void ** return_val, int * size); + NS_IMETHOD CopyDefaultCharPref( const char + *pref, char ** return_buffer ); + NS_IMETHOD CopyDefaultBinaryPref(const char *pref, + void ** return_val, int * size); - // Path prefs - NS_IMETHOD CopyPathPref(const char *pref, char ** return_buf); - NS_IMETHOD SetPathPref(const char *pref, - const char *path, PRBool set_default); + NS_IMETHOD GetFilePref(const char* pref, nsFileSpec* value); + NS_IMETHOD SetFilePref(const char* pref, const nsFileSpec* value, PRBool setDefault); + + // Pref info + NS_IMETHOD PrefIsLocked(const char *pref, PRBool *res); - // Pref info - NS_IMETHOD PrefIsLocked(const char *pref, PRBool *res); + // Save pref files + NS_IMETHOD SavePrefFile(); - // Save pref files - NS_IMETHOD SavePrefFile(void); - NS_IMETHOD SavePrefFileAs(const char *filename); - NS_IMETHOD SaveLIPrefFile(const char *filename); - - // Callbacks - NS_IMETHOD RegisterCallback( const char* domain, - PrefChangedFunc callback, - void* instance_data ); - NS_IMETHOD UnregisterCallback( const char* domain, + // Callbacks + NS_IMETHOD RegisterCallback( const char* domain, + PrefChangedFunc callback, + void* instance_data ); + NS_IMETHOD UnregisterCallback( const char* domain, PrefChangedFunc callback, void* instance_data ); - NS_IMETHOD CopyPrefsTree(const char *srcRoot, const char *destRoot); - NS_IMETHOD DeleteBranch(const char *branchName); -}; + NS_IMETHOD CopyPrefsTree(const char *srcRoot, const char *destRoot); + NS_IMETHOD DeleteBranch(const char *branchName); -nsPref* nsPref::mInstance = NULL; +protected: + + nsPref(); + virtual ~nsPref(); + + void useDefaultPrefFile(); + static nsPref *gInstance; + + nsFileSpec mFileSpec; + nsFileSpec mLIFileSpec; +}; // class nsPref + +nsPref* nsPref::gInstance = NULL; static PRInt32 g_InstanceCount = 0; static PRInt32 g_LockCount = 0; +static PrefResult pref_OpenFileSpec( + const nsFileSpec& fileSpec, + PRBool is_error_fatal, + PRBool verifyHash, + PRBool bGlobalContext, + PRBool skipFirstLine); + +//---------------------------------------------------------------------------------------- static nsresult _convertRes(int res) +//---------------------------------------------------------------------------------------- { - nsresult nsres = NS_OK; - switch (res) { - case PREF_OUT_OF_MEMORY: - nsres = NS_ERROR_OUT_OF_MEMORY; - break; - case PREF_NOT_INITIALIZED: - nsres = NS_ERROR_NOT_INITIALIZED; - break; - case PREF_TYPE_CHANGE_ERR: - case PREF_ERROR: - case PREF_BAD_LOCKFILE: - nsres = NS_ERROR_UNEXPECTED; - break; - case PREF_VALUECHANGED: - nsres = NS_PREF_VALUE_CHANGED; - break; - }; - - return nsres; + switch (res) + { + case PREF_OUT_OF_MEMORY: + return NS_ERROR_OUT_OF_MEMORY; + case PREF_NOT_INITIALIZED: + return NS_ERROR_NOT_INITIALIZED; + case PREF_TYPE_CHANGE_ERR: + case PREF_ERROR: + case PREF_BAD_LOCKFILE: + return NS_ERROR_UNEXPECTED; + case PREF_VALUECHANGED: + return NS_PREF_VALUE_CHANGED; + }; + return NS_OK; } -/* - * Constructor/Destructor - */ - -nsPref::nsPref() { - PR_AtomicIncrement(&g_InstanceCount); - NS_INIT_REFCNT(); -} - -nsPref::~nsPref() { - PR_AtomicDecrement(&g_InstanceCount); - mInstance = NULL; -} - -void -nsPref::useDefaultPrefFile(nsPref *aPrefInst) +//---------------------------------------------------------------------------------------- +nsPref::nsPref() +//---------------------------------------------------------------------------------------- { - /* temporary hack to load up pref files */ + PR_AtomicIncrement(&g_InstanceCount); + NS_INIT_REFCNT(); +} -#ifdef PREF_USE_SYSDIR - if (!aPrefInst) +//---------------------------------------------------------------------------------------- +nsPref::~nsPref() +//---------------------------------------------------------------------------------------- +{ + PR_AtomicDecrement(&g_InstanceCount); + gInstance = NULL; +} + +//---------------------------------------------------------------------------------------- +void nsPref::useDefaultPrefFile() +//---------------------------------------------------------------------------------------- +{ + nsIFileLocator* locator = nsnull; + nsresult rv = nsServiceManager::GetService(kFileLocatorCID, kIFileLocatorIID, (nsISupports**)&locator); + if (NS_FAILED(rv)) + return; + if (!locator) + return; + nsFileSpec newPrefs; + rv = locator->GetFileLocation(nsSpecialFileSpec::App_PreferencesFile50, &newPrefs); + if (NS_SUCCEEDED(rv)) + { + if (!newPrefs.Exists()) + { + nsOutputFileStream stream(newPrefs); + if (stream.is_open()) + { + stream << "// This is an empty prefs file" << nsEndl; + } + } + if (newPrefs.Exists()) + rv = StartUpWith(newPrefs); + } + nsServiceManager::ReleaseService(kFileLocatorCID, locator); return; - nsSpecialSystemDirectory sysDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - sysDir += "prefs50.js"; - aPrefInst->Startup(sysDir.GetCString()); - // Actually, should provide version of startup that takes an nsFileSpec. -#endif /* PREF_USE_SYSDIR */ +} // nsPref::useDefaultPrefFile -#ifdef PREF_BACKOUT - if (!aPrefInst) - return; - -#if defined(XP_UNIX) - aPrefInst->Startup("preferences.js"); -#elif defined(XP_MAC) - aPrefInst->Startup("Netscape Preferences"); -#else /* XP_WIN */ - aPrefInst->Startup("prefs.js"); -#endif - -// aPrefInst->Startup("prefs50.js"); - -#endif /* PREF_BACKOUT */ - - return; -} - -nsPref *nsPref::GetInstance() +//---------------------------------------------------------------------------------------- +nsPref* nsPref::GetInstance() +//---------------------------------------------------------------------------------------- { - if (mInstance == NULL) { - mInstance = new nsPref(); - useDefaultPrefFile(mInstance); - } - return mInstance; -} - -/* - * nsISupports Implementation - */ + if (!gInstance) + { + gInstance = new nsPref(); + gInstance->StartUp(); + } + return gInstance; +} // nsPref::GetInstance NS_IMPL_ISUPPORTS(nsPref, kIPrefIID); -/* - * nsIPref Implementation - */ -NS_IMETHODIMP nsPref::Startup(const char *filename) + + +//======================================================================================== +// nsIPref Implementation +//======================================================================================== + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::StartUp() +//---------------------------------------------------------------------------------------- { + useDefaultPrefFile(); + return NS_OK; +} - if (!filename) +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::StartUpWith(const nsFileSpec& inFile) +//---------------------------------------------------------------------------------------- +{ + if (mFileSpec == inFile) + return NS_OK; + + PRBool ok = PR_TRUE; + + /* --ML hash test */ + if (!gHashTable) + gHashTable = PR_NewHashTable(2048, PR_HashString, PR_CompareStrings, + PR_CompareValues, &pref_HashAllocOps, NULL); + if (!gHashTable) + return PR_FALSE; + + mFileSpec = inFile; + + if (!gMochaTaskState) + gMochaTaskState = JS_Init((PRUint32) 0xffffffffL); + + if (!gMochaContext) { -#if defined(XP_UNIX) - return _convertRes(PREF_Init("preferences.js")); -#elif defined(XP_MAC) - return _convertRes(PREF_Init("Netscape Preferences")); -#else /* XP_WIN */ - return _convertRes(PREF_Init("prefs.js")); + gMochaContext = JS_NewContext(gMochaTaskState, 8192); /* ???? What size? */ + if (!gMochaContext) + return PR_FALSE; + + JS_BeginRequest(gMochaContext); + + gGlobalConfigObject = JS_NewObject(gMochaContext, &global_class, NULL, NULL); + if (!gGlobalConfigObject) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; + } + + /* MLM - need a global object for set version call now. */ + JS_SetGlobalObject(gMochaContext, gGlobalConfigObject); + + JS_SetVersion(gMochaContext, JSVERSION_1_2); + + if (!JS_InitStandardClasses(gMochaContext, + gGlobalConfigObject)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; + } + + JS_SetBranchCallback(gMochaContext, pref_BranchCallback); + JS_SetErrorReporter(gMochaContext, NULL); + + gMochaPrefObject = JS_DefineObject(gMochaContext, + gGlobalConfigObject, + "PrefConfig", + &autoconf_class, + NULL, + JSPROP_ENUMERATE|JSPROP_READONLY); + + if (gMochaPrefObject) + { + if (!JS_DefineProperties(gMochaContext, + gMochaPrefObject, + autoconf_props)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; + } + if (!JS_DefineFunctions(gMochaContext, + gMochaPrefObject, + autoconf_methods)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; + } + } + +#if !defined(XP_PC) && !defined(XP_OS2) && !defined(XP_MAC) + ok = pref_InitInitialObjects(); #endif + } + else + JS_BeginRequest(gMochaContext); - } - else - { - return _convertRes(PREF_Init(filename)); - } -} + if (ok && mFileSpec.Exists()) + ok = (JSBool) (pref_OpenFileSpec(mFileSpec, PR_TRUE, PR_FALSE, PR_FALSE, PR_TRUE) == PREF_NOERROR); + else if (!ok) + gErrorOpeningUserPrefs = PR_TRUE; + JS_EndRequest(gMochaContext); + return ok; +} // nsPref::StartUpWith -NS_IMETHODIMP nsPref::Shutdown() +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::ShutDown() +//---------------------------------------------------------------------------------------- { - PREF_Cleanup(); - - return NS_OK; -} + PREF_Cleanup(); + return NS_OK; +} // nsPref::ShutDown /* * Config file input */ +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::ReadUserJSFile(const char *filename) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_ReadUserJSFile(filename)); + return _convertRes(PREF_ReadUserJSFile(filename)); } +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::ReadLIJSFile(const char *filename) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_ReadLIJSFile(filename)); + return _convertRes(PREF_ReadLIJSFile(filename)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::EvaluateConfigScript(const char * js_buffer, + size_t length, + const char* filename, + PRBool bGlobalContext, + PRBool bCallbacks) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_EvaluateConfigScript(js_buffer, + length, + filename, + bGlobalContext, + bCallbacks, + PR_TRUE)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SavePrefFileAs(const char *filename) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_SavePrefFileAs(filename)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SaveLIPrefFile(const char *filename) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_SaveLIPrefFile(filename)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::CopyPathPref(const char *pref_name, char ** return_buffer) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_CopyPathPref(pref_name, return_buffer)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SetPathPref(const char *pref_name, const char *path, PRBool set_default) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_SetPathPref(pref_name, path, set_default)); +} + +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::ReadUserJSFile(const nsFileSpec& fileSpec) +//---------------------------------------------------------------------------------------- +{ + return pref_OpenFileSpec(fileSpec, PR_FALSE, PR_FALSE, PR_TRUE, PR_FALSE); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::ReadLIJSFile(const nsFileSpec& fileSpec) +//---------------------------------------------------------------------------------------- +{ + mLIFileSpec = fileSpec; + return pref_OpenFileSpec(fileSpec, PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::EvaluateConfigScript(const char * js_buffer, + size_t length, + PRBool bGlobalContext, + PRBool bCallbacks) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_EvaluateConfigScript(js_buffer, + length, + nsnull, // bad, but not used for parsing. + bGlobalContext, + bCallbacks, + PR_TRUE)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::EvaluateConfigScriptFile(const char * js_buffer, + size_t length, + const nsFileSpec& fileSpec, + PRBool bGlobalContext, + PRBool bCallbacks) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_EvaluateConfigScript(js_buffer, + length, + fileSpec.GetCString(), // bad, but not used for parsing. + bGlobalContext, + bCallbacks, + PR_TRUE)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SavePrefFileAs(const nsFileSpec& fileSpec) +//---------------------------------------------------------------------------------------- +{ + return _convertRes(PREF_SavePrefFileSpecWith(fileSpec, (PLHashEnumerator)pref_savePref)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SaveLIPrefFile(const nsFileSpec& fileSpec) +//---------------------------------------------------------------------------------------- +{ + if (!gHashTable) + return PREF_NOT_INITIALIZED; + PREF_SetSpecialPrefsLocal(); + return _convertRes(PREF_SavePrefFileSpecWith(fileSpec, (PLHashEnumerator)pref_saveLIPref)); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SavePrefFile() +//---------------------------------------------------------------------------------------- +{ + if (!gHashTable) + return PREF_NOT_INITIALIZED; +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + if (gFileName) + return _convertRes(PREF_SavePrefFile()); +#endif + return _convertRes(PREF_SavePrefFileSpecWith(mFileSpec, (PLHashEnumerator)pref_savePref)); } /* @@ -297,31 +558,17 @@ NS_IMETHODIMP nsPref::ReadLIJSFile(const char *filename) NS_IMETHODIMP nsPref::GetConfigContext(JSContext **js_context) { - return _convertRes(PREF_GetConfigContext(js_context)); + return _convertRes(PREF_GetConfigContext(js_context)); } NS_IMETHODIMP nsPref::GetGlobalConfigObject(JSObject **js_object) { - return _convertRes(PREF_GetGlobalConfigObject(js_object)); + return _convertRes(PREF_GetGlobalConfigObject(js_object)); } NS_IMETHODIMP nsPref::GetPrefConfigObject(JSObject **js_object) { - return _convertRes(PREF_GetPrefConfigObject(js_object)); -} - -NS_IMETHODIMP nsPref::EvaluateConfigScript(const char * js_buffer, - size_t length, - const char* filename, - PRBool bGlobalContext, - PRBool bCallbacks) -{ - return _convertRes(PREF_EvaluateConfigScript(js_buffer, - length, - filename, - bGlobalContext, - bCallbacks, - PR_TRUE)); + return _convertRes(PREF_GetPrefConfigObject(js_object)); } /* @@ -329,44 +576,44 @@ NS_IMETHODIMP nsPref::EvaluateConfigScript(const char * js_buffer, */ NS_IMETHODIMP nsPref::GetCharPref(const char *pref, - char * return_buf, int * buf_length) + char * return_buf, int * buf_length) { - return _convertRes(PREF_GetCharPref(pref, return_buf, buf_length)); + return _convertRes(PREF_GetCharPref(pref, return_buf, buf_length)); } NS_IMETHODIMP nsPref::GetIntPref(const char *pref, PRInt32 * return_int) { - return _convertRes(PREF_GetIntPref(pref, return_int)); + return _convertRes(PREF_GetIntPref(pref, return_int)); } NS_IMETHODIMP nsPref::GetBoolPref(const char *pref, PRBool * return_val) { - return _convertRes(PREF_GetBoolPref(pref, return_val)); + return _convertRes(PREF_GetBoolPref(pref, return_val)); } NS_IMETHODIMP nsPref::GetBinaryPref(const char *pref, - void * return_val, int * buf_length) + void * return_val, int * buf_length) { - return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length)); + return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length)); } NS_IMETHODIMP nsPref::GetColorPref(const char *pref, - uint8 *red, uint8 *green, uint8 *blue) + uint8 *red, uint8 *green, uint8 *blue) { - return _convertRes(PREF_GetColorPref(pref, red, green, blue)); + return _convertRes(PREF_GetColorPref(pref, red, green, blue)); } NS_IMETHODIMP nsPref::GetColorPrefDWord(const char *pref, PRUint32 *colorref) { - return _convertRes(PREF_GetColorPrefDWord(pref, colorref)); + return _convertRes(PREF_GetColorPrefDWord(pref, colorref)); } NS_IMETHODIMP nsPref::GetRectPref(const char *pref, - PRInt16 *left, PRInt16 *top, - PRInt16 *right, PRInt16 *bottom) + PRInt16 *left, PRInt16 *top, + PRInt16 *right, PRInt16 *bottom) { - return _convertRes(PREF_GetRectPref(pref, left, top, right, bottom)); + return _convertRes(PREF_GetRectPref(pref, left, top, right, bottom)); } /* @@ -375,41 +622,41 @@ NS_IMETHODIMP nsPref::GetRectPref(const char *pref, NS_IMETHODIMP nsPref::SetCharPref(const char *pref,const char* value) { - return _convertRes(PREF_SetCharPref(pref, value)); + return _convertRes(PREF_SetCharPref(pref, value)); } NS_IMETHODIMP nsPref::SetIntPref(const char *pref,PRInt32 value) { - return _convertRes(PREF_SetIntPref(pref, value)); + return _convertRes(PREF_SetIntPref(pref, value)); } NS_IMETHODIMP nsPref::SetBoolPref(const char *pref,PRBool value) { - return _convertRes(PREF_SetBoolPref(pref, value)); + return _convertRes(PREF_SetBoolPref(pref, value)); } NS_IMETHODIMP nsPref::SetBinaryPref(const char *pref,void * value, long size) { - return _convertRes(PREF_SetBinaryPref(pref, value, size)); + return _convertRes(PREF_SetBinaryPref(pref, value, size)); } NS_IMETHODIMP nsPref::SetColorPref(const char *pref, - uint8 red, uint8 green, uint8 blue) + uint8 red, uint8 green, uint8 blue) { - return _convertRes(PREF_SetColorPref(pref, red, green, blue)); + return _convertRes(PREF_SetColorPref(pref, red, green, blue)); } NS_IMETHODIMP nsPref::SetColorPrefDWord(const char *pref, PRUint32 value) { - return _convertRes(PREF_SetColorPrefDWord(pref, value)); + return _convertRes(PREF_SetColorPrefDWord(pref, value)); } NS_IMETHODIMP nsPref::SetRectPref(const char *pref, - PRInt16 left, PRInt16 top, - PRInt16 right, PRInt16 bottom) + PRInt16 left, PRInt16 top, + PRInt16 right, PRInt16 bottom) { - return _convertRes(PREF_SetRectPref(pref, left, top, right, bottom)); + return _convertRes(PREF_SetRectPref(pref, left, top, right, bottom)); } /* @@ -420,47 +667,47 @@ NS_IMETHODIMP nsPref::GetDefaultCharPref(const char *pref, char * return_buf, int * buf_length) { - return _convertRes(PREF_GetDefaultCharPref(pref, return_buf, buf_length)); + return _convertRes(PREF_GetDefaultCharPref(pref, return_buf, buf_length)); } NS_IMETHODIMP nsPref::GetDefaultIntPref(const char *pref, PRInt32 * return_int) { - return _convertRes(PREF_GetDefaultIntPref(pref, return_int)); + return _convertRes(PREF_GetDefaultIntPref(pref, return_int)); } NS_IMETHODIMP nsPref::GetDefaultBoolPref(const char *pref, PRBool * return_val) { - return _convertRes(PREF_GetDefaultBoolPref(pref, return_val)); + return _convertRes(PREF_GetDefaultBoolPref(pref, return_val)); } NS_IMETHODIMP nsPref::GetDefaultBinaryPref(const char *pref, - void * return_val, - int * buf_length) + void * return_val, + int * buf_length) { - return _convertRes(PREF_GetDefaultBinaryPref(pref, return_val, buf_length)); + return _convertRes(PREF_GetDefaultBinaryPref(pref, return_val, buf_length)); } NS_IMETHODIMP nsPref::GetDefaultColorPref(const char *pref, - uint8 *red, uint8 *green, - uint8 *blue) + uint8 *red, uint8 *green, + uint8 *blue) { - return _convertRes(PREF_GetDefaultColorPref(pref, red, green, blue)); + return _convertRes(PREF_GetDefaultColorPref(pref, red, green, blue)); } NS_IMETHODIMP nsPref::GetDefaultColorPrefDWord(const char *pref, - PRUint32 *colorref) + PRUint32 *colorref) { - return _convertRes(PREF_GetDefaultColorPrefDWord(pref, colorref)); + return _convertRes(PREF_GetDefaultColorPrefDWord(pref, colorref)); } NS_IMETHODIMP nsPref::GetDefaultRectPref(const char *pref, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom) { - return _convertRes(PREF_GetDefaultRectPref(pref, - left, top, right, bottom)); + return _convertRes(PREF_GetDefaultRectPref(pref, + left, top, right, bottom)); } /* @@ -469,41 +716,41 @@ NS_IMETHODIMP nsPref::GetDefaultRectPref(const char *pref, NS_IMETHODIMP nsPref::SetDefaultCharPref(const char *pref,const char* value) { - return _convertRes(PREF_SetDefaultCharPref(pref, value)); + return _convertRes(PREF_SetDefaultCharPref(pref, value)); } NS_IMETHODIMP nsPref::SetDefaultIntPref(const char *pref,PRInt32 value) { - return _convertRes(PREF_SetDefaultIntPref(pref, value)); + return _convertRes(PREF_SetDefaultIntPref(pref, value)); } NS_IMETHODIMP nsPref::SetDefaultBoolPref(const char *pref, PRBool value) { - return _convertRes(PREF_SetDefaultBoolPref(pref, value)); + return _convertRes(PREF_SetDefaultBoolPref(pref, value)); } NS_IMETHODIMP nsPref::SetDefaultBinaryPref(const char *pref, - void * value, long size) + void * value, long size) { - return _convertRes(PREF_SetDefaultBinaryPref(pref, value, size)); + return _convertRes(PREF_SetDefaultBinaryPref(pref, value, size)); } NS_IMETHODIMP nsPref::SetDefaultColorPref(const char *pref, - uint8 red, uint8 green, uint8 blue) + uint8 red, uint8 green, uint8 blue) { - return _convertRes(PREF_SetDefaultColorPref(pref, red, green, blue)); + return _convertRes(PREF_SetDefaultColorPref(pref, red, green, blue)); } NS_IMETHODIMP nsPref::SetDefaultRectPref(const char *pref, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom) { - return _convertRes(PREF_SetDefaultRectPref(pref, left, top, right, bottom)); + return _convertRes(PREF_SetDefaultRectPref(pref, left, top, right, bottom)); } NS_IMETHODIMP nsPref::ClearUserPref(const char *pref_name) { - return _convertRes(PREF_ClearUserPref(pref_name)); + return _convertRes(PREF_ClearUserPref(pref_name)); } /* @@ -512,224 +759,387 @@ NS_IMETHODIMP nsPref::ClearUserPref(const char *pref_name) NS_IMETHODIMP nsPref::CopyCharPref(const char *pref, char ** return_buf) { - return _convertRes(PREF_CopyCharPref(pref, return_buf)); + return _convertRes(PREF_CopyCharPref(pref, return_buf)); } NS_IMETHODIMP nsPref::CopyBinaryPref(const char *pref, - void ** return_value, int *size) + void ** return_value, int *size) { - return _convertRes(PREF_CopyBinaryPref(pref, return_value, size)); + return _convertRes(PREF_CopyBinaryPref(pref, return_value, size)); } NS_IMETHODIMP nsPref::CopyDefaultCharPref( const char *pref, - char ** return_buffer ) + char ** return_buffer ) { - return _convertRes(PREF_CopyDefaultCharPref(pref, return_buffer)); + return _convertRes(PREF_CopyDefaultCharPref(pref, return_buffer)); } NS_IMETHODIMP nsPref::CopyDefaultBinaryPref(const char *pref, - void ** return_val, int * size) + void ** return_val, int * size) { - return _convertRes(PREF_CopyDefaultBinaryPref(pref, return_val, size)); + return _convertRes(PREF_CopyDefaultBinaryPref(pref, return_val, size)); } +#if 0 /* * Path prefs */ +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::CopyPathPref(const char *pref, char ** return_buf) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_CopyPathPref(pref, return_buf)); + return _convertRes(PREF_CopyPathPref(pref, return_buf)); } +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::SetPathPref(const char *pref, - const char *path, PRBool set_default) + const char *path, PRBool set_default) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_SetPathPref(pref, path, set_default)); + return _convertRes(PREF_SetPathPref(pref, path, set_default)); +} +#endif + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::GetFilePref(const char *pref_name, nsFileSpec* value) +//---------------------------------------------------------------------------------------- +{ + if (!value) + return NS_ERROR_NULL_POINTER; + char *encodedString = nsnull; + PrefResult result = PREF_CopyCharPref(pref_name, &encodedString); + if (result != PREF_NOERROR) + return _convertRes(result); + + nsInputStringStream stream(encodedString); + nsPersistentFileDescriptor descriptor; + stream >> descriptor; + PR_Free(encodedString); // Allocated by PREF_CopyCharPref + *value = descriptor; + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsPref::SetFilePref(const char *pref_name, + const nsFileSpec* value, PRBool set_default) +//---------------------------------------------------------------------------------------- +{ + if (!value) + return NS_ERROR_NULL_POINTER; + nsresult rv = NS_OK; + if (!value->Exists()) + { + // nsPersistentFileDescriptor requires an existing + // object. Make it first. + nsFileSpec tmp(*value); + tmp.CreateDir(); + } + nsPersistentFileDescriptor descriptor(*value); + char* encodedString = nsnull; + nsOutputStringStream stream(encodedString); + stream << descriptor; + if (encodedString && *encodedString) + { + if (set_default) + rv = PREF_SetDefaultCharPref(pref_name, encodedString); + else + rv = PREF_SetCharPref(pref_name, encodedString); + } + delete [] encodedString; // Allocated by nsOutputStringStream + return rv; } /* * Pref info */ +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::PrefIsLocked(const char *pref, PRBool *res) +//---------------------------------------------------------------------------------------- { - if (res == NULL) { - return NS_ERROR_INVALID_POINTER; - } + if (res == NULL) + return NS_ERROR_INVALID_POINTER; - *res = PREF_PrefIsLocked(pref); - return NS_OK; -} - -/* - * Save pref files - */ - -NS_IMETHODIMP nsPref::SavePrefFile(void) -{ - return _convertRes(PREF_SavePrefFile()); -} - -NS_IMETHODIMP nsPref::SavePrefFileAs(const char *filename) -{ - return _convertRes(PREF_SavePrefFileAs(filename)); -} - -NS_IMETHODIMP nsPref::SaveLIPrefFile(const char *filename) -{ - return _convertRes(PREF_SaveLIPrefFile(filename)); + *res = PREF_PrefIsLocked(pref); + return NS_OK; } /* * Callbacks */ +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::RegisterCallback( const char* domain, PrefChangedFunc callback, void* instance_data ) +//---------------------------------------------------------------------------------------- { - PREF_RegisterCallback(domain, callback, instance_data); - return NS_OK; + PREF_RegisterCallback(domain, callback, instance_data); + return NS_OK; } +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::UnregisterCallback( const char* domain, - PrefChangedFunc callback, - void* instance_data ) + PrefChangedFunc callback, + void* instance_data ) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_UnregisterCallback(domain, callback, instance_data)); + return _convertRes(PREF_UnregisterCallback(domain, callback, instance_data)); } /* - * Callbacks + * Tree editing */ +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::CopyPrefsTree(const char *srcRoot, const char *destRoot) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_CopyPrefsTree(srcRoot, destRoot)); + return _convertRes(PREF_CopyPrefsTree(srcRoot, destRoot)); } +//---------------------------------------------------------------------------------------- NS_IMETHODIMP nsPref::DeleteBranch(const char *branchName) +//---------------------------------------------------------------------------------------- { - return _convertRes(PREF_DeleteBranch(branchName)); + return _convertRes(PREF_DeleteBranch(branchName)); } -class nsPrefFactory: public nsIFactory { - NS_DECL_ISUPPORTS - - nsPrefFactory() { - NS_INIT_REFCNT(); - PR_AtomicIncrement(&g_InstanceCount); - } - - virtual ~nsPrefFactory() { - PR_AtomicDecrement(&g_InstanceCount); - } - - NS_IMETHOD CreateInstance(nsISupports *aDelegate, - const nsIID &aIID, - void **aResult); - - NS_IMETHOD LockFactory(PRBool aLock) { - if (aLock) { - PR_AtomicIncrement(&g_LockCount); - } else { - PR_AtomicDecrement(&g_LockCount); +//======================================================================================== +class nsPrefFactory: public nsIFactory +//======================================================================================== +{ + NS_DECL_ISUPPORTS + + nsPrefFactory() + { + NS_INIT_REFCNT(); + PR_AtomicIncrement(&g_InstanceCount); } - return NS_OK; - }; + + virtual ~nsPrefFactory() + { + PR_AtomicDecrement(&g_InstanceCount); + } + + NS_IMETHOD CreateInstance(nsISupports *aDelegate, + const nsIID &aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock) { + if (aLock) { + PR_AtomicIncrement(&g_LockCount); + } else { + PR_AtomicDecrement(&g_LockCount); + } + return NS_OK; + }; }; static NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID); NS_IMPL_ISUPPORTS(nsPrefFactory, kFactoryIID); -nsresult nsPrefFactory::CreateInstance(nsISupports *aDelegate, - const nsIID &aIID, - void **aResult) +//---------------------------------------------------------------------------------------- +nsresult nsPrefFactory::CreateInstance( + nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +//---------------------------------------------------------------------------------------- { - if (aDelegate != NULL) { - return NS_ERROR_NO_AGGREGATION; - } + if (aDelegate != NULL) + return NS_ERROR_NO_AGGREGATION; - nsPref *t = nsPref::GetInstance(); - - if (t == NULL) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsresult res = t->QueryInterface(aIID, aResult); - - if (NS_FAILED(res)) { - *aResult = NULL; - } + nsPref *t = nsPref::GetInstance(); + + if (t == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = t->QueryInterface(aIID, aResult); + + if (NS_FAILED(res)) + *aResult = NULL; - return res; -} - -extern "C" NS_EXPORT nsresult -NSGetFactory(nsISupports* serviceMgr, - const nsCID &aClass, - const char *aClassName, - const char *aProgID, - nsIFactory **aFactory) -{ - if (aFactory == NULL) { - return NS_ERROR_NULL_POINTER; - } - if (aClass.Equals(kPrefCID)) { - nsPrefFactory *factory = new nsPrefFactory(); - nsresult res = factory->QueryInterface(kFactoryIID, (void **) aFactory); - if (NS_FAILED(res)) { - *aFactory = NULL; - delete factory; - } return res; - } - return NS_NOINTERFACE; } +//---------------------------------------------------------------------------------------- +extern "C" NS_EXPORT nsresult NSGetFactory( + nsISupports* serviceMgr, + const nsCID &aClass, + const char *aClassName, + const char *aProgID, + nsIFactory **aFactory) +//---------------------------------------------------------------------------------------- +{ + if (aFactory == NULL) + return NS_ERROR_NULL_POINTER; + + if (aClass.Equals(kPrefCID)) + { + nsPrefFactory *factory = new nsPrefFactory(); + nsresult res = factory->QueryInterface(kFactoryIID, (void **) aFactory); + if (NS_FAILED(res)) + { + *aFactory = NULL; + delete factory; + } + return res; + } + return NS_NOINTERFACE; +} + +//---------------------------------------------------------------------------------------- extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* serviceMgr) +//---------------------------------------------------------------------------------------- { - return PRBool(g_InstanceCount == 0 && g_LockCount == 0); + return PRBool(g_InstanceCount == 0 && g_LockCount == 0); } +//---------------------------------------------------------------------------------------- extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *path) +//---------------------------------------------------------------------------------------- { - nsresult rv; + nsresult rv; - nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) return rv; - nsIComponentManager* compMgr; - rv = servMgr->GetService(kComponentManagerCID, - nsIComponentManager::GetIID(), - (nsISupports**)&compMgr); - if (NS_FAILED(rv)) return rv; + nsIComponentManager* compMgr; + rv = servMgr->GetService(kComponentManagerCID, + nsIComponentManager::GetIID(), + (nsISupports**)&compMgr); + if (NS_FAILED(rv)) return rv; - rv = compMgr->RegisterComponent(kPrefCID, NULL, NULL, path, - PR_TRUE, PR_TRUE); + rv = compMgr->RegisterComponent(kPrefCID, NULL, NULL, path, + PR_TRUE, PR_TRUE); - (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); - return rv; + (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); + return rv; } +//---------------------------------------------------------------------------------------- extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path) +//---------------------------------------------------------------------------------------- { - nsresult rv; + nsresult rv; - nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) return rv; - nsIComponentManager* compMgr; - rv = servMgr->GetService(kComponentManagerCID, - nsIComponentManager::GetIID(), - (nsISupports**)&compMgr); - if (NS_FAILED(rv)) return rv; + nsIComponentManager* compMgr; + rv = servMgr->GetService( + kComponentManagerCID, + nsIComponentManager::GetIID(), + (nsISupports**)&compMgr); + if (NS_FAILED(rv)) + return rv; - rv = compMgr->UnregisterFactory(kPrefCID, path); + rv = compMgr->UnregisterFactory(kPrefCID, path); - (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); - return rv; + (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); + return rv; } +//======================================================================================== +// C++ implementations of old C routines +//======================================================================================== + +//---------------------------------------------------------------------------------------- +PrefResult pref_OpenFileSpec( + const nsFileSpec& fileSpec, + PRBool is_error_fatal, + PRBool verifyHash, + PRBool bGlobalContext, + PRBool skipFirstLine) +//---------------------------------------------------------------------------------------- +{ + PrefResult result = PREF_NOERROR; + + if (!fileSpec.Exists()) + return PREF_ERROR; + + PRUint32 fileLength = fileSpec.GetFileSize(); + if (fileLength == 0) + return PREF_ERROR; + + nsInputFileStream stream(fileSpec); + if (!stream.is_open()) + result = PREF_ERROR; + + char* readBuf = nsnull; + if (result == PREF_NOERROR) + { + readBuf = (char*)PR_MALLOC(fileLength * sizeof(char)); + if (!readBuf) + result = PREF_OUT_OF_MEMORY; + } + + if (result == PREF_NOERROR) + { + PRUint32 bytesRead = stream.read(readBuf, fileLength); + if (bytesRead < fileLength) + result = PREF_ERROR; + else if (verifyHash && !pref_VerifyLockFile(readBuf, fileLength)) + result = PREF_BAD_LOCKFILE; + else if (PREF_EvaluateConfigScript(readBuf, fileLength, + fileSpec.GetCString(), bGlobalContext, PR_FALSE, skipFirstLine)) + result = PREF_NOERROR; + PR_Free(readBuf); + } + + // If the user prefs file exists but generates an error, + // don't clobber the file when we try to save it + if ((!readBuf || result != PREF_NOERROR) && is_error_fatal) + gErrorOpeningUserPrefs = PR_TRUE; +#ifdef XP_PC + if (gErrorOpeningUserPrefs && is_error_fatal) + MessageBox(nsnull,"Error in preference file (prefs.js). Default preferences will be used.","Netscape - Warning", MB_OK); +#endif + + JS_GC(gMochaContext); + return result; +} // pref_OpenFile + +//---------------------------------------------------------------------------------------- +PR_IMPLEMENT(PrefResult) PREF_SavePrefFileSpecWith( + const nsFileSpec& fileSpec, + PLHashEnumerator heSaveProc) +//---------------------------------------------------------------------------------------- +{ + if (!gHashTable) + return PREF_NOT_INITIALIZED; + + /* ?! Don't save (blank) user prefs if there was an error reading them */ + if (gErrorOpeningUserPrefs) + return PREF_NOERROR; + + char** valueArray = (char**) PR_Calloc(sizeof(char*), gHashTable->nentries); + if (!valueArray) + return PREF_OUT_OF_MEMORY; + + nsOutputFileStream stream(fileSpec); + if (!stream.is_open()) + return PREF_ERROR; + + stream << "// Mozilla User Preferences" << LINEBREAK + << "// This is a generated file! Do not edit." + << LINEBREAK << LINEBREAK; + + /* LI_STUFF here we pass in the heSaveProc proc used so that li can do its own thing */ + PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray); + + /* Sort the preferences to make a readable file on disk */ + XP_QSORT(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings); + for (PRUint32 valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++) + { + if (valueArray[valueIdx]) + { + stream << valueArray[valueIdx]; + PR_Free(valueArray[valueIdx]); + } + } + PR_Free(valueArray); + return PREF_NOERROR; +} diff --git a/mozilla/modules/libpref/src/prefapi.c b/mozilla/modules/libpref/src/prefapi.c index d30032c6ca1..b7bc1464977 100644 --- a/mozilla/modules/libpref/src/prefapi.c +++ b/mozilla/modules/libpref/src/prefapi.c @@ -29,21 +29,25 @@ **/ +#include "prefapi.h" + #include "jsapi.h" -#if defined(XP_MAC) -#include -#else -#include -#endif -#include -#ifdef _WIN32 -#include "windows.h" -#endif +#define PREF_SUPPORT_OLD_PATH_STRINGS 1 +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + #if defined(XP_MAC) + #include + #else + #include + #endif + #include + #ifdef _WIN32 + #include "windows.h" + #endif /* _WIN32 */ +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ #ifdef MOZ_ADMIN_LIB #include "prefldap.h" #endif -#include "prefapi.h" #if defined(XP_MAC) || defined(XP_UNIX) #include "fe_proto.h" @@ -63,7 +67,6 @@ #include "xpassert.h" #include "xp_str.h" -/* WHS TEMPORARY */ #define XP_QSORT qsort #if defined(XP_MAC) && defined (__MWERKS__) @@ -71,26 +74,6 @@ #pragma require_prototypes off #endif -JSTaskState * m_mochaTaskState = NULL; -JSContext * m_mochaContext = NULL; -JSObject * m_mochaPrefObject = NULL; -JSObject * m_GlobalConfigObject = NULL; - -static char * m_filename = NULL; -static char * m_lifilename = NULL; -static struct CallbackNode* m_Callbacks = NULL; -static PRBool m_ErrorOpeningUserPrefs = PR_FALSE; -static PRBool m_CallbacksEnabled = PR_FALSE; -static PRBool m_IsAnyPrefLocked = PR_FALSE; -static PRHashTable* m_HashTable = NULL; -static char * m_SavedLine = NULL; - -#define PREF_IS_LOCKED(pref) ((pref)->flags & PREF_LOCKED) -#define PREF_IS_CONFIG(pref) ((pref)->flags & PREF_CONFIG) -#define PREF_HAS_USER_VALUE(pref) ((pref)->flags & PREF_USERSET) -#define PREF_HAS_LI_VALUE(pref) ((pref)->flags & PREF_LILOCAL) /* LI_STUFF */ -#define PREF_TYPE(pref) (PrefType)((pref)->flags & PREF_VALUETYPE_MASK) - typedef union { char* stringVal; @@ -105,30 +88,26 @@ typedef struct uint8 flags; } PrefNode; -static JSBool pref_HashJSPref(unsigned int argc, jsval *argv, PrefAction action); -static PRBool pref_ValueChanged(PrefValue oldValue, PrefValue newValue, PrefType type); +/*----------------------- +** Hash table allocation +**----------------------*/ -/* Hash table allocation */ -PR_IMPLEMENT(void *) -pref_AllocTable(void *pool, size_t size) +PR_IMPLEMENT(void *) pref_AllocTable(void *pool, size_t size) { return malloc(size); } -PR_IMPLEMENT(void) -pref_FreeTable(void *pool, void *item) +PR_IMPLEMENT(void) pref_FreeTable(void *pool, void *item) { free(item); /* free items? */ } -PR_IMPLEMENT(PRHashEntry *) -pref_AllocEntry(void *pool, const void *key) +PR_IMPLEMENT(PLHashEntry *) pref_AllocEntry(void *pool, const void *key) { - return malloc(sizeof(PRHashEntry)); + return malloc(sizeof(PLHashEntry)); } -PR_IMPLEMENT(void) -pref_FreeEntry(void *pool, PRHashEntry *he, uint flag) +PR_IMPLEMENT(void) pref_FreeEntry(void *pool, PLHashEntry *he, uint flag) { PrefNode *pref = (PrefNode *) he->value; if (pref) { @@ -145,54 +124,6 @@ pref_FreeEntry(void *pool, PRHashEntry *he, uint flag) } } -static PRHashAllocOps pref_HashAllocOps = { - pref_AllocTable, pref_FreeTable, - pref_AllocEntry, pref_FreeEntry -}; - -#include "prlink.h" -extern PRLibrary *pref_LoadAutoAdminLib(void); -PRLibrary *m_AutoAdminLib = NULL; - -/* -- Privates */ -struct CallbackNode { - char* domain; - PrefChangedFunc func; - void* data; - struct CallbackNode* next; -}; - -/* -- Prototypes */ -PrefResult pref_DoCallback(const char* changed_pref); -PrefResult pref_OpenFile( - const char* filename, - PRBool is_error_fatal, - PRBool verifyHash, - PRBool bGlobalContext, - PRBool skipFirstLine); -PRBool pref_VerifyLockFile(char* buf, long buflen); - -PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default); -PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default); -PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default); -PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default); - -JSBool PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script); -void pref_ErrorReporter(JSContext *cx, const char *message,JSErrorReport *report); -void pref_Alert(char* msg); -PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAction action); - -/* -- Platform specific function extern */ -#if !defined(XP_WIN) && !defined(XP_OS2) -extern JSBool pref_InitInitialObjects(void); -#endif - -static JSClass global_class = { - "global", 0, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub -}; - JSBool PR_CALLBACK pref_NativeDefaultPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK pref_NativeUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK pref_NativeLockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); @@ -206,33 +137,105 @@ JSBool PR_CALLBACK pref_NativeLILocalPref(JSContext *cx, JSObject *obj, unsigned JSBool PR_CALLBACK pref_NativeLIUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK pref_NativeLIDefPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); +/*----------------------------------------------------------------------------------------*/ +#include "prefapi_private_data.h" -/* LI_STUFF added localPref pref_NativeLILocalPref, 1 */ -static JSFunctionSpec autoconf_methods[] = { - { "pref", pref_NativeDefaultPref, 2 }, - { "defaultPref", pref_NativeDefaultPref, 2 }, - { "user_pref", pref_NativeUserPref, 2 }, - { "lockPref", pref_NativeLockPref, 2 }, - { "unlockPref", pref_NativeUnlockPref, 1 }, - { "config", pref_NativeSetConfig, 2 }, - { "getPref", pref_NativeGetPref, 1 }, - { "getLDAPAttributes", pref_NativeGetLDAPAttr, 4 }, - { "localPref", pref_NativeLILocalPref, 1 }, - { "localUserPref", pref_NativeLIUserPref, 2 }, - { "localDefPref", pref_NativeLIDefPref, 2 }, - { NULL, NULL, 0 } +JSTaskState * gMochaTaskState = NULL; +JSContext * gMochaContext = NULL; +JSObject * gMochaPrefObject = NULL; +JSObject * gGlobalConfigObject = NULL; +JSClass global_class = { + "global", 0, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub + }; +JSClass autoconf_class = { + "PrefConfig", 0, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub + }; +JSPropertySpec autoconf_props[] = { + {0} + }; +JSFunctionSpec autoconf_methods[] = { + { "pref", pref_NativeDefaultPref, 2 }, + { "defaultPref", pref_NativeDefaultPref, 2 }, + { "user_pref", pref_NativeUserPref, 2 }, + { "lockPref", pref_NativeLockPref, 2 }, + { "unlockPref", pref_NativeUnlockPref, 1 }, + { "config", pref_NativeSetConfig, 2 }, + { "getPref", pref_NativeGetPref, 1 }, + { "getLDAPAttributes", pref_NativeGetLDAPAttr, 4 }, + { "localPref", pref_NativeLILocalPref, 1 }, + { "localUserPref", pref_NativeLIUserPref, 2 }, + { "localDefPref", pref_NativeLIDefPref, 2 }, + { NULL, NULL, 0 } + }; + +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +char * gFileName = NULL; +char * gLIFileName = NULL; +#endif /*PREF_SUPPORT_OLD_PATH_STRINGS*/ + +struct CallbackNode* gCallbacks = NULL; +PRBool gErrorOpeningUserPrefs = PR_FALSE; +PRBool gCallbacksEnabled = PR_FALSE; +PRBool gIsAnyPrefLocked = PR_FALSE; +PLHashTable* gHashTable = NULL; +char * gSavedLine = NULL; +PLHashAllocOps pref_HashAllocOps = { + pref_AllocTable, pref_FreeTable, + pref_AllocEntry, pref_FreeEntry + }; + +/*----------------------------------------------------------------------------------------*/ + +#define PREF_IS_LOCKED(pref) ((pref)->flags & PREF_LOCKED) +#define PREF_IS_CONFIG(pref) ((pref)->flags & PREF_CONFIG) +#define PREF_HAS_USER_VALUE(pref) ((pref)->flags & PREF_USERSET) +#define PREF_HAS_LI_VALUE(pref) ((pref)->flags & PREF_LILOCAL) /* LI_STUFF */ +#define PREF_TYPE(pref) (PrefType)((pref)->flags & PREF_VALUETYPE_MASK) + +static JSBool pref_HashJSPref(unsigned int argc, jsval *argv, PrefAction action); +static PRBool pref_ValueChanged(PrefValue oldValue, PrefValue newValue, PrefType type); + +#include "prlink.h" +extern PRLibrary *pref_LoadAutoAdminLib(void); +PRLibrary *gAutoAdminLib = NULL; + +/* -- Privates */ +struct CallbackNode { + char* domain; + PrefChangedFunc func; + void* data; + struct CallbackNode* next; }; -static JSPropertySpec autoconf_props[] = { - {0} -}; +/* -- Prototypes */ +PrefResult pref_DoCallback(const char* changed_pref); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PrefResult pref_OpenFile( + const char* filename, + PRBool is_error_fatal, + PRBool verifyHash, + PRBool bGlobalContext, + PRBool skipFirstLine); +PR_EXTERN(PrefResult) PREF_SavePrefFileWith(const char *filename, PLHashEnumerator heSaveProc); +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -static JSClass autoconf_class = { - "PrefConfig", 0, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub -}; +PRBool pref_VerifyLockFile(char* buf, long buflen); +PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default); +PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default); +PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default); +PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default); + +JSBool PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script); +void pref_ErrorReporter(JSContext *cx, const char *message,JSErrorReport *report); +void pref_Alert(char* msg); +PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAction action); + +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS PrefResult pref_OpenFile( const char* filename, PRBool is_error_fatal, @@ -254,17 +257,19 @@ PrefResult pref_OpenFile( return PREF_ERROR; fp = fopen(filename, "r"); - if (fp) { + if (fp) + { char* readBuf = (char *) malloc(fileLength * sizeof(char)); - if (readBuf) { + if (readBuf) + { fileLength = fread(readBuf, sizeof(char), fileLength, fp); - if ( verifyHash && pref_VerifyLockFile(readBuf, fileLength) == PR_FALSE ) + if ( verifyHash && !pref_VerifyLockFile(readBuf, fileLength)) { ok = PREF_BAD_LOCKFILE; } - else if ( PREF_EvaluateConfigScript(readBuf, fileLength, - filename, bGlobalContext, PR_FALSE, skipFirstLine ) == JS_TRUE ) + else if (PREF_EvaluateConfigScript(readBuf, fileLength, + filename, bGlobalContext, PR_FALSE, skipFirstLine )) { ok = PREF_NOERROR; } @@ -275,15 +280,16 @@ PrefResult pref_OpenFile( /* If the user prefs file exists but generates an error, don't clobber the file when we try to save it. */ if ((!readBuf || ok != PREF_NOERROR) && is_error_fatal) - m_ErrorOpeningUserPrefs = PR_TRUE; + gErrorOpeningUserPrefs = PR_TRUE; #ifdef XP_PC - if (m_ErrorOpeningUserPrefs && is_error_fatal) + if (gErrorOpeningUserPrefs && is_error_fatal) MessageBox(NULL,"Error in preference file (prefs.js). Default preferences will be used.","Netscape - Warning", MB_OK); #endif } - JS_GC(m_mochaContext); + JS_GC(gMochaContext); return (ok); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ /* Computes the MD5 hash of the given buffer (not including the first line) and verifies the first line of the buffer expresses the correct hash in the form: @@ -339,115 +345,127 @@ PRBool pref_VerifyLockFile(char* buf, long buflen) #endif } -PR_IMPLEMENT(PrefResult) -PREF_ReadLIJSFile(const char *filename) +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_ReadLIJSFile(const char *filename) { PrefResult ok; - if (filename) m_lifilename = strdup(filename); + if (filename) + { + free(gLIFileName); + gLIFileName = strdup(filename); + } ok = pref_OpenFile(filename, PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE); return ok; } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -PR_IMPLEMENT(PrefResult) -PREF_ReadUserJSFile(const char *filename) +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_ReadUserJSFile(const char *filename) { PrefResult ok = pref_OpenFile(filename, PR_FALSE, PR_FALSE, PR_TRUE, PR_FALSE); return ok; } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -PR_IMPLEMENT(PRBool) -PREF_Init(const char *filename) +PR_IMPLEMENT(PRBool) PREF_Init(const char *filename) { PRBool ok = PR_TRUE; /* --ML hash test */ - if (!m_HashTable) - m_HashTable = PR_NewHashTable(2048, PR_HashString, PR_CompareStrings, + if (!gHashTable) + gHashTable = PR_NewHashTable(2048, PR_HashString, PR_CompareStrings, PR_CompareValues, &pref_HashAllocOps, NULL); - if (!m_HashTable) + if (!gHashTable) return PR_FALSE; - if (filename) { - if (m_filename) /* happens if PREF_Init is called twice (it is) */ - free(m_filename); - m_filename = strdup(filename); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + if (filename) + { + if (gFileName) /* happens if PREF_Init is called twice (it is) */ + PL_strfree(gFileName); + gFileName = PL_strdup(filename); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ - if (!m_mochaTaskState) - m_mochaTaskState = JS_Init((PRUint32) 0xffffffffL); + if (!gMochaTaskState) + gMochaTaskState = JS_Init((PRUint32) 0xffffffffL); - if (!m_mochaContext) { - m_mochaContext = JS_NewContext(m_mochaTaskState, 8192); /* ???? What size? */ - if (!m_mochaContext) { + if (!gMochaContext) + { + gMochaContext = JS_NewContext(gMochaTaskState, 8192); /* ???? What size? */ + if (!gMochaContext) return PR_FALSE; - } - JS_BeginRequest(m_mochaContext); + JS_BeginRequest(gMochaContext); - m_GlobalConfigObject = JS_NewObject(m_mochaContext, &global_class, NULL, NULL); - if (!m_GlobalConfigObject) { - JS_EndRequest(m_mochaContext); + gGlobalConfigObject = JS_NewObject(gMochaContext, &global_class, NULL, NULL); + if (!gGlobalConfigObject) + { + JS_EndRequest(gMochaContext); return PR_FALSE; - } + } - /* MLM - need a global object for set version call now. */ - JS_SetGlobalObject(m_mochaContext, m_GlobalConfigObject); + /* MLM - need a global object for set version call now. */ + JS_SetGlobalObject(gMochaContext, gGlobalConfigObject); - JS_SetVersion(m_mochaContext, JSVERSION_1_2); + JS_SetVersion(gMochaContext, JSVERSION_1_2); - if (!JS_InitStandardClasses(m_mochaContext, - m_GlobalConfigObject)) { - JS_EndRequest(m_mochaContext); + if (!JS_InitStandardClasses(gMochaContext, + gGlobalConfigObject)) + { + JS_EndRequest(gMochaContext); return PR_FALSE; } - JS_SetBranchCallback(m_mochaContext, pref_BranchCallback); - JS_SetErrorReporter(m_mochaContext, NULL); + JS_SetBranchCallback(gMochaContext, pref_BranchCallback); + JS_SetErrorReporter(gMochaContext, NULL); - m_mochaPrefObject = JS_DefineObject(m_mochaContext, - m_GlobalConfigObject, + gMochaPrefObject = JS_DefineObject(gMochaContext, + gGlobalConfigObject, "PrefConfig", &autoconf_class, NULL, JSPROP_ENUMERATE|JSPROP_READONLY); - if (m_mochaPrefObject) { - if (!JS_DefineProperties(m_mochaContext, - m_mochaPrefObject, - autoconf_props)) { - JS_EndRequest(m_mochaContext); - return PR_FALSE; + if (gMochaPrefObject) + { + if (!JS_DefineProperties(gMochaContext, + gMochaPrefObject, + autoconf_props)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; } - - if (!JS_DefineFunctions(m_mochaContext, - m_mochaPrefObject, - autoconf_methods)) { - JS_EndRequest(m_mochaContext); - return PR_FALSE; + if (!JS_DefineFunctions(gMochaContext, + gMochaPrefObject, + autoconf_methods)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; } - } #if !defined(XP_PC) && !defined(XP_OS2) && !defined(XP_MAC) ok = pref_InitInitialObjects(); #endif - } else { - JS_BeginRequest(m_mochaContext); } + else + JS_BeginRequest(gMochaContext); - if (ok && filename) { - ok = (JSBool) (pref_OpenFile(filename, PR_TRUE, PR_FALSE, PR_FALSE, PR_TRUE) == PREF_NOERROR); - } - else if (!ok) { - m_ErrorOpeningUserPrefs = PR_TRUE; - } - JS_EndRequest(m_mochaContext); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + if (ok && gFileName) + ok = (PRBool)(pref_OpenFile(gFileName, PR_TRUE, PR_FALSE, PR_FALSE, PR_TRUE) == PREF_NOERROR); + else +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ + if (!ok) + gErrorOpeningUserPrefs = PR_TRUE; + JS_EndRequest(gMochaContext); return ok; -} +} /*PREF_Init*/ PR_IMPLEMENT(PrefResult) PREF_GetConfigContext(JSContext **js_context) @@ -455,9 +473,9 @@ PREF_GetConfigContext(JSContext **js_context) if (!js_context) return PREF_ERROR; *js_context = NULL; - if (m_mochaContext) { - *js_context = m_mochaContext; - JS_SetContextThread(m_mochaContext); + if (gMochaContext) { + *js_context = gMochaContext; + JS_SetContextThread(gMochaContext); } return PREF_NOERROR; @@ -469,8 +487,8 @@ PREF_GetGlobalConfigObject(JSObject **js_object) if (!js_object) return PREF_ERROR; *js_object = NULL; - if (m_GlobalConfigObject) - *js_object = m_GlobalConfigObject; + if (gGlobalConfigObject) + *js_object = gGlobalConfigObject; return PREF_NOERROR; } @@ -481,32 +499,34 @@ PREF_GetPrefConfigObject(JSObject **js_object) if (!js_object) return PREF_ERROR; *js_object = NULL; - if (m_mochaPrefObject) - *js_object = m_mochaPrefObject; + if (gMochaPrefObject) + *js_object = gMochaPrefObject; return PREF_NOERROR; } /* Frees the callback list. */ -PR_IMPLEMENT(void) -PREF_Cleanup() +PR_IMPLEMENT(void) PREF_Cleanup() { - struct CallbackNode* node = m_Callbacks; + struct CallbackNode* node = gCallbacks; struct CallbackNode* next_node; - while (node) { + while (node) + { next_node = node->next; PR_Free(node->domain); PR_Free(node); node = next_node; } - if (m_mochaContext) JS_DestroyContext(m_mochaContext); - if (m_mochaTaskState) JS_Finish(m_mochaTaskState); - m_mochaContext = NULL; - m_mochaTaskState = NULL; + if (gMochaContext) + JS_DestroyContext(gMochaContext); + if (gMochaTaskState) + JS_Finish(gMochaTaskState); + gMochaContext = NULL; + gMochaTaskState = NULL; - if (m_HashTable) - PR_HashTableDestroy(m_HashTable); + if (gHashTable) + PR_HashTableDestroy(gHashTable); } PR_IMPLEMENT(PrefResult) @@ -525,7 +545,7 @@ PREF_ReadLockFile(const char *filename) void PREF_SetCallbacksStatus( PRBool status ) { - m_CallbacksEnabled = status; + gCallbacksEnabled = status; } /* This is more recent than the below 3 routines which should be obsoleted */ @@ -540,27 +560,30 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, JSErrorReporter errReporter; if (bGlobalContext) - scope = m_GlobalConfigObject; + scope = gGlobalConfigObject; else - scope = m_mochaPrefObject; + scope = gMochaPrefObject; - if (!m_mochaContext || !scope) + if (!gMochaContext || !scope) return JS_FALSE; - JS_BeginRequest(m_mochaContext); - errReporter = JS_SetErrorReporter(m_mochaContext, pref_ErrorReporter); - m_CallbacksEnabled = bCallbacks; + JS_BeginRequest(gMochaContext); + errReporter = JS_SetErrorReporter(gMochaContext, pref_ErrorReporter); + gCallbacksEnabled = bCallbacks; - if (skipFirstLine) { + if (skipFirstLine) + { /* In order to protect the privacy of the JavaScript preferences file * from loading by the browser, we make the first line unparseable * by JavaScript. We must skip that line here before executing * the JavaScript code. */ unsigned int i=0; - while (i < length) { + while (i < length) + { char c = js_buffer[i++]; - if (c == '\r') { + if (c == '\r') + { if (js_buffer[i] == '\n') i++; break; @@ -568,22 +591,22 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, if (c == '\n') break; } - m_SavedLine = malloc(i+1); - if (!m_SavedLine) + gSavedLine = malloc(i+1); + if (!gSavedLine) return JS_FALSE; - memcpy(m_SavedLine, js_buffer, i); - m_SavedLine[i] = '\0'; + memcpy(gSavedLine, js_buffer, i); + gSavedLine[i] = '\0'; length -= i; js_buffer += i; } - ok = JS_EvaluateScript(m_mochaContext, scope, + ok = JS_EvaluateScript(gMochaContext, scope, js_buffer, length, filename, 0, &result); - m_CallbacksEnabled = PR_TRUE; /* ?? want to enable after reading user/lock file */ - JS_SetErrorReporter(m_mochaContext, errReporter); + gCallbacksEnabled = PR_TRUE; /* ?? want to enable after reading user/lock file */ + JS_SetErrorReporter(gMochaContext, errReporter); - JS_EndRequest(m_mochaContext); + JS_EndRequest(gMochaContext); return ok; } @@ -604,14 +627,14 @@ PREF_QuietEvaluateJSBuffer(const char * js_buffer, size_t length) JSBool ok; jsval result; - if (!m_mochaContext || !m_mochaPrefObject) + if (!gMochaContext || !gMochaPrefObject) return PREF_NOT_INITIALIZED; - JS_BeginRequest(m_mochaContext); - ok = JS_EvaluateScript(m_mochaContext, m_mochaPrefObject, + JS_BeginRequest(gMochaContext); + ok = JS_EvaluateScript(gMochaContext, gMochaPrefObject, js_buffer, length, NULL, 0, &result); - JS_EndRequest(m_mochaContext); + JS_EndRequest(gMochaContext); /* Hey, this really returns a JSBool */ return ok; } @@ -622,13 +645,13 @@ PREF_QuietEvaluateJSBufferWithGlobalScope(const char * js_buffer, size_t length) JSBool ok; jsval result; - if (!m_mochaContext || !m_GlobalConfigObject) + if (!gMochaContext || !gGlobalConfigObject) return PREF_NOT_INITIALIZED; - JS_BeginRequest(m_mochaContext); - ok = JS_EvaluateScript(m_mochaContext, m_GlobalConfigObject, + JS_BeginRequest(gMochaContext); + ok = JS_EvaluateScript(gMochaContext, gGlobalConfigObject, js_buffer, length, NULL, 0, &result); - JS_EndRequest(m_mochaContext); + JS_EndRequest(gMochaContext); /* Hey, this really returns a JSBool */ return ok; @@ -817,8 +840,8 @@ PREF_SetDefaultRectPref(const char *pref_name, int16 left, int16 top, int16 righ /* LI_STUFF this does the same as savePref except it omits the lilocal prefs from the file. */ -PR_IMPLEMENT(int) -pref_saveLIPref(PRHashEntry *he, int i, void *arg) +PR_IMPLEMENT(PrefResult) +pref_saveLIPref(PLHashEntry *he, int i, void *arg) { char **prefArray = (char**) arg; PrefNode *pref = (PrefNode *) he->value; @@ -868,29 +891,31 @@ pref_saveLIPref(PRHashEntry *he, int i, void *arg) prefArray[i] = PL_strdup(buf); } - return 0; + return PREF_NOERROR; } -PR_IMPLEMENT(int) -pref_savePref(PRHashEntry *he, int i, void *arg) +PR_IMPLEMENT(PrefResult) +pref_savePref(PLHashEntry *he, int i, void *arg) { char **prefArray = (char**) arg; PrefNode *pref = (PrefNode *) he->value; PR_ASSERT(pref); if (!pref) - return 0; + return PREF_NOERROR; if (PREF_HAS_USER_VALUE(pref) && pref_ValueChanged(pref->defaultPref, pref->userPref, - (PrefType) PREF_TYPE(pref))) { + (PrefType) PREF_TYPE(pref))) + { char buf[2048]; if (pref->flags & PREF_STRING) { char *tmp_str = str_escape(pref->userPref.stringVal); - if (tmp_str) { + if (tmp_str) + { PR_snprintf(buf, 2048, "user_pref(\"%s\", \"%s\");" LINEBREAK, (char*) he->key, tmp_str); PR_Free(tmp_str); @@ -906,10 +931,13 @@ pref_savePref(PRHashEntry *he, int i, void *arg) } prefArray[i] = PL_strdup(buf); - } else if (pref && PREF_IS_LOCKED(pref)) { + } + else if (pref && PREF_IS_LOCKED(pref)) + { char buf[2048]; - if (pref->flags & PREF_STRING) { + if (pref->flags & PREF_STRING) + { char *tmp_str = str_escape(pref->defaultPref.stringVal); if (tmp_str) { PR_snprintf(buf, 2048, "user_pref(\"%s\", \"%s\");" LINEBREAK, @@ -917,25 +945,26 @@ pref_savePref(PRHashEntry *he, int i, void *arg) PR_Free(tmp_str); } } - else if (pref->flags & PREF_INT) { + else if (pref->flags & PREF_INT) + { PR_snprintf(buf, 2048, "user_pref(\"%s\", %ld);" LINEBREAK, (char*) he->key, (long) pref->defaultPref.intVal); } - else if (pref->flags & PREF_BOOL) { + else if (pref->flags & PREF_BOOL) + { PR_snprintf(buf, 2048, "user_pref(\"%s\", %s);" LINEBREAK, (char*) he->key, (pref->defaultPref.boolVal) ? "true" : "false"); } - prefArray[i] = PL_strdup(buf); } /* LI_STUFF?? may need to write out the lilocal stuff here if it applies - probably won't support in the prefs.js file. We won't need to worry about the user.js since it is read only. */ - return 0; + return PREF_NOERROR; } PR_IMPLEMENT(int) -pref_CompareStrings (const void *v1, const void *v2) +pref_CompareStrings(const void *v1, const void *v2) { char *s1 = *(char**) v1; char *s2 = *(char**) v2; @@ -981,28 +1010,30 @@ This is called by them and does the right thing. ?? make this private to this file. */ +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + #define PREF_FILE_BANNER "// Netscape User Preferences" LINEBREAK \ "// This is a generated file! Do not edit." LINEBREAK LINEBREAK PR_IMPLEMENT(PrefResult) -PREF_SavePrefFileWith(const char *filename, PRHashEnumerator heSaveProc) +PREF_SavePrefFileWith(const char *filename, PLHashEnumerator heSaveProc) { PrefResult success = PREF_ERROR; FILE * fp; char **valueArray = NULL; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; /* ?! Don't save (blank) user prefs if there was an error reading them */ #if defined(XP_PC) || defined(XP_OS2) if (!filename) #else - if (!filename || m_ErrorOpeningUserPrefs) + if (!filename || gErrorOpeningUserPrefs) #endif return PREF_NOERROR; - valueArray = (char**) PR_Calloc(sizeof(char*), m_HashTable->nentries); + valueArray = (char**) PR_Calloc(sizeof(char*), gHashTable->nentries); if (!valueArray) return PREF_OUT_OF_MEMORY; @@ -1013,11 +1044,11 @@ PREF_SavePrefFileWith(const char *filename, PRHashEnumerator heSaveProc) fwrite(PREF_FILE_BANNER, sizeof(char), PL_strlen(PREF_FILE_BANNER), fp); /* LI_STUFF here we pass in the heSaveProc proc used so that li can do its own thing */ - PR_HashTableEnumerateEntries(m_HashTable, heSaveProc, valueArray); + PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray); /* Sort the preferences to make a readable file on disk */ - XP_QSORT(valueArray, m_HashTable->nentries, sizeof(char*), pref_CompareStrings); - for (valueIdx = 0; valueIdx < m_HashTable->nentries; valueIdx++) + XP_QSORT(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings); + for (valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++) { if (valueArray[valueIdx]) { @@ -1038,19 +1069,21 @@ PREF_SavePrefFileWith(const char *filename, PRHashEnumerator heSaveProc) return success; } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -PR_IMPLEMENT(PrefResult) -PREF_SavePrefFile() +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_SavePrefFile() { #if 0 /* defined(XP_MAC) || defined(XP_PC) */ return (PrefResult)pref_SaveProfile(); #else - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - return (PREF_SavePrefFileWith(m_filename, pref_savePref)); + return (PrefResult)PREF_SavePrefFileWith(gFileName, (PLHashEnumerator)pref_savePref); #endif } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ /* * We need to flag a bunch of prefs as local that aren't initialized via all.js. @@ -1120,31 +1153,36 @@ PREF_SetSpecialPrefsLocal(void) PrefNode* pref; int i; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; for (i = 0; i < (sizeof(prefName)/sizeof(prefName[0])); i++) { - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, prefName[i]); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, prefName[i]); if (pref) pref->flags |= PREF_LILOCAL; } return PREF_OK; } -PR_IMPLEMENT(PrefResult) -PREF_SaveLIPrefFile(const char *filename) +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_SaveLIPrefFile(const char *filename) { - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; PREF_SetSpecialPrefsLocal(); - return (PREF_SavePrefFileWith(((filename) ? filename : m_lifilename), pref_saveLIPref)); + return (PrefResult)PREF_SavePrefFileWith( + (filename ? filename : gLIFileName), + (PLHashEnumerator)pref_saveLIPref); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS*/ -PR_IMPLEMENT(PrefResult) -PREF_SavePrefFileAs(const char *filename) { - return PREF_SavePrefFileWith(filename, pref_savePref); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_SavePrefFileAs(const char *filename) +{ + return (PrefResult)PREF_SavePrefFileWith(filename, (PLHashEnumerator)pref_savePref); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default) { @@ -1153,10 +1191,10 @@ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * l PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref) { @@ -1171,7 +1209,7 @@ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * l *length = strlen(stringVal) + 1; else { - PL_strncpy(return_buffer, stringVal, PR_MIN(*length - 1, strlen(stringVal) + 1)); + PL_strncpy(return_buffer, stringVal, PR_MIN(*length - 1, (int)strlen(stringVal) + 1)); return_buffer[*length - 1] = '\0'; } result = PREF_OK; @@ -1186,10 +1224,10 @@ PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBoo char* stringVal; PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && pref->flags & PREF_STRING) { if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)) @@ -1210,10 +1248,10 @@ PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool ge PrefResult result = PREF_ERROR; PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && pref->flags & PREF_INT) { if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)) *return_int = pref->defaultPref.intVal; @@ -1229,10 +1267,10 @@ PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool PrefResult result = PREF_ERROR; PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && pref->flags & PREF_BOOL) { if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)) *return_value = pref->defaultPref.boolVal; @@ -1328,7 +1366,7 @@ PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size) char* buf; PrefResult result; - if (!m_mochaPrefObject || !return_value) return PREF_ERROR; + if (!gMochaPrefObject || !return_value) return PREF_ERROR; result = PREF_CopyCharPref(pref_name, &buf); @@ -1353,7 +1391,7 @@ ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPre char* buf; PrefResult result; - if (!m_mochaPrefObject || !return_value) + if (!gMochaPrefObject || !return_value) return PREF_ERROR; *return_value = NULL; @@ -1486,7 +1524,7 @@ PREF_GetDefaultRectPref(const char *pref_name, int16 *left, int16 *top, int16 *r /* Delete a branch. Used for deleting mime types */ PR_IMPLEMENT(int) -pref_DeleteItem(PRHashEntry *he, int i, void *arg) +pref_DeleteItem(PLHashEntry *he, int i, void *arg) { const char *to_delete = (const char *) arg; int len = strlen(to_delete); @@ -1494,7 +1532,7 @@ pref_DeleteItem(PRHashEntry *he, int i, void *arg) /* note if we're deleting "ldap" then we want to delete "ldap.xxx" and "ldap" (if such a leaf node exists) but not "ldap_1.xxx" */ if (to_delete && (PL_strncmp(he->key, to_delete, len) == 0 || - (len-1 == strlen(he->key) && PL_strncmp(he->key, to_delete, len-1) == 0))) + (len-1 == (int)strlen(he->key) && PL_strncmp(he->key, to_delete, len-1) == 0))) return HT_ENUMERATE_REMOVE; else return HT_ENUMERATE_NEXT; @@ -1506,8 +1544,10 @@ PREF_DeleteBranch(const char *branch_name) char* branch_dot = PR_smprintf("%s.", branch_name); if (!branch_dot) return PREF_OUT_OF_MEMORY; + if (!gHashTable) + return PREF_NOT_INITIALIZED; - PR_HashTableEnumerateEntries(m_HashTable, pref_DeleteItem, (void*) branch_dot); + PR_HashTableEnumerateEntries(gHashTable, pref_DeleteItem, (void*) branch_dot); PR_Free(branch_dot); return PREF_NOERROR; @@ -1522,13 +1562,13 @@ PREF_ClearLIPref(const char *pref_name) PrefResult success = PREF_ERROR; PrefNode* pref; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && PREF_HAS_LI_VALUE(pref)) { pref->flags &= ~PREF_LILOCAL; - if (m_CallbacksEnabled) + if (gCallbacksEnabled) pref_DoCallback(pref_name); success = PREF_OK; } @@ -1543,13 +1583,13 @@ PREF_ClearUserPref(const char *pref_name) PrefResult success = PREF_ERROR; PrefNode* pref; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && PREF_HAS_USER_VALUE(pref)) { pref->flags &= ~PREF_USERSET; - if (m_CallbacksEnabled) + if (gCallbacksEnabled) pref_DoCallback(pref_name); success = PREF_OK; } @@ -1572,7 +1612,7 @@ PR_IMPLEMENT(PrefResult) PREF_CopyConfigString(const char *obj_name, char **return_buffer) { PrefResult success = PREF_ERROR; - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, obj_name); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, obj_name); if (pref && pref->flags & PREF_STRING) { if (return_buffer) @@ -1590,7 +1630,7 @@ PREF_CopyIndexConfigString(const char *obj_name, PrefNode* pref; char* setup_buf = PR_smprintf("%s_%d.%s", obj_name, index, field); - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, setup_buf); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, setup_buf); if (pref && pref->flags & PREF_STRING) { if (return_buffer) @@ -1606,7 +1646,7 @@ PREF_GetConfigInt(const char *obj_name, PRInt32 *return_int) { PrefResult success = PREF_ERROR; - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, obj_name); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, obj_name); if (pref && pref->flags & PREF_INT) { *return_int = pref->defaultPref.intVal; @@ -1621,7 +1661,7 @@ PREF_GetConfigBool(const char *obj_name, PRBool *return_bool) { PrefResult success = PREF_ERROR; - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, obj_name); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, obj_name); if (pref && pref->flags & PREF_BOOL) { *return_bool = pref->defaultPref.boolVal; @@ -1636,17 +1676,17 @@ PrefResult pref_UnlockPref(const char *key) PrefNode* pref; PrefResult result = PREF_OK; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (!pref) { return PREF_DOES_NOT_EXIST; } if (PREF_IS_LOCKED(pref)) { pref->flags &= ~PREF_LOCKED; - if (m_CallbacksEnabled) { + if (gCallbacksEnabled) { pref_DoCallback(key); } } @@ -1659,10 +1699,10 @@ PrefResult pref_LockPref(const char *key) PrefNode* pref; PrefResult result = PREF_OK; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (!pref) { return PREF_DOES_NOT_EXIST; } @@ -1713,10 +1753,10 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc PrefNode* pref; PrefResult result = PREF_OK; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (!pref) { pref = (PrefNode*) calloc(sizeof(PrefNode), 1); if (!pref) @@ -1728,7 +1768,7 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc this should really get fixed right by some out of band data */ if (pref->flags & PREF_INT) pref->defaultPref.intVal = (PRInt32) -5632; - PR_HashTableAdd(m_HashTable, PL_strdup(key), pref); + PR_HashTableAdd(gHashTable, PL_strdup(key), pref); } else if ((pref->flags & PREF_VALUETYPE_MASK) != (type & PREF_VALUETYPE_MASK)) { PR_ASSERT(0); /* this shouldn't happen */ @@ -1788,11 +1828,11 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc result = PREF_VALUECHANGED; } pref->flags |= PREF_LOCKED; - m_IsAnyPrefLocked = PR_TRUE; + gIsAnyPrefLocked = PR_TRUE; break; } - if (result == PREF_VALUECHANGED && m_CallbacksEnabled) { + if (result == PREF_VALUECHANGED && gCallbacksEnabled) { PrefResult result2 = pref_DoCallback(key); if (result2 < 0) result = result2; @@ -1803,14 +1843,18 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc PR_IMPLEMENT(PrefType) PREF_GetPrefType(const char *pref_name) { - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); - if (pref) { - if (pref->flags & PREF_STRING) - return PREF_STRING; - else if (pref->flags & PREF_INT) - return PREF_INT; - else if (pref->flags & PREF_BOOL) - return PREF_BOOL; + if (gHashTable) + { + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); + if (pref) + { + if (pref->flags & PREF_STRING) + return PREF_STRING; + else if (pref->flags & PREF_INT) + return PREF_INT; + else if (pref->flags & PREF_BOOL) + return PREF_BOOL; + } } return PREF_INVALID; } @@ -1827,11 +1871,11 @@ JSBool PR_CALLBACK pref_NativeLILocalPref { if (argc >= 1 && JSVAL_IS_STRING(argv[0])) { const char *key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (pref && !PREF_HAS_LI_VALUE(pref)) { pref->flags |= PREF_LILOCAL; - if (m_CallbacksEnabled) { + if (gCallbacksEnabled) { pref_DoCallback(key); } } @@ -1870,11 +1914,11 @@ JSBool PR_CALLBACK pref_NativeUnlockPref { if (argc >= 1 && JSVAL_IS_STRING(argv[0])) { const char *key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (pref && PREF_IS_LOCKED(pref)) { pref->flags &= ~PREF_LOCKED; - if (m_CallbacksEnabled) { + if (gCallbacksEnabled) { pref_DoCallback(key); } } @@ -1898,7 +1942,7 @@ JSBool PR_CALLBACK pref_NativeGetPref if (argc >= 1 && JSVAL_IS_STRING(argv[0])) { const char *key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (pref) { PRBool use_default = (PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)); @@ -1924,8 +1968,8 @@ PR_IMPLEMENT(PRBool) PREF_PrefIsLocked(const char *pref_name) { PRBool result = PR_FALSE; - if (m_IsAnyPrefLocked) { - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + if (gIsAnyPrefLocked) { + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && PREF_IS_LOCKED(pref)) result = PR_TRUE; } @@ -1949,24 +1993,24 @@ typedef struct "a.b.c" or "a.b" then add "a.b" to the list. */ PR_IMPLEMENT(int) -pref_addChild(PRHashEntry *he, int i, void *arg) +pref_addChild(PLHashEntry *he, int i, void *arg) { PrefChildIter* pcs = (PrefChildIter*) arg; if ( PL_strncmp(he->key, pcs->parent, strlen(pcs->parent)) == 0 ) { char buf[512]; char* nextdelim; - int parentlen = strlen(pcs->parent); + PRUint32 parentlen = strlen(pcs->parent); char* substring; PRBool substringBordersSeparator = PR_FALSE; strncpy(buf, he->key, PR_MIN(512, strlen(he->key) + 1)); nextdelim = buf + parentlen; - if (parentlen < PL_strlen(buf)) { + if (parentlen < PL_strlen(buf)) + { /* Find the next delimiter if any and truncate the string there */ nextdelim = strstr(nextdelim, "."); - if (nextdelim) { + if (nextdelim) *nextdelim = '\0'; - } } substring = strstr(pcs->childList, buf); @@ -2000,7 +2044,8 @@ PR_IMPLEMENT(PrefResult) PREF_CreateChildList(const char* parent_node, char **child_list) { PrefChildIter pcs; - + if (!gHashTable) + return PREF_NOT_INITIALIZED; #ifdef XP_WIN16 pcs.bufsize = 20480; #else @@ -2015,7 +2060,7 @@ PREF_CreateChildList(const char* parent_node, char **child_list) return PREF_OUT_OF_MEMORY; pcs.childList[0] = '\0'; - PR_HashTableEnumerateEntries(m_HashTable, pref_addChild, &pcs); + PR_HashTableEnumerateEntries(gHashTable, pref_addChild, &pcs); *child_list = pcs.childList; PR_Free(pcs.parent); @@ -2167,8 +2212,8 @@ PREF_RegisterCallback(const char *pref_node, node->domain = PL_strdup(pref_node); node->func = callback; node->data = instance_data; - node->next = m_Callbacks; - m_Callbacks = node; + node->next = gCallbacks; + gCallbacks = node; } return; } @@ -2180,7 +2225,7 @@ PREF_UnregisterCallback(const char *pref_node, void * instance_data) { PrefResult result = PREF_ERROR; - struct CallbackNode* node = m_Callbacks; + struct CallbackNode* node = gCallbacks; struct CallbackNode* prev_node = NULL; while (node != NULL) @@ -2193,7 +2238,7 @@ PREF_UnregisterCallback(const char *pref_node, if (prev_node) prev_node->next = next_node; else - m_Callbacks = next_node; + gCallbacks = next_node; PR_Free(node->domain); PR_Free(node); node = next_node; @@ -2211,7 +2256,7 @@ PrefResult pref_DoCallback(const char* changed_pref) { PrefResult result = PREF_OK; struct CallbackNode* node; - for (node = m_Callbacks; node != NULL; node = node->next) + for (node = gCallbacks; node != NULL; node = node->next) { if ( PL_strncmp(changed_pref, node->domain, strlen(node->domain)) == 0 ) { int result2 = (*node->func) (changed_pref, node->data); @@ -2240,14 +2285,14 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr #ifdef MOZ_ADMIN_LIB ldap_func get_ldap_attributes = NULL; #if (defined (XP_MAC) && defined(powerc)) || defined (XP_PC) || defined(XP_UNIX) - if (m_AutoAdminLib == NULL) { - m_AutoAdminLib = pref_LoadAutoAdminLib(); + if (gAutoAdminLib == NULL) { + gAutoAdminLib = pref_LoadAutoAdminLib(); } - if (m_AutoAdminLib) { + if (gAutoAdminLib) { get_ldap_attributes = (ldap_func) PR_FindSymbol( - m_AutoAdminLib, + gAutoAdminLib, #ifndef XP_WIN16 "pref_get_ldap_attributes" #else @@ -2255,7 +2300,8 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr #endif ); } - if (get_ldap_attributes == NULL) { + if (get_ldap_attributes == NULL) + { /* This indicates the AutoAdmin dll was not found. */ *rval = JSVAL_NULL; return JS_TRUE; @@ -2267,7 +2313,8 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr if (argc >= 4 && JSVAL_IS_STRING(argv[0]) && JSVAL_IS_STRING(argv[1]) && JSVAL_IS_STRING(argv[2]) - && JSVAL_IS_STRING(argv[3])) { + && JSVAL_IS_STRING(argv[3])) + { char *return_error = NULL; char *value = get_ldap_attributes( JS_GetStringBytes(JSVAL_TO_STRING(argv[0])), @@ -2276,17 +2323,18 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr JS_GetStringBytes(JSVAL_TO_STRING(argv[3])), &return_error ); - if (value) { + if (value) + { JSString* str = JS_NewStringCopyZ(cx, value); PR_Free(value); - if (str) { + if (str) + { *rval = STRING_TO_JSVAL(str); return JS_TRUE; } } - if (return_error) { + if (return_error) pref_Alert(return_error); - } } #endif @@ -2297,7 +2345,7 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr /* Dump debugging info in response to about:config. */ PR_IMPLEMENT(int) -pref_printDebugInfo(PRHashEntry *he, int i, void *arg) +pref_printDebugInfo(PLHashEntry *he, int i, void *arg) { char *buf1=NULL, *buf2=NULL; PrefValue val; @@ -2332,7 +2380,7 @@ pref_printDebugInfo(PRHashEntry *he, int i, void *arg) else if (pref->flags & PREF_BOOL) buf2 = PR_smprintf("%s %s
", buf1, val.boolVal ? "true" : "false"); - if ((PL_strlen(buf2) + PL_strlen(pcs->childList) + 1) > pcs->bufsize) + if ((PL_strlen(buf2) + PL_strlen(pcs->childList) + 1) > (PRUint32)pcs->bufsize) { pcs->bufsize *= 3; pcs->childList = (char*) realloc(pcs->childList, sizeof(char) * pcs->bufsize); @@ -2354,7 +2402,7 @@ PREF_AboutConfig() pcs.childList[0] = '\0'; PL_strcat(pcs.childList, ""); - PR_HashTableEnumerateEntries(m_HashTable, pref_printDebugInfo, &pcs); + PR_HashTableEnumerateEntries(gHashTable, pref_printDebugInfo, &pcs); return pcs.childList; } @@ -2382,7 +2430,7 @@ pref_BranchCallback(JSContext *cx, JSScript *script) if (decoder->window_context && ++decoder->branch_count == 1000000) { decoder->branch_count = 0; message = PR_smprintf("Lengthy %s still running. Continue?", - lm_language_name); + lglanguage_name); if (message) { ok = FE_Confirm(decoder->window_context, message); PR_Free(message); @@ -2622,7 +2670,7 @@ PREF_GetListPref(const char* pref, char*** list) { char* value; char** p; - int num_members; + int nugmembers; *list = NULL; @@ -2630,9 +2678,9 @@ PREF_GetListPref(const char* pref, char*** list) return PREF_ERROR; } - num_members = pref_CountListMembers(value); + nugmembers = pref_CountListMembers(value); - p = *list = (char**) PR_MALLOC((num_members+1) * sizeof(char**)); + p = *list = (char**) PR_MALLOC((nugmembers+1) * sizeof(char**)); if ( *list == NULL ) return PREF_ERROR; for ( *p = strtok(value, ","); diff --git a/mozilla/modules/libpref/src/prefapi.cpp b/mozilla/modules/libpref/src/prefapi.cpp index d30032c6ca1..b7bc1464977 100644 --- a/mozilla/modules/libpref/src/prefapi.cpp +++ b/mozilla/modules/libpref/src/prefapi.cpp @@ -29,21 +29,25 @@ **/ +#include "prefapi.h" + #include "jsapi.h" -#if defined(XP_MAC) -#include -#else -#include -#endif -#include -#ifdef _WIN32 -#include "windows.h" -#endif +#define PREF_SUPPORT_OLD_PATH_STRINGS 1 +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + #if defined(XP_MAC) + #include + #else + #include + #endif + #include + #ifdef _WIN32 + #include "windows.h" + #endif /* _WIN32 */ +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ #ifdef MOZ_ADMIN_LIB #include "prefldap.h" #endif -#include "prefapi.h" #if defined(XP_MAC) || defined(XP_UNIX) #include "fe_proto.h" @@ -63,7 +67,6 @@ #include "xpassert.h" #include "xp_str.h" -/* WHS TEMPORARY */ #define XP_QSORT qsort #if defined(XP_MAC) && defined (__MWERKS__) @@ -71,26 +74,6 @@ #pragma require_prototypes off #endif -JSTaskState * m_mochaTaskState = NULL; -JSContext * m_mochaContext = NULL; -JSObject * m_mochaPrefObject = NULL; -JSObject * m_GlobalConfigObject = NULL; - -static char * m_filename = NULL; -static char * m_lifilename = NULL; -static struct CallbackNode* m_Callbacks = NULL; -static PRBool m_ErrorOpeningUserPrefs = PR_FALSE; -static PRBool m_CallbacksEnabled = PR_FALSE; -static PRBool m_IsAnyPrefLocked = PR_FALSE; -static PRHashTable* m_HashTable = NULL; -static char * m_SavedLine = NULL; - -#define PREF_IS_LOCKED(pref) ((pref)->flags & PREF_LOCKED) -#define PREF_IS_CONFIG(pref) ((pref)->flags & PREF_CONFIG) -#define PREF_HAS_USER_VALUE(pref) ((pref)->flags & PREF_USERSET) -#define PREF_HAS_LI_VALUE(pref) ((pref)->flags & PREF_LILOCAL) /* LI_STUFF */ -#define PREF_TYPE(pref) (PrefType)((pref)->flags & PREF_VALUETYPE_MASK) - typedef union { char* stringVal; @@ -105,30 +88,26 @@ typedef struct uint8 flags; } PrefNode; -static JSBool pref_HashJSPref(unsigned int argc, jsval *argv, PrefAction action); -static PRBool pref_ValueChanged(PrefValue oldValue, PrefValue newValue, PrefType type); +/*----------------------- +** Hash table allocation +**----------------------*/ -/* Hash table allocation */ -PR_IMPLEMENT(void *) -pref_AllocTable(void *pool, size_t size) +PR_IMPLEMENT(void *) pref_AllocTable(void *pool, size_t size) { return malloc(size); } -PR_IMPLEMENT(void) -pref_FreeTable(void *pool, void *item) +PR_IMPLEMENT(void) pref_FreeTable(void *pool, void *item) { free(item); /* free items? */ } -PR_IMPLEMENT(PRHashEntry *) -pref_AllocEntry(void *pool, const void *key) +PR_IMPLEMENT(PLHashEntry *) pref_AllocEntry(void *pool, const void *key) { - return malloc(sizeof(PRHashEntry)); + return malloc(sizeof(PLHashEntry)); } -PR_IMPLEMENT(void) -pref_FreeEntry(void *pool, PRHashEntry *he, uint flag) +PR_IMPLEMENT(void) pref_FreeEntry(void *pool, PLHashEntry *he, uint flag) { PrefNode *pref = (PrefNode *) he->value; if (pref) { @@ -145,54 +124,6 @@ pref_FreeEntry(void *pool, PRHashEntry *he, uint flag) } } -static PRHashAllocOps pref_HashAllocOps = { - pref_AllocTable, pref_FreeTable, - pref_AllocEntry, pref_FreeEntry -}; - -#include "prlink.h" -extern PRLibrary *pref_LoadAutoAdminLib(void); -PRLibrary *m_AutoAdminLib = NULL; - -/* -- Privates */ -struct CallbackNode { - char* domain; - PrefChangedFunc func; - void* data; - struct CallbackNode* next; -}; - -/* -- Prototypes */ -PrefResult pref_DoCallback(const char* changed_pref); -PrefResult pref_OpenFile( - const char* filename, - PRBool is_error_fatal, - PRBool verifyHash, - PRBool bGlobalContext, - PRBool skipFirstLine); -PRBool pref_VerifyLockFile(char* buf, long buflen); - -PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default); -PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default); -PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default); -PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default); - -JSBool PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script); -void pref_ErrorReporter(JSContext *cx, const char *message,JSErrorReport *report); -void pref_Alert(char* msg); -PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAction action); - -/* -- Platform specific function extern */ -#if !defined(XP_WIN) && !defined(XP_OS2) -extern JSBool pref_InitInitialObjects(void); -#endif - -static JSClass global_class = { - "global", 0, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub -}; - JSBool PR_CALLBACK pref_NativeDefaultPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK pref_NativeUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK pref_NativeLockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); @@ -206,33 +137,105 @@ JSBool PR_CALLBACK pref_NativeLILocalPref(JSContext *cx, JSObject *obj, unsigned JSBool PR_CALLBACK pref_NativeLIUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool PR_CALLBACK pref_NativeLIDefPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); +/*----------------------------------------------------------------------------------------*/ +#include "prefapi_private_data.h" -/* LI_STUFF added localPref pref_NativeLILocalPref, 1 */ -static JSFunctionSpec autoconf_methods[] = { - { "pref", pref_NativeDefaultPref, 2 }, - { "defaultPref", pref_NativeDefaultPref, 2 }, - { "user_pref", pref_NativeUserPref, 2 }, - { "lockPref", pref_NativeLockPref, 2 }, - { "unlockPref", pref_NativeUnlockPref, 1 }, - { "config", pref_NativeSetConfig, 2 }, - { "getPref", pref_NativeGetPref, 1 }, - { "getLDAPAttributes", pref_NativeGetLDAPAttr, 4 }, - { "localPref", pref_NativeLILocalPref, 1 }, - { "localUserPref", pref_NativeLIUserPref, 2 }, - { "localDefPref", pref_NativeLIDefPref, 2 }, - { NULL, NULL, 0 } +JSTaskState * gMochaTaskState = NULL; +JSContext * gMochaContext = NULL; +JSObject * gMochaPrefObject = NULL; +JSObject * gGlobalConfigObject = NULL; +JSClass global_class = { + "global", 0, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub + }; +JSClass autoconf_class = { + "PrefConfig", 0, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub + }; +JSPropertySpec autoconf_props[] = { + {0} + }; +JSFunctionSpec autoconf_methods[] = { + { "pref", pref_NativeDefaultPref, 2 }, + { "defaultPref", pref_NativeDefaultPref, 2 }, + { "user_pref", pref_NativeUserPref, 2 }, + { "lockPref", pref_NativeLockPref, 2 }, + { "unlockPref", pref_NativeUnlockPref, 1 }, + { "config", pref_NativeSetConfig, 2 }, + { "getPref", pref_NativeGetPref, 1 }, + { "getLDAPAttributes", pref_NativeGetLDAPAttr, 4 }, + { "localPref", pref_NativeLILocalPref, 1 }, + { "localUserPref", pref_NativeLIUserPref, 2 }, + { "localDefPref", pref_NativeLIDefPref, 2 }, + { NULL, NULL, 0 } + }; + +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +char * gFileName = NULL; +char * gLIFileName = NULL; +#endif /*PREF_SUPPORT_OLD_PATH_STRINGS*/ + +struct CallbackNode* gCallbacks = NULL; +PRBool gErrorOpeningUserPrefs = PR_FALSE; +PRBool gCallbacksEnabled = PR_FALSE; +PRBool gIsAnyPrefLocked = PR_FALSE; +PLHashTable* gHashTable = NULL; +char * gSavedLine = NULL; +PLHashAllocOps pref_HashAllocOps = { + pref_AllocTable, pref_FreeTable, + pref_AllocEntry, pref_FreeEntry + }; + +/*----------------------------------------------------------------------------------------*/ + +#define PREF_IS_LOCKED(pref) ((pref)->flags & PREF_LOCKED) +#define PREF_IS_CONFIG(pref) ((pref)->flags & PREF_CONFIG) +#define PREF_HAS_USER_VALUE(pref) ((pref)->flags & PREF_USERSET) +#define PREF_HAS_LI_VALUE(pref) ((pref)->flags & PREF_LILOCAL) /* LI_STUFF */ +#define PREF_TYPE(pref) (PrefType)((pref)->flags & PREF_VALUETYPE_MASK) + +static JSBool pref_HashJSPref(unsigned int argc, jsval *argv, PrefAction action); +static PRBool pref_ValueChanged(PrefValue oldValue, PrefValue newValue, PrefType type); + +#include "prlink.h" +extern PRLibrary *pref_LoadAutoAdminLib(void); +PRLibrary *gAutoAdminLib = NULL; + +/* -- Privates */ +struct CallbackNode { + char* domain; + PrefChangedFunc func; + void* data; + struct CallbackNode* next; }; -static JSPropertySpec autoconf_props[] = { - {0} -}; +/* -- Prototypes */ +PrefResult pref_DoCallback(const char* changed_pref); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PrefResult pref_OpenFile( + const char* filename, + PRBool is_error_fatal, + PRBool verifyHash, + PRBool bGlobalContext, + PRBool skipFirstLine); +PR_EXTERN(PrefResult) PREF_SavePrefFileWith(const char *filename, PLHashEnumerator heSaveProc); +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -static JSClass autoconf_class = { - "PrefConfig", 0, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub -}; +PRBool pref_VerifyLockFile(char* buf, long buflen); +PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default); +PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default); +PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default); +PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default); + +JSBool PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script); +void pref_ErrorReporter(JSContext *cx, const char *message,JSErrorReport *report); +void pref_Alert(char* msg); +PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAction action); + +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS PrefResult pref_OpenFile( const char* filename, PRBool is_error_fatal, @@ -254,17 +257,19 @@ PrefResult pref_OpenFile( return PREF_ERROR; fp = fopen(filename, "r"); - if (fp) { + if (fp) + { char* readBuf = (char *) malloc(fileLength * sizeof(char)); - if (readBuf) { + if (readBuf) + { fileLength = fread(readBuf, sizeof(char), fileLength, fp); - if ( verifyHash && pref_VerifyLockFile(readBuf, fileLength) == PR_FALSE ) + if ( verifyHash && !pref_VerifyLockFile(readBuf, fileLength)) { ok = PREF_BAD_LOCKFILE; } - else if ( PREF_EvaluateConfigScript(readBuf, fileLength, - filename, bGlobalContext, PR_FALSE, skipFirstLine ) == JS_TRUE ) + else if (PREF_EvaluateConfigScript(readBuf, fileLength, + filename, bGlobalContext, PR_FALSE, skipFirstLine )) { ok = PREF_NOERROR; } @@ -275,15 +280,16 @@ PrefResult pref_OpenFile( /* If the user prefs file exists but generates an error, don't clobber the file when we try to save it. */ if ((!readBuf || ok != PREF_NOERROR) && is_error_fatal) - m_ErrorOpeningUserPrefs = PR_TRUE; + gErrorOpeningUserPrefs = PR_TRUE; #ifdef XP_PC - if (m_ErrorOpeningUserPrefs && is_error_fatal) + if (gErrorOpeningUserPrefs && is_error_fatal) MessageBox(NULL,"Error in preference file (prefs.js). Default preferences will be used.","Netscape - Warning", MB_OK); #endif } - JS_GC(m_mochaContext); + JS_GC(gMochaContext); return (ok); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ /* Computes the MD5 hash of the given buffer (not including the first line) and verifies the first line of the buffer expresses the correct hash in the form: @@ -339,115 +345,127 @@ PRBool pref_VerifyLockFile(char* buf, long buflen) #endif } -PR_IMPLEMENT(PrefResult) -PREF_ReadLIJSFile(const char *filename) +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_ReadLIJSFile(const char *filename) { PrefResult ok; - if (filename) m_lifilename = strdup(filename); + if (filename) + { + free(gLIFileName); + gLIFileName = strdup(filename); + } ok = pref_OpenFile(filename, PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE); return ok; } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -PR_IMPLEMENT(PrefResult) -PREF_ReadUserJSFile(const char *filename) +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_ReadUserJSFile(const char *filename) { PrefResult ok = pref_OpenFile(filename, PR_FALSE, PR_FALSE, PR_TRUE, PR_FALSE); return ok; } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -PR_IMPLEMENT(PRBool) -PREF_Init(const char *filename) +PR_IMPLEMENT(PRBool) PREF_Init(const char *filename) { PRBool ok = PR_TRUE; /* --ML hash test */ - if (!m_HashTable) - m_HashTable = PR_NewHashTable(2048, PR_HashString, PR_CompareStrings, + if (!gHashTable) + gHashTable = PR_NewHashTable(2048, PR_HashString, PR_CompareStrings, PR_CompareValues, &pref_HashAllocOps, NULL); - if (!m_HashTable) + if (!gHashTable) return PR_FALSE; - if (filename) { - if (m_filename) /* happens if PREF_Init is called twice (it is) */ - free(m_filename); - m_filename = strdup(filename); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + if (filename) + { + if (gFileName) /* happens if PREF_Init is called twice (it is) */ + PL_strfree(gFileName); + gFileName = PL_strdup(filename); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ - if (!m_mochaTaskState) - m_mochaTaskState = JS_Init((PRUint32) 0xffffffffL); + if (!gMochaTaskState) + gMochaTaskState = JS_Init((PRUint32) 0xffffffffL); - if (!m_mochaContext) { - m_mochaContext = JS_NewContext(m_mochaTaskState, 8192); /* ???? What size? */ - if (!m_mochaContext) { + if (!gMochaContext) + { + gMochaContext = JS_NewContext(gMochaTaskState, 8192); /* ???? What size? */ + if (!gMochaContext) return PR_FALSE; - } - JS_BeginRequest(m_mochaContext); + JS_BeginRequest(gMochaContext); - m_GlobalConfigObject = JS_NewObject(m_mochaContext, &global_class, NULL, NULL); - if (!m_GlobalConfigObject) { - JS_EndRequest(m_mochaContext); + gGlobalConfigObject = JS_NewObject(gMochaContext, &global_class, NULL, NULL); + if (!gGlobalConfigObject) + { + JS_EndRequest(gMochaContext); return PR_FALSE; - } + } - /* MLM - need a global object for set version call now. */ - JS_SetGlobalObject(m_mochaContext, m_GlobalConfigObject); + /* MLM - need a global object for set version call now. */ + JS_SetGlobalObject(gMochaContext, gGlobalConfigObject); - JS_SetVersion(m_mochaContext, JSVERSION_1_2); + JS_SetVersion(gMochaContext, JSVERSION_1_2); - if (!JS_InitStandardClasses(m_mochaContext, - m_GlobalConfigObject)) { - JS_EndRequest(m_mochaContext); + if (!JS_InitStandardClasses(gMochaContext, + gGlobalConfigObject)) + { + JS_EndRequest(gMochaContext); return PR_FALSE; } - JS_SetBranchCallback(m_mochaContext, pref_BranchCallback); - JS_SetErrorReporter(m_mochaContext, NULL); + JS_SetBranchCallback(gMochaContext, pref_BranchCallback); + JS_SetErrorReporter(gMochaContext, NULL); - m_mochaPrefObject = JS_DefineObject(m_mochaContext, - m_GlobalConfigObject, + gMochaPrefObject = JS_DefineObject(gMochaContext, + gGlobalConfigObject, "PrefConfig", &autoconf_class, NULL, JSPROP_ENUMERATE|JSPROP_READONLY); - if (m_mochaPrefObject) { - if (!JS_DefineProperties(m_mochaContext, - m_mochaPrefObject, - autoconf_props)) { - JS_EndRequest(m_mochaContext); - return PR_FALSE; + if (gMochaPrefObject) + { + if (!JS_DefineProperties(gMochaContext, + gMochaPrefObject, + autoconf_props)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; } - - if (!JS_DefineFunctions(m_mochaContext, - m_mochaPrefObject, - autoconf_methods)) { - JS_EndRequest(m_mochaContext); - return PR_FALSE; + if (!JS_DefineFunctions(gMochaContext, + gMochaPrefObject, + autoconf_methods)) + { + JS_EndRequest(gMochaContext); + return PR_FALSE; } - } #if !defined(XP_PC) && !defined(XP_OS2) && !defined(XP_MAC) ok = pref_InitInitialObjects(); #endif - } else { - JS_BeginRequest(m_mochaContext); } + else + JS_BeginRequest(gMochaContext); - if (ok && filename) { - ok = (JSBool) (pref_OpenFile(filename, PR_TRUE, PR_FALSE, PR_FALSE, PR_TRUE) == PREF_NOERROR); - } - else if (!ok) { - m_ErrorOpeningUserPrefs = PR_TRUE; - } - JS_EndRequest(m_mochaContext); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + if (ok && gFileName) + ok = (PRBool)(pref_OpenFile(gFileName, PR_TRUE, PR_FALSE, PR_FALSE, PR_TRUE) == PREF_NOERROR); + else +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ + if (!ok) + gErrorOpeningUserPrefs = PR_TRUE; + JS_EndRequest(gMochaContext); return ok; -} +} /*PREF_Init*/ PR_IMPLEMENT(PrefResult) PREF_GetConfigContext(JSContext **js_context) @@ -455,9 +473,9 @@ PREF_GetConfigContext(JSContext **js_context) if (!js_context) return PREF_ERROR; *js_context = NULL; - if (m_mochaContext) { - *js_context = m_mochaContext; - JS_SetContextThread(m_mochaContext); + if (gMochaContext) { + *js_context = gMochaContext; + JS_SetContextThread(gMochaContext); } return PREF_NOERROR; @@ -469,8 +487,8 @@ PREF_GetGlobalConfigObject(JSObject **js_object) if (!js_object) return PREF_ERROR; *js_object = NULL; - if (m_GlobalConfigObject) - *js_object = m_GlobalConfigObject; + if (gGlobalConfigObject) + *js_object = gGlobalConfigObject; return PREF_NOERROR; } @@ -481,32 +499,34 @@ PREF_GetPrefConfigObject(JSObject **js_object) if (!js_object) return PREF_ERROR; *js_object = NULL; - if (m_mochaPrefObject) - *js_object = m_mochaPrefObject; + if (gMochaPrefObject) + *js_object = gMochaPrefObject; return PREF_NOERROR; } /* Frees the callback list. */ -PR_IMPLEMENT(void) -PREF_Cleanup() +PR_IMPLEMENT(void) PREF_Cleanup() { - struct CallbackNode* node = m_Callbacks; + struct CallbackNode* node = gCallbacks; struct CallbackNode* next_node; - while (node) { + while (node) + { next_node = node->next; PR_Free(node->domain); PR_Free(node); node = next_node; } - if (m_mochaContext) JS_DestroyContext(m_mochaContext); - if (m_mochaTaskState) JS_Finish(m_mochaTaskState); - m_mochaContext = NULL; - m_mochaTaskState = NULL; + if (gMochaContext) + JS_DestroyContext(gMochaContext); + if (gMochaTaskState) + JS_Finish(gMochaTaskState); + gMochaContext = NULL; + gMochaTaskState = NULL; - if (m_HashTable) - PR_HashTableDestroy(m_HashTable); + if (gHashTable) + PR_HashTableDestroy(gHashTable); } PR_IMPLEMENT(PrefResult) @@ -525,7 +545,7 @@ PREF_ReadLockFile(const char *filename) void PREF_SetCallbacksStatus( PRBool status ) { - m_CallbacksEnabled = status; + gCallbacksEnabled = status; } /* This is more recent than the below 3 routines which should be obsoleted */ @@ -540,27 +560,30 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, JSErrorReporter errReporter; if (bGlobalContext) - scope = m_GlobalConfigObject; + scope = gGlobalConfigObject; else - scope = m_mochaPrefObject; + scope = gMochaPrefObject; - if (!m_mochaContext || !scope) + if (!gMochaContext || !scope) return JS_FALSE; - JS_BeginRequest(m_mochaContext); - errReporter = JS_SetErrorReporter(m_mochaContext, pref_ErrorReporter); - m_CallbacksEnabled = bCallbacks; + JS_BeginRequest(gMochaContext); + errReporter = JS_SetErrorReporter(gMochaContext, pref_ErrorReporter); + gCallbacksEnabled = bCallbacks; - if (skipFirstLine) { + if (skipFirstLine) + { /* In order to protect the privacy of the JavaScript preferences file * from loading by the browser, we make the first line unparseable * by JavaScript. We must skip that line here before executing * the JavaScript code. */ unsigned int i=0; - while (i < length) { + while (i < length) + { char c = js_buffer[i++]; - if (c == '\r') { + if (c == '\r') + { if (js_buffer[i] == '\n') i++; break; @@ -568,22 +591,22 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, if (c == '\n') break; } - m_SavedLine = malloc(i+1); - if (!m_SavedLine) + gSavedLine = malloc(i+1); + if (!gSavedLine) return JS_FALSE; - memcpy(m_SavedLine, js_buffer, i); - m_SavedLine[i] = '\0'; + memcpy(gSavedLine, js_buffer, i); + gSavedLine[i] = '\0'; length -= i; js_buffer += i; } - ok = JS_EvaluateScript(m_mochaContext, scope, + ok = JS_EvaluateScript(gMochaContext, scope, js_buffer, length, filename, 0, &result); - m_CallbacksEnabled = PR_TRUE; /* ?? want to enable after reading user/lock file */ - JS_SetErrorReporter(m_mochaContext, errReporter); + gCallbacksEnabled = PR_TRUE; /* ?? want to enable after reading user/lock file */ + JS_SetErrorReporter(gMochaContext, errReporter); - JS_EndRequest(m_mochaContext); + JS_EndRequest(gMochaContext); return ok; } @@ -604,14 +627,14 @@ PREF_QuietEvaluateJSBuffer(const char * js_buffer, size_t length) JSBool ok; jsval result; - if (!m_mochaContext || !m_mochaPrefObject) + if (!gMochaContext || !gMochaPrefObject) return PREF_NOT_INITIALIZED; - JS_BeginRequest(m_mochaContext); - ok = JS_EvaluateScript(m_mochaContext, m_mochaPrefObject, + JS_BeginRequest(gMochaContext); + ok = JS_EvaluateScript(gMochaContext, gMochaPrefObject, js_buffer, length, NULL, 0, &result); - JS_EndRequest(m_mochaContext); + JS_EndRequest(gMochaContext); /* Hey, this really returns a JSBool */ return ok; } @@ -622,13 +645,13 @@ PREF_QuietEvaluateJSBufferWithGlobalScope(const char * js_buffer, size_t length) JSBool ok; jsval result; - if (!m_mochaContext || !m_GlobalConfigObject) + if (!gMochaContext || !gGlobalConfigObject) return PREF_NOT_INITIALIZED; - JS_BeginRequest(m_mochaContext); - ok = JS_EvaluateScript(m_mochaContext, m_GlobalConfigObject, + JS_BeginRequest(gMochaContext); + ok = JS_EvaluateScript(gMochaContext, gGlobalConfigObject, js_buffer, length, NULL, 0, &result); - JS_EndRequest(m_mochaContext); + JS_EndRequest(gMochaContext); /* Hey, this really returns a JSBool */ return ok; @@ -817,8 +840,8 @@ PREF_SetDefaultRectPref(const char *pref_name, int16 left, int16 top, int16 righ /* LI_STUFF this does the same as savePref except it omits the lilocal prefs from the file. */ -PR_IMPLEMENT(int) -pref_saveLIPref(PRHashEntry *he, int i, void *arg) +PR_IMPLEMENT(PrefResult) +pref_saveLIPref(PLHashEntry *he, int i, void *arg) { char **prefArray = (char**) arg; PrefNode *pref = (PrefNode *) he->value; @@ -868,29 +891,31 @@ pref_saveLIPref(PRHashEntry *he, int i, void *arg) prefArray[i] = PL_strdup(buf); } - return 0; + return PREF_NOERROR; } -PR_IMPLEMENT(int) -pref_savePref(PRHashEntry *he, int i, void *arg) +PR_IMPLEMENT(PrefResult) +pref_savePref(PLHashEntry *he, int i, void *arg) { char **prefArray = (char**) arg; PrefNode *pref = (PrefNode *) he->value; PR_ASSERT(pref); if (!pref) - return 0; + return PREF_NOERROR; if (PREF_HAS_USER_VALUE(pref) && pref_ValueChanged(pref->defaultPref, pref->userPref, - (PrefType) PREF_TYPE(pref))) { + (PrefType) PREF_TYPE(pref))) + { char buf[2048]; if (pref->flags & PREF_STRING) { char *tmp_str = str_escape(pref->userPref.stringVal); - if (tmp_str) { + if (tmp_str) + { PR_snprintf(buf, 2048, "user_pref(\"%s\", \"%s\");" LINEBREAK, (char*) he->key, tmp_str); PR_Free(tmp_str); @@ -906,10 +931,13 @@ pref_savePref(PRHashEntry *he, int i, void *arg) } prefArray[i] = PL_strdup(buf); - } else if (pref && PREF_IS_LOCKED(pref)) { + } + else if (pref && PREF_IS_LOCKED(pref)) + { char buf[2048]; - if (pref->flags & PREF_STRING) { + if (pref->flags & PREF_STRING) + { char *tmp_str = str_escape(pref->defaultPref.stringVal); if (tmp_str) { PR_snprintf(buf, 2048, "user_pref(\"%s\", \"%s\");" LINEBREAK, @@ -917,25 +945,26 @@ pref_savePref(PRHashEntry *he, int i, void *arg) PR_Free(tmp_str); } } - else if (pref->flags & PREF_INT) { + else if (pref->flags & PREF_INT) + { PR_snprintf(buf, 2048, "user_pref(\"%s\", %ld);" LINEBREAK, (char*) he->key, (long) pref->defaultPref.intVal); } - else if (pref->flags & PREF_BOOL) { + else if (pref->flags & PREF_BOOL) + { PR_snprintf(buf, 2048, "user_pref(\"%s\", %s);" LINEBREAK, (char*) he->key, (pref->defaultPref.boolVal) ? "true" : "false"); } - prefArray[i] = PL_strdup(buf); } /* LI_STUFF?? may need to write out the lilocal stuff here if it applies - probably won't support in the prefs.js file. We won't need to worry about the user.js since it is read only. */ - return 0; + return PREF_NOERROR; } PR_IMPLEMENT(int) -pref_CompareStrings (const void *v1, const void *v2) +pref_CompareStrings(const void *v1, const void *v2) { char *s1 = *(char**) v1; char *s2 = *(char**) v2; @@ -981,28 +1010,30 @@ This is called by them and does the right thing. ?? make this private to this file. */ +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS + #define PREF_FILE_BANNER "// Netscape User Preferences" LINEBREAK \ "// This is a generated file! Do not edit." LINEBREAK LINEBREAK PR_IMPLEMENT(PrefResult) -PREF_SavePrefFileWith(const char *filename, PRHashEnumerator heSaveProc) +PREF_SavePrefFileWith(const char *filename, PLHashEnumerator heSaveProc) { PrefResult success = PREF_ERROR; FILE * fp; char **valueArray = NULL; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; /* ?! Don't save (blank) user prefs if there was an error reading them */ #if defined(XP_PC) || defined(XP_OS2) if (!filename) #else - if (!filename || m_ErrorOpeningUserPrefs) + if (!filename || gErrorOpeningUserPrefs) #endif return PREF_NOERROR; - valueArray = (char**) PR_Calloc(sizeof(char*), m_HashTable->nentries); + valueArray = (char**) PR_Calloc(sizeof(char*), gHashTable->nentries); if (!valueArray) return PREF_OUT_OF_MEMORY; @@ -1013,11 +1044,11 @@ PREF_SavePrefFileWith(const char *filename, PRHashEnumerator heSaveProc) fwrite(PREF_FILE_BANNER, sizeof(char), PL_strlen(PREF_FILE_BANNER), fp); /* LI_STUFF here we pass in the heSaveProc proc used so that li can do its own thing */ - PR_HashTableEnumerateEntries(m_HashTable, heSaveProc, valueArray); + PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray); /* Sort the preferences to make a readable file on disk */ - XP_QSORT(valueArray, m_HashTable->nentries, sizeof(char*), pref_CompareStrings); - for (valueIdx = 0; valueIdx < m_HashTable->nentries; valueIdx++) + XP_QSORT(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings); + for (valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++) { if (valueArray[valueIdx]) { @@ -1038,19 +1069,21 @@ PREF_SavePrefFileWith(const char *filename, PRHashEnumerator heSaveProc) return success; } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ -PR_IMPLEMENT(PrefResult) -PREF_SavePrefFile() +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_SavePrefFile() { #if 0 /* defined(XP_MAC) || defined(XP_PC) */ return (PrefResult)pref_SaveProfile(); #else - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - return (PREF_SavePrefFileWith(m_filename, pref_savePref)); + return (PrefResult)PREF_SavePrefFileWith(gFileName, (PLHashEnumerator)pref_savePref); #endif } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ /* * We need to flag a bunch of prefs as local that aren't initialized via all.js. @@ -1120,31 +1153,36 @@ PREF_SetSpecialPrefsLocal(void) PrefNode* pref; int i; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; for (i = 0; i < (sizeof(prefName)/sizeof(prefName[0])); i++) { - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, prefName[i]); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, prefName[i]); if (pref) pref->flags |= PREF_LILOCAL; } return PREF_OK; } -PR_IMPLEMENT(PrefResult) -PREF_SaveLIPrefFile(const char *filename) +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_SaveLIPrefFile(const char *filename) { - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; PREF_SetSpecialPrefsLocal(); - return (PREF_SavePrefFileWith(((filename) ? filename : m_lifilename), pref_saveLIPref)); + return (PrefResult)PREF_SavePrefFileWith( + (filename ? filename : gLIFileName), + (PLHashEnumerator)pref_saveLIPref); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS*/ -PR_IMPLEMENT(PrefResult) -PREF_SavePrefFileAs(const char *filename) { - return PREF_SavePrefFileWith(filename, pref_savePref); +#ifdef PREF_SUPPORT_OLD_PATH_STRINGS +PR_IMPLEMENT(PrefResult) PREF_SavePrefFileAs(const char *filename) +{ + return (PrefResult)PREF_SavePrefFileWith(filename, (PLHashEnumerator)pref_savePref); } +#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default) { @@ -1153,10 +1191,10 @@ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * l PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref) { @@ -1171,7 +1209,7 @@ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * l *length = strlen(stringVal) + 1; else { - PL_strncpy(return_buffer, stringVal, PR_MIN(*length - 1, strlen(stringVal) + 1)); + PL_strncpy(return_buffer, stringVal, PR_MIN(*length - 1, (int)strlen(stringVal) + 1)); return_buffer[*length - 1] = '\0'; } result = PREF_OK; @@ -1186,10 +1224,10 @@ PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBoo char* stringVal; PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && pref->flags & PREF_STRING) { if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)) @@ -1210,10 +1248,10 @@ PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool ge PrefResult result = PREF_ERROR; PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && pref->flags & PREF_INT) { if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)) *return_int = pref->defaultPref.intVal; @@ -1229,10 +1267,10 @@ PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool PrefResult result = PREF_ERROR; PrefNode* pref; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && pref->flags & PREF_BOOL) { if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)) *return_value = pref->defaultPref.boolVal; @@ -1328,7 +1366,7 @@ PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size) char* buf; PrefResult result; - if (!m_mochaPrefObject || !return_value) return PREF_ERROR; + if (!gMochaPrefObject || !return_value) return PREF_ERROR; result = PREF_CopyCharPref(pref_name, &buf); @@ -1353,7 +1391,7 @@ ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPre char* buf; PrefResult result; - if (!m_mochaPrefObject || !return_value) + if (!gMochaPrefObject || !return_value) return PREF_ERROR; *return_value = NULL; @@ -1486,7 +1524,7 @@ PREF_GetDefaultRectPref(const char *pref_name, int16 *left, int16 *top, int16 *r /* Delete a branch. Used for deleting mime types */ PR_IMPLEMENT(int) -pref_DeleteItem(PRHashEntry *he, int i, void *arg) +pref_DeleteItem(PLHashEntry *he, int i, void *arg) { const char *to_delete = (const char *) arg; int len = strlen(to_delete); @@ -1494,7 +1532,7 @@ pref_DeleteItem(PRHashEntry *he, int i, void *arg) /* note if we're deleting "ldap" then we want to delete "ldap.xxx" and "ldap" (if such a leaf node exists) but not "ldap_1.xxx" */ if (to_delete && (PL_strncmp(he->key, to_delete, len) == 0 || - (len-1 == strlen(he->key) && PL_strncmp(he->key, to_delete, len-1) == 0))) + (len-1 == (int)strlen(he->key) && PL_strncmp(he->key, to_delete, len-1) == 0))) return HT_ENUMERATE_REMOVE; else return HT_ENUMERATE_NEXT; @@ -1506,8 +1544,10 @@ PREF_DeleteBranch(const char *branch_name) char* branch_dot = PR_smprintf("%s.", branch_name); if (!branch_dot) return PREF_OUT_OF_MEMORY; + if (!gHashTable) + return PREF_NOT_INITIALIZED; - PR_HashTableEnumerateEntries(m_HashTable, pref_DeleteItem, (void*) branch_dot); + PR_HashTableEnumerateEntries(gHashTable, pref_DeleteItem, (void*) branch_dot); PR_Free(branch_dot); return PREF_NOERROR; @@ -1522,13 +1562,13 @@ PREF_ClearLIPref(const char *pref_name) PrefResult success = PREF_ERROR; PrefNode* pref; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && PREF_HAS_LI_VALUE(pref)) { pref->flags &= ~PREF_LILOCAL; - if (m_CallbacksEnabled) + if (gCallbacksEnabled) pref_DoCallback(pref_name); success = PREF_OK; } @@ -1543,13 +1583,13 @@ PREF_ClearUserPref(const char *pref_name) PrefResult success = PREF_ERROR; PrefNode* pref; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && PREF_HAS_USER_VALUE(pref)) { pref->flags &= ~PREF_USERSET; - if (m_CallbacksEnabled) + if (gCallbacksEnabled) pref_DoCallback(pref_name); success = PREF_OK; } @@ -1572,7 +1612,7 @@ PR_IMPLEMENT(PrefResult) PREF_CopyConfigString(const char *obj_name, char **return_buffer) { PrefResult success = PREF_ERROR; - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, obj_name); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, obj_name); if (pref && pref->flags & PREF_STRING) { if (return_buffer) @@ -1590,7 +1630,7 @@ PREF_CopyIndexConfigString(const char *obj_name, PrefNode* pref; char* setup_buf = PR_smprintf("%s_%d.%s", obj_name, index, field); - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, setup_buf); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, setup_buf); if (pref && pref->flags & PREF_STRING) { if (return_buffer) @@ -1606,7 +1646,7 @@ PREF_GetConfigInt(const char *obj_name, PRInt32 *return_int) { PrefResult success = PREF_ERROR; - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, obj_name); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, obj_name); if (pref && pref->flags & PREF_INT) { *return_int = pref->defaultPref.intVal; @@ -1621,7 +1661,7 @@ PREF_GetConfigBool(const char *obj_name, PRBool *return_bool) { PrefResult success = PREF_ERROR; - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, obj_name); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, obj_name); if (pref && pref->flags & PREF_BOOL) { *return_bool = pref->defaultPref.boolVal; @@ -1636,17 +1676,17 @@ PrefResult pref_UnlockPref(const char *key) PrefNode* pref; PrefResult result = PREF_OK; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (!pref) { return PREF_DOES_NOT_EXIST; } if (PREF_IS_LOCKED(pref)) { pref->flags &= ~PREF_LOCKED; - if (m_CallbacksEnabled) { + if (gCallbacksEnabled) { pref_DoCallback(key); } } @@ -1659,10 +1699,10 @@ PrefResult pref_LockPref(const char *key) PrefNode* pref; PrefResult result = PREF_OK; - if (!m_HashTable) + if (!gHashTable) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (!pref) { return PREF_DOES_NOT_EXIST; } @@ -1713,10 +1753,10 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc PrefNode* pref; PrefResult result = PREF_OK; - if (!m_HashTable && !pref_useDefaultPrefFile()) + if (!gHashTable && !pref_useDefaultPrefFile()) return PREF_NOT_INITIALIZED; - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (!pref) { pref = (PrefNode*) calloc(sizeof(PrefNode), 1); if (!pref) @@ -1728,7 +1768,7 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc this should really get fixed right by some out of band data */ if (pref->flags & PREF_INT) pref->defaultPref.intVal = (PRInt32) -5632; - PR_HashTableAdd(m_HashTable, PL_strdup(key), pref); + PR_HashTableAdd(gHashTable, PL_strdup(key), pref); } else if ((pref->flags & PREF_VALUETYPE_MASK) != (type & PREF_VALUETYPE_MASK)) { PR_ASSERT(0); /* this shouldn't happen */ @@ -1788,11 +1828,11 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc result = PREF_VALUECHANGED; } pref->flags |= PREF_LOCKED; - m_IsAnyPrefLocked = PR_TRUE; + gIsAnyPrefLocked = PR_TRUE; break; } - if (result == PREF_VALUECHANGED && m_CallbacksEnabled) { + if (result == PREF_VALUECHANGED && gCallbacksEnabled) { PrefResult result2 = pref_DoCallback(key); if (result2 < 0) result = result2; @@ -1803,14 +1843,18 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc PR_IMPLEMENT(PrefType) PREF_GetPrefType(const char *pref_name) { - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); - if (pref) { - if (pref->flags & PREF_STRING) - return PREF_STRING; - else if (pref->flags & PREF_INT) - return PREF_INT; - else if (pref->flags & PREF_BOOL) - return PREF_BOOL; + if (gHashTable) + { + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); + if (pref) + { + if (pref->flags & PREF_STRING) + return PREF_STRING; + else if (pref->flags & PREF_INT) + return PREF_INT; + else if (pref->flags & PREF_BOOL) + return PREF_BOOL; + } } return PREF_INVALID; } @@ -1827,11 +1871,11 @@ JSBool PR_CALLBACK pref_NativeLILocalPref { if (argc >= 1 && JSVAL_IS_STRING(argv[0])) { const char *key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (pref && !PREF_HAS_LI_VALUE(pref)) { pref->flags |= PREF_LILOCAL; - if (m_CallbacksEnabled) { + if (gCallbacksEnabled) { pref_DoCallback(key); } } @@ -1870,11 +1914,11 @@ JSBool PR_CALLBACK pref_NativeUnlockPref { if (argc >= 1 && JSVAL_IS_STRING(argv[0])) { const char *key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (pref && PREF_IS_LOCKED(pref)) { pref->flags &= ~PREF_LOCKED; - if (m_CallbacksEnabled) { + if (gCallbacksEnabled) { pref_DoCallback(key); } } @@ -1898,7 +1942,7 @@ JSBool PR_CALLBACK pref_NativeGetPref if (argc >= 1 && JSVAL_IS_STRING(argv[0])) { const char *key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); - pref = (PrefNode*) PR_HashTableLookup(m_HashTable, key); + pref = (PrefNode*) PR_HashTableLookup(gHashTable, key); if (pref) { PRBool use_default = (PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref)); @@ -1924,8 +1968,8 @@ PR_IMPLEMENT(PRBool) PREF_PrefIsLocked(const char *pref_name) { PRBool result = PR_FALSE; - if (m_IsAnyPrefLocked) { - PrefNode* pref = (PrefNode*) PR_HashTableLookup(m_HashTable, pref_name); + if (gIsAnyPrefLocked) { + PrefNode* pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name); if (pref && PREF_IS_LOCKED(pref)) result = PR_TRUE; } @@ -1949,24 +1993,24 @@ typedef struct "a.b.c" or "a.b" then add "a.b" to the list. */ PR_IMPLEMENT(int) -pref_addChild(PRHashEntry *he, int i, void *arg) +pref_addChild(PLHashEntry *he, int i, void *arg) { PrefChildIter* pcs = (PrefChildIter*) arg; if ( PL_strncmp(he->key, pcs->parent, strlen(pcs->parent)) == 0 ) { char buf[512]; char* nextdelim; - int parentlen = strlen(pcs->parent); + PRUint32 parentlen = strlen(pcs->parent); char* substring; PRBool substringBordersSeparator = PR_FALSE; strncpy(buf, he->key, PR_MIN(512, strlen(he->key) + 1)); nextdelim = buf + parentlen; - if (parentlen < PL_strlen(buf)) { + if (parentlen < PL_strlen(buf)) + { /* Find the next delimiter if any and truncate the string there */ nextdelim = strstr(nextdelim, "."); - if (nextdelim) { + if (nextdelim) *nextdelim = '\0'; - } } substring = strstr(pcs->childList, buf); @@ -2000,7 +2044,8 @@ PR_IMPLEMENT(PrefResult) PREF_CreateChildList(const char* parent_node, char **child_list) { PrefChildIter pcs; - + if (!gHashTable) + return PREF_NOT_INITIALIZED; #ifdef XP_WIN16 pcs.bufsize = 20480; #else @@ -2015,7 +2060,7 @@ PREF_CreateChildList(const char* parent_node, char **child_list) return PREF_OUT_OF_MEMORY; pcs.childList[0] = '\0'; - PR_HashTableEnumerateEntries(m_HashTable, pref_addChild, &pcs); + PR_HashTableEnumerateEntries(gHashTable, pref_addChild, &pcs); *child_list = pcs.childList; PR_Free(pcs.parent); @@ -2167,8 +2212,8 @@ PREF_RegisterCallback(const char *pref_node, node->domain = PL_strdup(pref_node); node->func = callback; node->data = instance_data; - node->next = m_Callbacks; - m_Callbacks = node; + node->next = gCallbacks; + gCallbacks = node; } return; } @@ -2180,7 +2225,7 @@ PREF_UnregisterCallback(const char *pref_node, void * instance_data) { PrefResult result = PREF_ERROR; - struct CallbackNode* node = m_Callbacks; + struct CallbackNode* node = gCallbacks; struct CallbackNode* prev_node = NULL; while (node != NULL) @@ -2193,7 +2238,7 @@ PREF_UnregisterCallback(const char *pref_node, if (prev_node) prev_node->next = next_node; else - m_Callbacks = next_node; + gCallbacks = next_node; PR_Free(node->domain); PR_Free(node); node = next_node; @@ -2211,7 +2256,7 @@ PrefResult pref_DoCallback(const char* changed_pref) { PrefResult result = PREF_OK; struct CallbackNode* node; - for (node = m_Callbacks; node != NULL; node = node->next) + for (node = gCallbacks; node != NULL; node = node->next) { if ( PL_strncmp(changed_pref, node->domain, strlen(node->domain)) == 0 ) { int result2 = (*node->func) (changed_pref, node->data); @@ -2240,14 +2285,14 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr #ifdef MOZ_ADMIN_LIB ldap_func get_ldap_attributes = NULL; #if (defined (XP_MAC) && defined(powerc)) || defined (XP_PC) || defined(XP_UNIX) - if (m_AutoAdminLib == NULL) { - m_AutoAdminLib = pref_LoadAutoAdminLib(); + if (gAutoAdminLib == NULL) { + gAutoAdminLib = pref_LoadAutoAdminLib(); } - if (m_AutoAdminLib) { + if (gAutoAdminLib) { get_ldap_attributes = (ldap_func) PR_FindSymbol( - m_AutoAdminLib, + gAutoAdminLib, #ifndef XP_WIN16 "pref_get_ldap_attributes" #else @@ -2255,7 +2300,8 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr #endif ); } - if (get_ldap_attributes == NULL) { + if (get_ldap_attributes == NULL) + { /* This indicates the AutoAdmin dll was not found. */ *rval = JSVAL_NULL; return JS_TRUE; @@ -2267,7 +2313,8 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr if (argc >= 4 && JSVAL_IS_STRING(argv[0]) && JSVAL_IS_STRING(argv[1]) && JSVAL_IS_STRING(argv[2]) - && JSVAL_IS_STRING(argv[3])) { + && JSVAL_IS_STRING(argv[3])) + { char *return_error = NULL; char *value = get_ldap_attributes( JS_GetStringBytes(JSVAL_TO_STRING(argv[0])), @@ -2276,17 +2323,18 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr JS_GetStringBytes(JSVAL_TO_STRING(argv[3])), &return_error ); - if (value) { + if (value) + { JSString* str = JS_NewStringCopyZ(cx, value); PR_Free(value); - if (str) { + if (str) + { *rval = STRING_TO_JSVAL(str); return JS_TRUE; } } - if (return_error) { + if (return_error) pref_Alert(return_error); - } } #endif @@ -2297,7 +2345,7 @@ JSBool PR_CALLBACK pref_NativeGetLDAPAttr /* Dump debugging info in response to about:config. */ PR_IMPLEMENT(int) -pref_printDebugInfo(PRHashEntry *he, int i, void *arg) +pref_printDebugInfo(PLHashEntry *he, int i, void *arg) { char *buf1=NULL, *buf2=NULL; PrefValue val; @@ -2332,7 +2380,7 @@ pref_printDebugInfo(PRHashEntry *he, int i, void *arg) else if (pref->flags & PREF_BOOL) buf2 = PR_smprintf("%s %s
", buf1, val.boolVal ? "true" : "false"); - if ((PL_strlen(buf2) + PL_strlen(pcs->childList) + 1) > pcs->bufsize) + if ((PL_strlen(buf2) + PL_strlen(pcs->childList) + 1) > (PRUint32)pcs->bufsize) { pcs->bufsize *= 3; pcs->childList = (char*) realloc(pcs->childList, sizeof(char) * pcs->bufsize); @@ -2354,7 +2402,7 @@ PREF_AboutConfig() pcs.childList[0] = '\0'; PL_strcat(pcs.childList, ""); - PR_HashTableEnumerateEntries(m_HashTable, pref_printDebugInfo, &pcs); + PR_HashTableEnumerateEntries(gHashTable, pref_printDebugInfo, &pcs); return pcs.childList; } @@ -2382,7 +2430,7 @@ pref_BranchCallback(JSContext *cx, JSScript *script) if (decoder->window_context && ++decoder->branch_count == 1000000) { decoder->branch_count = 0; message = PR_smprintf("Lengthy %s still running. Continue?", - lm_language_name); + lglanguage_name); if (message) { ok = FE_Confirm(decoder->window_context, message); PR_Free(message); @@ -2622,7 +2670,7 @@ PREF_GetListPref(const char* pref, char*** list) { char* value; char** p; - int num_members; + int nugmembers; *list = NULL; @@ -2630,9 +2678,9 @@ PREF_GetListPref(const char* pref, char*** list) return PREF_ERROR; } - num_members = pref_CountListMembers(value); + nugmembers = pref_CountListMembers(value); - p = *list = (char**) PR_MALLOC((num_members+1) * sizeof(char**)); + p = *list = (char**) PR_MALLOC((nugmembers+1) * sizeof(char**)); if ( *list == NULL ) return PREF_ERROR; for ( *p = strtok(value, ","); diff --git a/mozilla/modules/libpref/src/prefapi_private_data.h b/mozilla/modules/libpref/src/prefapi_private_data.h index de23ed5d9f7..f242075d743 100644 --- a/mozilla/modules/libpref/src/prefapi_private_data.h +++ b/mozilla/modules/libpref/src/prefapi_private_data.h @@ -18,6 +18,7 @@ /* Data shared between prefapi.c and nsPref.cpp */ +NSPR_BEGIN_EXTERN_C extern JSTaskState * gMochaTaskState; extern JSContext * gMochaContext; extern JSObject * gMochaPrefObject; @@ -40,13 +41,16 @@ extern PLHashTable* gHashTable; extern char * gSavedLine; extern PLHashAllocOps pref_HashAllocOps; -NSPR_BEGIN_EXTERN_C PR_EXTERN(JSBool) PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script); PR_EXTERN(PrefResult) pref_savePref(PLHashEntry *he, int i, void *arg); PR_EXTERN(PrefResult) pref_saveLIPref(PLHashEntry *he, int i, void *arg); PR_EXTERN(PRBool) pref_VerifyLockFile(char* buf, long buflen); PR_EXTERN(PrefResult) PREF_SetSpecialPrefsLocal(void); PR_EXTERN(int) pref_CompareStrings(const void *v1, const void *v2); +/* -- Platform specific function extern */ +#if !defined(XP_WIN) && !defined(XP_OS2) +extern JSBool pref_InitInitialObjects(void); +#endif NSPR_END_EXTERN_C /* Possibly exportable */ diff --git a/mozilla/webshell/tests/viewer/nsViewerApp.cpp b/mozilla/webshell/tests/viewer/nsViewerApp.cpp index bcfbb3a29bd..e2e7ca13179 100644 --- a/mozilla/webshell/tests/viewer/nsViewerApp.cpp +++ b/mozilla/webshell/tests/viewer/nsViewerApp.cpp @@ -127,7 +127,7 @@ nsViewerApp::~nsViewerApp() { Destroy(); if (nsnull != mPrefs) { - mPrefs->Shutdown(); + mPrefs->ShutDown(); NS_RELEASE(mPrefs); } } @@ -234,7 +234,7 @@ nsViewerApp::Initialize(int argc, char** argv) if (NS_OK != rv) { return rv; } - mPrefs->Startup(nsnull); + mPrefs->StartUp(); // Load Fullcircle Talkback crash-reporting mechanism. diff --git a/mozilla/xpfe/AppCores/src/nsPrefsCore.cpp b/mozilla/xpfe/AppCores/src/nsPrefsCore.cpp index 6e207c9037b..a452b582d3d 100644 --- a/mozilla/xpfe/AppCores/src/nsPrefsCore.cpp +++ b/mozilla/xpfe/AppCores/src/nsPrefsCore.cpp @@ -140,6 +140,7 @@ nsresult nsPrefsCore::InitializePrefsManager() if (!prefs) return NS_ERROR_FAILURE; +#if 0 nsIFileLocator* locator; rv = nsServiceManager::GetService(kFileLocatorCID, kIFileLocatorIID, (nsISupports**)&locator); if (NS_FAILED(rv)) @@ -150,6 +151,7 @@ nsresult nsPrefsCore::InitializePrefsManager() nsFileSpec newPrefs; rv = locator->GetFileLocation(nsSpecialFileSpec::App_PreferencesFile50, &newPrefs); #if 0 + // Migration? if (NS_FAILED(rv) || !newPrefs.Exists()) { nsFileSpec oldPrefs; @@ -196,7 +198,7 @@ nsresult nsPrefsCore::InitializePrefsManager() if (NS_FAILED(rv)) return rv; - +#endif // 0 mPrefs = prefs; return NS_OK; } // nsPrefsCore::InitializePrefsManager @@ -366,19 +368,18 @@ nsresult nsPrefsCore::InitializeOneWidget( // Check the subtree first, then the real tree. // If the preference value is not set at all, let the HTML // determine the setting. - char* charVal; - if (NS_SUCCEEDED(mPrefs->CopyPathPref(tempPrefName, &charVal)) - || NS_SUCCEEDED(mPrefs->CopyPathPref(inPrefName, &charVal))) + nsFileSpec specVal; + if (NS_SUCCEEDED(mPrefs->GetFilePref(tempPrefName, &specVal)) + || NS_SUCCEEDED(mPrefs->GetFilePref(inPrefName, &specVal))) { - nsString newValue = charVal; - PR_Free(charVal); + nsString newValue = specVal.GetCString(); inElement->SetValue(newValue); } break; } } return NS_OK; -} +} // nsPrefsCore::InitializeOneWidget //---------------------------------------------------------------------------------------- nsresult nsPrefsCore::InitializeWidgetsRecursive(nsIDOMNode* inParentNode) @@ -520,10 +521,8 @@ nsresult nsPrefsCore::FinalizeOneWidget( nsresult rv = inElement->GetValue(fieldValue); if (NS_FAILED(rv)) return rv; - char* s = fieldValue.ToNewCString(); - mPrefs->SetPathPref(tempPrefName, s, PR_TRUE); - delete [] s; - break; + nsFileSpec specValue(fieldValue); + mPrefs->SetFilePref(tempPrefName, &specValue, PR_TRUE); break; } } @@ -532,7 +531,7 @@ nsresult nsPrefsCore::FinalizeOneWidget( // inElement->SetAttribute(attributeToSet, newValue); // } return NS_OK; -} +} // nsPrefsCore::FinalizeOneWidget //---------------------------------------------------------------------------------------- nsresult nsPrefsCore::FinalizeWidgetsRecursive(nsIDOMNode* inParentNode) diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index bd47676f94f..97d67132216 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -148,7 +148,6 @@ int main(int argc, char* argv[]) // XXX: This call will be replaced by a registry initialization... NS_SetupRegistry_1(); - //Is there a call to get current working directory ? nsIFileLocator* locator = nsnull; rv = nsServiceManager::GetService(kFileLocatorCID, kIFileLocatorIID, (nsISupports**)&locator); if (NS_FAILED(rv)) @@ -312,7 +311,7 @@ int main(int argc, char* argv[]) } /* - * Load preferences + * Load preferences, causing them to be initialized, and hold a reference to them. */ rv = nsServiceManager::GetService(kPrefCID, nsIPref::GetIID(), @@ -320,29 +319,6 @@ int main(int argc, char* argv[]) if (NS_FAILED(rv)) goto done; - { // <-Scoping for nsFileSpec - nsFileSpec newPrefs; - rv = locator->GetFileLocation(nsSpecialFileSpec::App_PreferencesFile50, &newPrefs); - if (NS_SUCCEEDED(rv)) - { - if (!newPrefs.Exists()) - { - nsOutputFileStream stream(newPrefs); - if (stream.is_open()) - { - stream << "// This is an empty prefs file" << nsEndl; - } - } - if (newPrefs.Exists()) - rv = prefs->Startup(newPrefs.GetCString()); - else - { - rv = NS_ERROR_FAILURE; - goto done; - } - } - } // <- end of scoping for nsFileSpec - /* * Create the Application Shell instance... */ @@ -488,7 +464,7 @@ done: /* Release the global preferences... */ if (prefs) { - prefs->Shutdown(); + prefs->ShutDown(); nsServiceManager::ReleaseService(kPrefCID, prefs); }