libreg threading and standalone fixes

This commit is contained in:
dveditz%netscape.com 1999-04-15 05:40:37 +00:00
Родитель 0d80e5ae5f
Коммит 6e0b7cd2b8
9 изменённых файлов: 1797 добавлений и 1887 удалений

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

@ -1,19 +1,25 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* Version 1.0 (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/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* 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
* NPL.
* License.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
*/
/* NSReg.h
*/
@ -115,39 +121,111 @@ typedef struct _reginfo
#endif
XP_BEGIN_PROTOS
/* ---------------------------------------------------------------------
* Registry API -- General
* ---------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------
* 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(
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_RegIsWritable - Check read/write status of open registry
*
* Parameters:
* hReg - handle of open registry to query
* ---------------------------------------------------------------------
*/
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 */
);
/* ---------------------------------------------------------------------
* DO NOT USE -- Will be removed
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegGetUsername(
char **name /* on return, an alloc'ed copy of the current user name */
);
VR_INTERFACE(REGERR) NR_RegSetUsername(
const char *name /* name of current user */
);
/* ---------------------------------------------------------------------
* 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 */
@ -155,6 +233,22 @@ VR_INTERFACE(REGERR) NR_RegAddKey(
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 */
@ -162,18 +256,58 @@ VR_INTERFACE(REGERR) NR_RegAddKeyRaw(
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 */
@ -181,6 +315,18 @@ VR_INTERFACE(REGERR) NR_RegGetKey(
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 */
@ -188,6 +334,24 @@ VR_INTERFACE(REGERR) NR_RegGetKeyRaw(
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 */
@ -197,11 +361,24 @@ VR_INTERFACE(REGERR) NR_RegEnumSubkeys(
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 */
@ -209,6 +386,19 @@ VR_INTERFACE(REGERR) NR_RegGetEntryInfo(
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 */
@ -217,6 +407,19 @@ VR_INTERFACE(REGERR) NR_RegGetEntryString(
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 */
@ -225,6 +428,19 @@ VR_INTERFACE(REGERR) NR_RegGetEntry(
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 */
@ -232,6 +448,20 @@ VR_INTERFACE(REGERR) NR_RegSetEntryString(
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 */
@ -241,12 +471,36 @@ VR_INTERFACE(REGERR) NR_RegSetEntry(
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 */

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

@ -1,19 +1,25 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* Version 1.0 (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/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* 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
* NPL.
* License.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
*/
/* VerReg.h
* XP Version Registry functions
@ -42,8 +48,9 @@ XP_BEGIN_PROTOS
* ---------------------------------------------------------------------
*/
/* global registry operations */
VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path);
/* 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);

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

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

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

@ -1,19 +1,25 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* Version 1.0 (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/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* 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
* NPL.
* License.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
*/
/* reg.h
* XP Registry functions (prototype)
@ -25,7 +31,6 @@
#include "vr_stubs.h"
#ifndef STANDALONE_REGISTRY
#include "prmon.h"
#include "prlock.h"
#endif
@ -37,7 +42,7 @@
#define MAJOR_VERSION 1 /* 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 HDRRESERVE 128 /* number of bytes reserved for hdr */
#define INTSIZE 4
#define DOUBLESIZE 8
@ -92,15 +97,15 @@ 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 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;
@ -120,11 +125,11 @@ typedef struct _desc
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 */
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*/
@ -134,7 +139,7 @@ typedef struct _hdr
#define HDR_AVAIL 8
#define HDR_ROOT 12
typedef XP_File FILEHANDLE; /* platform-specific file reference */
typedef XP_File FILEHANDLE; /* platform-specific file reference */
typedef struct _stdnodes {
REGOFF versions;
@ -146,10 +151,10 @@ typedef struct _stdnodes {
typedef struct _regfile
{
FILEHANDLE fh;
REGHDR hdr;
FILEHANDLE fh;
REGHDR hdr;
int refCount;
int hdrDirty;
int hdrDirty;
int inInit;
int readOnly;
char * filename;

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

@ -43,7 +43,17 @@
#include "FullPath.h" /* For FSpLocationFromFullPath() */
#endif
extern char* globalRegName;
#define DEF_REG "/.mozilla/registry"
#define WIN_REG "\\mozregistry.dat"
#define MAC_REG "\pMozilla Registry"
#define DEF_VERREG "/.netscape/registry"
#define WIN_VERREG "\\nsreg.dat"
#define MAC_VERREG "\pNetscape Registry"
/* ------------------------------------------------------------------
* OS/2 STUBS
* ------------------------------------------------------------------
@ -62,7 +72,7 @@ extern XP_File vr_fileOpen (const char *name, const char * mode)
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_WRITE_BIN );
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
@ -84,10 +94,24 @@ extern void vr_findGlobalRegName ()
pathlen = strlen(path);
if ( pathlen > 0 ) {
XP_STRCPY( path+pathlen, "\\mozregistry.dat" );
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 */
@ -109,7 +133,7 @@ extern XP_File vr_fileOpen (const char *name, const char * mode)
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_WRITE_BIN );
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
@ -123,11 +147,28 @@ extern void vr_findGlobalRegName ()
pathlen = GetWindowsDirectory(path, PATHLEN);
if ( pathlen > 0 ) {
XP_STRCPY( path+pathlen, "\\mozregistry.dat" );
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);
@ -162,39 +203,39 @@ extern XP_File vr_fileOpen(const char *name, const char * mode)
{
XP_File fh = NULL;
struct stat st;
OSErr anErr;
FSSpec newFSSpec;
OSErr anErr;
FSSpec newFSSpec;
#ifdef STANDALONE_REGISTRY
errno = 0; /* reset errno (only if we're using stdio) */
errno = 0; /* reset errno (only if we're using stdio) */
#endif
anErr = FSpLocationFromFullPath(strlen(name), name, &newFSSpec);
if (anErr == -43)
{
/* if file doesn't exist */
anErr = FSpCreate(&newFSSpec, 'MOSS', 'REGS', smSystemScript);
}
else
{
/* there is not much to do here. if we got noErr, the file exists. If we did not get
noErr or -43, we are pretty hosed.
*/
}
anErr = FSpLocationFromFullPath(strlen(name), name, &newFSSpec);
if (anErr == -43)
{
/* if file doesn't exist */
anErr = FSpCreate(&newFSSpec, 'MOSS', 'REGS', smSystemScript);
}
else
{
/* there is not much to do here. if we got noErr, the file exists. If we did not get
noErr or -43, we are pretty hosed.
*/
}
if ( name != NULL ) {
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN ); /* If/when we switch to MSL C Lib (gromit uses this), we might have to take out the Macro per bug #62382 */
else
{
/* should never get here! */
fh = fopen( name, XP_FILE_WRITE_BIN );
}
}
else
{
/* should never get here! */
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
}
#ifdef STANDALONE_REGISTRY
if (anErr != noErr)
errno = anErr;
if (anErr != noErr)
errno = anErr;
#endif
return fh;
}
@ -202,98 +243,155 @@ extern XP_File vr_fileOpen(const char *name, const char * mode)
extern void vr_findGlobalRegName()
{
FSSpec regSpec;
OSErr err;
short foundVRefNum;
long foundDirID;
FSSpec regSpec;
OSErr err;
short foundVRefNum;
long foundDirID;
int bCreate = 0;
err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);
err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);
if (!err)
{
err = FSMakeFSSpec(foundVRefNum, foundDirID, "\pMozilla Registry", &regSpec);
if (!err)
{
err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_REG, &regSpec);
if (err == -43) /* if file doesn't exist */
{
err = FSpCreate(&regSpec, 'MOSS', 'REGS', smSystemScript);
if (err == -43) /* if file doesn't exist */
{
err = FSpCreate(&regSpec, 'MOSS', 'REGS', smSystemScript);
bCreate = 1;
}
}
if (err == noErr)
{
Handle thePath;
short pathLen;
err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
if (err == noErr && thePath)
{
#ifdef STANDALONE_REGISTRY
globalRegName = XP_STRDUP(*(char**)thePath);
#else
/* Since we're now using NSPR, this HAS to be a unix path! */
const char* src;
char* dst;
globalRegName = (char*)XP_ALLOC(pathLen + 2);
src = *(char**)thePath;
dst = globalRegName;
*dst++ = '/';
while (pathLen--)
{
char c = *src++;
*dst++ = (c == ':') ? '/' : c;
}
*dst = '\0';
#endif
}
DisposeHandle(thePath);
}
}
if (err == noErr)
{
Handle thePath;
short pathLen;
err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
if (err == noErr && thePath)
{
#ifdef STANDALONE_REGISTRY
globalRegName = XP_STRDUP(*(char**)thePath);
#else
/* Since we're now using NSPR, this HAS to be a unix path! */
const char* src;
char* dst;
globalRegName = (char*)XP_ALLOC(pathLen + 2);
src = *(char**)thePath;
dst = globalRegName;
*dst++ = '/';
while (pathLen--)
{
char c = *src++;
*dst++ = (c == ':') ? '/' : c;
}
*dst = '\0';
#endif
}
DisposeHandle(thePath);
}
}
}
extern char* vr_findGlobalRegName()
{
FSSpec regSpec;
OSErr err;
short foundVRefNum;
long foundDirID;
int bCreate = 0;
/* quick exit if we have the info */
if ( verRegName != NULL )
return verRegName;
err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);
if (!err)
{
err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_VERREG, &regSpec);
if (err == -43) /* if file doesn't exist */
{
err = FSpCreate(&regSpec, 'MOSS', 'REGS', smSystemScript);
bCreate = 1;
}
if (err == noErr)
{
Handle thePath;
short pathLen;
err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
if (err == noErr && thePath)
{
#ifdef STANDALONE_REGISTRY
verRegName = XP_STRDUP(*(char**)thePath);
#else
/* Since we're now using NSPR, this HAS to be a unix path! */
const char* src;
char* dst;
verRegName = (char*)XP_ALLOC(pathLen + 2);
src = *(char**)thePath;
dst = verRegName;
*dst++ = '/';
while (pathLen--)
{
char c = *src++;
*dst++ = (c == ':') ? '/' : c;
}
*dst = '\0';
#endif
}
DisposeHandle(thePath);
}
}
return verRegName;
}
/* Moves and renames a file or directory.
Returns 0 on success, -1 on failure (errno contains mac error code).
*/
extern int nr_RenameFile(char *from, char *to)
{
OSErr err = -1;
FSSpec fromSpec;
FSSpec toSpec;
FSSpec destDirSpec;
FSSpec beforeRenameSpec;
OSErr err = -1;
FSSpec fromSpec;
FSSpec toSpec;
FSSpec destDirSpec;
FSSpec beforeRenameSpec;
#ifdef STANDALONE_REGISTRY
errno = 0; /* reset errno (only if we're using stdio) */
errno = 0; /* reset errno (only if we're using stdio) */
#endif
if (from && to) {
err = FSpLocationFromFullPath(XP_STRLEN(from), from, &fromSpec);
if (err != noErr) goto exit;
err = FSpLocationFromFullPath(XP_STRLEN(to), to, &toSpec);
if (from && to) {
err = FSpLocationFromFullPath(XP_STRLEN(from), from, &fromSpec);
if (err != noErr) goto exit;
err = FSpLocationFromFullPath(XP_STRLEN(to), to, &toSpec);
if (err != noErr && err != fnfErr) goto exit;
/* make an FSSpec for the destination directory */
err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, nil, &destDirSpec);
if (err != noErr) goto exit; /* parent directory must exist */
/* make an FSSpec for the destination directory */
err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, nil, &destDirSpec);
if (err != noErr) goto exit; /* parent directory must exist */
/* move it to the directory specified */
err = FSpCatMove(&fromSpec, &destDirSpec);
if (err != noErr) goto exit;
/* make a new FSSpec for the file or directory in its new location */
err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, fromSpec.name, &beforeRenameSpec);
if (err != noErr) goto exit;
/* rename the file or directory */
err = FSpRename(&beforeRenameSpec, toSpec.name);
}
exit:
/* move it to the directory specified */
err = FSpCatMove(&fromSpec, &destDirSpec);
if (err != noErr) goto exit;
/* make a new FSSpec for the file or directory in its new location */
err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, fromSpec.name, &beforeRenameSpec);
if (err != noErr) goto exit;
/* rename the file or directory */
err = FSpRename(&beforeRenameSpec, toSpec.name);
}
exit:
#ifdef STANDALONE_REGISTRY
if (err != noErr)
errno = err;
if (err != noErr)
errno = err;
#endif
return (err == noErr ? 0 : -1);
return (err == noErr ? 0 : -1);
}
@ -317,61 +415,61 @@ char *strdup(const char *source)
int strcasecmp(const char *str1, const char *str2)
{
char currentChar1, currentChar2;
char currentChar1, currentChar2;
while (1) {
currentChar1 = *str1;
currentChar2 = *str2;
if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
currentChar1 += ('A' - 'a');
if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
currentChar2 += ('A' - 'a');
if (currentChar1 == '\0')
break;
if (currentChar1 != currentChar2)
return currentChar1 - currentChar2;
str1++;
str2++;
}
return currentChar1 - currentChar2;
while (1) {
currentChar1 = *str1;
currentChar2 = *str2;
if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
currentChar1 += ('A' - 'a');
if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
currentChar2 += ('A' - 'a');
if (currentChar1 == '\0')
break;
if (currentChar1 != currentChar2)
return currentChar1 - currentChar2;
str1++;
str2++;
}
return currentChar1 - currentChar2;
}
int strncasecmp(const char *str1, const char *str2, int length)
{
char currentChar1, currentChar2;
char currentChar1, currentChar2;
while (length > 0) {
while (length > 0) {
currentChar1 = *str1;
currentChar2 = *str2;
currentChar1 = *str1;
currentChar2 = *str2;
if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
currentChar1 += ('A' - 'a');
if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
currentChar1 += ('A' - 'a');
if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
currentChar2 += ('A' - 'a');
if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
currentChar2 += ('A' - 'a');
if (currentChar1 == '\0')
break;
if (currentChar1 == '\0')
break;
if (currentChar1 != currentChar2)
return currentChar1 - currentChar2;
if (currentChar1 != currentChar2)
return currentChar1 - currentChar2;
str1++;
str2++;
str1++;
str2++;
length--;
}
}
return currentChar1 - currentChar2;
return currentChar1 - currentChar2;
}
#endif /* 0 */
@ -414,8 +512,6 @@ int main(int argc, char *argv[]);
#ifdef XP_UNIX
#define DEF_REG "/.mozilla/registry"
#ifdef STANDALONE_REGISTRY
extern XP_File vr_fileOpen (const char *name, const char * mode)
{
@ -426,7 +522,7 @@ extern XP_File vr_fileOpen (const char *name, const char * mode)
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_WRITE_BIN );
fh = fopen( name, XP_FILE_TRUNCATE_BIN );
}
return fh;
@ -448,41 +544,69 @@ extern void vr_findGlobalRegName ()
if (def != NULL) {
globalRegName = XP_STRDUP(def);
} else {
globalRegName = TheRegistry;
globalRegName = XP_STRDUP(TheRegistry);
}
XP_FREEIF(def);
#else
globalRegName = TheRegistry;
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*/
#if defined(STANDALONE_REGISTRY) && (defined(XP_UNIX) || defined(XP_OS2) || defined(XP_MAC))
int main(int argc, char *argv[])
{
XP_File fh;
char *entry;
char *p;
XP_File fh;
char *entry;
char *p;
char *v;
char buff[1024];
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
char buff[1024];
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
char ver[MAXREGPATHLEN+1];
if ( argc >= 3 )
{
TheRegistry = argv[1];
Flist = argv[2];
}
else
{
fprintf(stderr, "Usage: %s RegistryName FileList\n", argv[0]);
if ( argc >= 3 )
{
TheRegistry = argv[1];
Flist = argv[2];
}
else
{
fprintf(stderr, "Usage: %s RegistryName FileList\n", argv[0]);
fprintf(stderr, " The FileList file contains lines with comma-separated fields:\n");
fprintf(stderr, " <regItemName>,<version>,<full filepath>\n");
exit (1);
}
exit (1);
}
/* tmp use of buff to get the registry directory, which must be
* the navigator home directory. Preserve the slash to match
@ -513,25 +637,25 @@ int main(int argc, char *argv[])
#ifndef XP_MAC
if ( -1 == (access( TheRegistry, W_OK )) ) {
if ( -1 == (access( TheRegistry, W_OK )) ) {
sprintf(ver,"4.50.0.%ld",BUILDNUM);
VR_CreateRegistry("Communicator", buff, ver);
VR_CreateRegistry("Communicator", buff, ver);
}
#endif
if ( !(fh = fopen( Flist, "r" )) )
{
fprintf(stderr, "%s: Cannot open \"%s\"\n", argv[0], Flist);
exit (1);
}
if ( !(fh = fopen( Flist, "r" )) )
{
fprintf(stderr, "%s: Cannot open \"%s\"\n", argv[0], Flist);
exit (1);
}
while ( fgets ( buff, 1024, fh ) )
{
if ( *(entry = &buff[strlen(buff)-1]) == '\n' )
*entry = '\0';
while ( fgets ( buff, 1024, fh ) )
{
if ( *(entry = &buff[strlen(buff)-1]) == '\n' )
*entry = '\0';
entry = strchr(buff, ',');
strcpy(name, strtok(buff, ","));
entry = strchr(buff, ',');
strcpy(name, strtok(buff, ","));
strcpy(ver, strtok( NULL, ","));
strcpy(path, strtok( NULL, ","));
@ -539,14 +663,14 @@ int main(int argc, char *argv[])
while (*v && *v == ' ')
v++;
p = path;
while (*p && *p == ' ')
p++;
p = path;
while (*p && *p == ' ')
p++;
VR_Install ( name, p, v, FALSE );
}
fclose( fh );
return 0;
VR_Install ( name, p, v, FALSE );
}
fclose( fh );
return 0;
}
#endif /* STANDALONE_REGISTRY && (XP_UNIX || XP_OS2 || XP_MAC) */

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

@ -1,19 +1,25 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* Version 1.0 (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/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* 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
* NPL.
* License.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
*/
/* vr_stubs.h
*
@ -110,7 +116,7 @@
#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_MEMCPY(d, s, l) memcpy((d), (s), (l))
#define XP_MEMSET(d, c, l) memset((d), (c), (l))
#define PR_Lock(a) ((void)0)
@ -128,23 +134,23 @@ typedef FILE * XP_File;
#else /* if not standalone, use NSPR */
#define XP_FILE_READ PR_RDONLY, 0700
#define XP_FILE_READ_BIN PR_RDONLY, 0700
#define XP_FILE_WRITE PR_WRONLY, 0700
#define XP_FILE_WRITE_BIN PR_WRONLY, 0700
#define XP_FILE_UPDATE PR_RDWR
#define XP_FILE_TRUNCATE (PR_WRONLY | PR_TRUNCATE), 0700
#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_WRONLY | PR_TRUNCATE), 0644
#define XP_FILE_UPDATE_BIN PR_RDWR, 0700
#define XP_FILE_TRUNCATE_BIN (PR_RDWR | PR_TRUNCATE), 0700
#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
#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
/*
** Note that PR_Seek returns the offset (if successful) and -1 otherwise. So
@ -172,7 +178,7 @@ typedef FILE * XP_File;
#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_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))
@ -194,7 +200,7 @@ typedef unsigned char uint8;
#ifdef XP_MAC
#include <Types.h>
typedef char BOOL;
typedef char BOOL;
typedef char Bool;
typedef char XP_Bool;
#elif defined(XP_PC)
@ -225,32 +231,35 @@ typedef unsigned char uint8;
#ifdef XP_MAC
extern int nr_RenameFile(char *from, char *to);
#else
XP_BEGIN_PROTOS
#define nr_RenameFile(from, to) rename((from), (to))
XP_END_PROTOS
XP_BEGIN_PROTOS
#define nr_RenameFile(from, to) rename((from), (to))
XP_END_PROTOS
#endif
XP_BEGIN_PROTOS
extern char* globalRegName;
extern char* verRegName;
extern void vr_findGlobalRegName();
extern char* vr_findVerRegName();
#ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
XP_BEGIN_PROTOS
extern XP_File vr_fileOpen(const char *name, const char * mode);
extern void vr_findGlobalRegName();
#if !defined(XP_PC) && !(defined(__GLIBC__) && __GLIBC__ >= 2)
extern char * strdup(const char * s);
#endif
XP_END_PROTOS
#else
#define vr_fileOpen PR_Open
XP_BEGIN_PROTOS
extern void vr_findGlobalRegName();
XP_END_PROTOS
#endif /* STANDALONE_REGISTRY */
XP_END_PROTOS
#endif /* _VR_STUBS_H_ */

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

@ -28,19 +28,16 @@
extern char *errstr(REGERR err);
extern int DumpTree(void);
int gVerbose = 1;
int gPretend = 0;
int error(char *func, int err)
{
if (err == REGERR_OK)
{
if (gVerbose)
printf("%s Ok\n", func);
printf("\t%s -- OK\n", func);
}
else
{
printf("%s returns %s\n", func, errstr(err));
printf("\t%s -- %s\n", func, errstr(err));
}
return err;
@ -98,66 +95,20 @@ static int vr_ParseVersion(char *verstr, VERSION *result)
} // ParseVersion
void parse(char *cmd, char *name, VERSION *ver, char *path)
{
// expects 'cmd' points to: "<name>, <ver>, <path>"
char buf[256];
char *p;
cmd = GetNextWord(cmd, buf);
strcpy(name, buf);
p = cmd; // 'cmd' points to version
vr_ParseVersion(cmd, ver);
ver->check = gPretend ? 0xad : 0;
while (*p && *p != ',') // skip to next ','
p++;
if (*p == ',') // skip comma
p++;
while (*p && *p == ' ') // skip white space
p++;
strcpy(path, p);
} // parse
void vVerbose(char *cmd)
{
if (stricmp(cmd, "ON") == 0)
{
gVerbose = 1;
printf("Verbose mode is now ON.\n");
}
else
{
gVerbose = 0;
}
} // vVerbose
void vCreate(char *cmd)
{
// Syntax: Create [new,] 5.0b1
char buf[64];
char buf[512];
int flag = 0;
cmd = GetNextWord(cmd, buf);
if (stricmp(buf, "NEW,") == 0)
{
flag = CR_NEWREGISTRY;
}
error("VR_CreateRegistry", VR_CreateRegistry(flag, cmd));
error("VR_CreateRegistry", VR_CreateRegistry("Communicator", buf, cmd));
} // vCreate
void vDisplay(char *cmd)
{
DumpTree();
} // vDisplay
void vFind(char *cmd)
@ -187,18 +138,23 @@ void vHelp(char *cmd)
{
puts("Enter a command:");
puts("\tD)isplay - display the current contents of the Registry");
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("\tU)pdate <name>, <version>, <path> - update a component");
puts("\tF)ind <name> - returns version and path");
puts("\tV)erify <name> - verify component exists and checks out");
puts("\tC)reate <name> - create a new instance of Navigator (e.g., \"4.0\")");
puts("\tR)emove <name> - deletes a component from the Registry");
puts("\tT)est - perform a simple test on the Registry");
puts("\tver(B)ose ON|off - turn verbose mode on or off");
puts("\tP)retend on|OFF - pretend that test files exist");
puts("\tS)ave - save the Registry to disk");
puts("\tpac(K) registry - squeeze out unused space 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
@ -209,145 +165,26 @@ void vInstall(char *cmd)
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
VERSION ver;
char ver[MAXREGPATHLEN+1];
parse(cmd, name, &ver, path);
error("VR_Install", VR_Install(name, path, &ver));
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 vPack(char *cmd)
{
error("VR_PackRegistry", VR_PackRegistry(0));
} // vPack
void vPretend(char *cmd)
{
if (!cmd)
{
gPretend = !!gPretend;
}
else
{
if (stricmp(cmd, "ON") == 0)
gPretend = 1;
else
gPretend = 0;
}
if (gVerbose)
printf("Pretend mode is %s\n", gPretend ? "ON" : "OFF");
} // vPretend
void vRemove(char *cmd)
{
error("VR_Remove", VR_Remove(cmd));
} // vRemove
void vSave(char *cmd)
{
error("VR_Checkpoint", VR_Checkpoint());
} // vSave
void vTest(char *cmd)
{
VERSION ver;
ver.major = 4;
ver.minor = 0;
ver.release = 0;
ver.build = 237;
ver.check = gPretend ? 0xad : 0;
if (error("VR_Install", VR_Install("Navigator/NS.exe",
"c:\\Program Files\\Netscape\\Navigator\\Program\\NETSCAPE.EXE", &ver)))
return;
if (error("VR_Install", VR_Install("Navigator/Help",
"c:\\Program Files\\Netscape\\Navigator\\Program\\NETSCAPE.HLP", &ver)))
return;
if (error("VR_Install", VR_Install("Navigator/NSPR",
"c:\\Program Files\\Netscape\\Navigator\\Program\\NSPR32.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("Navigator/Player",
"c:\\Program Files\\Netscape\\Navigator\\Program\\NSPLAYER.EXE", &ver)))
return;
if (error("VR_Install", VR_Install("Navigator/NSJava",
"c:\\Program Files\\Netscape\\Navigator\\Program\\NSJAVA32.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("Web/Certificate.DB",
"c:\\Program Files\\Netscape\\Navigator\\Program\\CERT.DB", &ver)))
return;
if (error("VR_Install", VR_Install("Web/CertificateNI.DB",
"c:\\Program Files\\Netscape\\Navigator\\Program\\CERTNI.DB", &ver)))
return;
if (error("VR_Install", VR_Install("Web/Keys",
"c:\\Program Files\\Netscape\\Navigator\\Program\\KEY.DB", &ver)))
return;
if (error("VR_Install", VR_Install("MailNews/Postal",
"c:\\Program Files\\Netscape\\Navigator\\System\\POSTAL32.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("MailNews/Folders/Inbox",
"c:\\Program Files\\Netscape\\Navigator\\Mail\\INBOX.SNM", &ver)))
return;
if (error("VR_Install", VR_Install("MailNews/Folders/Sent",
"c:\\Program Files\\Netscape\\Navigator\\Mail\\SENT.SNM", &ver)))
return;
if (error("VR_Install", VR_Install("MailNews/Folders/Trash",
"c:\\Program Files\\Netscape\\Navigator\\Mail\\TRASH.SNM", &ver)))
return;
if (error("VR_Install", VR_Install("Components/NUL",
"c:\\Program Files\\Netscape\\Navigator\\Program\\Plugins\\NPNUL32.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("Components/PointCast",
"c:\\Program Files\\Netscape\\Navigator\\Program\\Plugins\\NPPCN32.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("Components/AWT",
"c:\\Program Files\\Netscape\\Navigator\\Program\\Java\\bin\\AWT3220.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("Components/MM",
"c:\\Program Files\\Netscape\\Navigator\\Program\\Java\\bin\\MM3220.DLL", &ver)))
return;
if (error("VR_Install", VR_Install("Java/Classes.Zip",
"c:\\Program Files\\Netscape\\Navigator\\Program\\Java\\classes\\MOZ2_0.ZIP", &ver)))
return;
if (error("VR_Install", VR_Install("Java/Classes Directory",
"c:\\Program Files\\Netscape\\Navigator\\Program\\Java\\classes\\MOZ2_0", &ver)))
return;
} // vTest
void vUpdate(char *cmd)
{
char name[MAXREGPATHLEN+1];
char path[MAXREGPATHLEN+1];
VERSION ver;
parse(cmd, name, &ver, path);
error("VR_Update", VR_Update(name, path, &ver));
} // vUpdate
void vVerify(char *cmd)
{
error("VR_CheckEntry", VR_CheckEntry(0, cmd));
} // vVerify
void interp(void)
{
@ -375,49 +212,56 @@ void interp(void)
switch(toupper(line[0]))
{
case 'B':
vVerbose(p);
break;
case 'C':
case 'N':
vCreate(p);
break;
case 'D':
vDisplay(p);
case 'A':
error("VR_SetRegDirectory", VR_SetRegDirectory(p));
break;
case 'C':
error("VR_Close", VR_Close());
break;
case 'I':
vInstall(p);
break;
case 'F':
vFind(p);
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 'I':
vInstall(p);
break;
case 'K':
vPack(p);
break;
case 'P':
vPretend(p);
break;
case 'R':
vRemove(p);
break;
case 'S':
vSave(p);
break;
case 'T':
vTest(p);
break;
case 'U':
vUpdate(p);
break;
case 'V':
vVerify(p);
break;
case 'Q':
case 'X':
vSave(0);
return;
} // switch
} // while

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

@ -55,6 +55,30 @@ char *errstr(REGERR err)
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>";
}
@ -62,377 +86,13 @@ char *errstr(REGERR err)
} // errstr
int CreateEmptyRegistry(void)
{
#if 0
int fh;
remove(REGFILE); // ignore errors like file not found
fh = _open(REGFILE, _O_CREAT, _S_IREAD|_S_IWRITE);
if (fh < 0)
return -1;
close(fh);
return 0;
#endif
return VR_CreateRegistry(CR_NEWREGISTRY, "4.0");
} // CreateEmptyRegistry
int BuildTree(void)
{
REGERR err;
err = NR_RegAdd(0,"/Machine/Old");
if (err != REGERR_OK)
{
printf("NR_RegAdd() returned %s.\n", errstr(err));
return err;
}
err = NR_RegAdd(0,"/User");
if (err != REGERR_OK)
{
printf("NR_RegAdd() returned %s.\n", errstr(err));
return err;
}
err = NR_RegAdd(0,"/Machine/4.0/Name1=Val1");
if (err != REGERR_OK)
{
printf("NR_RegAdd() returned %s.\n", errstr(err));
return err;
}
err = NR_RegAdd(0,"/Machine/4.0/Name2=Val2");
if (err != REGERR_OK)
{
printf("NR_RegAdd() returned %s.\n", errstr(err));
return err;
}
err = NR_RegAdd(0,"/Machine/4.0/Name2=Val3");
if (err != REGERR_OK)
{
printf("NR_RegAdd() returned %s.\n", errstr(err));
return err;
}
err = NR_RegAdd(0,"/Machine/4.0/Name3=Val4");
if (err != REGERR_OK)
{
printf("NR_RegAdd() returned %s.\n", errstr(err));
return err;
}
return VR_Checkpoint();
} // BuildTree
int FindKeys(void)
{
RKEY key;
REGERR err;
char buf[80];
if (NR_RegGetKey(0, "", &key) == REGERR_OK)
{
printf("NR_RegGetKey returns ok for an empty path.\n");
return 1;
}
if (NR_RegGetKey(0, "/", &key) != REGERR_OK)
{
printf("NR_RegGetKey couldn't find root.\n");
return 1;
}
if (NR_RegGetKey(0, "/Machine/Old", &key) != REGERR_OK)
{
printf("NR_RegGetKey couldn't find Old\n");
return 1;
}
printf("NR_RegGetKey returns key for Old as: 0x%lx\n", (long) key);
if (NR_RegGetKey(0, "/Machine/4.0", &key) != REGERR_OK)
{
printf("NR_RegGetKey couldn't find 4.0\n");
return 1;
}
printf("NR_RegGetKey returns key for 4.0 as: 0x%lx\n", (long) key);
// ----------------------------------------
if ((err = NR_RegFindValue(0, "/Machine/4.0/Name3", 64, buf)) != REGERR_OK)
{
printf("NR_RegFindValue (no key) returns %s\n", errstr(err));
return 1;
}
printf("NR_RegFindValue (no key) of Name3 = %s\n", buf);
if (NR_RegFindValue(key, "Aliens", 64, buf) == REGERR_OK)
{
printf("NR_RegFindValue finds Aliens.\n");
return 1;
}
if ((err = NR_RegFindValue(key, "Name3", 64, buf)) != REGERR_OK)
{
printf("NR_RegFindValue (w/key) returns %s\n", errstr(err));
return 1;
}
printf("NR_RegFindValue (w/key) of Name3 = %s\n", buf);
return 0;
} // FindTree
int DumpTree(void)
{
char *path;
char *line = "------------------------------------------------------------";
path = malloc(2048);
if (!path)
return REGERR_FAIL;
strcpy(path, "/");
puts(line);
puts(path);
while (NR_RegNext( 0, 512, path ) == REGERR_OK)
{
puts(path);
}
puts(line);
return 0;
} // DumpTree
int ChangeKeys(void)
{
REGERR err;
err = NR_RegUpdate(0,"/Machine/4.0/name3", "Infospect Software, Inc.");
if (err)
{
printf("Couldn't update name3's value to ISI.\n");
return err;
}
err = NR_RegUpdate(0,"/Machine/4.0/name3=Infospect Software, Inc.", "\"Jonathan=Kid1\"");
if (err)
{
printf("Couldn't update name3's value to Jon.\n");
return err;
}
err = NR_RegRename(0,"/Machine/4.0/name3=\"Jonathan=Kid1\"", "First born");
if (err)
{
printf("Couldn't update name3's name to First born.\n");
return err;
}
err = NR_RegUpdate(0,"/Machine/4.0/name2=Val2", "Kelley Ann");
if (err)
{
printf("Couldn't update name2's value to Kelley.\n");
return err;
}
return VR_Checkpoint();
} // ChangeKeys
int DeleteKeys(void)
{
REGERR err;
err = NR_RegDelete(0, "/User");
if (err)
{
printf("NR_RegDelete returned %s.\n", errstr(err));
return err;
}
return VR_Checkpoint();
} // DeleteKeys
int StressTest(void)
{
REGERR err;
RKEY key;
printf("Starting stress...\n");
err = NR_RegGetKey(0, "/Machine/4.0", &key);
if (err)
{
printf("Error getting key for 4.0 = %s\n", errstr(err));
return err;
}
err = NR_RegAdd(key, "A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/"
"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/"
"A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/" );
if (err)
{
printf("Adding humungous string returned %s\n", errstr(err));
return err;
}
// TODO: Add a value to one of the middle keys, get it back.
printf("Stress done.\n");
return 0;
} // StressTest
int Install(void)
{
int err;
VERSION ver;
ver.major = 4;
ver.minor = 2;
ver.release = 10;
ver.build = 937;
ver.check = 0;
err = VR_Install("Web/Navigator/netscape.exe",
"c:\\Netscape\\NETSCAPE.EXE", &ver);
if (err)
return err;
ver.release = 19;
ver.build = 722;
ver.check = 0;
err = VR_Install("Web/Navigator/nspr.dll",
"c:\\Netscape\\System\\Vtcprac.386", &ver);
if (err)
return err;
return VR_Checkpoint();
}
int GetInfo(void)
{
int err;
char buf[256];
VERSION ver;
err = VR_GetPath("Web/Navigator/nspr.dll", 256, buf);
if (err)
return err;
printf("GetPath(nspr.dll) returns %s\n", buf);
err = VR_GetVersion("Web/Navigator/netscape.exe", &ver);
if (err)
return err;
printf("GetVersion(netscape.exe) returns %d.%d.%d.%d and check=%d\n",
ver.major, ver.minor, ver.release, ver.build, ver.check);
return 0;
}
int main(int argc, char *argv[])
{
printf("Registry Test 4/10/99.\n");
printf("Registry Test 10/01/96.\n");
if (argc > 1)
{
gRegistry = argv[1];
}
else
{
gRegistry = REGFILE;
}
VR_RegistryName(gRegistry);
#if 1
if (NR_RegOpen(gRegistry) != REGERR_OK)
VR_CreateRegistry(CR_NEWREGISTRY, "4.0");
interp();
#else
if (CreateEmptyRegistry())
goto abort;
if (Install())
goto done;
if (DumpTree())
goto done;
if (GetInfo())
goto done;
#if defined(TEST_NR)
if ((err = NR_RegOpen(REGFILE)) != REGERR_OK)
{
printf("NR_RegOpen(%s) returned %s...Test aborted.\n", REGFILE, errstr(err));
goto abort;
}
if (BuildTree())
goto done;
if (FindKeys())
goto done;
if (DumpTree())
goto done;
if (ChangeKeys())
goto done;
if (DeleteKeys())
goto done;
if (DumpTree())
goto done;
if (StressTest())
goto done;
if (DumpTree())
goto done;
done:
NR_RegClose();
#else
done:
#endif
abort:
puts("Press Enter to continue...");
getchar();
#endif
interp();
return 0;
}