diff --git a/mozilla/modules/libreg/include/NSReg.h b/mozilla/modules/libreg/include/NSReg.h index 237fc4f14ef..4fd9897eef2 100644 --- a/mozilla/modules/libreg/include/NSReg.h +++ b/mozilla/modules/libreg/include/NSReg.h @@ -82,6 +82,7 @@ typedef struct _reginfo #define REGTYPE_ENTRY_STRING_UTF (REGTYPE_ENTRY + 1) #define REGTYPE_ENTRY_INT32_ARRAY (REGTYPE_ENTRY + 2) #define REGTYPE_ENTRY_BYTES (REGTYPE_ENTRY + 3) +#define REGTYPE_ENTRY_FILE (REGTYPE_ENTRY + 4) #define REG_DELETE_LIST_KEY "Netscape/Communicator/SoftwareUpdate/Delete List" #define REG_REPLACE_LIST_KEY "Netscape/Communicator/SoftwareUpdate/Replace List" @@ -95,7 +96,13 @@ typedef struct _reginfo /* Platform-dependent declspec for library interface */ #if defined(XP_PC) #if defined(WIN32) - #define VR_INTERFACE(type) __declspec(dllexport) type __stdcall + + #if defined (STANDALONE_REGISTRY) + #define VR_INTERFACE(type) __declspec(dllexport) type __cdecl + #else + #define VR_INTERFACE(type) __declspec(dllexport) type __stdcall + #endif + #elif defined(XP_OS2) #define VR_INTERFACE(type) type _Optlink #else @@ -229,10 +236,10 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries( REGINFO *info /* optional; returns info about entry */ ); -#ifndef STANDALONE_REGISTRY + VR_INTERFACE(void) NR_ShutdownRegistry(void); VR_INTERFACE(void) NR_StartupRegistry(void); -#endif /* STANDALONE_REGISTRY */ + XP_END_PROTOS diff --git a/mozilla/modules/libreg/src/VerReg.c b/mozilla/modules/libreg/src/VerReg.c index b063965bf42..67cecbacfca 100644 --- a/mozilla/modules/libreg/src/VerReg.c +++ b/mozilla/modules/libreg/src/VerReg.c @@ -31,13 +31,15 @@ * -------------------------------------------------------------------- */ #include +#include -#if defined(XP_WIN) +#if defined(XP_WIN) #include #endif #include #include +#include #include #include "reg.h" @@ -48,7 +50,7 @@ #include #endif -/* -------- local defines --------------- +/* -------- local defines --------------- */ #define MAXREGVERLEN 32 /* Version=12345.12345.12345.12345 */ @@ -69,7 +71,7 @@ #define PATH_ROOT(p) ( ((p) && *(p)==PATHDEL) ? ROOTKEY_VERSIONS : curver ) #define UNIX_ROOT(p) ( ((p) && *(p)==PATHDEL) ? ROOTKEY_VERSIONS : unixver ) - + /* --------------------------------------------------------------------- * Global variables * --------------------------------------------------------------------- @@ -98,7 +100,6 @@ PRMonitor *vr_monitor = NULL; static char *app_dir = NULL; - /* --------------------------------------------------------------------- * local functions * --------------------------------------------------------------------- @@ -118,9 +119,9 @@ static REGERR vr_GetPathname(HREG reg, RKEY key, char *entry, char *buf, uint32 static REGERR vr_FindKey(char *name, HREG *hreg, RKEY *key); -static void vr_GetUninstallItemPath(char *regPackageName, char *regbuf); -static void vr_convertPackageName(char *regPackageName, char *convertedPackageName); -static void vr_unmanglePackageName(char *mangledPackageName, char *regPackageName); +static REGERR vr_GetUninstallItemPath(char *regPackageName, char *regbuf, uint32 regbuflen); +static REGERR vr_convertPackageName(char *regPackageName, char *convertedPackageName, uint32 convertedDataLength); +static REGERR vr_unmanglePackageName(char *mangledPackageName, char *regPackageName, uint32 regPackageLength); #ifdef XP_MAC static void vr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length); @@ -171,7 +172,7 @@ 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) { @@ -194,11 +195,11 @@ static REGERR vr_Init(void) if (!bGlobalRegistry && err == REGERR_OK ) { unixver = 0; if (NR_RegOpen( regbuf, &unixreg ) == REGERR_OK) { - if (NR_RegGetKey( unixreg, ROOTKEY_VERSIONS, NAVIGATOR_NODE, - &navKey) == REGERR_OK) + if (NR_RegGetKey( unixreg, ROOTKEY_VERSIONS, NAVIGATOR_NODE, + &navKey) == REGERR_OK) { if (NR_RegGetEntryString( unixreg, navKey, CURRENT_VER, - curstr, sizeof(curstr)) == REGERR_OK ) + curstr, sizeof(curstr)) == REGERR_OK ) { NR_RegGetKey( unixreg, navKey, curstr, &unixver ); } @@ -207,20 +208,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 */ @@ -237,12 +238,12 @@ 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; } #endif - } + } done: #ifndef STANDALONE_REGISTRY @@ -352,8 +353,9 @@ static REGERR vr_GetCheck(char *path, int32 *check) return REGERR_NOFILE; case EACCES: /* file in use */ -#ifdef EMFILE /* Mac doesn't have EMFILE. */ - case EMFILE: /* too many files open */ + +#ifdef EMFILE + case EMFILE: /* too many files open */ #endif default: return REGERR_FAIL; @@ -396,18 +398,11 @@ static REGERR vr_GetCheck(char *path, int32 *check) static REGERR vr_SetPathname(HREG reg, RKEY key, char *entry, char *dir) { - /* save in platform/OS charset, so use BYTES. */ REGERR err; - void * alias = dir; int32 datalen = XP_STRLEN(dir)+1; /* include '\0' */ -#ifdef XP_MAC - alias = NULL; - vr_MacAliasFromPath(dir, &alias, &datalen); -#endif - err = NR_RegSetEntry( reg, key, entry, REGTYPE_ENTRY_BYTES, alias, datalen); -#ifdef XP_MAC - XP_FREEIF(alias); -#endif + + err = NR_RegSetEntry( reg, key, entry, REGTYPE_ENTRY_FILE, dir, datalen); + return err; } @@ -415,52 +410,69 @@ static REGERR vr_SetPathname(HREG reg, RKEY key, char *entry, char *dir) static REGERR vr_GetPathname(HREG reg, RKEY key, char *entry, char *buf, uint32 sizebuf) { - /* stored as BYTES since it's platform OS charset */ + REGERR err; + REGINFO info; + + info.size = sizeof(REGINFO); + #ifndef XP_MAC - REGERR err; - err = NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf ); - return err; + err = NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf ); + return err; #else - REGERR err; - REGINFO info; + + err = NR_RegGetEntryInfo( reg, key, entry, &info ); + + if (err != REGERR_OK) + return err; + + if (info.entryType == REGTYPE_ENTRY_FILE || + info.entryType == REGTYPE_ENTRY_STRING_UTF ) + { + err = NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf ); + } + else if (info.entryType == REGTYPE_ENTRY_BYTES) + { - info.size = sizeof(REGINFO); - - err = NR_RegGetEntryInfo( reg, key, entry,&info ); - if (err != REGERR_OK) - return err; - - if (info.entryType == REGTYPE_ENTRY_STRING_UTF) /* Assume that it is a file name */ - err = NR_RegGetEntry( reg, key, entry, (void*)buf, &sizebuf ); - else - { -#define MAC_ALIAS_BUFFER_SIZE 4000 + extern char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength); + + #define MAC_ALIAS_BUFFER_SIZE 4000 char stackBuf[MAC_ALIAS_BUFFER_SIZE]; uint32 stackBufSize = MAC_ALIAS_BUFFER_SIZE; char * tempBuf; - + err = NR_RegGetEntry( reg, key, entry, (void*)stackBuf, &stackBufSize ); + if (err != REGERR_OK) return err; - tempBuf = vr_PathFromMacAlias(stackBuf, stackBufSize); - - if (tempBuf == NULL) { + tempBuf = nr_PathFromMacAlias(stackBuf, stackBufSize); + + if (tempBuf == NULL) + { /* don't change error w/out changing vr_SetCurrentNav to match */ - buf[0] = '\0'; + buf[0] = '\0'; err = REGERR_NOFILE; - } - else { + } + else + { if (XP_STRLEN(tempBuf) > sizebuf) err = REGERR_BUFTOOSMALL; else XP_STRCPY(buf, tempBuf); - - XP_FREE(tempBuf); + + XP_FREE(tempBuf); } } - return err; -#endif + else + { + /* what did we put here?? */ + err = REGERR_BADTYPE; + } + + return err; + +#endif + } @@ -520,7 +532,7 @@ static REGERR vr_SetCurrentNav( char *installation, char *programPath, char *ver bFound = TRUE; } } - + /* Look for an existing installation if not found */ state = 0; while (!bFound && ((err == REGERR_OK) || (err == REGERR_NOFILE)) ) { @@ -589,104 +601,7 @@ done: } -#ifdef XP_MAC -#include -#include -#include -#include "FullPath.h" - -/* returns an alias as a malloc'd pointer. - * On failure, *alias is NULL - */ -static void vr_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; -} - -/* resolves an alias, and returns a full path to the Mac file - * If the alias changed, it would be nice to update our alias pointers - */ -static char * vr_PathFromMacAlias(const void * alias, uint32 aliasLength) -{ - OSErr err; - 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 */ - - /* 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 */ - { - short vRefNum; - long dirID; - 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 */ -fail: - if (h != NULL) - DisposeHandle( (Handle) h); - if (fullPath != NULL) - DisposeHandle( fullPath); - return cpath; -} - -#endif /* assumes registries are open (only use after vr_Init() returns OK). * For UNIX look first in the global, then in the local if not found @@ -703,7 +618,7 @@ static REGERR vr_FindKey(char *component_path, HREG *hreg, RKEY *key) rootkey = UNIX_ROOT(component_path); err = NR_RegGetKey( *hreg, rootkey, component_path, key ); } - if (unixreg == NULL || err == REGERR_NOFIND ) + if (unixreg == NULL || err == REGERR_NOFIND ) #endif { *hreg = vreg; @@ -715,6 +630,7 @@ static REGERR vr_FindKey(char *component_path, HREG *hreg, RKEY *key) } + /* --------------------------------------------------------------------- * Interface * --------------------------------------------------------------------- @@ -749,25 +665,36 @@ VR_INTERFACE(REGERR) VR_CreateRegistry( char *installation, char *programPath, c REGERR err; XP_StatStruct st; char * regname = ""; -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) +#ifdef XP_UNIX char * regbuf = NULL; #endif if ( installation == NULL || *installation == '\0' ) return REGERR_PARAM; -#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) + +#ifdef XP_UNIX + +#ifndef STANDALONE_REGISTRY if (bGlobalRegistry) { - regbuf = (char*)XP_ALLOC( 10 + XP_STRLEN(programPath) ); - if (regbuf == NULL) - return REGERR_MEMORY; +#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; - XP_STRCPY( regbuf, programPath ); - XP_STRCAT( regbuf, "registry" ); - regname = regbuf; +#ifndef STANDALONE_REGISTRY } -#endif +#endif + +#endif /* XP_UNIX */ + + #ifdef STANDALONE_REGISTRY /* standalone registry automatically creates it if not found */ @@ -787,7 +714,7 @@ VR_INTERFACE(REGERR) VR_CreateRegistry( char *installation, char *programPath, c XP_FileClose(fh); err = NR_RegOpen( regname, &vreg ); - if (err != REGERR_OK) + if (err != REGERR_OK) goto done; /* create default tree with 'installation' under Navigator */ @@ -897,8 +824,6 @@ VR_INTERFACE(REGERR) VR_GetPath(char *component_path, uint32 sizebuf, char *buf) } /* GetPath */ - - VR_INTERFACE(REGERR) VR_SetDefaultDirectory(char *component_path, char *directory) { REGERR err; @@ -973,7 +898,7 @@ VR_INTERFACE(REGERR) VR_Install(char *component_path, char *filepath, char *vers 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; @@ -1018,8 +943,6 @@ VR_INTERFACE(REGERR) VR_Remove(char *component_path) } /* Remove */ - - VR_INTERFACE(REGERR) VR_Enum(char *component_path, REGENUM *state, char *buffer, uint32 buflen) { @@ -1046,8 +969,6 @@ VR_INTERFACE(REGERR) VR_Enum(char *component_path, REGENUM *state, } /* Enum */ - - VR_INTERFACE(REGERR) VR_InRegistry(char *component_path) { REGERR err; @@ -1068,6 +989,7 @@ VR_INTERFACE(REGERR) VR_InRegistry(char *component_path) } /* InRegistry */ + VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path) { REGERR err; @@ -1139,7 +1061,6 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path) } /* CheckEntry */ - VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path) { char *tmp; @@ -1155,7 +1076,6 @@ VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path) return REGERR_OK; } - VR_INTERFACE(REGERR) VR_SetRefCount(char *component_path, int refcount) { REGERR err; @@ -1231,10 +1151,14 @@ VR_INTERFACE(REGERR) VR_GetRefCount(char *component_path, int *result) #pragma export reset #endif -static void vr_GetUninstallItemPath(char *regPackageName, char *regbuf) +static REGERR vr_GetUninstallItemPath(char *regPackageName, char *regbuf, uint32 regbuflen) { Bool bSharedUninstall = FALSE; Bool bNavPackage = FALSE; + uint32 len = 0; + uint32 sharedstrlen = 0; + uint32 curstrlen = 0; + uint32 curregbuflen = 0; /* determine install type */ if (*regPackageName == '\0') { @@ -1245,31 +1169,62 @@ static void vr_GetUninstallItemPath(char *regPackageName, char *regbuf) } /* create uninstall path prefix */ - XP_STRCPY( regbuf, REG_UNINSTALL_DIR ); - if (bSharedUninstall) + len = XP_STRLEN(REG_UNINSTALL_DIR); + if (len < regbuflen) { - XP_STRCAT( regbuf, SHAREDSTR ); + XP_STRCPY( regbuf, REG_UNINSTALL_DIR ); } else { - XP_STRCAT( regbuf, curstr ); - XP_STRCAT( regbuf, "/" ); + return REGERR_BUFTOOSMALL; + } + if (bSharedUninstall) + { + sharedstrlen = XP_STRLEN(SHAREDSTR); + if (sharedstrlen < (regbuflen - len)) + XP_STRCAT( regbuf, SHAREDSTR ); + else + return REGERR_BUFTOOSMALL; + } + else + { + curstrlen = XP_STRLEN(curstr); + if (curstrlen < (regbuflen - len)) + XP_STRCAT( regbuf, curstr ); + else + return REGERR_BUFTOOSMALL; + if (1 < (regbuflen - len - curstrlen)) + XP_STRCAT( regbuf, "/" ); + else + return REGERR_BUFTOOSMALL; } /* add final uninstall node name */ + len = 0; + curregbuflen = XP_STRLEN(regbuf); if ( bNavPackage ) { - XP_STRCAT( regbuf, UNINSTALL_NAV_STR ); + len = XP_STRLEN(UNINSTALL_NAV_STR); + if (len < (regbuflen - curregbuflen)) + XP_STRCAT( regbuf, UNINSTALL_NAV_STR ); + else + return REGERR_BUFTOOSMALL; } else { - XP_STRCAT( regbuf, regPackageName ); + len = XP_STRLEN(regPackageName); + if (len < (regbuflen - curregbuflen)) + XP_STRCAT( regbuf, regPackageName ); + else + return REGERR_BUFTOOSMALL; } + return REGERR_OK; } + /** * Replaces all '/' with '_',in the given string.If an '_' already exists in the * given string, it is escaped by adding another '_' to it. */ -static void vr_convertPackageName(char *regPackageName, char *convertedPackageName) +static REGERR vr_convertPackageName(char *regPackageName, char *convertedPackageName, uint32 convertedDataLength) { int32 length = 0; int i; @@ -1277,16 +1232,29 @@ static void vr_convertPackageName(char *regPackageName, char *convertedPackageNa length = XP_STRLEN(regPackageName); - for (i=0; i #include +#include #include +#include #ifdef SUNOS4 #include /* for SEEK_SET */ #endif /* SUNOS4 */ +#ifdef XP_MAC +#include "prmacos.h" +#endif + #include "reg.h" #include "NSReg.h" @@ -105,6 +111,120 @@ char *globalRegName = NULL; static char *user_name = NULL; + + +#ifdef XP_MAC + +void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length); +char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength); + +#include +#include +#include +#include +#include "FullPath.h" + +/* returns an alias as a malloc'd pointer. + * On failure, *alias is NULL + */ +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; +} + +/* resolves an alias, and returns a full path to the Mac file + * If the alias changed, it would be nice to update our alias pointers + */ +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 */ + + 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; +} + +#endif + + /* -------------------------------------------------------------------- * Registry List management * -------------------------------------------------------------------- @@ -207,8 +327,7 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) return REGERR_READONLY; else return REGERR_FAIL; - -#ifdef EMFILE /* Mac doesn't have EMFILE. */ +#ifdef EMFILE /* Mac Does not have EMFILE */ case EMFILE: /* too many files open */ #endif default: @@ -869,7 +988,7 @@ static REGERR nr_WriteString(REGFILE *reg, char *string, REGDESC *desc) return REGERR_BADUTF8; if (reg->readOnly) return REGERR_READONLY; - len = XP_STRLEN(string) + 1; + len = XP_STRLEN(string) + 1; return nr_WriteData( reg, string, len, desc ); @@ -1107,6 +1226,7 @@ static REGERR nr_NextName(char *pPath, char *buf, uint32 bufsize, char **newPath + static REGERR nr_CatName(REGFILE *reg, REGOFF node, char *path, uint32 bufsize, REGDESC *desc) { REGERR err = REGERR_OK; @@ -1169,7 +1289,7 @@ static REGERR nr_ReplaceName(REGFILE *reg, REGOFF node, char *path, uint32 bufsi --len; } if ( *p == PATHDEL ) { - p++; + p++; len++; } } @@ -1233,7 +1353,7 @@ static REGERR nr_FindAtLevel(REGFILE *reg, REGOFF offFirst, char *pName, REGDESC *pDesc, REGOFF *pOffPrev); static REGERR nr_CreateSubKey(REGFILE *reg, REGDESC *pParent, char *name); -static REGERR nr_CreateEntryString(REGFILE *reg, REGDESC *pParent, +static REGERR nr_CreateEntryString(REGFILE *reg, REGDESC *pParent, char *name, char *value); static REGERR nr_CreateEntry(REGFILE *reg, REGDESC *pParent, char *name, uint16 type, char *buffer, uint32 length); @@ -1705,7 +1825,7 @@ static void nr_InitStdRkeys( REGFILE *reg ) } /* 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 ); @@ -1855,7 +1975,6 @@ static void nr_Upgrade_1_1(REGFILE *reg) } - static char *nr_GetUsername() { if (NULL == user_name) { @@ -1950,10 +2069,6 @@ VR_INTERFACE(REGERR) NR_RegOpen( char *filename, HREG *hReg ) REGFILE *pReg; REGHANDLE *pHandle; - filename = nr_GetRegName( filename ); - - XP_ASSERT(bRegStarted); - /* initialize output handle in case of error */ *hReg = NULL; @@ -1961,6 +2076,8 @@ VR_INTERFACE(REGERR) NR_RegOpen( char *filename, HREG *hReg ) if ( !bRegStarted ) return REGERR_FAIL; + filename = nr_GetRegName( filename ); + #if !defined(STANDALONE_REGISTRY) PR_EnterMonitor(reglist_monitor); #endif @@ -2102,7 +2219,7 @@ VR_INTERFACE(REGERR) NR_RegClose( HREG hReg ) PR_ExitMonitor(reglist_monitor); #endif - reghnd->magic = 0; /* prevent accidental re-use */ + reghnd->magic = 0; /* prevent accidental re-use */ XP_FREE( reghnd ); return REGERR_OK; @@ -2120,7 +2237,6 @@ VR_INTERFACE(REGERR) NR_RegClose( HREG hReg ) static REGERR nr_createTempRegName( char *filename, uint32 filesize ); static REGERR nr_addNodesToNewReg( HREG hReg, RKEY rootkey, HREG hRegNew, void *userData, nr_RegPackCallbackFunc fn ); /* -------------------------------------------------------------------- */ - static REGERR nr_createTempRegName( char *filename, uint32 filesize ) { struct stat statbuf; @@ -2131,9 +2247,18 @@ static REGERR nr_createTempRegName( char *filename, uint32 filesize ) XP_STRCPY( tmpname, filename ); len = XP_STRLEN(tmpname); + if (len < filesize) { + tmpname[len-1] = '~'; + tmpname[len] = '\0'; + remove(tmpname); + if ( stat(tmpname, &statbuf) != 0 ) + nameFound = TRUE; + } + len++; while (!nameFound && len < filesize ) { tmpname[len-1] = '~'; tmpname[len] = '\0'; + remove(tmpname); if ( stat(tmpname, &statbuf) != 0 ) nameFound = TRUE; else @@ -2253,6 +2378,10 @@ VR_INTERFACE(REGERR) NR_RegPack( HREG hReg, void *userData, nr_RegPackCallbackFu int status = REGERR_OK; RKEY key; + XP_ASSERT(bRegStarted); + if ( !bRegStarted ) + return REGERR_FAIL; + reg = ((REGHANDLE*)hReg)->pReg; /* lock registry */ @@ -2720,7 +2849,6 @@ VR_INTERFACE(REGERR) NR_RegGetEntry( HREG hReg, RKEY key, char *name, break; - case REGTYPE_ENTRY_STRING_UTF: tmpbuf = (char*)buffer; err = nr_ReadData( reg, &desc, *size, tmpbuf ); @@ -2728,7 +2856,37 @@ VR_INTERFACE(REGERR) NR_RegGetEntry( HREG hReg, RKEY key, char *name, tmpbuf[(*size)-1] = '\0'; break; + case REGTYPE_ENTRY_FILE: + err = nr_ReadData( reg, &desc, *size, (char*)buffer ); +#ifdef XP_MAC + if (err == 0) + { + tmpbuf = nr_PathFromMacAlias(buffer, *size); + if (tmpbuf == NULL) + { + buffer = NULL; + err = REGERR_NOFIND; + } + else + { + needFree = TRUE; + + if (XP_STRLEN(tmpbuf) > *size) + { + err = REGERR_BUFTOOSMALL; + } + else + { + XP_STRCPY(buffer, tmpbuf); + } + } + } +#endif + + + break; + case REGTYPE_ENTRY_BYTES: default: /* return raw data for unknown types */ err = nr_ReadData( reg, &desc, *size, (char*)buffer ); @@ -2836,12 +2994,13 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HREG hReg, RKEY key, char *name, uint16 typ REGFILE* reg; REGDESC desc; REGDESC parent; - char *data; + char *data = NULL; uint32 nInt; uint32 *pIDest; uint32 *pISrc; XP_Bool needFree = FALSE; - + int32 datalen = size; + XP_ASSERT(bRegStarted); /* verify parameters */ @@ -2860,7 +3019,18 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HREG hReg, RKEY key, char *name, uint16 typ case REGTYPE_ENTRY_BYTES: data = (char*)buffer; break; + + case REGTYPE_ENTRY_FILE: +#ifdef XP_MAC + nr_MacAliasFromPath(buffer, &data, &datalen); + if (data) + needFree = TRUE; +#else + data = (char*)buffer; +#endif + break; + case REGTYPE_ENTRY_STRING_UTF: data = (char*)buffer; @@ -2910,7 +3080,7 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HREG hReg, RKEY key, char *name, uint16 typ if ( err == REGERR_OK ) { /* then update the existing one */ - err = nr_WriteData( reg, data, size, &desc ); + err = nr_WriteData( reg, data, datalen, &desc ); if ( err == REGERR_OK ) { desc.type = type; @@ -2920,7 +3090,7 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HREG hReg, RKEY key, char *name, uint16 typ else if ( err == REGERR_NOFIND ) { /* otherwise create a new entry */ - err = nr_CreateEntry( reg, &parent, name, type, data, size ); + err = nr_CreateEntry( reg, &parent, name, type, data, datalen ); } else { /* other errors fall through */ @@ -3293,10 +3463,6 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries( HREG hReg, RKEY key, REGENUM *state, - -#ifndef STANDALONE_REGISTRY -#include "VerReg.h" - /* --------------------------------------------------------------------- * --------------------------------------------------------------------- * Registry initialization and shut-down @@ -3304,7 +3470,14 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries( HREG hReg, RKEY key, REGENUM *state, * --------------------------------------------------------------------- */ +#include "VerReg.h" + +#ifndef STANDALONE_REGISTRY extern PRMonitor *vr_monitor; +#endif + + + #ifdef XP_UNIX extern XP_Bool bGlobalRegistry; #endif @@ -3323,11 +3496,14 @@ VR_INTERFACE(void) NR_StartupRegistry(void) if (bRegStarted) return; - + +#ifndef STANDALONE_REGISTRY vr_monitor = PR_NewMonitor(); XP_ASSERT( vr_monitor != NULL ); reglist_monitor = PR_NewMonitor(); XP_ASSERT( reglist_monitor != NULL ); +#endif + #ifdef XP_UNIX bGlobalRegistry = ( getenv(UNIX_GLOBAL_FLAG) != NULL ); #endif @@ -3337,7 +3513,8 @@ VR_INTERFACE(void) NR_StartupRegistry(void) vr_findGlobalRegName(); /* check to see that we have a valid registry */ - if (REGERR_OK == NR_RegOpen("", ®)) { + if (REGERR_OK == NR_RegOpen("", ®)) + { NR_RegClose(reg); } else { @@ -3346,7 +3523,6 @@ VR_INTERFACE(void) NR_StartupRegistry(void) VR_InRegistry("/Netscape"); VR_Close(); } - } VR_INTERFACE(void) NR_ShutdownRegistry(void) @@ -3355,12 +3531,14 @@ VR_INTERFACE(void) NR_ShutdownRegistry(void) if (!bRegStarted) return; - + +#ifndef STANDALONE_REGISTRY if ( vr_monitor != NULL ) { VR_Close(); PR_DestroyMonitor(vr_monitor); vr_monitor = NULL; } +#endif /* close any forgotten open registries */ while ( RegList != NULL ) { @@ -3372,10 +3550,14 @@ VR_INTERFACE(void) NR_ShutdownRegistry(void) nr_DeleteNode( pReg ); } + +#ifndef STANDALONE_REGISTRY if ( reglist_monitor != NULL ) { PR_DestroyMonitor( reglist_monitor ); reglist_monitor = NULL; } +#endif + XP_FREEIF(user_name); @@ -3388,6 +3570,4 @@ VR_INTERFACE(void) NR_ShutdownRegistry(void) #pragma export reset #endif -#endif /* STANDALONE_REGISTRY */ - /* EOF: reg.c */ diff --git a/mozilla/modules/libreg/src/reg.h b/mozilla/modules/libreg/src/reg.h index 1667840fab0..0136c5e3520 100644 --- a/mozilla/modules/libreg/src/reg.h +++ b/mozilla/modules/libreg/src/reg.h @@ -88,7 +88,7 @@ * Types and Objects * -------------------------------------------------------------------- */ - +#undef REGOFF typedef int32 REGOFF; /* offset into registry file */ typedef struct _desc diff --git a/mozilla/modules/libreg/src/vr_stubs.c b/mozilla/modules/libreg/src/vr_stubs.c index 7fc787876e9..869e822d408 100644 --- a/mozilla/modules/libreg/src/vr_stubs.c +++ b/mozilla/modules/libreg/src/vr_stubs.c @@ -21,6 +21,7 @@ */ #include +#include #ifndef STANDALONE_REGISTRY #include "prtypes.h" @@ -29,11 +30,6 @@ #include "vr_stubs.h" #ifdef XP_MAC -#ifndef theRegistry -#define theRegistry 33 /* Duplicated from uprefd.h. I know this is a bad thing to do but you */ - /* don't even want to know what including that would do since it's a */ - /* header for a C++ file */ -#endif /* theRegistry */ #include #include #include @@ -156,14 +152,32 @@ extern XP_File vr_fileOpen (const char *name, const char * mode) { XP_File fh = NULL; struct stat st; - + OSErr anErr; + FSSpec newFSSpec; + + 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 ); - } - + } + } return fh; } @@ -177,18 +191,15 @@ extern void vr_findGlobalRegName () Handle thePath; int bCreate = 0; Ptr finalPath; - Str255 registryName; err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID); if (!err) { - - GetIndString(registryName, 300, theRegistry); - err = FSMakeFSSpec(foundVRefNum, foundDirID, registryName, ®Spec); + err = FSMakeFSSpec(foundVRefNum, foundDirID, "\pNetscape Registry", ®Spec); if (err == -43) { /* if file doesn't exist */ - err = FSpCreate(®Spec, ' ', ' ', smSystemScript); + err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); bCreate = 1; } @@ -246,7 +257,7 @@ extern int nr_RenameFile(char *from, char *to) } -#if 0 +#if 1 /* Uncomment the following for older Mac build environments * that don't support these functions */ @@ -264,7 +275,6 @@ char *strdup(const char *source) return newAllocation; } - int strcasecmp(const char *str1, const char *str2) { char currentChar1, currentChar2; @@ -356,6 +366,7 @@ long BUILDNUM = ; #endif + REGERR vr_ParseVersion(char *verstr, VERSION *result); int main(int argc, char *argv[]); @@ -452,11 +463,17 @@ int main(int argc, char *argv[]) } strcat(buff, "/"); + + NR_StartupRegistry(); + VR_SetRegDirectory(buff); + + if ( -1 == (access( TheRegistry, W_OK )) ) { - sprintf(ver,"4.1.0.%ld",BUILDNUM); + sprintf(ver,"4.50.0.%ld",BUILDNUM); VR_CreateRegistry("Communicator", buff, ver); } + if ( !(fh = fopen( Flist, "r" )) ) { fprintf(stderr, "%s: Cannot open \"%s\"\n", argv[0], Flist); @@ -490,3 +507,5 @@ int main(int argc, char *argv[]) #endif /* STANDALONE_REGISTRY */ #endif /* XP_UNIX || XP_OS2 */ + +