summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/xml.c
AgeCommit message (Collapse)Author
2011-01-01Stamp copyrights for year 2011.Bruce Momjian
2010-11-23Remove useless whitespace at end of linesPeter Eisentraut
2010-10-21Improve handling of domains over arrays.Tom Lane
This patch eliminates various bizarre behaviors caused by sloppy thinking about the difference between a domain type and its underlying array type. In particular, the operation of updating one element of such an array has to be considered as yielding a value of the underlying array type, *not* a value of the domain, because there's no assurance that the domain's CHECK constraints are still satisfied. If we're intending to store the result back into a domain column, we have to re-cast to the domain type so that constraints are re-checked. For similar reasons, such a domain can't be blindly matched to an ANYARRAY polymorphic parameter, because the polymorphic function is likely to apply array-ish operations that could invalidate the domain constraints. For the moment, we just forbid such matching. We might later wish to insert an automatic downcast to the underlying array type, but such a change should also change matching of domains to ANYELEMENT for consistency. To ensure that all such logic is rechecked, this patch removes the original hack of setting a domain's pg_type.typelem field to match its base type; the typelem will always be zero instead. In those places where it's really okay to look through the domain type with no other logic changes, use the newly added get_base_element_type function in place of get_element_type. catversion bumped due to change in pg_type contents. Per bug #5717 from Richard Huxton and subsequent discussion.
2010-10-15Change references to SQL/XML:2003 to :2008 and renumber sections accordinglyPeter Eisentraut
2010-09-20Remove cvs keywords from all files.Magnus Hagander
2010-08-13Add xml_is_well_formed, xml_is_well_formed_document, xml_is_well_formed_contentTom Lane
functions to the core XML code. Per discussion, the former depends on XMLOPTION while the others do not. These supersede a version previously offered by contrib/xml2. Mike Fowler, reviewed by Pavel Stehule
2010-08-08Add an xpath_exists() function. This is equivalent to XMLEXISTS except thatTom Lane
it offers support for namespace mapping. Mike Fowler, reviewed by David Fetter
2010-08-05Add xmlexists functionPeter Eisentraut
by Mike Fowler, reviewed by Peter Eisentraut
2010-07-06pgindent run for 9.0, second runBruce Momjian
2010-03-03Export xml.c's libxml-error-handling support so that contrib/xml2 can use itTom Lane
too, instead of duplicating the functionality (badly). I renamed xml_init to pg_xml_init, because the former seemed just a bit too generic to be safe as a global symbol. I considered likewise renaming xml_ereport to pg_xml_ereport, but felt that the reference to ereport probably made it sufficiently PG-centric already.
2010-02-14Wrap calls to SearchSysCache and related functions using macros.Robert Haas
The purpose of this change is to eliminate the need for every caller of SearchSysCache, SearchSysCacheCopy, SearchSysCacheExists, GetSysCacheOid, and SearchSysCacheList to know the maximum number of allowable keys for a syscache entry (currently 4). This will make it far easier to increase the maximum number of keys in a future release should we choose to do so, and it makes the code shorter, too. Design and review by Tom Lane.
2010-01-02Update copyright for the year 2010.Bruce Momjian
2009-09-04Fix encoding handling in xml binary input function. If the XML header didn'tHeikki Linnakangas
specify an encoding explicitly, we used to treat it as being in database encoding when we parsed it, but then perform a UTF-8 -> database encoding conversion on it, which was completely bogus. It's now consistently treated as UTF-8.
2009-08-10Extend EXPLAIN to support output in XML or JSON format.Tom Lane
There are probably still some adjustments to be made in the details of the output, but this gets the basic structure in place. Robert Haas
2009-06-118.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef listBruce Momjian
provided by Andrew.
2009-06-10Ensure xmlFree(NULL) is a no-op instead of a core dump. Per report fromTom Lane
Sergey Burladyan, there are at least some dank corners of libxml2 that assume this behavior, even though their published documentation suggests they shouldn't. This is only really a live problem in 8.3, but the code is still there for possible debugging use in HEAD, so patch both branches.
2009-06-09Fix xmlattribute escaping XML special characters twice (bug #4822).Peter Eisentraut
Author: Itagaki Takahiro <itagaki.takahiro@oss.ntt.co.jp>
2009-06-08Fix map_sql_table_to_xmlschema() with dropped attributes.Peter Eisentraut
also backpatched to 8.3
2009-05-13Rewrite xml.c's memory management (yet again). Give up on the idea ofTom Lane
redirecting libxml's allocations into a Postgres context. Instead, just let it use malloc directly, and add PG_TRY blocks as needed to be sure we release libxml data structures in error recovery code paths. This is ugly but seems much more likely to play nicely with third-party uses of libxml, as seen in recent trouble reports about using Perl XML facilities in pl/perl and bug #4774 about contrib/xml2. I left the code for allocation redirection in place, but it's only built/used if you #define USE_LIBXMLCONTEXT. This is because I found it useful to corral libxml's allocations in a palloc context when hunting for libxml memory leaks, and we're surely going to have more of those in the future with this type of approach. But we don't want it turned on in a normal build because it breaks exactly what we need to fix. I have not re-indented most of the code sections that are now wrapped by PG_TRY(); that's for ease of review. pg_indent will fix it. This is a pre-existing bug in 8.3, but I don't dare back-patch this change until it's gotten a reasonable amount of field testing.
2009-05-12Fix intratransaction memory leaks in xml_recv, xmlconcat, xmlroot, andTom Lane
xml_parse, all arising from the same sloppy usage of parse_xml_decl. The original coding had that function returning its output string parameters in the libxml context, which is long-lived, and all but one of its callers neglected to free the strings afterwards. The easiest and most bulletproof fix is to return the strings in the local palloc context instead, since that's short-lived. This was only costing a dozen or two bytes per function call, but that adds up fast if the function is called repeatedly ... Noted while poking at the more general problem of what to do with our libxml memory allocation hooks. Back-patch to 8.3, which has the identical coding.
2009-04-08XMLATTRIBUTES() should send the attribute values throughPeter Eisentraut
map_sql_value_to_xml_value() instead of directly through the data type output function. This is per SQL standard, and consistent with XMLELEMENT().
2009-03-27Add an errdetail explaining why we reject infinite dates and timestampsTom Lane
while converting to XML. Bernd Helmle
2009-03-23Remove munging of xml and xpath params to xpath(). The XML must now be a ↵Andrew Dunstan
well formed XML document.
2009-01-07Fix executor/spi.h to follow our usual conventions for include files, ie,Tom Lane
not include postgres.h nor anything else it doesn't directly need. Add #includes to calling files as needed to compensate. Per my proposal of yesterday. This should be noted as a source code change in the 8.4 release notes, since it's likely to require changes in add-on modules.
2009-01-01Update copyright for 2009.Bruce Momjian
2008-11-10Fix bugs in sqlchar_to_unicode and unicode_to_sqlchar: both were measuringTom Lane
the length of a UTF8 character with pg_mblen (wrong if DB encoding isn't UTF8), and the latter was blithely assuming that a static buffer would somehow revert to all zeroes for each use.
2008-10-29Unicode escapes in strings and identifiersPeter Eisentraut
2008-10-14Extend the date type to support infinity and -infinity, analogously toTom Lane
the timestamp types. Turns out this doesn't even reduce the available range of dates, since the restriction to dates that work for Julian-date arithmetic is much tighter than the int32 range anyway. Per a longstanding TODO item.
2008-10-09Fix crash in bytea-to-XML mapping when the source value is toasted.Tom Lane
Report and fix by Michael McMaster. Some minor code beautification by me, also avoid memory leaks in the special-case paths.
2008-09-16Fix multiple memory leaks in xml_out(). Per report from Matt Magoffin.Tom Lane
2008-08-25Move exprType(), exprTypmod(), expression_tree_walker(), and related routinesTom Lane
into nodes/nodeFuncs, so as to reduce wanton cross-subsystem #includes inside the backend. There's probably more that should be done along this line, but this is a start anyway.
2008-07-03Fix transaction-lifespan memory leak in xpath(). Report by Matt Magoffin,Tom Lane
fix by Kris Jurka.
2008-05-12Restructure some header files a bit, in particular heapam.h, by removing someAlvaro Herrera
unnecessary #include lines in it. Also, move some tuple routine prototypes and macros to htup.h, which allows removal of heapam.h inclusion from some .c files. For this to work, a new header file access/sysattr.h needed to be created, initially containing attribute numbers of system columns, for pg_dump usage. While at it, make contrib ltree, intarray and hstore header files more consistent with our header style.
2008-05-04Use new cstring/text conversion functions in some additional places.Tom Lane
These changes assume that the varchar and xml data types are represented the same as text. (I did not, however, accept the portions of the proposed patch that wanted to assume bytea is the same as text --- tgl.) Brendan Jurd
2008-04-04Turn xmlbinary and xmloption GUC variables into enumsTurn xmlbinary andMagnus Hagander
xmloption GUC variables into enums..
2008-03-25Simplify and standardize conversions between TEXT datums and ordinary CTom Lane
strings. This patch introduces four support functions cstring_to_text, cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and two macros CStringGetTextDatum and TextDatumGetCString. A number of existing macros that provided variants on these themes were removed. Most of the places that need to make such conversions now require just one function or macro call, in place of the multiple notational layers that used to be needed. There are no longer any direct calls of textout or textin, and we got most of the places that were using handmade conversions via memcpy (there may be a few still lurking, though). This commit doesn't make any serious effort to eliminate transient memory leaks caused by detoasting toasted text objects before they reach text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few places where it was easy, but much more could be done. Brendan Jurd and Tom Lane
2008-03-24Fix various infelicities that have snuck into usage of errdetail() andTom Lane
friends. Avoid double translation of some messages, ensure other messages are exposed for translation (and make them follow the style guidelines), avoid unsafe passing of an unpredictable message text as a format string.
2008-03-01Disable the undocumented xmlvalidate() function, which was unintentionallyTom Lane
left in the code though it was not meant to be provided. It represents a security hole because unprivileged users could use it to look at (at least the first line of) any file readable by the backend. Fortunately, this is only possible if the backend was built with XML support, so the damage is at least mitigated; and 8.3 probably hasn't propagated into any security-critical uses yet anyway. Per report from Sergey Burladyan.
2008-01-15Revise memory management for libxml calls. Instead of keeping libxml's dataTom Lane
in whichever context happens to be current during a call of an xml.c function, use a dedicated context that will not go away until we explicitly delete it (which we do at transaction end or subtransaction abort). This makes recovery after an error much simpler --- we don't have to individually delete the data structures created by libxml. Also, we need to initialize and cleanup libxml only once per transaction (if there's no error) instead of once per function call, so it should be a bit faster. We'll need to keep an eye out for intra-transaction memory leaks, though. Alvaro and Tom.
2008-01-12It turns out the LIBXML_TEST_VERSION macro calls xmlInitParser().Tom Lane
Therefore we must xmlCleanupParser(), or we risk leaving behind dangling pointers to whatever memory context is current when xml_init() is called. This seems to fix bug #3860, though we might still want the more invasive solution being worked on by Alvaro.
2008-01-12Fix two places in xml.c that neglected to check the return values ofNeil Conway
SPI_prepare() and SPI_cursor_open(), to silence a Coverity warning.
2008-01-12Minor perf tweak for _SPI_strdup(): if we're going to call strlen()Neil Conway
anyway, it is faster to memcpy() than to strcpy().
2008-01-01Update copyrights in source tree to 2008.Bruce Momjian
2007-11-28Fix XML Schema structure for char types without length (bug #3782)Peter Eisentraut
2007-11-27Suppress compiler warning.Tom Lane
2007-11-27Make casts from xml to text independent of the XML option setting, thusPeter Eisentraut
immutable and indexable. Also fix the volatility settings of some other XML-related functions.
2007-11-25Use double quotes for quoting xml attributes.Peter Eisentraut
2007-11-20Fix bogus length calculation that could lead to crash if the stringTom Lane
happened to be right up against the end of memory, per report from Matt Magoffin. While at it, avoid useless multiple copying of string by not depending on xmlStrncatNew.
2007-11-15Re-run pgindent with updated list of typedefs. (Updated README shouldBruce Momjian
avoid this problem in the future.)
2007-11-15pgindent run for 8.3.Bruce Momjian