ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
xml_doctype.c File Reference

Bounded external-only DOCTYPE lexer for the no-heap XML reader. More...

#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "xml_internal.h"
Include dependency graph for xml_doctype.c:

Go to the source code of this file.

Functions

static bool internal_space (uint8_t byte)
 Test whether one byte is XML spacing inside a DOCTYPE.
static bool internal_skip_space (const uint8_t *source, size_t end, size_t *position)
 Skip XML spacing and report whether at least one byte was consumed.
static bool internal_pubid_byte (uint8_t byte)
 Test the XML PubidChar subset accepted in public identifiers.
static ra8_err_t internal_literal (const uint8_t *source, size_t end, size_t *position, bool public_id)
 Parse one quoted system or public identifier literal.
static ra8_err_t internal_keyword (const uint8_t *source, size_t end, size_t *position, const char *keyword)
 Consume an exact ASCII keyword followed by required spacing.
static ra8_err_t internal_external_id (const uint8_t *source, size_t end, size_t *position)
 Parse a SYSTEM or PUBLIC external identifier.
ra8_err_t priv_xml_doctype (xml_reader_t *reader)
 Validate and skip one supported pre-root external DOCTYPE.

Detailed Description

Bounded external-only DOCTYPE lexer for the no-heap XML reader.

Accepts and ignores lexically valid bare, SYSTEM, and PUBLIC declarations before the root without resolving external resources; internal subsets and unsupported declaration forms fail closed.

[Ring 3 / LIB] {World: NS}

Definition in file xml_doctype.c.

Function Documentation

◆ internal_external_id()

ra8_err_t internal_external_id ( const uint8_t * source,
size_t end,
size_t * position )
static

Parse a SYSTEM or PUBLIC external identifier.

Accepts SYSTEM literal or PUBLIC identifier plus system literal.

Parameters
[in]sourceImmutable XML source.
[in]endOne-past-last readable declaration byte.
[in,out]positionOffset at the external identifier keyword.
Returns
Repository error code.
Return values
k_ra8_okOne valid external identifier consumed.
k_ra8_err_validation_failedIdentifier grammar was malformed.
Precondition
source spans at least end bytes.
*position <= end and position is writable.
Postcondition
Success leaves position after the final literal.
Failure leaves source unchanged; position may be partial.
Note
External identifiers are checked but never resolved.
Since
0.1.0

Definition at line 177 of file xml_doctype.c.

References internal_keyword(), internal_literal(), internal_skip_space(), k_ra8_err_validation_failed, k_ra8_ok, and priv_xml_bytes_equal().

Referenced by priv_xml_doctype().

◆ internal_keyword()

ra8_err_t internal_keyword ( const uint8_t * source,
size_t end,
size_t * position,
const char * keyword )
static

Consume an exact ASCII keyword followed by required spacing.

Matches case-sensitively without reading beyond end.

Parameters
[in]sourceImmutable XML source.
[in]endOne-past-last readable declaration byte.
[in,out]positionCurrent keyword offset.
[in]keywordNUL-terminated expected ASCII keyword.
Returns
Repository error code.
Return values
k_ra8_okKeyword and following XML spacing consumed.
k_ra8_err_validation_failedBytes or required spacing did not match.
Precondition
source spans at least end bytes.
position and keyword are valid inputs.
Postcondition
Success advances beyond at least one spacing byte.
Failure leaves source unchanged; position may be partial.
Note
Matching is intentionally case-sensitive.
Since
0.1.0

Definition at line 149 of file xml_doctype.c.

References internal_skip_space(), k_ra8_err_validation_failed, k_ra8_ok, priv_xml_bytes_equal(), and strlen().

Referenced by internal_external_id().

◆ internal_literal()

ra8_err_t internal_literal ( const uint8_t * source,
size_t end,
size_t * position,
bool public_id )
static

Parse one quoted system or public identifier literal.

Respects either quote and validates optional PubidChar bytes.

Parameters
[in]sourceImmutable XML source.
[in]endOne-past-last readable declaration byte.
[in,out]positionOffset of the opening quote, then byte after closure.
[in]public_idRequire XML PubidChar bytes when true.
Returns
Repository error code.
Return values
k_ra8_okLiteral validated and consumed.
k_ra8_err_validation_failedQuote, byte, or terminator was invalid.
Precondition
source spans at least end bytes.
*position <= end and position is writable.
Postcondition
Success advances after the matching closing quote.
Failure leaves source unchanged; position may be partial.
Note
No resource named by the literal is fetched.
Since
0.1.0

Definition at line 108 of file xml_doctype.c.

References internal_pubid_byte(), k_ra8_err_validation_failed, k_ra8_ok, and priv_xml_raw().

Referenced by internal_external_id().

◆ internal_pubid_byte()

bool internal_pubid_byte ( uint8_t byte)
static

Test the XML PubidChar subset accepted in public identifiers.

Accepts XML spacing, alphanumerics, and XML punctuation.

Parameters
[in]byteByte to classify.
Returns
True exactly for one supported PubidChar.
Return values
truebyte is permitted.
falsebyte is forbidden.
Precondition
byte is an unsigned source byte.
Public identifiers use XML's ASCII PubidChar set.
Postcondition
No memory is modified.
The result depends only on byte.
Note
Pure and thread-safe.
Since
0.1.0

Definition at line 80 of file xml_doctype.c.

References RA8_INTERNAL, and strchr().

Referenced by internal_literal().

◆ internal_skip_space()

bool internal_skip_space ( const uint8_t * source,
size_t end,
size_t * position )
static

Skip XML spacing and report whether at least one byte was consumed.

Advances only inside the supplied half-open byte range.

Parameters
[in]sourceImmutable XML source.
[in]endOne-past-last readable byte for this declaration.
[in,out]positionCurrent scan offset.
Returns
True when at least one spacing byte was skipped.
Return values
truePosition advanced.
falseNo XML spacing began at the position.
Precondition
source spans at least end bytes.
*position <= end and position is writable.
Postcondition
Position never exceeds end.
Source bytes remain unchanged.
Note
Pure with respect to source bytes.
Since
0.1.0

Definition at line 57 of file xml_doctype.c.

References internal_space(), and RA8_INTERNAL.

Referenced by internal_external_id(), internal_keyword(), and priv_xml_doctype().

◆ internal_space()

bool internal_space ( uint8_t byte)
static

Test whether one byte is XML spacing inside a DOCTYPE.

Recognises the four XML S characters without locale state.

Parameters
[in]byteByte to classify.
Returns
True exactly for XML spacing.
Return values
truebyte is XML spacing.
falsebyte is not XML spacing.
Precondition
byte is an unsigned source byte.
Locale-dependent ctype state is not consulted.
Postcondition
No memory is modified.
The result depends only on byte.
Note
Pure and thread-safe.
Since
0.1.0

Definition at line 35 of file xml_doctype.c.

References RA8_INTERNAL.

Referenced by internal_skip_space().

◆ priv_xml_doctype()

ra8_err_t priv_xml_doctype ( xml_reader_t * reader)

Validate and skip one supported pre-root external DOCTYPE.

Accepts bare, SYSTEM, or PUBLIC external-only forms and fetches nothing.

Parameters
[in,out]readerActive reader positioned at <!DOCTYPE.
Returns
Repository error code.
Return values
k_ra8_okSupported declaration consumed.
k_ra8_err_validation_failedPlacement, subset, or grammar was invalid.
Precondition
Reader source/position describe a complete bounded document.
No root or prior DOCTYPE has been consumed.
Postcondition
Success advances after > and marks one DOCTYPE seen.
Failure leaves immutable source bytes unchanged.
Note
Internal subsets and entity declarations fail closed.
Since
0.1.0

Definition at line 196 of file xml_doctype.c.

References xml_reader_t::doctype_seen, internal_external_id(), internal_skip_space(), k_ra8_err_validation_failed, k_ra8_ok, xml_reader_t::position, priv_xml_bytes_equal(), priv_xml_qname(), xml_reader_t::root_count, xml_reader_t::source, and xml_reader_t::source_len.

Referenced by internal_special().