MCPcopy Create free account
hub / github.com/apache/cloudberry / xml_errorHandler

Function xml_errorHandler

src/backend/utils/adt/xml.c:1764–1929  ·  view source on GitHub ↗

* Error handler for libxml errors and warnings */

Source from the content-addressed store, hash-verified

1762 * Error handler for libxml errors and warnings
1763 */
1764static void
1765xml_errorHandler(void *data, xmlErrorPtr error)
1766{
1767 PgXmlErrorContext *xmlerrcxt = (PgXmlErrorContext *) data;
1768 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt;
1769 xmlParserInputPtr input = (ctxt != NULL) ? ctxt->input : NULL;
1770 xmlNodePtr node = error->node;
1771 const xmlChar *name = (node != NULL &&
1772 node->type == XML_ELEMENT_NODE) ? node->name : NULL;
1773 int domain = error->domain;
1774 int level = error->level;
1775 StringInfo errorBuf;
1776
1777 /*
1778 * Defend against someone passing us a bogus context struct.
1779 *
1780 * We force a backend exit if this check fails because longjmp'ing out of
1781 * libxml would likely render it unsafe to use further.
1782 */
1783 if (xmlerrcxt->magic != ERRCXT_MAGIC)
1784 elog(FATAL, "xml_errorHandler called with invalid PgXmlErrorContext");
1785
1786 /*----------
1787 * Older libxml versions report some errors differently.
1788 * First, some errors were previously reported as coming from the parser
1789 * domain but are now reported as coming from the namespace domain.
1790 * Second, some warnings were upgraded to errors.
1791 * We attempt to compensate for that here.
1792 *----------
1793 */
1794 switch (error->code)
1795 {
1796 case XML_WAR_NS_URI:
1797 level = XML_ERR_ERROR;
1798 domain = XML_FROM_NAMESPACE;
1799 break;
1800
1801 case XML_ERR_NS_DECL_ERROR:
1802 case XML_WAR_NS_URI_RELATIVE:
1803 case XML_WAR_NS_COLUMN:
1804 case XML_NS_ERR_XML_NAMESPACE:
1805 case XML_NS_ERR_UNDEFINED_NAMESPACE:
1806 case XML_NS_ERR_QNAME:
1807 case XML_NS_ERR_ATTRIBUTE_REDEFINED:
1808 case XML_NS_ERR_EMPTY:
1809 domain = XML_FROM_NAMESPACE;
1810 break;
1811 }
1812
1813 /* Decide whether to act on the error or not */
1814 switch (domain)
1815 {
1816 case XML_FROM_PARSER:
1817 case XML_FROM_NONE:
1818 case XML_FROM_MEMORY:
1819 case XML_FROM_IO:
1820
1821 /*

Callers

nothing calls this directly

Calls 8

makeStringInfoFunction · 0.85
appendStringInfoFunction · 0.85
appendStringInfoStringFunction · 0.85
chopStringInfoNewlinesFunction · 0.85
appendBinaryStringInfoFunction · 0.85
pfreeFunction · 0.50
errmsg_internalFunction · 0.50

Tested by

no test coverage detected