Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
nsReadConfig Class Reference

#include <nsReadConfig.h>

Inheritance diagram for nsReadConfig:
Inheritance graph
Collaboration diagram for nsReadConfig:
Collaboration graph

List of all members.

Public Member Functions

nsReadConfig ()
virtual ~nsReadConfig ()
nsresult Init ()
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Protected Member Functions

nsresult readConfigFile ()
nsresult openAndEvaluateJSFile (const char *aFileName, PRInt32 obscureValue, PRBool isEncoded, PRBool isBinDir)

Protected Attributes

PRBool mRead

Private Attributes

nsCOMPtr< nsIAutoConfigmAutoConfig

Detailed Description

Definition at line 45 of file nsReadConfig.h.

Constructor & Destructor Documentation

Definition at line 111 of file nsReadConfig.cpp.

    if (!MCD)
      MCD = PR_NewLogModule("MCD");

Definition at line 131 of file nsReadConfig.cpp.

Here is the call graph for this function:

Member Function Documentation

Definition at line 118 of file nsReadConfig.cpp.

    nsresult rv;
    nsCOMPtr<nsIObserverService> observerService = 
        do_GetService(";1", &rv);

    if (observerService) {
        rv = observerService->AddObserver(this, NS_PREFSERVICE_READ_TOPIC_ID, PR_FALSE);

Here is the call graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
nsresult nsReadConfig::openAndEvaluateJSFile ( const char *  aFileName,
PRInt32  obscureValue,
PRBool  isEncoded,
PRBool  isBinDir 
) [protected]

Definition at line 270 of file nsReadConfig.cpp.

    nsresult rv;
    nsCOMPtr<nsIFile> jsFile;

    if (isBinDir) {
        rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, 
        if (NS_FAILED(rv)) 
            return rv;
#ifdef XP_MAC
        jsFile->AppendNative(NS_LITERAL_CSTRING("Essential Files"));
    } else {
        rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR,
        if (NS_FAILED(rv)) 
            return rv;
        rv = jsFile->AppendNative(NS_LITERAL_CSTRING("autoconfig"));
        if (NS_FAILED(rv))
            return rv;
    rv = jsFile->AppendNative(nsDependentCString(aFileName));
    if (NS_FAILED(rv)) 
        return rv;

    nsCOMPtr<nsIInputStream> inStr;
    rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
    if (NS_FAILED(rv)) 
        return rv;        
    PRInt64 fileSize;
    PRUint32 fs, amt = 0;
    LL_L2UI(fs, fileSize); // Converting 64 bit structure to unsigned int

    char *buf = (char *)PR_Malloc(fs * sizeof(char));
    if (!buf) 
        return NS_ERROR_OUT_OF_MEMORY;
    rv = inStr->Read(buf, fs, &amt);
    NS_ASSERTION((amt == fs), "failed to read the entire configuration file!!");
    if (NS_SUCCEEDED(rv)) {
        if (obscureValue > 0) {

            // Unobscure file by subtracting some value from every char. 
            for (PRUint32 i = 0; i < amt; i++)
                buf[i] -= obscureValue;
        nsCAutoString path;

        nsCAutoString fileURL;
        fileURL = NS_LITERAL_CSTRING("file:///") + path;
        rv = EvaluateAdminConfigScript(buf, amt, fileURL.get(), 
                                       PR_FALSE, PR_TRUE, 
                                       isEncoded ? PR_TRUE:PR_FALSE);
    return rv;

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 155 of file nsReadConfig.cpp.

    nsresult rv = NS_OK;
    nsXPIDLCString lockFileName;
    nsXPIDLCString lockVendor;
    PRUint32 fileNameLen = 0;
    nsCOMPtr<nsIPrefBranch> defaultPrefBranch;
    nsCOMPtr<nsIPrefService> prefService = 
        do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return rv;

    rv = prefService->GetDefaultBranch(nsnull, getter_AddRefs(defaultPrefBranch));
    if (NS_FAILED(rv))
        return rv;
    // This preference is set in the all.js or all-ns.js (depending whether 
    // running mozilla or netscp6)

    rv = defaultPrefBranch->GetCharPref("general.config.filename", 

    PR_LOG(MCD, PR_LOG_DEBUG, ("general.config.filename = %s\n", lockFileName.get()));
    if (NS_FAILED(rv))
        return rv;

    // This needs to be read only once.
    if (!mRead) {
        // Initiate the new JS Context for Preference management
        rv = CentralizedAdminPrefManagerInit();
        if (NS_FAILED(rv))
            return rv;
        // Open and evaluate function calls to set/lock/unlock prefs
        rv = openAndEvaluateJSFile("prefcalls.js", 0, PR_FALSE, PR_FALSE);
        if (NS_FAILED(rv)) 
            return rv;

        // Evaluate platform specific directives
        rv = openAndEvaluateJSFile("platform.js", 0, PR_FALSE, PR_FALSE);
        if (NS_FAILED(rv)) 
            return rv;

        mRead = PR_TRUE;
    // If the lockFileName is NULL return ok, because no lockFile will be used
    // 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).

    nsCOMPtr<nsIPrefBranch> prefBranch;
    rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
    NS_ENSURE_SUCCESS(rv, rv);

    PRInt32 obscureValue = 0;
    (void) defaultPrefBranch->GetIntPref("general.config.obscure_value", &obscureValue);
    PR_LOG(MCD, PR_LOG_DEBUG, ("evaluating .cfg file %s with obscureValue %d\n", lockFileName.get(), obscureValue));
    rv = openAndEvaluateJSFile(lockFileName.get(), PR_TRUE, obscureValue, PR_TRUE);
    if (NS_FAILED(rv))
      PR_LOG(MCD, PR_LOG_DEBUG, ("error evaluating .cfg file %s %x\n", lockFileName.get(), rv));
      return rv;
    rv = prefBranch->GetCharPref("general.config.filename", 
    if (NS_FAILED(rv))
        // There is NO REASON we should ever get here. This is POST reading 
        // of the config file.
        return NS_ERROR_FAILURE;

    rv = prefBranch->GetCharPref("general.config.vendor", 
    // If vendor is not NULL, do this check
    if (NS_SUCCEEDED(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 = prefBranch->GetCharPref("autoadmin.global_config_url",
    if (NS_SUCCEEDED(rv) && !urlName.IsEmpty()) {

        // Instantiating nsAutoConfig object if the pref is present
        mAutoConfig = do_CreateInstance(NS_AUTOCONFIG_CONTRACTID, &rv);
        if (NS_FAILED(rv))
            return NS_ERROR_OUT_OF_MEMORY;

        rv = mAutoConfig->SetConfigURL(urlName);
        if (NS_FAILED(rv))
            return NS_ERROR_FAILURE;

    return NS_OK;
} // ReadConfigFile

Here is the call graph for this function:

Member Data Documentation

Definition at line 67 of file nsReadConfig.h.

Definition at line 65 of file nsReadConfig.h.

The documentation for this class was generated from the following files: