andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * pkix_errpaths.c andre@0: * andre@0: * Error Handling Helper Functions andre@0: * andre@0: */ andre@0: andre@0: #define PKIX_STDVARS_POINTER andre@0: #include "pkix_error.h" andre@0: andre@0: const PKIX_StdVars zeroStdVars; andre@0: andre@0: PKIX_Error* andre@0: PKIX_DoThrow(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass, andre@0: PKIX_ERRORCODE errCode, PKIX_ERRORCLASS overrideClass, andre@0: void *plContext) andre@0: { andre@0: if (!pkixErrorReceived && !pkixErrorResult && pkixErrorList) { andre@0: pkixTempResult = PKIX_List_GetItem(pkixErrorList, 0, andre@0: (PKIX_PL_Object**)&pkixReturnResult, andre@0: plContext); andre@0: } else { andre@0: pkixTempResult = (PKIX_Error*)pkix_Throw(errClass, myFuncName, errCode, andre@0: overrideClass, pkixErrorResult, andre@0: &pkixReturnResult, plContext); andre@0: } andre@0: if (pkixReturnResult) { andre@0: if (pkixErrorResult != PKIX_ALLOC_ERROR()) { andre@0: PKIX_DECREF(pkixErrorResult); andre@0: } andre@0: pkixTempResult = pkixReturnResult; andre@0: } else if (pkixErrorResult) { andre@0: if (pkixTempResult != PKIX_ALLOC_ERROR()) { andre@0: PKIX_DECREF(pkixTempResult); andre@0: } andre@0: pkixTempResult = pkixErrorResult; andre@0: } andre@0: if (pkixErrorList) { andre@0: PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixErrorList, plContext); andre@0: pkixErrorList = NULL; andre@0: } andre@0: return pkixTempResult; andre@0: } andre@0: andre@0: PKIX_Error * andre@0: PKIX_DoReturn(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass, andre@0: PKIX_Boolean doLogger, void *plContext) andre@0: { andre@0: PKIX_OBJECT_UNLOCK(lockedObject); andre@0: if (pkixErrorReceived || pkixErrorResult || pkixErrorList) andre@0: return PKIX_DoThrow(stdVars, errClass, pkixErrorCode, pkixErrorClass, andre@0: plContext); andre@0: /* PKIX_DEBUG_EXIT(type); */ andre@0: if (doLogger) andre@0: _PKIX_DEBUG_TRACE(pkixLoggersDebugTrace, "<<<", PKIX_LOGGER_LEVEL_TRACE); andre@0: return NULL; andre@0: } andre@0: andre@0: /* PKIX_DoAddError - creates the list of received error if it does not exist andre@0: * yet and adds newly received error into the list. */ andre@0: void andre@0: PKIX_DoAddError(PKIX_StdVars *stdVars, PKIX_Error *error, void * plContext) andre@0: { andre@0: PKIX_List *localList = NULL; andre@0: PKIX_Error *localError = NULL; andre@0: PKIX_Boolean listCreated = PKIX_FALSE; andre@0: andre@0: if (!pkixErrorList) { andre@0: localError = PKIX_List_Create(&localList, plContext); andre@0: if (localError) andre@0: goto cleanup; andre@0: listCreated = PKIX_TRUE; andre@0: } else { andre@0: localList = pkixErrorList; andre@0: } andre@0: andre@0: localError = PKIX_List_AppendItem(localList, (PKIX_PL_Object*)error, andre@0: plContext); andre@0: PORT_Assert (localError == NULL); andre@0: if (localError != NULL) { andre@0: if (listCreated) { andre@0: /* ignore the error code of DecRef function */ andre@0: PKIX_PL_Object_DecRef((PKIX_PL_Object*)localList, plContext); andre@0: localList = NULL; andre@0: } andre@0: } else { andre@0: pkixErrorList = localList; andre@0: } andre@0: andre@0: cleanup: andre@0: andre@0: if (localError && localError != PKIX_ALLOC_ERROR()) { andre@0: PKIX_PL_Object_DecRef((PKIX_PL_Object*)localError, plContext); andre@0: } andre@0: andre@0: if (error && error != PKIX_ALLOC_ERROR()) { andre@0: PKIX_PL_Object_DecRef((PKIX_PL_Object*)error, plContext); andre@0: } andre@0: } andre@0: