|
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 */ |
|
10 |
|
11 #include "pkix_resourcelimits.h" |
|
12 |
|
13 /* --Private-Functions-------------------------------------------- */ |
|
14 |
|
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; |
|
25 |
|
26 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Destroy"); |
|
27 PKIX_NULLCHECK_ONE(object); |
|
28 |
|
29 /* Check that this object is a ResourceLimits object */ |
|
30 PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), |
|
31 PKIX_OBJECTNOTRESOURCELIMITS); |
|
32 |
|
33 rLimits = (PKIX_ResourceLimits *)object; |
|
34 |
|
35 rLimits->maxTime = 0; |
|
36 rLimits->maxFanout = 0; |
|
37 rLimits->maxDepth = 0; |
|
38 rLimits->maxCertsNumber = 0; |
|
39 rLimits->maxCrlsNumber = 0; |
|
40 |
|
41 cleanup: |
|
42 |
|
43 PKIX_RETURN(RESOURCELIMITS); |
|
44 } |
|
45 |
|
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; |
|
61 |
|
62 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Equals"); |
|
63 PKIX_NULLCHECK_THREE(first, second, pResult); |
|
64 |
|
65 PKIX_CHECK(pkix_CheckType(first, PKIX_RESOURCELIMITS_TYPE, plContext), |
|
66 PKIX_FIRSTOBJECTNOTRESOURCELIMITS); |
|
67 |
|
68 PKIX_CHECK(PKIX_PL_Object_GetType(second, &secondType, plContext), |
|
69 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); |
|
70 |
|
71 *pResult = PKIX_FALSE; |
|
72 |
|
73 if (secondType != PKIX_RESOURCELIMITS_TYPE) goto cleanup; |
|
74 |
|
75 firstRLimits = (PKIX_ResourceLimits *)first; |
|
76 secondRLimits = (PKIX_ResourceLimits *)second; |
|
77 |
|
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); |
|
85 |
|
86 *pResult = cmpResult; |
|
87 |
|
88 cleanup: |
|
89 |
|
90 PKIX_RETURN(RESOURCELIMITS); |
|
91 } |
|
92 |
|
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; |
|
105 |
|
106 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_Hashcode"); |
|
107 PKIX_NULLCHECK_TWO(object, pHashcode); |
|
108 |
|
109 PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), |
|
110 PKIX_OBJECTNOTRESOURCELIMITS); |
|
111 |
|
112 rLimits = (PKIX_ResourceLimits*)object; |
|
113 |
|
114 hash = 31 * rLimits->maxTime + (rLimits->maxFanout << 1) + |
|
115 (rLimits->maxDepth << 2) + (rLimits->maxCertsNumber << 3) + |
|
116 rLimits->maxCrlsNumber; |
|
117 |
|
118 *pHashcode = hash; |
|
119 |
|
120 cleanup: |
|
121 |
|
122 PKIX_RETURN(RESOURCELIMITS); |
|
123 } |
|
124 |
|
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; |
|
139 |
|
140 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_ToString"); |
|
141 PKIX_NULLCHECK_TWO(object, pString); |
|
142 |
|
143 PKIX_CHECK(pkix_CheckType(object, PKIX_RESOURCELIMITS_TYPE, plContext), |
|
144 PKIX_OBJECTNOTRESOURCELIMITS); |
|
145 |
|
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"; |
|
153 |
|
154 PKIX_CHECK(PKIX_PL_String_Create |
|
155 (PKIX_ESCASCII, |
|
156 asciiFormat, |
|
157 0, |
|
158 &formatString, |
|
159 plContext), |
|
160 PKIX_STRINGCREATEFAILED); |
|
161 |
|
162 rLimits = (PKIX_ResourceLimits*)object; |
|
163 |
|
164 PKIX_CHECK(PKIX_PL_Sprintf |
|
165 (&rLimitsString, |
|
166 plContext, |
|
167 formatString, |
|
168 rLimits->maxTime, |
|
169 rLimits->maxFanout, |
|
170 rLimits->maxDepth), |
|
171 PKIX_SPRINTFFAILED); |
|
172 |
|
173 *pString = rLimitsString; |
|
174 |
|
175 cleanup: |
|
176 |
|
177 PKIX_DECREF(formatString); |
|
178 |
|
179 PKIX_RETURN(RESOURCELIMITS); |
|
180 } |
|
181 |
|
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 { |
|
197 |
|
198 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; |
|
199 pkix_ClassTable_Entry entry; |
|
200 |
|
201 PKIX_ENTER(RESOURCELIMITS, "pkix_ResourceLimits_RegisterSelf"); |
|
202 |
|
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; |
|
212 |
|
213 systemClasses[PKIX_RESOURCELIMITS_TYPE] = entry; |
|
214 |
|
215 PKIX_RETURN(RESOURCELIMITS); |
|
216 } |
|
217 |
|
218 /* --Public-Functions--------------------------------------------- */ |
|
219 |
|
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; |
|
229 |
|
230 PKIX_ENTER(RESOURCELIMITS, "PKIX_ResourceLimits_Create"); |
|
231 PKIX_NULLCHECK_ONE(pResourceLimits); |
|
232 |
|
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); |
|
239 |
|
240 /* initialize fields */ |
|
241 rLimits->maxTime = 0; |
|
242 rLimits->maxFanout = 0; |
|
243 rLimits->maxDepth = 0; |
|
244 rLimits->maxCertsNumber = 0; |
|
245 rLimits->maxCrlsNumber = 0; |
|
246 |
|
247 *pResourceLimits = rLimits; |
|
248 |
|
249 cleanup: |
|
250 |
|
251 PKIX_RETURN(RESOURCELIMITS); |
|
252 |
|
253 } |
|
254 |
|
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); |
|
267 |
|
268 *pMaxTime = rLimits->maxTime; |
|
269 |
|
270 PKIX_RETURN(RESOURCELIMITS); |
|
271 } |
|
272 |
|
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); |
|
285 |
|
286 rLimits->maxTime = maxTime; |
|
287 |
|
288 PKIX_RETURN(RESOURCELIMITS); |
|
289 } |
|
290 |
|
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); |
|
303 |
|
304 *pMaxFanout = rLimits->maxFanout; |
|
305 |
|
306 PKIX_RETURN(RESOURCELIMITS); |
|
307 } |
|
308 |
|
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); |
|
321 |
|
322 rLimits->maxFanout = maxFanout; |
|
323 |
|
324 PKIX_RETURN(RESOURCELIMITS); |
|
325 } |
|
326 |
|
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); |
|
339 |
|
340 *pMaxDepth = rLimits->maxDepth; |
|
341 |
|
342 PKIX_RETURN(RESOURCELIMITS); |
|
343 } |
|
344 |
|
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); |
|
357 |
|
358 rLimits->maxDepth = maxDepth; |
|
359 |
|
360 PKIX_RETURN(RESOURCELIMITS); |
|
361 } |
|
362 |
|
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); |
|
375 |
|
376 *pMaxNumber = rLimits->maxCertsNumber; |
|
377 |
|
378 PKIX_RETURN(RESOURCELIMITS); |
|
379 } |
|
380 |
|
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); |
|
393 |
|
394 rLimits->maxCertsNumber = maxNumber; |
|
395 |
|
396 PKIX_RETURN(RESOURCELIMITS); |
|
397 } |
|
398 |
|
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); |
|
411 |
|
412 *pMaxNumber = rLimits->maxCrlsNumber; |
|
413 |
|
414 PKIX_RETURN(RESOURCELIMITS); |
|
415 } |
|
416 |
|
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); |
|
429 |
|
430 rLimits->maxCrlsNumber = maxNumber; |
|
431 |
|
432 PKIX_RETURN(RESOURCELIMITS); |
|
433 } |