Import 1.9b4 NSS tag from cvs
[mozilla-nss.git] / security / nss / lib / libpkix / pkix / util / pkix_errpaths.c
blob56bb759a4e986633e64f1503c1b3a525463e5d98
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 * The Original Code is the PKIX-C library.
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.
21 * Contributor(s):
22 * Sun Microsystems, Inc.
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.
36 * ***** END LICENSE BLOCK ***** */
38 * pkix_errpaths.c
40 * Error Handling Helper Functions
44 #define PKIX_STDVARS_POINTER
45 #include "pkix_error.h"
47 const PKIX_StdVars zeroStdVars;
49 PKIX_Error*
50 PKIX_DoThrow(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass,
51 PKIX_ERRORCODE errCode, PKIX_ERRORCLASS overrideClass,
52 void *plContext)
54 if (!pkixErrorReceived && !pkixErrorResult && pkixErrorList) {
55 pkixTempResult = PKIX_List_GetItem(pkixErrorList, 0,
56 (PKIX_PL_Object**)&pkixReturnResult,
57 plContext);
58 } else {
59 pkixTempResult = (PKIX_Error*)pkix_Throw(errClass, myFuncName, errCode,
60 overrideClass, pkixErrorResult,
61 &pkixReturnResult, plContext);
63 if (pkixReturnResult) {
64 if (pkixErrorResult != PKIX_ALLOC_ERROR()) {
65 PKIX_DECREF(pkixErrorResult);
67 pkixTempResult = pkixReturnResult;
68 } else if (pkixErrorResult) {
69 if (pkixTempResult != PKIX_ALLOC_ERROR()) {
70 PKIX_DECREF(pkixTempResult);
72 pkixTempResult = pkixErrorResult;
74 if (pkixErrorList) {
75 PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixErrorList, plContext);
76 pkixErrorList = NULL;
78 return pkixTempResult;
81 PKIX_Error *
82 PKIX_DoReturn(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass,
83 PKIX_Boolean doLogger, void *plContext)
85 PKIX_OBJECT_UNLOCK(lockedObject);
86 if (pkixErrorReceived || pkixErrorResult || pkixErrorList)
87 return PKIX_DoThrow(stdVars, errClass, pkixErrorCode, pkixErrorClass,
88 plContext);
89 /* PKIX_DEBUG_EXIT(type); */
90 if (doLogger)
91 _PKIX_DEBUG_TRACE(pkixLoggersDebugTrace, "<<<", PKIX_LOGGER_LEVEL_TRACE);
92 return NULL;
95 /* PKIX_DoAddError - creates the list of received error if it does not exist
96 * yet and adds newly received error into the list. */
97 void
98 PKIX_DoAddError(PKIX_StdVars *stdVars, PKIX_Error *error, void * plContext)
100 PKIX_List *localList = NULL;
101 PKIX_Error *localError = NULL;
102 PKIX_Boolean listCreated = PKIX_FALSE;
104 if (!pkixErrorList) {
105 localError = PKIX_List_Create(&localList, plContext);
106 if (localError)
107 goto cleanup;
108 listCreated = PKIX_TRUE;
109 } else {
110 localList = pkixErrorList;
113 localError = PKIX_List_AppendItem(localList, (PKIX_PL_Object*)error,
114 plContext);
115 PORT_Assert (localError == NULL);
116 if (localError != NULL) {
117 if (listCreated) {
118 /* ignore the error code of DecRef function */
119 PKIX_PL_Object_DecRef((PKIX_PL_Object*)localList, plContext);
120 localList = NULL;
122 } else {
123 pkixErrorList = localList;
126 cleanup:
128 if (localError && localError != PKIX_ALLOC_ERROR()) {
129 PKIX_PL_Object_DecRef((PKIX_PL_Object*)localError, plContext);
132 if (error && error != PKIX_ALLOC_ERROR()) {
133 PKIX_PL_Object_DecRef((PKIX_PL_Object*)error, plContext);