Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | /* |
michael@0 | 5 | * pkix_error.c |
michael@0 | 6 | * |
michael@0 | 7 | * Error Object Functions |
michael@0 | 8 | * |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "pkix_error.h" |
michael@0 | 12 | |
michael@0 | 13 | #undef PKIX_ERRORENTRY |
michael@0 | 14 | |
michael@0 | 15 | #define PKIX_ERRORENTRY(name,desc,nsserr) #desc |
michael@0 | 16 | |
michael@0 | 17 | #if defined PKIX_ERROR_DESCRIPTION |
michael@0 | 18 | |
michael@0 | 19 | const char * const PKIX_ErrorText[] = |
michael@0 | 20 | { |
michael@0 | 21 | #include "pkix_errorstrings.h" |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | #else |
michael@0 | 25 | |
michael@0 | 26 | #include "prprf.h" |
michael@0 | 27 | |
michael@0 | 28 | #endif /* PKIX_ERROR_DESCRIPTION */ |
michael@0 | 29 | |
michael@0 | 30 | extern const PKIX_Int32 PKIX_PLErrorIndex[]; |
michael@0 | 31 | |
michael@0 | 32 | /* --Private-Functions-------------------------------------------- */ |
michael@0 | 33 | |
michael@0 | 34 | /* |
michael@0 | 35 | * FUNCTION: pkix_Error_Equals |
michael@0 | 36 | * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) |
michael@0 | 37 | */ |
michael@0 | 38 | static PKIX_Error * |
michael@0 | 39 | pkix_Error_Equals( |
michael@0 | 40 | PKIX_PL_Object *firstObject, |
michael@0 | 41 | PKIX_PL_Object *secondObject, |
michael@0 | 42 | PKIX_Boolean *pResult, |
michael@0 | 43 | void *plContext) |
michael@0 | 44 | { |
michael@0 | 45 | PKIX_Error *firstError = NULL; |
michael@0 | 46 | PKIX_Error *secondError = NULL; |
michael@0 | 47 | PKIX_Error *firstCause = NULL; |
michael@0 | 48 | PKIX_Error *secondCause = NULL; |
michael@0 | 49 | PKIX_PL_Object *firstInfo = NULL; |
michael@0 | 50 | PKIX_PL_Object *secondInfo = NULL; |
michael@0 | 51 | PKIX_ERRORCLASS firstClass, secondClass; |
michael@0 | 52 | PKIX_UInt32 secondType; |
michael@0 | 53 | PKIX_Boolean boolResult, unequalFlag; |
michael@0 | 54 | |
michael@0 | 55 | PKIX_ENTER(ERROR, "pkix_Error_Equals"); |
michael@0 | 56 | PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); |
michael@0 | 57 | |
michael@0 | 58 | unequalFlag = PKIX_FALSE; |
michael@0 | 59 | |
michael@0 | 60 | /* First just compare pointer values to save time */ |
michael@0 | 61 | if (firstObject == secondObject) { |
michael@0 | 62 | *pResult = PKIX_TRUE; |
michael@0 | 63 | goto cleanup; |
michael@0 | 64 | } else { |
michael@0 | 65 | /* Result will only be set to true if all tests pass */ |
michael@0 | 66 | *pResult = PKIX_FALSE; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | PKIX_CHECK(pkix_CheckType(firstObject, PKIX_ERROR_TYPE, plContext), |
michael@0 | 70 | PKIX_FIRSTOBJECTNOTANERROROBJECT); |
michael@0 | 71 | |
michael@0 | 72 | PKIX_CHECK(PKIX_PL_Object_GetType |
michael@0 | 73 | (secondObject, &secondType, plContext), |
michael@0 | 74 | PKIX_ERRORGETTINGSECONDOBJECTTYPE); |
michael@0 | 75 | |
michael@0 | 76 | /* If types differ, then return false. Result is already set */ |
michael@0 | 77 | if (secondType != PKIX_ERROR_TYPE) goto cleanup; |
michael@0 | 78 | |
michael@0 | 79 | /* It is safe to cast to PKIX_Error */ |
michael@0 | 80 | firstError = (PKIX_Error *) firstObject; |
michael@0 | 81 | secondError = (PKIX_Error *) secondObject; |
michael@0 | 82 | |
michael@0 | 83 | /* Compare error codes */ |
michael@0 | 84 | firstClass = firstError->errClass; |
michael@0 | 85 | secondClass = secondError->errClass; |
michael@0 | 86 | |
michael@0 | 87 | /* If codes differ, return false. Result is already set */ |
michael@0 | 88 | if (firstClass != secondClass) goto cleanup; |
michael@0 | 89 | |
michael@0 | 90 | /* Compare causes */ |
michael@0 | 91 | firstCause = firstError->cause; |
michael@0 | 92 | secondCause = secondError->cause; |
michael@0 | 93 | |
michael@0 | 94 | /* Ensure that either both or none of the causes are NULL */ |
michael@0 | 95 | if (((firstCause != NULL) && (secondCause == NULL))|| |
michael@0 | 96 | ((firstCause == NULL) && (secondCause != NULL))) |
michael@0 | 97 | unequalFlag = PKIX_TRUE; |
michael@0 | 98 | |
michael@0 | 99 | if ((firstCause != NULL) && (secondCause != NULL)) { |
michael@0 | 100 | PKIX_CHECK(PKIX_PL_Object_Equals |
michael@0 | 101 | ((PKIX_PL_Object*)firstCause, |
michael@0 | 102 | (PKIX_PL_Object*)secondCause, |
michael@0 | 103 | &boolResult, |
michael@0 | 104 | plContext), |
michael@0 | 105 | PKIX_ERRORINRECURSIVEEQUALSCALL); |
michael@0 | 106 | |
michael@0 | 107 | /* Set the unequalFlag so that we return after dec refing */ |
michael@0 | 108 | if (boolResult == 0) unequalFlag = PKIX_TRUE; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | /* If the cause errors are not equal, return null */ |
michael@0 | 112 | if (unequalFlag) goto cleanup; |
michael@0 | 113 | |
michael@0 | 114 | /* Compare info fields */ |
michael@0 | 115 | firstInfo = firstError->info; |
michael@0 | 116 | secondInfo = secondError->info; |
michael@0 | 117 | |
michael@0 | 118 | if (firstInfo != secondInfo) goto cleanup; |
michael@0 | 119 | |
michael@0 | 120 | /* Ensure that either both or none of the infos are NULL */ |
michael@0 | 121 | if (((firstInfo != NULL) && (secondInfo == NULL))|| |
michael@0 | 122 | ((firstInfo == NULL) && (secondInfo != NULL))) |
michael@0 | 123 | unequalFlag = PKIX_TRUE; |
michael@0 | 124 | |
michael@0 | 125 | if ((firstInfo != NULL) && (secondInfo != NULL)) { |
michael@0 | 126 | |
michael@0 | 127 | PKIX_CHECK(PKIX_PL_Object_Equals |
michael@0 | 128 | ((PKIX_PL_Object*)firstInfo, |
michael@0 | 129 | (PKIX_PL_Object*)secondInfo, |
michael@0 | 130 | &boolResult, |
michael@0 | 131 | plContext), |
michael@0 | 132 | PKIX_ERRORINRECURSIVEEQUALSCALL); |
michael@0 | 133 | |
michael@0 | 134 | /* Set the unequalFlag so that we return after dec refing */ |
michael@0 | 135 | if (boolResult == 0) unequalFlag = PKIX_TRUE; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | /* If the infos are not equal, return null */ |
michael@0 | 139 | if (unequalFlag) goto cleanup; |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | /* Compare descs */ |
michael@0 | 143 | if (firstError->errCode != secondError->errCode) { |
michael@0 | 144 | unequalFlag = PKIX_TRUE; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | if (firstError->plErr != secondError->plErr) { |
michael@0 | 148 | unequalFlag = PKIX_TRUE; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | /* If the unequalFlag was set, return false */ |
michael@0 | 152 | if (unequalFlag) goto cleanup; |
michael@0 | 153 | |
michael@0 | 154 | /* Errors are equal in all fields at this point */ |
michael@0 | 155 | *pResult = PKIX_TRUE; |
michael@0 | 156 | |
michael@0 | 157 | cleanup: |
michael@0 | 158 | |
michael@0 | 159 | PKIX_RETURN(ERROR); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | /* |
michael@0 | 163 | * FUNCTION: pkix_Error_Destroy |
michael@0 | 164 | * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) |
michael@0 | 165 | */ |
michael@0 | 166 | static PKIX_Error * |
michael@0 | 167 | pkix_Error_Destroy( |
michael@0 | 168 | PKIX_PL_Object *object, |
michael@0 | 169 | void *plContext) |
michael@0 | 170 | { |
michael@0 | 171 | PKIX_Error *error = NULL; |
michael@0 | 172 | |
michael@0 | 173 | PKIX_ENTER(ERROR, "pkix_Error_Destroy"); |
michael@0 | 174 | PKIX_NULLCHECK_ONE(object); |
michael@0 | 175 | |
michael@0 | 176 | PKIX_CHECK(pkix_CheckType(object, PKIX_ERROR_TYPE, plContext), |
michael@0 | 177 | PKIX_OBJECTNOTANERROR); |
michael@0 | 178 | |
michael@0 | 179 | error = (PKIX_Error *)object; |
michael@0 | 180 | |
michael@0 | 181 | PKIX_DECREF(error->cause); |
michael@0 | 182 | |
michael@0 | 183 | PKIX_DECREF(error->info); |
michael@0 | 184 | |
michael@0 | 185 | cleanup: |
michael@0 | 186 | |
michael@0 | 187 | PKIX_RETURN(ERROR); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | |
michael@0 | 191 | /* XXX This is not thread safe */ |
michael@0 | 192 | static PKIX_UInt32 pkix_error_cause_depth = 1; |
michael@0 | 193 | |
michael@0 | 194 | /* |
michael@0 | 195 | * FUNCTION: pkix_Error_ToString |
michael@0 | 196 | * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) |
michael@0 | 197 | */ |
michael@0 | 198 | static PKIX_Error * |
michael@0 | 199 | pkix_Error_ToString( |
michael@0 | 200 | PKIX_PL_Object *object, |
michael@0 | 201 | PKIX_PL_String **pString, |
michael@0 | 202 | void *plContext) |
michael@0 | 203 | { |
michael@0 | 204 | PKIX_Error *error = NULL; |
michael@0 | 205 | PKIX_Error *cause = NULL; |
michael@0 | 206 | PKIX_PL_String *desc = NULL; |
michael@0 | 207 | PKIX_PL_String *formatString = NULL; |
michael@0 | 208 | PKIX_PL_String *causeString = NULL; |
michael@0 | 209 | PKIX_PL_String *optCauseString = NULL; |
michael@0 | 210 | PKIX_PL_String *errorNameString = NULL; |
michael@0 | 211 | char *format = NULL; |
michael@0 | 212 | PKIX_ERRORCLASS errClass; |
michael@0 | 213 | |
michael@0 | 214 | PKIX_ENTER(ERROR, "pkix_Error_ToString"); |
michael@0 | 215 | PKIX_NULLCHECK_TWO(object, pString); |
michael@0 | 216 | |
michael@0 | 217 | PKIX_CHECK(pkix_CheckType(object, PKIX_ERROR_TYPE, plContext), |
michael@0 | 218 | PKIX_OBJECTNOTANERROR); |
michael@0 | 219 | |
michael@0 | 220 | error = (PKIX_Error *)object; |
michael@0 | 221 | |
michael@0 | 222 | /* Get this error's errClass, description and the string of its cause */ |
michael@0 | 223 | errClass = error->errClass; |
michael@0 | 224 | |
michael@0 | 225 | /* Get the description string */ |
michael@0 | 226 | PKIX_Error_GetDescription(error, &desc, plContext); |
michael@0 | 227 | |
michael@0 | 228 | /* Get the cause */ |
michael@0 | 229 | cause = error->cause; |
michael@0 | 230 | |
michael@0 | 231 | /* Get the causes's description string */ |
michael@0 | 232 | if (cause != NULL) { |
michael@0 | 233 | pkix_error_cause_depth++; |
michael@0 | 234 | |
michael@0 | 235 | /* Get the cause string */ |
michael@0 | 236 | PKIX_CHECK(PKIX_PL_Object_ToString |
michael@0 | 237 | ((PKIX_PL_Object*)cause, &causeString, plContext), |
michael@0 | 238 | PKIX_ERRORGETTINGCAUSESTRING); |
michael@0 | 239 | |
michael@0 | 240 | format = "\n*** Cause (%d): %s"; |
michael@0 | 241 | |
michael@0 | 242 | PKIX_CHECK(PKIX_PL_String_Create |
michael@0 | 243 | (PKIX_ESCASCII, |
michael@0 | 244 | format, |
michael@0 | 245 | 0, |
michael@0 | 246 | &formatString, |
michael@0 | 247 | plContext), |
michael@0 | 248 | PKIX_STRINGCREATEFAILED); |
michael@0 | 249 | |
michael@0 | 250 | /* Create the optional Cause String */ |
michael@0 | 251 | PKIX_CHECK(PKIX_PL_Sprintf |
michael@0 | 252 | (&optCauseString, |
michael@0 | 253 | plContext, |
michael@0 | 254 | formatString, |
michael@0 | 255 | pkix_error_cause_depth, |
michael@0 | 256 | causeString), |
michael@0 | 257 | PKIX_SPRINTFFAILED); |
michael@0 | 258 | |
michael@0 | 259 | PKIX_DECREF(formatString); |
michael@0 | 260 | |
michael@0 | 261 | pkix_error_cause_depth--; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | /* Create the Format String */ |
michael@0 | 265 | if (optCauseString != NULL) { |
michael@0 | 266 | format = "*** %s Error- %s%s"; |
michael@0 | 267 | } else { |
michael@0 | 268 | format = "*** %s Error- %s"; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | /* Ensure that error errClass is known, otherwise default to Object */ |
michael@0 | 272 | if (errClass >= PKIX_NUMERRORCLASSES) { |
michael@0 | 273 | errClass = 0; |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | PKIX_CHECK(PKIX_PL_String_Create |
michael@0 | 277 | (PKIX_ESCASCII, |
michael@0 | 278 | (void *)PKIX_ERRORCLASSNAMES[errClass], |
michael@0 | 279 | 0, |
michael@0 | 280 | &errorNameString, |
michael@0 | 281 | plContext), |
michael@0 | 282 | PKIX_STRINGCREATEFAILED); |
michael@0 | 283 | |
michael@0 | 284 | PKIX_CHECK(PKIX_PL_String_Create |
michael@0 | 285 | (PKIX_ESCASCII, |
michael@0 | 286 | format, |
michael@0 | 287 | 0, |
michael@0 | 288 | &formatString, |
michael@0 | 289 | plContext), |
michael@0 | 290 | PKIX_STRINGCREATEFAILED); |
michael@0 | 291 | |
michael@0 | 292 | /* Create the output String */ |
michael@0 | 293 | PKIX_CHECK(PKIX_PL_Sprintf |
michael@0 | 294 | (pString, |
michael@0 | 295 | plContext, |
michael@0 | 296 | formatString, |
michael@0 | 297 | errorNameString, |
michael@0 | 298 | desc, |
michael@0 | 299 | optCauseString), |
michael@0 | 300 | PKIX_SPRINTFFAILED); |
michael@0 | 301 | |
michael@0 | 302 | cleanup: |
michael@0 | 303 | |
michael@0 | 304 | PKIX_DECREF(desc); |
michael@0 | 305 | PKIX_DECREF(causeString); |
michael@0 | 306 | PKIX_DECREF(formatString); |
michael@0 | 307 | PKIX_DECREF(optCauseString); |
michael@0 | 308 | PKIX_DECREF(errorNameString); |
michael@0 | 309 | |
michael@0 | 310 | PKIX_RETURN(ERROR); |
michael@0 | 311 | } |
michael@0 | 312 | |
michael@0 | 313 | /* |
michael@0 | 314 | * FUNCTION: pkix_Error_Hashcode |
michael@0 | 315 | * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) |
michael@0 | 316 | */ |
michael@0 | 317 | static PKIX_Error * |
michael@0 | 318 | pkix_Error_Hashcode( |
michael@0 | 319 | PKIX_PL_Object *object, |
michael@0 | 320 | PKIX_UInt32 *pResult, |
michael@0 | 321 | void *plContext) |
michael@0 | 322 | { |
michael@0 | 323 | PKIX_ENTER(ERROR, "pkix_Error_Hashcode"); |
michael@0 | 324 | PKIX_NULLCHECK_TWO(object, pResult); |
michael@0 | 325 | |
michael@0 | 326 | /* XXX Unimplemented */ |
michael@0 | 327 | /* XXX Need to make hashcodes equal when two errors are equal */ |
michael@0 | 328 | *pResult = (PKIX_UInt32)object; |
michael@0 | 329 | |
michael@0 | 330 | PKIX_RETURN(ERROR); |
michael@0 | 331 | } |
michael@0 | 332 | |
michael@0 | 333 | /* --Initializers------------------------------------------------- */ |
michael@0 | 334 | |
michael@0 | 335 | /* |
michael@0 | 336 | * PKIX_ERRORCLASSNAMES is an array of strings, with each string holding a |
michael@0 | 337 | * descriptive name for an error errClass. This is used by the default |
michael@0 | 338 | * PKIX_PL_Error_ToString function. |
michael@0 | 339 | * |
michael@0 | 340 | * Note: PKIX_ERRORCLASSES is defined in pkixt.h as a list of error types. |
michael@0 | 341 | * (More precisely, as a list of invocations of ERRMACRO(type).) The |
michael@0 | 342 | * macro is expanded in pkixt.h to define error numbers, and here to |
michael@0 | 343 | * provide corresponding strings. For example, since the fifth ERRMACRO |
michael@0 | 344 | * entry is MUTEX, then PKIX_MUTEX_ERROR is defined in pkixt.h as 4, and |
michael@0 | 345 | * PKIX_ERRORCLASSNAMES[4] is initialized here with the value "MUTEX". |
michael@0 | 346 | */ |
michael@0 | 347 | #undef ERRMACRO |
michael@0 | 348 | #define ERRMACRO(type) #type |
michael@0 | 349 | |
michael@0 | 350 | const char * |
michael@0 | 351 | PKIX_ERRORCLASSNAMES[PKIX_NUMERRORCLASSES] = |
michael@0 | 352 | { |
michael@0 | 353 | PKIX_ERRORCLASSES |
michael@0 | 354 | }; |
michael@0 | 355 | |
michael@0 | 356 | /* |
michael@0 | 357 | * FUNCTION: pkix_Error_RegisterSelf |
michael@0 | 358 | * DESCRIPTION: |
michael@0 | 359 | * Registers PKIX_ERROR_TYPE and its related functions with systemClasses[] |
michael@0 | 360 | * THREAD SAFETY: |
michael@0 | 361 | * Not Thread Safe - for performance and complexity reasons |
michael@0 | 362 | * |
michael@0 | 363 | * Since this function is only called by PKIX_PL_Initialize, which should |
michael@0 | 364 | * only be called once, it is acceptable that this function is not |
michael@0 | 365 | * thread-safe. |
michael@0 | 366 | */ |
michael@0 | 367 | PKIX_Error * |
michael@0 | 368 | pkix_Error_RegisterSelf(void *plContext) |
michael@0 | 369 | { |
michael@0 | 370 | extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; |
michael@0 | 371 | pkix_ClassTable_Entry entry; |
michael@0 | 372 | |
michael@0 | 373 | PKIX_ENTER(ERROR, "pkix_Error_RegisterSelf"); |
michael@0 | 374 | |
michael@0 | 375 | entry.description = "Error"; |
michael@0 | 376 | entry.objCounter = 0; |
michael@0 | 377 | entry.typeObjectSize = sizeof(PKIX_Error); |
michael@0 | 378 | entry.destructor = pkix_Error_Destroy; |
michael@0 | 379 | entry.equalsFunction = pkix_Error_Equals; |
michael@0 | 380 | entry.hashcodeFunction = pkix_Error_Hashcode; |
michael@0 | 381 | entry.toStringFunction = pkix_Error_ToString; |
michael@0 | 382 | entry.comparator = NULL; |
michael@0 | 383 | entry.duplicateFunction = pkix_duplicateImmutable; |
michael@0 | 384 | |
michael@0 | 385 | systemClasses[PKIX_ERROR_TYPE] = entry; |
michael@0 | 386 | |
michael@0 | 387 | PKIX_RETURN(ERROR); |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | /* --Public-Functions--------------------------------------------- */ |
michael@0 | 391 | |
michael@0 | 392 | /* |
michael@0 | 393 | * FUNCTION: PKIX_Error_Create (see comments in pkix_util.h) |
michael@0 | 394 | */ |
michael@0 | 395 | PKIX_Error * |
michael@0 | 396 | PKIX_Error_Create( |
michael@0 | 397 | PKIX_ERRORCLASS errClass, |
michael@0 | 398 | PKIX_Error *cause, |
michael@0 | 399 | PKIX_PL_Object *info, |
michael@0 | 400 | PKIX_ERRORCODE errCode, |
michael@0 | 401 | PKIX_Error **pError, |
michael@0 | 402 | void *plContext) |
michael@0 | 403 | { |
michael@0 | 404 | PKIX_Error *tempCause = NULL; |
michael@0 | 405 | PKIX_Error *error = NULL; |
michael@0 | 406 | |
michael@0 | 407 | PKIX_ENTER(ERROR, "PKIX_Error_Create"); |
michael@0 | 408 | |
michael@0 | 409 | PKIX_NULLCHECK_ONE(pError); |
michael@0 | 410 | |
michael@0 | 411 | /* |
michael@0 | 412 | * when called here, if PKIX_PL_Object_Alloc returns an error, |
michael@0 | 413 | * it must be a PKIX_ALLOC_ERROR |
michael@0 | 414 | */ |
michael@0 | 415 | pkixErrorResult = PKIX_PL_Object_Alloc |
michael@0 | 416 | (PKIX_ERROR_TYPE, |
michael@0 | 417 | ((PKIX_UInt32)(sizeof (PKIX_Error))), |
michael@0 | 418 | (PKIX_PL_Object **)&error, |
michael@0 | 419 | plContext); |
michael@0 | 420 | |
michael@0 | 421 | if (pkixErrorResult) return (pkixErrorResult); |
michael@0 | 422 | |
michael@0 | 423 | error->errClass = errClass; |
michael@0 | 424 | |
michael@0 | 425 | /* Ensure we don't have a loop. Follow causes until NULL */ |
michael@0 | 426 | for (tempCause = cause; |
michael@0 | 427 | tempCause != NULL; |
michael@0 | 428 | tempCause = tempCause->cause) { |
michael@0 | 429 | /* If we detect a loop, throw a new error */ |
michael@0 | 430 | if (tempCause == error) { |
michael@0 | 431 | PKIX_ERROR(PKIX_LOOPOFERRORCAUSEDETECTED); |
michael@0 | 432 | } |
michael@0 | 433 | } |
michael@0 | 434 | |
michael@0 | 435 | PKIX_INCREF(cause); |
michael@0 | 436 | error->cause = cause; |
michael@0 | 437 | |
michael@0 | 438 | PKIX_INCREF(info); |
michael@0 | 439 | error->info = info; |
michael@0 | 440 | |
michael@0 | 441 | error->errCode = errCode; |
michael@0 | 442 | |
michael@0 | 443 | error->plErr = PKIX_PLErrorIndex[error->errCode]; |
michael@0 | 444 | |
michael@0 | 445 | *pError = error; |
michael@0 | 446 | error = NULL; |
michael@0 | 447 | |
michael@0 | 448 | cleanup: |
michael@0 | 449 | /* PKIX-XXX Fix for leak during error creation */ |
michael@0 | 450 | PKIX_DECREF(error); |
michael@0 | 451 | |
michael@0 | 452 | PKIX_RETURN(ERROR); |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | /* |
michael@0 | 456 | * FUNCTION: PKIX_Error_GetErrorClass (see comments in pkix_util.h) |
michael@0 | 457 | */ |
michael@0 | 458 | PKIX_Error * |
michael@0 | 459 | PKIX_Error_GetErrorClass( |
michael@0 | 460 | PKIX_Error *error, |
michael@0 | 461 | PKIX_ERRORCLASS *pClass, |
michael@0 | 462 | void *plContext) |
michael@0 | 463 | { |
michael@0 | 464 | PKIX_ENTER(ERROR, "PKIX_Error_GetErrorClass"); |
michael@0 | 465 | PKIX_NULLCHECK_TWO(error, pClass); |
michael@0 | 466 | |
michael@0 | 467 | *pClass = error->errClass; |
michael@0 | 468 | |
michael@0 | 469 | PKIX_RETURN(ERROR); |
michael@0 | 470 | } |
michael@0 | 471 | |
michael@0 | 472 | /* |
michael@0 | 473 | * FUNCTION: PKIX_Error_GetErrorCode (see comments in pkix_util.h) |
michael@0 | 474 | */ |
michael@0 | 475 | PKIX_Error * |
michael@0 | 476 | PKIX_Error_GetErrorCode( |
michael@0 | 477 | PKIX_Error *error, |
michael@0 | 478 | PKIX_ERRORCODE *pCode, |
michael@0 | 479 | void *plContext) |
michael@0 | 480 | { |
michael@0 | 481 | PKIX_ENTER(ERROR, "PKIX_Error_GetErrorCode"); |
michael@0 | 482 | PKIX_NULLCHECK_TWO(error, pCode); |
michael@0 | 483 | |
michael@0 | 484 | *pCode = error->errCode; |
michael@0 | 485 | |
michael@0 | 486 | PKIX_RETURN(ERROR); |
michael@0 | 487 | } |
michael@0 | 488 | |
michael@0 | 489 | /* |
michael@0 | 490 | * FUNCTION: PKIX_Error_GetCause (see comments in pkix_util.h) |
michael@0 | 491 | */ |
michael@0 | 492 | PKIX_Error * |
michael@0 | 493 | PKIX_Error_GetCause( |
michael@0 | 494 | PKIX_Error *error, |
michael@0 | 495 | PKIX_Error **pCause, |
michael@0 | 496 | void *plContext) |
michael@0 | 497 | { |
michael@0 | 498 | PKIX_ENTER(ERROR, "PKIX_Error_GetCause"); |
michael@0 | 499 | PKIX_NULLCHECK_TWO(error, pCause); |
michael@0 | 500 | |
michael@0 | 501 | if (error->cause != PKIX_ALLOC_ERROR()){ |
michael@0 | 502 | PKIX_INCREF(error->cause); |
michael@0 | 503 | } |
michael@0 | 504 | |
michael@0 | 505 | *pCause = error->cause; |
michael@0 | 506 | |
michael@0 | 507 | cleanup: |
michael@0 | 508 | PKIX_RETURN(ERROR); |
michael@0 | 509 | } |
michael@0 | 510 | |
michael@0 | 511 | /* |
michael@0 | 512 | * FUNCTION: PKIX_Error_GetSupplementaryInfo (see comments in pkix_util.h) |
michael@0 | 513 | */ |
michael@0 | 514 | PKIX_Error * |
michael@0 | 515 | PKIX_Error_GetSupplementaryInfo( |
michael@0 | 516 | PKIX_Error *error, |
michael@0 | 517 | PKIX_PL_Object **pInfo, |
michael@0 | 518 | void *plContext) |
michael@0 | 519 | { |
michael@0 | 520 | PKIX_ENTER(ERROR, "PKIX_Error_GetSupplementaryInfo"); |
michael@0 | 521 | PKIX_NULLCHECK_TWO(error, pInfo); |
michael@0 | 522 | |
michael@0 | 523 | PKIX_INCREF(error->info); |
michael@0 | 524 | |
michael@0 | 525 | *pInfo = error->info; |
michael@0 | 526 | |
michael@0 | 527 | cleanup: |
michael@0 | 528 | PKIX_RETURN(ERROR); |
michael@0 | 529 | } |
michael@0 | 530 | |
michael@0 | 531 | /* |
michael@0 | 532 | * FUNCTION: PKIX_Error_GetDescription (see comments in pkix_util.h) |
michael@0 | 533 | */ |
michael@0 | 534 | PKIX_Error * |
michael@0 | 535 | PKIX_Error_GetDescription( |
michael@0 | 536 | PKIX_Error *error, |
michael@0 | 537 | PKIX_PL_String **pDesc, |
michael@0 | 538 | void *plContext) |
michael@0 | 539 | { |
michael@0 | 540 | PKIX_PL_String *descString = NULL; |
michael@0 | 541 | #ifndef PKIX_ERROR_DESCRIPTION |
michael@0 | 542 | char errorStr[32]; |
michael@0 | 543 | #endif |
michael@0 | 544 | |
michael@0 | 545 | PKIX_ENTER(ERROR, "PKIX_Error_GetDescription"); |
michael@0 | 546 | PKIX_NULLCHECK_TWO(error, pDesc); |
michael@0 | 547 | |
michael@0 | 548 | #ifndef PKIX_ERROR_DESCRIPTION |
michael@0 | 549 | PR_snprintf(errorStr, 32, "Error code: %d", error->errCode); |
michael@0 | 550 | #endif |
michael@0 | 551 | |
michael@0 | 552 | PKIX_PL_String_Create(PKIX_ESCASCII, |
michael@0 | 553 | #if defined PKIX_ERROR_DESCRIPTION |
michael@0 | 554 | (void *)PKIX_ErrorText[error->errCode], |
michael@0 | 555 | #else |
michael@0 | 556 | errorStr, |
michael@0 | 557 | #endif |
michael@0 | 558 | 0, |
michael@0 | 559 | &descString, |
michael@0 | 560 | plContext); |
michael@0 | 561 | |
michael@0 | 562 | *pDesc = descString; |
michael@0 | 563 | |
michael@0 | 564 | PKIX_RETURN(ERROR); |
michael@0 | 565 | } |