|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Bounded no-heap XML pull-reader implementation. More...
#include "xml.h"#include <limits.h>#include <string.h>#include "ra8_attributes.h"#include "xml_internal.h"#include "xml_reader_internal.h"Go to the source code of this file.
Functions | |
| static bool | internal_space (uint8_t c) |
| static bool | internal_ascii_letter (uint8_t c) |
| static bool | internal_name_start (uint8_t c) |
| static bool | internal_name_continue (uint8_t c) |
| ra8_err_t | priv_xml_qname (const uint8_t *source, size_t end, size_t start, size_t *out_end) |
| Scan the supported QName subset over a bounded byte range. | |
| void | xml_attr_begin (const xml_event_t *event, xml_attr_cursor_t *cursor) |
| Initialise source-order attribute iteration for a start event. | |
| static ra8_err_t | internal_attr_value (const uint8_t *source, uint32_t end, uint32_t *position, xml_attribute_t *out) |
| Parse the equals sign, quote, and value of one XML attribute. | |
| static ra8_err_t | internal_attr_parse (const uint8_t *source, size_t source_len, uint32_t end, xml_attr_cursor_t *cursor, xml_attribute_t *out) |
| static bool | internal_attr_duplicate (const uint8_t *source, size_t source_len, const xml_event_t *event, const xml_attribute_t *current, uint16_t prior_count) |
| ra8_err_t | xml_attr_next (const uint8_t *source, size_t source_len, const xml_event_t *event, xml_attr_cursor_t *cursor, xml_attribute_t *out_attribute, bool *out_has_value) |
| Return the next source-order attribute. | |
| static ra8_err_t | internal_markup_end (const uint8_t *source, size_t length, size_t start, size_t *out_end) |
| static ra8_err_t | internal_attributes (const uint8_t *source, size_t source_len, xml_event_t *event) |
| static ra8_err_t | internal_start (xml_reader_t *reader, size_t end, xml_event_t *event) |
| static ra8_err_t | internal_end (xml_reader_t *reader, size_t end, xml_event_t *event) |
| static ra8_err_t | internal_terminator (const uint8_t *source, size_t length, size_t start, const char *terminator, size_t *out_start) |
| static ra8_err_t | internal_comment (xml_reader_t *reader) |
| static bool | internal_xml_target (const uint8_t *source, size_t start, size_t end) |
| static bool | internal_encoding (const uint8_t *source, xml_span_t value) |
| static bool | internal_declaration_attr (const uint8_t *source, size_t source_len, const xml_attribute_t *attribute, uint16_t ordinal, bool *saw_encoding, bool *saw_standalone) |
| static ra8_err_t | internal_declaration (xml_reader_t *reader, size_t target_end, size_t term) |
| static ra8_err_t | internal_pi (xml_reader_t *reader) |
| static ra8_err_t | internal_cdata (xml_reader_t *reader, xml_event_t *event) |
| static ra8_err_t | internal_special (xml_reader_t *reader, xml_event_t *event, bool *out_emitted) |
| static ra8_err_t | internal_text (xml_reader_t *reader, xml_event_t *event) |
| ra8_err_t | xml_reader_init (xml_reader_t *reader, const uint8_t *source, size_t source_len, xml_workspace_t *workspace) |
| Initialise a pull pass over immutable bytes. | |
| ra8_err_t | xml_reader_next (xml_reader_t *reader, xml_event_t *out_event) |
| Return the next semantic event and validate syntax incrementally. | |
| ra8_err_t | xml_validate (const uint8_t *source, size_t source_len, xml_workspace_t *workspace) |
| Validate a complete document before any consumer mutation. | |
Bounded no-heap XML pull-reader implementation.
Implements strict UTF-8/XML 1.0 lexical validation, bounded entity decoding, attribute traversal, and source-aliasing pull events using only caller-owned stack storage.
[Ring 3 / LIB] {World: NS}
Definition in file xml.c.
|
static |
|
static |
Definition at line 158 of file xml.c.
References internal_attr_parse(), k_ra8_ok, xml_span_t::length, memcmp(), xml_attribute_t::name, xml_span_t::offset, RA8_INTERNAL, and xml_attr_begin().
Referenced by internal_attributes().
|
static |
Definition at line 131 of file xml.c.
References xml_attr_cursor_t::emitted, internal_attr_value(), internal_space(), k_ra8_err_validation_failed, k_ra8_ok, xml_attribute_t::name, xml_attr_cursor_t::position, priv_xml_qname(), RA8_INTERNAL, xml_attribute_t::value, and xml_decoded_size().
Referenced by internal_attr_duplicate(), internal_attributes(), internal_declaration(), and xml_attr_next().
|
static |
Parse the equals sign, quote, and value of one XML attribute.
Skips allowed XML whitespace, requires a quoted value, rejects a literal less-than sign, and advances the caller past the closing quote.
| [in] | source | Complete immutable XML source. |
| [in] | end | Exclusive end of the current start-tag payload. |
| [in,out] | position | Cursor just past the attribute name. |
| [out] | out | Attribute whose value span receives the parsed range. |
| k_ra8_ok | A quoted value was parsed and position advanced. |
| k_ra8_err_validation_failed | The separator or value is malformed. |
source, position, and out are non-NULL. source is readable through end. position. position. Definition at line 98 of file xml.c.
References internal_space(), k_ra8_err_validation_failed, k_ra8_ok, and xml_attribute_t::value.
Referenced by internal_attr_parse().
|
static |
Definition at line 231 of file xml.c.
References internal_attr_duplicate(), internal_attr_parse(), internal_space(), internal_space(), k_ra8_err_validation_failed, k_ra8_ok, xml_attr_cursor_t::position, xml_event_t::self_closing, and xml_attr_begin().
Referenced by internal_start().
|
static |
Definition at line 492 of file xml.c.
References internal_terminator(), k_priv_xml_cdata_open_bytes, k_ra8_err_validation_failed, k_ra8_ok, k_xml_event_cdata, xml_reader_t::position, priv_xml_raw(), RA8_INTERNAL, xml_reader_t::source, xml_reader_t::source_len, and xml_reader_t::stack_size.
Referenced by internal_special().
|
static |
Definition at line 362 of file xml.c.
References internal_terminator(), k_ra8_err_validation_failed, k_ra8_ok, xml_reader_t::position, priv_xml_raw(), RA8_INTERNAL, xml_reader_t::source, and xml_reader_t::source_len.
Referenced by internal_special().
|
static |
Definition at line 424 of file xml.c.
References xml_reader_t::declaration_seen, internal_attr_parse(), internal_declaration_attr(), internal_space(), k_priv_utf8_bom_first, k_ra8_err_validation_failed, k_ra8_ok, xml_attr_cursor_t::position, xml_reader_t::position, xml_reader_t::root_count, xml_reader_t::source, and xml_reader_t::source_len.
Referenced by internal_pi().
|
static |
Definition at line 399 of file xml.c.
References internal_encoding(), xml_attribute_t::name, RA8_INTERNAL, xml_attribute_t::value, and xml_span_equal().
Referenced by internal_declaration().
|
static |
Definition at line 392 of file xml.c.
References k_priv_xml_encoding_bytes, xml_span_t::length, xml_span_t::offset, priv_xml_bytes_equal(), and RA8_INTERNAL.
Referenced by internal_declaration_attr().
|
static |
Definition at line 313 of file xml.c.
References xml_workspace_t::frames, internal_space(), k_ra8_err_validation_failed, k_ra8_ok, k_xml_event_end, memcmp(), xml_frame_t::name_length, xml_frame_t::name_offset, xml_reader_t::position, priv_xml_qname(), RA8_INTERNAL, xml_reader_t::root_closed, xml_reader_t::source, xml_reader_t::stack_size, and xml_reader_t::workspace.
Referenced by xml_reader_next().
|
static |
Definition at line 207 of file xml.c.
References k_ra8_err_validation_failed, and k_ra8_ok.
Referenced by xml_reader_next().
|
static |
Definition at line 41 of file xml.c.
References internal_name_start(), and RA8_INTERNAL.
Referenced by priv_xml_qname().
|
static |
Definition at line 36 of file xml.c.
References internal_ascii_letter(), and RA8_INTERNAL.
Referenced by internal_name_continue(), and priv_xml_qname().
|
static |
Definition at line 465 of file xml.c.
References internal_declaration(), internal_space(), internal_terminator(), internal_xml_target(), k_ra8_err_validation_failed, k_ra8_ok, xml_reader_t::position, priv_xml_bytes_equal(), priv_xml_qname(), priv_xml_raw(), RA8_INTERNAL, xml_reader_t::source, and xml_reader_t::source_len.
Referenced by internal_special().
|
static |
Definition at line 24 of file xml.c.
References RA8_INTERNAL.
Referenced by internal_attr_parse(), internal_attr_value(), internal_attributes(), internal_end(), internal_pi(), internal_start(), and internal_text().
|
static |
Definition at line 515 of file xml.c.
References internal_cdata(), internal_comment(), internal_pi(), k_priv_xml_cdata_open_bytes, k_priv_xml_doctype_open_bytes, k_ra8_err_validation_failed, k_ra8_ok, xml_reader_t::position, priv_xml_bytes_equal(), priv_xml_doctype(), xml_reader_t::source, and xml_reader_t::source_len.
Referenced by xml_reader_next().
|
static |
Definition at line 272 of file xml.c.
References xml_workspace_t::frames, internal_attributes(), internal_space(), k_ra8_err_validation_failed, k_ra8_ok, k_xml_event_start, k_xml_max_element_depth, xml_span_t::length, xml_event_t::name, xml_reader_t::position, priv_xml_qname(), RA8_INTERNAL, xml_reader_t::root_closed, xml_reader_t::root_count, xml_event_t::self_closing, xml_reader_t::source, xml_reader_t::source_len, xml_reader_t::stack_size, and xml_reader_t::workspace.
Referenced by xml_reader_next().
|
static |
Definition at line 346 of file xml.c.
References k_ra8_err_validation_failed, k_ra8_ok, priv_xml_bytes_equal(), RA8_INTERNAL, and strlen().
Referenced by internal_cdata(), internal_comment(), and internal_pi().
|
static |
Definition at line 539 of file xml.c.
References internal_space(), k_ra8_err_validation_failed, k_ra8_ok, k_xml_event_text, xml_reader_t::position, RA8_INTERNAL, xml_reader_t::source, xml_reader_t::source_len, xml_reader_t::stack_size, and xml_decoded_size().
Referenced by xml_reader_next().
|
static |
| ra8_err_t priv_xml_qname | ( | const uint8_t * | source, |
| size_t | end, | ||
| size_t | start, | ||
| size_t * | out_end ) |
Scan the supported QName subset over a bounded byte range.
Accepts one or two ASCII NCName components separated by one colon.
| [in] | source | Immutable XML source. |
| [in] | end | One-past-last readable lexical byte. |
| [in] | start | Candidate QName start offset. |
| [out] | out_end | One-past-last accepted QName byte. |
| k_ra8_ok | At least one valid QName component was consumed. |
| k_ra8_err_validation_failed | Start or namespace spelling was invalid. |
source spans at least end readable bytes. out_end is writable and does not overlap source. Definition at line 47 of file xml.c.
References internal_name_continue(), internal_name_start(), k_ra8_err_validation_failed, and k_ra8_ok.
Referenced by internal_attr_parse(), internal_end(), internal_pi(), internal_start(), and priv_xml_doctype().
| void xml_attr_begin | ( | const xml_event_t * | event, |
| xml_attr_cursor_t * | cursor ) |
Initialise source-order attribute iteration for a start event.
Derives the first attribute position from the event's bounded name span.
| [in] | event | Valid start event returned by the reader. |
| [out] | cursor | Attribute cursor to initialise. |
event aliases the same live source later passed to xml_attr_next. cursor does not overlap event. cursor addresses the first attribute. Definition at line 70 of file xml.c.
References xml_attr_cursor_t::emitted, and xml_attr_cursor_t::position.
Referenced by internal_attr_duplicate(), internal_attributes(), internal_attributes(), and priv_epub_xml_attr().
|
nodiscard |
Return the next source-order attribute.
| [in] | source | Immutable source that produced event. |
| [in] | source_len | Exact readable extent of source. |
| [in] | event | Start event whose attributes are being traversed. |
| [in,out] | cursor | Cursor initialised by xml_attr_begin. |
| [out] | out_attribute | Next source-aliasing name/value spans. |
| [out] | out_has_value | False after the final attribute. |
| k_ra8_ok | An attribute or the clean end of the sequence was reported. |
| k_ra8_err_null_ptr | A required pointer is NULL. |
| k_ra8_err_validation_failed | An event/span/cursor is stale or malformed. |
source spans exactly source_len readable bytes and remains live. event came from that same source and cursor belongs to event. source_len and the cursor advances once; on clean end, out_attribute is unchanged. source and event are never modified. cursor and out_attribute; progress may be partial. Definition at line 181 of file xml.c.
References xml_event_t::attribute_count, xml_attr_cursor_t::emitted, internal_attr_parse(), k_ra8_err_null_ptr, k_ra8_err_validation_failed, k_ra8_ok, xml_span_t::length, xml_event_t::markup, xml_event_t::name, and priv_xml_span_valid().
Referenced by internal_attributes(), and priv_epub_xml_attr().
|
nodiscard |
Initialise a pull pass over immutable bytes.
| [out] | reader | Reader state to initialise. |
| [in] | source | Immutable complete XML byte sequence. |
| [in] | source_len | Exact readable extent of source in bytes. |
| [in,out] | workspace | Exclusive caller-owned element-stack storage. |
| k_ra8_ok | Reader ready. |
| k_ra8_err_null_ptr | A required pointer is NULL. |
| k_ra8_err_invalid_size | source_len is zero or exceeds UINT32_MAX. |
source remains readable and immutable for the complete pull pass. source_len is the source's true readable extent, not a sentinel length. workspace is not shared with another live reader. reader owns no source bytes and starts before the first event. source and workspace are unchanged. Definition at line 571 of file xml.c.
References k_priv_utf8_bom_first, k_priv_utf8_bom_second, k_priv_utf8_bom_third, k_ra8_err_invalid_size, k_ra8_err_null_ptr, k_ra8_ok, and xml_reader_t::position.
Referenced by internal_emit(), internal_select(), priv_epub_xml_reader(), and xml_validate().
|
nodiscard |
Return the next semantic event and validate syntax incrementally.
| [in,out] | reader | Active pull pass. |
| [out] | out_event | Next source-aliasing event. |
| k_ra8_ok | Event returned, or kind==none at validated EOF. |
| k_ra8_err_null_ptr | reader or out_event is NULL. |
| k_ra8_err_validation_failed | Malformed XML or depth overflow. |
reader was initialised successfully and its source remains live. Definition at line 590 of file xml.c.
References xml_reader_t::finished, internal_end(), internal_markup_end(), internal_special(), internal_start(), internal_text(), k_ra8_err_null_ptr, k_ra8_err_validation_failed, k_ra8_ok, xml_reader_t::position, xml_reader_t::root_closed, xml_reader_t::root_count, xml_reader_t::source, xml_reader_t::source_len, and xml_reader_t::stack_size.
Referenced by internal_collect_spine(), internal_emit(), internal_manifest_lookup(), internal_nav_has_list(), internal_opf_first(), internal_opf_shape(), internal_select(), internal_select_nav(), internal_toc_capacity(), priv_epub_xml_find(), priv_epub_xml_parse_nav(), priv_epub_xml_parse_ncx(), and xml_validate().
|
nodiscard |
Validate a complete document before any consumer mutation.
| [in] | source | Immutable complete XML byte sequence. |
| [in] | source_len | Exact readable extent of source. |
| [in,out] | workspace | Exclusive caller-owned validation stack. |
| k_ra8_ok | Document is well formed within the depth bound. |
| k_ra8_err_null_ptr | A required pointer is NULL. |
| k_ra8_err_invalid_size | source_len is zero or exceeds UINT32_MAX. |
| k_ra8_err_validation_failed | Document is malformed. |
source spans exactly source_len readable bytes. workspace is not shared by another live reader. source is byte-for-byte unchanged on success and failure. Definition at line 631 of file xml.c.
References k_ra8_ok, k_xml_event_none, xml_reader_init(), and xml_reader_next().
Referenced by priv_epub_xml_parse_container(), priv_epub_xml_parse_nav(), priv_epub_xml_parse_ncx(), priv_epub_xml_parse_opf(), and ra8_rabook_xml_parse_chapter().