PageRenderTime 42ms CodeModel.GetById 16ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

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