diff --git a/mozilla/modules/libreg/include/NSReg.h b/mozilla/modules/libreg/include/NSReg.h index 0f3fbe8f012..abe5ca29c0c 100644 --- a/mozilla/modules/libreg/include/NSReg.h +++ b/mozilla/modules/libreg/include/NSReg.h @@ -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 */ /* 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 */ diff --git a/mozilla/modules/libreg/include/VerReg.h b/mozilla/modules/libreg/include/VerReg.h index 092c76b18aa..f90e3c39e12 100644 --- a/mozilla/modules/libreg/include/VerReg.h +++ b/mozilla/modules/libreg/include/VerReg.h @@ -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 */ /* 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); diff --git a/mozilla/modules/libreg/src/VerReg.c b/mozilla/modules/libreg/src/VerReg.c index eeea1a0f8c3..96272d89d5d 100644 --- a/mozilla/modules/libreg/src/VerReg.c +++ b/mozilla/modules/libreg/src/VerReg.c @@ -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 */ /* ==================================================================== * VerReg.c @@ -24,9 +30,9 @@ /* -------------------------------------------------------------------- * Install 'Navigator' produces a tree of: * - * /Components/Netscape/Web/Navigator/ - * ...Path="c:\netscape\program\netscape.exe" - * ...Version=4.0.0.0 + * /Components/Netscape/Web/Navigator/ + * ...Path="c:\netscape\program\netscape.exe" + * ...Version=4.0.0.0 * * -------------------------------------------------------------------- */ @@ -54,21 +60,21 @@ /* -------- local defines --------------- */ -#define MAXREGVERLEN 32 /* Version=12345.12345.12345.12345 */ +#define MAXREGVERLEN 32 /* Version=12345.12345.12345.12345 */ -#define VERSTR "Version" -#define CHKSTR "Check" -#define PATHSTR "Path" -#define DIRSTR "Directory" -#define NAVHOME "Navigator Home" -#define REFCSTR "RefCount" -#define SHAREDSTR "Shared" -#define PACKAGENAMESTR "PackageName" -#define SHAREDFILESSTR "/Shared Files" +#define VERSTR "Version" +#define CHKSTR "Check" +#define PATHSTR "Path" +#define DIRSTR "Directory" +#define NAVHOME "Navigator Home" +#define REFCSTR "RefCount" +#define SHAREDSTR "Shared" +#define PACKAGENAMESTR "PackageName" +#define SHAREDFILESSTR "/Shared Files" -#define VERSION_NAME "Communicator" -#define NAVIGATOR_NODE "/Netscape" -#define CURRENT_VER "Current Navigator" +#define VERSION_NAME "Communicator" +#define NAVIGATOR_NODE "/Netscape" +#define CURRENT_VER "Current Navigator" #define PATH_ROOT(p) ( ((p) && *(p)==PATHDEL) ? ROOTKEY_VERSIONS : curver ) #define UNIX_ROOT(p) ( ((p) && *(p)==PATHDEL) ? ROOTKEY_VERSIONS : unixver ) @@ -84,6 +90,12 @@ static char curstr[MAXREGNAMELEN]; static HREG vreg = 0; +static char *app_dir = NULL; + +char *verRegName = NULL; +static char *versionName = NULL; + + #if defined(XP_UNIX) /* Extra Unix variables to deal with two registries * "vreg" is always the writable registry. @@ -99,10 +111,9 @@ XP_Bool bGlobalRegistry = FALSE; #endif #ifndef STANDALONE_REGISTRY -PRMonitor *vr_monitor = NULL; +PRLock *vr_lock = NULL; #endif -static char *app_dir = NULL; /* --------------------------------------------------------------------- * local functions @@ -137,7 +148,7 @@ static REGERR vr_Init(void) { REGERR err = REGERR_OK; - char *regname = ""; + char *regname = vr_findVerRegName(); #if defined(XP_UNIX) || defined(STANDALONE_REGISTRY) char curstr[MAXREGNAMELEN]; RKEY navKey; @@ -147,10 +158,10 @@ static REGERR vr_Init(void) #endif #ifndef STANDALONE_REGISTRY - if (vr_monitor == NULL) - return REGERR_FAIL; - PR_EnterMonitor(vr_monitor); + if (vr_lock == NULL) + return REGERR_FAIL; #endif + PR_Lock(vr_lock); if (!isInited) { @@ -166,9 +177,6 @@ static REGERR vr_Init(void) err = REGERR_MEMORY; } } - else { - err = REGERR_PARAM; - } if ( err != REGERR_OK ) goto done; @@ -177,15 +185,12 @@ static REGERR vr_Init(void) #endif /* Open version registry */ - err = NR_RegOpen( regname, &vreg ); + err = NR_RegOpen( regname, &vreg ); #ifndef STANDALONE_REGISTRY - if (err == REGERR_NOFILE) { - /* create it if not found */ - err = VR_CreateRegistry( VERSION_NAME, app_dir, "" ); - } - else if (err == REGERR_OK) { - /* otherwise find/set the current nav node */ + if (err == REGERR_OK) + { + /* find/set the current nav node */ err = vr_SetCurrentNav( VERSION_NAME, app_dir, NULL ); if ( REGERR_OK != err ) { /* couldn't find or set current nav -- big problems! */ @@ -213,20 +218,20 @@ static REGERR vr_Init(void) } #endif - if (err == REGERR_OK) { + if (err == REGERR_OK) { /* successfully opened! */ isInited = 1; } goto done; #else - if (err != REGERR_OK) - goto done; + if (err != REGERR_OK) + goto done; - /* Determine 'curver' key and ensure correct structure by adding */ + /* Determine 'curver' key and ensure correct structure by adding */ /* ...find top-level "Navigator" node (add if missing) */ - err = NR_RegAddKey( vreg, ROOTKEY_VERSIONS, NAVIGATOR_NODE, &navKey ); - if (err != REGERR_OK) + err = NR_RegAddKey( vreg, ROOTKEY_VERSIONS, NAVIGATOR_NODE, &navKey ); + if (err != REGERR_OK) goto done; /* ...look for "Current Version" entry */ @@ -243,7 +248,7 @@ static REGERR vr_Init(void) /* ...look for "curstr" child key of the navigator node */ err = NR_RegAddKey( vreg, navKey, curstr, &curver ); - if (err == REGERR_OK) { + if (err == REGERR_OK) { /* successfully opened! */ isInited = 1; } @@ -251,15 +256,13 @@ static REGERR vr_Init(void) } done: -#ifndef STANDALONE_REGISTRY - PR_ExitMonitor(vr_monitor); -#ifdef XP_UNIX + PR_Unlock(vr_lock); +#if defined(XP_UNIX) && !defined(STANDALONE_REGISTRY) XP_FREEIF(regbuf); -#endif #endif return err; -} /* Init */ +} /* Init */ @@ -297,35 +300,35 @@ static Bool vr_CompareDirs( char *dir1, char *dir2 ) REGERR 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++; - } - } - } + 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; + return REGERR_OK; -} /* ParseVersion */ +} /* ParseVersion */ @@ -335,67 +338,67 @@ REGERR vr_ParseVersion(char *verstr, VERSION *result) static REGERR vr_GetCheck(char *path, int32 *check) { - int fh; - char *buf; - int actual; - char *p; - int i; - int chk; + int fh; + char *buf; + int actual; + char *p; + int i; + int chk; - XP_ASSERT(path); - XP_ASSERT(check); - - *check = chk = 0; + XP_ASSERT(path); + XP_ASSERT(check); + + *check = chk = 0; #ifdef NEED_XP_FIXES - /* open file for read */ - fh = open(path, O_RDONLY| O_BINARY); - if (fh < 0) - { - switch (errno) - { - case ENOENT: /* file not found */ - return REGERR_NOFILE; + /* open file for read */ + fh = open(path, O_RDONLY| O_BINARY); + if (fh < 0) + { + switch (errno) + { + case ENOENT: /* file not found */ + return REGERR_NOFILE; - case EACCES: /* file in use */ - + case EACCES: /* file in use */ + #ifdef EMFILE - case EMFILE: /* too many files open */ + case EMFILE: /* too many files open */ #endif - default: - return REGERR_FAIL; - } - } + default: + return REGERR_FAIL; + } + } - buf = malloc(BLKSIZ); - if (!buf) - { - close(fh); - return REGERR_MEMORY; - } + buf = malloc(BLKSIZ); + if (!buf) + { + close(fh); + return REGERR_MEMORY; + } - do - { - /* read a block */ - actual = read(fh, buf, BLKSIZ); - /* add to checksum */ - for (p=buf, i=0; i sizebuf) - err = REGERR_BUFTOOSMALL; - else - XP_STRCPY(buf, tempBuf); - - XP_FREE(tempBuf); + else + { + if (XP_STRLEN(tempBuf) > sizebuf) + err = REGERR_BUFTOOSMALL; + else + XP_STRCPY(buf, tempBuf); + + XP_FREE(tempBuf); } - } - else - { - /* what did we put here?? */ - err = REGERR_BADTYPE; - } + } + else + { + /* what did we put here?? */ + err = REGERR_BADTYPE; + } return err; @@ -488,27 +491,29 @@ static REGERR vr_SetCurrentNav( char *installation, char *programPath, char *ver { REGERR err; REGENUM state; - RKEY navKey; + RKEY navKey; int bFound; int nCopy; char regname[MAXREGNAMELEN]; char dirbuf[MAXREGNAMELEN]; - err = NR_RegAddKey( vreg, ROOTKEY_VERSIONS, NAVIGATOR_NODE, &navKey ); - if (err != REGERR_OK) - goto done; + err = NR_RegAddKey( vreg, ROOTKEY_VERSIONS, NAVIGATOR_NODE, &navKey ); + if (err != REGERR_OK) + goto done; /* ...look for "Current Version" entry */ err = NR_RegGetEntryString( vreg, navKey, CURRENT_VER, curstr, sizeof(curstr)); if ( err == REGERR_NOFIND ) { /* No current installation, we can simply add a new one */ - err = NR_RegAddKey( vreg, navKey, installation, &curver ); + err = NR_RegAddKey( vreg, navKey, installation, &curver ); /* ... add Path and Version properties */ - if ( err == REGERR_OK ) { + if ( err == REGERR_OK ) + { err = vr_SetPathname( vreg, curver, NAVHOME, programPath ); - if ( REGERR_OK == err && versionStr != NULL) { + if ( REGERR_OK == err && versionStr != NULL && *versionStr != '\0') + { err = NR_RegSetEntryString( vreg, curver, VERSTR, versionStr ); } } @@ -518,8 +523,8 @@ static REGERR vr_SetCurrentNav( char *installation, char *programPath, char *ver err = NR_RegSetEntryString(vreg, navKey, CURRENT_VER, installation); } - if (err != REGERR_OK) - goto done; + if (err != REGERR_OK) + goto done; } else if ( REGERR_OK == err ) { @@ -563,7 +568,7 @@ static REGERR vr_SetCurrentNav( char *installation, char *programPath, char *ver if (bFound) { err = NR_RegSetEntryString( vreg, navKey, CURRENT_VER, curstr ); /* update version (curver already set) */ - if ( REGERR_OK == err && versionStr != NULL ) { + if ( REGERR_OK == err && versionStr != NULL && *versionStr != '\0' ) { err = NR_RegSetEntryString( vreg, curver, VERSTR, versionStr ); } } @@ -591,7 +596,7 @@ static REGERR vr_SetCurrentNav( char *installation, char *programPath, char *ver /* add path and version properties */ err = vr_SetPathname( vreg, curver, NAVHOME, programPath ); - if ( REGERR_OK == err && versionStr != NULL ) { + if ( REGERR_OK == err && versionStr != NULL && *versionStr != '\0' ) { err = NR_RegSetEntryString( vreg, curver, VERSTR, versionStr ); } @@ -627,7 +632,7 @@ static REGERR vr_FindKey(char *component_path, HREG *hreg, RKEY *key) #endif { *hreg = vreg; - rootkey = PATH_ROOT(component_path); + rootkey = PATH_ROOT(component_path); err = NR_RegGetKey( *hreg, rootkey, component_path, key ); } @@ -663,94 +668,72 @@ VR_INTERFACE(REGERR) VR_PackRegistry(void *userData, nr_RegPackCallbackFunc fn) #endif /* STANDALONE_REGISTRY */ - +#ifdef STANDALONE_REGISTRY VR_INTERFACE(REGERR) VR_CreateRegistry( char *installation, char *programPath, char *versionStr ) { - FILEHANDLE fh; - REGERR err; -#ifndef STANDALONE_REGISTRY - XP_StatStruct st; -#endif - char * regname = ""; + REGERR err; + char * regname = vr_findVerRegName(); #ifdef XP_UNIX char * regbuf = NULL; #endif - if ( installation == NULL || *installation == '\0' ) - return REGERR_PARAM; - + if ( installation == NULL || *installation == '\0' ) + return REGERR_PARAM; #ifdef XP_UNIX - #ifndef STANDALONE_REGISTRY if (bGlobalRegistry) +#endif { -#endif - - regbuf = (char*)XP_ALLOC( 10 + XP_STRLEN(programPath) ); - if (regbuf == NULL) - return REGERR_MEMORY; - - XP_STRCPY( regbuf, programPath ); - XP_STRCAT( regbuf, "registry" ); - regname = regbuf; + regbuf = (char*)XP_ALLOC( 10 + XP_STRLEN(programPath) ); + if (regbuf == NULL) + return REGERR_MEMORY; -#ifndef STANDALONE_REGISTRY + XP_STRCPY( regbuf, programPath ); + XP_STRCAT( regbuf, "registry" ); + regname = regbuf; } -#endif - #endif /* XP_UNIX */ + PR_Lock(vr_lock); + /* automatically creates it if not found */ + err = NR_RegOpen( regname, &vreg ); + if (err == REGERR_OK) + { + /* create default tree with 'installation' under Navigator */ + /* set Current to the installation string */ -#ifdef STANDALONE_REGISTRY - /* standalone registry automatically creates it if not found */ - fh = vr_fileOpen( regname, XP_FILE_UPDATE_BIN ); -#else - if ( ( XP_Stat ( regname, &st, xpRegistry ) == 0) ) - fh = vr_fileOpen( regname, XP_FILE_UPDATE_BIN ); - else - /* create a new empty registry */ - fh = vr_fileOpen( regname, XP_FILE_WRITE_BIN ); -#endif + err = vr_SetCurrentNav( installation, programPath, versionStr ); - if (fh == NULL) { - err = REGERR_FAIL; - goto done; + if ( REGERR_OK == err ) + isInited = 1; + else + NR_RegClose( vreg ); } - XP_FileClose(fh); - err = NR_RegOpen( regname, &vreg ); - if (err != REGERR_OK) - goto done; + PR_Unlock(vr_lock); - /* create default tree with 'installation' under Navigator */ - /* set Current to the installation string */ - - err = vr_SetCurrentNav( installation, programPath, versionStr ); - - if ( REGERR_OK == err ) - isInited = 1; - -done: -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) +#if defined(XP_UNIX) XP_FREEIF( regbuf ); #endif - return err; + return err; -} /* CreateRegistry */ +} /* CreateRegistry */ +#endif VR_INTERFACE(REGERR) VR_Close(void) { - REGERR err = REGERR_OK; + REGERR err = REGERR_OK; #ifndef STANDALONE_REGISTRY - if (vr_monitor == NULL) - return REGERR_FAIL; - PR_EnterMonitor(vr_monitor); + if (vr_lock == NULL) + return REGERR_FAIL; #endif + PR_Lock(vr_lock); + if (isInited) { #if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) if ( unixreg != NULL ) @@ -760,211 +743,190 @@ VR_INTERFACE(REGERR) VR_Close(void) isInited = 0; } -#ifndef STANDALONE_REGISTRY - PR_ExitMonitor(vr_monitor); -#endif + PR_Unlock(vr_lock); return err; -} /* Close */ +} /* Close */ + + VR_INTERFACE(REGERR) VR_GetVersion(char *component_path, VERSION *result) { - REGERR err; - RKEY key; - HREG hreg; - VERSION ver; - char buf[MAXREGNAMELEN]; -#if defined(STANDALONE_REGISTRY) || !defined(XP_UNIX) - RKEY rootkey; -#endif + REGERR err; + RKEY key; + HREG hreg; + VERSION ver; + char buf[MAXREGNAMELEN]; - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; + + hreg = vreg; - hreg = vreg; - -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) err = vr_FindKey( component_path, &hreg, &key ); -#else - rootkey = PATH_ROOT(component_path); - err = NR_RegGetKey( vreg, rootkey, component_path, &key ); -#endif - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; err = NR_RegGetEntryString( hreg, key, VERSTR, buf, sizeof(buf) ); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; - vr_ParseVersion(buf, &ver); + vr_ParseVersion(buf, &ver); - memcpy(result, &ver, sizeof(VERSION)); + memcpy(result, &ver, sizeof(VERSION)); + + return REGERR_OK; + +} /* GetVersion */ - return REGERR_OK; -} /* GetVersion */ VR_INTERFACE(REGERR) VR_GetPath(char *component_path, uint32 sizebuf, char *buf) { - REGERR err; - RKEY key; - HREG hreg; -#if defined(STANDALONE_REGISTRY) || !defined(XP_UNIX) - RKEY rootkey; -#endif + REGERR err; + RKEY key; + HREG hreg; - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; + + hreg = vreg; - hreg = vreg; - -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) err = vr_FindKey( component_path, &hreg, &key ); -#else - rootkey = PATH_ROOT(component_path); - err = NR_RegGetKey( vreg, rootkey, component_path, &key ); -#endif - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; err = vr_GetPathname( hreg, key, PATHSTR, buf, sizebuf ); - return err; + return err; + +} /* GetPath */ + -} /* GetPath */ VR_INTERFACE(REGERR) VR_SetDefaultDirectory(char *component_path, char *directory) { - REGERR err; - RKEY rootkey; - RKEY key; + REGERR err; + RKEY rootkey; + RKEY key; - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; - rootkey = PATH_ROOT(component_path); + rootkey = PATH_ROOT(component_path); err = NR_RegGetKey( vreg, rootkey, component_path, &key ); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; -/* err = NR_RegSetEntryString( vreg, key, DIRSTR, directory ); */ err = vr_SetPathname( vreg, key, DIRSTR, directory ); - return err; + return err; } VR_INTERFACE(REGERR) VR_GetDefaultDirectory(char *component_path, uint32 sizebuf, char *buf) { - REGERR err; - RKEY key; - HREG hreg; -#if defined(STANDALONE_REGISTRY) || !defined(XP_UNIX) - RKEY rootkey; -#endif - err = vr_Init(); - if (err != REGERR_OK) - return err; + REGERR err; + RKEY key; + HREG hreg; + + err = vr_Init(); + if (err != REGERR_OK) + return err; + + hreg = vreg; - hreg = vreg; - -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) err = vr_FindKey( component_path, &hreg, &key ); -#else - rootkey = PATH_ROOT(component_path); - err = NR_RegGetKey( vreg, rootkey, component_path, &key ); -#endif - if (err != REGERR_OK) - return err; - -/* err = NR_RegGetEntryString( vreg, key, DIRSTR, buf, sizebuf ); */ + if (err != REGERR_OK) + return err; + err = vr_GetPathname( hreg, key, DIRSTR, buf, sizebuf ); - return err; + return err; } VR_INTERFACE(REGERR) VR_Install(char *component_path, char *filepath, char *version, int bDirectory) { - REGERR err; - RKEY rootKey; - RKEY key; + REGERR err; + RKEY rootKey; + RKEY key; - /* Initialize the registry in case this is first call */ - err = vr_Init(); - if (err != REGERR_OK) - return err; + /* Initialize the registry in case this is first call */ + err = vr_Init(); + if (err != REGERR_OK) + return err; - /* Use curver if path is relative */ - rootKey = PATH_ROOT(component_path); + /* Use curver if path is relative */ + rootKey = PATH_ROOT(component_path); - /* Make sure path components (keys) exist by calling Add */ + /* Make sure path components (keys) exist by calling Add */ /* (special "" component must always exist, and Add fails) */ if ( component_path != NULL && *component_path == '\0' ) { err = NR_RegGetKey( vreg, rootKey, component_path, &key ); } else { - err = NR_RegAddKey( vreg, rootKey, component_path, &key ); + err = NR_RegAddKey( vreg, rootKey, component_path, &key ); } - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; - if ( version != NULL && *version != '\0' ) { + if ( version != NULL && *version != '\0' ) { /* Add "Version" entry with values like "4.0.0.0" */ - err = NR_RegSetEntryString( vreg, key, VERSTR, version ); - if (err != REGERR_OK) - goto abort; + err = NR_RegSetEntryString( vreg, key, VERSTR, version ); + if (err != REGERR_OK) + goto abort; } if ( filepath != NULL && *filepath != '\0' ) { /* add "Path" entry */ err = vr_SetPathname( vreg, key, (bDirectory)?DIRSTR:PATHSTR, filepath ); - if (err != REGERR_OK) - goto abort; + if (err != REGERR_OK) + goto abort; } - return REGERR_OK; + return REGERR_OK; abort: - NR_RegDeleteKey( vreg, rootKey, component_path ); - return err; + NR_RegDeleteKey( vreg, rootKey, component_path ); + return err; -} /* Install */ +} /* Install */ VR_INTERFACE(REGERR) VR_Remove(char *component_path) { - REGERR err; - RKEY rootkey; + REGERR err; + RKEY rootkey; - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; - rootkey = PATH_ROOT(component_path); + rootkey = PATH_ROOT(component_path); - return NR_RegDeleteKey( vreg, rootkey, component_path ); + return NR_RegDeleteKey( vreg, rootkey, component_path ); -} /* Remove */ +} /* Remove */ VR_INTERFACE(REGERR) VR_Enum(char *component_path, REGENUM *state, char *buffer, uint32 buflen) { - REGERR err; + REGERR err; RKEY rootkey; - RKEY key; - + RKEY key; + err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( component_path == NULL ) rootkey = ROOTKEY_VERSIONS; @@ -972,8 +934,8 @@ VR_INTERFACE(REGERR) VR_Enum(char *component_path, REGENUM *state, rootkey = PATH_ROOT(component_path); err = NR_RegGetKey( vreg, rootkey, component_path, &key ); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; err = NR_RegEnumSubkeys( vreg, key, state, buffer, buflen, REGENUM_DEPTH_FIRST); @@ -983,56 +945,38 @@ VR_INTERFACE(REGERR) VR_Enum(char *component_path, REGENUM *state, VR_INTERFACE(REGERR) VR_InRegistry(char *component_path) { - REGERR err; - RKEY key; -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) - HREG hreg; -#else - RKEY rootkey; -#endif + REGERR err; + RKEY key; + HREG hreg; - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) return vr_FindKey( component_path, &hreg, &key ); -#else - rootkey = PATH_ROOT(component_path); - return NR_RegGetKey( vreg, rootkey, component_path, &key ); -#endif -} /* InRegistry */ +} /* InRegistry */ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path) { - REGERR err; - RKEY key; - char path[MAXREGPATHLEN]; -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) - HREG hreg; -#else - RKEY rootkey; -#endif + REGERR err; + RKEY key; + char path[MAXREGPATHLEN]; + HREG hreg; #ifdef USE_CHECKSUM - char buf[MAXREGNAMELEN]; - long calculatedCheck; - int storedCheck; + char buf[MAXREGNAMELEN]; + long calculatedCheck; + int storedCheck; #endif - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) err = vr_FindKey( component_path, &hreg, &key ); -#else - rootkey = PATH_ROOT(component_path); - err = NR_RegGetKey( vreg, rootkey, component_path, &key ); -#endif if ( err != REGERR_OK ) return err; @@ -1056,114 +1000,119 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path) #if defined(USE_CHECKSUM) && !defined(XP_UNIX) - err = NR_RegGetEntryString( vreg, key, CHKSTR, buf, sizeof(buf) ); - if (err != REGERR_OK) - return err; - - storedCheck = atoi(buf); - - err = vr_GetCheck(filepath, &calculatedCheck); + err = NR_RegGetEntryString( vreg, key, CHKSTR, buf, sizeof(buf) ); if (err != REGERR_OK) return err; - if (storedCheck != calculatedCheck) - { - /* printf("File %s checksum was %d, not %d as expected.\n", - filepath, calculatedCheck, storedCheck); - */ - return REGERR_BADCHECK; - } + storedCheck = atoi(buf); + + err = vr_GetCheck(filepath, &calculatedCheck); + if (err != REGERR_OK) + return err; + + if (storedCheck != calculatedCheck) + { + return REGERR_BADCHECK; + } #endif /* USE_CHECKSUM */ - return REGERR_OK; + return REGERR_OK; + +} /* CheckEntry */ + -} /* CheckEntry */ VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path) { - char *tmp; + char *tmp; - tmp = XP_STRDUP(path); - if (NULL == tmp) { - return REGERR_MEMORY; - } + tmp = XP_STRDUP(path); + if (NULL == tmp) { + return REGERR_MEMORY; + } - XP_FREEIF(app_dir); - app_dir = tmp; + PR_Lock(vr_lock); - return REGERR_OK; + XP_FREEIF(app_dir); + app_dir = tmp; + + PR_Unlock(vr_lock); + + return REGERR_OK; } + + VR_INTERFACE(REGERR) VR_SetRefCount(char *component_path, int refcount) { - REGERR err; - RKEY rootKey; - RKEY key; + REGERR err; + RKEY rootKey; + RKEY key; char rcstr[MAXREGNAMELEN]; err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; - /* Use curver if path is relative */ - rootKey = PATH_ROOT(component_path); + /* Use curver if path is relative */ + rootKey = PATH_ROOT(component_path); - /* Make sure path components (keys) exist by calling Add */ + /* Make sure path components (keys) exist by calling Add */ /* (special "" component must always exist, and Add fails) */ if ( component_path != NULL && *component_path == '\0' ) { err = REGERR_PARAM; } else { - err = NR_RegAddKey( vreg, rootKey, component_path, &key ); + err = NR_RegAddKey( vreg, rootKey, component_path, &key ); } - - if (err != REGERR_OK) - return err; + + if (err != REGERR_OK) + return err; *rcstr = '\0'; - /* itoa(refcount, rcstr, 10); */ - XP_SPRINTF(rcstr, "%d", refcount); - - if ( rcstr != NULL && *rcstr != '\0' ) { + /* itoa(refcount, rcstr, 10); */ + XP_SPRINTF(rcstr, "%d", refcount); + + if ( rcstr != NULL && *rcstr != '\0' ) { /* Add "RefCount" */ - err = NR_RegSetEntryString( vreg, key, REFCSTR, rcstr ); + err = NR_RegSetEntryString( vreg, key, REFCSTR, rcstr ); } return err; -} /* SetRefCount */ +} /* SetRefCount */ VR_INTERFACE(REGERR) VR_GetRefCount(char *component_path, int *result) { - REGERR err; - RKEY rootkey; + REGERR err; + RKEY rootkey; RKEY key; - char buf[MAXREGNAMELEN]; + char buf[MAXREGNAMELEN]; *result = -1; - err = vr_Init(); - if (err != REGERR_OK) - return err; + err = vr_Init(); + if (err != REGERR_OK) + return err; /* "Uninstall" only happens in the writable registry, so no * need to search the shared one on Unix using vr_FindKey() */ rootkey = PATH_ROOT(component_path); err = NR_RegGetKey( vreg, rootkey, component_path, &key ); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; err = NR_RegGetEntryString( vreg, key, REFCSTR, buf, sizeof(buf) ); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; *result = atoi( buf ); - return REGERR_OK; + return REGERR_OK; -} /* GetRefCount */ +} /* GetRefCount */ #ifdef XP_MAC #pragma export reset @@ -1351,14 +1300,14 @@ static REGERR vr_unmanglePackageName(char *mangledPackageName, char *regPackageN VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPackageName) { - REGERR err; - RKEY key; + REGERR err; + RKEY key; char *regbuf; uint32 regbuflen = 0; err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( regPackageName == NULL ) err = REGERR_PARAM; @@ -1374,7 +1323,7 @@ VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPack if (err != REGERR_OK) { XP_FREE(regbuf); - return err; + return err; } err = NR_RegAddKey( vreg, ROOTKEY_PRIVATE, regbuf, &key ); XP_FREE(regbuf); @@ -1384,25 +1333,25 @@ VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPack err = REGERR_MEMORY; } - if (err == REGERR_OK) + if (err == REGERR_OK) err = NR_RegSetEntryString( vreg, key, PACKAGENAMESTR, userPackageName ); - return err; + return err; -} /* UninstallCreateNode */ +} /* UninstallCreateNode */ VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, uint32 buflen) { - REGERR err; - RKEY key; + REGERR err; + RKEY key; char *regbuf = NULL; char *convertedName = NULL; uint32 convertedDataLength = 0; uint32 regbuflen = 0; err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( regPackageName == NULL || *regPackageName == '\0' || outbuf == NULL ) return REGERR_PARAM; @@ -1417,7 +1366,7 @@ VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, err = vr_convertPackageName(regPackageName, convertedName, convertedDataLength); if (err != REGERR_OK) { XP_FREE(convertedName); - return err; + return err; } regbuflen = 256 + XP_STRLEN(convertedName); regbuf = (char*)XP_ALLOC( regbuflen ); @@ -1435,22 +1384,22 @@ VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, err = NR_RegGetEntryString( vreg, key, PACKAGENAMESTR, outbuf, buflen ); XP_FREE(convertedName); - return err; + return err; -} /* GetUninstallName */ +} /* GetUninstallName */ VR_INTERFACE(REGERR) VR_UninstallAddFileToList(char *regPackageName, char *vrName) { - REGERR err; - RKEY key; + REGERR err; + RKEY key; char *regbuf; uint32 regbuflen = 0; uint32 curregbuflen = 0; uint32 len = 0; - + err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( regPackageName == NULL ) err = REGERR_PARAM; @@ -1482,30 +1431,30 @@ VR_INTERFACE(REGERR) VR_UninstallAddFileToList(char *regPackageName, char *vrNam err = REGERR_MEMORY; } - if (err != REGERR_OK) + if (err != REGERR_OK) { - return err; + return err; } err = NR_RegSetEntryString( vreg, key, vrName, ""); return err; -} /* UninstallAddFileToList */ +} /* UninstallAddFileToList */ VR_INTERFACE(REGERR) VR_UninstallFileExistsInList(char *regPackageName, char *vrName) { - REGERR err; - RKEY key; + REGERR err; + RKEY key; char *regbuf; char sharedfilesstr[MAXREGNAMELEN]; uint32 regbuflen = 0; uint32 curregbuflen = 0; uint32 len = 0; - + err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( regPackageName == NULL ) err = REGERR_PARAM; @@ -1536,22 +1485,22 @@ VR_INTERFACE(REGERR) VR_UninstallFileExistsInList(char *regPackageName, char *vr { err = REGERR_MEMORY; } - + if (err != REGERR_OK) { - return err; + return err; } err = NR_RegGetEntryString( vreg, key, vrName, sharedfilesstr, sizeof(sharedfilesstr) ); return err; -} /* UninstallFileExistsInList */ +} /* UninstallFileExistsInList */ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM *state, char *buffer, uint32 buflen) { - REGERR err; + REGERR err; RKEY key; char *regbuf; char *converted_component_path; @@ -1561,8 +1510,8 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * uint32 len = 0; err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( component_path == NULL ) return REGERR_PARAM; @@ -1577,7 +1526,7 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * if (err != REGERR_OK) { XP_FREEIF(converted_component_path); - return err; + return err; } regbuflen = 256 + XP_STRLEN(converted_component_path); @@ -1607,7 +1556,7 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * XP_FREE(converted_component_path); if (err != REGERR_OK) - return err; + return err; err = NR_RegEnumEntries( vreg, key, state, buffer, buflen, NULL); @@ -1617,18 +1566,18 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * VR_INTERFACE(REGERR) VR_UninstallDeleteFileFromList(char *component_path, char *vrName) { - REGERR err; - RKEY key; + REGERR err; + RKEY key; char *regbuf; char *converted_component_path; uint32 convertedDataLength = 0; uint32 regbuflen = 0; uint32 curregbuflen = 0; uint32 len = 0; - + err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( component_path == NULL ) err = REGERR_PARAM; @@ -1646,7 +1595,7 @@ VR_INTERFACE(REGERR) VR_UninstallDeleteFileFromList(char *component_path, char * if (err != REGERR_OK) { XP_FREEIF(converted_component_path); - return err; + return err; } regbuflen = 256 + XP_STRLEN(converted_component_path); @@ -1672,32 +1621,32 @@ VR_INTERFACE(REGERR) VR_UninstallDeleteFileFromList(char *component_path, char * { err = REGERR_MEMORY; } - + XP_FREE(converted_component_path); if (err != REGERR_OK) { - return err; + return err; } err = NR_RegDeleteEntry( vreg, key, vrName); return err; -} /* UninstallDeleteFileFromList */ +} /* UninstallDeleteFileFromList */ VR_INTERFACE(REGERR) VR_UninstallDeleteSharedFilesKey(char *component_path) { - REGERR err; - char *regbuf; + REGERR err; + char *regbuf; char *converted_component_path; uint32 convertedDataLength = 0; uint32 regbuflen = 0; uint32 curregbuflen = 0; uint32 len = 0; - + err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( component_path == NULL ) err = REGERR_PARAM; @@ -1712,7 +1661,7 @@ VR_INTERFACE(REGERR) VR_UninstallDeleteSharedFilesKey(char *component_path) if (err != REGERR_OK) { XP_FREEIF(converted_component_path); - return err; + return err; } regbuflen = 256 + XP_STRLEN(converted_component_path); @@ -1742,19 +1691,19 @@ VR_INTERFACE(REGERR) VR_UninstallDeleteSharedFilesKey(char *component_path) XP_FREE(converted_component_path); return err; -} /* UninstallDeleteSharedFilesKey */ +} /* UninstallDeleteSharedFilesKey */ VR_INTERFACE(REGERR) VR_UninstallDestroy(char *component_path) { - REGERR err; + REGERR err; char *regbuf; char *converted_component_path; uint32 convertedDataLength = 0; uint32 regbuflen = 0; - + err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; if ( component_path == NULL ) err = REGERR_PARAM; @@ -1769,7 +1718,7 @@ VR_INTERFACE(REGERR) VR_UninstallDestroy(char *component_path) if (err != REGERR_OK) { XP_FREEIF(converted_component_path); - return err; + return err; } regbuflen = 256 + XP_STRLEN(converted_component_path); @@ -1791,24 +1740,24 @@ VR_INTERFACE(REGERR) VR_UninstallDestroy(char *component_path) { err = REGERR_MEMORY; } - + XP_FREE(converted_component_path); return err; -} /* UninstallDestroy */ +} /* UninstallDestroy */ VR_INTERFACE(REGERR) VR_EnumUninstall(REGENUM *state, char* userPackageName, int32 len1, char*regPackageName, int32 len2, Bool bSharedList) { - REGERR err; + REGERR err; RKEY key; RKEY key1; char regbuf[MAXREGPATHLEN+1] = {0}; char temp[MAXREGPATHLEN+1] = {0}; err = vr_Init(); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; XP_STRCPY( regbuf, REG_UNINSTALL_DIR ); if (bSharedList) @@ -1821,8 +1770,8 @@ VR_INTERFACE(REGERR) VR_EnumUninstall(REGENUM *state, char* userPackageName, } err = NR_RegGetKey( vreg, ROOTKEY_PRIVATE, regbuf, &key ); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; *regbuf = '\0'; *userPackageName = '\0'; @@ -1837,17 +1786,17 @@ VR_INTERFACE(REGERR) VR_EnumUninstall(REGENUM *state, char* userPackageName, } } if (err != REGERR_OK) - return err; + return err; err = NR_RegGetKey( vreg, key, regbuf, &key1 ); if (err != REGERR_OK) - return err; + return err; err = NR_RegGetEntryString( vreg, key1, PACKAGENAMESTR, userPackageName, len1); if (err != REGERR_OK) { - *userPackageName = '\0'; + *userPackageName = '\0'; return err; } diff --git a/mozilla/modules/libreg/src/reg.c b/mozilla/modules/libreg/src/reg.c index 4f60f740c91..6dcfcf6f7a9 100644 --- a/mozilla/modules/libreg/src/reg.c +++ b/mozilla/modules/libreg/src/reg.c @@ -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 */ /* ==================================================================== * reg.c @@ -22,15 +28,15 @@ */ /* TODO: - * - Replace 'malloc' in NR_RegPack with the Netscape XP equivalent - * - Solve DOS 'errno' problem mentioned below - * - Solve rename across volume problem described in VR_PackRegistry + * - Replace 'malloc' in NR_RegPack with the Netscape XP equivalent + * - Solve DOS 'errno' problem mentioned below + * - Solve rename across volume problem described in VR_PackRegistry */ /* Preprocessor Defines * STANDALONE_REGISTRY - define if not linking with Navigator - * NOCACHE_HDR - define if multi-threaded access to registry - * SELF_REPAIR - define to skip header update on open + * NOCACHE_HDR - define if multi-threaded access to registry + * SELF_REPAIR - define to skip header update on open * VERIFY_READ - define TRUE to double-check short reads */ #define NOCACHE_HDR 1 @@ -149,31 +155,31 @@ char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength); */ void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length) { - OSErr err; - FSSpec fs; - AliasHandle macAlias; - *alias = NULL; - *length = 0; - c2pstr((char*)fileName); - err = FSMakeFSSpec(0, 0, (unsigned char *)fileName, &fs); - p2cstr((unsigned char *)fileName); - if ( err != noErr ) - return; - err = NewAlias(NULL, &fs, &macAlias); - if ( (err != noErr) || ( macAlias == NULL )) - return; - *length = GetHandleSize( (Handle) macAlias ); - *alias = XP_ALLOC( *length ); - if ( *alias == NULL ) - { - DisposeHandle((Handle)macAlias); - return; - } - HLock( (Handle) macAlias ); - XP_MEMCPY(*alias, *macAlias , *length); - HUnlock( (Handle) macAlias ); - DisposeHandle( (Handle) macAlias); - return; + OSErr err; + FSSpec fs; + AliasHandle macAlias; + *alias = NULL; + *length = 0; + c2pstr((char*)fileName); + err = FSMakeFSSpec(0, 0, (unsigned char *)fileName, &fs); + p2cstr((unsigned char *)fileName); + if ( err != noErr ) + return; + err = NewAlias(NULL, &fs, &macAlias); + if ( (err != noErr) || ( macAlias == NULL )) + return; + *length = GetHandleSize( (Handle) macAlias ); + *alias = XP_ALLOC( *length ); + if ( *alias == NULL ) + { + DisposeHandle((Handle)macAlias); + return; + } + HLock( (Handle) macAlias ); + XP_MEMCPY(*alias, *macAlias , *length); + HUnlock( (Handle) macAlias ); + DisposeHandle( (Handle) macAlias); + return; } /* resolves an alias, and returns a full path to the Mac file @@ -181,65 +187,65 @@ void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length) */ char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength) { - OSErr err; - short vRefNum; - long dirID; - AliasHandle h = NULL; - Handle fullPath = NULL; - short fullPathLength; - char * cpath = NULL; - FSSpec fs; - Boolean ignore; /* Change flag, it would be nice to change the alias on disk - if the file location changed */ - - - XP_MEMSET( &fs, '\0', sizeof(FSSpec) ); - - - /* Copy the alias to a handle and resolve it */ - h = (AliasHandle) NewHandle(aliasLength); - if ( h == NULL) - goto fail; - - - HLock( (Handle) h); - XP_MEMCPY( *h, alias, aliasLength ); - HUnlock( (Handle) h); - - - err = ResolveAlias(NULL, h, &fs, &ignore); - if (err != noErr) - goto fail; - - /* if the file is inside the trash, assume that user has deleted - it and that we do not want to look at it */ - err = FindFolder(fs.vRefNum, kTrashFolderType, false, &vRefNum, &dirID); - if (err == noErr) - if (dirID == fs.parID) /* File is inside the trash */ - goto fail; - - /* Get the full path and create a char * out of it */ + OSErr err; + short vRefNum; + long dirID; + AliasHandle h = NULL; + Handle fullPath = NULL; + short fullPathLength; + char * cpath = NULL; + FSSpec fs; + Boolean ignore; /* Change flag, it would be nice to change the alias on disk + if the file location changed */ + + + XP_MEMSET( &fs, '\0', sizeof(FSSpec) ); + + + /* Copy the alias to a handle and resolve it */ + h = (AliasHandle) NewHandle(aliasLength); + if ( h == NULL) + goto fail; + + + HLock( (Handle) h); + XP_MEMCPY( *h, alias, aliasLength ); + HUnlock( (Handle) h); + + + err = ResolveAlias(NULL, h, &fs, &ignore); + if (err != noErr) + goto fail; + + /* if the file is inside the trash, assume that user has deleted + it and that we do not want to look at it */ + err = FindFolder(fs.vRefNum, kTrashFolderType, false, &vRefNum, &dirID); + if (err == noErr) + if (dirID == fs.parID) /* File is inside the trash */ + goto fail; + + /* Get the full path and create a char * out of it */ - err = GetFullPath(fs.vRefNum, fs.parID,fs.name, &fullPathLength, &fullPath); - if ( (err != noErr) || (fullPath == NULL) ) - goto fail; - - cpath = (char*) XP_ALLOC(fullPathLength + 1); - if ( cpath == NULL) - goto fail; - - HLock( fullPath ); - XP_MEMCPY(cpath, *fullPath, fullPathLength); - cpath[fullPathLength] = 0; - HUnlock( fullPath ); - - /* Drop through */ + err = GetFullPath(fs.vRefNum, fs.parID,fs.name, &fullPathLength, &fullPath); + if ( (err != noErr) || (fullPath == NULL) ) + goto fail; + + cpath = (char*) XP_ALLOC(fullPathLength + 1); + if ( cpath == NULL) + goto fail; + + HLock( fullPath ); + XP_MEMCPY(cpath, *fullPath, fullPathLength); + cpath[fullPathLength] = 0; + HUnlock( fullPath ); + + /* Drop through */ fail: - if (h != NULL) - DisposeHandle( (Handle) h); - if (fullPath != NULL) - DisposeHandle( fullPath); - return cpath; + if (h != NULL) + DisposeHandle( (Handle) h); + if (fullPath != NULL) + DisposeHandle( fullPath); + return cpath; } #endif @@ -317,7 +323,7 @@ static REGFILE* vr_findRegFile(char *filename) * -------------------------------------------------------------------- */ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh); -static REGERR nr_CloseFile(FILEHANDLE *fh); /* Note: fh is a pointer */ +static REGERR nr_CloseFile(FILEHANDLE *fh); /* Note: fh is a pointer */ static REGERR nr_ReadFile(FILEHANDLE fh, REGOFF offset, int32 len, void *buffer); static REGERR nr_WriteFile(FILEHANDLE fh, REGOFF offset, int32 len, void *buffer); static REGERR nr_LockRange(FILEHANDLE fh, REGOFF offset, int32 len); @@ -340,14 +346,14 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) #ifdef XP_MAC case fnfErr: #else - case ENOENT: /* file not found */ + case ENOENT: /* file not found */ #endif return REGERR_NOFILE; #ifdef XP_MAC case opWrErr: #else - case EACCES: /* file in use */ + case EACCES: /* file in use */ #endif /* DVNOTE: should we try read only? */ (*fh) = vr_fileOpen(path, XP_FILE_READ_BIN); @@ -355,9 +361,7 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) return REGERR_READONLY; else return REGERR_FAIL; -#ifdef EMFILE /* Mac Does not have EMFILE */ - case EMFILE: /* too many files open */ -#endif + default: return REGERR_FAIL; } @@ -369,52 +373,52 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) #else static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) { - PR_ASSERT( path != NULL ); + PR_ASSERT( path != NULL ); PR_ASSERT( fh != NULL ); - /* Open the file for exclusive random read/write */ - (*fh) = PR_Open(path, PR_RDWR|PR_CREATE_FILE, 00700); - if ( !VALID_FILEHANDLE(*fh) ) - { - switch (PR_GetError()) - { - case PR_FILE_NOT_FOUND_ERROR: /* file not found */ - return REGERR_NOFILE; + /* Open the file for exclusive random read/write */ + (*fh) = PR_Open(path, PR_RDWR|PR_CREATE_FILE, 00644); + if ( !VALID_FILEHANDLE(*fh) ) + { + switch (PR_GetError()) + { + case PR_FILE_NOT_FOUND_ERROR: /* file not found */ + return REGERR_NOFILE; - case PR_FILE_IS_BUSY_ERROR: /* file in use */ - case PR_FILE_IS_LOCKED_ERROR: - case PR_ILLEGAL_ACCESS_ERROR: + case PR_FILE_IS_BUSY_ERROR: /* file in use */ + case PR_FILE_IS_LOCKED_ERROR: + case PR_ILLEGAL_ACCESS_ERROR: case PR_NO_ACCESS_RIGHTS_ERROR: /* DVNOTE: should we try read only? */ - (*fh) = PR_Open(path, PR_RDONLY, 00700); - if ( VALID_FILEHANDLE(*fh) ) + (*fh) = PR_Open(path, PR_RDONLY, 00644); + if ( VALID_FILEHANDLE(*fh) ) return REGERR_READONLY; else return REGERR_FAIL; - default: - return REGERR_FAIL; - } - } + default: + return REGERR_FAIL; + } + } - return REGERR_OK; + return REGERR_OK; -} /* OpenFile */ +} /* OpenFile */ #endif static REGERR nr_CloseFile(FILEHANDLE *fh) { - /* NOTE: 'fh' is a pointer, unlike other Close functions - * This is necessary so that nr_CloseFile can set it to NULL - */ + /* NOTE: 'fh' is a pointer, unlike other Close functions + * This is necessary so that nr_CloseFile can set it to NULL + */ XP_ASSERT( fh != NULL ); - if ( VALID_FILEHANDLE(*fh) ) - XP_FileClose(*fh); - (*fh) = NULL; - return REGERR_OK; + if ( VALID_FILEHANDLE(*fh) ) + XP_FileClose(*fh); + (*fh) = NULL; + return REGERR_OK; -} /* CloseFile */ +} /* CloseFile */ @@ -427,34 +431,34 @@ static REGERR nr_ReadFile(FILEHANDLE fh, REGOFF offset, int32 len, void *buffer) #endif int32 readlen; - REGERR err = REGERR_OK; + REGERR err = REGERR_OK; - XP_ASSERT(len > 0); - XP_ASSERT(buffer != NULL); - XP_ASSERT(fh != NULL); + XP_ASSERT(len > 0); + XP_ASSERT(buffer != NULL); + XP_ASSERT(fh != NULL); #if VERIFY_READ - memset(buffer, FILLCHAR, len); + XP_MEMSET(buffer, FILLCHAR, len); #endif - if (XP_FileSeek(fh, offset, SEEK_SET) != 0 ) { + if (XP_FileSeek(fh, offset, SEEK_SET) != 0 ) { err = REGERR_FAIL; } else { readlen = XP_FileRead(buffer, len, fh ); /* PR_READ() returns an unreliable length, check EOF separately */ - if (readlen < 0) { + if (readlen < 0) { #if !defined(STANDALONE_REGISTRY) || !defined(XP_MAC) - #if defined(STANDALONE_REGISTRY) - if (errno == EBADF) /* bad file handle, not open for read, etc. */ - #else - if (PR_GetError() == PR_BAD_DESCRIPTOR_ERROR) - #endif - err = REGERR_FAIL; - else + #if defined(STANDALONE_REGISTRY) + if (errno == EBADF) /* bad file handle, not open for read, etc. */ + #else + if (PR_GetError() == PR_BAD_DESCRIPTOR_ERROR) + #endif + err = REGERR_FAIL; + else #endif - err = REGERR_BADREAD; - } + err = REGERR_BADREAD; + } else if (readlen < len) { #if VERIFY_READ /* PR_READ() says we hit EOF but return length is unreliable. */ @@ -618,27 +622,27 @@ static void nr_WriteShort(uint16 num, char *buffer) * Block I/O * -------------------------------------------------------------------- */ -static REGERR nr_ReadHdr(REGFILE *reg); /* Reads the file header, creates file if empty */ -static REGERR nr_WriteHdr(REGFILE *reg); /* Writes the file header */ +static REGERR nr_ReadHdr(REGFILE *reg); /* Reads the file header, creates file if empty */ +static REGERR nr_WriteHdr(REGFILE *reg); /* Writes the file header */ static REGERR nr_CreateRoot(REGFILE *reg); static REGERR nr_Lock(REGFILE *reg); static REGERR nr_Unlock(REGFILE *reg); -static REGERR nr_ReadDesc(REGFILE *reg, REGOFF offset, REGDESC *desc); /* reads a desc */ +static REGERR nr_ReadDesc(REGFILE *reg, REGOFF offset, REGDESC *desc); /* reads a desc */ static REGERR nr_ReadName(REGFILE *reg, REGDESC *desc, uint32 buflen, char *buf); static REGERR nr_ReadData(REGFILE *reg, REGDESC *desc, uint32 buflen, char *buf); -static REGERR nr_WriteDesc(REGFILE *reg, REGDESC *desc); /* writes a desc */ -static REGERR nr_WriteString(REGFILE *reg, char *string, REGDESC *desc); /* writes a string */ -static REGERR nr_WriteData(REGFILE *reg, char *string, uint32 len, REGDESC *desc); /* writes a string */ +static REGERR nr_WriteDesc(REGFILE *reg, REGDESC *desc); /* writes a desc */ +static REGERR nr_WriteString(REGFILE *reg, char *string, REGDESC *desc); /* writes a string */ +static REGERR nr_WriteData(REGFILE *reg, char *string, uint32 len, REGDESC *desc); /* writes a string */ -static REGERR nr_AppendDesc(REGFILE *reg, REGDESC *desc, REGOFF *result); /* adds a desc */ -static REGERR nr_AppendName(REGFILE *reg, char *name, REGDESC *desc); /* adds a name */ -static REGERR nr_AppendString(REGFILE *reg, char *string, REGDESC *desc); /* adds a string */ -static REGERR nr_AppendData(REGFILE *reg, char *string, uint32 len, REGDESC *desc); /* adds a string */ +static REGERR nr_AppendDesc(REGFILE *reg, REGDESC *desc, REGOFF *result); /* adds a desc */ +static REGERR nr_AppendName(REGFILE *reg, char *name, REGDESC *desc); /* adds a name */ +static REGERR nr_AppendString(REGFILE *reg, char *string, REGDESC *desc); /* adds a string */ +static REGERR nr_AppendData(REGFILE *reg, char *string, uint32 len, REGDESC *desc); /* adds a string */ -static XP_Bool nr_IsValidUTF8(char *string); /* checks if a string is UTF-8 encoded */ +static XP_Bool nr_IsValidUTF8(char *string); /* checks if a string is UTF-8 encoded */ /* -------------------------------------------------------------------- */ @@ -646,24 +650,24 @@ static XP_Bool nr_IsValidUTF8(char *string); /* checks if a string is UTF-8 enco static REGERR nr_ReadHdr(REGFILE *reg) { - int err; - long filelength; + int err; + long filelength; char hdrBuf[sizeof(REGHDR)]; - XP_ASSERT(reg); - reg->hdrDirty = 0; + XP_ASSERT(reg); + reg->hdrDirty = 0; - err = nr_ReadFile(reg->fh, 0, sizeof(REGHDR), &hdrBuf); + err = nr_ReadFile(reg->fh, 0, sizeof(REGHDR), &hdrBuf); - switch (err) - { - case REGERR_BADREAD: - /* header doesn't exist, so create one */ - err = nr_CreateRoot(reg); - break; + switch (err) + { + case REGERR_BADREAD: + /* header doesn't exist, so create one */ + err = nr_CreateRoot(reg); + break; - case REGERR_OK: - /* header read successfully -- convert */ + case REGERR_OK: + /* header read successfully -- convert */ reg->hdr.magic = nr_ReadLong ( hdrBuf + HDR_MAGIC ); reg->hdr.verMajor = nr_ReadShort( hdrBuf + HDR_VERMAJOR ); reg->hdr.verMinor = nr_ReadShort( hdrBuf + HDR_VERMINOR ); @@ -671,8 +675,8 @@ static REGERR nr_ReadHdr(REGFILE *reg) reg->hdr.root = nr_ReadLong ( hdrBuf + HDR_ROOT ); /* check to see if it's the right file type */ - if (reg->hdr.magic != MAGIC_NUMBER) { - err = REGERR_BADMAGIC; + if (reg->hdr.magic != MAGIC_NUMBER) { + err = REGERR_BADMAGIC; break; } @@ -689,29 +693,29 @@ static REGERR nr_ReadHdr(REGFILE *reg) #if SELF_REPAIR if ( reg->inInit && !(reg->readOnly) ) { - filelength = nr_GetFileLength(reg->fh); - if (reg->hdr.avail != filelength) - { - reg->hdr.avail = filelength; - reg->hdrDirty = 1; + filelength = nr_GetFileLength(reg->fh); + if (reg->hdr.avail != filelength) + { + reg->hdr.avail = filelength; + reg->hdrDirty = 1; #if NOCACHE_HDR - err = nr_WriteHdr(reg); + err = nr_WriteHdr(reg); #endif - } + } } -#endif /* SELF_REPAIR */ - break; +#endif /* SELF_REPAIR */ + break; - default: - /* unexpected error from nr_ReadFile()*/ + default: + /* unexpected error from nr_ReadFile()*/ XP_ASSERT(FALSE); - err = REGERR_FAIL; - break; - } /* switch */ + err = REGERR_FAIL; + break; + } /* switch */ - return err; + return err; -} /* ReadHdr */ +} /* ReadHdr */ @@ -721,7 +725,7 @@ static REGERR nr_WriteHdr(REGFILE *reg) #define HACK_WRITE_ENTIRE_RESERVE 1 #endif - REGERR err; + REGERR err; #if HACK_WRITE_ENTIRE_RESERVE /* * pinkerton @@ -729,12 +733,12 @@ static REGERR nr_WriteHdr(REGFILE *reg) * sure that we write all 128 bytes to push out the EOF to the right location */ char hdrBuf[HDRRESERVE]; - memset(hdrBuf, NULL, HDRRESERVE); + XP_MEMSET(hdrBuf, NULL, HDRRESERVE); #else char hdrBuf[sizeof(REGHDR)]; #endif - XP_ASSERT(reg); + XP_ASSERT(reg); if (reg->readOnly) return REGERR_READONLY; @@ -746,38 +750,38 @@ static REGERR nr_WriteHdr(REGFILE *reg) nr_WriteLong ( reg->hdr.avail, hdrBuf + HDR_AVAIL ); nr_WriteLong ( reg->hdr.root, hdrBuf + HDR_ROOT ); - /* err = nr_WriteFile(reg->fh, 0, sizeof(REGHDR), ®->hdr); */ - err = nr_WriteFile(reg->fh, 0, sizeof(hdrBuf), &hdrBuf); + /* err = nr_WriteFile(reg->fh, 0, sizeof(REGHDR), ®->hdr); */ + err = nr_WriteFile(reg->fh, 0, sizeof(hdrBuf), &hdrBuf); - if (err == REGERR_OK) - reg->hdrDirty = 0; + if (err == REGERR_OK) + reg->hdrDirty = 0; - return err; + return err; -} /* WriteHdr */ +} /* WriteHdr */ static REGERR nr_CreateRoot(REGFILE *reg) { - /* Called when an empty file is detected by ReadHdr */ - REGERR err; - REGDESC root; + /* Called when an empty file is detected by ReadHdr */ + REGERR err; + REGDESC root; - XP_ASSERT(reg); + XP_ASSERT(reg); - /* Create 'hdr' */ - reg->hdr.magic = MAGIC_NUMBER; + /* Create 'hdr' */ + reg->hdr.magic = MAGIC_NUMBER; reg->hdr.verMajor = MAJOR_VERSION; reg->hdr.verMinor = MINOR_VERSION; - reg->hdr.root = 0; - reg->hdr.avail = HDRRESERVE; + reg->hdr.root = 0; + reg->hdr.avail = HDRRESERVE; - /* Create root descriptor */ - root.location = 0; - root.left = 0; - root.value = 0; - root.down = 0; + /* Create root descriptor */ + root.location = 0; + root.left = 0; + root.value = 0; + root.down = 0; root.type = REGTYPE_KEY; root.valuelen = 0; root.valuebuf = 0; @@ -795,22 +799,22 @@ static REGERR nr_CreateRoot(REGFILE *reg) * we can just write out the header first, extending the EOF to 128 bytes where * the name and desc can follow w/out silently failing. */ - nr_WriteHdr(reg); + nr_WriteHdr(reg); #endif - err = nr_AppendName(reg, ROOTKEY_STR, &root); - if (err != REGERR_OK) - return err; + err = nr_AppendName(reg, ROOTKEY_STR, &root); + if (err != REGERR_OK) + return err; err = nr_AppendDesc(reg, &root, ®->hdr.root); - if (err != REGERR_OK) - return err; + if (err != REGERR_OK) + return err; - return nr_WriteHdr(reg); /* actually commit to disk */ + return nr_WriteHdr(reg); /* actually commit to disk */ /* Create standard top-level nodes */ -} /* CreateRoot */ +} /* CreateRoot */ @@ -894,46 +898,46 @@ static REGERR nr_ReadDesc(REGFILE *reg, REGOFF offset, REGDESC *desc) static REGERR nr_ReadName(REGFILE *reg, REGDESC *desc, uint32 buflen, char *buf) { - REGERR err; + REGERR err; XP_ASSERT(reg); - XP_ASSERT(desc->name > 0); - XP_ASSERT(desc->name < reg->hdr.avail); - XP_ASSERT(buflen > 0); - XP_ASSERT(buf); + XP_ASSERT(desc->name > 0); + XP_ASSERT(desc->name < reg->hdr.avail); + XP_ASSERT(buflen > 0); + XP_ASSERT(buf); if ( desc->namelen > buflen ) return REGERR_BUFTOOSMALL; - err = nr_ReadFile(reg->fh, desc->name, desc->namelen, buf); + err = nr_ReadFile(reg->fh, desc->name, desc->namelen, buf); - buf[buflen-1] = '\0'; /* avoid runaways */ + buf[buflen-1] = '\0'; /* avoid runaways */ - return err; + return err; -} /* ReadName */ +} /* ReadName */ static REGERR nr_ReadData(REGFILE *reg, REGDESC *desc, uint32 buflen, char *buf) { - REGERR err; + REGERR err; XP_ASSERT(reg); - XP_ASSERT(desc->value > 0); - XP_ASSERT(desc->value < reg->hdr.avail); - XP_ASSERT(buflen > 0); - XP_ASSERT(buf); + XP_ASSERT(desc->value > 0); + XP_ASSERT(desc->value < reg->hdr.avail); + XP_ASSERT(buflen > 0); + XP_ASSERT(buf); if ( desc->valuelen > buflen ) return REGERR_BUFTOOSMALL; - err = nr_ReadFile(reg->fh, desc->value, desc->valuelen, buf); + err = nr_ReadFile(reg->fh, desc->value, desc->valuelen, buf); - return err; + return err; -} /* nr_ReadData */ +} /* nr_ReadData */ @@ -942,7 +946,7 @@ static REGERR nr_WriteDesc(REGFILE *reg, REGDESC *desc) char descBuf[ DESC_SIZE ]; XP_ASSERT(reg); - XP_ASSERT(desc); + XP_ASSERT(desc); XP_ASSERT( desc->location >= HDRRESERVE ); XP_ASSERT( desc->location < reg->hdr.avail ); @@ -968,7 +972,7 @@ static REGERR nr_WriteDesc(REGFILE *reg, REGDESC *desc) nr_WriteLong( desc->down, descBuf + DESC_DOWN ); } - return nr_WriteFile(reg->fh, desc->location, DESC_SIZE, descBuf); + return nr_WriteFile(reg->fh, desc->location, DESC_SIZE, descBuf); } /* nr_WriteDesc */ @@ -976,19 +980,19 @@ static REGERR nr_WriteDesc(REGFILE *reg, REGDESC *desc) static REGERR nr_AppendDesc(REGFILE *reg, REGDESC *desc, REGOFF *result) { - REGERR err; + REGERR err; char descBuf[ DESC_SIZE ]; - XP_ASSERT(reg); - XP_ASSERT(desc); - XP_ASSERT(result); + XP_ASSERT(reg); + XP_ASSERT(desc); + XP_ASSERT(result); - *result = 0; + *result = 0; if (reg->readOnly) return REGERR_READONLY; - desc->location = reg->hdr.avail; + desc->location = reg->hdr.avail; /* convert to XP int format */ nr_WriteLong ( desc->location, descBuf + DESC_LOCATION ); @@ -1009,33 +1013,33 @@ static REGERR nr_AppendDesc(REGFILE *reg, REGDESC *desc, REGOFF *result) nr_WriteLong( desc->down, descBuf + DESC_DOWN ); } - err = nr_WriteFile(reg->fh, reg->hdr.avail, DESC_SIZE, descBuf); + err = nr_WriteFile(reg->fh, reg->hdr.avail, DESC_SIZE, descBuf); if (err == REGERR_OK) - { - *result = reg->hdr.avail; - reg->hdr.avail += DESC_SIZE; - reg->hdrDirty = 1; + { + *result = reg->hdr.avail; + reg->hdr.avail += DESC_SIZE; + reg->hdrDirty = 1; #if NOCACHE_HDR - err = nr_WriteHdr(reg); + err = nr_WriteHdr(reg); #endif - } + } - return err; + return err; -} /* AppendDesc */ +} /* AppendDesc */ static REGERR nr_AppendName(REGFILE *reg, char *name, REGDESC *desc) { - REGERR err; - int len; + REGERR err; + int len; char *p; - XP_ASSERT(reg); - XP_ASSERT(name); - XP_ASSERT(desc); + XP_ASSERT(reg); + XP_ASSERT(name); + XP_ASSERT(desc); if (!nr_IsValidUTF8(name)) return REGERR_BADUTF8; @@ -1148,11 +1152,11 @@ static REGERR nr_AppendString(REGFILE *reg, char *string, REGDESC *desc) static REGERR nr_AppendData(REGFILE *reg, char *string, uint32 len, REGDESC *desc) { - REGERR err; + REGERR err; - XP_ASSERT(reg); - XP_ASSERT(string); - XP_ASSERT(desc); + XP_ASSERT(reg); + XP_ASSERT(string); + XP_ASSERT(desc); if (reg->readOnly) return REGERR_READONLY; @@ -1164,31 +1168,31 @@ static REGERR nr_AppendData(REGFILE *reg, char *string, uint32 len, REGDESC *des return REGERR_NAMETOOLONG; /* save the string */ - err = nr_WriteFile(reg->fh, reg->hdr.avail, len, string); - if (err == REGERR_OK) - { + err = nr_WriteFile(reg->fh, reg->hdr.avail, len, string); + if (err == REGERR_OK) + { desc->value = reg->hdr.avail; desc->valuelen = len; desc->valuebuf = len; - reg->hdr.avail += len; - reg->hdrDirty = 1; + reg->hdr.avail += len; + reg->hdrDirty = 1; #if NOCACHE_HDR - err = nr_WriteHdr(reg); + err = nr_WriteHdr(reg); #endif - } + } - return err; + return err; -} /* nr_AppendData */ +} /* nr_AppendData */ static XP_Bool nr_IsValidUTF8(char *string) { - int follow = 0; + int follow = 0; char *c; unsigned char ch; - XP_ASSERT(string); + XP_ASSERT(string); if ( !string ) return FALSE; @@ -1276,20 +1280,20 @@ static REGERR nr_NextName(char *pPath, char *buf, uint32 bufsize, char **newPath REGERR err = REGERR_OK; /* initialization and validation */ - XP_ASSERT(buf); + XP_ASSERT(buf); *newPath = NULL; *buf = '\0'; - if ( pPath==NULL || *pPath=='\0' ) - return REGERR_NOMORE; + if ( pPath==NULL || *pPath=='\0' ) + return REGERR_NOMORE; /* ... skip an initial path delimiter */ - if ( *pPath == PATHDEL ) { - pPath++; + if ( *pPath == PATHDEL ) { + pPath++; - if ( *pPath == '\0' ) - return REGERR_NOMORE; + if ( *pPath == '\0' ) + return REGERR_NOMORE; } /* ... missing name segment or initial blank are errors*/ @@ -1297,8 +1301,8 @@ static REGERR nr_NextName(char *pPath, char *buf, uint32 bufsize, char **newPath return REGERR_BADNAME; /* copy first path segment into return buf */ - while ( *pPath != '\0' && *pPath != PATHDEL ) - { + while ( *pPath != '\0' && *pPath != PATHDEL ) + { if ( len == bufsize ) { err = REGERR_NAMETOOLONG; break; @@ -1306,10 +1310,10 @@ static REGERR nr_NextName(char *pPath, char *buf, uint32 bufsize, char **newPath if ( *pPath < ' ' && *pPath > 0 ) return REGERR_BADNAME; - *buf++ = *pPath++; + *buf++ = *pPath++; len++; - } - *buf = '\0'; + } + *buf = '\0'; /* ... name segment can't end with blanks, either */ if ( ' ' == *(buf-1) ) @@ -1318,9 +1322,9 @@ static REGERR nr_NextName(char *pPath, char *buf, uint32 bufsize, char **newPath /* return a pointer to the start of the next segment */ *newPath = pPath; - return err; + return err; -} /* nr_NextName */ +} /* nr_NextName */ @@ -1329,37 +1333,37 @@ static REGERR nr_CatName(REGFILE *reg, REGOFF node, char *path, uint32 bufsize, { REGERR err = REGERR_OK; - char *p; - uint32 len = XP_STRLEN(path); + char *p; + uint32 len = XP_STRLEN(path); - if (len > 0) - { - p = &path[len-1]; - if (*p != PATHDEL) - { + if (len > 0) + { + p = &path[len-1]; + if (*p != PATHDEL) + { if ( len < bufsize ) { - p++; - *p = PATHDEL; + p++; + *p = PATHDEL; len++; } else err = REGERR_BUFTOOSMALL; - } - p++; /* point one past PATHDEL */ - } - else - p = path; + } + p++; /* point one past PATHDEL */ + } + else + p = path; if ( err == REGERR_OK ) { err = nr_ReadDesc( reg, node, desc ); if ( err == REGERR_OK ) { - err = nr_ReadName( reg, desc, bufsize-len, p ); + err = nr_ReadName( reg, desc, bufsize-len, p ); } } return err; -} /* CatName */ +} /* CatName */ @@ -1369,13 +1373,13 @@ static REGERR nr_ReplaceName(REGFILE *reg, REGOFF node, char *path, uint32 bufsi * the backwards path search will fail for multi-byte/Unicode names */ - char *p; + char *p; uint32 len; - REGERR err; + REGERR err; XP_ASSERT(path); - len = XP_STRLEN(path); + len = XP_STRLEN(path); if ( len > bufsize ) return REGERR_PARAM; @@ -1397,46 +1401,46 @@ static REGERR nr_ReplaceName(REGFILE *reg, REGOFF node, char *path, uint32 bufsi err = nr_ReadDesc( reg, node, desc ); if ( err == REGERR_OK ) { - err = nr_ReadName( reg, desc, bufsize-len, p ); + err = nr_ReadName( reg, desc, bufsize-len, p ); } return err; -} /* ReplaceName */ +} /* ReplaceName */ static REGERR nr_RemoveName(char *path) { - /* Typical inputs: - * path = "/Machine/4.0/" output = "/Machine" - * path = "/Machine" output = "" - * path = "" output = REGERR_NOMORE + /* Typical inputs: + * path = "/Machine/4.0/" output = "/Machine" + * path = "/Machine" output = "" + * path = "" output = REGERR_NOMORE * * NOTE! It is EXREMELY important that names be in UTF-8; otherwise * the backwards path search will fail for multi-byte/Unicode names - */ + */ - int len = XP_STRLEN(path); - char *p; - if (len < 1) - return REGERR_NOMORE; + int len = XP_STRLEN(path); + char *p; + if (len < 1) + return REGERR_NOMORE; - p = &path[len-1]; - /* if last char is '/', ignore it */ - if (*p == PATHDEL) - p--; + p = &path[len-1]; + /* if last char is '/', ignore it */ + if (*p == PATHDEL) + p--; - while ((p > path) && (*p != PATHDEL)) - p--; + while ((p > path) && (*p != PATHDEL)) + p--; -/* if (*p != PATHDEL) - return REGERR_NOMORE; +/* if (*p != PATHDEL) + return REGERR_NOMORE; */ - *p = '\0'; - return REGERR_OK; + *p = '\0'; + return REGERR_OK; -} /* RemoveName */ +} /* RemoveName */ @@ -1445,10 +1449,10 @@ static REGERR nr_RemoveName(char *path) * -------------------------------------------------------------------- */ static REGERR nr_Find(REGFILE *reg, REGOFF offParent, char *pPath, - REGDESC *pDesc, REGOFF *pPrev, REGOFF *pParent, Bool raw); + REGDESC *pDesc, REGOFF *pPrev, REGOFF *pParent, Bool raw); static REGERR nr_FindAtLevel(REGFILE *reg, REGOFF offFirst, char *pName, - REGDESC *pDesc, REGOFF *pOffPrev); + REGDESC *pDesc, REGOFF *pOffPrev); static REGERR nr_CreateSubKey(REGFILE *reg, REGDESC *pParent, char *name); static REGERR nr_CreateEntryString(REGFILE *reg, REGDESC *pParent, @@ -1461,11 +1465,11 @@ static REGERR nr_CreateEntry(REGFILE *reg, REGDESC *pParent, char *name, static REGERR nr_Find(REGFILE *reg, REGOFF offParent, - char *pPath, - REGDESC *pDesc, - REGOFF *pPrev, - REGOFF *pParent, - Bool raw) + char *pPath, + REGDESC *pDesc, + REGOFF *pPrev, + REGOFF *pParent, + Bool raw) { REGERR err; @@ -1487,10 +1491,12 @@ static REGERR nr_Find(REGFILE *reg, err = nr_ReadDesc( reg, offParent, &desc); if (raw == TRUE) { - /* save current location as parent of next segment */ - offParent = desc.location; - /* look for name at next level down */ - err = nr_FindAtLevel(reg, desc.down, pPath, &desc, &offPrev); + if ( err == REGERR_OK ) { + /* save current location as parent of next segment */ + offParent = desc.location; + /* look for name at next level down */ + err = nr_FindAtLevel(reg, desc.down, pPath, &desc, &offPrev); + } } else { /* Walk 'path', reading keys into 'desc' */ @@ -1516,11 +1522,11 @@ static REGERR nr_Find(REGFILE *reg, if (pDesc) { COPYDESC(pDesc, &desc); } - if (pPrev) { - *pPrev = offPrev; + if (pPrev) { + *pPrev = offPrev; } - if (pParent) { - *pParent = offParent; + if (pParent) { + *pParent = offParent; } } @@ -1542,35 +1548,35 @@ static REGERR nr_Find(REGFILE *reg, * if the node is not found. */ static REGERR nr_FindAtLevel(REGFILE *reg, - REGOFF offset, - char *pName, - REGDESC *pDesc, - REGOFF *pOffPrev) + REGOFF offset, + char *pName, + REGDESC *pDesc, + REGOFF *pOffPrev) { - char namebuf[MAXREGNAMELEN]; - REGDESC desc; - REGERR err; + char namebuf[MAXREGNAMELEN]; + REGDESC desc; + REGERR err; REGOFF prev = 0; - /* Note: offset=0 when there's no 'down' or 'left' */ - XP_ASSERT(reg); - XP_ASSERT(offset < reg->hdr.avail); - XP_ASSERT(pName); - XP_ASSERT(*pName); + /* Note: offset=0 when there's no 'down' or 'left' */ + XP_ASSERT(reg); + XP_ASSERT(offset < reg->hdr.avail); + XP_ASSERT(pName); + XP_ASSERT(*pName); - while ( offset != 0 ) + while ( offset != 0 ) { /* get name of next node */ - err = nr_ReadDesc(reg, offset, &desc); - if (err != REGERR_OK) - return err; + err = nr_ReadDesc(reg, offset, &desc); + if (err != REGERR_OK) + return err; - err = nr_ReadName(reg, &desc, sizeof(namebuf), namebuf); - if (err != REGERR_OK) - return err; + err = nr_ReadName(reg, &desc, sizeof(namebuf), namebuf); + if (err != REGERR_OK) + return err; /* check to see if it's the one we want */ - if (XP_STRCASECMP(namebuf, pName) == 0) { + if (XP_STRCASECMP(namebuf, pName) == 0) { /* Found it! */ if ( pDesc != NULL ) { COPYDESC( pDesc, &desc ); @@ -1583,11 +1589,11 @@ static REGERR nr_FindAtLevel(REGFILE *reg, /* advance to the next node */ prev = offset; - offset = desc.left; - } + offset = desc.left; + } - return REGERR_NOFIND; -} /* FindAtLevel */ + return REGERR_NOFIND; +} /* FindAtLevel */ @@ -1640,7 +1646,7 @@ static REGERR nr_CreateEntryString(REGFILE *reg, REGDESC *pParent, char *name, c XP_ASSERT(name); XP_ASSERT(value); - memset( &desc, 0, sizeof(REGDESC) ); + XP_MEMSET( &desc, 0, sizeof(REGDESC) ); err = nr_AppendName(reg, name, &desc); if (err != REGERR_OK) @@ -1670,36 +1676,36 @@ static REGERR nr_CreateEntryString(REGFILE *reg, REGDESC *pParent, char *name, c static REGERR nr_CreateEntry(REGFILE *reg, REGDESC *pParent, char *name, uint16 type, char *value, uint32 length) { - REGDESC desc; - REGERR err; + REGDESC desc; + REGERR err; - XP_ASSERT(reg); - XP_ASSERT(pParent); - XP_ASSERT(name); - XP_ASSERT(value); + XP_ASSERT(reg); + XP_ASSERT(pParent); + XP_ASSERT(name); + XP_ASSERT(value); - memset( &desc, 0, sizeof(REGDESC) ); + XP_MEMSET( &desc, 0, sizeof(REGDESC) ); - err = nr_AppendName(reg, name, &desc); + err = nr_AppendName(reg, name, &desc); if (err != REGERR_OK) - return err; + return err; - err = nr_AppendData(reg, value, length, &desc); + err = nr_AppendData(reg, value, length, &desc); if (err != REGERR_OK) - return err; + return err; desc.type = type; - desc.left = pParent->value; - desc.down = 0; + desc.left = pParent->value; + desc.down = 0; desc.parent = pParent->location; - err = nr_AppendDesc(reg, &desc, &pParent->value); + err = nr_AppendDesc(reg, &desc, &pParent->value); if (err != REGERR_OK) - return err; + return err; - /* printf("nr_AddEntry: %s=%s @0x%lx\n", name, value, pParent->value); */ + /* printf("nr_AddEntry: %s=%s @0x%lx\n", name, value, pParent->value); */ - return nr_WriteDesc(reg, pParent); + return nr_WriteDesc(reg, pParent); } /* nr_CreateEntry */ @@ -1709,103 +1715,103 @@ static REGERR nr_CreateEntry(REGFILE *reg, REGDESC *pParent, char *name, VR_INTERFACE(REGERR) NR_RegRename(RKEY key, char *path, char *newname) { - REGDESC desc; - REGERR err; + REGDESC desc; + REGERR err; - if ( !VALID_FILEHANDLE(gReg.fh) ) - return REGERR_FAIL; + if ( !VALID_FILEHANDLE(gReg.fh) ) + return REGERR_FAIL; - /* Okay to Update to "", but names must not be null */ - if (!newname || !*newname) - return REGERR_PARAM; + /* Okay to Update to "", but names must not be null */ + if (!newname || !*newname) + return REGERR_PARAM; - err = nr_Lock(&gReg); - if (err != REGERR_OK) - return err; + err = nr_Lock(&gReg); + if (err != REGERR_OK) + return err; - /* Find the key or entry to rename (and validate the - incoming parameters) */ - err = nr_Find((REGOFF)key, path, &desc, 0, 0, FALSE); - if (err != REGERR_OK) - goto cleanup; + /* Find the key or entry to rename (and validate the + incoming parameters) */ + err = nr_Find((REGOFF)key, path, &desc, 0, 0, FALSE); + if (err != REGERR_OK) + goto cleanup; - /* Write the new name string to the file and update - the key or entry's pointer */ - err = nr_AppendName(&gReg, newname, &desc); - if (err != REGERR_OK) - goto cleanup; + /* Write the new name string to the file and update + the key or entry's pointer */ + err = nr_AppendName(&gReg, newname, &desc); + if (err != REGERR_OK) + goto cleanup; - /* Write the key or entry back to the disk and return */ - err = nr_WriteDesc(&gReg, &desc); + /* Write the key or entry back to the disk and return */ + err = nr_WriteDesc(&gReg, &desc); cleanup: - nr_Unlock(&gReg); - return err; + nr_Unlock(&gReg); + return err; -} /* RegRename */ +} /* RegRename */ VR_INTERFACE(REGERR) NR_RegPack(char *newfilename) { - REGFILE dstReg; - char *path = NULL; - int err = REGERR_OK; + REGFILE dstReg; + char *path = NULL; + int err = REGERR_OK; - dstReg.fh = NULL; + dstReg.fh = NULL; - if (!newfilename || !*newfilename) - return REGERR_PARAM; - if ( !VALID_FILEHANDLE(gReg.fh) ) - return REGERR_FAIL; + if (!newfilename || !*newfilename) + return REGERR_PARAM; + if ( !VALID_FILEHANDLE(gReg.fh) ) + return REGERR_FAIL; - /* open it & create a header by trying to read */ - err = nr_OpenFile(newfilename, &dstReg.fh); - if (err != REGERR_OK) - goto cleanup; - err = nr_ReadHdr(&dstReg); - if (err != REGERR_OK) - goto cleanup; + /* open it & create a header by trying to read */ + err = nr_OpenFile(newfilename, &dstReg.fh); + if (err != REGERR_OK) + goto cleanup; + err = nr_ReadHdr(&dstReg); + if (err != REGERR_OK) + goto cleanup; - /* read records from the current registry file and - add them to 'dstReg' */ - path = XP_ALLOC(PACKBUFFERSIZE); - if (path == NULL) - { - err = REGERR_FAIL; - goto cleanup; - } + /* read records from the current registry file and + add them to 'dstReg' */ + path = XP_ALLOC(PACKBUFFERSIZE); + if (path == NULL) + { + err = REGERR_FAIL; + goto cleanup; + } - XP_STRCPY(path, "/"); + XP_STRCPY(path, "/"); - err = nr_Lock(&gReg); - if (err != REGERR_OK) - goto cleanup; + err = nr_Lock(&gReg); + if (err != REGERR_OK) + goto cleanup; - while (NR_RegNext( 0, PACKBUFFERSIZE, path ) == REGERR_OK) - { - err = nr_RegGenericAdd(&dstReg, 0, path); - if (err != REGERR_OK) - break; - } + while (NR_RegNext( 0, PACKBUFFERSIZE, path ) == REGERR_OK) + { + err = nr_RegGenericAdd(&dstReg, 0, path); + if (err != REGERR_OK) + break; + } - nr_Unlock(&gReg); + nr_Unlock(&gReg); cleanup: XP_FREEIF(path); - if ( VALID_FILEHANDLE(dstReg.fh) ) + if ( VALID_FILEHANDLE(dstReg.fh) ) { /* even if not caching headers it could be dirty due to an error */ - if (dstReg.hdrDirty) { - nr_WriteHdr(&dstReg); + if (dstReg.hdrDirty) { + nr_WriteHdr(&dstReg); } - nr_CloseFile(&dstReg.fh); - } + nr_CloseFile(&dstReg.fh); + } - return err; + return err; -} /* RegPack */ +} /* RegPack */ #endif /* old interface */ @@ -1816,7 +1822,7 @@ cleanup: * --------------------------------------------------------------------- */ static REGOFF nr_TranslateKey( REGFILE *reg, RKEY key ); -static void nr_InitStdRkeys( REGFILE *reg ); +static REGERR nr_InitStdRkeys( REGFILE *reg ); static Bool nr_ProtectedNode( REGFILE *reg, REGOFF key ); static REGERR nr_RegAddKey( REGFILE *reg, RKEY key, char *path, RKEY *newKey, Bool raw ); static REGERR nr_RegDeleteKey( REGFILE *reg, RKEY key, char *path, Bool raw ); @@ -1904,15 +1910,15 @@ static REGOFF nr_TranslateKey( REGFILE *reg, RKEY key ) -static void nr_InitStdRkeys( REGFILE *reg ) +static REGERR nr_InitStdRkeys( REGFILE *reg ) { - REGERR err; + REGERR err = REGERR_OK; RKEY key; XP_ASSERT( reg != NULL ); /* initialize to invalid key values */ - memset( ®->rkeys, 0, sizeof(STDNODES) ); + XP_MEMSET( ®->rkeys, 0, sizeof(STDNODES) ); /* Add each key before looking it up. Adding an already * existing key is harmless, and these MUST exist. @@ -1920,30 +1926,32 @@ static void nr_InitStdRkeys( REGFILE *reg ) /* ROOTKEY_USERS */ err = nr_RegAddKey( reg, reg->hdr.root, ROOTKEY_USERS_STR, &key, FALSE ); - if ( err == REGERR_OK ) { - reg->rkeys.users = key; - } + if ( err != REGERR_OK ) + return err; + reg->rkeys.users = key; /* ROOTKEY_COMMON */ err = nr_RegAddKey( reg, reg->hdr.root, ROOTKEY_COMMON_STR, &key, FALSE ); - if ( err == REGERR_OK ) { - reg->rkeys.common = key; - } + if ( err != REGERR_OK ) + return err; + reg->rkeys.common = key; /* ROOTKEY_VERSIONS */ err = nr_RegAddKey( reg, reg->hdr.root, ROOTKEY_VERSIONS_STR, &key, FALSE ); - if ( err == REGERR_OK ) { - reg->rkeys.versions = key; - } + if ( err != REGERR_OK ) + return err; + reg->rkeys.versions = key; /* ROOTKEY_CURRENT_USER */ - /* delay until first use -- see nr_TranslateKey */ + /* delay until first use -- see nr_TranslateKey */ /* ROOTKEY_PRIVATE */ err = nr_RegAddKey( reg, reg->hdr.root, ROOTKEY_PRIVATE_STR, &key, FALSE ); - if ( err == REGERR_OK ) { - reg->rkeys.privarea = key; - } + if ( err != REGERR_OK ) + return err; + reg->rkeys.privarea = key; + + return err; } /* nr_InitStdRkeys */ @@ -1985,13 +1993,15 @@ static REGERR nr_RegAddKey( REGFILE *reg, RKEY key, char *path, RKEY *newKey, Bo err = nr_ReadDesc( reg, start, &desc ); if (raw == TRUE) { - /* look for name at next level down */ - err = nr_FindAtLevel(reg, desc.down, path, &desc, 0); + if ( err == REGERR_OK) { + /* look for name at next level down */ + err = nr_FindAtLevel(reg, desc.down, path, &desc, 0); - /* if key is not found */ - if ( err == REGERR_NOFIND ) { - /* add it as a sub-key to the last found key */ - err = nr_CreateSubKey(reg, &desc, path); + /* if key is not found */ + if ( err == REGERR_NOFIND ) { + /* add it as a sub-key to the last found key */ + err = nr_CreateSubKey(reg, &desc, path); + } } } else { @@ -2171,16 +2181,24 @@ static REGERR nr_RegOpen( char *filename, HREG *hReg ) /* ...other misc initialization */ pReg->refCount = 0; + status = nr_InitStdRkeys( pReg ); + if ( status == REGERR_OK ) { + /* ...and add it to the list */ + nr_AddNode( pReg ); + } + else { + nr_CloseFile( &(pReg->fh) ); + XP_FREE( pReg->filename ); + XP_FREE( pReg ); + goto bail; + } + #ifndef STANDALONE_REGISTRY pReg->lock = PR_NewLock(); #endif + /* now done with everything that needs to protect the header */ pReg->inInit = FALSE; - - nr_InitStdRkeys( pReg ); - - /* ...and add it to the list */ - nr_AddNode( pReg ); } /* create a new handle to the regfile */ @@ -2282,7 +2300,7 @@ static char* nr_GetRegName (char *name) * A variable which, on exit will contain an alloc'ed string which is a * copy of the current username. * - * Output: + * DO NOT USE -- OBSOLETE * --------------------------------------------------------------------- */ @@ -2306,6 +2324,9 @@ VR_INTERFACE(REGERR) NR_RegGetUsername(char **name) /* --------------------------------------------------------------------- * 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 @@ -2343,11 +2364,11 @@ VR_INTERFACE(REGERR) NR_RegSetUsername(const char *name) /* --------------------------------------------------------------------- - * NReg_Open - Open a netscape XP registry + * NR_RegOpen - Open a netscape XP registry * * Parameters: - * filename - registry file to open. NULL or "" opens standard - * local registry. (This parameter currently ignored) + * filename - registry file to open. NULL or "" opens the standard + * local registry. * hReg - OUT: handle to opened registry * * Output: @@ -2357,9 +2378,11 @@ VR_INTERFACE(REGERR) NR_RegOpen( char *filename, HREG *hReg ) { REGERR status = REGERR_OK; - /* you must call NR_StartupRegistry() first */ +#if !defined(STANDALONE_REGISTRY) + /* you must call NR_StartupRegistry() first */ if ( regStartCount <= 0 ) return REGERR_FAIL; +#endif PR_Lock(reglist_lock); @@ -2399,6 +2422,33 @@ VR_INTERFACE(REGERR) NR_RegClose( HREG hReg ) +/* --------------------------------------------------------------------- + * NR_RegIsWritable - Check read/write status of open registry + * + * Parameters: + * hReg - handle of open registry to query + * --------------------------------------------------------------------- + */ +VR_INTERFACE(REGERR) NR_RegIsWritable( HREG hReg ) +{ + REGERR err; + REGFILE* reg; + + /* verify parameters */ + err = VERIFY_HREG( hReg ); + if ( err != REGERR_OK ) + return err; + + reg = ((REGHANDLE*)hReg)->pReg; + + if ( reg->readOnly ) + return REGERR_READONLY; + else + return REGERR_OK; + +} /* NR_RegIsWritable */ + + /* --------------------------------------------------------------------- * NR_RegAddKey - Add a key node to the registry @@ -2457,18 +2507,16 @@ VR_INTERFACE(REGERR) NR_RegAddKey( HREG hReg, RKEY key, char *path, RKEY *newKey /* --------------------------------------------------------------------- * NR_RegAddKeyRaw - Add a key node to the registry * - * This routine is simply a wrapper to perform user input - * validation and translation from HREG and standard key - * values into the internal format. It is different from - * NR_RegAddKey() in that it takes a keyname rather than - * a path. + * 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. + * name happens. + * newkey - if not null the RKEY of the new key is returned * --------------------------------------------------------------------- */ VR_INTERFACE(REGERR) NR_RegAddKeyRaw( HREG hReg, RKEY key, char *keyname, RKEY *newKey ) @@ -2516,6 +2564,8 @@ VR_INTERFACE(REGERR) NR_RegAddKeyRaw( HREG hReg, RKEY key, char *keyname, RKEY * * 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. @@ -2594,6 +2644,7 @@ VR_INTERFACE(REGERR) NR_RegDeleteKeyRaw( HREG hReg, RKEY key, char *keyname ) * 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, RKEY key, char *path, RKEY *result ) @@ -2652,6 +2703,7 @@ VR_INTERFACE(REGERR) NR_RegGetKey( HREG hReg, RKEY key, char *path, RKEY *result * 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, RKEY key, char *keyname, RKEY *result ) @@ -2966,7 +3018,7 @@ VR_INTERFACE(REGERR) NR_RegGetEntry( HREG hReg, RKEY key, char *name, /* --------------------------------------------------------------------- - * NR_RegSetEntryString - Store a UTF string value associated with the + * NR_RegSetEntryString - Store a UTF-8 string value associated with the * named entry of the specified key. Used for * both creation and update. * @@ -2974,7 +3026,7 @@ VR_INTERFACE(REGERR) NR_RegGetEntry( HREG hReg, RKEY key, char *name, * hReg - handle of open registry * key - RKEY of key that contains entry--obtain with NR_RegGetKey() * name - name of entry - * buffer - UTF String to store + * buffer - UTF-8 String to store * --------------------------------------------------------------------- */ VR_INTERFACE(REGERR) NR_RegSetEntryString( HREG hReg, RKEY key, char *name, @@ -3086,7 +3138,7 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HREG hReg, RKEY key, char *name, uint16 typ if (data) needFree = TRUE; #else - data = (char*)buffer; + data = (char*)buffer; #endif break; @@ -3202,7 +3254,7 @@ VR_INTERFACE(REGERR) NR_RegDeleteEntry( HREG hReg, RKEY key, char *name ) /* lock registry */ err = nr_Lock( reg ); if ( err != REGERR_OK ) - return err; + return err; /* read starting desc */ err = nr_ReadDesc( reg, key, &parent); @@ -3252,6 +3304,8 @@ VR_INTERFACE(REGERR) NR_RegDeleteEntry( HREG hReg, RKEY key, char *name ) /* --------------------------------------------------------------------- * 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() @@ -3456,6 +3510,8 @@ VR_INTERFACE(REGERR) NR_RegEnumSubkeys( HREG hReg, RKEY key, REGENUM *state, /* --------------------------------------------------------------------- * 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() @@ -3605,7 +3661,7 @@ static REGERR nr_addNodesToNewReg( HREG hReg, RKEY rootkey, HREG hRegNew, void * REGENUM state = 0; REGENUM entrystate = 0; REGINFO info; - int err = REGERR_OK; + int err = REGERR_OK; int status = REGERR_OK; RKEY key; RKEY newKey; @@ -3627,10 +3683,10 @@ static REGERR nr_addNodesToNewReg( HREG hReg, RKEY rootkey, HREG hRegNew, void * { err = NR_RegEnumSubkeys( hReg, rootkey, &state, keyname, sizeof(keyname), REGENUM_DESCEND ); if ( err != REGERR_OK ) - break; + break; err = NR_RegAddKey( hRegNew, rootkey, keyname, &newKey ); if ( err != REGERR_OK ) - break; + break; cnt++; if (cnt >= prevCnt + 15) { @@ -3639,11 +3695,11 @@ static REGERR nr_addNodesToNewReg( HREG hReg, RKEY rootkey, HREG hRegNew, void * } err = NR_RegGetKey( hReg, rootkey, keyname, &key ); if ( err != REGERR_OK ) - break; + break; entrystate = 0; status = REGERR_OK; while (status == REGERR_OK) { - info.size = sizeof(REGINFO); + info.size = sizeof(REGINFO); status = NR_RegEnumEntries( hReg, key, &entrystate, entryname, sizeof(entryname), &info ); if ( status == REGERR_OK ) { @@ -3703,13 +3759,13 @@ VR_INTERFACE(REGERR) NR_RegPack( HREG hReg, void *userData, nr_RegPackCallbackFu /* lock registry */ err = nr_Lock( reg ); if ( err != REGERR_OK ) - return err; + return err; PR_Lock(reglist_lock); XP_STRCPY(tempfilename, reg->filename); err = nr_createTempRegName(tempfilename, sizeof(tempfilename)); if ( err != REGERR_OK ) - goto safe_exit; + goto safe_exit; /* force file creation */ fh = vr_fileOpen(tempfilename, XP_FILE_WRITE_BIN); @@ -3721,23 +3777,23 @@ VR_INTERFACE(REGERR) NR_RegPack( HREG hReg, void *userData, nr_RegPackCallbackFu err = NR_RegOpen(tempfilename, &hRegTemp); if ( err != REGERR_OK ) - goto safe_exit; + goto safe_exit; bCloseTempFile = TRUE; /* must open temp file first or we get the same name twice */ XP_STRCPY(oldfilename, reg->filename); err = nr_createTempRegName(oldfilename, sizeof(oldfilename)); if ( err != REGERR_OK ) - goto safe_exit; + goto safe_exit; key = ROOTKEY_PRIVATE; err = nr_addNodesToNewReg( hReg, key, hRegTemp, userData, fn); if ( err != REGERR_OK ) - goto safe_exit; + goto safe_exit; key = ROOTKEY_VERSIONS; err = nr_addNodesToNewReg( hReg, key, hRegTemp, userData, fn); if ( err != REGERR_OK ) - goto safe_exit; + goto safe_exit; key = ROOTKEY_COMMON; err = nr_addNodesToNewReg( hReg, key, hRegTemp, userData, fn); if ( err != REGERR_OK ) @@ -3745,7 +3801,7 @@ VR_INTERFACE(REGERR) NR_RegPack( HREG hReg, void *userData, nr_RegPackCallbackFu key = ROOTKEY_USERS; err = nr_addNodesToNewReg( hReg, key, hRegTemp, userData, fn); if ( err != REGERR_OK ) - goto safe_exit; + goto safe_exit; err = NR_RegClose(hRegTemp); bCloseTempFile = FALSE; @@ -3807,12 +3863,12 @@ safe_exit: #include "VerReg.h" #ifndef STANDALONE_REGISTRY -extern PRMonitor *vr_monitor; +extern PRLock *vr_lock; #endif -#ifdef XP_UNIX +#if defined(XP_UNIX) && !defined(STANDALONE_REGISTRY) extern XP_Bool bGlobalRegistry; #endif @@ -3841,7 +3897,8 @@ VR_INTERFACE(REGERR) NR_StartupRegistry(void) if ( status == REGERR_OK ) { - if ( ++regStartCount == 1 ) + ++regStartCount; + if ( regStartCount == 1 ) { /* first time only initialization */ @@ -3856,14 +3913,12 @@ VR_INTERFACE(REGERR) NR_StartupRegistry(void) /* initialization for version registry */ #ifndef STANDALONE_REGISTRY - vr_monitor = PR_NewMonitor(); - XP_ASSERT( vr_monitor != NULL ); -#endif - + vr_lock = PR_NewLock(); + XP_ASSERT( vr_lock != NULL ); #ifdef XP_UNIX bGlobalRegistry = ( getenv(UNIX_GLOBAL_FLAG) != NULL ); #endif - +#endif } /* if ( regStartCount == 1 ) */ PR_Unlock( reglist_lock ); @@ -3875,14 +3930,18 @@ VR_INTERFACE(REGERR) NR_StartupRegistry(void) VR_INTERFACE(void) NR_ShutdownRegistry(void) { REGFILE* pReg; + XP_Bool bDestroyLocks = FALSE; -#ifndef STANDALONE_REGISTRY /* people should track whether NR_StartupRegistry() was successful * and not call this if it fails... but they won't so we'll try to * handle that case gracefully. */ +#ifndef STANDALONE_REGISTRY if ( reglist_lock == NULL ) return; /* was not started successfully */ +#else + if ( regStartCount == 0 ) + return; /* was not started successfully */ #endif PR_Lock( reglist_lock ); @@ -3891,15 +3950,8 @@ VR_INTERFACE(void) NR_ShutdownRegistry(void) if ( regStartCount == 0 ) { /* shutdown for real. */ - /* Close version registry first */ -#ifndef STANDALONE_REGISTRY - if ( vr_monitor != NULL ) - { - VR_Close(); - PR_DestroyMonitor(vr_monitor); - vr_monitor = NULL; - } -#endif + /* Close version registry first if open */ + VR_Close(); /* close any forgotten open registries */ while ( RegList != NULL ) @@ -3914,15 +3966,21 @@ VR_INTERFACE(void) NR_ShutdownRegistry(void) XP_FREEIF(user_name); XP_FREEIF(globalRegName); + XP_FREEIF(verRegName); + + bDestroyLocks = TRUE; } PR_Unlock( reglist_lock ); #ifndef STANDALONE_REGISTRY - if ( regStartCount == 0 ) + if ( bDestroyLocks ) { PR_DestroyLock( reglist_lock ); reglist_lock = NULL; + + PR_DestroyLock(vr_lock); + vr_lock = NULL; } #endif diff --git a/mozilla/modules/libreg/src/reg.h b/mozilla/modules/libreg/src/reg.h index d93281b80c1..3a280bb7855 100644 --- a/mozilla/modules/libreg/src/reg.h +++ b/mozilla/modules/libreg/src/reg.h @@ -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 */ /* 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; diff --git a/mozilla/modules/libreg/src/vr_stubs.c b/mozilla/modules/libreg/src/vr_stubs.c index fc200c936d4..f1612db67d0 100644 --- a/mozilla/modules/libreg/src/vr_stubs.c +++ b/mozilla/modules/libreg/src/vr_stubs.c @@ -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", ®Spec); + if (!err) + { + err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_REG, ®Spec); - if (err == -43) /* if file doesn't exist */ - { - err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); + if (err == -43) /* if file doesn't exist */ + { + err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); bCreate = 1; - } + } - if (err == noErr) - { - Handle thePath; - short pathLen; - err = FSpGetFullPath(®Spec, &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(®Spec, &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, ®Spec); + + if (err == -43) /* if file doesn't exist */ + { + err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); + bCreate = 1; + } + + if (err == noErr) + { + Handle thePath; + short pathLen; + err = FSpGetFullPath(®Spec, &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, " ,,\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) */ diff --git a/mozilla/modules/libreg/src/vr_stubs.h b/mozilla/modules/libreg/src/vr_stubs.h index 942604ace11..c56c1b0bdb7 100644 --- a/mozilla/modules/libreg/src/vr_stubs.h +++ b/mozilla/modules/libreg/src/vr_stubs.h @@ -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 */ /* 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 - 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_ */ diff --git a/mozilla/modules/libreg/tests/interp.c b/mozilla/modules/libreg/tests/interp.c index 58b02352622..dbcc5b44f32 100644 --- a/mozilla/modules/libreg/tests/interp.c +++ b/mozilla/modules/libreg/tests/interp.c @@ -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: ", , " - 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 [, ] - create a new registry"); + puts("\tA)pp - set application directory"); + puts("\tC)lose - close the registry"); + puts(""); puts("\tI)nstall , , - install a new component"); - puts("\tU)pdate , , - update a component"); - puts("\tF)ind - returns version and path"); - puts("\tV)erify - verify component exists and checks out"); - puts("\tC)reate - create a new instance of Navigator (e.g., \"4.0\")"); puts("\tR)emove - 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 - checks for existence in registry"); + puts("\tT)est - validates physical existence"); + puts("\tE)num - dumps named subtree"); + puts(""); + puts("\tV)ersion - gets component version"); + puts("\tP)ath - gets component path"); + puts("\treF)count - gets component refcount"); + puts("\tD)ir - gets component directory"); + puts("\tSR)efcount - sets component refcount"); + puts("\tSD)ir - 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 diff --git a/mozilla/modules/libreg/tests/regtest.c b/mozilla/modules/libreg/tests/regtest.c index 39d694f0323..209e591976f 100644 --- a/mozilla/modules/libreg/tests/regtest.c +++ b/mozilla/modules/libreg/tests/regtest.c @@ -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 ""; } @@ -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; - }