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

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

mercurial