Fix for Bug 87661 - moving AutoConfig creation after reading of netscape.cfg

r=bnesse, sr=shaver and a=asa
This commit is contained in:
mitesh%netscape.com 2001-08-24 19:44:45 +00:00
parent df1c31d081
commit f384d9fc0e
5 changed files with 104 additions and 114 deletions

View File

@ -43,5 +43,5 @@
[uuid (80DB54AE-13F2-11d5-BE44-00108335A220)]
interface nsIAutoConfig : nsISupports {
void downloadAutoCfg();
attribute string configURL;
};

View File

@ -37,17 +37,7 @@
// nsISupports Implementation
NS_IMPL_THREADSAFE_ADDREF(nsAutoConfig)
NS_IMPL_THREADSAFE_RELEASE(nsAutoConfig)
NS_INTERFACE_MAP_BEGIN(nsAutoConfig)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAutoConfig)
NS_INTERFACE_MAP_ENTRY(nsIAutoConfig)
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_END
NS_IMPL_THREADSAFE_ISUPPORTS5(nsAutoConfig, nsIAutoConfig, nsITimerCallback, nsIStreamListener, nsIObserver, nsIRequestObserver)
nsAutoConfig::nsAutoConfig()
{
@ -84,6 +74,30 @@ nsAutoConfig::~nsAutoConfig()
{
}
// attribute string configURL
NS_IMETHODIMP nsAutoConfig::GetConfigURL(char * *aConfigURL)
{
if (!aConfigURL)
return NS_ERROR_NULL_POINTER;
if (mConfigURL.IsEmpty()) {
*aConfigURL = nsnull;
return NS_OK;
}
*aConfigURL = mConfigURL.ToNewCString();
if (!*aConfigURL)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP nsAutoConfig::SetConfigURL(const char * aConfigURL)
{
if (!aConfigURL)
return NS_ERROR_NULL_POINTER;
mConfigURL.Assign(aConfigURL);
return NS_OK;
}
NS_IMETHODIMP
nsAutoConfig::OnStartRequest(nsIRequest* request, nsISupports* context)
{
@ -167,12 +181,12 @@ nsAutoConfig::OnStopRequest(nsIRequest* request, nsISupports* context,
// Notify method as a TimerCallBack function
NS_IMETHODIMP_(void) nsAutoConfig::Notify(nsITimer *timer)
{
DownloadAutoCfg();
downloadAutoConfig();
}
/* Observe() is called twice: once at the instantiation time and other
after the profile is set. It doesn't do anything but return NS_OK during the
creation time. Second time it calls DownloadAutoCfg().
creation time. Second time it calls downloadAutoConfig().
*/
NS_IMETHODIMP nsAutoConfig::Observe(nsISupports *aSubject,
@ -198,11 +212,11 @@ NS_IMETHODIMP nsAutoConfig::Observe(nsISupports *aSubject,
}
}
// We will be calling DownloadAutoCfg even if there is no profile
// We will be calling downloadAutoConfig even if there is no profile
// name. Nothing will be passed as a parameter to the URL and the
// default case will be picked up by the script.
rv = DownloadAutoCfg();
rv = downloadAutoConfig();
// We are done with AutoConfig, removing it from the observer list
@ -219,7 +233,7 @@ NS_IMETHODIMP nsAutoConfig::Observe(nsISupports *aSubject,
return rv;
}
NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
nsresult nsAutoConfig::downloadAutoConfig()
{
nsresult rv;
nsCAutoString emailAddr;
@ -227,13 +241,11 @@ NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
PRBool appendMail=PR_FALSE, offline=PR_FALSE;
static PRBool firstTime = PR_TRUE;
if (mConfigURL.IsEmpty()) {
NS_WARNING("AutoConfig called without global_config_url");
return NS_OK;
}
// get the value of the autoconfig url
rv = mPrefBranch->GetCharPref("autoadmin.global_config_url",
getter_Copies(urlName));
if (NS_FAILED(rv) || (nsCRT::strlen(urlName) == 0))
return NS_OK; // Return ok if there is no config url set.
// Check to see if the network is online/offline
nsCOMPtr<nsIIOService> ios = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv))
@ -257,8 +269,6 @@ NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
nsCAutoString cfgUrl(urlName);
/* Append user's identity at the end of the URL if the pref says so.
First we are checking for the user's email address but if it is not
available in the case where the client is used without messenger, user's
@ -275,8 +285,8 @@ NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
In this case the autoconfig URL is a script and
emailAddr as passed as an argument
*/
cfgUrl.Append("?");
cfgUrl.Append(emailAddr);
mConfigURL.Append("?");
mConfigURL.Append(emailAddr);
}
}
@ -300,7 +310,7 @@ NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
nsCOMPtr<nsIURI> url;
nsCOMPtr<nsIChannel> channel;
rv = NS_NewURI(getter_AddRefs(url), cfgUrl, nsnull, nsnull);
rv = NS_NewURI(getter_AddRefs(url), mConfigURL, nsnull, nsnull);
if (NS_FAILED(rv))
return rv;
@ -346,11 +356,11 @@ NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
PLEvent *event;
while (!mLoaded) {
rv = currentThreadQ->WaitForEvent(&event);
NS_ASSERTION(NS_SUCCEEDED(rv),"-->nsAutoConfig::DownloadAutoCfg: currentThreadQ->WaitForEvent failed...");
NS_ASSERTION(NS_SUCCEEDED(rv),"-->nsAutoConfig::downloadAutoConfig: currentThreadQ->WaitForEvent failed...");
if (NS_FAILED(rv))
return rv;
rv = currentThreadQ->HandleEvent(event);
NS_ASSERTION(NS_SUCCEEDED(rv), "-->nsAutoConfig::DownloadAutoCfg: currentThreadQ->HandleEvent failed...");
NS_ASSERTION(NS_SUCCEEDED(rv), "-->nsAutoConfig::downloadAutoConfig: currentThreadQ->HandleEvent failed...");
if (NS_FAILED(rv))
return rv;
}
@ -359,7 +369,7 @@ NS_IMETHODIMP nsAutoConfig::DownloadAutoCfg()
return NS_OK;
} // nsPref::DownloadAutoCfg()
} // nsPref::downloadAutoConfig()

