OLD | NEW |
1 /* | 1 /* |
2 * error.c: module displaying/handling XML parser errors | 2 * error.c: module displaying/handling XML parser errors |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * Daniel Veillard <daniel@veillard.com> | 6 * Daniel Veillard <daniel@veillard.com> |
7 */ | 7 */ |
8 | 8 |
9 #define IN_LIBXML | 9 #define IN_LIBXML |
10 #include "libxml.h" | 10 #include "libxml.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 * | 125 * |
126 * Function to reset the handler and the error context for out of | 126 * Function to reset the handler and the error context for out of |
127 * context structured error messages. | 127 * context structured error messages. |
128 * This simply means that @handler will be called for subsequent | 128 * This simply means that @handler will be called for subsequent |
129 * error messages while not parsing nor validating. And @ctx will | 129 * error messages while not parsing nor validating. And @ctx will |
130 * be passed as first argument to @handler | 130 * be passed as first argument to @handler |
131 * For multi-threaded applications, this must be set separately for each thread. | 131 * For multi-threaded applications, this must be set separately for each thread. |
132 */ | 132 */ |
133 void | 133 void |
134 xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { | 134 xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { |
135 xmlGenericErrorContext = ctx; | 135 xmlStructuredErrorContext = ctx; |
136 xmlStructuredError = handler; | 136 xmlStructuredError = handler; |
137 } | 137 } |
138 | 138 |
139 /************************************************************************ | 139 /************************************************************************ |
140 * * | 140 * * |
141 * Handling of parsing errors * | 141 * Handling of parsing errors * |
142 * * | 142 * * |
143 ************************************************************************/ | 143 ************************************************************************/ |
144 | 144 |
145 /** | 145 /** |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 464 } |
465 /* | 465 /* |
466 * Check if structured error handler set | 466 * Check if structured error handler set |
467 */ | 467 */ |
468 if (schannel == NULL) { | 468 if (schannel == NULL) { |
469 schannel = xmlStructuredError; | 469 schannel = xmlStructuredError; |
470 /* | 470 /* |
471 * if user has defined handler, change data ptr to user's choice | 471 * if user has defined handler, change data ptr to user's choice |
472 */ | 472 */ |
473 if (schannel != NULL) | 473 if (schannel != NULL) |
474 » data = xmlGenericErrorContext; | 474 » data = xmlStructuredErrorContext; |
475 } | 475 } |
476 if ((domain == XML_FROM_VALID) && | 476 if ((domain == XML_FROM_VALID) && |
477 ((channel == xmlParserValidityError) || | 477 ((channel == xmlParserValidityError) || |
478 (channel == xmlParserValidityWarning))) { | 478 (channel == xmlParserValidityWarning))) { |
479 ctxt = (xmlParserCtxtPtr) ctx; | 479 ctxt = (xmlParserCtxtPtr) ctx; |
480 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) && | 480 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) && |
481 (ctxt->sax->initialized == XML_SAX2_MAGIC)) | 481 (ctxt->sax->initialized == XML_SAX2_MAGIC)) |
482 schannel = ctxt->sax->serror; | 482 schannel = ctxt->sax->serror; |
483 } | 483 } |
484 if (code == XML_ERR_OK) | 484 if (code == XML_ERR_OK) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 prev->type = XML_XINCLUDE_START; | 566 prev->type = XML_XINCLUDE_START; |
567 } else { | 567 } else { |
568 to->file = (char *) xmlGetProp(prev, BAD_CAST "href"); | 568 to->file = (char *) xmlGetProp(prev, BAD_CAST "href"); |
569 } | 569 } |
570 } else | 570 } else |
571 #endif | 571 #endif |
572 to->file = (char *) xmlStrdup(baseptr->doc->URL); | 572 to->file = (char *) xmlStrdup(baseptr->doc->URL); |
573 if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) { | 573 if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) { |
574 to->file = (char *) xmlStrdup(node->doc->URL); | 574 to->file = (char *) xmlStrdup(node->doc->URL); |
575 } | 575 } |
576 file = to->file; | |
577 } | 576 } |
578 to->line = line; | 577 to->line = line; |
579 if (str1 != NULL) | 578 if (str1 != NULL) |
580 to->str1 = (char *) xmlStrdup((const xmlChar *) str1); | 579 to->str1 = (char *) xmlStrdup((const xmlChar *) str1); |
581 if (str2 != NULL) | 580 if (str2 != NULL) |
582 to->str2 = (char *) xmlStrdup((const xmlChar *) str2); | 581 to->str2 = (char *) xmlStrdup((const xmlChar *) str2); |
583 if (str3 != NULL) | 582 if (str3 != NULL) |
584 to->str3 = (char *) xmlStrdup((const xmlChar *) str3); | 583 to->str3 = (char *) xmlStrdup((const xmlChar *) str3); |
585 to->int1 = int1; | 584 to->int1 = int1; |
586 to->int2 = col; | 585 to->int2 = col; |
587 to->node = node; | 586 to->node = node; |
588 to->ctxt = ctx; | 587 to->ctxt = ctx; |
589 | 588 |
590 if (to != &xmlLastError) | 589 if (to != &xmlLastError) |
591 xmlCopyError(to,&xmlLastError); | 590 xmlCopyError(to,&xmlLastError); |
592 | 591 |
593 /* | 592 /* |
594 * Find the callback channel if channel param is NULL | 593 * Find the callback channel if channel param is NULL |
595 */ | 594 */ |
596 if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL) && (
ctxt->sax != NULL)) { | 595 if ((ctxt != NULL) && (channel == NULL) && |
| 596 (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { |
597 if (level == XML_ERR_WARNING) | 597 if (level == XML_ERR_WARNING) |
598 channel = ctxt->sax->warning; | 598 channel = ctxt->sax->warning; |
599 else | 599 else |
600 channel = ctxt->sax->error; | 600 channel = ctxt->sax->error; |
601 data = ctxt->userData; | 601 data = ctxt->userData; |
602 } else if (channel == NULL) { | 602 } else if (channel == NULL) { |
603 if (xmlStructuredError != NULL) | 603 if ((schannel == NULL) && (xmlStructuredError != NULL)) { |
604 schannel = xmlStructuredError; | 604 schannel = xmlStructuredError; |
605 » else | 605 » data = xmlStructuredErrorContext; |
| 606 » } else { |
606 channel = xmlGenericError; | 607 channel = xmlGenericError; |
607 » if (!data) { | 608 » if (!data) { |
608 » data = xmlGenericErrorContext; | 609 » » data = xmlGenericErrorContext; |
609 } | 610 » } |
| 611 » } |
610 } | 612 } |
611 if (schannel != NULL) { | 613 if (schannel != NULL) { |
612 schannel(data, to); | 614 schannel(data, to); |
613 return; | 615 return; |
614 } | 616 } |
615 if (channel == NULL) | 617 if (channel == NULL) |
616 return; | 618 return; |
617 | 619 |
618 if ((channel == xmlParserError) || | 620 if ((channel == xmlParserError) || |
619 (channel == xmlParserWarning) || | 621 (channel == xmlParserWarning) || |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 * Cleanup the last global error registered. For parsing error | 922 * Cleanup the last global error registered. For parsing error |
921 * this does not change the well-formedness result. | 923 * this does not change the well-formedness result. |
922 */ | 924 */ |
923 void | 925 void |
924 xmlCtxtResetLastError(void *ctx) | 926 xmlCtxtResetLastError(void *ctx) |
925 { | 927 { |
926 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 928 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
927 | 929 |
928 if (ctxt == NULL) | 930 if (ctxt == NULL) |
929 return; | 931 return; |
| 932 ctxt->errNo = XML_ERR_OK; |
930 if (ctxt->lastError.code == XML_ERR_OK) | 933 if (ctxt->lastError.code == XML_ERR_OK) |
931 return; | 934 return; |
932 xmlResetError(&ctxt->lastError); | 935 xmlResetError(&ctxt->lastError); |
933 } | 936 } |
934 | 937 |
935 /** | 938 /** |
936 * xmlCopyError: | 939 * xmlCopyError: |
937 * @from: a source error | 940 * @from: a source error |
938 * @to: a target error | 941 * @to: a target error |
939 * | 942 * |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 to->file = file; | 980 to->file = file; |
978 to->str1 = str1; | 981 to->str1 = str1; |
979 to->str2 = str2; | 982 to->str2 = str2; |
980 to->str3 = str3; | 983 to->str3 = str3; |
981 | 984 |
982 return 0; | 985 return 0; |
983 } | 986 } |
984 | 987 |
985 #define bottom_error | 988 #define bottom_error |
986 #include "elfgcchack.h" | 989 #include "elfgcchack.h" |
OLD | NEW |