397825 - libpkix: ifdef code that uses user object types. r=nelson

This commit is contained in:
alexei.volkov.bugs%sun.com 2007-12-10 23:53:12 +00:00
Родитель 6b9f46f1bc
Коммит 021e74b720
14 изменённых файлов: 310 добавлений и 186 удалений

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

@ -44,8 +44,6 @@
#include "testutil.h"
#include "testutil_nss.h"
#define PKIX_TESTUSERCHECKER_TYPE (PKIX_NUMTYPES+30)
static void *plContext = NULL;
static PKIX_UInt32 numUserCheckerCalled = 0;
@ -92,7 +90,6 @@ int test_buildchain_uchecker(int argc, char *argv[])
PKIX_PL_String *dirNameString = NULL;
PKIX_PL_Cert *trustedCert = NULL;
PKIX_PL_Cert *targetCert = NULL;
PKIX_UInt32 actualMinorVersion = 0;
PKIX_UInt32 numCerts = 0;
PKIX_UInt32 i = 0;
PKIX_UInt32 j = 0;
@ -226,18 +223,6 @@ int test_buildchain_uchecker(int argc, char *argv[])
(PKIX_ProcessingParams_SetTargetCertConstraints
(procParams, certSelector, plContext));
/* create user checker */
PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_RegisterType
(PKIX_TESTUSERCHECKER_TYPE,
"Extended Key Usage User Object",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
plContext));
PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertChainChecker_Create
(testUserChecker,
supportForward,

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

@ -201,8 +201,8 @@ testEkuChecker(
(procParams, PKIX_FALSE, plContext));
if (only4EE == PKIX_FALSE) {
subTest("PKIX_PL_EkuChecker_Initialize");
PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_EkuChecker_Initialize
subTest("PKIX_PL_EkuChecker_Create");
PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_EkuChecker_Create
(procParams, plContext));
}

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

