aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-11-07 10:27:52 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-11-07 10:27:52 -0500
commitc59f94e81e56fe24428952f116f3c9555f42cc4f (patch)
treef12da95493c4e82a19de6823339c19628c0b8159
parent33cb96ba1a84c612491fb5794674a649d1a6a4d6 (diff)
downloadpostgresql-c59f94e81e56fe24428952f116f3c9555f42cc4f.tar.gz
postgresql-c59f94e81e56fe24428952f116f3c9555f42cc4f.zip
Revert "Delete contrib/xml2's legacy implementation of xml_is_well_formed()."
This partly reverts commit 20540710e83f2873707c284a0c0693f0b57156c4. Since we've given up on adding PGDLLEXPORT markers to PG_FUNCTION_INFO_V1, there's no need to remove the legacy compatibility function. I kept the documentation changes, though, as they seem appropriate anyway.
-rw-r--r--contrib/xml2/xpath.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
index 28445be3690..ac28996867b 100644
--- a/contrib/xml2/xpath.c
+++ b/contrib/xml2/xpath.c
@@ -81,6 +81,51 @@ pgxml_parser_init(PgXmlStrictness strictness)
}
+/*
+ * Returns true if document is well-formed
+ *
+ * Note: this has been superseded by a core function. We still have to
+ * have it in the contrib module so that existing SQL-level references
+ * to the function won't fail; but in normal usage with up-to-date SQL
+ * definitions for the contrib module, this won't be called.
+ */
+
+PG_FUNCTION_INFO_V1(xml_is_well_formed);
+
+Datum
+xml_is_well_formed(PG_FUNCTION_ARGS)
+{
+ text *t = PG_GETARG_TEXT_P(0); /* document buffer */
+ bool result = false;
+ int32 docsize = VARSIZE(t) - VARHDRSZ;
+ xmlDocPtr doctree;
+ PgXmlErrorContext *xmlerrcxt;
+
+ xmlerrcxt = pgxml_parser_init(PG_XML_STRICTNESS_LEGACY);
+
+ PG_TRY();
+ {
+ doctree = xmlParseMemory((char *) VARDATA(t), docsize);
+
+ result = (doctree != NULL);
+
+ if (doctree != NULL)
+ xmlFreeDoc(doctree);
+ }
+ PG_CATCH();
+ {
+ pg_xml_done(xmlerrcxt, true);
+
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
+
+ pg_xml_done(xmlerrcxt, false);
+
+ PG_RETURN_BOOL(result);
+}
+
+
/* Encodes special characters (<, >, &, " and \r) as XML entities */
PG_FUNCTION_INFO_V1(xml_encode_special_chars);