landing XPCOM_BRANCH

git-svn-id: svn://10.0.0.236/trunk@2218 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hardts
1998-05-22 21:56:30 +00:00
parent d583c3a3b9
commit 217d4a9900
47 changed files with 1759 additions and 491 deletions

View File

@@ -1618,6 +1618,12 @@ install: \
!IF EXIST($(DIST)\bin\sched32.dll)
$(OUTDIR)\sched32.dll \
!ENDIF
!IF EXIST($(DIST)\bin\libreg32.dll)
$(OUTDIR)\libreg32.dll \
!ENDIF
!IF EXIST($(DIST)\bin\xpcom32.dll)
$(OUTDIR)\xpcom32.dll \
!ENDIF
!IF EXIST($(DIST)\bin\jrt32$(VERSION_NUMBER).dll)
$(OUTDIR)\jrt32$(VERSION_NUMBER).dll \
!ENDIF
@@ -1723,6 +1729,12 @@ install: \
!IF EXIST($(DIST)\bin\sched16.dll)
$(OUTDIR)\sched16.dll \
!ENDIF
!IF EXIST($(DIST)\bin\libreg16.dll)
$(OUTDIR)\libreg16.dll \
!ENDIF
!IF EXIST($(DIST)\bin\xpcom16.dll)
$(OUTDIR)\xpcom16.dll \
!ENDIF
!IF EXIST($(DIST)\bin\nsinit.exe)
$(OUTDIR)\nsinit.exe \
!ENDIF
@@ -1874,6 +1886,12 @@ $(OUTDIR)\xppref32.dll: $(DIST)\bin\xppref32.dll
$(OUTDIR)\sched32.dll: $(DIST)\bin\sched32.dll
@IF EXIST $(DIST)\bin\sched32.dll copy $(DIST)\bin\sched32.dll $(OUTDIR)\sched32.dll
$(OUTDIR)\libreg32.dll: $(DIST)\bin\libreg32.dll
@IF EXIST $(DIST)\bin\libreg32.dll copy $(DIST)\bin\libreg32.dll $(OUTDIR)\libreg32.dll
$(OUTDIR)\xpcom32.dll: $(DIST)\bin\xpcom32.dll
@IF EXIST $(DIST)\bin\xpcom32.dll copy $(DIST)\bin\xpcom32.dll $(OUTDIR)\xpcom32.dll
$(OUTDIR)\uni3200.dll: $(DIST)\bin\uni3200.dll
@IF EXIST $(DIST)\bin\uni3200.dll copy $(DIST)\bin\uni3200.dll $(OUTDIR)\uni3200.dll
@@ -1949,6 +1967,12 @@ $(OUTDIR)\xppref16.dll: $(DIST)\bin\xppref16.dll
$(OUTDIR)\sched16.dll: $(DIST)\bin\sched16.dll
@IF EXIST $(DIST)\bin\sched16.dll copy $(DIST)\bin\sched16.dll $(OUTDIR)\sched16.dll
$(OUTDIR)\libreg16.dll: $(DIST)\bin\libreg16.dll
@IF EXIST $(DIST)\bin\libreg16.dll copy $(DIST)\bin\libreg16.dll $(OUTDIR)\libreg16.dll
$(OUTDIR)\xpcom16.dll: $(DIST)\bin\xpcom16.dll
@IF EXIST $(DIST)\bin\xpcom16.dll copy $(DIST)\bin\xpcom16.dll $(OUTDIR)\xpcom16.dll
$(OUTDIR)\uni1600.dll: $(DIST)\bin\uni1600.dll
@IF EXIST $(DIST)\bin\uni1600.dll copy $(DIST)\bin\uni1600.dll $(OUTDIR)\uni1600.dll
@@ -2212,6 +2236,7 @@ BUILD_SOURCE: $(OBJ_FILES)
$(DIST)\lib\softup16.lib +
!else
$(DIST)\lib\libreg16.lib +
$(DIST)\lib\xpcom16.lib +
$(DIST)\lib\libsjs16.lib +
$(DIST)\lib\libnjs16.lib +
!endif
@@ -2249,6 +2274,8 @@ BUILD_SOURCE: $(OBJ_FILES)
$(DIST)\lib\hook.lib +
$(DIST)\lib\png.lib +
$(DIST)\lib\sched16.lib +
$(DIST)\lib\libreg16.lib +
$(DIST)\lib\xpcom16.lib +
$(DIST)\lib\rdf16.lib +
$(DIST)\lib\xpstrdll.lib +
$(DIST)\lib\abouturl.lib +
@@ -2676,5 +2703,7 @@ ns.zip:
editor32.dll \
xppref32.dll \
sched32.dll \
libreg32.dll \
xpcom32.dll \
netscape.cfg \
moz40p3

View File

@@ -18,6 +18,6 @@
DEPTH = ../..
DIRS = include src
DIRS = include src
include $(DEPTH)/config/rules.mk

View File

@@ -81,17 +81,17 @@ typedef struct _reginfo
#define UNIX_GLOBAL_FLAG "MOZILLA_SHARED_REGISTRY"
/* Platform-dependent declspec for library interface */
#if defined(STANDALONE_REGISTRY) && defined(XP_PC)
#if defined(WIN32)
#define VR_INTERFACE(type) __declspec(dllexport) type __stdcall
#elif defined(XP_OS2)
#define VR_INTERFACE(type) type _Optlink
#else
#define VR_INTERFACE(type) type _far _pascal _export
#endif
#if defined(XP_PC)
#if defined(WIN32)
#define VR_INTERFACE(type) __declspec(dllexport) type __stdcall
#elif defined(XP_OS2)
#define VR_INTERFACE(type) type _Optlink
#else
#define VR_INTERFACE(type) type _far _pascal _export
#endif
#else
#define VR_INTERFACE(type) type
#endif /* STANDALONE_REGISTRY and XP_PC */
#define VR_INTERFACE(type) type
#endif
XP_BEGIN_PROTOS
@@ -113,6 +113,10 @@ VR_INTERFACE(REGERR) NR_RegPack(
HREG hReg /* handle of open registry to pack */
);
VR_INTERFACE(REGERR) NR_RegSetUsername(
const char *name /* name of current user */
);
/* ---------------------------------------------------------------------
* Registry API -- Key Management functions
* ---------------------------------------------------------------------
@@ -207,8 +211,8 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries(
);
#ifndef STANDALONE_REGISTRY
void NR_ShutdownRegistry(void);
void NR_StartupRegistry(void);
VR_INTERFACE(void) NR_ShutdownRegistry(void);
VR_INTERFACE(void) NR_StartupRegistry(void);
#endif /* STANDALONE_REGISTRY */
XP_END_PROTOS

View File

@@ -54,14 +54,10 @@ VR_INTERFACE(REGERR) VR_InRegistry(char *path);
VR_INTERFACE(REGERR) VR_ValidateComponent(char *path);
VR_INTERFACE(REGERR) VR_Enum(REGENUM *state, char *buffer, uint32 buflen);
#ifndef STANDALONE_REGISTRY
VR_INTERFACE(void) VR_Initialize(void* env);
#endif
VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path);
XP_END_PROTOS
#endif /* _VERREG_H_ */
/* EOF: VerReg.h */

View File

@@ -37,6 +37,7 @@ DEPTH=..\..
#// DIRS - There are subdirectories to process
#//
#//------------------------------------------------------------------------
DIRS=include src
#//------------------------------------------------------------------------

View File

@@ -22,7 +22,7 @@ LIBRARY_NAME = reg
REQUIRES = libreg nspr dbm pref js
CSRCS = reg.c VerReg.c
CSRCS = reg.c VerReg.c vr_stubs.c
BIN_SRCS = VerReg.c reg.c vr_stubs.c
BIN_OBJS = $(addprefix $(OBJDIR)/R_,$(BIN_SRCS:.c=.o))
@@ -42,9 +42,9 @@ PROGRAM = $(OBJDIR)/vreg$(BIN_SUFFIX)
$(PROGRAM): $(BIN_OBJS)
@$(MAKE_OBJDIR)
ifeq ($(OS_ARCH), OS2)
$(LINK_EXE) -OUT:$@ $(BIN_OBJS) $(LDFLAGS) $(OS_LIBS) $(DIST)/lib/libxp.$(LIB_SUFFIX)
$(LINK_EXE) -OUT:$@ $(BIN_OBJS) $(LDFLAGS) $(OS_LIBS)
else
$(CCF) -o $@ $(BIN_OBJS) $(LDFLAGS) $(DIST)/lib/lib$(LITE_PREFIX)xp.$(LIB_SUFFIX)
$(CCF) -o $@ $(BIN_OBJS) $(LDFLAGS)
endif
$(OBJDIR)/R_VerReg.o: VerReg.c

View File

@@ -37,36 +37,10 @@
#include <io.h>
#endif
#ifndef STANDALONE_REGISTRY
#include "xp_mcom.h"
#include "xp_core.h"
#ifndef NSPR20
#include "prosdep.h"
#else
#ifdef XP_MAC
#include <Folders.h>
#include "prosdep.h"
#else
#include "md/prosdep.h"
#endif
#endif
#include "prmon.h"
#ifdef BROKEN
#include "su_folderspec.h"
#endif
#else
#ifdef XP_MAC
#include <types.h>
#include <stat.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#endif
#include "reg.h"
#include "NSReg.h"
@@ -115,6 +89,7 @@ XP_Bool bGlobalRegistry = FALSE;
PRMonitor *vr_monitor = NULL;
#endif
static char *app_dir = NULL;
/* ---------------------------------------------------------------------
* local functions
@@ -160,14 +135,14 @@ static REGERR vr_Init(void)
if (!isInited)
{
#ifndef STANDALONE_REGISTRY
#ifdef BROKEN
curPath = FE_GetDirectoryPath(eCommunicatorFolder);
#else
/* can't use Version Registry interface until "BROKEN" works */
err = REGERR_FAIL;
goto done;
#endif
#if !defined(STANDALONE_REGISTRY)
curPath = app_dir;
if (curPath == NULL) {
/* can't use Version Registry interface until "BROKEN" works */
err = REGERR_FAIL;
goto done;
}
#ifdef XP_UNIX
if (curPath != NULL) {
regbuf = (char*)XP_ALLOC( 10 + XP_STRLEN(curPath) );
@@ -259,7 +234,6 @@ static REGERR vr_Init(void)
done:
#ifndef STANDALONE_REGISTRY
PR_ExitMonitor(vr_monitor);
XP_FREEIF(curPath);
#ifdef XP_UNIX
XP_FREEIF(regbuf);
#endif
@@ -1101,7 +1075,7 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path)
}
urlPath = path;
#ifndef STANDALONE_REGISTRY
#ifdef BROKEN
url = XP_PlatformFileToURL(path);
if ( url == NULL )
return REGERR_MEMORY;
@@ -1144,4 +1118,17 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path)
#pragma export reset
#endif
VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path)
{
char *tmp = XP_STRDUP(path);
if (NULL == tmp) {
return REGERR_MEMORY;
}
XP_FREEIF(app_dir);
app_dir = tmp;
return REGERR_OK;
}
/* EOF: VerReg.c */

View File