@ -151,6 +151,7 @@ createObjects(
{
PKIX_TEST_STD_VARS();
#ifdef PKIX_USER_OBJECT_TYPE
PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_RegisterType
(1000, /* type */
"thousand", /* description */
@ -195,6 +196,7 @@ createObjects(
PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_IncRef(*obj3, plContext));
cleanup:
#endif /* PKIX_USER_OBJECT_TYPE */
PKIX_TEST_RETURN();
}
@ -282,6 +284,7 @@ cleanup:
int test_object(int argc, char *argv[]) {
#ifdef PKIX_USER_OBJECT_TYPE
PKIX_PL_Object *obj, *obj2, *obj3, *obj4;
PKIX_UInt32 actualMinorVersion;
PKIX_UInt32 j = 0;
@ -313,7 +316,7 @@ cleanup:
PKIX_Shutdown(plContext);
endTests("Objects");
#endif /* PKIX_USER_OBJECT_TYPE */
return (0);
}

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

@ -530,7 +530,7 @@ cert_CreatePkixProcessingParams(
#ifdef PKIX_NOTDEF
/* Code should be enabled after patch for 390532 is integrated. */
PKIX_CHECK(
PKIX_PL_EkuChecker_Initialize(procParams, plContext),
PKIX_PL_EkuChecker_Create(procParams, plContext),
PKIX_EKUCHECKERINITIALIZEFAILED);
#endif /* PKIX_NOTDEF */

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

@ -577,6 +577,7 @@ PKIX_PL_Object_IsTypeRegistered(
PKIX_Boolean *pBool,
void *plContext);
#ifdef PKIX_USER_OBJECT_TYPE
/*
* FUNCTION: PKIX_PL_Object_RegisterType
* DESCRIPTION:
@ -634,6 +635,7 @@ PKIX_PL_Object_RegisterType(
PKIX_PL_DuplicateCallback duplicateFunction,
void *plContext);
#endif
/*
* FUNCTION: PKIX_PL_Object_InvalidateCache
* DESCRIPTION:

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

@ -284,10 +284,11 @@ PKIX_PL_LdapCertStore_Create(
void *plContext);
/*
* FUNCTION: PKIX_PL_EkuChecker_Initialize
* FUNCTION: PKIX_PL_EkuChecker_Create
*
* DESCRIPTION:
* Create a CertChainChecker with EkuCheckerState.
* Create a CertChainChecker with EkuCheckerState and add it into
* PKIX_ProcessingParams object.
*
* PARAMETERS
* "params"
@ -307,7 +308,7 @@ PKIX_PL_LdapCertStore_Create(
* Returns a Fatal Error
*/
PKIX_Error *
PKIX_PL_EkuChecker_Initialize(
PKIX_PL_EkuChecker_Create(
PKIX_ProcessingParams *params,
void *plContext);

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

@ -253,7 +253,8 @@ typedef int PKIX_Boolean;
TYPEMACRO(OCSPREQUEST), \
TYPEMACRO(OCSPRESPONSE), \
TYPEMACRO(HTTPDEFAULTCLIENT), \
TYPEMACRO(VERIFYNODE)
TYPEMACRO(VERIFYNODE), \
TYPEMACRO(EKUCHECKER)
#define TYPEMACRO(type) PKIX_ ## type ## _TYPE
@ -262,12 +263,17 @@ typedef enum { /* Now invoke all those TYPEMACROs to assign the numbers */
PKIX_NUMTYPES /* This gets PKIX_NUMTYPES defined as the total number */
} PKIX_TYPENUM;
#ifdef PKIX_USER_OBJECT_TYPE
/* User Define Object Types
*
* User may define their own object types offset from PKIX_USER_OBJECT_TYPE
*/
#define PKIX_USER_OBJECT_TYPEBASE 1000
#endif /* PKIX_USER_OBJECT_TYPE */
/* Error Codes
*
* This list is used to define a set of PKIX_Error exception class numbers.
@ -346,6 +352,7 @@ typedef enum { /* Now invoke all those TYPEMACROs to assign the numbers */
ERRMACRO(OCSPRESPONSE), \
ERRMACRO(HTTPDEFAULTCLIENT), \
ERRMACRO(VERIFYNODE), \
ERRMACRO(EKUCHECKER), \
ERRMACRO(CERTVFYPKIX)
#define ERRMACRO(type) PKIX_ ## type ## _ERROR

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

@ -1320,6 +1320,16 @@ extern const PKIX_StdVars zeroStdVars;
#define PKIX_VERIFYNODE_DEBUG_ARG(expr, arg)
#endif
#if PKIX_EKUCHECKER
#define PKIX_EKUCHECKER_DEBUG(expr) \
PKIX_DEBUG(expr)
#define PKIX_EKUCHECKER_DEBUG_ARG(expr, arg) \
PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_EKUCHECKER_DEBUG(expr)
#define PKIX_EKUCHECKER_DEBUG_ARG(expr, arg)
#endif
#if PKIX_CERTVFYPKIXDEBUG
#define PKIX_CERTVFYPKIX_DEBUG(expr) \
PKIX_DEBUG(expr)

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

@ -65,29 +65,29 @@ PKIX_Int32 ekuCertUsages[] = {
};
/*
* FUNCTION: pkix_pl_EkuCheckerState_Destroy
* FUNCTION: pkix_pl_EkuChecker_Destroy
* (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
*/
static PKIX_Error *
pkix_pl_EkuCheckerState_Destroy(
pkix_pl_EkuChecker_Destroy(
PKIX_PL_Object *object,
void *plContext)
{
pkix_pl_EkuCheckerState *ekuCheckerState = NULL;
pkix_pl_EkuChecker *ekuCheckerState = NULL;
PKIX_ENTER(USERDEFINEDMODULES, "pkix_pl_EkuCheckerState_Destroy");
PKIX_ENTER(EKUCHECKER, "pkix_pl_EkuChecker_Destroy");
PKIX_NULLCHECK_ONE(object);
PKIX_CHECK(pkix_CheckType(object, PKIX_EKUCHECKERSTATE_TYPE, plContext),
PKIX_CHECK(pkix_CheckType(object, PKIX_EKUCHECKER_TYPE, plContext),
PKIX_OBJECTNOTANEKUCHECKERSTATE);
ekuCheckerState = (pkix_pl_EkuCheckerState *)object;
ekuCheckerState = (pkix_pl_EkuChecker *)object;
PKIX_DECREF(ekuCheckerState->ekuOID);
cleanup:
PKIX_RETURN(USERDEFINEDMODULES);
PKIX_RETURN(EKUCHECKER);
}
/*
@ -132,7 +132,7 @@ pkix_pl_EkuChecker_GetRequiredEku(
PKIX_UInt32 i;
PKIX_Boolean isContained = PKIX_FALSE;
PKIX_ENTER(USERDEFINEDMODULES, "pkix_pl_EkuChecker_GetRequiredEku");
PKIX_ENTER(EKUCHECKER, "pkix_pl_EkuChecker_GetRequiredEku");
PKIX_NULLCHECK_TWO(certSelector, pRequiredExtKeyUsage);
/* Get initial EKU OIDs from ComCertSelParams, if set */
@ -215,11 +215,11 @@ cleanup:
PKIX_DECREF(supportedOids);
PKIX_DECREF(comCertSelParams);
PKIX_RETURN(USERDEFINEDMODULES);
PKIX_RETURN(EKUCHECKER);
}
/*
* FUNCTION: pkix_EkuCheckerState_Create
* FUNCTION: pkix_EkuChecker_Create
* DESCRIPTION:
*
* Creates a new Extend Key Usage CheckerState using "params" to retrieve
@ -243,21 +243,21 @@ cleanup:
* Returns a Fatal Error if the function fails in an unrecoverable way.
*/
static PKIX_Error *
pkix_pl_EkuCheckerState_Create(
pkix_pl_EkuChecker_Create(
PKIX_ProcessingParams *params,
pkix_pl_EkuCheckerState **pState,
pkix_pl_EkuChecker **pState,
void *plContext)
{
pkix_pl_EkuCheckerState *state = NULL;
pkix_pl_EkuChecker *state = NULL;
PKIX_CertSelector *certSelector = NULL;
PKIX_UInt32 requiredExtKeyUsage = 0;
PKIX_ENTER(USERDEFINEDMODULES, "pkix_pl_EkuCheckerState_Create");
PKIX_ENTER(EKUCHECKER, "pkix_pl_EkuChecker_Create");
PKIX_NULLCHECK_TWO(params, pState);
PKIX_CHECK(PKIX_PL_Object_Alloc
(PKIX_EKUCHECKERSTATE_TYPE,
sizeof (pkix_pl_EkuCheckerState),
(PKIX_EKUCHECKER_TYPE,
sizeof (pkix_pl_EkuChecker),
(PKIX_PL_Object **)&state,
plContext),
PKIX_COULDNOTCREATEEKUCHECKERSTATEOBJECT);
@ -291,7 +291,7 @@ cleanup:
PKIX_DECREF(state);
PKIX_RETURN(USERDEFINEDMODULES);
PKIX_RETURN(EKUCHECKER);
}
/*
@ -327,11 +327,11 @@ pkix_pl_EkuChecker_Check(
void **pNBIOContext,
void *plContext)
{
pkix_pl_EkuCheckerState *state = NULL;
pkix_pl_EkuChecker *state = NULL;
PKIX_List *certEkuList = NULL;
PKIX_Boolean checkPassed = PKIX_TRUE;
PKIX_ENTER(USERDEFINEDMODULES, "pkix_pl_EkuChecker_Check");
PKIX_ENTER(EKUCHECKER, "pkix_pl_EkuChecker_Check");
PKIX_NULLCHECK_THREE(checker, cert, pNBIOContext);
*pNBIOContext = NULL; /* no non-blocking IO */
@ -360,23 +360,62 @@ cleanup:
PKIX_DECREF(certEkuList);
PKIX_DECREF(state);
PKIX_RETURN(USERDEFINEDMODULES);
PKIX_RETURN(EKUCHECKER);
}
/*
* FUNCTION: pkix_pl_EkuCheckerState_Initialize
* FUNCTION: pkix_pl_EkuChecker_RegisterSelf
*
* DESCRIPTION:
* Registers PKIX_PL_HTTPCERTSTORECONTEXT_TYPE and its related
* functions with systemClasses[]
*
* THREAD SAFETY:
* Not Thread Safe - for performance and complexity reasons
*
* Since this function is only called by PKIX_PL_Initialize, which should
* only be called once, it is acceptable that this function is not
* thread-safe.
*/
PKIX_Error *
pkix_pl_EkuChecker_RegisterSelf(void *plContext)
{
extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
pkix_ClassTable_Entry entry;
PKIX_ENTER
(EKUCHECKER,
"pkix_pl_EkuChecker_RegisterSelf");
entry.description = "EkuChecker";
entry.objCounter = 0;
entry.typeObjectSize = sizeof(pkix_pl_EkuChecker);
entry.destructor = pkix_pl_EkuChecker_Destroy,
entry.equalsFunction = NULL;
entry.hashcodeFunction = NULL;
entry.toStringFunction = NULL;
entry.comparator = NULL;
entry.duplicateFunction = NULL;
systemClasses[PKIX_EKUCHECKER_TYPE] = entry;
PKIX_RETURN(EKUCHECKER);
}
/*
* FUNCTION: pkix_pl_EkuChecker_Initialize
* (see comments in pkix_sample_modules.h)
*/
PKIX_Error *
PKIX_PL_EkuChecker_Initialize(
PKIX_PL_EkuChecker_Create(
PKIX_ProcessingParams *params,
void *plContext)
{
PKIX_CertChainChecker *checker = NULL;
pkix_pl_EkuCheckerState *state = NULL;
pkix_pl_EkuChecker *state = NULL;
PKIX_List *critExtOIDsList = NULL;
PKIX_ENTER(USERDEFINEDMODULES, "PKIX_PL_EkuChecker_Initialize");
PKIX_ENTER(EKUCHECKER, "PKIX_PL_EkuChecker_Initialize");
PKIX_NULLCHECK_ONE(params);
/*
@ -384,21 +423,7 @@ PKIX_PL_EkuChecker_Initialize(
* an application defined checker can be hooked into libpkix.
*/
/* Register user type object for EKU Checker State */
PKIX_CHECK(PKIX_PL_Object_RegisterType
(PKIX_EKUCHECKERSTATE_TYPE,
/* PKIX_EXTENDEDKEYUSAGEUSEROBJECT, */
"PKIXEXTENDEDKEYUSAGEUSEROBJECT",
pkix_pl_EkuCheckerState_Destroy,
NULL,
NULL,
NULL,
NULL,
pkix_duplicateImmutable,
plContext),
PKIX_OBJECTREGISTERTYPEFAILED);
PKIX_CHECK(pkix_pl_EkuCheckerState_Create
PKIX_CHECK(pkix_pl_EkuChecker_Create
(params, &state, plContext),
PKIX_EKUCHECKERSTATECREATEFAILED);
@ -431,5 +456,5 @@ cleanup:
PKIX_DECREF(checker);
PKIX_DECREF(state);
PKIX_RETURN(USERDEFINEDMODULES);
PKIX_RETURN(EKUCHECKER);
}

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

@ -50,16 +50,15 @@
extern "C" {
#endif
#define PKIX_EKUCHECKERSTATE_TYPE (PKIX_USER_OBJECT_TYPEBASE+1)
typedef struct pkix_pl_EkuChecker pkix_pl_EkuChecker;
typedef struct pkix_pl_EkuCheckerState pkix_pl_EkuCheckerState;
struct pkix_pl_EkuCheckerState {
struct pkix_pl_EkuChecker {
PKIX_UInt32 requiredExtKeyUsage;
PKIX_PL_OID *ekuOID;
};
/* see source file for function documentation */
PKIX_Error *pkix_pl_EkuChecker_RegisterSelf(void *plContext);
#ifdef __cplusplus
}

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

@ -103,6 +103,7 @@
#include "pkix_pl_httpdefaultclient.h"
#include "pkix_pl_infoaccess.h"
#include "pkix_sample_modules.h"
#include "pkix_pl_ekuchecker.h"
#define MAX_DIGITS_32 (PKIX_UInt32) 10

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

@ -227,6 +227,7 @@ PKIX_PL_Initialize(
pkix_pl_OcspResponse_RegisterSelf(plContext);
pkix_pl_HttpDefaultClient_RegisterSelf(plContext);
pkix_VerifyNode_RegisterSelf(plContext);
pkix_pl_EkuChecker_RegisterSelf(plContext);
if (pPlContext) {
PKIX_CHECK(PKIX_PL_NssContext_Create

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

@ -43,6 +43,7 @@
#include "pkix_pl_object.h"
#ifdef PKIX_USER_OBJECT_TYPE
/* --Class-Table-Initializers------------------------------------ */
/*
@ -66,6 +67,7 @@ static pkix_pl_PrimHashTable pkix_Raw_ClassTable = {
20 /* Number of Buckets */
};
static pkix_pl_PrimHashTable * classTable = &pkix_Raw_ClassTable;
#endif /* PKIX_USER_OBJECT_TYPE */
/* --Private-Functions-------------------------------------------- */
@ -96,8 +98,7 @@ pkix_pl_Object_GetHeader(
void *plContext)
{
PKIX_PL_Object *header = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_UInt32 myType;
PKIX_UInt32 objType;
PKIX_ENTER(OBJECT, "pkix_pl_Object_GetHeader");
PKIX_NULLCHECK_TWO(object, pObjectHeader);
@ -107,16 +108,19 @@ pkix_pl_Object_GetHeader(
/* The header is sizeof(PKIX_PL_Object) before the object pointer */
header = (PKIX_PL_Object *)((char *)object - sizeof(PKIX_PL_Object));
myType = header->type;
objType = header->type;
if (objType >= PKIX_NUMTYPES) { /* if this is a user-defined type */
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
if (myType >= PKIX_NUMTYPES) { /* if this is a user-defined type */
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
PKIX_CHECK(pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&myType,
header->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext),
@ -128,6 +132,12 @@ pkix_pl_Object_GetHeader(
if (ctEntry == NULL) {
PKIX_ERROR_FATAL(PKIX_UNKNOWNOBJECTTYPE);
}
#else
PORT_Assert(objType < PKIX_NUMTYPES);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
}
if ((header == NULL)||
@ -265,36 +275,28 @@ pkix_pl_Object_ToString_Default(
PKIX_PL_String **pString,
void *plContext)
{
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_String *formatString = NULL;
PKIX_PL_String *descString = NULL;
char *format = "%s@Address: %x";
char *description = NULL;
PKIX_UInt32 type;
PKIX_UInt32 objType;
PKIX_ENTER(OBJECT, "pkix_pl_Object_ToString_Default");
PKIX_NULLCHECK_TWO(object, pString);
PKIX_CHECK(PKIX_PL_Object_GetType(object, &type, plContext),
PKIX_CHECK(PKIX_PL_Object_GetType(object, &objType, plContext),
PKIX_OBJECTGETTYPEFAILED);
/* Ensure that type code is known. Otherwise, default to Object */
/* See pkixt.h for all known types. */
/* XXX Throw an illegal type error here? */
if (type >= PKIX_NUMTYPES) {
type = 0;
}
if (objType >= PKIX_NUMTYPES){
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
/* first, special handling for system types */
if (type < PKIX_NUMTYPES){
description = systemClasses[type].description;
} else {
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&type,
type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -308,9 +310,19 @@ pkix_pl_Object_ToString_Default(
PKIX_ERROR_FATAL(PKIX_UNDEFINEDCLASSTABLEENTRY);
} else {
description = ctEntry->description;
if (description == NULL) {
description = "User Type Object";
}
}
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
description = systemClasses[objType].description;
}
PKIX_CHECK(PKIX_PL_String_Create
(PKIX_ESCASCII,
(void *)format,
@ -424,9 +436,9 @@ pkix_pl_Object_RetrieveEqualsCallback(
void *plContext)
{
PKIX_PL_Object *objectHeader = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_EqualsCallback func = NULL;
pkix_ClassTable_Entry entry;
PKIX_UInt32 objType;
PKIX_ENTER(OBJECT, "pkix_pl_Object_RetrieveEqualsCallback");
PKIX_NULLCHECK_TWO(object, pEqualsCallback);
@ -435,21 +447,18 @@ pkix_pl_Object_RetrieveEqualsCallback(
(object, &objectHeader, plContext),
PKIX_RECEIVEDCORRUPTEDOBJECTARGUMENT);
/* first, special handling for system types */
if (objectHeader->type < PKIX_NUMTYPES){
entry = systemClasses[objectHeader->type];
func = entry.equalsFunction;
if (func == NULL){
func = pkix_pl_Object_Equals_Default;
}
*pEqualsCallback = func;
} else {
objType = objectHeader->type;
if (objType >= PKIX_NUMTYPES){
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&objectHeader->type,
objectHeader->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -464,6 +473,19 @@ pkix_pl_Object_RetrieveEqualsCallback(
} else {
*pEqualsCallback = ctEntry->equalsFunction;
}
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
entry = systemClasses[objType];
func = entry.equalsFunction;
if (func == NULL){
func = pkix_pl_Object_Equals_Default;
}
*pEqualsCallback = func;
}
cleanup:
@ -489,7 +511,6 @@ cleanup:
PKIX_Error *
pkix_pl_Object_RegisterSelf(void *plContext)
{
extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
pkix_ClassTable_Entry entry;
PKIX_ENTER(ERROR, "pkix_pl_Object_RegisterSelf");
@ -516,14 +537,13 @@ pkix_pl_Object_RegisterSelf(void *plContext)
*/
PKIX_Error *
PKIX_PL_Object_Alloc(
PKIX_TYPENUM type,
PKIX_TYPENUM objType,
PKIX_UInt32 size,
PKIX_PL_Object **pObject,
void *plContext)
{
PKIX_PL_Object *object = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_Boolean typeRegistered;
PKIX_ENTER(OBJECT, "PKIX_PL_Object_Alloc");
PKIX_NULLCHECK_ONE(pObject);
@ -533,13 +553,15 @@ PKIX_PL_Object_Alloc(
* All system types have already been registered by PKIX_PL_Initialize.
*/
if (type >= PKIX_NUMTYPES) { /* i.e. if this is a user-defined type */
if (objType >= PKIX_NUMTYPES) { /* i.e. if this is a user-defined type */
#ifdef PKIX_USER_OBJECT_TYPE
PKIX_Boolean typeRegistered;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&type,
type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -554,8 +576,14 @@ PKIX_PL_Object_Alloc(
if (!typeRegistered) {
PKIX_ERROR_FATAL(PKIX_UNKNOWNTYPEARGUMENT);
}
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
ctEntry = &systemClasses[type];
ctEntry = &systemClasses[objType];
}
PORT_Assert(size == ctEntry->typeObjectSize);
@ -569,7 +597,7 @@ PKIX_PL_Object_Alloc(
/* Initialize all object fields */
object->magicHeader = PKIX_MAGIC_HEADER;
object->type = type;
object->type = objType;
object->references = 1; /* Default to a single reference */
object->stringRep = NULL;
object->hashcode = 0;
@ -606,27 +634,34 @@ cleanup:
*/
PKIX_Error *
PKIX_PL_Object_IsTypeRegistered(
PKIX_UInt32 type,
PKIX_UInt32 objType,
PKIX_Boolean *pBool,
void *plContext)
{
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
#endif
PKIX_ENTER(OBJECT, "PKIX_PL_Object_IsTypeRegistered");
PKIX_NULLCHECK_ONE(pBool);
/* first, we handle the system types */
if (type < PKIX_NUMTYPES) {
if (objType < PKIX_NUMTYPES) {
*pBool = PKIX_TRUE;
goto cleanup;
}
#ifndef PKIX_USER_OBJECT_TYPE
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
#else
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&type,
type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -638,18 +673,20 @@ PKIX_PL_Object_IsTypeRegistered(
}
*pBool = (ctEntry != NULL);
#endif /* PKIX_USER_OBJECT_TYPE */
cleanup:
PKIX_RETURN(OBJECT);
}
#ifdef PKIX_USER_OBJECT_TYPE
/*
* FUNCTION: PKIX_PL_Object_RegisterType (see comments in pkix_pl_system.h)
*/
PKIX_Error *
PKIX_PL_Object_RegisterType(
PKIX_UInt32 type,
PKIX_UInt32 objType,
char *description,
PKIX_PL_DestructorCallback destructor,
PKIX_PL_EqualsCallback equalsFunction,
@ -669,7 +706,7 @@ PKIX_PL_Object_RegisterType(
* These can not be overwritten.
*/
if (type < PKIX_NUMTYPES) { /* if this is a system type */
if (objType < PKIX_NUMTYPES) { /* if this is a system type */
PKIX_ERROR(PKIX_CANTREREGISTERSYSTEMTYPE);
}
@ -677,8 +714,8 @@ PKIX_PL_Object_RegisterType(
PR_Lock(classTableLock);
PKIX_CHECK(pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&type,
type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext),
@ -727,13 +764,13 @@ PKIX_PL_Object_RegisterType(
plContext),
PKIX_COULDNOTMALLOCNEWKEY);
key->ht_int = type;
key->ht_int = objType;
PKIX_CHECK(pkix_pl_PrimHashTable_Add
(classTable,
(void *)key,
(void *)ctEntry,
type,
objType,
NULL,
plContext),
PKIX_PRIMHASHTABLEADDFAILED);
@ -744,6 +781,7 @@ cleanup:
PKIX_RETURN(OBJECT);
}
#endif /* PKIX_USER_OBJECT_TYPE */
/*
* FUNCTION: PKIX_PL_Object_IncRef (see comments in pkix_pl_system.h)
@ -832,15 +870,17 @@ PKIX_PL_Object_DecRef(
if (refCount == 0) {
PKIX_PL_DestructorCallback destructor = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_UInt32 objType = objectHeader->type;
/* first, special handling for system types */
if (objectHeader->type >= PKIX_NUMTYPES){
if (objType >= PKIX_NUMTYPES){
#ifdef PKIX_USER_OBJECT_TYPE
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&objectHeader->type,
objectHeader->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -855,8 +895,14 @@ PKIX_PL_Object_DecRef(
if (ctEntry != NULL){
destructor = ctEntry->destructor;
}
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
ctEntry = &systemClasses[objectHeader->type];
ctEntry = &systemClasses[objType];
destructor = ctEntry->destructor;
}
@ -902,9 +948,9 @@ PKIX_PL_Object_Equals(
{
PKIX_PL_Object *firstObjectHeader = NULL;
PKIX_PL_Object *secondObjectHeader = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_EqualsCallback func = NULL;
pkix_ClassTable_Entry entry;
PKIX_UInt32 objType;
PKIX_ENTER(OBJECT, "PKIX_PL_Object_Equals");
PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult);
@ -927,14 +973,11 @@ PKIX_PL_Object_Equals(
}
}
/* first, special handling for system types */
if (firstObjectHeader->type < PKIX_NUMTYPES){
entry = systemClasses[firstObjectHeader->type];
func = entry.equalsFunction;
if (func == NULL){
func = pkix_pl_Object_Equals_Default;
}
} else {
objType = firstObjectHeader->type;
if (objType >= PKIX_NUMTYPES) {
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
@ -956,6 +999,18 @@ PKIX_PL_Object_Equals(
} else {
func = ctEntry->equalsFunction;
}
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
entry = systemClasses[objType];
func = entry.equalsFunction;
if (func == NULL){
func = pkix_pl_Object_Equals_Default;
}
}
PKIX_CHECK(func(firstObject, secondObject, pResult, plContext),
@ -976,9 +1031,9 @@ PKIX_PL_Object_Duplicate(
void *plContext)
{
PKIX_PL_Object *firstObjectHeader = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_DuplicateCallback func = NULL;
pkix_ClassTable_Entry entry;
PKIX_UInt32 objType;
PKIX_ENTER(OBJECT, "PKIX_PL_Object_Duplicate");
PKIX_NULLCHECK_TWO(firstObject, pNewObject);
@ -987,20 +1042,18 @@ PKIX_PL_Object_Duplicate(
(firstObject, &firstObjectHeader, plContext),
PKIX_RECEIVEDCORRUPTEDOBJECTARGUMENT);
/* first, special handling for system types */
if (firstObjectHeader->type < PKIX_NUMTYPES){
entry = systemClasses[firstObjectHeader->type];
func = entry.duplicateFunction;
if (!func){
PKIX_ERROR_FATAL(PKIX_UNDEFINEDDUPLICATEFUNCTION);
}
} else {
objType = firstObjectHeader->type;
if (objType >= PKIX_NUMTYPES) {
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&firstObjectHeader->type,
firstObjectHeader->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -1016,6 +1069,18 @@ PKIX_PL_Object_Duplicate(
} else {
func = ctEntry->duplicateFunction;
}
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
entry = systemClasses[objType];
func = entry.duplicateFunction;
if (!func){
PKIX_ERROR_FATAL(PKIX_UNDEFINEDDUPLICATEFUNCTION);
}
}
PKIX_CHECK(func(firstObject, pNewObject, plContext),
@ -1036,7 +1101,6 @@ PKIX_PL_Object_Hashcode(
void *plContext)
{
PKIX_PL_Object *objectHeader = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_HashcodeCallback func = NULL;
pkix_ClassTable_Entry entry;
PKIX_UInt32 objectHash;
@ -1051,20 +1115,19 @@ PKIX_PL_Object_Hashcode(
/* if we don't have a cached copy from before, we create one */
if (!objectHeader->hashcodeCached){
PKIX_UInt32 objType = objectHeader->type;
/* first, special handling for system types */
if (objectHeader->type < PKIX_NUMTYPES){
entry = systemClasses[objectHeader->type];
func = entry.hashcodeFunction;
if (func == NULL){
func = pkix_pl_Object_Hashcode_Default;
}
} else {
if (objType >= PKIX_NUMTYPES){
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&objectHeader->type,
objectHeader->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -1082,6 +1145,18 @@ PKIX_PL_Object_Hashcode(
}
func = ctEntry->hashcodeFunction;
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
entry = systemClasses[objType];
func = entry.hashcodeFunction;
if (func == NULL){
func = pkix_pl_Object_Hashcode_Default;
}
}
PKIX_CHECK(func(object, &objectHash, plContext),
@ -1120,7 +1195,6 @@ PKIX_PL_Object_ToString(
void *plContext)
{
PKIX_PL_Object *objectHeader = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_ToStringCallback func = NULL;
pkix_ClassTable_Entry entry;
PKIX_PL_String *objectString;
@ -1135,20 +1209,18 @@ PKIX_PL_Object_ToString(
/* if we don't have a cached copy from before, we create one */
if (!objectHeader->stringRep){
/* first, special handling for system types */
if (objectHeader->type < PKIX_NUMTYPES){
entry = systemClasses[objectHeader->type];
func = entry.toStringFunction;
if (func == NULL){
func = pkix_pl_Object_ToString_Default;
}
} else {
PKIX_UInt32 objType = objectHeader->type;
if (objType >= PKIX_NUMTYPES){
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&objectHeader->type,
objectHeader->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -1165,6 +1237,18 @@ PKIX_PL_Object_ToString(
}
func = ctEntry->toStringFunction;
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
entry = systemClasses[objType];
func = entry.toStringFunction;
if (func == NULL){
func = pkix_pl_Object_ToString_Default;
}
}
PKIX_CHECK(func(object, &objectString, plContext),
@ -1239,9 +1323,9 @@ PKIX_PL_Object_Compare(
{
PKIX_PL_Object *firstObjectHeader = NULL;
PKIX_PL_Object *secondObjectHeader = NULL;
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_PL_ComparatorCallback func = NULL;
pkix_ClassTable_Entry entry;
PKIX_UInt32 objType;
PKIX_ENTER(OBJECT, "PKIX_PL_Object_Compare");
PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult);
@ -1256,20 +1340,18 @@ PKIX_PL_Object_Compare(
(secondObject, &secondObjectHeader, plContext),
PKIX_RECEIVEDCORRUPTEDOBJECTARGUMENT);
/* first, special handling for system types */
if (firstObjectHeader->type < PKIX_NUMTYPES){
entry = systemClasses[firstObjectHeader->type];
func = entry.comparator;
if (!func){
PKIX_ERROR(PKIX_UNDEFINEDCOMPARATOR);
}
} else {
objType = firstObjectHeader->type;
if (objType >= PKIX_NUMTYPES){
#ifdef PKIX_USER_OBJECT_TYPE
pkix_ClassTable_Entry *ctEntry = NULL;
PKIX_OBJECT_DEBUG("\tCalling PR_Lock).\n");
PR_Lock(classTableLock);
pkixErrorResult = pkix_pl_PrimHashTable_Lookup
(classTable,
(void *)&firstObjectHeader->type,
firstObjectHeader->type,
(void *)&objType,
objType,
NULL,
(void **)&ctEntry,
plContext);
@ -1284,6 +1366,19 @@ PKIX_PL_Object_Compare(
}
func = ctEntry->comparator;
#else
PORT_Assert (0);
pkixErrorCode = PKIX_UNKNOWNOBJECTTYPE;
pkixErrorClass = PKIX_FATAL_ERROR;
goto cleanup;
#endif /* PKIX_USER_OBJECT_TYPE */
} else {
/* special handling for system types */
entry = systemClasses[objType];
func = entry.comparator;
if (!func){
PKIX_ERROR(PKIX_UNDEFINEDCOMPARATOR);
}
}
PKIX_CHECK(func(firstObject, secondObject, pResult, plContext),

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

@ -88,20 +88,15 @@ pkix_pl_Object_RetrieveEqualsCallback(
PKIX_PL_EqualsCallback *equalsCallback,
void *plContext);
PKIX_Error *
PKIX_PL_Object_RegisterSystemType(
PKIX_UInt32 type,
PKIX_PL_DestructorCallback destructor,
PKIX_PL_EqualsCallback equalsFunction,
PKIX_PL_HashcodeCallback hashcodeFunction,
PKIX_PL_ToStringCallback toStringFunction,
PKIX_PL_ComparatorCallback comparator,
PKIX_PL_DuplicateCallback duplicateFunction,
void *plContext);
extern PKIX_Boolean initializing;
extern PKIX_Boolean initialized;
#ifdef PKIX_USER_OBJECT_TYPE
extern PRLock *classTableLock;
#endif
extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
PKIX_Error *