View File

@ -52,6 +52,7 @@ class nsAutoConfig : public nsIAutoConfig,
protected:
nsresult downloadAutoConfig();
nsresult readOfflineFile();
nsresult evaluateLocalFile(nsIFile * file);
nsresult writeFailoverFile();
@ -60,4 +61,5 @@ class nsAutoConfig : public nsIAutoConfig,
nsCOMPtr<nsIPrefBranch> mPrefBranch;
PRBool mLoaded;
nsCOMPtr<nsITimer> mTimer;
nsCString mConfigURL;
};

View File

@ -27,6 +27,7 @@
#include "nsISignatureVerifier.h"
#include "nsPrefBranch.h"
#include "nsXPIDLString.h"
#include "nsIAutoConfig.h"
#include "nsQuickSort.h"
#include "prefapi.h"
@ -158,55 +159,76 @@ NS_IMETHODIMP nsPrefService::ReadConfigFile()
nsXPIDLCString lockFileName;
nsXPIDLCString lockVendor;
PRUint32 fileNameLen = 0;
PRUint32 vendorLen = 0;
// This preference is set in the all.js or all-ns.js (depending whether running mozilla or netscp6)
// default - preference is commented out, so it doesn't exist
rv = mRootBranch->GetCharPref("general.config.filename", getter_Copies(lockFileName));
if(NS_FAILED(rv))
// This preference is set in the all.js or all-ns.js (depending whether
// running mozilla or netscp6) default - preference is commented out, so
// it doesn't exist
rv = mRootBranch->GetCharPref("general.config.filename",
getter_Copies(lockFileName));
if (NS_FAILED(rv))
return NS_OK;
// If the lockFileName is NULL return ok, because no lockFile will be used
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(lockPrefFile));
if (NS_SUCCEEDED(rv))
{
// If the lockFileName is NULL return ok, because no lockFile will be used
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
getter_AddRefs(lockPrefFile));
if (NS_SUCCEEDED(rv)) {
#ifdef XP_MAC
lockPrefFile->Append("Essential Files");
#endif
if (NS_SUCCEEDED(lockPrefFile->Append(lockFileName)))
{
if (NS_FAILED(openPrefFile(lockPrefFile, PR_FALSE, PR_TRUE, PR_FALSE, PR_TRUE)))
if (NS_SUCCEEDED(lockPrefFile->Append(lockFileName))) {
if (NS_FAILED(openPrefFile(lockPrefFile, PR_FALSE, PR_TRUE,
PR_FALSE, PR_TRUE)))
return NS_ERROR_FAILURE;
// failure here means problem within the config file script
}
}
// Once the config file is read, we should check that the vendor name is consistent
// By checking for the vendor name after reading the config file we allow for the
// preference to be set (and locked) by the creator of the cfg file meaning the
// file can not be renamed (successfully).
rv = mRootBranch->GetCharPref("general.config.filename", getter_Copies(lockFileName));
if(NS_FAILED(rv))
// Once the config file is read, we should check that the vendor name
// is consistent By checking for the vendor name after reading the config
// file we allow for the preference to be set (and locked) by the creator
// of the cfg file meaning the file can not be renamed (successfully).
rv = mRootBranch->GetCharPref("general.config.filename",
getter_Copies(lockFileName));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
// There is NO REASON we should ever get here. This is POST reading of the config file.
// There is NO REASON we should ever get here. This is POST reading
// of the config file.
rv = mRootBranch->GetCharPref("general.config.vendor",
getter_Copies(lockVendor));
// If vendor is not NULL, do this check
if (NS_SUCCEEDED(rv)) {
rv = mRootBranch->GetCharPref("general.config.vendor", getter_Copies(lockVendor));
if(NS_FAILED(rv))
return NS_OK;
// if the vendor is null (default) ignore this check
fileNameLen = PL_strlen(lockFileName);
vendorLen = PL_strlen(lockVendor);
// lockVendor and lockFileName should be the same with the addtion of .cfg to the filename
// by checking this post reading of the cfg file this value can be set within the cfg file
// adding a level of security.
if (PL_strncmp(lockFileName, lockVendor, fileNameLen -4) != 0)
return NS_ERROR_FAILURE;
return rv;
fileNameLen = PL_strlen(lockFileName);
// lockVendor and lockFileName should be the same with the addtion of
// .cfg to the filename by checking this post reading of the cfg file
// this value can be set within the cfg file adding a level of security.
if (PL_strncmp(lockFileName, lockVendor, fileNameLen -4) != 0)
return NS_ERROR_FAILURE;
}
// get the value of the autoconfig url
nsXPIDLCString urlName;
rv = mRootBranch->GetCharPref("autoadmin.global_config_url",
getter_Copies(urlName));
if (NS_SUCCEEDED(rv) && *urlName != '\0' ) {
// Instantiating nsAutoConfig object if the pref is present
nsCOMPtr<nsIAutoConfig> autocfg;
autocfg = do_CreateInstance(NS_AUTOCONFIG_CONTRACTID,&rv);
if (NS_FAILED(rv))
return NS_ERROR_OUT_OF_MEMORY;
rv = autocfg->SetConfigURL(urlName);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
}
return NS_OK;
} // nsPref::ReadConfigFile

