| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #include "wizard/studio.h" |
|---|
| 44 | #include "wizard/client.h" |
|---|
| 45 | #include "wizard/exception.h" |
|---|
| 46 | #include "wizard/exception-private.h" |
|---|
| 47 | #include "wizard/hashmap.h" |
|---|
| 48 | #include "wizard/log.h" |
|---|
| 49 | #include "wizard/memory_.h" |
|---|
| 50 | #include "wizard/string_.h" |
|---|
| 51 | #include "wizard/utility.h" |
|---|
| 52 | #include "wizard/wizard.h" |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | struct _ExceptionInfo |
|---|
| 58 | { |
|---|
| 59 | ExceptionType |
|---|
| 60 | severity; |
|---|
| 61 | |
|---|
| 62 | char |
|---|
| 63 | *reason, |
|---|
| 64 | *description; |
|---|
| 65 | |
|---|
| 66 | void |
|---|
| 67 | *exceptions; |
|---|
| 68 | |
|---|
| 69 | WizardBooleanType |
|---|
| 70 | relinquish; |
|---|
| 71 | |
|---|
| 72 | SemaphoreInfo |
|---|
| 73 | *semaphore; |
|---|
| 74 | |
|---|
| 75 | unsigned long |
|---|
| 76 | signature; |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 83 | extern "C" { |
|---|
| 84 | #endif |
|---|
| 85 | |
|---|
| 86 | static void |
|---|
| 87 | DefaultErrorHandler(const ExceptionType,const char *,const char *), |
|---|
| 88 | DefaultFatalErrorHandler(const ExceptionType,const char *,const char *), |
|---|
| 89 | DefaultWarningHandler(const ExceptionType,const char *,const char *); |
|---|
| 90 | |
|---|
| 91 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 92 | } |
|---|
| 93 | #endif |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | static ErrorHandler |
|---|
| 99 | error_handler = DefaultErrorHandler; |
|---|
| 100 | |
|---|
| 101 | static FatalErrorHandler |
|---|
| 102 | fatal_error_handler = DefaultFatalErrorHandler; |
|---|
| 103 | |
|---|
| 104 | static WarningHandler |
|---|
| 105 | warning_handler = DefaultWarningHandler; |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | WizardExport ExceptionInfo *AcquireExceptionInfo(void) |
|---|
| 126 | { |
|---|
| 127 | ExceptionInfo |
|---|
| 128 | *exception; |
|---|
| 129 | |
|---|
| 130 | exception=(ExceptionInfo *) AcquireWizardMemory(sizeof(*exception)); |
|---|
| 131 | if (exception == (ExceptionInfo *) NULL) |
|---|
| 132 | ThrowFatalException(ResourceFatalError,"memory allocation failed `%s'"); |
|---|
| 133 | (void) ResetWizardMemory(exception,0,sizeof(*exception)); |
|---|
| 134 | GetExceptionInfo(exception); |
|---|
| 135 | exception->relinquish=WizardTrue; |
|---|
| 136 | exception->signature=WizardSignature; |
|---|
| 137 | return(exception); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | static void *DestroyExceptionElement(void *exception) |
|---|
| 165 | { |
|---|
| 166 | register ExceptionInfo |
|---|
| 167 | *p; |
|---|
| 168 | |
|---|
| 169 | p=(ExceptionInfo *) exception; |
|---|
| 170 | if (p->reason != (char *) NULL) |
|---|
| 171 | p->reason=(char *) RelinquishWizardMemory(p->reason); |
|---|
| 172 | if (p->description != (char *) NULL) |
|---|
| 173 | p->description=(char *) RelinquishWizardMemory(p->description); |
|---|
| 174 | p=(ExceptionInfo *) RelinquishWizardMemory(p); |
|---|
| 175 | return((void *) NULL); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | WizardExport void ClearWizardException(ExceptionInfo *exception) |
|---|
| 179 | { |
|---|
| 180 | register ExceptionInfo |
|---|
| 181 | *p; |
|---|
| 182 | |
|---|
| 183 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 184 | assert(exception->signature == WizardSignature); |
|---|
| 185 | if (exception->exceptions == (void *) NULL) |
|---|
| 186 | return; |
|---|
| 187 | (void) LockSemaphoreInfo(exception->semaphore); |
|---|
| 188 | p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *) |
|---|
| 189 | exception->exceptions); |
|---|
| 190 | while (p != (ExceptionInfo *) NULL) |
|---|
| 191 | { |
|---|
| 192 | p=(ExceptionInfo *) DestroyExceptionElement(p); |
|---|
| 193 | p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *) |
|---|
| 194 | exception->exceptions); |
|---|
| 195 | } |
|---|
| 196 | exception->severity=UndefinedException; |
|---|
| 197 | exception->reason=(char *) NULL; |
|---|
| 198 | exception->description=(char *) NULL; |
|---|
| 199 | (void) UnlockSemaphoreInfo(exception->semaphore); |
|---|
| 200 | errno=0; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | WizardExport void CatchException(ExceptionInfo *exception) |
|---|
| 227 | { |
|---|
| 228 | register const ExceptionInfo |
|---|
| 229 | *p; |
|---|
| 230 | |
|---|
| 231 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 232 | assert(exception->signature == WizardSignature); |
|---|
| 233 | if (exception->exceptions == (void *) NULL) |
|---|
| 234 | return; |
|---|
| 235 | (void) LockSemaphoreInfo(exception->semaphore); |
|---|
| 236 | ResetLinkedListIterator((LinkedListInfo *) exception->exceptions); |
|---|
| 237 | p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) |
|---|
| 238 | exception->exceptions); |
|---|
| 239 | while (p != (const ExceptionInfo *) NULL) |
|---|
| 240 | { |
|---|
| 241 | if ((p->severity >= WarningException) && (p->severity < ErrorException)) |
|---|
| 242 | WizardWarning(p->severity,p->reason,p->description); |
|---|
| 243 | if ((p->severity >= ErrorException) && (p->severity < FatalErrorException)) |
|---|
| 244 | WizardError(p->severity,p->reason,p->description); |
|---|
| 245 | if (exception->severity >= FatalErrorException) |
|---|
| 246 | WizardFatalError(p->severity,p->reason,p->description); |
|---|
| 247 | p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) |
|---|
| 248 | exception->exceptions); |
|---|
| 249 | } |
|---|
| 250 | (void) UnlockSemaphoreInfo(exception->semaphore); |
|---|
| 251 | ClearWizardException(exception); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | static void DefaultErrorHandler(const ExceptionType wizard_unused(severity), |
|---|
| 283 | const char *reason,const char *description) |
|---|
| 284 | { |
|---|
| 285 | if (reason == (char *) NULL) |
|---|
| 286 | return; |
|---|
| 287 | (void) fprintf(stderr,"%s: %s",GetClientName(),reason); |
|---|
| 288 | if (description != (char *) NULL) |
|---|
| 289 | (void) fprintf(stderr," (%s)",description); |
|---|
| 290 | (void) fprintf(stderr,".\n"); |
|---|
| 291 | (void) fflush(stderr); |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | static void DefaultFatalErrorHandler(const ExceptionType severity, |
|---|
| 324 | const char *reason,const char *description) |
|---|
| 325 | { |
|---|
| 326 | if (reason == (char *) NULL) |
|---|
| 327 | return; |
|---|
| 328 | (void) fprintf(stderr,"%s: %s",GetClientName(),reason); |
|---|
| 329 | if (description != (char *) NULL) |
|---|
| 330 | (void) fprintf(stderr," (%s)",description); |
|---|
| 331 | (void) fprintf(stderr,".\n"); |
|---|
| 332 | (void) fflush(stderr); |
|---|
| 333 | WizardsToolkitTerminus(); |
|---|
| 334 | exit(1); |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | static void DefaultWarningHandler(const ExceptionType wizard_unused(severity), |
|---|
| 366 | const char *reason,const char *description) |
|---|
| 367 | { |
|---|
| 368 | if (reason == (char *) NULL) |
|---|
| 369 | return; |
|---|
| 370 | (void) fprintf(stderr,"%s: %s",GetClientName(),reason); |
|---|
| 371 | if (description != (char *) NULL) |
|---|
| 372 | (void) fprintf(stderr," (%s)",description); |
|---|
| 373 | (void) fprintf(stderr,".\n"); |
|---|
| 374 | (void) fflush(stderr); |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | WizardExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) |
|---|
| 400 | { |
|---|
| 401 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 402 | assert(exception->signature == WizardSignature); |
|---|
| 403 | (void) LockSemaphoreInfo(exception->semaphore); |
|---|
| 404 | exception->severity=UndefinedException; |
|---|
| 405 | if (exception->exceptions != (void *) NULL) |
|---|
| 406 | exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *) |
|---|
| 407 | exception->exceptions,DestroyExceptionElement); |
|---|
| 408 | exception->signature=(~WizardSignature); |
|---|
| 409 | (void) UnlockSemaphoreInfo(exception->semaphore); |
|---|
| 410 | DestroySemaphoreInfo(&exception->semaphore); |
|---|
| 411 | if (exception->relinquish != WizardFalse) |
|---|
| 412 | exception=(ExceptionInfo *) RelinquishWizardMemory(exception); |
|---|
| 413 | return(exception); |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | WizardExport void GetExceptionInfo(ExceptionInfo *exception) |
|---|
| 439 | { |
|---|
| 440 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 441 | (void) ResetWizardMemory(exception,0,sizeof(*exception)); |
|---|
| 442 | exception->severity=UndefinedException; |
|---|
| 443 | exception->exceptions=(void *) NewLinkedList(0); |
|---|
| 444 | exception->semaphore=AllocateSemaphoreInfo(); |
|---|
| 445 | exception->signature=WizardSignature; |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | WizardExport char *GetExceptionMessage(const int error) |
|---|
| 472 | { |
|---|
| 473 | char |
|---|
| 474 | exception[MaxTextExtent]; |
|---|
| 475 | |
|---|
| 476 | #if defined(WIZARDSTOOLKIT_HAVE_STRERROR_R) |
|---|
| 477 | (void) strerror_r(error,exception,sizeof(exception)); |
|---|
| 478 | #else |
|---|
| 479 | (void) CopyWizardString(exception,strerror(error),sizeof(exception)); |
|---|
| 480 | #endif |
|---|
| 481 | return(ConstantString(exception)); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | static const char *ExceptionSeverityToTag(const ExceptionType severity) |
|---|
| 512 | { |
|---|
| 513 | switch (severity) |
|---|
| 514 | { |
|---|
| 515 | case OptionWarning: return("Option/Warning/"); |
|---|
| 516 | case RandomWarning: return("Random/Warning/"); |
|---|
| 517 | case HashWarning: return("Hash/Warning/"); |
|---|
| 518 | case MACWarning: return("MAC/Warning/"); |
|---|
| 519 | case EntropyWarning: return("Entropy/Warning/"); |
|---|
| 520 | case ConfigureWarning: return("Configure/Warning/"); |
|---|
| 521 | case CipherWarning: return("Cipher/Warning/"); |
|---|
| 522 | case KeymapWarning: return("Keymap/Warning/"); |
|---|
| 523 | case AuthenticateWarning: return("Authenticate/Warning/"); |
|---|
| 524 | case KeyringWarning: return("Keyring/Warning/"); |
|---|
| 525 | case ParseWarning: return("Parse/Warning/"); |
|---|
| 526 | case UserWarning: return("User/Warning/"); |
|---|
| 527 | case SplayTreeWarning: return("SplayTree/Warning/"); |
|---|
| 528 | case HashmapWarning: return("Hashmap/Warning/"); |
|---|
| 529 | case LogWarning: return("Log/Warning/"); |
|---|
| 530 | case StringWarning: return("String/Warning/"); |
|---|
| 531 | case FileWarning: return("File/Warning/"); |
|---|
| 532 | case BlobWarning: return("Blob/Warning/"); |
|---|
| 533 | case ResourceWarning: return("ResourceLimit/Warning/"); |
|---|
| 534 | case OptionError: return("Option/Error/"); |
|---|
| 535 | case RandomError: return("Random/Error/"); |
|---|
| 536 | case HashError: return("Hash/Error/"); |
|---|
| 537 | case MACError: return("MAC/Error/"); |
|---|
| 538 | case EntropyError: return("Entropy/Error/"); |
|---|
| 539 | case ConfigureError: return("Configure/Error/"); |
|---|
| 540 | case CipherError: return("Cipher/Error/"); |
|---|
| 541 | case KeymapError: return("Keymap/Error/"); |
|---|
| 542 | case AuthenticateError: return("Authenticate/Error/"); |
|---|
| 543 | case KeyringError: return("Keyring/Error/"); |
|---|
| 544 | case ParseError: return("Parse/Error/"); |
|---|
| 545 | case UserError: return("User/Error/"); |
|---|
| 546 | case SplayTreeError: return("SplayTree/Error/"); |
|---|
| 547 | case StringError: return("String/Error/"); |
|---|
| 548 | case FileError: return("File/Error/"); |
|---|
| 549 | case BlobError: return("Blob/Error/"); |
|---|
| 550 | case ResourceError: return("ResourceLimit/Error/"); |
|---|
| 551 | case OptionFatalError: return("Option/FatalError/"); |
|---|
| 552 | case RandomFatalError: return("Random/FatalError/"); |
|---|
| 553 | case HashFatalError: return("Hash/FatalError/"); |
|---|
| 554 | case MACFatalError: return("MAC/FatalError/"); |
|---|
| 555 | case EntropyFatalError: return("Entropy/FatalError/"); |
|---|
| 556 | case ConfigureFatalError: return("Configure/FatalError/"); |
|---|
| 557 | case CipherFatalError: return("Cipher/FatalError/"); |
|---|
| 558 | case KeymapFatalError: return("Keymap/FatalError/"); |
|---|
| 559 | case AuthenticateFatalError: return("Authenticate/FatalError/"); |
|---|
| 560 | case KeyringFatalError: return("Keyring/FatalError/"); |
|---|
| 561 | case ParseFatalError: return("Parse/FatalError/"); |
|---|
| 562 | case UserFatalError: return("User/FatalError/"); |
|---|
| 563 | case SplayTreeFatalError: return("SplayTree/FatalError/"); |
|---|
| 564 | case HashmapFatalError: return("Hashmap/FatalError/"); |
|---|
| 565 | case LogFatalError: return("Log/FatalError/"); |
|---|
| 566 | case StringFatalError: return("String/FatalError/"); |
|---|
| 567 | case FileFatalError: return("File/FatalError/"); |
|---|
| 568 | case BlobFatalError: return("Blob/FatalError/"); |
|---|
| 569 | case ResourceFatalError: return("ResourceLimit/FatalError/"); |
|---|
| 570 | default: break; |
|---|
| 571 | } |
|---|
| 572 | return(""); |
|---|
| 573 | } |
|---|
| 574 | |
|---|
| 575 | WizardExport const char *GetLocaleExceptionMessage(const ExceptionType severity, |
|---|
| 576 | const char *tag) |
|---|
| 577 | { |
|---|
| 578 | #if defined(WIZARDSTOOLKIT_LOCALE) |
|---|
| 579 | char |
|---|
| 580 | message[MaxTextExtent]; |
|---|
| 581 | |
|---|
| 582 | const char |
|---|
| 583 | *locale_message; |
|---|
| 584 | |
|---|
| 585 | assert(tag != (const char *) NULL); |
|---|
| 586 | (void) FormatWizardString(message,MaxTextExtent,"Exception/%s%s", |
|---|
| 587 | ExceptionSeverityToTag(severity),tag); |
|---|
| 588 | locale_message=GetLocaleMessage(message); |
|---|
| 589 | if (locale_message == (const char *) NULL) |
|---|
| 590 | return(tag); |
|---|
| 591 | if (locale_message == message) |
|---|
| 592 | return(tag); |
|---|
| 593 | return(locale_message); |
|---|
| 594 | #else |
|---|
| 595 | return(tag); |
|---|
| 596 | #endif |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | WizardExport ExceptionType GetExceptionSeverity(const ExceptionInfo *exception) |
|---|
| 622 | { |
|---|
| 623 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 624 | assert(exception->signature == WizardSignature); |
|---|
| 625 | return(exception->severity); |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | WizardExport void InheritException(ExceptionInfo *exception, |
|---|
| 654 | const ExceptionInfo *relative) |
|---|
| 655 | { |
|---|
| 656 | register const ExceptionInfo |
|---|
| 657 | *p; |
|---|
| 658 | |
|---|
| 659 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 660 | assert(exception->signature == WizardSignature); |
|---|
| 661 | assert(relative != (ExceptionInfo *) NULL); |
|---|
| 662 | assert(relative->signature == WizardSignature); |
|---|
| 663 | if (relative->exceptions == (void *) NULL) |
|---|
| 664 | return; |
|---|
| 665 | (void) LockSemaphoreInfo(exception->semaphore); |
|---|
| 666 | ResetLinkedListIterator((LinkedListInfo *) relative->exceptions); |
|---|
| 667 | p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) |
|---|
| 668 | relative->exceptions); |
|---|
| 669 | while (p != (const ExceptionInfo *) NULL) |
|---|
| 670 | { |
|---|
| 671 | (void) ThrowException(exception,p->severity,p->reason,p->description); |
|---|
| 672 | p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) |
|---|
| 673 | relative->exceptions); |
|---|
| 674 | } |
|---|
| 675 | (void) UnlockSemaphoreInfo(exception->semaphore); |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | WizardExport void WizardError(const ExceptionType error,const char *reason, |
|---|
| 708 | const char *description) |
|---|
| 709 | { |
|---|
| 710 | if (error_handler != (ErrorHandler) NULL) |
|---|
| 711 | (*error_handler)(error,reason,description); |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | WizardExport void WizardFatalError(const ExceptionType error,const char *reason, |
|---|
| 744 | const char *description) |
|---|
| 745 | { |
|---|
| 746 | if (fatal_error_handler != (ErrorHandler) NULL) |
|---|
| 747 | (*fatal_error_handler)(error,reason,description); |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | WizardExport void WizardWarning(const ExceptionType warning,const char *reason, |
|---|
| 778 | const char *description) |
|---|
| 779 | { |
|---|
| 780 | if (warning_handler != (WarningHandler) NULL) |
|---|
| 781 | (*warning_handler)(warning,reason,description); |
|---|
| 782 | } |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 786 | |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | WizardExport ErrorHandler SetErrorHandler(ErrorHandler handler) |
|---|
| 808 | { |
|---|
| 809 | ErrorHandler |
|---|
| 810 | previous_handler; |
|---|
| 811 | |
|---|
| 812 | previous_handler=error_handler; |
|---|
| 813 | error_handler=handler; |
|---|
| 814 | return(previous_handler); |
|---|
| 815 | } |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | |
|---|
| 826 | |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | WizardExport FatalErrorHandler SetFatalErrorHandler(FatalErrorHandler handler) |
|---|
| 841 | { |
|---|
| 842 | FatalErrorHandler |
|---|
| 843 | previous_handler; |
|---|
| 844 | |
|---|
| 845 | previous_handler=fatal_error_handler; |
|---|
| 846 | fatal_error_handler=handler; |
|---|
| 847 | return(previous_handler); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | WizardExport WarningHandler SetWarningHandler(WarningHandler handler) |
|---|
| 874 | { |
|---|
| 875 | WarningHandler |
|---|
| 876 | previous_handler; |
|---|
| 877 | |
|---|
| 878 | previous_handler=warning_handler; |
|---|
| 879 | warning_handler=handler; |
|---|
| 880 | return(previous_handler); |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | |
|---|
| 895 | |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | |
|---|
| 899 | |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | |
|---|
| 911 | |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | WizardExport WizardBooleanType ThrowException(ExceptionInfo *exception, |
|---|
| 915 | const ExceptionType severity,const char *reason,const char *description) |
|---|
| 916 | { |
|---|
| 917 | register ExceptionInfo |
|---|
| 918 | *p; |
|---|
| 919 | |
|---|
| 920 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 921 | assert(exception->signature == WizardSignature); |
|---|
| 922 | if (exception->exceptions == (void *) NULL) |
|---|
| 923 | return(WizardTrue); |
|---|
| 924 | p=(ExceptionInfo *) GetLastValueInLinkedList((LinkedListInfo *) |
|---|
| 925 | exception->exceptions); |
|---|
| 926 | if ((p != (ExceptionInfo *) NULL) && (p->severity == severity) && |
|---|
| 927 | (LocaleCompare(exception->reason,reason) == 0) && |
|---|
| 928 | (LocaleCompare(exception->description,description) == 0)) |
|---|
| 929 | return(WizardTrue); |
|---|
| 930 | p=(ExceptionInfo *) AcquireWizardMemory(sizeof(*p)); |
|---|
| 931 | if (p == (ExceptionInfo *) NULL) |
|---|
| 932 | ThrowFatalException(ResourceFatalError,"memory allocation failed `%s'"); |
|---|
| 933 | (void) ResetWizardMemory(p,0,sizeof(*p)); |
|---|
| 934 | p->severity=severity; |
|---|
| 935 | if (reason != (const char *) NULL) |
|---|
| 936 | p->reason=ConstantString(reason); |
|---|
| 937 | if (description != (const char *) NULL) |
|---|
| 938 | p->description=ConstantString(description); |
|---|
| 939 | p->signature=WizardSignature; |
|---|
| 940 | (void) AppendValueToLinkedList((LinkedListInfo *) exception->exceptions,p); |
|---|
| 941 | exception->severity=p->severity; |
|---|
| 942 | exception->reason=p->reason; |
|---|
| 943 | exception->description=p->description; |
|---|
| 944 | return(WizardTrue); |
|---|
| 945 | } |
|---|
| 946 | |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | |
|---|
| 957 | |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | |
|---|
| 961 | |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | |
|---|
| 966 | |
|---|
| 967 | |
|---|
| 968 | |
|---|
| 969 | |
|---|
| 970 | |
|---|
| 971 | |
|---|
| 972 | |
|---|
| 973 | |
|---|
| 974 | |
|---|
| 975 | |
|---|
| 976 | |
|---|
| 977 | |
|---|
| 978 | |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | WizardExport WizardBooleanType ThrowWizardExceptionList( |
|---|
| 984 | ExceptionInfo *exception,const char *module,const char *function, |
|---|
| 985 | const unsigned long line,const ExceptionType severity,const char *format, |
|---|
| 986 | va_list operands) |
|---|
| 987 | { |
|---|
| 988 | char |
|---|
| 989 | message[MaxTextExtent], |
|---|
| 990 | reason[MaxTextExtent]; |
|---|
| 991 | |
|---|
| 992 | int |
|---|
| 993 | n; |
|---|
| 994 | |
|---|
| 995 | WizardBooleanType |
|---|
| 996 | status; |
|---|
| 997 | |
|---|
| 998 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 999 | assert(exception->signature == WizardSignature); |
|---|
| 1000 | #if defined(WIZARDSTOOLKIT_HAVE_VSNPRINTF) |
|---|
| 1001 | n=vsnprintf(reason,MaxTextExtent,format,operands); |
|---|
| 1002 | #else |
|---|
| 1003 | n=vsprintf(reason,format,operands); |
|---|
| 1004 | #endif |
|---|
| 1005 | if (n < 0) |
|---|
| 1006 | reason[MaxTextExtent-1]='\0'; |
|---|
| 1007 | status=LogWizardEvent(exception->severity >= ErrorException ? |
|---|
| 1008 | ExceptionEvent : WarningEvent,module,function,line,"%s",reason); |
|---|
| 1009 | (void) FormatWizardString(message,MaxTextExtent,"%s @ %s/%s/%ld",reason, |
|---|
| 1010 | module,function,line); |
|---|
| 1011 | (void) ThrowException(exception,severity,message,(char *) NULL); |
|---|
| 1012 | return(status); |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, |
|---|
| 1016 | const char *module,const char *function,const unsigned long line, |
|---|
| 1017 | const ExceptionType severity,const char *format,...) |
|---|
| 1018 | { |
|---|
| 1019 | WizardBooleanType |
|---|
| 1020 | status; |
|---|
| 1021 | |
|---|
| 1022 | va_list |
|---|
| 1023 | operands; |
|---|
| 1024 | |
|---|
| 1025 | va_start(operands,format); |
|---|
| 1026 | status=ThrowWizardExceptionList(exception,module,function,line,severity, |
|---|
| 1027 | format,operands); |
|---|
| 1028 | va_end(operands); |
|---|
| 1029 | return(status); |
|---|
| 1030 | } |
|---|