Backout changeset 971ed890c27d (bug 679352), since burning comm-central; a=callek

This commit is contained in:
Ed Morley 2011-09-25 16:26:10 +01:00
Родитель 27cc5cc8df
Коммит ec547b0b85
19 изменённых файлов: 8826 добавлений и 0 удалений

Просмотреть файл

@ -54,9 +54,13 @@ endif
EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME_PATH,unicharutil_external_s,$(LIBXUL_DIST)/lib)
# migration requires mozreg
LOCAL_INCLUDES += -I$(srcdir)/../migration/src
SHARED_LIBRARY_LIBS += ../migration/src/$(LIB_PREFIX)migration_s.$(LIB_SUFFIX)
EXTRA_DSO_LDOPTS += $(LIBXUL_DIST)/lib/$(LIB_PREFIX)mozreg_s.$(LIB_SUFFIX)
# This has to come after the above chunk, because mozreg_s has dependencies on
# stuff in MOZ_COMPONENT_LIBS.
EXTRA_DSO_LDOPTS += \
$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
$(MOZ_COMPONENT_LIBS) \

Просмотреть файл

@ -0,0 +1,50 @@
#
# ***** 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
# http://www.mozilla.org/MPL/
#
# 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 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 *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libreg
DIRS = include src
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,50 @@
#
# ***** 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
# http://www.mozilla.org/MPL/
#
# 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 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libreg
EXPORTS = VerReg.h NSReg.h
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,574 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/* NSReg.h
*/
#ifndef _NSREG_H_
#define _NSREG_H_
typedef void (*nr_RegPackCallbackFunc) (void *userData, int32 bytes, int32 totalBytes);
typedef int32 REGERR;
typedef int32 RKEY;
typedef uint32 REGENUM;
typedef void * HREG;
typedef struct _reginfo
{
uint16 size; /* must be initialized to sizeof(REGINFO) */
uint16 entryType;
uint32 entryLength;
} REGINFO;
#define REGERR_OK (0)
#define REGERR_FAIL (1)
#define REGERR_NOMORE (2)
#define REGERR_NOFIND (3)
#define REGERR_BADREAD (4)
#define REGERR_BADLOCN (5)
#define REGERR_PARAM (6)
#define REGERR_BADMAGIC (7)
#define REGERR_BADCHECK (8)
#define REGERR_NOFILE (9)
#define REGERR_MEMORY (10)
#define REGERR_BUFTOOSMALL (11)
#define REGERR_NAMETOOLONG (12)
#define REGERR_REGVERSION (13)
#define REGERR_DELETED (14)
#define REGERR_BADTYPE (15)
#define REGERR_NOPATH (16)
#define REGERR_BADNAME (17)
#define REGERR_READONLY (18)
#define REGERR_BADUTF8 (19)
/* Total path length */
#define MAXREGPATHLEN (2048)
/* Name on the path (including null terminator) */
#define MAXREGNAMELEN (512)
/* Value of an entry */
#define MAXREGVALUELEN (0x7FFF)
/* Standard keys */
#define ROOTKEY_USERS (0x01)
#define ROOTKEY_COMMON (0x02)
#define ROOTKEY_CURRENT_USER (0x03)
#define ROOTKEY_PRIVATE (0x04)
/* enumeration styles */
#define REGENUM_NORMAL (0x00)
#define REGENUM_CHILDREN REGENUM_NORMAL
#define REGENUM_DESCEND (0x01)
#define REGENUM_DEPTH_FIRST (0x02)
/* entry data types */
#define REGTYPE_ENTRY (0x0010)
#define REGTYPE_ENTRY_STRING_UTF (REGTYPE_ENTRY + 1)
#define REGTYPE_ENTRY_INT32_ARRAY (REGTYPE_ENTRY + 2)
#define REGTYPE_ENTRY_BYTES (REGTYPE_ENTRY + 3)
#define REGTYPE_ENTRY_FILE (REGTYPE_ENTRY + 4)
#define REG_DELETE_LIST_KEY "Mozilla/XPInstall/Delete List"
#define REG_REPLACE_LIST_KEY "Mozilla/XPInstall/Replace List"
#define REG_UNINSTALL_DIR "Mozilla/XPInstall/Uninstall/"
#define REG_REPLACE_SRCFILE "ReplacementFile"
#define REG_REPLACE_DESTFILE "DestinationFile"
#define UNINSTALL_NAV_STR "_"
#define UNIX_GLOBAL_FLAG "MOZILLA_SHARED_REGISTRY"
/* libreg functions are not DLLexported and may have hidden visibility */
#define VR_INTERFACE(type) type
PR_BEGIN_EXTERN_C
/* ---------------------------------------------------------------------
* Registry API -- General
* ---------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------
* NR_RegSetBufferSize - Sets the file buffer size
*
* Parameters:
* hReg - handle to opened registry
* bufsize - size of the new buffer
*
* Output:
* ---------------------------------------------------------------------
* returns the size of the buffer or -1 for err
*/
VR_INTERFACE(int) NR_RegSetBufferSize(
HREG hReg, /* handle to opened registry */
int bufsize
);
/* ---------------------------------------------------------------------
* NR_RegOpen - Open a netscape XP registry
*
* Parameters:
* filename - registry file to open. NULL or "" opens the standard
* local registry.
* hReg - OUT: handle to opened registry
*
* Output:
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegOpen(
const char *filename, /* reg. file to open (NULL == standard registry) */
HREG *hReg /* OUT: handle to opened registry */
);
/* ---------------------------------------------------------------------
* NR_RegClose - Close a netscape XP registry
*
* Parameters:
* hReg - handle of open registry to be closed.
*
* After calling this routine the handle is no longer valid
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegClose(
HREG hReg /* handle of open registry to close */
);
/* ---------------------------------------------------------------------
* NR_RegFlush - Manually flush data in a netscape XP registry
*
* Parameters:
* hReg - handle of open registry to be flushed.
*
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegFlush(
HREG hReg /* handle of open registry to flush */
);
/* ---------------------------------------------------------------------
* NR_RegIsWritable - Check read/write status of open registry
*
* Parameters:
* hReg - handle of open registry to query
* Returns:
* REGERR_OK if writable, REGERR_READONLY if not, possibly
* other errors for an invalid hReg
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegIsWritable(
HREG hReg /* handle of open registry to query */
);
VR_INTERFACE(REGERR) NR_RegPack(
HREG hReg, /* handle of open registry to pack */
void *userData,
nr_RegPackCallbackFunc fn
);
/* ---------------------------------------------------------------------
* NR_RegSetUsername - Set the current username
*
* If the current user profile name is not set then trying to use
* HKEY_CURRENT_USER will result in an error.
*
* Parameters:
* name - name of the current user
*
* Output:
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegSetUsername(
const char *name /* name of current user */
);
/* ---------------------------------------------------------------------
* NR_RegGetUniqueName
*
* Returns a unique name that can be used for anonymous key/value names
*
* Parameters:
* hReg - handle of open registry
* outbuf - where to put the string
* buflen - how big the buffer is
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetUniqueName(
HREG hReg, /* handle of open registry */
char* outbuf, /* buffer to hold key name */
uint32 buflen /* size of buffer */
);
/* ---------------------------------------------------------------------
* DO NOT USE -- Will be removed
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetUsername(
char **name /* on return, an alloc'ed copy of the current user name */
);
/* ---------------------------------------------------------------------
* Registry API -- Key Management functions
* ---------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------
* NR_RegAddKey - Add a key node to the registry
*
* Can also be used to find an existing node for convenience.
*
* Parameters:
* hReg - handle of open registry
* key - registry key obtained from NR_RegGetKey(),
* or one of the standard top-level keys
* path - relative path of key to be added. Intermediate
* nodes will be added if necessary.
* newkey - If not null returns RKEY of new or found node
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegAddKey(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
char *path, /* relative path of subkey to add */
RKEY *newKey /* if not null returns newly created key */
);
/* ---------------------------------------------------------------------
* NR_RegAddKeyRaw - Add a key node to the registry
*
* This routine is different from NR_RegAddKey() in that it takes
* a keyname rather than a path.
*
* Parameters:
* hReg - handle of open registry
* key - registry key obtained from NR_RegGetKey(),
* or one of the standard top-level keys
* keyname - name of key to be added. No parsing of this
* name happens.
* newkey - if not null the RKEY of the new key is returned
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegAddKeyRaw(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
char *keyname, /* name of key to add */
RKEY *newKey /* if not null returns newly created key */
);
/* ---------------------------------------------------------------------
* NR_RegDeleteKey - Delete the specified key
*
* Note that delete simply orphans blocks and makes no attempt
* to reclaim space in the file. Use NR_RegPack()
*
* Cannot be used to delete keys with child keys
*
* Parameters:
* hReg - handle of open registry
* key - starting node RKEY, typically one of the standard ones.
* path - relative path of key to delete
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegDeleteKey(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
char *path /* relative path of subkey to delete */
);
/* ---------------------------------------------------------------------
* NR_RegDeleteKeyRaw - Delete the specified raw key
*
* Note that delete simply orphans blocks and makes no attempt
* to reclaim space in the file. Use NR_RegPack()
*
* Parameters:
* hReg - handle of open registry
* key - RKEY or parent to the raw key you wish to delete
* keyname - name of child key to delete
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegDeleteKeyRaw(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
char *keyname /* name subkey to delete */
);
/* ---------------------------------------------------------------------
* NR_RegGetKey - Get the RKEY value of a node from its path
*
* Parameters:
* hReg - handle of open registry
* key - starting node RKEY, typically one of the standard ones.
* path - relative path of key to find. (a blank path just gives you
* the starting key--useful for verification, VersionRegistry)
* result - if successful the RKEY of the specified sub-key
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetKey(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
const char *path, /* relative path of subkey to find */
RKEY *result /* returns RKEY of specified sub-key */
);
/* ---------------------------------------------------------------------
* NR_RegGetKeyRaw - Get the RKEY value of a node from its keyname
*
* Parameters:
* hReg - handle of open registry
* key - starting node RKEY, typically one of the standard ones.
* keyname - keyname of key to find. (a blank keyname just gives you
* the starting key--useful for verification, VersionRegistry)
* result - if successful the RKEY of the specified sub-key
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetKeyRaw(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
char *keyname, /* name of key to get */
RKEY *result /* returns RKEY of specified sub-key */
);
/* ---------------------------------------------------------------------
* NR_RegEnumSubkeys - Enumerate the subkey names for the specified key
*
* Returns REGERR_NOMORE at end of enumeration.
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key to enumerate--obtain with NR_RegGetKey()
* eState - enumerations state, must contain NULL to start
* buffer - location to store subkey names. Once an enumeration
* is started user must not modify contents since values
* are built using the previous contents.
* bufsize - size of buffer for names
* style - 0 returns direct child keys only, REGENUM_DESCEND
* returns entire sub-tree
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegEnumSubkeys(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
REGENUM *state, /* enum state, must be NULL to start */
char *buffer, /* buffer for entry names */
uint32 bufsize, /* size of buffer */
uint32 style /* 0: children only; REGENUM_DESCEND: sub-tree */
);
/* ---------------------------------------------------------------------
* Registry API -- Entry Management functions
* ---------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------
* NR_RegGetEntryInfo - Get some basic info about the entry data
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* name - name of entry
* info - return: Entry info object
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetEntryInfo(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
char *name, /* entry name */
REGINFO *info /* returned entry info */
);
/* ---------------------------------------------------------------------
* NR_RegGetEntryString - Get the UTF string value associated with the
* named entry of the specified key.
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* name - name of entry
* buffer - destination for string
* bufsize - size of buffer
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetEntryString(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
const char *name, /* entry name */
char *buffer, /* buffer to hold value (UTF String) */
uint32 bufsize /* length of buffer */
);
/* ---------------------------------------------------------------------
* NR_RegGetEntry - Get the value data associated with the
* named entry of the specified key.
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* name - name of entry
* buffer - destination for data
* size - in: size of buffer
* out: size of actual data (incl. \0 term. for strings)
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetEntry(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
char *name, /* entry name */
void *buffer, /* buffer to hold value */
uint32 *size /* in:length of buffer */
); /* out: data length, >>includes<< null terminator*/
/* ---------------------------------------------------------------------
* NR_RegSetEntryString - Store a UTF-8 string value associated with the
* named entry of the specified key. Used for
* both creation and update.
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* name - name of entry
* buffer - UTF-8 String to store
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegSetEntryString(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
char *name, /* entry name */
char *buffer /* UTF String value */
);
/* ---------------------------------------------------------------------
* NR_RegSetEntry - Store value data associated with the named entry
* of the specified key. Used for both creation and update.
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* name - name of entry
* type - type of data to be stored
* buffer - data to store
* size - length of data to store in bytes
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegSetEntry(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
char *name, /* entry name */
uint16 type, /* type of value data */
void *buffer, /* data buffer */
uint32 size /* data length in bytes; incl. null term for strings */
);
/* ---------------------------------------------------------------------
* NR_RegDeleteEntry - Delete the named entry
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* name - name of entry
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegDeleteEntry(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
char *name /* value name */
);
/* ---------------------------------------------------------------------
* NR_RegEnumEntries - Enumerate the entry names for the specified key
*
* Returns REGERR_NOMORE at end of enumeration.
*
* Parameters:
* hReg - handle of open registry
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
* eState - enumerations state, must contain NULL to start
* buffer - location to store entry names
* bufsize - size of buffer for names
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegEnumEntries(
HREG hReg, /* handle of open registry */
RKEY key, /* containing key */
REGENUM *state, /* enum state, must be NULL to start */
char *buffer, /* buffer for entry names */
uint32 bufsize, /* size of buffer */
REGINFO *info /* optional; returns info about entry */
);
VR_INTERFACE(void) NR_ShutdownRegistry(void);
VR_INTERFACE(REGERR) NR_StartupRegistry(void);
PR_END_EXTERN_C
#endif /* _NSREG_H_ */
/* EOF: NSReg.h */

Просмотреть файл

@ -0,0 +1,105 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/* VerReg.h
* XP Version Registry functions
*/
#ifndef _VERREG_H_
#define _VERREG_H_
#include "NSReg.h"
typedef struct _version
{
int32 major;
int32 minor;
int32 release;
int32 build;
int32 check;
} VERSION;
/* CreateRegistry flags */
#define CR_NEWREGISTRY 1
PR_BEGIN_EXTERN_C
/* ---------------------------------------------------------------------
* Version Registry Operations
* ---------------------------------------------------------------------
*/
/* global registry operations */
/* VR_CreateRegistry is available only in the STANDALONE_REGISTRY builds */
VR_INTERFACE(REGERR) VR_CreateRegistry(char *installation, char *programPath, char *versionStr);
VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path);
VR_INTERFACE(REGERR) VR_PackRegistry(void *userData, nr_RegPackCallbackFunc pdCallbackFunction);
VR_INTERFACE(REGERR) VR_Close(void);
/* component-level functions */
VR_INTERFACE(REGERR) VR_Install(char *component_path, char *filepath, char *version, int bDirectory);
VR_INTERFACE(REGERR) VR_Remove(char *component_path);
VR_INTERFACE(REGERR) VR_InRegistry(char *path);
VR_INTERFACE(REGERR) VR_ValidateComponent(char *path);
VR_INTERFACE(REGERR) VR_Enum(char *component_path, REGENUM *state, char *buffer, uint32 buflen);
/* dealing with parts of individual components */
VR_INTERFACE(REGERR) VR_GetVersion(char *component_path, VERSION *result);
VR_INTERFACE(REGERR) VR_GetPath(char *component_path, uint32 sizebuf, char *buf);
VR_INTERFACE(REGERR) VR_SetRefCount(char *component_path, int refcount);
VR_INTERFACE(REGERR) VR_GetRefCount(char *component_path, int *result);
VR_INTERFACE(REGERR) VR_GetDefaultDirectory(char *component_path, uint32 sizebuf, char *buf);
VR_INTERFACE(REGERR) VR_SetDefaultDirectory(char *component_path, char *directory);
/* uninstall functions */
VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPackageName);
VR_INTERFACE(REGERR) VR_UninstallAddFileToList(char *regPackageName, char *vrName);
VR_INTERFACE(REGERR) VR_UninstallFileExistsInList(char *regPackageName, char *vrName);
VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM *state, char *buffer, uint32 buflen);
VR_INTERFACE(REGERR) VR_UninstallDeleteFileFromList(char *component_path, char *vrName);
VR_INTERFACE(REGERR) VR_UninstallDeleteSharedFilesKey(char *regPackageName);
VR_INTERFACE(REGERR) VR_UninstallDestroy(char *regPackageName);
VR_INTERFACE(REGERR) VR_EnumUninstall(REGENUM *state, char* userPackageName,
int32 len1, char*regPackageName, int32 len2, XP_Bool bSharedList);
VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, uint32 buflen);
PR_END_EXTERN_C
#endif /* _VERREG_H_ */
/* EOF: VerReg.h */

Просмотреть файл

@ -0,0 +1,82 @@
#
# ***** 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
# http://www.mozilla.org/MPL/
#
# 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 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(srcdir)/objs.mk
MODULE = libreg
LIBRARY_NAME = mozreg_s
DIST_INSTALL = 1
CSRCS = $(MODULES_LIBREG_SRC_LCSRCS) nr_bufio.c
BIN_SRCS = VerReg.c reg.c vr_stubs.c
PROGOBJS = $(addprefix R_,$(BIN_SRCS:.c=.o))
# We don't want a shared lib. Static lib only.
FORCE_STATIC_LIB = 1
# Force use of PIC
FORCE_USE_PIC = 1
# We do want this in the static libraries list
EXPORT_LIBRARY = 1
USE_STATIC_LIBS = 1
SDK_LIBRARY = $(LIBRARY)
include $(topsrcdir)/config/config.mk
DEFINES += -DUSE_BUFFERED_REGISTRY_IO
include $(topsrcdir)/config/rules.mk
R_%.o: %.c
$(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) -DSTANDALONE_REGISTRY $<
ifdef _MSC_VER
# Don't include directives about which CRT to use
OS_COMPILE_CXXFLAGS += -Zl
OS_COMPILE_CFLAGS += -Zl
DEFINES += -D_USE_ANSI_CPP
endif

1766
modules/libreg/src/VerReg.c Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,758 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Edward Kandrot <kandrot@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/*------------------------------------------------------------------------
* nr_bufio
*
* Buffered I/O routines to improve registry performance
* the routines mirror fopen(), fclose() et al
*
* Inspired by the performance gains James L. Nance <jim_nance@yahoo.com>
* got using NSPR memory-mapped I/O for the registry. Unfortunately NSPR
* doesn't support mmapio on the Mac.
*-----------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#if defined(XP_MACOSX)
#include <Carbon/Carbon.h>
#endif
#if defined(SUNOS4)
#include <unistd.h> /* for SEEK_SET */
#endif /* SUNOS4 */
#include "prerror.h"
#include "prlog.h"
#include "vr_stubs.h"
#include "nr_bufio.h"
#define BUFIO_BUFSIZE_DEFAULT 0x2000
#define STARTS_IN_BUF(f) ((f->fpos >= f->datastart) && \
(f->fpos < (f->datastart+f->datasize)))
#define ENDS_IN_BUF(f,c) (((f->fpos + c) > (PRUint32)f->datastart) && \
((f->fpos + c) <= (PRUint32)(f->datastart+f->datasize)))
#if DEBUG_dougt
static num_reads = 0;
#endif
struct BufioFileStruct
{
FILE *fd; /* real file descriptor */
PRInt32 fsize; /* total size of file */
PRInt32 fpos; /* our logical position in the file */
PRInt32 datastart; /* the file position at which the buffer starts */
PRInt32 datasize; /* the amount of data actually in the buffer*/
PRInt32 bufsize; /* size of the in memory buffer */
PRBool bufdirty; /* whether the buffer been written to */
PRInt32 dirtystart;
PRInt32 dirtyend;
PRBool readOnly; /* whether the file allows writing or not */
#ifdef DEBUG_dveditzbuf
PRUint32 reads;
PRUint32 writes;
#endif
char *data; /* the data buffer */
};
static PRBool _bufio_loadBuf( BufioFile* file, PRUint32 count );
static int _bufio_flushBuf( BufioFile* file );
#ifdef XP_OS2
#include <fcntl.h>
#include <sys/stat.h>
#include <share.h>
#include <io.h>
FILE* os2_fileopen(const char* name, const char* mode)
{
int access = O_RDWR;
int descriptor;
int pmode = 0;
/* Fail if only one character is passed in - this shouldn't happen */
if (mode[1] == '\0') {
return NULL;
}
/* Only possible options are wb+, rb+, wb and rb */
if (mode[0] == 'w' && mode[1] == 'b') {
access |= (O_TRUNC | O_CREAT);
if (mode[2] == '+') {
access |= O_RDWR;
pmode = S_IREAD | S_IWRITE;
} else {
access |= O_WRONLY;
pmode = S_IWRITE;
}
}
if (mode[0] == 'r' && mode[1] == 'b') {
if (mode[2] == '+') {
access |= O_RDWR;
pmode = S_IREAD | S_IWRITE;
} else {
access = O_RDONLY;
pmode = S_IREAD;
}
}
descriptor = sopen(name, access, SH_DENYNO, pmode);
if (descriptor != -1) {
return fdopen(descriptor, mode);
}
return NULL;
}
#endif
/**
* like fopen() this routine takes *native* filenames, not NSPR names.
*/
BufioFile* bufio_Open(const char* name, const char* mode)
{
FILE *fd;
BufioFile *file = NULL;
#ifdef XP_OS2
fd = os2_fileopen( name, mode );
#else
fd = fopen( name, mode );
#endif
if ( fd )
{
/* file opened successfully, initialize the bufio structure */
file = PR_NEWZAP( BufioFile );
if ( file )
{
file->fd = fd;
file->bufsize = BUFIO_BUFSIZE_DEFAULT; /* set the default buffer size */
file->data = (char*)PR_Malloc( file->bufsize );
if ( file->data )
{
/* get file size to finish initialization of bufio */
if ( !fseek( fd, 0, SEEK_END ) )
{
file->fsize = ftell( fd );
file->readOnly = strcmp(mode,XP_FILE_READ) == 0 ||
strcmp(mode,XP_FILE_READ_BIN) == 0;
}
else
{
PR_Free( file->data );
PR_DELETE( file );
}
}
else
PR_DELETE( file );
}
/* close file if we couldn't create BufioFile */
if (!file)
{
fclose( fd );
PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 );
}
}
else
{
/* couldn't open file. Figure out why and set NSPR errors */
switch (errno)
{
/* file not found */
#if defined(XP_MACOSX)
case fnfErr:
#else
case ENOENT:
#endif
PR_SetError(PR_FILE_NOT_FOUND_ERROR,0);
break;
/* file in use */
#if defined(XP_MACOSX)
case opWrErr:
#else
case EACCES:
#endif
PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR,0);
break;
default:
PR_SetError(PR_UNKNOWN_ERROR,0);
break;
}
}
return file;
}
/**
* close the buffered file and destroy BufioFile struct
*/
int bufio_Close(BufioFile* file)
{
int retval = -1;
if ( file )
{
if ( file->bufdirty )
_bufio_flushBuf( file );
retval = fclose( file->fd );
if ( file->data )
PR_Free( file->data );
PR_DELETE( file );
#if DEBUG_dougt
printf(" --- > Buffered registry read fs hits (%d)\n", num_reads);
#endif
}
return retval;
}
/**
* change the logical position in the file. Equivalent to fseek()
*/
int bufio_Seek(BufioFile* file, PRInt32 offset, int whence)
{
if (!file)
return -1;
switch(whence)
{
case SEEK_SET:
file->fpos = offset;
break;
case SEEK_END:
file->fpos = file->fsize + offset;
break;
case SEEK_CUR:
file->fpos = file->fpos + offset;
break;
default:
return -1;
}
if ( file->fpos < 0 )
file->fpos = 0;
return 0;
}
/**
* like ftell() returns the current position in the file, or -1 for error
*/
PRInt32 bufio_Tell(BufioFile* file)
{
if (file)
return file->fpos;
else
return -1;
}
PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count)
{
PRInt32 startOffset;
PRInt32 endOffset;
PRInt32 leftover;
PRUint32 bytesCopied;
PRUint32 bytesRead;
PRUint32 retcount = 0;
/* sanity check arguments */
if ( !file || !dest || count == 0 || file->fpos >= file->fsize )
return 0;
/* Adjust amount to read if we're near EOF */
if ( (file->fpos + count) > (PRUint32)file->fsize )
count = file->fsize - file->fpos;
/* figure out how much of the data we want is already buffered */
startOffset = file->fpos - file->datastart;
endOffset = startOffset + count;
if ( startOffset >= 0 && startOffset < file->datasize )
{
/* The beginning of what we want is in the buffer */
/* so copy as much as is available of what we want */
if ( endOffset <= file->datasize )
bytesCopied = count;
else
bytesCopied = file->datasize - startOffset;
memcpy( dest, file->data + startOffset, bytesCopied );
retcount = bytesCopied;
file->fpos += bytesCopied;
#ifdef DEBUG_dveditzbuf
file->reads++;
#endif
/* Was that all we wanted, or do we need to get more? */
leftover = count - bytesCopied;
PR_ASSERT( leftover >= 0 ); /* negative left? something's wrong! */
if ( leftover )
{
/* need data that's not in the buffer */
/* if what's left fits in a buffer then load the buffer with the */
/* new area before giving the data, otherwise just read right */
/* into the user's dest buffer */
if ( _bufio_loadBuf( file, leftover ) )
{
startOffset = file->fpos - file->datastart;
/* we may not have been able to load as much as we wanted */
if ( startOffset > file->datasize )
bytesRead = 0;
else if ( startOffset+leftover <= file->datasize )
bytesRead = leftover;
else
bytesRead = file->datasize - startOffset;
if ( bytesRead )
{
memcpy( dest+bytesCopied, file->data+startOffset, bytesRead );
file->fpos += bytesRead;
retcount += bytesRead;
#ifdef DEBUG_dveditzbuf
file->reads++;
#endif
}
}
else
{
/* we need more than we could load into a buffer, so */
/* skip buffering and just read the data directly */
if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )
{
#if DEBUG_dougt
++num_reads;
#endif
bytesRead = fread(dest+bytesCopied, 1, leftover, file->fd);
file->fpos += bytesRead;
retcount += bytesRead;
}
else
{
/* XXX seek failed, couldn't load more data -- help! */
/* should we call PR_SetError() ? */
}
}
}
}
else
{
/* range doesn't start in the loaded buffer but it might end there */
if ( endOffset > 0 && endOffset <= file->datasize )
bytesCopied = endOffset;
else
bytesCopied = 0;
leftover = count - bytesCopied;
if ( bytesCopied )
{
/* the tail end of the range we want is already buffered */
/* first copy the buffered data to the dest area */
memcpy( dest+leftover, file->data, bytesCopied );
#ifdef DEBUG_dveditzbuf
file->reads++;
#endif
}
/* now pick up the part that's not already in the buffer */
if ( _bufio_loadBuf( file, leftover ) )
{
/* we were able to load some data */
startOffset = file->fpos - file->datastart;
/* we may not have been able to read as much as we wanted */
if ( startOffset > file->datasize )
bytesRead = 0;
else if ( startOffset+leftover <= file->datasize )
bytesRead = leftover;
else
bytesRead = file->datasize - startOffset;
if ( bytesRead )
{
memcpy( dest, file->data+startOffset, bytesRead );
#ifdef DEBUG_dveditzbuf
file->reads++;
#endif
}
}
else
{
/* leftover data doesn't fit so skip buffering */
if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )
{
bytesRead = fread(dest, 1, leftover, file->fd);
#if DEBUG_dougt
++num_reads;
#endif
}
else
bytesRead = 0;
}
/* if we couldn't read all the leftover, don't tell caller */
/* about the tail end we copied from the first buffer */
if ( bytesRead == (PRUint32)leftover )
retcount = bytesCopied + bytesRead;
else
retcount = bytesRead;
file->fpos += retcount;
}
return retcount;
}
/**
* Buffered writes
*/
PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count)
{
const char* newsrc;
PRInt32 startOffset;
PRInt32 endOffset;
PRUint32 leftover;
PRUint32 retcount = 0;
PRUint32 bytesWritten = 0;
PRUint32 bytesCopied = 0;
/* sanity check arguments */
if ( !file || !src || count == 0 || file->readOnly )
return 0;
/* Write to the current buffer if we can, otherwise load a new buffer */
startOffset = file->fpos - file->datastart;
endOffset = startOffset + count;
if ( startOffset >= 0 && startOffset < file->bufsize )
{
/* the area we want to write starts in the buffer */
if ( endOffset <= file->bufsize )
bytesCopied = count;
else
bytesCopied = file->bufsize - startOffset;
memcpy( file->data + startOffset, src, bytesCopied );
file->bufdirty = PR_TRUE;
endOffset = startOffset + bytesCopied;
file->dirtystart = PR_MIN( startOffset, file->dirtystart );
file->dirtyend = PR_MAX( endOffset, file->dirtyend );
#ifdef DEBUG_dveditzbuf
file->writes++;
#endif
if ( endOffset > file->datasize )
file->datasize = endOffset;
retcount = bytesCopied;
file->fpos += bytesCopied;
/* was that all we had to write, or is there more? */
leftover = count - bytesCopied;
newsrc = src+bytesCopied;
}
else
{
/* range doesn't start in the loaded buffer but it might end there */
if ( endOffset > 0 && endOffset <= file->bufsize )
bytesCopied = endOffset;
else
bytesCopied = 0;
leftover = count - bytesCopied;
newsrc = src;
if ( bytesCopied )
{
/* the tail end of the write range is already in the buffer */
memcpy( file->data, src+leftover, bytesCopied );
file->bufdirty = PR_TRUE;
file->dirtystart = 0;
file->dirtyend = PR_MAX( endOffset, file->dirtyend );
#ifdef DEBUG_dveditzbuf
file->writes++;
#endif
if ( endOffset > file->datasize )
file->datasize = endOffset;
}
}
/* if we only wrote part of the request pick up the leftovers */
if ( leftover )
{
/* load the buffer with the new range, if possible */
if ( _bufio_loadBuf( file, leftover ) )
{
startOffset = file->fpos - file->datastart;
endOffset = startOffset + leftover;
memcpy( file->data+startOffset, newsrc, leftover );
file->bufdirty = PR_TRUE;
file->dirtystart = startOffset;
file->dirtyend = endOffset;
#ifdef DEBUG_dveditzbuf
file->writes++;
#endif
if ( endOffset > file->datasize )
file->datasize = endOffset;
bytesWritten = leftover;
}
else
{
/* request didn't fit in a buffer, write directly */
if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )
bytesWritten = fwrite( newsrc, 1, leftover, file->fd );
else
bytesWritten = 0; /* seek failed! */
}
if ( retcount )
{
/* we already counted the first part we wrote */
retcount += bytesWritten;
file->fpos += bytesWritten;
}
else
{
retcount = bytesCopied + bytesWritten;
file->fpos += retcount;
}
}
if ( file->fpos > file->fsize )
file->fsize = file->fpos;
return retcount;
}
int bufio_Flush(BufioFile* file)
{
if ( file->bufdirty )
_bufio_flushBuf( file );
return fflush(file->fd);
}
/*---------------------------------------------------------------------------*
* internal helper functions
*---------------------------------------------------------------------------*/
/**
* Attempts to load the buffer with the requested amount of data.
* Returns PR_TRUE if it was able to load *some* of the requested
* data, but not necessarily all. Returns PR_FALSE if the read fails
* or if the requested amount wouldn't fit in the buffer.
*/
static PRBool _bufio_loadBuf( BufioFile* file, PRUint32 count )
{
PRInt32 startBuf;
PRInt32 endPos;
PRInt32 endBuf;
PRUint32 bytesRead;
/* no point in buffering more than the physical buffer will hold */
if ( count > (PRUint32)file->bufsize )
return PR_FALSE;
/* Is caller asking for data we already have? */
if ( STARTS_IN_BUF(file) && ENDS_IN_BUF(file,count) )
{
PR_ASSERT(0);
return PR_TRUE;
}
/* if the buffer's dirty make sure we successfully flush it */
if ( file->bufdirty && _bufio_flushBuf(file) != 0 )
return PR_FALSE;
/* For now we're not trying anything smarter than simple paging. */
/* Slide over if necessary to fit the entire request */
startBuf = ( file->fpos / file->bufsize ) * file->bufsize;
endPos = file->fpos + count;
endBuf = startBuf + file->bufsize;
if ( endPos > endBuf )
startBuf += (endPos - endBuf);
if ( fseek( file->fd, startBuf, SEEK_SET ) != 0 )
return PR_FALSE;
else
{
#if DEBUG_dougt
++num_reads;
#endif
bytesRead = fread( file->data, 1, file->bufsize, file->fd );
file->datastart = startBuf;
file->datasize = bytesRead;
file->bufdirty = PR_FALSE;
file->dirtystart = file->bufsize;
file->dirtyend = 0;
#ifdef DEBUG_dveditzbuf
printf("REG: buffer read %d (%d) after %d reads\n",startBuf,file->fpos,file->reads);
file->reads = 0;
file->writes = 0;
#endif
return PR_TRUE;
}
}
static int _bufio_flushBuf( BufioFile* file )
{
PRUint32 written;
PRUint32 dirtyamt;
PRInt32 startpos;
PR_ASSERT(file);
if ( !file || !file->bufdirty )
return 0;
startpos = file->datastart + file->dirtystart;
if ( !fseek( file->fd, startpos, SEEK_SET ) )
{
dirtyamt = file->dirtyend - file->dirtystart;
written = fwrite( file->data+file->dirtystart, 1, dirtyamt, file->fd );
if ( written == dirtyamt )
{
#ifdef DEBUG_dveditzbuf
printf("REG: buffer flush %d - %d after %d writes\n",startpos,startpos+written,file->writes);
file->writes = 0;
#endif
file->bufdirty = PR_FALSE;
file->dirtystart = file->bufsize;
file->dirtyend = 0;
return 0;
}
}
return -1;
}
/*
* sets the file buffer size to bufsize, clearing the buffer in the process.
*
* accepts bufsize of -1 to mean default buffer size, defined by BUFIO_BUFSIZE_DEFAULT
* returns new buffers size, or -1 if error occurred
*/
int bufio_SetBufferSize(BufioFile* file, int bufsize)
{
char *newBuffer;
int retVal = -1;
PR_ASSERT(file);
if (!file)
return retVal;
if (bufsize == -1)
bufsize = BUFIO_BUFSIZE_DEFAULT;
if (bufsize == file->bufsize)
return bufsize;
newBuffer = (char*)PR_Malloc( bufsize );
if (newBuffer)
{
/* if the buffer's dirty make sure we successfully flush it */
if ( file->bufdirty && _bufio_flushBuf(file) != 0 )
{
PR_Free( newBuffer );
return -1;
}
file->bufsize = bufsize;
if ( file->data )
PR_Free( file->data );
file->data = newBuffer;
file->datasize = 0;
file->datastart = 0;
retVal = bufsize;
}
return retVal;
}
/* EOF nr_bufio.c */

Просмотреть файл

@ -0,0 +1,64 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Edward Kandrot <kandrot@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/* nr_bufio.h
* Buffered I/O routines to improve registry performance
*
* the routines mirror fopen(), fclose() et al
*
* __NOTE__: the filenames are *native* filenames, not NSPR names.
*/
#ifndef _NR_BUFIO_H_
#define _NR_BUFIO_H_
typedef struct BufioFileStruct BufioFile;
BufioFile* bufio_Open(const char* name, const char* mode);
int bufio_Close(BufioFile* file);
int bufio_Seek(BufioFile* file, PRInt32 offset, int whence);
PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count);
PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count);
PRInt32 bufio_Tell(BufioFile* file);
int bufio_Flush(BufioFile* file);
int bufio_SetBufferSize(BufioFile* file, int bufsize);
#endif /* _NR_BUFIO_H_ */

Просмотреть файл

@ -0,0 +1,47 @@
#
# ***** 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
# http://www.mozilla.org/MPL/
#
# 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) 2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either 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 *****
MODULES_LIBREG_SRC_LCSRCS = \
reg.c \
VerReg.c \
vr_stubs.c \
$(NULL)
MODULES_LIBREG_SRC_CSRCS := $(addprefix $(topsrcdir)/modules/libreg/src/, $(MODULES_LIBREG_SRC_LCSRCS))

3920
modules/libreg/src/reg.c Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

196
modules/libreg/src/reg.h Normal file
Просмотреть файл

@ -0,0 +1,196 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/* reg.h
* XP Registry functions (prototype)
*/
#ifndef _REG_H_
#define _REG_H_
#include "vr_stubs.h"
#ifndef STANDALONE_REGISTRY
#include "prlock.h"
#endif
/* --------------------------------------------------------------------
* Miscellaneous Definitions
* --------------------------------------------------------------------
*/
#define MAGIC_NUMBER 0x76644441L
#define MAJOR_VERSION 2 /* major version for incompatible changes */
#define MINOR_VERSION 2 /* minor ver for new (compatible) features */
#define PATHDEL '/'
#define HDRRESERVE 128 /* number of bytes reserved for hdr */
#define INTSIZE 4
#define DOUBLESIZE 8
#define PACKBUFFERSIZE 2048
/* Node types */
#define REGTYPE_KEY (1)
#define REGTYPE_DELETED (0x0080)
/* Private standard keys */
#define ROOTKEY (0x20)
#define ROOTKEY_VERSIONS (0x21)
/* strings for standard keys */
#define ROOTKEY_STR "/"
#define ROOTKEY_VERSIONS_STR "Version Registry"
#define ROOTKEY_USERS_STR "Users"
#define ROOTKEY_COMMON_STR "Common"
#define ROOTKEY_PRIVATE_STR "Private Arenas"
#define OLD_VERSIONS_STR "ROOTKEY_VERSIONS"
#define OLD_USERS_STR "ROOTKEY_USERS"
#define OLD_COMMON_STR "ROOTKEY_COMMON"
/* needs to be kept in sync with PE. see ns/cmd/winfe/profile.h */
/* and ns/cmd/macfe/central/profile.cp */
#define ASW_MAGIC_PROFILE_NAME "User1"
/* macros */
#define COPYDESC(dest,src) memcpy((dest),(src),sizeof(REGDESC))
#define VALID_FILEHANDLE(fh) ((fh) != NULL)
#define INVALID_NAME_CHAR(p) ( ((unsigned char)(p) < 0x20) )
#define TYPE_IS_ENTRY(type) ( (type) & REGTYPE_ENTRY )
#define TYPE_IS_KEY(type) ( !((type) & REGTYPE_ENTRY) )
#define VERIFY_HREG(h)\
( ((h) == NULL) ? REGERR_PARAM : \
( (((REGHANDLE*)(h))->magic == MAGIC_NUMBER) ? REGERR_OK : REGERR_BADMAGIC ) )
/* --------------------------------------------------------------------
* Types and Objects
* --------------------------------------------------------------------
*/
#undef REGOFF
typedef int32 REGOFF; /* offset into registry file */
typedef struct _desc
{
REGOFF location; /* this object's offset (for verification) */
REGOFF name; /* name string */
uint16 namelen; /* length of name string (including terminator) */
uint16 type; /* node type (key, or entry style) */
REGOFF left; /* next object at this level (0 if none) */
REGOFF down; /* KEY: first subkey VALUE: 0 */
REGOFF value; /* KEY: first entry object VALUE: value string */
uint32 valuelen; /* KEY: 0 VALUE: length of value data */
uint32 valuebuf; /* KEY: 0 VALUE: length available */
REGOFF parent; /* the node on the immediate level above */
} REGDESC;
/* offsets into structure on disk */
#define DESC_LOCATION 0
#define DESC_NAME 4
#define DESC_NAMELEN 8
#define DESC_TYPE 10
#define DESC_LEFT 12
#define DESC_DOWN 16
#define DESC_VALUE 20
#define DESC_VALUELEN 24
#define DESC_VALUEBUF 16 /* stored in place of "down" for entries */
#define DESC_PARENT 28
#define DESC_SIZE 32 /* size of desc on disk */
typedef struct _hdr
{
uint32 magic; /* must equal MAGIC_NUMBER */
uint16 verMajor; /* major version number */
uint16 verMinor; /* minor version number */
REGOFF avail; /* next available offset */
REGOFF root; /* root object */
} REGHDR;
/* offsets into structure on disk*/
#define HDR_MAGIC 0
#define HDR_VERMAJOR 4
#define HDR_VERMINOR 6
#define HDR_AVAIL 8
#define HDR_ROOT 12
typedef XP_File FILEHANDLE; /* platform-specific file reference */
typedef struct _stdnodes {
REGOFF versions;
REGOFF users;
REGOFF common;
REGOFF current_user;
REGOFF privarea;
} STDNODES;
typedef struct _regfile
{
FILEHANDLE fh;
REGHDR hdr;
int refCount;
int hdrDirty;
int inInit;
int readOnly;
char * filename;
STDNODES rkeys;
struct _regfile *next;
struct _regfile *prev;
#ifndef STANDALONE_REGISTRY
PRLock *lock;
PRUint64 uniqkey;
#endif
} REGFILE;
typedef struct _reghandle
{
uint32 magic; /* for validating reg handles */
REGFILE *pReg; /* the real registry file object */
} REGHANDLE;
#endif /* _REG_H_ */
/* EOF: reg.h */

Просмотреть файл

@ -0,0 +1,507 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* 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 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 ***** */
/* this file contains stubs needed to build the registry routines
* into a stand-alone library for use with our installers
*/
#ifdef STANDALONE_REGISTRY
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#else
#include "prtypes.h"
#include "plstr.h"
#endif /*STANDALONE_REGISTRY*/
#include "vr_stubs.h"
#ifdef XP_MACOSX
#include <Carbon/Carbon.h>
#include <stdlib.h>
#endif
#ifdef XP_BEOS
#include <FindDirectory.h>
#endif
#ifdef XP_MACOSX
/* So that we're not dependent on the size of chars in a wide string literal */
static const UniChar kOSXRegParentName[] =
{ 'M', 'o', 'z', 'i', 'l', 'l', 'a' };
static const UniChar kOSXRegName[] =
{ 'G', 'l', 'o', 'b', 'a', 'l', '.', 'r', 'e', 'g', 's' };
static const UniChar kOSXVersRegName[] =
{ 'V', 'e', 'r', 's', 'i', 'o', 'n', 's', '.', 'r', 'e', 'g', 's' };
#define UNICHAR_ARRAY_LEN(s) (sizeof(s) / sizeof(UniChar))
#endif
#define DEF_REG "/.mozilla/registry"
#define WIN_REG "\\mozregistry.dat"
#define MAC_REG "\pMozilla Registry"
#define BEOS_REG "/mozilla/registry"
#define DEF_VERREG "/.mozilla/mozver.dat"
#define WIN_VERREG "\\mozver.dat"
#define MAC_VERREG "\pMozilla Versions"
#define BEOS_VERREG "/mozilla/mozver.dat"
/* ------------------------------------------------------------------
* OS/2 STUBS
* ------------------------------------------------------------------
*/
#ifdef XP_OS2
#define INCL_DOS
#include <os2.h>
#ifdef STANDALONE_REGISTRY
extern XP_File vr_fileOpen (const char *name, const char * mode)
{
XP_File fh = NULL;
struct stat st;
if ( name != NULL ) {
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
}
#endif /*STANDALONE_REGISTRY*/
extern void vr_findGlobalRegName ()
{
char path[ CCHMAXPATH ];
int pathlen;
XP_File fh = NULL;
struct stat st;
XP_STRCPY(path, ".");
pathlen = strlen(path);
if ( pathlen > 0 ) {
XP_STRCPY( path+pathlen, WIN_REG );
globalRegName = XP_STRDUP(path);
}
}
char* vr_findVerRegName()
{
/* need to find a global place for the version registry */
if ( verRegName == NULL )
{
if ( globalRegName == NULL)
vr_findGlobalRegName();
verRegName = XP_STRDUP(globalRegName);
}
return verRegName;
}
#endif /* XP_OS2 */
/* ------------------------------------------------------------------
* WINDOWS STUBS
* ------------------------------------------------------------------
*/
#if defined(XP_WIN)
#include "windows.h"
#define PATHLEN 260
#ifdef STANDALONE_REGISTRY
extern XP_File vr_fileOpen (const char *name, const char * mode)
{
XP_File fh = NULL;
struct stat st;
if ( name != NULL ) {
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
}
#endif /*STANDALONE_REGISTRY*/
extern void vr_findGlobalRegName ()
{
char path[ PATHLEN ];
int pathlen;
pathlen = GetWindowsDirectory(path, PATHLEN);
if ( pathlen > 0 ) {
XP_FREEIF(globalRegName);
XP_STRCPY( path+pathlen, WIN_REG );
globalRegName = XP_STRDUP(path);
}
}
char* vr_findVerRegName()
{
char path[ PATHLEN ];
int pathlen;
if ( verRegName == NULL )
{
pathlen = GetWindowsDirectory(path, PATHLEN);
if ( pathlen > 0 ) {
XP_STRCPY( path+pathlen, WIN_VERREG );
verRegName = XP_STRDUP(path);
}
}
return verRegName;
}
#if !defined(WIN32) && !defined(__BORLANDC__)
int FAR PASCAL _export WEP(int);
int FAR PASCAL LibMain(HANDLE hInst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
{
if ( wHeapSize > 0 )
UnlockData(0);
return 1;
}
int FAR PASCAL _export WEP(int nParam)
{
return 1;
}
#endif /* not WIN32 */
#endif /* XP_WIN */
/* ------------------------------------------------------------------
* MACINTOSH STUBS
* ------------------------------------------------------------------
*/
#if defined(XP_MACOSX)
#ifdef STANDALONE_REGISTRY
extern XP_File vr_fileOpen(const char *name, const char * mode)
{
XP_File fh = NULL;
struct stat st;
errno = 0; /* reset errno (only if we're using stdio) */
if ( name != NULL ) {
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
{
/* should never get here! */
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
}
return fh;
}
#endif /*STANDALONE_REGISTRY*/
extern void vr_findGlobalRegName()
{
OSErr err;
FSRef foundRef;
err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
if (err == noErr)
{
FSRef parentRef;
err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
kTextEncodingUnknown, &parentRef);
if (err == fnfErr)
{
err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
}
if (err == noErr)
{
FSRef regRef;
err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
kTextEncodingUnknown, &regRef);
if (err == fnfErr)
{
FSCatalogInfo catalogInfo;
FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
}
if (err == noErr)
{
UInt8 pathBuf[PATH_MAX];
err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
if (err == noErr)
globalRegName = XP_STRDUP((const char*)pathBuf);
}
}
}
}
extern char* vr_findVerRegName()
{
OSErr err;
FSRef foundRef;
err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
if (err == noErr)
{
FSRef parentRef;
err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
kTextEncodingUnknown, &parentRef);
if (err == fnfErr)
{
err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
}
if (err == noErr)
{
FSRef regRef;
err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
kTextEncodingUnknown, &regRef);
if (err == fnfErr)
{
FSCatalogInfo catalogInfo;
FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
}
if (err == noErr)
{
UInt8 pathBuf[PATH_MAX];
err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
if (err == noErr)
verRegName = XP_STRDUP((const char*)pathBuf);
}
}
}
return verRegName;
}
#endif /* XP_MACOSX */
/* ------------------------------------------------------------------
* UNIX STUBS
* ------------------------------------------------------------------
*/
#if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
#include <stdlib.h>
#ifdef XP_OS2
#include <io.h>
#define W_OK 0x02 /*evil hack from the docs...*/
#else
#include <unistd.h>
#endif
#include "NSReg.h"
#include "VerReg.h"
char *TheRegistry = "registry";
char *Flist;
REGERR vr_ParseVersion(char *verstr, VERSION *result);
#if defined(XP_UNIX) && !defined(XP_MACOSX)
#ifdef STANDALONE_REGISTRY
extern XP_File vr_fileOpen (const char *name, const char * mode)
{
XP_File fh = NULL;
struct stat st;
if ( name != NULL ) {
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
}
#endif /*STANDALONE_REGISTRY*/
extern void vr_findGlobalRegName ()
{
#ifndef STANDALONE_REGISTRY
char *def = NULL;
char *home = getenv("HOME");
if (home != NULL) {
def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_REG)+1);
if (def != NULL) {
XP_STRCPY(def, home);
XP_STRCAT(def, DEF_REG);
}
}
if (def != NULL) {
globalRegName = XP_STRDUP(def);
} else {
globalRegName = XP_STRDUP(TheRegistry);
}
XP_FREEIF(def);
#else
globalRegName = XP_STRDUP(TheRegistry);
#endif /*STANDALONE_REGISTRY*/
}
char* vr_findVerRegName ()
{
if ( verRegName != NULL )
return verRegName;
#ifndef STANDALONE_REGISTRY
{
char *def = NULL;
char *home = getenv("HOME");
if (home != NULL) {
def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_VERREG)+1);
if (def != NULL) {
XP_STRCPY(def, home);
XP_STRCAT(def, DEF_VERREG);
}
}
if (def != NULL) {
verRegName = XP_STRDUP(def);
}
XP_FREEIF(def);
}
#else
verRegName = XP_STRDUP(TheRegistry);
#endif /*STANDALONE_REGISTRY*/
return verRegName;
}
#endif /*XP_UNIX*/
/* ------------------------------------------------------------------
* BeOS STUBS
* ------------------------------------------------------------------
*/
#ifdef XP_BEOS
#ifdef STANDALONE_REGISTRY
extern XP_File vr_fileOpen (const char *name, const char * mode)
{
XP_File fh = NULL;
struct stat st;
if ( name != NULL ) {
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
}
#endif /*STANDALONE_REGISTRY*/
extern void vr_findGlobalRegName ()
{
#ifndef STANDALONE_REGISTRY
char *def = NULL;
char settings[1024];
find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings));
if (settings != NULL) {
def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_REG)+1);
if (def != NULL) {
XP_STRCPY(def, settings);
XP_STRCAT(def, BEOS_REG);
}
}
if (def != NULL) {
globalRegName = XP_STRDUP(def);
} else {
globalRegName = XP_STRDUP(TheRegistry);
}
XP_FREEIF(def);
#else
globalRegName = XP_STRDUP(TheRegistry);
#endif /*STANDALONE_REGISTRY*/
}
char* vr_findVerRegName ()
{
if ( verRegName != NULL )
return verRegName;
#ifndef STANDALONE_REGISTRY
{
char *def = NULL;
char settings[1024];
find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings));
if (settings != NULL) {
def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_VERREG)+1);
if (def != NULL) {
XP_STRCPY(def, settings);
XP_STRCAT(def, BEOS_VERREG);
}
}
if (def != NULL) {
verRegName = XP_STRDUP(def);
}
XP_FREEIF(def);
}
#else
verRegName = XP_STRDUP(TheRegistry);
#endif /*STANDALONE_REGISTRY*/
return verRegName;
}
#endif /*XP_BEOS*/
#endif /* XP_UNIX || XP_OS2 */

Просмотреть файл

@ -0,0 +1,283 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/* vr_stubs.h
*
* XP code stubs for stand-alone registry library
*
*/
#ifndef _VR_STUBS_H_
#define _VR_STUBS_H_
#ifdef STANDALONE_REGISTRY
#include <errno.h>
#include <string.h>
#else
#include "prio.h"
#include "prlog.h"
#include "prmem.h"
#include "plstr.h"
#endif /* STANDALONE_REGISTRY*/
#if ( defined(BSDI) && !defined(BSDI_2) ) || defined(XP_OS2)
#include <sys/types.h>
#endif
#include <sys/stat.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#if defined(__cplusplus)
# define XP_CPLUSPLUS
# define XP_IS_CPLUSPLUS 1
#else
# define XP_IS_CPLUSPLUS 0
#endif
#if defined(XP_CPLUSPLUS)
# define XP_BEGIN_PROTOS extern "C" {
# define XP_END_PROTOS }
#else
# define XP_BEGIN_PROTOS
# define XP_END_PROTOS
#endif
#ifdef STANDALONE_REGISTRY
#define USE_STDIO_MODES
#define XP_FileSeek(file,offset,whence) fseek((file), (offset), (whence))
#define XP_FileRead(dest,count,file) fread((dest), 1, (count), (file))
#define XP_FileWrite(src,count,file) fwrite((src), 1, (count), (file))
#define XP_FileTell(file) ftell(file)
#define XP_FileFlush(file) fflush(file)
#define XP_FileClose(file) fclose(file)
#define XP_FileSetBufferSize(file,bufsize) (-1)
#define XP_ASSERT(x) ((void)0)
#define XP_STRCAT(a,b) strcat((a),(b))
#define XP_ATOI atoi
#define XP_STRNCPY(a,b,n) strncpy((a),(b),(n))
#define XP_STRCPY(a,b) strcpy((a),(b))
#define XP_STRLEN(x) strlen(x)
#define XP_SPRINTF sprintf
#define XP_FREE(x) free((x))
#define XP_ALLOC(x) malloc((x))
#define XP_FREEIF(x) if ((x)) free((x))
#define XP_STRCMP(x,y) strcmp((x),(y))
#define XP_STRNCMP(x,y,n) strncmp((x),(y),(n))
#define XP_STRDUP(s) strdup((s))
#define XP_MEMCPY(d, s, l) memcpy((d), (s), (l))
#define XP_MEMSET(d, c, l) memset((d), (c), (l))
#define PR_Lock(a) ((void)0)
#define PR_Unlock(a) ((void)0)
#if defined(XP_WIN) || defined(XP_OS2)
#define XP_STRCASECMP(x,y) stricmp((x),(y))
#define XP_STRNCASECMP(x,y,n) strnicmp((x),(y),(n))
#else
#define XP_STRCASECMP(x,y) strcasecmp((x),(y))
#define XP_STRNCASECMP(x,y,n) strncasecmp((x),(y),(n))
#endif /* XP_WIN || XP_OS2 */
typedef FILE * XP_File;
#else /* not standalone, use NSPR */
/*-------------------------------------*/
/* Alternate fileI/O function mappings */
/*-------------------------------------*/
#if USE_BUFFERED_REGISTRY_IO
/*-----------------------------------------------*/
/* home-grown XP buffering */
/* writes are buffered too so use flush! */
/*-----------------------------------------------*/
#define USE_STDIO_MODES
#include "nr_bufio.h"
#define XP_FileSeek(file,offset,whence) bufio_Seek((file),(offset),(whence))
#define XP_FileRead(dest,count,file) bufio_Read((file), (dest), (count))
#define XP_FileWrite(src,count,file) bufio_Write((file), (src), (count))
#define XP_FileTell(file) bufio_Tell(file)
#define XP_FileClose(file) bufio_Close(file)
#define XP_FileOpen(path, mode) bufio_Open((path), (mode))
#define XP_FileFlush(file) bufio_Flush(file)
#define XP_FileSetBufferSize(file,bufsize) bufio_SetBufferSize(file,bufsize)
typedef BufioFile* XP_File;
#else
/*-----------------------------------------------*/
/* standard NSPR file I/O */
/*-----------------------------------------------*/
#define USE_NSPR_MODES
/*
** Note that PR_Seek returns the offset (if successful) and -1 otherwise. So
** to make this code work
** if (XP_FileSeek(fh, offset, SEEK_SET) != 0) { error handling }
** we return 1 if PR_Seek() returns a negative value, and 0 otherwise
*/
#define XP_FileSeek(file,offset,whence) (PR_Seek((file), (offset), (whence)) < 0)
#define XP_FileRead(dest,count,file) PR_Read((file), (dest), (count))
#define XP_FileWrite(src,count,file) PR_Write((file), (src), (count))
#define XP_FileTell(file) PR_Seek(file, 0, PR_SEEK_CUR)
#define XP_FileOpen(path, mode) PR_Open((path), mode )
#define XP_FileClose(file) PR_Close(file)
#define XP_FileFlush(file) PR_Sync(file)
#define XP_FileSetBufferSize(file,bufsize) (-1)
typedef PRFileDesc* XP_File;
#endif /*USE_MMAP_REGISTRY_IO*/
#define XP_ASSERT(x) PR_ASSERT((x))
#define XP_STRCAT(a,b) PL_strcat((a),(b))
#define XP_ATOI PL_atoi
#define XP_STRCPY(a,b) PL_strcpy((a),(b))
#define XP_STRNCPY(a,b,n) PL_strncpy((a),(b),(n))
#define XP_STRLEN(x) PL_strlen(x)
#define XP_SPRINTF sprintf
#define XP_FREE(x) PR_Free((x))
#define XP_ALLOC(x) PR_Malloc((x))
#define XP_FREEIF(x) PR_FREEIF(x)
#define XP_STRCMP(x,y) PL_strcmp((x),(y))
#define XP_STRNCMP(x,y,n) PL_strncmp((x),(y),(n))
#define XP_STRDUP(s) PL_strdup((s))
#define XP_MEMCPY(d, s, l) memcpy((d), (s), (l))
#define XP_MEMSET(d, c, l) memset((d), (c), (l))
#define XP_STRCASECMP(x,y) PL_strcasecmp((x),(y))
#define XP_STRNCASECMP(x,y,n) PL_strncasecmp((x),(y),(n))
#endif /*STANDALONE_REGISTRY*/
/*--- file open modes for stdio ---*/
#ifdef USE_STDIO_MODES
#define XP_FILE_READ "r"
#define XP_FILE_READ_BIN "rb"
#define XP_FILE_WRITE "w"
#define XP_FILE_WRITE_BIN "wb"
#define XP_FILE_UPDATE "r+"
#define XP_FILE_TRUNCATE "w+"
#ifdef SUNOS4
/* XXX SunOS4 hack -- make this universal by using r+b and w+b */
#define XP_FILE_UPDATE_BIN "r+"
#define XP_FILE_TRUNCATE_BIN "w+"
#else
#define XP_FILE_UPDATE_BIN "rb+"
#define XP_FILE_TRUNCATE_BIN "wb+"
#endif
#endif /* USE_STDIO_MODES */
/*--- file open modes for NSPR file I/O ---*/
#ifdef USE_NSPR_MODES
#define XP_FILE_READ PR_RDONLY, 0644
#define XP_FILE_READ_BIN PR_RDONLY, 0644
#define XP_FILE_WRITE PR_WRONLY, 0644
#define XP_FILE_WRITE_BIN PR_WRONLY, 0644
#define XP_FILE_UPDATE (PR_RDWR|PR_CREATE_FILE), 0644
#define XP_FILE_TRUNCATE (PR_RDWR | PR_TRUNCATE), 0644
#define XP_FILE_UPDATE_BIN PR_RDWR|PR_CREATE_FILE, 0644
#define XP_FILE_TRUNCATE_BIN (PR_RDWR | PR_TRUNCATE), 0644
#ifdef SEEK_SET
#undef SEEK_SET
#undef SEEK_CUR
#undef SEEK_END
#define SEEK_SET PR_SEEK_SET
#define SEEK_CUR PR_SEEK_CUR
#define SEEK_END PR_SEEK_END
#endif
#endif /* USE_NSPR_MODES */
#ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
#include "prtypes.h"
#endif /*STANDALONE_REGISTRY*/
typedef int XP_Bool;
typedef struct stat XP_StatStruct;
#define XP_Stat(file,data) stat((file),(data))
XP_BEGIN_PROTOS
#define nr_RenameFile(from, to) rename((from), (to))
extern char* globalRegName;
extern char* verRegName;
extern void vr_findGlobalRegName();
extern char* vr_findVerRegName();
#ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
extern XP_File vr_fileOpen(const char *name, const char * mode);
#else
#define vr_fileOpen PR_Open
#endif /* STANDALONE_REGISTRY */
XP_END_PROTOS
#endif /* _VR_STUBS_H_ */