@@ -31,7 +31,7 @@ IGNORE_MANIFEST=1
DEPTH= ..\..\..
!ifndef MAKE_OBJ_TYPE
MAKE_OBJ_TYPE=EXE
MAKE_OBJ_TYPE=DLL
!endif
#//------------------------------------------------------------------------
@@ -39,8 +39,6 @@ MAKE_OBJ_TYPE=EXE
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
LIBNAME=libreg$(MOZ_BITS)
PDBFILE=$(LIBNAME).pdb
#//------------------------------------------------------------------------
#//
@@ -51,6 +49,7 @@ PDBFILE=$(LIBNAME).pdb
OBJS= \
.\$(OBJDIR)\reg.obj \
.\$(OBJDIR)\VerReg.obj \
.\$(OBJDIR)\vr_stubs.obj \
$(NULL)
#//------------------------------------------------------------------------
@@ -60,6 +59,8 @@ OBJS= \
#//
#//------------------------------------------------------------------------
LIBNAME=libreg$(MOZ_BITS)
DLL=$(OBJDIR)\$(LIBNAME).dll
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
#//------------------------------------------------------------------------
@@ -69,15 +70,14 @@ LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
#//
#//------------------------------------------------------------------------
LCFLAGS = $(LCFLAGS)
LLIBS = $(LLIBS) $(LIBNSPR)
#//
#// Win16 places ALL public header files in $(PUBLIC)/win16
#//
!if "$(MOZ_BITS)" != "16"
LINCS= $(LINCS) -I$(PUBLIC)/libreg \
-I$(PUBLIC)/nspr \
-I$(PUBLIC)/dbm \
-I$(PUBLIC)/pref \
-I$(PUBLIC)/js \
$(NULL)
!endif
@@ -88,6 +88,11 @@ LINCS= $(LINCS) -I$(PUBLIC)/libreg \
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
install:: $(LIBRARY)
export:: $(DLL)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
$(MAKE_INSTALL) $(DLL) $(DIST)\bin
clobber::
$(RM) $(DIST)\bin\$(DLL)
$(RM) $(DIST)\lib\$(LIBRARY)

View File

@@ -33,13 +33,10 @@
#define VERIFY_READ 1
#endif
#ifndef STANDALONE_REGISTRY
#include "xp_mcom.h"
#include "xp_error.h"
#include "prmon.h"
#include "prefapi.h"
#else
#ifdef XP_MAC
#include <size_t.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -49,7 +46,6 @@
#ifdef SUNOS4
#include <unistd.h> /* for SEEK_SET */
#endif /* SUNOS4 */
#endif /* STANDALONE_REGISTRY */
#include "reg.h"
#include "NSReg.h"
@@ -97,7 +93,7 @@ static XP_Bool bRegStarted = FALSE;
#if !defined(STANDALONE_REGISTRY)
static PRMonitor *reglist_monitor;
#endif
static char *user_name = NULL;
/* --------------------------------------------------------------------
@@ -1513,6 +1509,8 @@ static void nr_InitStdRkeys( REGFILE *reg );
static Bool nr_ProtectedNode( REGFILE *reg, REGOFF key );
static REGERR nr_RegAddKey( REGFILE *reg, RKEY key, char *path, RKEY *newKey );
static void nr_Upgrade_1_1( REGFILE *reg );
static char* nr_GetUsername();
/* --------------------------------------------------------------------- */
@@ -1549,9 +1547,8 @@ static REGOFF nr_TranslateKey( REGFILE *reg, RKEY key )
REGERR err;
char* profName;
err = PREF_CopyDefaultCharPref( "profile.name", &profName );
if (err == PREF_NOERROR ) {
profName = nr_GetUsername();
if ( NULL != profName ) {
/* Don't assign a slot for missing or magic profile */
if ( '\0' == *profName ||
0 == XP_STRCMP(ASW_MAGIC_PROFILE_NAME, profName))
@@ -1790,12 +1787,42 @@ static void nr_Upgrade_1_1(REGFILE *reg)
}
static char *nr_GetUsername()
{
if (NULL == user_name) {
return "default";
} else {
return user_name;
}
}
/* ---------------------------------------------------------------------
* Public API
* --------------------------------------------------------------------- */
/* ---------------------------------------------------------------------
* NR_RegSetUsername - Set the current username
*
* Parameters:
* name - name of the current user
*
* Output:
* ---------------------------------------------------------------------
*/
VR_INTERFACE(REGERR) NR_RegSetUsername(const char *name)
{
char *tmp = XP_STRDUP(name);
if (NULL == tmp) {
return REGERR_MEMORY;
}
XP_FREEIF(user_name);
user_name = tmp;
return REGERR_OK;
}
/* ---------------------------------------------------------------------
* NReg_Open - Open a netscape XP registry
*
@@ -2845,19 +2872,13 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries( HREG hReg, RKEY key, REGENUM *state,
#ifndef STANDALONE_REGISTRY
#include "VerReg.h"
#ifdef WIN32
extern BOOL WFE_IsMoveFileExBroken();
#endif
/* ---------------------------------------------------------------------
* ---------------------------------------------------------------------
* Registry initialization and shut-down
* ---------------------------------------------------------------------
* ---------------------------------------------------------------------
*/
#ifdef BROKEN
extern void SU_InitMonitor(void);
extern void SU_DestroyMonitor(void);
#endif
extern PRMonitor *vr_monitor;
#ifdef XP_UNIX
extern XP_Bool bGlobalRegistry;
@@ -2867,14 +2888,12 @@ extern XP_Bool bGlobalRegistry;
#pragma export on
#endif
void NR_StartupRegistry(void)
VR_INTERFACE(void) NR_StartupRegistry(void)
{
HREG reg;
RKEY key;
REGERR err;
REGENUM state;
XP_Bool removeFromList;
XP_StatStruct stat;
if (bRegStarted)
return;
vr_monitor = PR_NewMonitor();
XP_ASSERT( vr_monitor != NULL );
@@ -2884,110 +2903,10 @@ void NR_StartupRegistry(void)
bGlobalRegistry = ( getenv(UNIX_GLOBAL_FLAG) != NULL );
#endif
#ifdef BROKEN
SU_InitMonitor();
#endif
bRegStarted = TRUE;
/* need to register a PREF callback for "profile.name" */
/* check to see that we have a valid registry */
if (REGERR_OK == NR_RegOpen("", &reg))
{
#ifdef XP_PC
/* perform scheduled file deletions and replacements (PC only) */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE,
REG_DELETE_LIST_KEY,&key))
{
char *urlFile;
char *pFile;
char buf[MAXREGNAMELEN];
state = 0;
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state,
buf, sizeof(buf), NULL ))
{
urlFile = XP_PlatformFileToURL(buf);
if ( urlFile == NULL)
continue;
pFile = urlFile+7;
removeFromList = FALSE;
if (0 == XP_FileRemove(pFile, xpURL)) {
/* file was successfully deleted */
removeFromList = TRUE;
}
else if (XP_Stat(pFile, &stat, xpURL) != 0) {
/* file doesn't appear to exist */
removeFromList = TRUE;
}
if (removeFromList) {
err = NR_RegDeleteEntry( reg, key, buf );
/* must reset state or enum will stop on deleted entry */
if ( err == REGERR_OK )
state = 0;
}
XP_FREEIF(urlFile);
}
/* delete list node if empty */
state = 0;
if (REGERR_NOMORE == NR_RegEnumEntries( reg, key, &state, buf,
sizeof(buf), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
}
}
/* replace files if any listed */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE,
REG_REPLACE_LIST_KEY, &key))
{
char tmpfile[MAXREGNAMELEN];
char target[MAXREGNAMELEN];
state = 0;
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state,
tmpfile, sizeof(tmpfile), NULL ))
{
removeFromList = FALSE;
if (XP_Stat(tmpfile, &stat, xpURL) != 0)
{
/* new file is gone! */
removeFromList = TRUE;
}
else if ( REGERR_OK != NR_RegGetEntryString( reg, key,
tmpfile, target, sizeof(target) ) )
{
/* can't read target filename, corruption? */
removeFromList = TRUE;
}
else {
if (XP_Stat(target, &stat, xpURL) == 0) {
/* need to delete old file first */
XP_FileRemove( target, xpURL );
}
if (0 == XP_FileRename(tmpfile, xpURL, target, xpURL)) {
removeFromList = TRUE;
}
}
if (removeFromList) {
err = NR_RegDeleteEntry( reg, key, tmpfile );
/* must reset state or enum will stop on deleted entry */
if ( err == REGERR_OK )
state = 0;
}
}
/* delete list node if empty */
state = 0;
if (REGERR_NOMORE == NR_RegEnumEntries(reg, key, &state, tmpfile,
sizeof(tmpfile), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
}
}
#endif /* XP_PC */
if (REGERR_OK == NR_RegOpen("", &reg)) {
NR_RegClose(reg);
}
else {
@@ -2996,9 +2915,10 @@ void NR_StartupRegistry(void)
VR_InRegistry("/Netscape");
VR_Close();
}
}
void NR_ShutdownRegistry(void)
VR_INTERFACE(void) NR_ShutdownRegistry(void)
{
REGFILE* pReg;
@@ -3022,9 +2942,10 @@ void NR_ShutdownRegistry(void)
PR_DestroyMonitor( reglist_monitor );
reglist_monitor = NULL;
}
#ifdef BROKEN
SU_DestroyMonitor();
#endif
XP_FREEIF(user_name);
bRegStarted = FALSE;
}
#ifdef XP_MAC

View File

@@ -22,9 +22,9 @@
#ifndef _REG_H_
#define _REG_H_
#ifdef STANDALONE_REGISTRY
#include "vr_stubs.h"
#else
#ifndef STANDALONE_REGISTRY
#include "prmon.h"
#endif

View File

@@ -19,10 +19,12 @@
/* this file contains stubs needed to build the registry routines
* into a stand-alone library for use with our installers
*/
#ifdef STANDALONE_REGISTRY
#include <stdio.h>
#include <string.h>
#ifndef STANDALONE_REGISTRY
#include "prtypes.h"
#endif
#include "vr_stubs.h"
#ifdef XP_MAC
@@ -176,6 +178,7 @@ char *strdup(const char *source)
return newAllocation;
}
int strcasecmp(const char *str1, const char *str2)
{
char currentChar1, currentChar2;
@@ -255,32 +258,63 @@ int strncasecmp(const char *str1, const char *str2, int length)
#include "NSReg.h"
#include "VerReg.h"
char *TheRegistry;
char *TheRegistry = "registry";
char *Flist;
/* WARNING: build hackery */
#ifdef STANDALONE_REGISTRY
long BUILDNUM =
#include "../../../build/build_number"
;
#endif
REGERR vr_ParseVersion(char *verstr, VERSION *result);
int main(int argc, char *argv[]);
#ifdef XP_UNIX
XP_File VR_StubOpen (const char * mode)
#define DEF_REG "/.netscape/registry"
XP_File VR_StubOpen (const char *name, const char * mode)
{
XP_File fh;
struct stat st;
if ( stat( TheRegistry, &st ) == 0 )
fh = fopen( TheRegistry, XP_FILE_UPDATE_BIN );
else
fh = fopen( TheRegistry, XP_FILE_WRITE_BIN );
return fh;
}
#ifndef STANDALONE_REGISTRY
char *def = NULL;
if (name == NULL || *name == '\0') {
char *home = getenv("HOME");
if (home != NULL) {
def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_REG));
if (def != NULL) {
XP_STRCPY(def, home);
XP_STRCAT(def, DEF_REG);
}
}
if (def != NULL) {
name = def;
} else {
name = TheRegistry;
}
}
#else
name = TheRegistry;
#endif
if ( stat( name, &st ) == 0 )
fh = fopen( name, XP_FILE_UPDATE_BIN );
else
fh = fopen( name, XP_FILE_WRITE_BIN );
#ifndef STANDALONE_REGISTRY
XP_FREEIF(def);
#endif
return fh;
}
#endif
#ifdef STANDALONE_REGISTRY
int main(int argc, char *argv[])
{
XP_File fh;
@@ -361,6 +395,7 @@ int main(int argc, char *argv[])
fclose( fh );
return 0;
}
#endif /* XP_UNIX || XP_OS2 */
#endif /* STANDALONE_REGISTRY */
#endif /* XP_UNIX || XP_OS2 */

View File

