/security/nss/lib/libpkix/pkix/util/pkix_errpaths.c

http://github.com/zpao/v8monkey · C · 136 lines · 79 code · 11 blank · 46 comment · 30 complexity · daaf716a460b1fc335f8f6bb627f68a7 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_errpaths.c
  39. *
  40. * Error Handling Helper Functions
  41. *
  42. */
  43. #define PKIX_STDVARS_POINTER
  44. #include "pkix_error.h"
  45. const PKIX_StdVars zeroStdVars;
  46. PKIX_Error*
  47. PKIX_DoThrow(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass,
  48. PKIX_ERRORCODE errCode, PKIX_ERRORCLASS overrideClass,
  49. void *plContext)
  50. {
  51. if (!pkixErrorReceived && !pkixErrorResult && pkixErrorList) {
  52. pkixTempResult = PKIX_List_GetItem(pkixErrorList, 0,
  53. (PKIX_PL_Object**)&pkixReturnResult,
  54. plContext);
  55. } else {
  56. pkixTempResult = (PKIX_Error*)pkix_Throw(errClass, myFuncName, errCode,
  57. overrideClass, pkixErrorResult,
  58. &pkixReturnResult, plContext);
  59. }
  60. if (pkixReturnResult) {
  61. if (pkixErrorResult != PKIX_ALLOC_ERROR()) {
  62. PKIX_DECREF(pkixErrorResult);
  63. }
  64. pkixTempResult = pkixReturnResult;
  65. } else if (pkixErrorResult) {
  66. if (pkixTempResult != PKIX_ALLOC_ERROR()) {
  67. PKIX_DECREF(pkixTempResult);
  68. }
  69. pkixTempResult = pkixErrorResult;
  70. }
  71. if (pkixErrorList) {
  72. PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixErrorList, plContext);
  73. pkixErrorList = NULL;
  74. }
  75. return pkixTempResult;
  76. }
  77. PKIX_Error *
  78. PKIX_DoReturn(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass,
  79. PKIX_Boolean doLogger, void *plContext)
  80. {
  81. PKIX_OBJECT_UNLOCK(lockedObject);
  82. if (pkixErrorReceived || pkixErrorResult || pkixErrorList)
  83. return PKIX_DoThrow(stdVars, errClass, pkixErrorCode, pkixErrorClass,
  84. plContext);
  85. /* PKIX_DEBUG_EXIT(type); */
  86. if (doLogger)
  87. _PKIX_DEBUG_TRACE(pkixLoggersDebugTrace, "<<<", PKIX_LOGGER_LEVEL_TRACE);
  88. return NULL;
  89. }
  90. /* PKIX_DoAddError - creates the list of received error if it does not exist
  91. * yet and adds newly received error into the list. */
  92. void
  93. PKIX_DoAddError(PKIX_StdVars *stdVars, PKIX_Error *error, void * plContext)
  94. {
  95. PKIX_List *localList = NULL;
  96. PKIX_Error *localError = NULL;
  97. PKIX_Boolean listCreated = PKIX_FALSE;
  98. if (!pkixErrorList) {
  99. localError = PKIX_List_Create(&localList, plContext);
  100. if (localError)
  101. goto cleanup;
  102. listCreated = PKIX_TRUE;
  103. } else {
  104. localList = pkixErrorList;
  105. }
  106. localError = PKIX_List_AppendItem(localList, (PKIX_PL_Object*)error,
  107. plContext);
  108. PORT_Assert (localError == NULL);
  109. if (localError != NULL) {
  110. if (listCreated) {
  111. /* ignore the error code of DecRef function */
  112. PKIX_PL_Object_DecRef((PKIX_PL_Object*)localList, plContext);
  113. localList = NULL;
  114. }
  115. } else {
  116. pkixErrorList = localList;
  117. }
  118. cleanup:
  119. if (localError && localError != PKIX_ALLOC_ERROR()) {
  120. PKIX_PL_Object_DecRef((PKIX_PL_Object*)localError, plContext);
  121. }
  122. if (error && error != PKIX_ALLOC_ERROR()) {
  123. PKIX_PL_Object_DecRef((PKIX_PL_Object*)error, plContext);
  124. }
  125. }