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