@@ -69,12 +69,17 @@
#define XP_FileFlush(file) fflush(file)
#define XP_FileClose(file) fclose(file)
#ifdef XP_UNIX
#define XP_FileOpen(name,type,mode) VR_StubOpen((name), (mode))
#else
#define XP_FileOpen(name,type,mode) VR_StubOpen((mode))
#endif
#define XP_BEGIN_PROTOS
#define XP_END_PROTOS
#define XP_ASSERT(x) ((void)0)
#define XP_STRCAT(a,b) strcat((a),(b))
#define XP_STRCPY(a,b) strcpy((a),(b))
#define XP_STRLEN(x) strlen(x)
#define XP_SPRINTF sprintf
@@ -88,34 +93,25 @@
#define XP_MEMSET(d, c, l) memset((d), (c), (l))
#ifdef XP_PC
#define XP_STRCASECMP(x,y) strcmpi((x),(y))
#ifdef XP_OS2
#define XP_STRCASECMP(x,y) stricmp((x),(y))
#define XP_STRNCASECMP(x,y,n) strnicmp((x),(y),(n))
#else
#define XP_STRNCASECMP(x,y,n) strncmpi((x),(y),(n))
#endif
#endif
#ifdef XP_MAC
#define XP_STRCASECMP(x,y) strcasecmp((x),(y))
#define XP_STRNCASECMP(x,y,n) strncasecmp((x),(y),(n))
extern int strcasecmp(const char *str1, const char *str2);
extern int strncasecmp(const char *str1, const char *str2, int length);
#endif
#ifdef XP_UNIX
#define XP_STRCASECMP strcasecomp /* from libxp.a */
#endif
typedef FILE * XP_File;
#ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
typedef long int32;
typedef unsigned long uint32;
typedef short int16;
typedef unsigned short uint16;
typedef unsigned char uint8;
#endif
typedef char Bool;
typedef int XP_Bool;
@@ -128,7 +124,16 @@ typedef int XP_Bool;
#define XP_Stat(file,data,type) stat((file),(data))
#endif
#ifdef XP_UNIX
extern XP_File VR_StubOpen (const char *name, const char * mode);
#else
extern XP_File VR_StubOpen (const char * mode);
#endif
#ifdef XP_MAC
extern int strcasecmp(const char *str1, const char *str2);
extern int strncasecmp(const char *str1, const char *str2, int length);
extern char * strdup(const char *str);
#endif
#endif /* _VR_STUBS_H_ */

View File

@@ -15,6 +15,6 @@
# Reserved.
DEPTH = ..
DIRS = src
DIRS = src tests
include $(DEPTH)/config/rules.mk

View File

@@ -19,6 +19,10 @@
#include "nsDebug.h"
#include "prlog.h"
#if defined(_WIN32)
#include <windows.h>
#endif
/**
* Implementation of the nsDebug methods. Note that this code is
* always compiled in, in case some other module that uses it is
@@ -47,6 +51,20 @@ NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
#endif
}
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
{
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Break: at file %s, line %d", aFile, aLine));
PR_LogFlush();
//XXX this works on win32 only for now. For all the other platforms call Abort
#if defined(_WIN32)
::DebugBreak();
#else
Abort(aFile, aLine);
#endif
}
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
const char* aFile, PRIntn aLine)
{
@@ -54,7 +72,7 @@ NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
@@ -64,7 +82,7 @@ NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
@@ -74,7 +92,7 @@ NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
@@ -84,7 +102,7 @@ NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::NotReached(const char* aMessage,
@@ -93,7 +111,7 @@ NS_COM void nsDebug::NotReached(const char* aMessage,
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Error(const char* aMessage,
@@ -102,7 +120,7 @@ NS_COM void nsDebug::Error(const char* aMessage,
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Warning(const char* aMessage,

View File

@@ -15,34 +15,40 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <stdio.h>
#include "nsID.h"
#include "prprf.h"
static const char gIDFormat[] =
"{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
static const char gIDFormat2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
/*
* Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} string into
* an nsID
*/
PRBool nsID::Parse(char *aIDStr) {
int count, n1, n2, n3[8];
long int n0;
NS_COM PRBool nsID::Parse(char *aIDStr)
{
PRInt32 count = 0;
PRInt32 n1, n2, n3[8];
PRInt32 n0;
count = sscanf(aIDStr, gIDFormat,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
if (NULL != aIDStr) {
count = PR_sscanf(aIDStr,
(aIDStr[0] == '{') ? gIDFormat : gIDFormat2,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
m0 = (PRInt32) n0;
m1 = (PRInt16) n1;
m2 = (PRInt16) n2;
for (int i = 0; i < 8; i++) {
m3[i] = (PRInt8) n3[i];
m0 = (PRInt32) n0;
m1 = (PRInt16) n1;
m2 = (PRInt16) n2;
for (int i = 0; i < 8; i++) {
m3[i] = (PRInt8) n3[i];
}
}
return (PRBool) (count == 11);
}
@@ -51,15 +57,16 @@ PRBool nsID::Parse(char *aIDStr) {
* format. Caller should delete [] the string.
*/
char *nsID::ToString() const
NS_COM char *nsID::ToString() const
{
char *res = new char[39];
if (res != NULL) {
sprintf(res, gIDFormat,
(long int) m0, (int) m1, (int) m2,
(int) m3[0], (int) m3[1], (int) m3[2], (int) m3[3],
(int) m3[4], (int) m3[5], (int) m3[6], (int) m3[7]);
PR_snprintf(res, 39, gIDFormat,
m0, (PRUint32) m1, (PRUint32) m2,
(PRUint32) m3[0], (PRUint32) m3[1], (PRUint32) m3[2],
(PRUint32) m3[3], (PRUint32) m3[4], (PRUint32) m3[5],
(PRUint32) m3[6], (PRUint32) m3[7]);
}
return res;
}

View File

@@ -25,7 +25,6 @@
#include "prlink.h"
#include "nsRepository.h"
#ifdef USE_NSREG
#define STANDALONE_REGISTRY
#define XP_BEGIN_PROTOS extern "C" {
#define XP_END_PROTOS };
#include "NSReg.h"
@@ -34,7 +33,6 @@
nsHashtable *NSRepository::factories = NULL;
PRMonitor *NSRepository::monitor = NULL;
static NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kFactory2IID, NS_IFACTORY2_IID);
class FactoryEntry {
@@ -77,15 +75,15 @@ public:
id = aID;
}
PRUint32 HashValue() {
PRUint32 HashValue(void) const {
return id.m0;
}
PRBool Equals(nsHashKey *aKey) {
return (id.Equals(((IDKey *) aKey)->id));
PRBool Equals(const nsHashKey *aKey) const {
return (id.Equals(((const IDKey *) aKey)->id));
}
nsHashKey *Clone() {
nsHashKey *Clone(void) const {
return new IDKey(id);
}
};
@@ -100,15 +98,16 @@ static nsresult platformRegister(const nsCID &aCID, const char *aLibrary)
if (err == REGERR_OK) {
RKEY key;
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
"SOFTWARE\\Netscape\\CID", &key);
"Classes", &key);
if (err == REGERR_OK) {
char *cidString = aCID.ToString();
NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
err = NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
delete [] cidString;
}
NR_RegClose(hreg);
}
return NS_OK;
return err;
}
static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
@@ -118,15 +117,15 @@ static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
if (err == REGERR_OK) {
RKEY key;
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
"SOFTWARE\\Netscape\\CID", &key);
"Classes", &key);
if (err == REGERR_OK) {
char *cidString = aCID.ToString();
NR_RegDeleteEntry(hreg, key, cidString);
err = NR_RegDeleteEntry(hreg, key, cidString);
delete [] cidString;
}
NR_RegClose(hreg);
}
return NS_OK;
return err;
}
static FactoryEntry *platformFind(const nsCID &aCID)
@@ -137,11 +136,11 @@ static FactoryEntry *platformFind(const nsCID &aCID)
if (err == REGERR_OK) {
RKEY key;
err = NR_RegGetKey(hreg, ROOTKEY_COMMON,
"SOFTWARE\\Netscape\\CID", &key);
"Classes", &key);
if (err == REGERR_OK) {
char *cidString = aCID.ToString();
char library[_MAX_PATH];
uint32 len = _MAX_PATH;
char library[256];
uint32 len = 256;
err = NR_RegGetEntryString(hreg, key, cidString, library, len);
delete [] cidString;
@@ -294,6 +293,9 @@ nsresult NSRepository::Initialize()
monitor = PR_NewMonitor();
}
#ifdef USE_NSREG
NR_StartupRegistry();
#endif
return NS_OK;
}

View File

