1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/libpkix/pkix/params/pkix_resourcelimits.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,433 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +/* 1.8 + * pkix_resourcelimits.c 1.9 + * 1.10 + * Resourcelimits Params Object Functions 1.11 + * 1.12 + */ 1.13 + 1.14 +#include "pkix_resourcelimits.h" 1.15 + 1.16 +/* --Private-Functions-------------------------------------------- */ 1.17 + 1.18 +/* 1.19 + * FUNCTION: pkix_ResourceLimits_Destroy 1.20 + * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) 1.21 + */ 1.22 +static PKIX_Error * 1.23 +pkix_ResourceLimits_Destroy( 1.24 + PKIX_PL_Object *object, 1.25 + void *plContext) 1.26 +{ 1.27 + PKIX_ResourceLimits *rLimits = NULL; 1.28 + 1.29 + PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Destroy"); 1.30 + PKIX_NULLCHECK_ONE(object); 1.31 + 1.32 + /* Check that this object is a ResourceLimits object */ 1.33 + PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), 1.34 + PKIX_OBJECTNOTRESOURCELIMITS); 1.35 + 1.36 + rLimits = (PKIX_ResourceLimits *)object; 1.37 + 1.38 + rLimits->maxTime = 0; 1.39 + rLimits->maxFanout = 0; 1.40 + rLimits->maxDepth = 0; 1.41 + rLimits->maxCertsNumber = 0; 1.42 + rLimits->maxCrlsNumber = 0; 1.43 + 1.44 +cleanup: 1.45 + 1.46 + PKIX_RETURN(RESOURCELIMITS); 1.47 +} 1.48 + 1.49 +/* 1.50 + * FUNCTION: pkix_ResourceLimits_Equals 1.51 + * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) 1.52 + */ 1.53 +static PKIX_Error * 1.54 +pkix_ResourceLimits_Equals( 1.55 + PKIX_PL_Object *first, 1.56 + PKIX_PL_Object *second, 1.57 + PKIX_Boolean *pResult, 1.58 + void *plContext) 1.59 +{ 1.60 + PKIX_UInt32 secondType; 1.61 + PKIX_Boolean cmpResult; 1.62 + PKIX_ResourceLimits *firstRLimits = NULL; 1.63 + PKIX_ResourceLimits *secondRLimits = NULL; 1.64 + 1.65 + PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Equals"); 1.66 + PKIX_NULLCHECK_THREE(first, second, pResult); 1.67 + 1.68 + PKIX_CHECK(pkix_CheckType(first, PKIX_RESOURCELIMITS_TYPE, plContext), 1.69 + PKIX_FIRSTOBJECTNOTRESOURCELIMITS); 1.70 + 1.71 + PKIX_CHECK(PKIX_PL_Object_GetType(second, &secondType, plContext), 1.72 + PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); 1.73 + 1.74 + *pResult = PKIX_FALSE; 1.75 + 1.76 + if (secondType != PKIX_RESOURCELIMITS_TYPE) goto cleanup; 1.77 + 1.78 + firstRLimits = (PKIX_ResourceLimits *)first; 1.79 + secondRLimits = (PKIX_ResourceLimits *)second; 1.80 + 1.81 + cmpResult = (firstRLimits->maxTime == secondRLimits->maxTime) && 1.82 + (firstRLimits->maxFanout == secondRLimits->maxFanout) && 1.83 + (firstRLimits->maxDepth == secondRLimits->maxDepth) && 1.84 + (firstRLimits->maxCertsNumber == 1.85 + secondRLimits->maxCertsNumber) && 1.86 + (firstRLimits->maxCrlsNumber == 1.87 + secondRLimits->maxCrlsNumber); 1.88 + 1.89 + *pResult = cmpResult; 1.90 + 1.91 +cleanup: 1.92 + 1.93 + PKIX_RETURN(RESOURCELIMITS); 1.94 +} 1.95 + 1.96 +/* 1.97 + * FUNCTION: pkix_ResourceLimits_Hashcode 1.98 + * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) 1.99 + */ 1.100 +static PKIX_Error * 1.101 +pkix_ResourceLimits_Hashcode( 1.102 + PKIX_PL_Object *object, 1.103 + PKIX_UInt32 *pHashcode, 1.104 + void *plContext) 1.105 +{ 1.106 + PKIX_ResourceLimits *rLimits = NULL; 1.107 + PKIX_UInt32 hash = 0; 1.108 + 1.109 + PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Hashcode"); 1.110 + PKIX_NULLCHECK_TWO(object, pHashcode); 1.111 + 1.112 + PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), 1.113 + PKIX_OBJECTNOTRESOURCELIMITS); 1.114 + 1.115 + rLimits = (PKIX_ResourceLimits*)object; 1.116 + 1.117 + hash = 31 * rLimits->maxTime + (rLimits->maxFanout << 1) + 1.118 + (rLimits->maxDepth << 2) + (rLimits->maxCertsNumber << 3) + 1.119 + rLimits->maxCrlsNumber; 1.120 + 1.121 + *pHashcode = hash; 1.122 + 1.123 +cleanup: 1.124 + 1.125 + PKIX_RETURN(RESOURCELIMITS); 1.126 +} 1.127 + 1.128 +/* 1.129 + * FUNCTION: pkix_ResourceLimits_ToString 1.130 + * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) 1.131 + */ 1.132 +static PKIX_Error * 1.133 +pkix_ResourceLimits_ToString( 1.134 + PKIX_PL_Object *object, 1.135 + PKIX_PL_String **pString, 1.136 + void *plContext) 1.137 +{ 1.138 + PKIX_ResourceLimits *rLimits = NULL; 1.139 + char *asciiFormat = NULL; 1.140 + PKIX_PL_String *formatString = NULL; 1.141 + PKIX_PL_String *rLimitsString = NULL; 1.142 + 1.143 + PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_ToString"); 1.144 + PKIX_NULLCHECK_TWO(object, pString); 1.145 + 1.146 + PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), 1.147 + PKIX_OBJECTNOTRESOURCELIMITS); 1.148 + 1.149 + /* maxCertsNumber and maxCrlsNumber are not supported */ 1.150 + asciiFormat = 1.151 + "[\n" 1.152 + "\tMaxTime: \t\t%d\n" 1.153 + "\tMaxFanout: \t\t%d\n" 1.154 + "\tMaxDepth: \t\t%d\n" 1.155 + "]\n"; 1.156 + 1.157 + PKIX_CHECK(PKIX_PL_String_Create 1.158 + (PKIX_ESCASCII, 1.159 + asciiFormat, 1.160 + 0, 1.161 + &formatString, 1.162 + plContext), 1.163 + PKIX_STRINGCREATEFAILED); 1.164 + 1.165 + rLimits = (PKIX_ResourceLimits*)object; 1.166 + 1.167 + PKIX_CHECK(PKIX_PL_Sprintf 1.168 + (&rLimitsString, 1.169 + plContext, 1.170 + formatString, 1.171 + rLimits->maxTime, 1.172 + rLimits->maxFanout, 1.173 + rLimits->maxDepth), 1.174 + PKIX_SPRINTFFAILED); 1.175 + 1.176 + *pString = rLimitsString; 1.177 + 1.178 +cleanup: 1.179 + 1.180 + PKIX_DECREF(formatString); 1.181 + 1.182 + PKIX_RETURN(RESOURCELIMITS); 1.183 +} 1.184 + 1.185 +/* 1.186 + * FUNCTION: pkix_ResourceLimits_RegisterSelf 1.187 + * DESCRIPTION: 1.188 + * Registers PKIX_RESOURCELIMITS_TYPE and its related functions with 1.189 + * systemClasses[] 1.190 + * THREAD SAFETY: 1.191 + * Not Thread Safe - for performance and complexity reasons 1.192 + * 1.193 + * Since this function is only called by PKIX_PL_Initialize, which should 1.194 + * only be called once, it is acceptable that this function is not 1.195 + * thread-safe. 1.196 + */ 1.197 +PKIX_Error * 1.198 +pkix_ResourceLimits_RegisterSelf(void *plContext) 1.199 +{ 1.200 + 1.201 + extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; 1.202 + pkix_ClassTable_Entry entry; 1.203 + 1.204 + PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_RegisterSelf"); 1.205 + 1.206 + entry.description = "ResourceLimits"; 1.207 + entry.objCounter = 0; 1.208 + entry.typeObjectSize = sizeof(PKIX_ResourceLimits); 1.209 + entry.destructor = pkix_ResourceLimits_Destroy; 1.210 + entry.equalsFunction = pkix_ResourceLimits_Equals; 1.211 + entry.hashcodeFunction = pkix_ResourceLimits_Hashcode; 1.212 + entry.toStringFunction = pkix_ResourceLimits_ToString; 1.213 + entry.comparator = NULL; 1.214 + entry.duplicateFunction = NULL; 1.215 + 1.216 + systemClasses[PKIX_RESOURCELIMITS_TYPE] = entry; 1.217 + 1.218 + PKIX_RETURN(RESOURCELIMITS); 1.219 +} 1.220 + 1.221 +/* --Public-Functions--------------------------------------------- */ 1.222 + 1.223 +/* 1.224 + * FUNCTION: PKIX_ResourceLimits_Create (see comments in pkix_params.h) 1.225 + */ 1.226 +PKIX_Error * 1.227 +PKIX_ResourceLimits_Create( 1.228 + PKIX_ResourceLimits **pResourceLimits, 1.229 + void *plContext) 1.230 +{ 1.231 + PKIX_ResourceLimits *rLimits = NULL; 1.232 + 1.233 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_Create"); 1.234 + PKIX_NULLCHECK_ONE(pResourceLimits); 1.235 + 1.236 + PKIX_CHECK(PKIX_PL_Object_Alloc 1.237 + (PKIX_RESOURCELIMITS_TYPE, 1.238 + sizeof (PKIX_ResourceLimits), 1.239 + (PKIX_PL_Object **)&rLimits, 1.240 + plContext), 1.241 + PKIX_COULDNOTCREATERESOURCELIMITOBJECT); 1.242 + 1.243 + /* initialize fields */ 1.244 + rLimits->maxTime = 0; 1.245 + rLimits->maxFanout = 0; 1.246 + rLimits->maxDepth = 0; 1.247 + rLimits->maxCertsNumber = 0; 1.248 + rLimits->maxCrlsNumber = 0; 1.249 + 1.250 + *pResourceLimits = rLimits; 1.251 + 1.252 +cleanup: 1.253 + 1.254 + PKIX_RETURN(RESOURCELIMITS); 1.255 + 1.256 +} 1.257 + 1.258 +/* 1.259 + * FUNCTION: PKIX_ResourceLimits_GetMaxTime 1.260 + * (see comments in pkix_params.h) 1.261 + */ 1.262 +PKIX_Error * 1.263 +PKIX_ResourceLimits_GetMaxTime( 1.264 + PKIX_ResourceLimits *rLimits, 1.265 + PKIX_UInt32 *pMaxTime, 1.266 + void *plContext) 1.267 +{ 1.268 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxTime"); 1.269 + PKIX_NULLCHECK_TWO(rLimits, pMaxTime); 1.270 + 1.271 + *pMaxTime = rLimits->maxTime; 1.272 + 1.273 + PKIX_RETURN(RESOURCELIMITS); 1.274 +} 1.275 + 1.276 +/* 1.277 + * FUNCTION: PKIX_ResourceLimits_SetMaxTime 1.278 + * (see comments in pkix_params.h) 1.279 + */ 1.280 +PKIX_Error * 1.281 +PKIX_ResourceLimits_SetMaxTime( 1.282 + PKIX_ResourceLimits *rLimits, 1.283 + PKIX_UInt32 maxTime, 1.284 + void *plContext) 1.285 +{ 1.286 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxTime"); 1.287 + PKIX_NULLCHECK_ONE(rLimits); 1.288 + 1.289 + rLimits->maxTime = maxTime; 1.290 + 1.291 + PKIX_RETURN(RESOURCELIMITS); 1.292 +} 1.293 + 1.294 +/* 1.295 + * FUNCTION: PKIX_ResourceLimits_GetMaxFanout 1.296 + * (see comments in pkix_params.h) 1.297 + */ 1.298 +PKIX_Error * 1.299 +PKIX_ResourceLimits_GetMaxFanout( 1.300 + PKIX_ResourceLimits *rLimits, 1.301 + PKIX_UInt32 *pMaxFanout, 1.302 + void *plContext) 1.303 +{ 1.304 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxFanout"); 1.305 + PKIX_NULLCHECK_TWO(rLimits, pMaxFanout); 1.306 + 1.307 + *pMaxFanout = rLimits->maxFanout; 1.308 + 1.309 + PKIX_RETURN(RESOURCELIMITS); 1.310 +} 1.311 + 1.312 +/* 1.313 + * FUNCTION: PKIX_ResourceLimits_SetMaxFanout 1.314 + * (see comments in pkix_params.h) 1.315 + */ 1.316 +PKIX_Error * 1.317 +PKIX_ResourceLimits_SetMaxFanout( 1.318 + PKIX_ResourceLimits *rLimits, 1.319 + PKIX_UInt32 maxFanout, 1.320 + void *plContext) 1.321 +{ 1.322 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxFanout"); 1.323 + PKIX_NULLCHECK_ONE(rLimits); 1.324 + 1.325 + rLimits->maxFanout = maxFanout; 1.326 + 1.327 + PKIX_RETURN(RESOURCELIMITS); 1.328 +} 1.329 + 1.330 +/* 1.331 + * FUNCTION: PKIX_ResourceLimits_GetMaxDepth 1.332 + * (see comments in pkix_params.h) 1.333 + */ 1.334 +PKIX_Error * 1.335 +PKIX_ResourceLimits_GetMaxDepth( 1.336 + PKIX_ResourceLimits *rLimits, 1.337 + PKIX_UInt32 *pMaxDepth, 1.338 + void *plContext) 1.339 +{ 1.340 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxDepth"); 1.341 + PKIX_NULLCHECK_TWO(rLimits, pMaxDepth); 1.342 + 1.343 + *pMaxDepth = rLimits->maxDepth; 1.344 + 1.345 + PKIX_RETURN(RESOURCELIMITS); 1.346 +} 1.347 + 1.348 +/* 1.349 + * FUNCTION: PKIX_ResourceLimits_SetMaxDepth 1.350 + * (see comments in pkix_params.h) 1.351 + */ 1.352 +PKIX_Error * 1.353 +PKIX_ResourceLimits_SetMaxDepth( 1.354 + PKIX_ResourceLimits *rLimits, 1.355 + PKIX_UInt32 maxDepth, 1.356 + void *plContext) 1.357 +{ 1.358 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxDepth"); 1.359 + PKIX_NULLCHECK_ONE(rLimits); 1.360 + 1.361 + rLimits->maxDepth = maxDepth; 1.362 + 1.363 + PKIX_RETURN(RESOURCELIMITS); 1.364 +} 1.365 + 1.366 +/* 1.367 + * FUNCTION: PKIX_ResourceLimits_GetMaxNumberOfCerts 1.368 + * (see comments in pkix_params.h) 1.369 + */ 1.370 +PKIX_Error * 1.371 +PKIX_ResourceLimits_GetMaxNumberOfCerts( 1.372 + PKIX_ResourceLimits *rLimits, 1.373 + PKIX_UInt32 *pMaxNumber, 1.374 + void *plContext) 1.375 +{ 1.376 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxNumberOfCerts"); 1.377 + PKIX_NULLCHECK_TWO(rLimits, pMaxNumber); 1.378 + 1.379 + *pMaxNumber = rLimits->maxCertsNumber; 1.380 + 1.381 + PKIX_RETURN(RESOURCELIMITS); 1.382 +} 1.383 + 1.384 +/* 1.385 + * FUNCTION: PKIX_ResourceLimits_SetMaxNumberOfCerts 1.386 + * (see comments in pkix_params.h) 1.387 + */ 1.388 +PKIX_Error * 1.389 +PKIX_ResourceLimits_SetMaxNumberOfCerts( 1.390 + PKIX_ResourceLimits *rLimits, 1.391 + PKIX_UInt32 maxNumber, 1.392 + void *plContext) 1.393 +{ 1.394 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxNumberOfCerts"); 1.395 + PKIX_NULLCHECK_ONE(rLimits); 1.396 + 1.397 + rLimits->maxCertsNumber = maxNumber; 1.398 + 1.399 + PKIX_RETURN(RESOURCELIMITS); 1.400 +} 1.401 + 1.402 +/* 1.403 + * FUNCTION: PKIX_ResourceLimits_GetMaxNumberOfCRLs 1.404 + * (see comments in pkix_params.h) 1.405 + */ 1.406 +PKIX_Error * 1.407 +PKIX_ResourceLimits_GetMaxNumberOfCRLs( 1.408 + PKIX_ResourceLimits *rLimits, 1.409 + PKIX_UInt32 *pMaxNumber, 1.410 + void *plContext) 1.411 +{ 1.412 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxNumberOfCRLs"); 1.413 + PKIX_NULLCHECK_TWO(rLimits, pMaxNumber); 1.414 + 1.415 + *pMaxNumber = rLimits->maxCrlsNumber; 1.416 + 1.417 + PKIX_RETURN(RESOURCELIMITS); 1.418 +} 1.419 + 1.420 +/* 1.421 + * FUNCTION: PKIX_ResourceLimits_SetMaxNumberOfCRLs 1.422 + * (see comments in pkix_params.h) 1.423 + */ 1.424 +PKIX_Error * 1.425 +PKIX_ResourceLimits_SetMaxNumberOfCRLs( 1.426 + PKIX_ResourceLimits *rLimits, 1.427 + PKIX_UInt32 maxNumber, 1.428 + void *plContext) 1.429 +{ 1.430 + PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxNumberOfCRLs"); 1.431 + PKIX_NULLCHECK_ONE(rLimits); 1.432 + 1.433 + rLimits->maxCrlsNumber = maxNumber; 1.434 + 1.435 + PKIX_RETURN(RESOURCELIMITS); 1.436 +}