Просмотреть файл

@ -0,0 +1,293 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* 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 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 ***** */
/* Registry interpreter */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "VerReg.h"
#include "NSReg.h"
extern char *errstr(REGERR err);
extern int DumpTree(void);
int error(char *func, int err)
{
if (err == REGERR_OK)
{
printf("\t%s -- OK\n", func);
}
else
{
printf("\t%s -- %s\n", func, errstr(err));
}
return err;
} /* error */
static char *GetNextWord(char *cmd, char *buf)
{
/* copies until ',' or eos, then skips spaces */
if (!cmd || !buf)
return 0;
while (*cmd && *cmd != ',')
*buf++ = *cmd++;
*buf = '\0';
if (*cmd == ',')
{
cmd++;
while(*cmd && *cmd == ' ')
cmd++;
}
return cmd;
} /* GetNextWord */
static int vr_ParseVersion(char *verstr, VERSION *result)
{
result->major = result->minor = result->release = result->build = 0;
result->major = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
if (*verstr)
{
verstr++;
result->minor = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
if (*verstr)
{
verstr++;
result->release = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
if (*verstr)
{
verstr++;
result->build = atoi(verstr);
while (*verstr && *verstr != '.')
verstr++;
}
}
}
return REGERR_OK;
} /* ParseVersion */
void vCreate(char *cmd)
{
/* Syntax: Create [new,] 5.0b1 */
char buf[512];
int flag = 0;
cmd = GetNextWord(cmd, buf);
error("VR_CreateRegistry", VR_CreateRegistry("Communicator", buf, cmd));
} /* vCreate */
void vFind(char *cmd)
{
VERSION ver;
char path[MAXREGPATHLEN];
if (error("VR_GetVersion", VR_GetVersion(cmd, &ver)) == REGERR_OK)
{
if (error("VR_GetPath", VR_GetPath(cmd, sizeof(path), path)) == REGERR_OK)
{
printf("%s found: ver=%d.%d.%d.%d, check=0x%04x, path=%s\n",
cmd, ver.major, ver.minor, ver.release, ver.build, ver.check,
path);
return;
}
}
printf("%s not found.\n", cmd);
return;
} /* vFind */
void vHelp(char *cmd)
{
puts("Enter a command:");
puts("\tN)ew <dir> [, <ver>] - create a new registry");
puts("\tA)pp <dir> - set application directory");
puts("\tC)lose - close the registry");
puts("");
puts("\tI)nstall <name>, <version>, <path> - install a new component");
puts("\tR)emove <name> - deletes a component from the Registry");
puts("\tX)ists <name> - checks for existence in registry");
puts("\tT)est <name> - validates physical existence");
puts("\tE)num <name> - dumps named subtree");
puts("");
puts("\tV)ersion <name> - gets component version");
puts("\tP)ath <name> - gets component path");
puts("\treF)count <name> - gets component refcount");
puts("\tD)ir <name> - gets component directory");
puts("\tSR)efcount <name>- sets component refcount");
puts("\tSD)ir <name> - sets component directory");
puts("");
puts("\tQ)uit - end the program");
} /* vHelp */
void vInstall(char *cmd)
{
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
char ver[MAXREGPATHLEN+1];
char *pPath, *pVer;
cmd = GetNextWord(cmd, name);
cmd = GetNextWord(cmd, ver);
cmd = GetNextWord(cmd, path);
pVer = ( ver[0] != '*' ) ? ver : NULL;
pPath = ( path[0] != '*' ) ? path : NULL;
error("VR_Install", VR_Install(name, pPath, pVer, FALSE));
} /* vInstall */
void interp(void)
{
char line[256];
char *p;
while(1)
{
putchar('>');
putchar(' ');
fflush(stdin); fflush(stdout); fflush(stderr);
gets(line);
/* p points to next word after verb on command line */
p = line;
while (*p && *p!=' ')
p++;
if (!*p)
p = 0;
else
{
while(*p && *p==' ')
p++;
}
switch(toupper(line[0]))
{
case 'N':
vCreate(p);
break;
case 'A':
error("VR_SetRegDirectory", VR_SetRegDirectory(p));
break;
case 'C':
error("VR_Close", VR_Close());
break;
case 'I':
vInstall(p);
break;
case 'R':
error("VR_Remove", VR_Remove(p));
break;
case 'X':
error("VR_InRegistry", VR_InRegistry(p));
break;
case 'T':
error("VR_ValidateComponent", VR_ValidateComponent(p));
break;
#if LATER
case 'E':
vEnum(p);
break;
case 'V':
vVersion(p);
break;
case 'P':
vPath(p);
break;
case 'F':
vGetRefCount(p);
break;
case 'D':
vGetDir(p);
break;
case 'S':
puts("--Unsupported--");
#endif
case 'H':
default:
vHelp(line);
break;
case 'Q':
return;
} /* switch */
} /* while */
assert(0);
return; /* shouldn't get here */
} /* interp */
/* EOF: interp.c */

Просмотреть файл

@ -0,0 +1,117 @@
/* -*- 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
* http://www.mozilla.org/MPL/
*
* 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 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 ***** */
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#include "NSReg.h"
#include "VerReg.h"
extern void interp(void);
#define REGFILE "c:\\temp\\reg.dat"
char *gRegistry;
int main(int argc, char *argv[]);
char *errstr(REGERR err)
{
switch( err )
{
case REGERR_OK:
return "REGERR_OK";
case REGERR_FAIL:
return "REGERR_FAIL";
case REGERR_NOMORE:
return "REGERR_MORE";
case REGERR_NOFIND:
return "REGERR_NOFIND";
case REGERR_BADREAD:
return "REGERR_BADREAD";
case REGERR_BADLOCN:
return "REGERR_BADLOCN";
case REGERR_PARAM:
return "REGERR_PARAM";
case REGERR_BADMAGIC:
return "REGERR_BADMAGIC";
case REGERR_BADCHECK:
return "REGERR_BADCHECK";
case REGERR_NOFILE:
return "REGERR_NOFILE";
case REGERR_MEMORY:
return "REGERR_MEMORY";
case REGERR_BUFTOOSMALL:
return "REGERR_BUFTOOSMALL";
case REGERR_NAMETOOLONG:
return "REGERR_NAMETOOLONG";
case REGERR_REGVERSION:
return "REGERR_REGVERSION";
case REGERR_DELETED:
return "REGERR_DELETED";
case REGERR_BADTYPE:
return "REGERR_BADTYPE";
case REGERR_NOPATH:
return "REGERR_NOPATH";
case REGERR_BADNAME:
return "REGERR_BADNAME";
case REGERR_READONLY:
return "REGERR_READONLY";
case REGERR_BADUTF8:
return "REGERR_BADUTF8";
default:
return "<Unknown>";
}
} // errstr
int main(int argc, char *argv[])
{
printf("Registry Test 4/10/99.\n");
interp();
return 0;
}

Просмотреть файл

@ -64,6 +64,7 @@ LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
endif
ifneq (,$(filter WINNT OS2,$(OS_ARCH)))
REQUIRES += libreg
DEFINES += -DZLIB_DLL=1
endif
@ -111,6 +112,7 @@ STATIC_LIBS += \
xpcom_core \
ucvutil_s \
chromium_s \
mozreg_s \
$(NULL)
# component libraries

Просмотреть файл

@ -294,6 +294,12 @@ MAKEFILES_libjar="
modules/libjar/test/Makefile
"
MAKEFILES_libreg="
modules/libreg/Makefile
modules/libreg/include/Makefile
modules/libreg/src/Makefile
"
MAKEFILES_libpref="
modules/libpref/Makefile
modules/libpref/public/Makefile
@ -744,6 +750,7 @@ add_makefiles "
$MAKEFILES_content
$MAKEFILES_layout
$MAKEFILES_libjar
$MAKEFILES_libreg
$MAKEFILES_libpref
$MAKEFILES_mathml
$MAKEFILES_plugin

Просмотреть файл

@ -59,6 +59,7 @@ tier_platform_dirs += modules/zlib
endif
tier_platform_dirs += \
modules/libreg \
modules/libpref \
intl \
netwerk \