@@ -25,11 +25,11 @@
static PR_CALLBACK PLHashNumber _hashValue(const void *key)
{
return ((nsHashKey *) key)->HashValue();
return ((const nsHashKey *) key)->HashValue();
}
static PR_CALLBACK PRIntn _hashKeyCompare(const void *key1, const void *key2) {
return ((nsHashKey *) key1)->Equals((nsHashKey *) key2);
return ((const nsHashKey *) key1)->Equals((const nsHashKey *) key2);
}
static PR_CALLBACK PRIntn _hashValueCompare(const void *value1,
@@ -78,6 +78,17 @@ static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg)
HT_ENUMERATE_STOP;
}
//
// HashKey
//
nsHashKey::nsHashKey(void)
{
}
nsHashKey::~nsHashKey(void)
{
}
nsHashtable::nsHashtable(PRUint32 aInitSize) {
hashtable = PL_NewHashTable(aInitSize,
_hashValue,

View File

@@ -0,0 +1,341 @@
/* -*- 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
* 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
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupportsArray.h"
static NS_DEFINE_IID(kISupportsArrayIID, NS_ISUPPORTSARRAY_IID);
static const PRInt32 kGrowArrayBy = 8;
static const PRInt32 kAutoArraySize = 4;
class SupportsArrayImpl : public nsISupportsArray {
public:
SupportsArrayImpl(void);
~SupportsArrayImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& aOther);
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& aOther) const { return Equals(&aOther); }
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther) const;
NS_IMETHOD_(PRInt32) Count(void) const { return mCount; }
NS_IMETHOD_(nsISupports*) ElementAt(PRInt32 aIndex) const;
NS_IMETHOD_(nsISupports*) operator[](PRInt32 aIndex) const { return ElementAt(aIndex); }
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex = 0) const;
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const;
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRInt32 aIndex);
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex);
NS_IMETHOD_(PRBool) AppendElement(nsISupports* aElement) {
return InsertElementAt(aElement, mCount);
}
NS_IMETHOD_(PRBool) RemoveElementAt(PRInt32 aIndex);
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex = 0);
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
NS_IMETHOD_(void) Clear(void);
NS_IMETHOD_(void) Compact(void);
NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData);
NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData);
protected:
void DeleteArray(void);
nsISupports** mArray;
PRInt32 mArraySize;
PRInt32 mCount;
nsISupports* mAutoArray[kAutoArraySize];
private:
// Copy constructors are not allowed
SupportsArrayImpl(const nsISupportsArray& other);
};
SupportsArrayImpl::SupportsArrayImpl()
{
NS_INIT_REFCNT();
mArray = &(mAutoArray[0]);
mArraySize = kAutoArraySize;
mCount = 0;
}
SupportsArrayImpl::~SupportsArrayImpl()
{
DeleteArray();
}
NS_IMPL_ISUPPORTS(SupportsArrayImpl, kISupportsArrayIID);
void SupportsArrayImpl::DeleteArray(void)
{
Clear();
if (mArray != &(mAutoArray[0])) {
delete[] mArray;
mArray = &(mAutoArray[0]);
mArraySize = kAutoArraySize;
}
}
nsISupportsArray& SupportsArrayImpl::operator=(const nsISupportsArray& aOther)
{
PRInt32 otherCount = aOther.Count();
if (otherCount > mArraySize) {
DeleteArray();
mArraySize = otherCount;
mArray = new nsISupports*[mArraySize];
}
else {
Clear();
}
mCount = otherCount;
while (0 <= --otherCount) {
mArray[otherCount] = aOther.ElementAt(otherCount);
}
return *this;
}
PRBool SupportsArrayImpl::Equals(const nsISupportsArray* aOther) const
{
if (0 != aOther) {
const SupportsArrayImpl* other = (const SupportsArrayImpl*)aOther;
if (mCount == other->mCount) {
PRInt32 index = mCount;
while (0 <= --index) {
if (mArray[index] != other->mArray[index]) {
return PR_FALSE;
}
}
return PR_TRUE;
}
}
return PR_FALSE;
}
nsISupports* SupportsArrayImpl::ElementAt(PRInt32 aIndex) const
{
if ((0 <= aIndex) && (aIndex < mCount)) {
nsISupports* element = mArray[aIndex];
NS_ADDREF(element);
return element;
}
return 0;
}
PRInt32 SupportsArrayImpl::IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex) const
{
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
const nsISupports** ep = (start + aStartIndex);
const nsISupports** end = (start + mCount);
while (ep < end) {
if (aPossibleElement == *ep) {
return (ep - start);
}
ep++;
}
}
return -1;
}
PRInt32 SupportsArrayImpl::LastIndexOf(const nsISupports* aPossibleElement) const
{
if (0 < mCount) {
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
const nsISupports** ep = (start + mCount);
while (start <= --ep) {
if (aPossibleElement == *ep) {
return (ep - start);
}
}
}
return -1;
}
PRBool SupportsArrayImpl::InsertElementAt(nsISupports* aElement, PRInt32 aIndex)
{
if ((0 <= aIndex) && (aIndex <= mCount)) {
if (mArraySize < (mCount + 1)) { // need to grow the array
mArraySize += kGrowArrayBy;
nsISupports** oldArray = mArray;
mArray = new nsISupports*[mArraySize];
if (0 == mArray) { // ran out of memory
mArray = oldArray;
mArraySize -= kGrowArrayBy;
return PR_FALSE;
}
if (0 != oldArray) { // need to move old data
if (0 < aIndex) {
::memcpy(mArray, oldArray, aIndex * sizeof(nsISupports*));
}
PRInt32 slide = (mCount - aIndex);
if (0 < slide) {
::memcpy(mArray + aIndex + 1, oldArray + aIndex, slide * sizeof(nsISupports*));
}
if (oldArray != &(mAutoArray[0])) {
delete[] oldArray;
}
}
}
else {
PRInt32 slide = (mCount - aIndex);
if (0 < slide) {
::memmove(mArray + aIndex + 1, mArray + aIndex, slide * sizeof(nsISupports*));
}
}
mArray[aIndex] = aElement;
NS_ADDREF(aElement);
mCount++;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex)
{
if ((0 <= aIndex) && (aIndex < mCount)) {
NS_ADDREF(aElement); // addref first in case it's the same object!
NS_RELEASE(mArray[aIndex]);
mArray[aIndex] = aElement;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::RemoveElementAt(PRInt32 aIndex)
{
if ((0 <= aIndex) && (aIndex < mCount)) {
NS_RELEASE(mArray[aIndex]);
mCount--;
PRInt32 slide = (mCount - aIndex);
if (0 < slide) {
::memmove(mArray + aIndex, mArray + aIndex + 1,
slide * sizeof(nsISupports*));
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex)
{
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
nsISupports** ep = mArray;
nsISupports** end = ep + mCount;
while (ep < end) {
if (*ep == aElement) {
return RemoveElementAt(PRInt32(ep - mArray));
}
ep++;
}
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::RemoveLastElement(const nsISupports* aElement)
{
if (0 < mCount) {
nsISupports** ep = (mArray + mCount);
while (mArray <= --ep) {
if (*ep == aElement) {
return RemoveElementAt(PRInt32(ep - mArray));
}
}
}
return PR_FALSE;
}
void SupportsArrayImpl::Clear(void)
{
while (0 <= --mCount) {
NS_RELEASE(mArray[mCount]);
}
mCount = 0;
}
void SupportsArrayImpl::Compact(void)
{
if ((mArraySize != mCount) && (kAutoArraySize < mArraySize)) {
nsISupports** oldArray = mArray;
PRInt32 oldArraySize = mArraySize;
if (mCount <= kAutoArraySize) {
mArray = &(mAutoArray[0]);
mArraySize = kAutoArraySize;
}
else {
mArray = new nsISupports*[mCount];
mArraySize = mCount;
}
if (0 == mArray) {
mArray = oldArray;
mArraySize = oldArraySize;
return;
}
::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
delete[] oldArray;
}
}
PRBool SupportsArrayImpl::EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData)
{
PRInt32 index = -1;
PRBool running = PR_TRUE;
while (running && (++index < mCount)) {
running = (*aFunc)(mArray[index], aData);
}
return running;
}
PRBool SupportsArrayImpl::EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData)
{
PRInt32 index = mCount;
PRBool running = PR_TRUE;
while (running && (0 <= --index)) {
running = (*aFunc)(mArray[index], aData);
}
return running;
}
NS_COM nsresult
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
{
if (aInstancePtrResult == 0) {
return NS_ERROR_NULL_POINTER;
}
SupportsArrayImpl *it = new SupportsArrayImpl();
if (0 == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kISupportsArrayIID, (void **) aInstancePtrResult);
}

View File

@@ -19,6 +19,10 @@
#include "nsDebug.h"
#include "prlog.h"
#if defined(_WIN32)
#include <windows.h>
#endif
/**
* Implementation of the nsDebug methods. Note that this code is
* always compiled in, in case some other module that uses it is
@@ -47,6 +51,20 @@ NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
#endif
}
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
{
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Break: at file %s, line %d", aFile, aLine));
PR_LogFlush();
//XXX this works on win32 only for now. For all the other platforms call Abort
#if defined(_WIN32)
::DebugBreak();
#else
Abort(aFile, aLine);
#endif
}
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
const char* aFile, PRIntn aLine)
{
@@ -54,7 +72,7 @@ NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
@@ -64,7 +82,7 @@ NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
@@ -74,7 +92,7 @@ NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
@@ -84,7 +102,7 @@ NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::NotReached(const char* aMessage,
@@ -93,7 +111,7 @@ NS_COM void nsDebug::NotReached(const char* aMessage,
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Error(const char* aMessage,
@@ -102,7 +120,7 @@ NS_COM void nsDebug::Error(const char* aMessage,
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Warning(const char* aMessage,

View File

@@ -15,34 +15,40 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <stdio.h>
#include "nsID.h"
#include "prprf.h"
static const char gIDFormat[] =
"{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
static const char gIDFormat2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
/*
* Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} string into
* an nsID
*/
PRBool nsID::Parse(char *aIDStr) {
int count, n1, n2, n3[8];
long int n0;
NS_COM PRBool nsID::Parse(char *aIDStr)
{
PRInt32 count = 0;
PRInt32 n1, n2, n3[8];
PRInt32 n0;
count = sscanf(aIDStr, gIDFormat,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
if (NULL != aIDStr) {
count = PR_sscanf(aIDStr,
(aIDStr[0] == '{') ? gIDFormat : gIDFormat2,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
m0 = (PRInt32) n0;
m1 = (PRInt16) n1;
m2 = (PRInt16) n2;
for (int i = 0; i < 8; i++) {
m3[i] = (PRInt8) n3[i];
m0 = (PRInt32) n0;
m1 = (PRInt16) n1;
m2 = (PRInt16) n2;
for (int i = 0; i < 8; i++) {
m3[i] = (PRInt8) n3[i];
}
}
return (PRBool) (count == 11);
}
@@ -51,15 +57,16 @@ PRBool nsID::Parse(char *aIDStr) {
* format. Caller should delete [] the string.
*/
char *nsID::ToString() const
NS_COM char *nsID::ToString() const
{
char *res = new char[39];
if (res != NULL) {
sprintf(res, gIDFormat,
(long int) m0, (int) m1, (int) m2,
(int) m3[0], (int) m3[1], (int) m3[2], (int) m3[3],
(int) m3[4], (int) m3[5], (int) m3[6], (int) m3[7]);
PR_snprintf(res, 39, gIDFormat,
m0, (PRUint32) m1, (PRUint32) m2,
(PRUint32) m3[0], (PRUint32) m3[1], (PRUint32) m3[2],
(PRUint32) m3[3], (PRUint32) m3[4], (PRUint32) m3[5],
(PRUint32) m3[6], (PRUint32) m3[7]);
}
return res;
}

View File

@@ -20,6 +20,6 @@ IGNORE_MANIFEST=1
#
DEPTH=..
DIRS=src
DIRS=src tests
include <$(DEPTH)\config\rules.mak>

View File

@@ -22,20 +22,26 @@ LIBRARY_NAME = xpcom
CPPSRCS = nsDebug.cpp \
nsHashtable.cpp \
nsID.cpp \
nsSupportsArray.cpp \
nsRepository.cpp \
$(NULL)
EXPORTS = nsAgg.h \
nsCom.h \
EXPORTS = nsCom.h \
nsAgg.h \
nsDebug.h \
nsError.h \
nsHashtable.h \
nsID.h \
nsIFactory.h \
nsISupports.h \
nsIPtr.h \
nsISupportsArray.h \
nsRepository.h \
nsIEnumerator.h \
$(NULL)
DEFINES = -D_IMPL_NS_COM
LCFLAGS = -D_IMPL_NS_COM -DUSE_NSREG
REQUIRES = libreg
include $(DEPTH)/config/rules.mk

View File

@@ -21,38 +21,46 @@ MAKE_OBJ_TYPE = DLL
DEPTH=..\..
LINCS = \
-I$(PUBLIC)\libreg \
$(NULL)
LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\libreg32.lib \
$(NULL)
LIBNAME = .\$(OBJDIR)\xpcom$(MOZ_BITS)
DLL = $(LIBNAME).dll
LCFLAGS = -D_IMPL_NS_COM
REQUIRES =
LCFLAGS = -D_IMPL_NS_COM -DUSE_NSREG -DWIN32_LEAN_AND_MEAN
CPPSRCS = \
nsDebug.cpp \
nsHashtable.cpp \
nsID.cpp \
nsRepository.cpp \
nsSupportsArray.cpp \
CPP_OBJS = \
.\$(OBJDIR)\nsDebug.obj \
.\$(OBJDIR)\nsHashtable.obj \
.\$(OBJDIR)\nsID.obj \
.\$(OBJDIR)\nsSupportsArray.obj \
.\$(OBJDIR)\nsRepository.obj \
EXPORTS = \
nsAgg.h \
nsCom.h \
nsDebug.h \
nsError.h \
nsHashtable.h \
nsID.h \
nsIFactory.h \
nsISupports.h \
nsIPtr.h \
nsISupportsArray.h \
nsRepository.h \
nsIEnumerator.h \
$(NULL)
@@ -61,7 +69,8 @@ MODULE = xpcom
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib
libs:: $(DLL)
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib

View File

@@ -29,8 +29,8 @@ protected: \
\
/* You must implement this operation instead of the nsISupports */ \
/* methods if you inherit from nsAggregated. */ \
NS_IMETHOD AggregatedQueryInterface(const nsIID& aIID, \
void** aInstancePtr); \
NS_IMETHOD \
AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
\
class Internal : public nsISupports { \
public: \
@@ -38,7 +38,7 @@ protected: \
Internal() {} \
\
NS_IMETHOD QueryInterface(const nsIID& aIID, \
void** aInstancePtr); \
void** aInstancePtr); \
NS_IMETHOD_(nsrefcnt) AddRef(void); \
NS_IMETHOD_(nsrefcnt) Release(void); \
\
@@ -60,7 +60,7 @@ public: \
// Put this in your class's implementation file:
#define NS_IMPL_AGGREGATED(_class) \
NS_METHOD \
NS_IMETHODIMP \
_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
{ \
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
@@ -74,7 +74,7 @@ _class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
return AggregatedQueryInterface(aIID, aInstancePtr); \
} \
\
NS_METHOD_(nsrefcnt) \
NS_IMETHODIMP_(nsrefcnt) \
_class::AddRef(void) \
{ \
if (fOuter) \
@@ -83,7 +83,7 @@ _class::AddRef(void) \
return ++mRefCnt; \
} \
\
NS_METHOD_(nsrefcnt) \
NS_IMETHODIMP_(nsrefcnt) \
_class::Release(void) \
{ \
if (fOuter) \
@@ -97,21 +97,21 @@ _class::Release(void) \
} \
} \
\
NS_METHOD \
NS_IMETHODIMP \
_class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
{ \
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
return agg->AggregatedQueryInterface(aIID, aInstancePtr); \
} \
\
NS_METHOD \
NS_IMETHODIMP_(nsrefcnt) \
_class::Internal::AddRef(void) \
{ \
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
return ++agg->mRefCnt; \
} \
\
NS_METHOD \
NS_IMETHODIMP_(nsrefcnt) \
_class::Internal::Release(void) \
{ \
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \

View File

@@ -24,41 +24,50 @@
*/
#ifdef _IMPL_NS_COM
# ifdef XP_PC
# define NS_COM _declspec(dllexport)
# else // !XP_PC
# define NS_COM
# endif // !XP_PC
#ifdef XP_PC
#define NS_COM _declspec(dllexport)
#else // !XP_PC
#define NS_COM
#endif // !XP_PC
#else // !_IMPL_NS_COM
# ifdef XP_PC
# define NS_COM _declspec(dllimport)
# else // !XP_PC
# define NS_COM
# endif // !XP_PC
#ifdef XP_PC
#define NS_COM _declspec(dllimport)
#else // !XP_PC
#define NS_COM
#endif // !XP_PC
#endif // !_IMPL_NS_COM
/*
* DLL Export macro
*/
#ifndef NS_EXPORT
# ifdef XP_PC
# define NS_EXPORT _declspec(dllexport)
# else // !XP_PC
# define NS_EXPORT
# endif // !XP_PC
#endif // !NS_EXPORT
#ifdef XP_PC
# define NS_METHOD_(Type) Type __stdcall
# define NS_METHOD nsresult __stdcall
#else // !XP_PC
# define NS_METHOD_(Type) Type
# define NS_METHOD nsresult
#endif // !XP_PC
#define NS_IMETHOD_(Type) virtual NS_METHOD_(Type)
#define NS_IMETHOD virtual NS_METHOD
#define NS_EXPORT _declspec(dllexport)
#define NS_EXPORT_(type) _declspec(dllexport) type __stdcall
#define NS_IMETHOD_(type) virtual type __stdcall
#define NS_IMETHOD virtual nsresult __stdcall
#define NS_IMETHODIMP_(type) type __stdcall
#define NS_IMETHODIMP nsresult __stdcall
#define NS_METHOD_(type) type __stdcall
#define NS_METHOD nsresult __stdcall
#else // !XP_PC
#define NS_EXPORT
#define NS_EXPORT_(type) type
#define NS_IMETHOD_(type) virtual type
#define NS_IMETHOD virtual nsresult
#define NS_IMETHODIMP_(type) type
#define NS_IMETHODIMP nsresult
#define NS_METHOD_(type) type
#define NS_METHOD nsresult
#endif // !XP_PC
#endif

View File

@@ -19,6 +19,10 @@
#include "nsDebug.h"
#include "prlog.h"
#if defined(_WIN32)
#include <windows.h>
#endif
/**
* Implementation of the nsDebug methods. Note that this code is
* always compiled in, in case some other module that uses it is
@@ -47,6 +51,20 @@ NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
#endif
}
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
{
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Break: at file %s, line %d", aFile, aLine));
PR_LogFlush();
//XXX this works on win32 only for now. For all the other platforms call Abort
#if defined(_WIN32)
::DebugBreak();
#else
Abort(aFile, aLine);
#endif
}
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
const char* aFile, PRIntn aLine)
{
@@ -54,7 +72,7 @@ NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
@@ -64,7 +82,7 @@ NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
@@ -74,7 +92,7 @@ NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
@@ -84,7 +102,7 @@ NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
PR_LOG(gDebugLog, PR_LOG_ERROR,
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::NotReached(const char* aMessage,
@@ -93,7 +111,7 @@ NS_COM void nsDebug::NotReached(const char* aMessage,
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Error(const char* aMessage,
@@ -102,7 +120,7 @@ NS_COM void nsDebug::Error(const char* aMessage,
InitLog();
PR_LOG(gDebugLog, PR_LOG_ERROR,
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
Abort(aFile, aLine);
Break(aFile, aLine);
}
NS_COM void nsDebug::Warning(const char* aMessage,

View File

@@ -41,6 +41,11 @@ public:
*/
static NS_COM void Abort(const char* aFile, PRIntn aLine);
/**
* Break the executing program into the debugger.
*/
static NS_COM void Break(const char* aFile, PRIntn aLine);
/**
* Log a pre-condition message to the debug log
*/
@@ -101,6 +106,15 @@ if (!(expr)) \
if (!(expr)) \
nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
/**
* Test an assertion for truth. If the expression is not true then
* trigger a program failure. The expression will still be
* executed in release mode.
*/
#define NS_VERIFY(expr,str) \
if (!(expr)) \
nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
/**
* Test a post-condition for truth. If the expression is not true then
* trigger a program failure.
@@ -141,16 +155,24 @@ if (!(expr)) \
#define NS_ABORT() \
nsDebug::Abort(__FILE__, __LINE__)
/**
* Cause a break
*/
#define NS_BREAK() \
nsDebug::Break(__FILE__, __LINE__)
#else /* NS_DEBUG */
#define NS_PRECONDITION(expr,str) {}
#define NS_ASSERTION(expr,str) {}
#define NS_VERIFY(expr,str) expr
#define NS_POSTCONDITION(expr,str) {}
#define NS_NOTYETIMPLEMENTED(str) {}
#define NS_NOTREACHED(str) {}
#define NS_ERROR(str) {}
#define NS_WARNING(str) {}
#define NS_ABORT() {}
#define NS_BREAK() {}
#endif /* ! NS_DEBUG */

View File

@@ -0,0 +1,88 @@
/* -*- 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
* 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
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsError_h
#define nsError_h
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
/**
* @name Standard return values
*/
//@{
/// Standard "it worked" return value
#define NS_OK 0
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
/// Returned when an instance is not initialized
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
/// Returned when an instance is already initialized
#define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 2)
/// Returned by a not implemented function
#define NS_ERROR_NOT_IMPLEMENTED ((nsresult) 0x80004001L)
/// Returned when a given interface is not supported.
#define NS_NOINTERFACE ((nsresult) 0x80004002L)
#define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
#define NS_ERROR_INVALID_POINTER ((nsresult) 0x80004003L)
#define NS_ERROR_NULL_POINTER NS_ERROR_INVALID_POINTER
/// Returned when a function aborts
#define NS_ERROR_ABORT ((nsresult) 0x80004004L)
/// Returned when a function fails
#define NS_ERROR_FAILURE ((nsresult) 0x80004005L)
/// Returned when an unexpected error occurs
#define NS_ERROR_UNEXPECTED ((nsresult) 0x8000ffffL)
/// Returned when a memory allocation failes
#define NS_ERROR_OUT_OF_MEMORY ((nsresult) 0x8007000eL)
/// Returned when an illegal value is passed
#define NS_ERROR_ILLEGAL_VALUE ((nsresult) 0x80070057L)
/// Returned when a class doesn't allow aggregation
#define NS_ERROR_NO_AGGREGATION ((nsresult) 0x80040110L)
/// Returned when a class doesn't allow aggregation
#define NS_ERROR_NOT_AVAILABLE ((nsresult) 0x80040111L)
/// Returned when a class is not registered
#define NS_ERROR_FACTORY_NOT_REGISTERED ((nsresult) 0x80040154L)
/// Returned when a dynamically loaded factory couldn't be found
#define NS_ERROR_FACTORY_NOT_LOADED ((nsresult) 0x800401f8L)
/// Returned when a factory doesn't support signatures
#define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT \
(NS_ERROR_BASE + 0x101)
/// Returned when a factory already is registered
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
//@}
#endif

View File

@@ -25,11 +25,11 @@
static PR_CALLBACK PLHashNumber _hashValue(const void *key)
{
return ((nsHashKey *) key)->HashValue();
return ((const nsHashKey *) key)->HashValue();
}
static PR_CALLBACK PRIntn _hashKeyCompare(const void *key1, const void *key2) {
return ((nsHashKey *) key1)->Equals((nsHashKey *) key2);
return ((const nsHashKey *) key1)->Equals((const nsHashKey *) key2);
}
static PR_CALLBACK PRIntn _hashValueCompare(const void *value1,
@@ -78,6 +78,17 @@ static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg)
HT_ENUMERATE_STOP;
}
//
// HashKey
//
nsHashKey::nsHashKey(void)
{
}
nsHashKey::~nsHashKey(void)
{
}
nsHashtable::nsHashtable(PRUint32 aInitSize) {
hashtable = PL_NewHashTable(aInitSize,
_hashValue,

View File

@@ -20,19 +20,23 @@
#define nsHashtable_h__
#include "plhash.h"
#include "nsCom.h"
class nsHashKey {
class NS_COM nsHashKey {
protected:
nsHashKey(void);
public:
virtual PRUint32 HashValue() = 0;
virtual PRBool Equals(nsHashKey *aKey) = 0;
virtual nsHashKey *Clone() = 0;
virtual ~nsHashKey(void);
virtual PRUint32 HashValue(void) const = 0;
virtual PRBool Equals(const nsHashKey *aKey) const = 0;
virtual nsHashKey *Clone(void) const = 0;
};
// Enumerator callback function. Use
typedef PRBool (*nsHashtableEnumFunc)(nsHashKey *aKey, void *aData);
class nsHashtable {
class NS_COM nsHashtable {
private:
// members
PLHashTable *hashtable;
@@ -41,6 +45,7 @@ public:
nsHashtable(PRUint32 aSize = 256);
~nsHashtable();
PRInt32 Count(void) { return hashtable->nentries; }
void *Put(nsHashKey *aKey, void *aData);
void *Get(nsHashKey *aKey);
void *Remove(nsHashKey *aKey);

View File

@@ -15,34 +15,40 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <stdio.h>
#include "nsID.h"
#include "prprf.h"
static const char gIDFormat[] =
"{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
static const char gIDFormat2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
/*
* Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} string into
* an nsID
*/
PRBool nsID::Parse(char *aIDStr) {
int count, n1, n2, n3[8];
long int n0;
NS_COM PRBool nsID::Parse(char *aIDStr)
{
PRInt32 count = 0;
PRInt32 n1, n2, n3[8];
PRInt32 n0;
count = sscanf(aIDStr, gIDFormat,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
if (NULL != aIDStr) {
count = PR_sscanf(aIDStr,
(aIDStr[0] == '{') ? gIDFormat : gIDFormat2,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
m0 = (PRInt32) n0;
m1 = (PRInt16) n1;
m2 = (PRInt16) n2;
for (int i = 0; i < 8; i++) {
m3[i] = (PRInt8) n3[i];
m0 = (PRInt32) n0;
m1 = (PRInt16) n1;
m2 = (PRInt16) n2;
for (int i = 0; i < 8; i++) {
m3[i] = (PRInt8) n3[i];
}
}
return (PRBool) (count == 11);
}
@@ -51,15 +57,16 @@ PRBool nsID::Parse(char *aIDStr) {
* format. Caller should delete [] the string.
*/
char *nsID::ToString() const
NS_COM char *nsID::ToString() const
{
char *res = new char[39];
if (res != NULL) {
sprintf(res, gIDFormat,
(long int) m0, (int) m1, (int) m2,
(int) m3[0], (int) m3[1], (int) m3[2], (int) m3[3],
(int) m3[4], (int) m3[5], (int) m3[6], (int) m3[7]);
PR_snprintf(res, 39, gIDFormat,
m0, (PRUint32) m1, (PRUint32) m2,
(PRUint32) m3[0], (PRUint32) m3[1], (PRUint32) m3[2],
(PRUint32) m3[3], (PRUint32) m3[4], (PRUint32) m3[5],
(PRUint32) m3[6], (PRUint32) m3[7]);
}
return res;
}

View File

@@ -21,15 +21,34 @@
#include "prtypes.h"
#include "string.h"
#include "nsCom.h"
/**
* A "unique identifier". This is modeled after OSF DCE UUIDs.
*/
struct nsID {
/**
* @name Indentifier values
*/
//@{
PRUint32 m0;
PRUint16 m1, m2;
PRUint16 m1;
PRUint16 m2;
PRUint8 m3[8];
//@}
/**
* @name Methods
*/
//@{
/**
* Equivalency method. Compares this nsID with another.
* @return <b>PR_TRUE</b> if they are the same, <b>PR_FALSE</b> if not.
*/
inline PRBool Equals(const nsID& other) const {
return (PRBool)
((((PRUint32*) &m0)[0] == ((PRUint32*) &other.m0)[0]) &&
@@ -38,14 +57,33 @@ struct nsID {
(((PRUint32*) &m0)[3] == ((PRUint32*) &other.m0)[3]));
}
// Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} string into
// an nsID
PRBool Parse(char *aIDStr);
/**
* nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
* string into an nsID
*/
NS_COM PRBool Parse(char *aIDStr);
// Returns an allocated string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
// format. Caller should free string.
char* ToString() const;
/**
* nsID string encoder. Returns an allocated string in
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
*/
NS_COM char* ToString() const;
//@}
};
/**
* Declare an ID. If NS_IMPL_IDS is set, a variable <i>_name</i> is declared
* with the given values, otherwise <i>_name</i> is declared as an
* <tt>extern</tt> variable.
*/
#ifdef NS_IMPL_IDS
#define NS_DECLARE_ID(_name,m0,m1,m2,m30,m31,m32,m33,m34,m35,m36,m37) \
extern "C" const nsID _name = {m0,m1,m2,{m30,m31,m32,m33,m34,m35,m36,m37}}
#else
#define NS_DECLARE_ID(_name,m0,m1,m2,m30,m31,m32,m33,m34,m35,m36,m37) \
extern "C" const nsID _name
#endif
#endif

View File

@@ -46,10 +46,10 @@ typedef nsID nsCID;
class nsIFactory: public nsISupports {
public:
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
REFNSIID aIID,
void **aResult) = 0;
NS_IMETHOD_(void) LockFactory(PRBool aLock) = 0;
NS_IMETHOD LockFactory(PRBool aLock) = 0;
};
/**
@@ -65,7 +65,7 @@ public:
class nsIFactory2: public nsIFactory {
public:
NS_IMETHOD CreateInstance2(nsISupports *aOuter,
const nsIID &aIID,
REFNSIID aIID,
void *aSignature,
void **aResult) = 0;
};

142
mozilla/xpcom/src/nsIPtr.h Normal file
View File

@@ -0,0 +1,142 @@
/* -*- 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
* 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
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIPtr_h___
#define nsIPtr_h___
#include "nsISupports.h"
/*
* nsIPtr is an "auto-release pointer" class for nsISupports based interfaces
*
* It's intent is to be a "set and forget" pointer to help with managing
* active references to nsISupports bases objects.
*
* The pointer object ensures that the underlying pointer is always
* released whenever the value is changed or when the object leaves scope.
*
* Proper care needs to be taken when assigning pointers to a nsIPtr.
* When asigning from a C pointer (nsISupports*), the pointer presumes
* an active reference and subsumes it. When assigning from another nsIPtr,
* a new reference is established.
*
* There are 3 ways to assign a value to a nsIPtr.
* 1) Direct construction or assignment from a C pointer.
* 2) Direct construction or assignment form another nsIPtr.
* 3) Usage of an "out parameter" method.
* a) AssignRef() releases the underlying pointer and returns a reference to it.
* Useful for pointer reference out paramaters.
* b) AssignPtr() releases the underlying pointer and returns a pointer to it.
* c) Query() releases the underlying pointer and returns a (void**) pointer to it.
* Useful for calls to QueryInterface()
* 4) The SetAddRef() method. This is equivalent to an assignment followed by an AddRef().
*
* examples:
*
* class It {
* void NS_NewFoo(nsIFoo** aFoo);
* nsIFoo* GetFoo(void);
* void GetBar(nsIBar*& aBar);
* };
*
* nsIFooPtr foo = it->GetFoo();
* nsIBarPtr bar;
*
* it->NS_NewFoo(foo.AssignPtr());
* it->GetBar(bar.AssignRef());
* it->QueryInterface(kIFooIID, foo.Query());
* bar.SetAddRef(new Bar());
*
* Advantages:
* Set and forget. Once a pointer is assigned to a nsIPtr, it is impossible
* to forget to release it.
* Always pre-initialized. You can't forget to initialize the pointer.
*
* Disadvantages:
* Usage of this class doesn't eliminate the need to think about ref counts
* and assign values properly, AddRef'ing as needed.
* The nsIPtr doesn't typecast exactly like a C pointer. In order to achieve
* typecasting, it may be necessary to first cast to a C pointer of the
* underlying type.
*
*/
#define NS_DEF_PTR(cls) \
class cls##Ptr { \
public: \
cls##Ptr(void) : mPtr(0) {} \
cls##Ptr(const cls##Ptr& aCopy) : mPtr(aCopy.mPtr) \
{ if(0 != mPtr) mPtr->AddRef(); } \
cls##Ptr(cls* aInterface) : mPtr(aInterface) {} \
~cls##Ptr(void) { if(0 != mPtr) mPtr->Release(); } \
cls##Ptr& operator=(const cls##Ptr& aCopy) \
{ if(mPtr == aCopy.mPtr) return *this; \
if(0 != aCopy.mPtr) aCopy.mPtr->AddRef(); \
if(0 != mPtr) mPtr->Release(); \
mPtr = aCopy.mPtr; return *this; } \
cls##Ptr& operator=(cls* aInterface) \
{ if(mPtr == aInterface) return *this; \
if(0 != mPtr) mPtr->Release(); mPtr = aInterface; \
return *this; } \
cls##Ptr& operator=(PRInt32 aInt) \
{ if(0 != mPtr) mPtr->Release(); mPtr = 0; \
return *this; } \
void SetAddRef(cls* aInterface) \
{ if(aInterface == mPtr) return; \
if(0 != aInterface) aInterface->AddRef(); \
if(0 != mPtr) mPtr->Release(); mPtr = aInterface; } \
cls* AddRef(void) { mPtr->AddRef(); return mPtr; } \
cls* IfAddRef(void) \
{ if(0 != mPtr) mPtr->AddRef(); return mPtr; } \
cls*& AssignRef(void) \
{ if(0 != mPtr) mPtr->Release(); mPtr = 0; return mPtr; } \
cls** AssignPtr(void) \
{ if(0 != mPtr) mPtr->Release(); mPtr = 0; return &mPtr; } \
void** Query(void) \
{ if(0 != mPtr) mPtr->Release(); mPtr = 0; return (void**)&mPtr; } \
PRBool IsNull() const \
{ return PRBool(0 == mPtr); } \
PRBool IsNotNull() const \
{ return PRBool(0 != mPtr); } \
PRBool operator==(const cls##Ptr& aCopy) const \
{ return PRBool(mPtr == aCopy.mPtr); } \
PRBool operator==(cls* aInterface) const \
{ return PRBool(mPtr == aInterface); } \
PRBool operator!=(const cls##Ptr& aCopy) const \
{ return PRBool(mPtr != aCopy.mPtr); } \
PRBool operator!=(cls* aInterface) const \
{ return PRBool(mPtr != aInterface); } \
cls* operator->(void) { return mPtr; } \
cls& operator*(void) { return *mPtr; } \
operator cls*(void) { return mPtr; } \
const cls* operator->(void) const { return mPtr; } \
const cls& operator*(void) const { return *mPtr; } \
operator const cls*(void) const { return mPtr; } \
private: \
void* operator new(size_t size) { return 0; } \
void operator delete(void* aPtr) {} \
cls* mPtr; \
public: \
friend inline PRBool operator==(const cls* aInterface, const cls##Ptr& aPtr) \
{ return PRBool(aInterface == aPtr.mPtr); } \
friend inline PRBool operator!=(const cls* aInterface, const cls##Ptr& aPtr) \
{ return PRBool(aInterface != aPtr.mPtr); } \
}
#endif // nsIPtr_h___

View File

@@ -21,74 +21,110 @@
#include "nsDebug.h"
#include "nsID.h"
#include "nsError.h"
// An "interface id" which can be used to uniquely identify a given
// interface. Primarily used as an argument to nsISupports.QueryInterface
// method.
/*@{*/
/**
* An "interface id" which can be used to uniquely identify a given
* interface.
*/
typedef nsID nsIID;
// Define an IID
/**
* A macro shorthand for <tt>const nsIID&<tt>
*/
#define REFNSIID const nsIID&
/**
* Define an IID (obsolete)
*/
#define NS_DEFINE_IID(_name, _iidspec) \
const nsIID _name = _iidspec
//----------------------------------------------------------------------
// IID for the nsISupports interface
// {00000000-0000-0000-c000-000000000046}
/**
* IID for the nsISupports interface
* {00000000-0000-0000-c000-000000000046}
*/
#define NS_ISUPPORTS_IID \
{ 0x00000000, 0x0000, 0x0000, \
{0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
/**
* Generic result data type
*/
// Standard "it worked" return value
#define NS_OK 0
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
// Some standard error codes we use
#define NS_ERROR_OUT_OF_MEMORY (NS_ERROR_BASE + 0)
#define NS_ERROR_NO_AGGREGATION (NS_ERROR_BASE + 1)
#define NS_ERROR_NULL_POINTER (NS_ERROR_BASE + 2)
#define NS_ERROR_ILLEGAL_VALUE (NS_ERROR_BASE + 3)
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 4)
#define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 5)
#define NS_ERROR_NOT_IMPLEMENTED (NS_ERROR_BASE + 6)
#define NS_ERROR_FAILURE (NS_ERROR_BASE + 7)
// Generic result data type
typedef PRUint32 nsresult;
// This is returned by QueryInterface when a given interface is not
// supported.
#define NS_NOINTERFACE ((nsresult) 0x80004002L)
// Reference count values
/**
* Reference count values
*/
typedef PRUint32 nsrefcnt;
// Basic component object model interface. Objects which implement
// this interface support runtime interface discovery (QueryInterface)
// and a reference counted memory model (AddRef/Release). This is
// modelled after the win32 IUnknown API.
/**
* Basic component object model interface. Objects which implement
* this interface support runtime interface discovery (QueryInterface)
* and a reference counted memory model (AddRef/Release). This is
* modelled after the win32 IUnknown API.
*/
class nsISupports {
public:
NS_IMETHOD QueryInterface(const nsIID& aIID,
/**
* @name Methods
*/
//@{
/**
* A run time mechanism for interface discovery.
* @param aIID [in] A requested interface IID
* @param aInstancePtr [out] A pointer to an interface pointer to
* receive the result.
* @return <b>NS_OK</b> if the interface is supported by the associated
* instance, <b>NS_NOINTERFACE</b> if it is not.
* <b>NS_ERROR_INVALID_POINTER</b> if <i>aInstancePtr</i> is <b>NULL</b>.
*/
NS_IMETHOD QueryInterface(REFNSIID aIID,
void** aInstancePtr) = 0;
/**
* Increases the reference count for this interface.
* The associated instance will not be deleted unless
* the reference count is returned to zero.
*
* @return The resulting reference count.
*/
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
/**
* Decreases the reference count for this interface.
* Generally, if the reference count returns to zero,
* the associated instance is deleted.
*
* @return The resulting reference count.
*/
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
//@}
};
//----------------------------------------------------------------------
// Some convenience macros for implementing AddRef and Release
/**
* Some convenience macros for implementing AddRef and Release
*/
// Declare the reference count variable and the implementations of the
// AddRef and QueryInterface methods.
/**
* Declare the reference count variable and the implementations of the
* AddRef and QueryInterface methods.
*/
#define NS_DECL_ISUPPORTS \
public: \
NS_IMETHOD QueryInterface(const nsIID& aIID, \
NS_IMETHOD QueryInterface(REFNSIID aIID, \
void** aInstancePtr); \
NS_IMETHOD_(nsrefcnt) AddRef(void); \
NS_IMETHOD_(nsrefcnt) Release(void); \
@@ -96,35 +132,60 @@ protected: \
nsrefcnt mRefCnt; \
public:
// Initialize the reference count variable. Add this to each and every
// constructor you implement.
/**
* Initialize the reference count variable. Add this to each and every
* constructor you implement.
*/
#define NS_INIT_REFCNT() mRefCnt = 0
// Use this macro to implement the AddRef method for a given _class
/**
* Use this macro to implement the AddRef method for a given <i>_class</i>
* @param _class The name of the class implementing the method
*/
#define NS_IMPL_ADDREF(_class) \
nsrefcnt _class::AddRef(void) \
{ \
return ++mRefCnt; \
}
/**
* Macro for adding a reference to an interface.
* @param _ptr The interface pointer.
*/
#define NS_ADDREF(_ptr) \
(_ptr)->AddRef()
/**
* Macro for adding a reference to an interface that checks for NULL.
* @param _ptr The interface pointer.
*/
#define NS_IF_ADDREF(_ptr) \
((0 != (_ptr)) ? (_ptr)->AddRef() : 0);
/**
* Macro for releasing a reference to an interface.
* @param _ptr The interface pointer.
*/
#define NS_RELEASE(_ptr) \
(_ptr)->Release(); \
(_ptr) = NULL
/**
* Macro for releasing a reference to an interface that checks for NULL;
* @param _ptr The interface pointer.
*/
#define NS_IF_RELEASE(_ptr) \
((0 != (_ptr)) ? (_ptr)->Release() : 0); \
(_ptr) = NULL
// Use this macro to implement the Release method for a given _class
/**
* Use this macro to implement the Release method for a given <i>_class</i>
* @param _class The name of the class implementing the method
*/
#define NS_IMPL_RELEASE(_class) \
nsrefcnt _class::Release(void) \
{ \
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
if (--mRefCnt == 0) { \
delete this; \
return 0; \
@@ -134,18 +195,23 @@ nsrefcnt _class::Release(void) \
//----------------------------------------------------------------------
// Some convenience macros for implementing QueryInterface
/*
* Some convenience macros for implementing QueryInterface
*/
/**
* This implements query interface with two assumptions: First, the
* class in question implements nsISupports and it's own interface and
* nothing else. Second, the implementation of the class's primary
* inheritance chain leads to it's own interface.
*
* @param _class The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*/
// This implements query interface with two assumptions: First, the
// class in question implements nsISupports and it's own interface and
// nothing else. Second, the implementation of the class's primary
// inheritance chain leads to it's own interface.
//
// _class is the name of the class implementing the method
// _classiiddef is the name of the #define symbol that defines the IID
// for the class (e.g. NS_ISUPPORTS_IID)
#define NS_IMPL_QUERY_INTERFACE(_class,_classiiddef) \
nsresult _class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
nsresult _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
{ \
if (NULL == aInstancePtr) { \
return NS_ERROR_NULL_POINTER; \
@@ -165,9 +231,19 @@ nsresult _class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
return NS_NOINTERFACE; \
}
/**
* Convenience macro for implementing all nsISupports methods for
* a simple class.
* @param _class The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*/
#define NS_IMPL_ISUPPORTS(_class,_classiiddef) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE(_class,_classiiddef)
/*@}*/
#endif /* nsISupports_h___ */

View File

@@ -0,0 +1,72 @@
/* -*- 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
* 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
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsISupportsArray_h___
#define nsISupportsArray_h___
#include "nsCom.h"
#include "nsISupports.h"
// {791eafa0-b9e6-11d1-8031-006008159b5a}
#define NS_ISUPPORTSARRAY_IID \
{0x791eafa0, 0xb9e6, 0x11d1, \
{0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
// Enumerator callback function. Return PR_FALSE to stop
typedef PRBool (*nsISupportsArrayEnumFunc)(nsISupports* aElement, void *aData);
class nsISupportsArray : public nsISupports {
public:
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& other) = 0;
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& other) const = 0;
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* other) const = 0;
NS_IMETHOD_(PRInt32) Count(void) const = 0;
NS_IMETHOD_(nsISupports*) ElementAt(PRInt32 aIndex) const = 0;
NS_IMETHOD_(nsISupports*) operator[](PRInt32 aIndex) const = 0;
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex = 0) const = 0;
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const = 0;
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRInt32 aIndex) = 0;
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex) = 0;
NS_IMETHOD_(PRBool) AppendElement(nsISupports* aElement) = 0;
NS_IMETHOD_(PRBool) RemoveElementAt(PRInt32 aIndex) = 0;
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex = 0) = 0;
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement) = 0;
NS_IMETHOD_(void) Clear(void) = 0;
NS_IMETHOD_(void) Compact(void) = 0;
NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData) = 0;
NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData) = 0;
private:
// Copy constructors are not allowed
// XXX test wether this has to be here nsISupportsArray(const nsISupportsArray& other);
};
extern NS_COM nsresult
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult);
#endif // nsISupportsArray_h___

View File

@@ -25,7 +25,6 @@
#include "prlink.h"
#include "nsRepository.h"
#ifdef USE_NSREG
#define STANDALONE_REGISTRY
#define XP_BEGIN_PROTOS extern "C" {
#define XP_END_PROTOS };
#include "NSReg.h"
@@ -34,7 +33,6 @@
nsHashtable *NSRepository::factories = NULL;
PRMonitor *NSRepository::monitor = NULL;
static NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kFactory2IID, NS_IFACTORY2_IID);
class FactoryEntry {
@@ -77,15 +75,15 @@ public:
id = aID;
}
PRUint32 HashValue() {
PRUint32 HashValue(void) const {
return id.m0;
}
PRBool Equals(nsHashKey *aKey) {
return (id.Equals(((IDKey *) aKey)->id));
PRBool Equals(const nsHashKey *aKey) const {
return (id.Equals(((const IDKey *) aKey)->id));
}
nsHashKey *Clone() {
nsHashKey *Clone(void) const {
return new IDKey(id);
}
};
@@ -100,15 +98,16 @@ static nsresult platformRegister(const nsCID &aCID, const char *aLibrary)
if (err == REGERR_OK) {
RKEY key;
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
"SOFTWARE\\Netscape\\CID", &key);
"Classes", &key);
if (err == REGERR_OK) {
char *cidString = aCID.ToString();
NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
err = NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
delete [] cidString;
}
NR_RegClose(hreg);
}
return NS_OK;
return err;
}
static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
@@ -118,15 +117,15 @@ static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
if (err == REGERR_OK) {
RKEY key;
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
"SOFTWARE\\Netscape\\CID", &key);
"Classes", &key);
if (err == REGERR_OK) {
char *cidString = aCID.ToString();
NR_RegDeleteEntry(hreg, key, cidString);
err = NR_RegDeleteEntry(hreg, key, cidString);
delete [] cidString;
}
NR_RegClose(hreg);
}
return NS_OK;
return err;
}
static FactoryEntry *platformFind(const nsCID &aCID)
@@ -137,11 +136,11 @@ static FactoryEntry *platformFind(const nsCID &aCID)
if (err == REGERR_OK) {
RKEY key;
err = NR_RegGetKey(hreg, ROOTKEY_COMMON,
"SOFTWARE\\Netscape\\CID", &key);
"Classes", &key);
if (err == REGERR_OK) {
char *cidString = aCID.ToString();
char library[_MAX_PATH];
uint32 len = _MAX_PATH;
char library[256];
uint32 len = 256;
err = NR_RegGetEntryString(hreg, key, cidString, library, len);
delete [] cidString;
@@ -294,6 +293,9 @@ nsresult NSRepository::Initialize()
monitor = PR_NewMonitor();
}
#ifdef USE_NSREG
NR_StartupRegistry();
#endif
return NS_OK;
}

View File

@@ -23,28 +23,34 @@
#include "prmon.h"
#include "nsCom.h"
#include "nsID.h"
#include "nsError.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsHashtable.h"
/*
* NSIRepository class
* Prototypes for dynamic library export functions
*/
// Errors
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
#define NS_ERROR_FACTORY_NOT_REGISTERED (NS_ERROR_BASE + 0x101)
#define NS_ERROR_FACTORY_NOT_LOADED (NS_ERROR_BASE + 0x102)
#define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT (NS_ERROR_BASE + 0x103)
#define NS_ERROR_FACTORY_NOT_UNREGISTERED (NS_ERROR_BASE + 0x104)
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass,
nsIFactory **aFactory);
extern "C" NS_EXPORT PRBool NSCanUnload(void);
extern "C" NS_EXPORT nsresult NSRegisterSelf(const char *path);
extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char *path);
/*
* Dynamic library export function types
*/
typedef nsresult (*nsFactoryProc)(const nsCID &aCLass,
nsIFactory **aFactory);
typedef PRBool (*nsCanUnloadProc)();
typedef PRBool (*nsCanUnloadProc)(void);
typedef nsresult (*nsRegisterProc)(const char *path);
typedef nsresult (*nsUnregisterProc)(const char *path);
class FactoryEntry;
/*
* NSRepository class
*/
class NS_COM NSRepository {
private:

View File

@@ -0,0 +1,341 @@
/* -*- 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
* 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
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupportsArray.h"
static NS_DEFINE_IID(kISupportsArrayIID, NS_ISUPPORTSARRAY_IID);
static const PRInt32 kGrowArrayBy = 8;
static const PRInt32 kAutoArraySize = 4;
class SupportsArrayImpl : public nsISupportsArray {
public:
SupportsArrayImpl(void);
~SupportsArrayImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& aOther);
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& aOther) const { return Equals(&aOther); }
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther) const;
NS_IMETHOD_(PRInt32) Count(void) const { return mCount; }
NS_IMETHOD_(nsISupports*) ElementAt(PRInt32 aIndex) const;
NS_IMETHOD_(nsISupports*) operator[](PRInt32 aIndex) const { return ElementAt(aIndex); }
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex = 0) const;
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const;
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRInt32 aIndex);
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex);
NS_IMETHOD_(PRBool) AppendElement(nsISupports* aElement) {
return InsertElementAt(aElement, mCount);
}
NS_IMETHOD_(PRBool) RemoveElementAt(PRInt32 aIndex);
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex = 0);
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
NS_IMETHOD_(void) Clear(void);
NS_IMETHOD_(void) Compact(void);
NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData);
NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData);
protected:
void DeleteArray(void);
nsISupports** mArray;
PRInt32 mArraySize;
PRInt32 mCount;
nsISupports* mAutoArray[kAutoArraySize];
private:
// Copy constructors are not allowed
SupportsArrayImpl(const nsISupportsArray& other);
};
SupportsArrayImpl::SupportsArrayImpl()
{
NS_INIT_REFCNT();
mArray = &(mAutoArray[0]);
mArraySize = kAutoArraySize;
mCount = 0;
}
SupportsArrayImpl::~SupportsArrayImpl()
{
DeleteArray();
}
NS_IMPL_ISUPPORTS(SupportsArrayImpl, kISupportsArrayIID);
void SupportsArrayImpl::DeleteArray(void)
{
Clear();
if (mArray != &(mAutoArray[0])) {
delete[] mArray;
mArray = &(mAutoArray[0]);
mArraySize = kAutoArraySize;
}
}
nsISupportsArray& SupportsArrayImpl::operator=(const nsISupportsArray& aOther)
{
PRInt32 otherCount = aOther.Count();
if (otherCount > mArraySize) {
DeleteArray();
mArraySize = otherCount;
mArray = new nsISupports*[mArraySize];
}
else {
Clear();
}
mCount = otherCount;
while (0 <= --otherCount) {
mArray[otherCount] = aOther.ElementAt(otherCount);
}
return *this;
}
PRBool SupportsArrayImpl::Equals(const nsISupportsArray* aOther) const
{
if (0 != aOther) {
const SupportsArrayImpl* other = (const SupportsArrayImpl*)aOther;
if (mCount == other->mCount) {
PRInt32 index = mCount;
while (0 <= --index) {
if (mArray[index] != other->mArray[index]) {
return PR_FALSE;
}
}
return PR_TRUE;
}
}
return PR_FALSE;
}
nsISupports* SupportsArrayImpl::ElementAt(PRInt32 aIndex) const
{
if ((0 <= aIndex) && (aIndex < mCount)) {
nsISupports* element = mArray[aIndex];
NS_ADDREF(element);
return element;
}
return 0;
}
PRInt32 SupportsArrayImpl::IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex) const
{
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
const nsISupports** ep = (start + aStartIndex);
const nsISupports** end = (start + mCount);
while (ep < end) {
if (aPossibleElement == *ep) {
return (ep - start);
}
ep++;
}
}
return -1;
}
PRInt32 SupportsArrayImpl::LastIndexOf(const nsISupports* aPossibleElement) const
{
if (0 < mCount) {
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
const nsISupports** ep = (start + mCount);
while (start <= --ep) {
if (aPossibleElement == *ep) {
return (ep - start);
}
}
}
return -1;
}
PRBool SupportsArrayImpl::InsertElementAt(nsISupports* aElement, PRInt32 aIndex)
{
if ((0 <= aIndex) && (aIndex <= mCount)) {
if (mArraySize < (mCount + 1)) { // need to grow the array
mArraySize += kGrowArrayBy;
nsISupports** oldArray = mArray;
mArray = new nsISupports*[mArraySize];
if (0 == mArray) { // ran out of memory
mArray = oldArray;
mArraySize -= kGrowArrayBy;
return PR_FALSE;
}
if (0 != oldArray) { // need to move old data
if (0 < aIndex) {
::memcpy(mArray, oldArray, aIndex * sizeof(nsISupports*));
}
PRInt32 slide = (mCount - aIndex);
if (0 < slide) {
::memcpy(mArray + aIndex + 1, oldArray + aIndex, slide * sizeof(nsISupports*));
}
if (oldArray != &(mAutoArray[0])) {
delete[] oldArray;
}
}
}
else {
PRInt32 slide = (mCount - aIndex);
if (0 < slide) {
::memmove(mArray + aIndex + 1, mArray + aIndex, slide * sizeof(nsISupports*));
}
}
mArray[aIndex] = aElement;
NS_ADDREF(aElement);
mCount++;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex)
{
if ((0 <= aIndex) && (aIndex < mCount)) {
NS_ADDREF(aElement); // addref first in case it's the same object!
NS_RELEASE(mArray[aIndex]);
mArray[aIndex] = aElement;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::RemoveElementAt(PRInt32 aIndex)
{
if ((0 <= aIndex) && (aIndex < mCount)) {
NS_RELEASE(mArray[aIndex]);
mCount--;
PRInt32 slide = (mCount - aIndex);
if (0 < slide) {
::memmove(mArray + aIndex, mArray + aIndex + 1,
slide * sizeof(nsISupports*));
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex)
{
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
nsISupports** ep = mArray;
nsISupports** end = ep + mCount;
while (ep < end) {
if (*ep == aElement) {
return RemoveElementAt(PRInt32(ep - mArray));
}
ep++;
}
}
return PR_FALSE;
}
PRBool SupportsArrayImpl::RemoveLastElement(const nsISupports* aElement)
{
if (0 < mCount) {
nsISupports** ep = (mArray + mCount);
while (mArray <= --ep) {
if (*ep == aElement) {
return RemoveElementAt(PRInt32(ep - mArray));
}
}
}
return PR_FALSE;
}
void SupportsArrayImpl::Clear(void)
{
while (0 <= --mCount) {
NS_RELEASE(mArray[mCount]);
}
mCount = 0;
}
void SupportsArrayImpl::Compact(void)
{
if ((mArraySize != mCount) && (kAutoArraySize < mArraySize)) {
nsISupports** oldArray = mArray;
PRInt32 oldArraySize = mArraySize;
if (mCount <= kAutoArraySize) {
mArray = &(mAutoArray[0]);
mArraySize = kAutoArraySize;
}
else {
mArray = new nsISupports*[mCount];
mArraySize = mCount;
}
if (0 == mArray) {
mArray = oldArray;
mArraySize = oldArraySize;
return;
}
::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
delete[] oldArray;
}
}
PRBool SupportsArrayImpl::EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData)
{
PRInt32 index = -1;
PRBool running = PR_TRUE;
while (running && (++index < mCount)) {
running = (*aFunc)(mArray[index], aData);
}
return running;
}
PRBool SupportsArrayImpl::EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData)
{
PRInt32 index = mCount;
PRBool running = PR_TRUE;
while (running && (0 <= --index)) {
running = (*aFunc)(mArray[index], aData);
}
return running;
}
NS_COM nsresult
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
{
if (aInstancePtrResult == 0) {
return NS_ERROR_NULL_POINTER;
}
SupportsArrayImpl *it = new SupportsArrayImpl();
if (0 == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kISupportsArrayIID, (void **) aInstancePtrResult);
}

View File

@@ -20,17 +20,19 @@ DEPTH=../..
include $(DEPTH)/config/config.mk
CPPSRCS = \
RegFactory.cpp \
TestFactory.cpp \
$(NULL)
INCLUDES=-I../src
INCLUDES=-I../src -I$(DIST)/include
DIRS = dynamic
OBJS = $(CPPSRCS:.cpp=.o)
EX_LIBS = \
$(DIST)/lib/libxpcom.a \
$(DIST)/bin/libreg.so \
$(DIST)/bin/libxpcom.so \
$(DIST)/lib/libplc21.a \
$(DIST)/lib/libplds21.a \
$(DIST)/lib/libnspr21.a \
@@ -45,7 +47,7 @@ include $(DEPTH)/config/rules.mk
$(OBJDIR)/%.o: %.cpp
@$(MAKE_OBJDIR)
$(CCC) -o $@ $(CFLAGS) -c $*.cpp
$(CCC) -o $@ $(CFLAGS) -DUSE_NSREG -c $*.cpp
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
@$(MAKE_OBJDIR)
@@ -53,6 +55,6 @@ $(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
export::
instal:: $(TARGETS)
$(INSTALL) NON_DIRS $(DIST)/bin
install:: $(PROGS)
$(INSTALL) $(PROGS) $(DIST)/bin

View File

@@ -23,13 +23,32 @@
static PRBool gUnreg = PR_FALSE;
void print_err(nsresult err)
{
switch (err) {
case NS_ERROR_FACTORY_NOT_LOADED:
cerr << "Factory not loaded";
break;
case NS_NOINTERFACE:
cerr << "No Interface";
break;
case NS_ERROR_NULL_POINTER:
cerr << "Null pointer";
break;
case NS_ERROR_OUT_OF_MEMORY:
cerr << "Out of memory";
break;
default:
cerr << hex << err << dec;
}
}
PRLibrary *GetLib(const char *path) {
return PR_LoadLibrary(path);
}
int Register(const char *path)
nsresult Register(const char *path)
{
int res = NS_OK;
nsresult res = NS_OK;
PRLibrary *instance = GetLib(path);
if (instance != NULL) {
nsRegisterProc proc = (nsRegisterProc) PR_FindSymbol(instance,
@@ -45,9 +64,9 @@ int Register(const char *path)
return res;
}
int Unregister(const char *path)
nsresult Unregister(const char *path)
{
int res = NS_OK;
nsresult res = NS_OK;
PRLibrary *instance = GetLib(path);
if (instance != NULL) {
nsUnregisterProc proc = (nsUnregisterProc) PR_FindSymbol(instance,
@@ -87,14 +106,18 @@ int ProcessArgs(int argc, char *argv[])
if (NS_SUCCEEDED(res)) {
cout << "Successfully unregistered: " << argv[i] << "\n";
} else {
cerr << "Unregister failed (" << res << "): " << argv[i] << "\n";
cerr << "Unregister failed (";
print_err(res);
cerr << "): " << argv[i] << "\n";
}
} else {
res = Register(argv[i]);
if (NS_SUCCEEDED(res)) {
cout << "Successfully registered: " << argv[i] << "\n";
} else {
cerr << "Register failed (" << res << "): " << argv[i] << "\n";
cerr << "Register failed (";
print_err(res);
cerr << "): " << argv[i] << "\n";
}
}
i++;

View File

View File

@@ -97,7 +97,7 @@ public:
const nsIID &aIID,
void **aResult);
NS_IMETHOD_(void) LockFactory(PRBool aLock) {};
NS_IMETHOD LockFactory(PRBool aLock) { return NS_OK; }
};
NS_IMPL_ISUPPORTS(TestFactory, kFactoryIID);
@@ -134,7 +134,7 @@ extern "C" void RegisterTestFactories() {
PR_FALSE);
// Windows can use persistant registry
#ifndef XP_PC
#ifndef USE_NSREG
NSRepository::RegisterFactory(kTestLoadedFactoryCID,
"libtestdynamic.so",
PR_FALSE,

View File

View File

@@ -27,9 +27,6 @@ NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_CID(kTestLoadedFactoryCID, NS_TESTLOADEDFACTORY_CID);
NS_DEFINE_IID(kTestClassIID, NS_ITESTCLASS_IID);
static PRInt32 g_InstanceCount = 0;
static PRInt32 g_LockCount = 0;
/**
* ITestClass implementation
*/
@@ -39,13 +36,7 @@ class TestDynamicClassImpl: public ITestClass {
TestDynamicClassImpl() {
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
~TestDynamicClassImpl() {
PR_AtomicDecrement(&g_InstanceCount);
}
void Test();
};
@@ -59,28 +50,32 @@ void TestDynamicClassImpl::Test() {
* TestFactory implementation
*/
static PRInt32 g_FactoryCount = 0;
static PRInt32 g_LockCount = 0;
class TestDynamicFactory: public nsIFactory {
NS_DECL_ISUPPORTS
TestDynamicFactory() {
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
PR_AtomicIncrement(&g_FactoryCount);
}
~TestDynamicFactory() {
PR_AtomicDecrement(&g_InstanceCount);
PR_AtomicDecrement(&g_FactoryCount);
}
NS_IMETHOD CreateInstance(nsISupports *aDelegate,
const nsIID &aIID,
void **aResult);
NS_IMETHOD_(void) LockFactory(PRBool aLock) {
NS_IMETHOD LockFactory(PRBool aLock) {
if (aLock) {
PR_AtomicIncrement(&g_LockCount);
} else {
PR_AtomicDecrement(&g_LockCount);
}
return NS_OK;
};
};
@@ -128,7 +123,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID,
}
extern "C" NS_EXPORT PRBool NSCanUnload() {
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
return PRBool(g_FactoryCount == 0 && g_LockCount == 0);
}
extern "C" NS_EXPORT nsresult NSRegisterSelf(const char *path)

View File

@@ -24,7 +24,13 @@ DIRS = dynamic windows
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\TestFactory.exe
PROG2 = .\$(OBJDIR)\RegFactory.exe
PROGRAMS = $(PROG1) $(PROG2)
PROG3 = .\$(OBJDIR)\TestArray.exe
PROG4 = .\$(OBJDIR)\TestID.exe
PROGRAMS = $(PROG1) $(PROG2) $(PROG3) $(PROG4)
LCFLAGS=-DUSE_NSREG
REQUIRES=libreg
LINCS=-I..\src
@@ -59,4 +65,6 @@ clobber::
$(PROG1): $(OBJDIR) TestFactory.cpp
$(PROG2): $(OBJDIR) RegFactory.cpp
$(PROG3): $(OBJDIR) TestArray.cpp
$(PROG3): $(OBJDIR) TestID.cpp

View File

@@ -87,10 +87,11 @@ public:
const nsIID &aIID,
void **aResult);
NS_IMETHOD_(void) LockFactory(PRBool aLock) {
NS_IMETHOD LockFactory(PRBool aLock) {
cout << "nsTestComFactory: ";
cout << (aLock == PR_TRUE ? "Locking server" : "Unlocking server");
cout << "\n";
return S_OK;
}
};