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

Bounded XHTML-to-RABOOK streaming builder. More...

#include <stddef.h>
#include <stdint.h>
#include "book.h"
#include "ra8_err.h"
#include "rabook_compile.h"
#include "xml.h"
Include dependency graph for ra8_rabook_xml_shim.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_rabook_xml_workspace_t
 Caller-owned storage for one parser invocation. More...

Enumerations

enum  ra8_rabook_xml_limits_t : uint16_t {
  k_ra8_rabook_xml_max_attributes = 32U ,
  k_ra8_rabook_xml_body_siblings = 256U
}
 XHTML consumer limits matching the established format contract. More...

Functions

ra8_err_t ra8_rabook_xml_parse_chapter (const uint8_t *xhtml_bytes, size_t xhtml_len, ra8_rabook_ctx_t *ctx, const char *chapter_href, const char *chapter_title, ra8_rabook_xml_workspace_t *workspace)
 Parse one XHTML chapter and append it to ctx.

Detailed Description

Bounded XHTML-to-RABOOK streaming builder.

Converts immutable XHTML into the canonical RABOOK DOM using a strict no-heap XML pull reader and explicit caller-owned workspace.

[Ring 4 / EPUB Compiler] {World: NS}

Definition in file ra8_rabook_xml_shim.h.

Enumeration Type Documentation

◆ ra8_rabook_xml_limits_t

enum ra8_rabook_xml_limits_t : uint16_t

XHTML consumer limits matching the established format contract.

Enumerator
k_ra8_rabook_xml_max_attributes 

Attributes accepted per element.

k_ra8_rabook_xml_body_siblings 

Direct children searched for body.

Definition at line 29 of file ra8_rabook_xml_shim.h.

Function Documentation

◆ ra8_rabook_xml_parse_chapter()

ra8_err_t ra8_rabook_xml_parse_chapter ( const uint8_t * xhtml_bytes,
size_t xhtml_len,
ra8_rabook_ctx_t * ctx,
const char * chapter_href,
const char * chapter_title,
ra8_rabook_xml_workspace_t * workspace )
nodiscard

Parse one XHTML chapter and append it to ctx.

Validates all immutable source bytes before modifying ctx. A direct <body> child among at most 256 root element children is emitted. A document exceeding that bounded search is rejected; when the complete bounded set has no body, the document root is emitted. Text and attributes are entity-decoded; inter-element whitespace is preserved; comments, PIs, and CDATA are skipped.

Parameters
[in]xhtml_bytesImmutable complete XHTML byte sequence.
[in]xhtml_lenExact readable extent of xhtml_bytes in bytes.
[in,out]ctxInitialised builder receiving one chapter on success.
[in]chapter_hrefNUL-terminated immutable chapter identity.
[in]chapter_titleNUL-terminated immutable chapter title.
[in,out]workspaceExclusive caller-owned parser and builder scratch.
Return values
k_ra8_okChapter appended.
k_ra8_err_null_ptrA required pointer is NULL.
k_ra8_err_invalid_sizexhtml_len is zero or exceeds UINT32_MAX.
k_ra8_err_validation_failedXML is malformed, too deeply nested, or exceeds the bounded body search.
k_ra8_err_no_memBuilder or attribute capacity is exhausted.
Precondition
Every source/string argument remains readable and immutable for the call.
ctx is initialized; its storage and workspace are writable, non-overlapping, and not used by another live operation.
Postcondition
Any failure restores ctx to its entry state; bytes written beyond the restored active counts and all workspace bytes are unspecified scratch.
On success the chapter is canonical and all input bytes remain unchanged.
The function performs no dynamic allocation.
Note
Thread-safe for distinct contexts and workspaces.
Since
0.1.0

Definition at line 608 of file ra8_rabook_xml_shim.c.

References ra8_rabook_ctx_t::failed, internal_emit(), internal_parse_chapter_validate_args(), internal_select(), k_book_nil, k_ra8_err_no_mem, k_ra8_err_validation_failed, k_ra8_ok, ra8_rabook_add_chapter(), ra8_rabook_intern(), ra8_rabook_xml_workspace_t::xml, and xml_validate().

Referenced by internal_compile_chapters().