security/nss/lib/libpkix/pkix/params/pkix_resourcelimits.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 /*
michael@0 5 * pkix_resourcelimits.c
michael@0 6 *
michael@0 7 * Resourcelimits Params Object Functions
michael@0 8 *
michael@0 9 */
michael@0 10
michael@0 11 #include "pkix_resourcelimits.h"
michael@0 12
michael@0 13 /* --Private-Functions-------------------------------------------- */
michael@0 14
michael@0 15 /*
michael@0 16 * FUNCTION: pkix_ResourceLimits_Destroy
michael@0 17 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
michael@0 18 */
michael@0 19 static PKIX_Error *
michael@0 20 pkix_ResourceLimits_Destroy(
michael@0 21 PKIX_PL_Object *object,
michael@0 22 void *plContext)
michael@0 23 {
michael@0 24 PKIX_ResourceLimits *rLimits = NULL;
michael@0 25
michael@0 26 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Destroy");
michael@0 27 PKIX_NULLCHECK_ONE(object);
michael@0 28
michael@0 29 /* Check that this object is a ResourceLimits object */
michael@0 30 PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext),
michael@0 31 PKIX_OBJECTNOTRESOURCELIMITS);
michael@0 32
michael@0 33 rLimits = (PKIX_ResourceLimits *)object;
michael@0 34
michael@0 35 rLimits->maxTime = 0;
michael@0 36 rLimits->maxFanout = 0;
michael@0 37 rLimits->maxDepth = 0;
michael@0 38 rLimits->maxCertsNumber = 0;
michael@0 39 rLimits->maxCrlsNumber = 0;
michael@0 40
michael@0 41 cleanup:
michael@0 42
michael@0 43 PKIX_RETURN(RESOURCELIMITS);
michael@0 44 }
michael@0 45
michael@0 46 /*
michael@0 47 * FUNCTION: pkix_ResourceLimits_Equals
michael@0 48 * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h)
michael@0 49 */
michael@0 50 static PKIX_Error *
michael@0 51 pkix_ResourceLimits_Equals(
michael@0 52 PKIX_PL_Object *first,
michael@0 53 PKIX_PL_Object *second,
michael@0 54 PKIX_Boolean *pResult,
michael@0 55 void *plContext)
michael@0 56 {
michael@0 57 PKIX_UInt32 secondType;
michael@0 58 PKIX_Boolean cmpResult;
michael@0 59 PKIX_ResourceLimits *firstRLimits = NULL;
michael@0 60 PKIX_ResourceLimits *secondRLimits = NULL;
michael@0 61
michael@0 62 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Equals");
michael@0 63 PKIX_NULLCHECK_THREE(first, second, pResult);
michael@0 64
michael@0 65 PKIX_CHECK(pkix_CheckType(first, PKIX_RESOURCELIMITS_TYPE, plContext),
michael@0 66 PKIX_FIRSTOBJECTNOTRESOURCELIMITS);
michael@0 67
michael@0 68 PKIX_CHECK(PKIX_PL_Object_GetType(second, &secondType, plContext),
michael@0 69 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT);
michael@0 70
michael@0 71 *pResult = PKIX_FALSE;
michael@0 72
michael@0 73 if (secondType != PKIX_RESOURCELIMITS_TYPE) goto cleanup;
michael@0 74
michael@0 75 firstRLimits = (PKIX_ResourceLimits *)first;
michael@0 76 secondRLimits = (PKIX_ResourceLimits *)second;
michael@0 77
michael@0 78 cmpResult = (firstRLimits->maxTime == secondRLimits->maxTime) &&
michael@0 79 (firstRLimits->maxFanout == secondRLimits->maxFanout) &&
michael@0 80 (firstRLimits->maxDepth == secondRLimits->maxDepth) &&
michael@0 81 (firstRLimits->maxCertsNumber ==
michael@0 82 secondRLimits->maxCertsNumber) &&
michael@0 83 (firstRLimits->maxCrlsNumber ==
michael@0 84 secondRLimits->maxCrlsNumber);
michael@0 85
michael@0 86 *pResult = cmpResult;
michael@0 87
michael@0 88 cleanup:
michael@0 89
michael@0 90 PKIX_RETURN(RESOURCELIMITS);
michael@0 91 }
michael@0 92
michael@0 93 /*
michael@0 94 * FUNCTION: pkix_ResourceLimits_Hashcode
michael@0 95 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h)
michael@0 96 */
michael@0 97 static PKIX_Error *
michael@0 98 pkix_ResourceLimits_Hashcode(
michael@0 99 PKIX_PL_Object *object,
michael@0 100 PKIX_UInt32 *pHashcode,
michael@0 101 void *plContext)
michael@0 102 {
michael@0 103 PKIX_ResourceLimits *rLimits = NULL;
michael@0 104 PKIX_UInt32 hash = 0;
michael@0 105
michael@0 106 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Hashcode");
michael@0 107 PKIX_NULLCHECK_TWO(object, pHashcode);
michael@0 108
michael@0 109 PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext),
michael@0 110 PKIX_OBJECTNOTRESOURCELIMITS);
michael@0 111
michael@0 112 rLimits = (PKIX_ResourceLimits*)object;
michael@0 113
michael@0 114 hash = 31 * rLimits->maxTime + (rLimits->maxFanout << 1) +
michael@0 115 (rLimits->maxDepth << 2) + (rLimits->maxCertsNumber << 3) +
michael@0 116 rLimits->maxCrlsNumber;
michael@0 117
michael@0 118 *pHashcode = hash;
michael@0 119
michael@0 120 cleanup:
michael@0 121
michael@0 122 PKIX_RETURN(RESOURCELIMITS);
michael@0 123 }
michael@0 124
michael@0 125 /*
michael@0 126 * FUNCTION: pkix_ResourceLimits_ToString
michael@0 127 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h)
michael@0 128 */
michael@0 129 static PKIX_Error *
michael@0 130 pkix_ResourceLimits_ToString(
michael@0 131 PKIX_PL_Object *object,
michael@0 132 PKIX_PL_String **pString,
michael@0 133 void *plContext)
michael@0 134 {
michael@0 135 PKIX_ResourceLimits *rLimits = NULL;
michael@0 136 char *asciiFormat = NULL;
michael@0 137 PKIX_PL_String *formatString = NULL;
michael@0 138 PKIX_PL_String *rLimitsString = NULL;
michael@0 139
michael@0 140 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_ToString");
michael@0 141 PKIX_NULLCHECK_TWO(object, pString);
michael@0 142
michael@0 143 PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext),
michael@0 144 PKIX_OBJECTNOTRESOURCELIMITS);
michael@0 145
michael@0 146 /* maxCertsNumber and maxCrlsNumber are not supported */
michael@0 147 asciiFormat =
michael@0 148 "[\n"
michael@0 149 "\tMaxTime: \t\t%d\n"
michael@0 150 "\tMaxFanout: \t\t%d\n"
michael@0 151 "\tMaxDepth: \t\t%d\n"
michael@0 152 "]\n";
michael@0 153
michael@0 154 PKIX_CHECK(PKIX_PL_String_Create
michael@0 155 (PKIX_ESCASCII,
michael@0 156 asciiFormat,
michael@0 157 0,
michael@0 158 &formatString,
michael@0 159 plContext),
michael@0 160 PKIX_STRINGCREATEFAILED);
michael@0 161
michael@0 162 rLimits = (PKIX_ResourceLimits*)object;
michael@0 163
michael@0 164 PKIX_CHECK(PKIX_PL_Sprintf
michael@0 165 (&rLimitsString,
michael@0 166 plContext,
michael@0 167 formatString,
michael@0 168 rLimits->maxTime,
michael@0 169 rLimits->maxFanout,
michael@0 170 rLimits->maxDepth),
michael@0 171 PKIX_SPRINTFFAILED);
michael@0 172
michael@0 173 *pString = rLimitsString;
michael@0 174
michael@0 175 cleanup:
michael@0 176
michael@0 177 PKIX_DECREF(formatString);
michael@0 178
michael@0 179 PKIX_RETURN(RESOURCELIMITS);
michael@0 180 }
michael@0 181
michael@0 182 /*
michael@0 183 * FUNCTION: pkix_ResourceLimits_RegisterSelf
michael@0 184 * DESCRIPTION:
michael@0 185 * Registers PKIX_RESOURCELIMITS_TYPE and its related functions with
michael@0 186 * systemClasses[]
michael@0 187 * THREAD SAFETY:
michael@0 188 * Not Thread Safe - for performance and complexity reasons
michael@0 189 *
michael@0 190 * Since this function is only called by PKIX_PL_Initialize, which should
michael@0 191 * only be called once, it is acceptable that this function is not
michael@0 192 * thread-safe.
michael@0 193 */
michael@0 194 PKIX_Error *
michael@0 195 pkix_ResourceLimits_RegisterSelf(void *plContext)
michael@0 196 {
michael@0 197
michael@0 198 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
michael@0 199 pkix_ClassTable_Entry entry;
michael@0 200
michael@0 201 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_RegisterSelf");
michael@0 202
michael@0 203 entry.description = "ResourceLimits";
michael@0 204 entry.objCounter = 0;
michael@0 205 entry.typeObjectSize = sizeof(PKIX_ResourceLimits);
michael@0 206 entry.destructor = pkix_ResourceLimits_Destroy;
michael@0 207 entry.equalsFunction = pkix_ResourceLimits_Equals;
michael@0 208 entry.hashcodeFunction = pkix_ResourceLimits_Hashcode;
michael@0 209 entry.toStringFunction = pkix_ResourceLimits_ToString;
michael@0 210 entry.comparator = NULL;
michael@0 211 entry.duplicateFunction = NULL;
michael@0 212
michael@0 213 systemClasses[PKIX_RESOURCELIMITS_TYPE] = entry;
michael@0 214
michael@0 215 PKIX_RETURN(RESOURCELIMITS);
michael@0 216 }
michael@0 217
michael@0 218 /* --Public-Functions--------------------------------------------- */
michael@0 219
michael@0 220 /*
michael@0 221 * FUNCTION: PKIX_ResourceLimits_Create (see comments in pkix_params.h)
michael@0 222 */
michael@0 223 PKIX_Error *
michael@0 224 PKIX_ResourceLimits_Create(
michael@0 225 PKIX_ResourceLimits **pResourceLimits,
michael@0 226 void *plContext)
michael@0 227 {
michael@0 228 PKIX_ResourceLimits *rLimits = NULL;
michael@0 229
michael@0 230 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_Create");
michael@0 231 PKIX_NULLCHECK_ONE(pResourceLimits);
michael@0 232
michael@0 233 PKIX_CHECK(PKIX_PL_Object_Alloc
michael@0 234 (PKIX_RESOURCELIMITS_TYPE,
michael@0 235 sizeof (PKIX_ResourceLimits),
michael@0 236 (PKIX_PL_Object **)&rLimits,
michael@0 237 plContext),
michael@0 238 PKIX_COULDNOTCREATERESOURCELIMITOBJECT);
michael@0 239
michael@0 240 /* initialize fields */
michael@0 241 rLimits->maxTime = 0;
michael@0 242 rLimits->maxFanout = 0;
michael@0 243 rLimits->maxDepth = 0;
michael@0 244 rLimits->maxCertsNumber = 0;
michael@0 245 rLimits->maxCrlsNumber = 0;
michael@0 246
michael@0 247 *pResourceLimits = rLimits;
michael@0 248
michael@0 249 cleanup:
michael@0 250
michael@0 251 PKIX_RETURN(RESOURCELIMITS);
michael@0 252
michael@0 253 }
michael@0 254
michael@0 255 /*
michael@0 256 * FUNCTION: PKIX_ResourceLimits_GetMaxTime
michael@0 257 * (see comments in pkix_params.h)
michael@0 258 */
michael@0 259 PKIX_Error *
michael@0 260 PKIX_ResourceLimits_GetMaxTime(
michael@0 261 PKIX_ResourceLimits *rLimits,
michael@0 262 PKIX_UInt32 *pMaxTime,
michael@0 263 void *plContext)
michael@0 264 {
michael@0 265 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxTime");
michael@0 266 PKIX_NULLCHECK_TWO(rLimits, pMaxTime);
michael@0 267
michael@0 268 *pMaxTime = rLimits->maxTime;
michael@0 269
michael@0 270 PKIX_RETURN(RESOURCELIMITS);
michael@0 271 }
michael@0 272
michael@0 273 /*
michael@0 274 * FUNCTION: PKIX_ResourceLimits_SetMaxTime
michael@0 275 * (see comments in pkix_params.h)
michael@0 276 */
michael@0 277 PKIX_Error *
michael@0 278 PKIX_ResourceLimits_SetMaxTime(
michael@0 279 PKIX_ResourceLimits *rLimits,
michael@0 280 PKIX_UInt32 maxTime,
michael@0 281 void *plContext)
michael@0 282 {
michael@0 283 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxTime");
michael@0 284 PKIX_NULLCHECK_ONE(rLimits);
michael@0 285
michael@0 286 rLimits->maxTime = maxTime;
michael@0 287
michael@0 288 PKIX_RETURN(RESOURCELIMITS);
michael@0 289 }
michael@0 290
michael@0 291 /*
michael@0 292 * FUNCTION: PKIX_ResourceLimits_GetMaxFanout
michael@0 293 * (see comments in pkix_params.h)
michael@0 294 */
michael@0 295 PKIX_Error *
michael@0 296 PKIX_ResourceLimits_GetMaxFanout(
michael@0 297 PKIX_ResourceLimits *rLimits,
michael@0 298 PKIX_UInt32 *pMaxFanout,
michael@0 299 void *plContext)
michael@0 300 {
michael@0 301 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxFanout");
michael@0 302 PKIX_NULLCHECK_TWO(rLimits, pMaxFanout);
michael@0 303
michael@0 304 *pMaxFanout = rLimits->maxFanout;
michael@0 305
michael@0 306 PKIX_RETURN(RESOURCELIMITS);
michael@0 307 }
michael@0 308
michael@0 309 /*
michael@0 310 * FUNCTION: PKIX_ResourceLimits_SetMaxFanout
michael@0 311 * (see comments in pkix_params.h)
michael@0 312 */
michael@0 313 PKIX_Error *
michael@0 314 PKIX_ResourceLimits_SetMaxFanout(
michael@0 315 PKIX_ResourceLimits *rLimits,
michael@0 316 PKIX_UInt32 maxFanout,
michael@0 317 void *plContext)
michael@0 318 {
michael@0 319 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxFanout");
michael@0 320 PKIX_NULLCHECK_ONE(rLimits);
michael@0 321
michael@0 322 rLimits->maxFanout = maxFanout;
michael@0 323
michael@0 324 PKIX_RETURN(RESOURCELIMITS);
michael@0 325 }
michael@0 326
michael@0 327 /*
michael@0 328 * FUNCTION: PKIX_ResourceLimits_GetMaxDepth
michael@0 329 * (see comments in pkix_params.h)
michael@0 330 */
michael@0 331 PKIX_Error *
michael@0 332 PKIX_ResourceLimits_GetMaxDepth(
michael@0 333 PKIX_ResourceLimits *rLimits,
michael@0 334 PKIX_UInt32 *pMaxDepth,
michael@0 335 void *plContext)
michael@0 336 {
michael@0 337 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxDepth");
michael@0 338 PKIX_NULLCHECK_TWO(rLimits, pMaxDepth);
michael@0 339
michael@0 340 *pMaxDepth = rLimits->maxDepth;
michael@0 341
michael@0 342 PKIX_RETURN(RESOURCELIMITS);
michael@0 343 }
michael@0 344
michael@0 345 /*
michael@0 346 * FUNCTION: PKIX_ResourceLimits_SetMaxDepth
michael@0 347 * (see comments in pkix_params.h)
michael@0 348 */
michael@0 349 PKIX_Error *
michael@0 350 PKIX_ResourceLimits_SetMaxDepth(
michael@0 351 PKIX_ResourceLimits *rLimits,
michael@0 352 PKIX_UInt32 maxDepth,
michael@0 353 void *plContext)
michael@0 354 {
michael@0 355 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxDepth");
michael@0 356 PKIX_NULLCHECK_ONE(rLimits);
michael@0 357
michael@0 358 rLimits->maxDepth = maxDepth;
michael@0 359
michael@0 360 PKIX_RETURN(RESOURCELIMITS);
michael@0 361 }
michael@0 362
michael@0 363 /*
michael@0 364 * FUNCTION: PKIX_ResourceLimits_GetMaxNumberOfCerts
michael@0 365 * (see comments in pkix_params.h)
michael@0 366 */
michael@0 367 PKIX_Error *
michael@0 368 PKIX_ResourceLimits_GetMaxNumberOfCerts(
michael@0 369 PKIX_ResourceLimits *rLimits,
michael@0 370 PKIX_UInt32 *pMaxNumber,
michael@0 371 void *plContext)
michael@0 372 {
michael@0 373 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxNumberOfCerts");
michael@0 374 PKIX_NULLCHECK_TWO(rLimits, pMaxNumber);
michael@0 375
michael@0 376 *pMaxNumber = rLimits->maxCertsNumber;
michael@0 377
michael@0 378 PKIX_RETURN(RESOURCELIMITS);
michael@0 379 }
michael@0 380
michael@0 381 /*
michael@0 382 * FUNCTION: PKIX_ResourceLimits_SetMaxNumberOfCerts
michael@0 383 * (see comments in pkix_params.h)
michael@0 384 */
michael@0 385 PKIX_Error *
michael@0 386 PKIX_ResourceLimits_SetMaxNumberOfCerts(
michael@0 387 PKIX_ResourceLimits *rLimits,
michael@0 388 PKIX_UInt32 maxNumber,
michael@0 389 void *plContext)
michael@0 390 {
michael@0 391 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxNumberOfCerts");
michael@0 392 PKIX_NULLCHECK_ONE(rLimits);
michael@0 393
michael@0 394 rLimits->maxCertsNumber = maxNumber;
michael@0 395
michael@0 396 PKIX_RETURN(RESOURCELIMITS);
michael@0 397 }
michael@0 398
michael@0 399 /*
michael@0 400 * FUNCTION: PKIX_ResourceLimits_GetMaxNumberOfCRLs
michael@0 401 * (see comments in pkix_params.h)
michael@0 402 */
michael@0 403 PKIX_Error *
michael@0 404 PKIX_ResourceLimits_GetMaxNumberOfCRLs(
michael@0 405 PKIX_ResourceLimits *rLimits,
michael@0 406 PKIX_UInt32 *pMaxNumber,
michael@0 407 void *plContext)
michael@0 408 {
michael@0 409 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_GetMaxNumberOfCRLs");
michael@0 410 PKIX_NULLCHECK_TWO(rLimits, pMaxNumber);
michael@0 411
michael@0 412 *pMaxNumber = rLimits->maxCrlsNumber;
michael@0 413
michael@0 414 PKIX_RETURN(RESOURCELIMITS);
michael@0 415 }
michael@0 416
michael@0 417 /*
michael@0 418 * FUNCTION: PKIX_ResourceLimits_SetMaxNumberOfCRLs
michael@0 419 * (see comments in pkix_params.h)
michael@0 420 */
michael@0 421 PKIX_Error *
michael@0 422 PKIX_ResourceLimits_SetMaxNumberOfCRLs(
michael@0 423 PKIX_ResourceLimits *rLimits,
michael@0 424 PKIX_UInt32 maxNumber,
michael@0 425 void *plContext)
michael@0 426 {
michael@0 427 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_SetMaxNumberOfCRLs");
michael@0 428 PKIX_NULLCHECK_ONE(rLimits);
michael@0 429
michael@0 430 rLimits->maxCrlsNumber = maxNumber;
michael@0 431
michael@0 432 PKIX_RETURN(RESOURCELIMITS);
michael@0 433 }

mercurial