PageRenderTime 32ms CodeModel.GetById 19ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 44#define PKIX_STDVARS_POINTER
 45#include "pkix_error.h"
 46
 47const PKIX_StdVars zeroStdVars;
 48
 49PKIX_Error*
 50PKIX_DoThrow(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass, 
 51             PKIX_ERRORCODE errCode, PKIX_ERRORCLASS overrideClass,
 52             void *plContext)
 53{
 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);
 62    }
 63    if (pkixReturnResult) {
 64        if (pkixErrorResult != PKIX_ALLOC_ERROR()) {
 65            PKIX_DECREF(pkixErrorResult);
 66        }
 67        pkixTempResult = pkixReturnResult;
 68    } else if (pkixErrorResult) {
 69        if (pkixTempResult != PKIX_ALLOC_ERROR()) {
 70            PKIX_DECREF(pkixTempResult);
 71        }
 72        pkixTempResult = pkixErrorResult;
 73    }
 74    if (pkixErrorList) {
 75        PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixErrorList, plContext);
 76        pkixErrorList = NULL;
 77    }
 78    return pkixTempResult;
 79}
 80
 81PKIX_Error *
 82PKIX_DoReturn(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass,
 83              PKIX_Boolean doLogger, void *plContext)
 84{
 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;
 93}
 94
 95/* PKIX_DoAddError - creates the list of received error if it does not exist
 96 * yet and adds newly received error into the list. */
 97void
 98PKIX_DoAddError(PKIX_StdVars *stdVars, PKIX_Error *error, void * plContext)
 99{
100    PKIX_List *localList = NULL;
101    PKIX_Error *localError = NULL;
102    PKIX_Boolean listCreated = PKIX_FALSE;
103
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;
111    }
112
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;
121        }
122    } else {
123        pkixErrorList = localList;
124    }
125
126cleanup:
127
128    if (localError && localError != PKIX_ALLOC_ERROR()) {
129        PKIX_PL_Object_DecRef((PKIX_PL_Object*)localError, plContext);
130    }
131
132    if (error && error != PKIX_ALLOC_ERROR()) {
133        PKIX_PL_Object_DecRef((PKIX_PL_Object*)error, plContext);
134    }
135}
136