nsRegistry.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG /* Allow logging in the release build */
#endif
#include "nsIGenericFactory.h"
#include "nsRegistry.h"
#include "nsIEnumerator.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "NSReg.h"
#include "prmem.h"
#include "prlock.h"
#include "prlog.h"
#include "prprf.h"
#include "nsCRT.h"
#include "nsMemory.h"
#include "nsCOMPtr.h"
#include "nsILocalFile.h"
#include "nsIServiceManager.h"
#include "nsTextFormatter.h"
#ifdef XP_BEOS
#include <FindDirectory.h>
#include <Path.h>
#endif
/* extra locking for the paranoid */
/* #define EXTRA_THREADSAFE */
#ifndef EXTRA_THREADSAFE
#define PR_Lock(x) (void)0
#define PR_Unlock(x) (void)0
#endif
// Logging of debug output
extern PRLogModuleInfo *nsComponentManagerLog;
/*-------------------------------- nsRegistry ----------------------------------
| This class implements the nsIRegistry interface using the functions |
| |
| Since that interface is designed to match the libreg function, this class |
| is implemented with each member function being a simple wrapper for the |
| corresponding libreg function. |
| |
| #define EXTRA_THREADSAFE if you are worried about libreg thread safety. |
| It should not be necessary, but I'll leave in the code for the paranoid. |
------------------------------------------------------------------------------*/
#define NS_MOZILLA_DIR_PERMISSION 00700
#include "nsRegistry.h"
/*
struct nsRegistry : public nsIRegistry {
// This class implements the nsISupports interface functions.
NS_DECL_ISUPPORTS
// This class implements the nsIRegistry interface functions.
NS_DECL_NSIREGISTRY
nsRegistry();
private:
~nsRegistry();
protected:
HREG mReg; // Registry handle.
#ifdef EXTRA_THREADSAFE
PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize.
#endif
char *mCurRegFile; // these are to prevent open from opening the registry again
nsWellKnownRegistry mCurRegID;
NS_IMETHOD Close();
}; // nsRegistry
*/
#include "nsIFactory.h"
/*----------------------------- nsRegistryFactory ------------------------------
| Class factory for nsRegistry objects. |
------------------------------------------------------------------------------*/
struct nsRegistryFactory : public nsIFactory {
// This class implements the nsISupports interface functions.
// nsIFactory methods
// ctor
};
/*--------------------------- nsRegSubtreeEnumerator ---------------------------
| This class implements the nsIEnumerator interface and is used to implement |
| the nsRegistry EnumerateSubtrees and EnumerateAllSubtrees functions. |
------------------------------------------------------------------------------*/
struct nsRegSubtreeEnumerator : public nsIRegistryEnumerator {
// This class implements the nsISupports interface functions.
// This class implements the nsIEnumerator interface functions.
// And our magic behind-the-back fast-path thing.
// virtual dtor since subclasses call our Release()
virtual ~nsRegSubtreeEnumerator();
protected:
#ifdef EXTRA_THREADSAFE
#endif
}; // nsRegSubtreeEnumerator
/*--------------------------- nsRegValueEnumerator -----------------------------
| This class is a variation on nsRegSubtreeEnumerator that allocates |
| nsRegistryValue objects rather than nsRegistryNode objects. It also |
| overrides certain functions to make sure the "value" oriented libreg |
| functions used rather than the subtree oriented ones. |
------------------------------------------------------------------------------*/
struct nsRegValueEnumerator : public nsRegSubtreeEnumerator {
// Override CurrentItem to allocate nsRegistryValue objects.
// Override advance() to use proper NR_RegEnumEntries.
}; // nsRegValueEnumerator
/*------------------------------ nsRegistryNode --------------------------------
| This class implements the nsIRegistryNode interface. Instances are |
| allocated by nsRegSubtreeEnumerator::CurrentItem. |
------------------------------------------------------------------------------*/
struct nsRegistryNode : public nsIRegistryNode {
// This class implements the nsISupports interface functions.
// This class implements the nsIRegistryNode interface functions.
// ctor
private:
~nsRegistryNode();
protected:
#ifdef EXTRA_THREADSAFE
#endif
}; // nsRegistryNode
/*------------------------------ nsRegistryValue -------------------------------
| This class implements the nsIRegistryValue interface. Instances are |
| allocated by nsRegValueEnumerator::CurrentItem. |
------------------------------------------------------------------------------*/
struct nsRegistryValue : public nsIRegistryValue {
// This class implements the nsISupports interface functions.
// This class implements the nsIRegistryValue interface functions.
// ctor
private:
~nsRegistryValue();
protected:
#ifdef EXTRA_THREADSAFE
#endif
}; // nsRegistryValue
/*----------------------------- regerr2nsresult --------------------------------
| This utility function maps a REGERR value to a corresponding nsresult |
| error code. |
------------------------------------------------------------------------------*/
switch( err ) {
case REGERR_OK:
break;
case REGERR_FAIL:
break;
case REGERR_NOMORE:
break;
case REGERR_NOFIND:
break;
case REGERR_PARAM:
case REGERR_BADTYPE:
case REGERR_BADNAME:
break;
case REGERR_NOFILE:
break;
case REGERR_MEMORY:
break;
case REGERR_BUFTOOSMALL:
break;
case REGERR_NAMETOOLONG:
break;
case REGERR_NOPATH:
break;
case REGERR_READONLY:
break;
case REGERR_BADUTF8:
break;
}
return rv;
}
/*----------------------------- reginfo2DataType -------------------------------
| This utility function converts the type field in the REGINFO structure to |
| the corresponding nsIRegistry::DataType value. |
------------------------------------------------------------------------------*/
// Transfer information, based on entry type.
case REGTYPE_ENTRY_STRING_UTF:
//out.length = in.entryLength;
break;
// Convert length in bytes to array dimension.
//out.length = in.entryLength / sizeof(PRInt32);
break;
case REGTYPE_ENTRY_BYTES:
//out.length = in.entryLength;
break;
case REGTYPE_ENTRY_FILE:
//out.length = in.entryLength;
break;
}
}
/*----------------------------- reginfo2DataType -------------------------------
| This utility function converts the length field in the REGINFO structure to |
| the proper units (if type==Int32 array, we divide by sizeof(PRInt32)). |
------------------------------------------------------------------------------*/
// Transfer information, based on entry type.
case REGTYPE_ENTRY_STRING_UTF:
break;
// Convert length in bytes to array dimension.
break;
case REGTYPE_ENTRY_BYTES:
break;
case REGTYPE_ENTRY_FILE:
break;
}
}
/*------------------------ nsISupports Implementation --------------------------
| This code generates the implementation of the nsISupports member functions |
| for each class implemented in this file. |
------------------------------------------------------------------------------*/
/*-------------------------- nsRegistry::nsRegistry ----------------------------
| Vanilla nsRegistry constructor. |
------------------------------------------------------------------------------*/
#ifdef EXTRA_THREADSAFE
mregLock = PR_NewLock();
#endif
return;
}
/*------------------------- nsRegistry::~nsRegistry ----------------------------
| The dtor closes the registry file(if open). |
------------------------------------------------------------------------------*/
nsRegistry::~nsRegistry() {
if( mReg ) {
Close();
}
#ifdef EXTRA_THREADSAFE
if (mregLock) {
}
#endif
return;
}
/*----------------------------- nsRegistry::Open -------------------------------
| If the argument is null, delegate to OpenDefault, else open the registry |
| file. We first check to see if a registry file is already open and close |
| it if so. |
------------------------------------------------------------------------------*/
// Check for default.
if( !regFile ) {
}
#ifdef DEBUG_dp
#endif /* DEBUG_dp */
{
// Cant open another registry without closing explictly.
return NS_ERROR_INVALID_ARG;
}
// Do we have an open registry ?
{
{
// The right one is already open
return NS_OK;
}
else
{
// Opening a new registry without closing an already open one.
// This is an error.
return NS_ERROR_FAILURE;
}
}
// Open specified registry.
// No error checking for no mem. Trust me.
// Convert the result.
return regerr2nsresult( err );
}
static void
// Create ~/.mozilla as that is the default place for the registry file
* vr_findGlobalRegName(). vr_findRegFile() will create the registry file
* if it doesn't exist. But it wont create directories.
*
* Hence we need to create the directory if it doesn't exist already.
*
* Why create it here as opposed to the app ?
* ------------------------------------------
* The app cannot create the directory in main() as most of the registry
* and initialization happens due to use of static variables.
* And we dont want to be dependent on the order in which
* these static stuff happen.
*
* Permission for the $HOME/.mozilla will be Read,Write,Execute
* for user only. Nothing to group and others.
*/
{
char dotMozillaDir[1024];
{
("nsComponentManager: Creating Directory %s", dotMozillaDir));
}
}
#endif /* XP_UNIX */
#ifdef XP_BEOS
BPath p;
char settingsMozillaDir[1024];
("nsComponentManager: Creating Directory %s", settingsMozillaDir));
}
#endif
}
/*----------------------------- nsRegistry::OpenWellKnownRegistry --------------
| Takes a registry id and maps that to a file name for opening. We first check |
| to see if a registry file is already open and close it if so. |
------------------------------------------------------------------------------*/
{
{
// Cant open another registry without closing explictly.
return NS_ERROR_INVALID_ARG;
}
{
// Already opened.
return NS_OK;
}
switch ( (nsWellKnownRegistry) regid ) {
NS_WARNING("ApplicationComponentRegistry is unsupported!");
break;
case ApplicationRegistry:
{
if (registryLocation)
{
// dveditz needs to fix his registry so that I can pass an
// nsIFile interface and not hack
return rv;
}
}
break;
default:
break;
}
return NS_ERROR_REG_BADTYPE;
}
#ifdef DEBUG_dp
#endif /* DEBUG_dp */
// Store the registry that was opened for optimizing future opens.
// Convert the result.
return regerr2nsresult( err );
}
#if 0
/*-------------------------- nsRegistry::OpenDefault ---------------------------
| Open the "default" registry; in the case of this libreg-based implementation |
| that is done by passing a null file name pointer to NR_RegOpen. |
------------------------------------------------------------------------------*/
}
#endif
/*----------------------------- nsRegistry::Close ------------------------------
| Tests the mReg handle and if non-null, closes the registry via NR_RegClose. |
------------------------------------------------------------------------------*/
if( mReg ) {
mReg = 0;
mCurRegID = 0;
}
return regerr2nsresult( err );
}
/*----------------------------- nsRegistry::Flush ------------------------------
| Flushes the registry via NR_RegFlush. |
------------------------------------------------------------------------------*/
if( mReg ) {
}
return regerr2nsresult( err );
}
/*----------------------------- nsRegistry::IsOpen -----------------------------
| Tests the mReg handle and returns whether the registry is open or not. |
------------------------------------------------------------------------------*/
return NS_OK;
}
/*--------------------------- nsRegistry::AddKey -------------------------------
| Add a key into the registry or find an existing one. This is generally used |
| instead of GetKey unless it's an error for the key not to exist already i
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::AddKey( nsRegistryKey baseKey, const PRUnichar *keyname, nsRegistryKey *_retval)
{
if ( !keyname )
return NS_ERROR_NULL_POINTER;
}
/*--------------------------- nsRegistry::GetKey -------------------------------
| returns the nsRegistryKey associated with a given node in the registry |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::GetKey(nsRegistryKey baseKey, const PRUnichar *keyname, nsRegistryKey *_retval)
{
return NS_ERROR_NULL_POINTER;
}
/*--------------------------- nsRegistry::RemoveKey ----------------------------
| Delete a key from the registry |
------------------------------------------------------------------------------*/
{
if ( !keyname )
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsRegistry::GetString(nsRegistryKey baseKey, const PRUnichar *valname, PRUnichar **_retval)
{
// Make sure caller gave us place for result.
return NS_ERROR_NULL_POINTER;
// initialize the return value
if (NS_SUCCEEDED(rv))
{
}
return rv;
}
NS_IMETHODIMP nsRegistry::SetString(nsRegistryKey baseKey, const PRUnichar *valname, const PRUnichar *value)
{
return NS_ERROR_NULL_POINTER;
return SetStringUTF8( baseKey,
}
/*--------------------------- nsRegistry::GetString ----------------------------
| First, look for the entry using GetValueInfo. If found, and it's a string, |
| allocate space for it and fetch the value. |
------------------------------------------------------------------------------*/
// Make sure caller gave us place for result.
if ( !result )
return NS_ERROR_NULL_POINTER;
char regStr[MAXREGPATHLEN];
// initialize the return value
*result = 0;
// Attempt to get string into our fixed buffer
sizeof(regStr) );
{
if (!*result)
}
else if ( err == REGERR_BUFTOOSMALL )
{
// find the real size and malloc it
// See if that worked.
{
if( *result )
{
// Get string from registry into result buffer.
// Convert status.
{
// Didn't get result, free buffer
*result = 0;
}
}
else
{
}
}
}
else
{
// Convert status.
}
return rv;
}
{
// Attempt to get string into our fixed buffer
// Convert status.
if (rv == NS_ERROR_REG_BUFFER_TOO_SMALL) {
// fill length with the actual length
return rv1;
}
return rv;
}
/*--------------------------- nsRegistry::SetString ----------------------------
| Simply sets the registry contents using NR_RegSetEntryString. |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::SetStringUTF8( nsRegistryKey baseKey, const char *path, const char *value ) {
// Set the contents.
// Convert result.
return regerr2nsresult( err );
}
/*---------------------------- nsRegistry::GetBytesUTF8 ------------------------------
| This function is just shorthand for fetching a char array. We |
| implement it "manually" using NR_RegGetEntry |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::GetBytesUTF8( nsRegistryKey baseKey, const char *path, PRUint32* length, PRUint8** result) {
if ( !result )
return NS_ERROR_NULL_POINTER;
char regStr[MAXREGPATHLEN];
// initialize the return value
*length = 0;
*result = 0;
// Get info about the requested entry.
// See if that worked.
{
// Make sure the entry is an PRInt8 array.
{
// Attempt to get string into our fixed buffer
{
if (!*result)
{
*length = 0;
}
else
{
}
}
else if ( err == REGERR_BUFTOOSMALL )
{
// find the real size and malloc it
// See if that worked.
{
if( *result )
{
// Get bytes from registry into result field.
// Convert status.
{
// Didn't get result, free buffer
*result = 0;
*length = 0;
}
}
else
{
}
}
}
}
else
{
// They asked for the wrong type of value.
}
}
return rv;
}
{
// Get info about the requested entry.
// See if that worked.
return rv;
// Make sure we are dealing with bytes
return NS_ERROR_REG_BADTYPE;
// Attempt to get bytes into our fixed buffer
if (rv == NS_ERROR_REG_BUFFER_TOO_SMALL) {
// fill length with the actual length
return rv1;
}
return rv;
}
/*---------------------------- nsRegistry::GetInt ------------------------------
| This function is just shorthand for fetching a 1-element PRInt32 array. We |
| implement it "manually" using NR_RegGetEntry |
------------------------------------------------------------------------------*/
// Make sure caller gave us place for result.
if( result ) {
// Get info about the requested entry.
// See if that worked.
// Make sure the entry is an PRInt32 array.
// Get int from registry into result field.
// Convert status.
} else {
// They asked for the wrong type of value.
}
}
} else {
}
return rv;
}
/*---------------------------- nsRegistry::GetLongLong--------------------------
| This function is just shorthand for fetching a 1-element PRInt64 array. We |
| implement it "manually" using NR_RegGetEntry |
------------------------------------------------------------------------------*/
// Convert status.
return regerr2nsresult( err );
}
/*---------------------------- nsRegistry::SetBytesUTF8 ------------------------------
| Write out the value as a char array, using NR_RegSetEntry. |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::SetBytesUTF8( nsRegistryKey baseKey, const char *path, PRUint32 length, PRUint8* value) {
// Set the contents.
(char*)path,
(char*)value,
length);
// Convert result.
return regerr2nsresult( err );
}
/*---------------------------- nsRegistry::SetInt ------------------------------
| Write out the value as a one-element PRInt32 array, using NR_RegSetEntry. |
------------------------------------------------------------------------------*/
// Set the contents.
(char*)path,
&value,
sizeof value );
// Convert result.
return regerr2nsresult( err );
}
/*---------------------------- nsRegistry::SetLongLong---------------------------
| Write out the value as a one-element PRInt64 array, using NR_RegSetEntry. |
------------------------------------------------------------------------------*/
// Set the contents.
(char*)path,
(void*)value,
sizeof(PRInt64) );
// Convert result.
return regerr2nsresult( err );
}
/*-------------------------- nsRegistry::AddSubtree ----------------------------
| Add a new registry subkey with the specified name, using NR_RegAddKey. |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::AddSubtree( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
// Add the subkey.
// Convert result.
return regerr2nsresult( err );
}
/*-------------------------- nsRegistry::AddSubtreeRaw--------------------------
| Add a new registry subkey with the specified name, using NR_RegAddKeyRaw |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::AddSubtreeRaw( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
// Add the subkey.
// Convert result.
return regerr2nsresult( err );
}
/*------------------------- nsRegistry::RemoveSubtree --------------------------
| Deletes the subtree at a given location using NR_RegDeleteKey. |
------------------------------------------------------------------------------*/
// libreg doesn't delete keys if there are subkeys under the key
// Hence we have to recurse through to delete the subtree
{
return rv;
}
// Now recurse through and delete all keys under hierarchy
subkeyname[0] = '\0';
REGENUM_NORMAL) == REGERR_OK)
{
#ifdef DEBUG_dp
#endif /* DEBUG_dp */
// Even though this is not a "Raw" API the subkeys may still, in fact,
// *be* raw. Since we're recursively deleting this will work either way.
// If we were guaranteed none would be raw then a depth-first enumeration
// would be much more efficient.
}
// If success in deleting all subkeys, delete this key too
{
#ifdef DEBUG_dp
#endif /* DEBUG_dp */
}
// Convert result.
return rv;
}
/*------------------------- nsRegistry::RemoveSubtreeRaw -----------------------
| Deletes the subtree at a given location using NR_RegDeleteKeyRaw |
------------------------------------------------------------------------------*/
// libreg doesn't delete keys if there are subkeys under the key
// Hence we have to recurse through to delete the subtree
int n = sizeof(subkeyname);
{
return rv;
}
// Now recurse through and delete all keys under hierarchy
subkeyname[0] = '\0';
{
#ifdef DEBUG_dp
#endif /* DEBUG_dp */
}
// If success in deleting all subkeys, delete this key too
{
#ifdef DEBUG_dp
#endif /* DEBUG_dp */
}
// Convert result.
return rv;
}
/*-------------------------- nsRegistry::GetSubtree ----------------------------
| obtained using NR_RegGetKey. |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::GetSubtree( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
// Make sure we have a place for the result.
if( result ) {
// Get key.
// Convert result.
} else {
}
return rv;
}
/*-------------------------- nsRegistry::GetSubtreeRaw--------------------------
| obtained using NR_RegGetKeyRaw. |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::GetSubtreeRaw( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
// Make sure we have a place for the result.
if( result ) {
// Get key.
// Convert result.
} else {
}
return rv;
}
/*----------------------- nsRegistry::EnumerateSubtrees ------------------------
| Allocate a nsRegSubtreeEnumerator object and return it to the caller. |
| We construct the enumerator using the registry handle from this registry |
| object, the user-specified registry key, and indicate that we don't want |
| to recurse down subtrees. No libreg functions are invoked at this point |
|(that will happen when the enumerator member functions are called). |
------------------------------------------------------------------------------*/
// Make sure we have a place to put the result.
if( result ) {
// Check for success.
if( *result ) {
// Bump refcnt on behalf of caller.
} else {
// Unable to allocate space for the enumerator object.
}
} else {
}
return rv;
}
/*--------------------- nsRegistry::EnumerateAllSubtrees -----------------------
| Same as EnumerateSubtrees but we pass PR_TRUE to request that the |
| enumerator object descend subtrees when it is used. |
------------------------------------------------------------------------------*/
// Make sure we have a place to put the result.
if( result ) {
// Check for success.
if( *result ) {
// Bump refcnt on behalf of caller.
} else {
// Unable to allocate space for the enumerator object.
}
} else {
}
return rv;
}
/*------------------------- nsRegistry::GetValueType ---------------------------
| Gets the type from the registry using the NR_GetEntryInfo libreg API. |
| The result is transferred to the PRUint32 value passed in (with conversion |
| to the appropriate nsIRegistry::DataType value). |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::GetValueType( nsRegistryKey baseKey, const char *path, PRUint32 *result ) {
// Make sure we have a place to put the result.
if( result ) {
// Get registry info into local structure.
// Copy info to user's result value.
} else {
}
} else {
}
return rv;
}
/*------------------------ nsRegistry::GetValueLength --------------------------
| Gets the registry value info via NR_RegGetEntryInfo. The length is |
| converted to the proper "units" via reginfo2Length. |
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::GetValueLength( nsRegistryKey baseKey, const char *path, PRUint32 *result ) {
// Make sure we have a place to put the result.
if( result ) {
// Get registry info into local structure.
// Copy info to user's result value.
} else {
}
} else {
}
return rv;
}
/*-------------------------- nsRegistry::DeleteValue ---------------------------
| Remove the registry value with the specified name |
------------------------------------------------------------------------------*/
{
// Delete the value
// Convert result.
return regerr2nsresult( err );
}
/*------------------------ nsRegistry::EnumerateValues -------------------------
| Allocates and returns an instance of nsRegValueEnumerator constructed in |
| EnumerateSubtrees. |
------------------------------------------------------------------------------*/
// Make sure we have a place to put the result.
if( result ) {
// Check for success.
if( *result ) {
// Bump refcnt on behalf of caller.
} else {
// Unable to allocate space for the enumerator object.
}
} else {
}
return rv;
}
/*---------------------- nsRegistry::GetCurrentUserName ------------------------
| Simple wrapper for NR_RegGetUsername. |
------------------------------------------------------------------------------*/
// Make sure we have a place to put the result.
if( result ) {
// Get the user name.
// Convert the result.
} else {
}
return rv;
}
/*---------------------- nsRegistry::SetCurrentUserName ------------------------
| Simple wrapper for NR_RegSetUsername. |
------------------------------------------------------------------------------*/
// Set the user name.
// Convert result.
return rv;
}
/*----------------------------- nsRegistry::Pack -------------------------------
| Simple wrapper for NR_RegPack. We don't set up any callback. |
------------------------------------------------------------------------------*/
// Pack the registry.
// Convert result.
return rv;
}
/*----------------------------- nsRegistry::EscapeKey -------------------------------
| Escape a binary key so that the registry works OK, since it expects UTF8
| with no slashes or control characters. This is probably better than raw.
| If no escaping is required, then the method is successful and a null is
| returned, indicating that the caller should use the original string.
------------------------------------------------------------------------------*/
static const char sEscapeKeyHex[] = "0123456789abcdef0123456789ABCDEF";
NS_IMETHODIMP nsRegistry::EscapeKey(PRUint8* key, PRUint32 termination, PRUint32* length, PRUint8** escaped)
{
char* b = value;
char* e = b + *length;
int escapees = 0;
while (b < e) // Count characters outside legal range or slash
{
int c = *b++;
if (c <= ' '
|| c > '~'
|| c == '/'
|| c == '%')
{
escapees++;
}
}
if (escapees == 0) // If no escapees, then no results
{
*length = 0;
return NS_OK;
}
// New length includes two extra chars for escapees.
{
*length = 0;
return NS_ERROR_OUT_OF_MEMORY;
}
char* n = (char*)*escaped;
b = value;
while (escapees && b < e)
{
char c = *b++;
if (c < ' '
|| c > '~'
|| c == '/'
|| c == '%')
{
*(n++) = '%';
*(n++) = sEscapeKeyHex[ 0xF & c ];
escapees--;
}
else
{
*(n++) = c;
}
}
e += termination;
if (b < e)
{
strncpy(n, b, e - b);
}
return rv;
}
/*----------------------------- nsRegistry::UnescapeKey -------------------------------
| Unscape a binary key so that the registry works OK, since it expects UTF8
| with no slashes or control characters. This is probably better than raw.
| If no escaping is required, then the method is successful and a null is
| returned, indicating that the caller should use the original string.
------------------------------------------------------------------------------*/
NS_IMETHODIMP nsRegistry::UnescapeKey(PRUint8* escaped, PRUint32 termination, PRUint32* length, PRUint8** key)
{
char* b = value;
char* e = b + *length;
int escapees = 0;
while (b < e) // Count characters outside legal range or slash
{
if (*b++ == '%')
{
escapees++;
}
}
if (escapees == 0) // If no escapees, then no results
{
*length = 0;
return NS_OK;
}
// New length includes two extra chars for escapees.
{
*length = 0;
return NS_ERROR_OUT_OF_MEMORY;
}
char* n = (char*)*key;
b = value;
while (escapees && b < e)
{
char c = *(b++);
if (c == '%')
{
if (e - b >= 2)
{
{
}
else
{
escapees = -1;
}
}
else
{
escapees = -1;
}
escapees--;
}
else
{
*(n++) = c;
}
}
if (escapees < 0)
{
*length = 0;
return NS_ERROR_INVALID_ARG;
}
e += termination;
if (b < e)
{
strncpy(n, b, e - b);
}
return rv;
}
/*-------------- nsRegistry::SetBufferSize-------------------------------------
| Sets the size of the file used for the registry's buffer size. |
------------------------------------------------------------------------------*/
{
int newSize;
// set the file buffer size
return newSize;
}
/*-------------- nsRegSubtreeEnumerator::nsRegSubtreeEnumerator ----------------
| The ctor simply stashes all the information that will be needed to enumerate |
| the subkeys. |
------------------------------------------------------------------------------*/
mName[0] = '\0';
#ifdef EXTRA_THREADSAFE
// Create a registry lock
mregLock = PR_NewLock();
#endif
return;
}
{
#ifdef EXTRA_THREADSAFE
if (mregLock) {
}
#endif
}
/*----------------------- nsRegSubtreeEnumerator::First ------------------------
| Set mEnum to 0; this will cause the next NR_RegEnum call to go to |
| the beginning. We then do a Next() call in order to do a "lookahead" to |
| properly detect an empty list (i.e., set the mDone flag). |
------------------------------------------------------------------------------*/
// Reset "done" flag.
// Clear Name
mName[0] = '\0';
// Go to beginning.
// Lookahead so mDone flag gets set for empty list.
return rv;
}
/*----------------------- nsRegSubtreeEnumerator::Next -------------------------
| First, we check if we've already advanced to the end by checking the mDone |
| flag. |
| |
| We advance mEnum to the next enumeration value which is in the mNext |
| lookahead buffer. We must then call advance to lookahead and properly set |
| the isDone flag. |
------------------------------------------------------------------------------*/
// Check for at end.
if ( !mDone ) {
// Advance to next spot.
// Lookahead so mDone is properly set (and to update mNext).
} else {
// Set result accordingly.
}
return rv;
}
/*---------------------- nsRegSubtreeEnumerator::advance -----------------------
| Advance mNext to next subkey using NR_RegEnumSubkeys. We set mDone if |
| there are no more subkeys. |
------------------------------------------------------------------------------*/
// See if we ran off end.
if( err == REGERR_NOMORE ) {
// Remember we've run off end.
}
// Convert result.
return rv;
}
/*-------------------- nsRegSubtreeEnumerator::CurrentItem ---------------------
| Allocates and returns a new instance of class nsRegistryNode. The node |
| object will hold the curent mEnum value so it can obtain its name from |
| the registry when asked. |
------------------------------------------------------------------------------*/
// Make sure there is a place to put the result.
if( result ) {
if( *result ) {
} else {
}
} else {
}
return rv;
}
/*--------------nsRegSubtreeEnumerator::CurrentItemInPlaceUTF8-----------------
| An ugly name for an ugly function. Hands back a shared pointer to the |
| name (encoded as UTF-8), and the subkey identifier. |
-----------------------------------------------------------------------------*/
const char **name )
{
/* [shared] */
return NS_OK;
}
/*---------------------- nsRegSubtreeEnumerator::IsDone ------------------------
| Simply return mDone. |
------------------------------------------------------------------------------*/
return rv;
}
/*---------------- nsRegValueEnumerator::nsRegValueEnumerator ------------------
| Delegates everything to the base class constructor. |
------------------------------------------------------------------------------*/
return;
}
/*--------------------- nsRegValueEnumerator::CurrentItem ----------------------
| As the nsRegSubtreeEnumerator counterpart, but allocates an object of |
| class nsRegistryValue. |
------------------------------------------------------------------------------*/
// Make sure there is a place to put the result.
if( result ) {
if( *result ) {
} else {
}
} else {
}
return rv;
}
/*----------------------- nsRegValueEnumerator::advance ------------------------
| Advance mNext to next subkey using NR_RegEnumEntries. We set mDone if |
| there are no more entries. |
------------------------------------------------------------------------------*/
char name[MAXREGNAMELEN];
// See if we ran off end.
if( err == REGERR_NOMORE ) {
// Remember we've run off end.
}
// Convert result.
return rv;
}
/*---------------------- nsRegistryNode::nsRegistryNode ------------------------
| Store the arguments in the corresponding data members and initialize |
| the other data members. We defer the libreg calls till we're asked for |
| our name. We use mErr==-1 to indicate we haven't fetched the name yet. |
------------------------------------------------------------------------------*/
#ifdef EXTRA_THREADSAFE
mregLock = PR_NewLock();
#endif
return;
}
{
#ifdef EXTRA_THREADSAFE
if (mregLock) {
}
#endif
}
/*-------------------------- nsRegistryNode::GetName ---------------------------
| If we haven't fetched it yet, get the name of the corresponding subkey now, |
| using NR_RegEnumSubkeys. |
------------------------------------------------------------------------------*/
// Make sure there is a place to put the result.
if ( !*result ) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
/*-------------------------- nsRegistryNode::GetNameUTF8 -----------------------
| If we haven't fetched it yet, get the name of the corresponding subkey now, |
| using NR_RegEnumSubkeys. |
------------------------------------------------------------------------------*/
// Make sure there is a place to put the result.
if ( !*result ) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
/*-------------------------- nsRegistryNode::GetKey ----------------------------
| Get the subkey corresponding to this node |
| using NR_RegEnumSubkeys. |
------------------------------------------------------------------------------*/
return rv;
}
/*--------------------- nsRegistryValue::nsRegistryValue -----------------------
| Implemented the same way as the nsRegistryNode ctor. |
------------------------------------------------------------------------------*/
#ifdef EXTRA_THREADSAFE
mregLock = PR_NewLock();
#endif
}
{
#ifdef EXTRA_THREADSAFE
if (mregLock) {
}
#endif
}
/*------------------------- nsRegistryValue::GetName ---------------------------
| See nsRegistryNode::GetName; we use NR_RegEnumEntries in this case. |
------------------------------------------------------------------------------*/
// Make sure we have a place to put the result.
if( result ) {
// Ensure we've got the info we need.
// worked, return actual result.
if ( *result ) {
} else {
}
}
} else {
}
return rv;
}
/*------------------------- nsRegistryValue::GetNameUTF8 -----------------------
| See nsRegistryNode::GetName; we use NR_RegEnumEntries in this case. |
------------------------------------------------------------------------------*/
// Make sure we have a place to put the result.
if( result ) {
// Ensure we've got the info we need.
// worked, return actual result.
if ( *result ) {
} else {
}
}
} else {
}
return rv;
}
/*----------------------- nsRegistryValue::GetType ------------------------
| We test if we've got the info already. If not, we git it by calling |
| getInfo. We calculate the result by converting the REGINFO type field to |
| a nsIRegistry::DataType value (using reginfo2DataType). |
------------------------------------------------------------------------------*/
// Make sure we have room for th result.
if( result ) {
// Make sure we've got the info we need.
// Check if it worked.
// Convert result from REGINFO to nsIRegistry::ValueInfo.
}
} else {
}
return rv;
}
/*---------------------- nsRegistryValue::GetLength -----------------------
| We test if we've got the info already. If not, we git it by calling |
| getInfo. We calculate the result by converting the REGINFO type field to |
| a nsIRegistry::DataType value (using reginfo2Length). |
------------------------------------------------------------------------------*/
// Make sure we have room for th result.
if( result ) {
// Make sure we've got the info we need.
// Check if it worked.
// Convert result from REGINFO to length.
}
} else {
}
return rv;
}
/*------------------------- nsRegistryValue::getInfo ---------------------------
------------------------------------------------------------------------------*/
// Test whether we haven't tried to get it yet.
if( mErr == -1 ) {
// Get name and info.
// Convert result.
}
return rv;
}
}
void **aResult) {
return NS_ERROR_NULL_POINTER;
} else {
}
if(0 != aOuter) {
return NS_ERROR_NO_AGGREGATION;
}
if(newRegistry == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}
{
// Not implemented in simplest case.
return NS_OK;
}
// This is a temporary hack; needs work to support dynamic binding
// via nsComponentManager and support for multiple factories per DLL.
if( aFactory == 0 ) {
return NS_ERROR_NULL_POINTER;
} else {
*aFactory = 0;
}
if(0 == inst) {
} else {
}
return rv;
}