/* Helper routines for parsing XML using Expat.
- Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 2006-2019 Free Software Foundation, Inc.
This file is part of GDB.
#define XML_SUPPORT_H
#include "gdb_obstack.h"
-#include "vec.h"
+#include "common/vec.h"
+#include "common/xml-utils.h"
+#include "common/byte-vector.h"
struct gdb_xml_parser;
struct gdb_xml_element;
extern const char *xml_builtin[][2];
-/* Return a malloc allocated string with special characters from TEXT
- replaced by entity references. */
-
-char *xml_escape_text (const char *text);
-
/* Support for XInclude. */
/* Callback to fetch a new XML file, based on the provided HREF. */
-typedef char *(*xml_fetch_another) (const char *href, void *baton);
+typedef gdb::optional<gdb::char_vector> (*xml_fetch_another) (const char *href,
+ void *baton);
-/* Return a new string which is the expansion of TEXT after processing
- <xi:include> tags. FETCHER will be called (with FETCHER_BATON) to
- retrieve any new files. DEPTH should be zero on the initial call.
+/* Append the expansion of TEXT after processing <xi:include> tags in
+ RESULT. FETCHER will be called (with FETCHER_BATON) to retrieve
+ any new files. DEPTH should be zero on the initial call.
- On failure, this function uses NAME in a warning and returns NULL.
+ On failure, this function uses NAME in a warning and returns false.
It may throw an exception, but does not for XML parsing
problems. */
-char *xml_process_xincludes (const char *name, const char *text,
- xml_fetch_another fetcher, void *fetcher_baton,
- int depth);
+bool xml_process_xincludes (std::string &result,
+ const char *name, const char *text,
+ xml_fetch_another fetcher, void *fetcher_baton,
+ int depth);
/* Simplified XML parser infrastructure. */
struct gdb_xml_value
{
+ gdb_xml_value (const char *name_, void *value_)
+ : name (name_), value (value_)
+ {}
+
const char *name;
- void *value;
+ gdb::unique_xmalloc_ptr<void> value;
};
-typedef struct gdb_xml_value gdb_xml_value_s;
-DEF_VEC_O(gdb_xml_value_s);
/* The type of an attribute handler.
typedef void (gdb_xml_element_start_handler)
(struct gdb_xml_parser *parser, const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes);
+ void *user_data, std::vector<gdb_xml_value> &attributes);
/* A handler called at the end of an element.
gdb_xml_element_end_handler *end_handler;
};
-/* Initialize and return a parser. Register a cleanup to destroy the
- parser. */
-
-struct gdb_xml_parser *gdb_xml_create_parser_and_cleanup
- (const char *name, const struct gdb_xml_element *elements,
- void *user_data);
-
-/* Associate DTD_NAME, which must be the name of a compiled-in DTD,
- with PARSER. */
-
-void gdb_xml_use_dtd (struct gdb_xml_parser *parser, const char *dtd_name);
-
-/* Invoke PARSER on BUFFER. BUFFER is the data to parse, which
- should be NUL-terminated.
+/* Parse a XML document. DOCUMENT is the data to parse, which should
+ be NUL-terminated. If non-NULL, use the compiled-in DTD named
+ DTD_NAME to drive the parsing.
The return value is 0 for success or -1 for error. It may throw,
but only if something unexpected goes wrong during parsing; parse
errors will be caught, warned about, and reported as failure. */
-int gdb_xml_parse (struct gdb_xml_parser *parser, const char *buffer);
+int gdb_xml_parse_quick (const char *name, const char *dtd_name,
+ const struct gdb_xml_element *elements,
+ const char *document, void *user_data);
/* Issue a debugging message from one of PARSER's handlers. */
void gdb_xml_debug (struct gdb_xml_parser *parser, const char *format, ...)
- ATTRIBUTE_PRINTF (2, 0);
+ ATTRIBUTE_PRINTF (2, 3);
/* Issue an error message from one of PARSER's handlers, and stop
parsing. */
void gdb_xml_error (struct gdb_xml_parser *parser, const char *format, ...)
- ATTR_NORETURN ATTRIBUTE_PRINTF (2, 0);
+ ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
+
+/* Find the attribute named NAME in the set of parsed attributes
+ ATTRIBUTES. Returns NULL if not found. */
+
+struct gdb_xml_value *xml_find_attribute
+ (std::vector<gdb_xml_value> &attributes, const char *name);
/* Parse an integer attribute into a ULONGEST. */
ULONGEST gdb_xml_parse_ulongest (struct gdb_xml_parser *parser,
const char *value);
-/* Simple printf to obstack function. Current implemented formatters:
- %s - grow an xml escaped text in OBSTACK. */
-
-extern void obstack_xml_printf (struct obstack *obstack,
- const char *format, ...)
- ATTRIBUTE_PRINTF_2;
-
/* Open FILENAME, read all its text into memory, close it, and return
- the text. If something goes wrong, return NULL and warn. */
+ the text. If something goes wrong, return an uninstantiated optional
+ and warn. */
-extern char *xml_fetch_content_from_file (const char *filename,
- void *baton);
+extern gdb::optional<gdb::char_vector> xml_fetch_content_from_file
+ (const char *filename, void *baton);
#endif