andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * pkix_resourcelimits.c andre@0: * andre@0: * Resourcelimits Params Object Functions andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_resourcelimits.h" andre@0: andre@0: /* --Private-Functions-------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ResourceLimits_Destroy andre@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ResourceLimits_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_ResourceLimits *rLimits = NULL; andre@0: andre@0: PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Destroy"); andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: /* Check that this object is a ResourceLimits object */ andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), andre@0: PKIX_OBJECTNOTRESOURCELIMITS); andre@0: andre@0: rLimits = (PKIX_ResourceLimits *)object; andre@0: andre@0: rLimits->maxTime = 0; andre@0: rLimits->maxFanout = 0; andre@0: rLimits->maxDepth = 0; andre@0: rLimits->maxCertsNumber = 0; andre@0: rLimits->maxCrlsNumber = 0; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ResourceLimits_Equals andre@0: * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ResourceLimits_Equals( andre@0: PKIX_PL_Object *first, andre@0: PKIX_PL_Object *second, andre@0: PKIX_Boolean *pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_UInt32 secondType; andre@0: PKIX_Boolean cmpResult; andre@0: PKIX_ResourceLimits *firstRLimits = NULL; andre@0: PKIX_ResourceLimits *secondRLimits = NULL; andre@0: andre@0: PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Equals"); andre@0: PKIX_NULLCHECK_THREE(first, second, pResult); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(first, PKIX_RESOURCELIMITS_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTRESOURCELIMITS); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_GetType(second, &secondType, plContext), andre@0: PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); andre@0: andre@0: *pResult = PKIX_FALSE; andre@0: andre@0: if (secondType != PKIX_RESOURCELIMITS_TYPE) goto cleanup; andre@0: andre@0: firstRLimits = (PKIX_ResourceLimits *)first; andre@0: secondRLimits = (PKIX_ResourceLimits *)second; andre@0: andre@0: cmpResult = (firstRLimits->maxTime == secondRLimits->maxTime) && andre@0: (firstRLimits->maxFanout == secondRLimits->maxFanout) && andre@0: (firstRLimits->maxDepth == secondRLimits->maxDepth) && andre@0: (firstRLimits->maxCertsNumber == andre@0: secondRLimits->maxCertsNumber) && andre@0: (firstRLimits->maxCrlsNumber == andre@0: secondRLimits->maxCrlsNumber); andre@0: andre@0: *pResult = cmpResult; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ResourceLimits_Hashcode andre@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ResourceLimits_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_ResourceLimits *rLimits = NULL; andre@0: PKIX_UInt32 hash = 0; andre@0: andre@0: PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Hashcode"); andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), andre@0: PKIX_OBJECTNOTRESOURCELIMITS); andre@0: andre@0: rLimits = (PKIX_ResourceLimits*)object; andre@0: andre@0: hash = 31 * rLimits->maxTime + (rLimits->maxFanout << 1) + andre@0: (rLimits->maxDepth << 2) + (rLimits->maxCertsNumber << 3) + andre@0: rLimits->maxCrlsNumber; andre@0: andre@0: *pHashcode = hash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ResourceLimits_ToString andre@0: * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ResourceLimits_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_ResourceLimits *rLimits = NULL; andre@0: char *asciiFormat = NULL; andre@0: PKIX_PL_String *formatString = NULL; andre@0: PKIX_PL_String *rLimitsString = NULL; andre@0: andre@0: PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_ToString"); andre@0: PKIX_NULLCHECK_TWO(object, pString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), andre@0: PKIX_OBJECTNOTRESOURCELIMITS); andre@0: andre@0: /* maxCertsNumber and maxCrlsNumber are not supported */ andre@0: asciiFormat = andre@0: "[\n" andre@0: "\tMaxTime: \t\t%d\n" andre@0: "\tMaxFanout: \t\t%d\n" andre@0: "\tMaxDepth: \t\t%d\n" andre@0: "]\n"; andre@0: andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: asciiFormat, andre@0: 0, andre@0: &formatString, andre@0: plContext), andre@0: PKIX_STRINGCREATEFAILED); andre@0: andre@0: rLimits = (PKIX_ResourceLimits*)object; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&rLimitsString, andre@0: plContext, andre@0: formatString, andre@0: rLimits->maxTime, andre@0: rLimits->maxFanout, andre@0: rLimits->maxDepth), andre@0: PKIX_SPRINTFFAILED); andre@0: andre@0: *pString = rLimitsString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(formatString); andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ResourceLimits_RegisterSelf andre@0: * DESCRIPTION: andre@0: * Registers PKIX_RESOURCELIMITS_TYPE and its related functions with andre@0: * systemClasses[] andre@0: * THREAD SAFETY: andre@0: * Not Thread Safe - for performance and complexity reasons andre@0: * andre@0: * Since this function is only called by PKIX_PL_Initialize, which should andre@0: * only be called once, it is acceptable that this function is not andre@0: * thread-safe. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_ResourceLimits_RegisterSelf(void *plContext) andre@0: { andre@0: andre@0: extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; andre@0: pkix_ClassTable_Entry entry; andre@0: andre@0: PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_RegisterSelf"); andre@0: andre@0: entry.description = "ResourceLimits"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_ResourceLimits); andre@0: entry.destructor = pkix_ResourceLimits_Destroy; andre@0: entry.equalsFunction = pkix_ResourceLimits_Equals; andre@0: entry.hashcodeFunction = pkix_ResourceLimits_Hashcode; andre@0: entry.toStringFunction = pkix_ResourceLimits_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = NULL; andre@0: andre@0: systemClasses[PKIX_RESOURCELIMITS_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* --Public-Functions--------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_Create (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_Create( andre@0: PKIX_ResourceLimits **pResourceLimits, andre@0: void *plContext) andre@0: { andre@0: PKIX_ResourceLimits *rLimits = NULL; andre@0: andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_Create"); andre@0: PKIX_NULLCHECK_ONE(pResourceLimits); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_RESOURCELIMITS_TYPE, andre@0: sizeof (PKIX_ResourceLimits), andre@0: (PKIX_PL_Object **)&rLimits, andre@0: plContext), andre@0: PKIX_COULDNOTCREATERESOURCELIMITOBJECT); andre@0: andre@0: /* initialize fields */ andre@0: rLimits->maxTime = 0; andre@0: rLimits->maxFanout = 0; andre@0: rLimits->maxDepth = 0; andre@0: rLimits->maxCertsNumber = 0; andre@0: rLimits->maxCrlsNumber = 0; andre@0: andre@0: *pResourceLimits = rLimits; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_GetMaxTime andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_GetMaxTime( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 *pMaxTime, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxTime"); andre@0: PKIX_NULLCHECK_TWO(rLimits, pMaxTime); andre@0: andre@0: *pMaxTime = rLimits->maxTime; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_SetMaxTime andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_SetMaxTime( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 maxTime, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxTime"); andre@0: PKIX_NULLCHECK_ONE(rLimits); andre@0: andre@0: rLimits->maxTime = maxTime; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_GetMaxFanout andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_GetMaxFanout( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 *pMaxFanout, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxFanout"); andre@0: PKIX_NULLCHECK_TWO(rLimits, pMaxFanout); andre@0: andre@0: *pMaxFanout = rLimits->maxFanout; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_SetMaxFanout andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_SetMaxFanout( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 maxFanout, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxFanout"); andre@0: PKIX_NULLCHECK_ONE(rLimits); andre@0: andre@0: rLimits->maxFanout = maxFanout; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_GetMaxDepth andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_GetMaxDepth( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 *pMaxDepth, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxDepth"); andre@0: PKIX_NULLCHECK_TWO(rLimits, pMaxDepth); andre@0: andre@0: *pMaxDepth = rLimits->maxDepth; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_SetMaxDepth andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_SetMaxDepth( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 maxDepth, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxDepth"); andre@0: PKIX_NULLCHECK_ONE(rLimits); andre@0: andre@0: rLimits->maxDepth = maxDepth; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_GetMaxNumberOfCerts andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_GetMaxNumberOfCerts( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 *pMaxNumber, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxNumberOfCerts"); andre@0: PKIX_NULLCHECK_TWO(rLimits, pMaxNumber); andre@0: andre@0: *pMaxNumber = rLimits->maxCertsNumber; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_SetMaxNumberOfCerts andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_SetMaxNumberOfCerts( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 maxNumber, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxNumberOfCerts"); andre@0: PKIX_NULLCHECK_ONE(rLimits); andre@0: andre@0: rLimits->maxCertsNumber = maxNumber; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_GetMaxNumberOfCRLs andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_GetMaxNumberOfCRLs( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 *pMaxNumber, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxNumberOfCRLs"); andre@0: PKIX_NULLCHECK_TWO(rLimits, pMaxNumber); andre@0: andre@0: *pMaxNumber = rLimits->maxCrlsNumber; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ResourceLimits_SetMaxNumberOfCRLs andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ResourceLimits_SetMaxNumberOfCRLs( andre@0: PKIX_ResourceLimits *rLimits, andre@0: PKIX_UInt32 maxNumber, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxNumberOfCRLs"); andre@0: PKIX_NULLCHECK_ONE(rLimits); andre@0: andre@0: rLimits->maxCrlsNumber = maxNumber; andre@0: andre@0: PKIX_RETURN(RESOURCELIMITS); andre@0: }