View File

@ -26,8 +26,6 @@
#include "nsPrefBranch.h"
#include "nsIPref.h"
#include "nsAutoConfig.h"
#include "nsIAppStartupNotifier.h"
#include "nsICategoryManager.h"
// remove this when nsPref goes away
extern NS_IMETHODIMP nsPrefConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult);
@ -39,46 +37,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefLocalizedString, Init)
//separate module so it is bundled with pref module.
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAutoConfig,Init)
// Registering nsAutoConfig module as part of the app-startup category to
// get it instantiated.
static NS_METHOD
RegisterAutoConfig(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager>
categoryManager(do_GetService("@mozilla.org/categorymanager;1", &rv));
if (NS_SUCCEEDED(rv)) {
rv = categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY,
"AutoConfig Module",
NS_AUTOCONFIG_CONTRACTID,
PR_TRUE, PR_TRUE,nsnull);
}
return rv;
}
static NS_METHOD
UnRegisterAutoConfig(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager>
categoryManager(do_GetService("@mozilla.org/categorymanager;1", &rv));
if (NS_SUCCEEDED(rv)) {
rv = categoryManager->DeleteCategoryEntry(APPSTARTUP_CATEGORY,
"AutoConfig Module",
PR_TRUE);
}
return rv;
}
// The list of components we register
static nsModuleComponentInfo components[] =
{
@ -106,9 +64,7 @@ static nsModuleComponentInfo components[] =
NS_AUTOCONFIG_CLASSNAME,
NS_AUTOCONFIG_CID,
NS_AUTOCONFIG_CONTRACTID,
nsAutoConfigConstructor,
RegisterAutoConfig,
UnRegisterAutoConfig
nsAutoConfigConstructor
},
};