zxsd 0.20.0
Embedded XML Schema validation for C
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
zxsd.h File Reference

Public API for the zxsd XML validation runtime. More...

#include <stddef.h>
#include <stdint.h>
#include "zxsd_version.h"
Include dependency graph for zxsd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  zxsd_result_t
 Structured result returned by every generated validator. More...
 
struct  zxsd_allocator_t
 Optional allocator used by validation features requiring scratch storage. More...
 
struct  zxsd_simple_ref_t
 Reference to a built-in or generated simple type. More...
 
struct  zxsd_simple
 Generated descriptor for a restricted, list or union simple type. More...
 
struct  zxsd_element_t
 Generated descriptor for an element particle. More...
 
struct  zxsd_attribute_t
 Generated descriptor for an XML attribute. More...
 
struct  zxsd_wildcard_t
 XML Schema element or attribute wildcard. More...
 
struct  zxsd_particle
 Recursive descriptor for a compiled content-model particle. More...
 
struct  zxsd_complex
 Generated descriptor for a complex XML Schema type. More...
 
struct  zxsd_xpath_step_t
 One expanded-name step in the restricted identity XPath subset. More...
 
struct  zxsd_xpath
 Compiled restricted XPath used by identity constraints. More...
 
struct  zxsd_identity_t
 Compiled xs:unique, xs:key or xs:keyref descriptor. More...
 
struct  zxsd_global_element_t
 Global element declaration available to strict/lax wildcards. More...
 
struct  zxsd_global_attribute_t
 Global attribute declaration available to strict/lax wildcards. More...
 
struct  zxsd_named_type_t
 Named type entry used to resolve runtime xsi:type values. More...
 
struct  zxsd_notation_t
 Global XML Schema notation declaration. More...
 
struct  zxsd_schema_t
 Root descriptor consumed by the generic validation runtime. More...
 
struct  zxsd_stream_model_node_t
 Internal immutable continuation or frontier entry, for static allocation only. More...
 
struct  zxsd_stream_frame_t
 Internal per-element state exposed only to permit static allocation. More...
 
struct  zxsd_stream_namespace_t
 Internal namespace binding retained by the event-driven validator. More...
 
struct  zxsd_stream_t
 Bounded state for the event-driven validator. More...
 
struct  zxsd_xml_reader_t
 Bounded raw-XML reader feeding an event-driven validator. More...
 
struct  zxsd_runtime_config_t
 Caller configuration stamp for a same-toolchain runtime boundary. More...
 

Macros

#define ZXSD_MAX_INPUT   (1024u * 1024u)
 Maximum accepted XML input size, in bytes.
 
#define ZXSD_MAX_DEPTH   32u
 Maximum nesting depth accepted by the embedded XML parser.
 
#define ZXSD_MAX_PARTICLES   32u
 Maximum number of child particles in one complex type.
 
#define ZXSD_MAX_ATTRIBUTES   32u
 Maximum number of attributes in one element.
 
#define ZXSD_MAX_NAMESPACES   16u
 Maximum number of simultaneously active namespace bindings.
 
#define ZXSD_MAX_IDENTITY_ROWS   64u
 Maximum stored tuples per identity constraint.
 
#define ZXSD_MAX_IDENTITY_VALUES   ZXSD_MAX_IDENTITY_ROWS
 Maximum identity values, retained as a compatibility alias for rows.
 
#define ZXSD_MAX_IDENTITY_TEXT   4096u
 Maximum total UTF-8 bytes retained for document ID and IDREF values.
 
#define ZXSD_MAX_IDENTITY_CONSTRAINTS   16u
 Maximum identity constraints attached to one root declaration.
 
#define ZXSD_MAX_IDENTITY_FIELDS   8u
 Maximum fields in one identity-constraint tuple.
 
#define ZXSD_MAX_XPATH_DEPTH   8u
 Maximum number of steps in a compiled identity XPath.
 
#define ZXSD_MAX_XPATH_ALTERNATIVES   8u
 Maximum union branches in one compiled identity XPath.
 
#define ZXSD_STREAM_TEXT_CAPACITY   ZXSD_MAX_TEXT_LENGTH
 Maximum decoded character data retained for one streamed element.
 
#define ZXSD_MAX_TEXT_LENGTH   1024u
 Maximum lexical length of one element or attribute value.
 
#define ZXSD_MAX_PATTERN_LENGTH   4096u
 Maximum UTF-8 byte length of one generated XSD regular expression.
 
#define ZXSD_MAX_REGEX_NODES   512u
 Maximum parsed expression nodes used by the allocation-free regex engine.
 
#define ZXSD_MAX_REGEX_DEPTH   32u
 Maximum parenthesis and character-class subtraction nesting depth.
 
#define ZXSD_MAX_SCHEMA_COMPLEXITY   4096u
 Maximum aggregate descriptor count accepted by the runtime.
 
#define ZXSD_STREAM_NAME_CAPACITY   128u
 Maximum local-name or namespace-URI length accepted by streaming calls.
 
#define ZXSD_STREAM_CHILD_CAPACITY   64u
 Maximum child tokens retained for a streamed model requiring history.
 
#define ZXSD_STREAM_MODEL_CAPACITY   128u
 Shared continuation/state slots for nested streaming content models.
 
#define ZXSD_XML_TOKEN_CAPACITY   4096u
 Maximum bytes retained for one incomplete XML tag, comment, PI, or CDATA section.
 
#define ZXSD_RUNTIME_CONFIG_INIT
 Initialize a runtime stamp using the including translation unit's configuration.
 

Typedefs

typedef void *(* zxsd_allocate_fn) (void *context, size_t size)
 Allocate runtime scratch storage.
 
typedef void(* zxsd_deallocate_fn) (void *context, void *pointer)
 Release runtime scratch storage.
 
typedef struct zxsd_simple zxsd_simple_t
 Generated descriptor for a restricted, list or union simple type.
 
typedef struct zxsd_particle zxsd_particle_t
 Recursive descriptor for a compiled content-model particle.
 
typedef struct zxsd_complex zxsd_complex_t
 Generated descriptor for a complex XML Schema type.
 
typedef struct zxsd_xpath zxsd_xpath_t
 Compiled restricted XPath used by identity constraints.
 
typedef void(* zxsd_xml_event_fn) (void *user_data, zxsd_xml_event_t event, const char *namespace_uri, const char *local_name, const char *value, size_t value_length)
 Observe one decoded event accepted by the incremental validator.
 

Enumerations

enum  zxsd_error_t {
  ZXSD_OK = 0 , ZXSD_ERR_ARGUMENT , ZXSD_ERR_INPUT_TOO_LARGE , ZXSD_ERR_MALFORMED_XML ,
  ZXSD_ERR_EXCESSIVE_NESTING , ZXSD_ERR_WRONG_ROOT , ZXSD_ERR_MISSING_ELEMENT , ZXSD_ERR_UNEXPECTED_ELEMENT ,
  ZXSD_ERR_ELEMENT_ORDER , ZXSD_ERR_OCCURRENCE , ZXSD_ERR_MISSING_ATTRIBUTE , ZXSD_ERR_UNEXPECTED_ATTRIBUTE ,
  ZXSD_ERR_INVALID_VALUE , ZXSD_ERR_TEXT_NOT_ALLOWED , ZXSD_ERR_IDENTITY_CONSTRAINT , ZXSD_ERR_STREAM_LIMIT ,
  ZXSD_ERR_RESOURCE_LIMIT , ZXSD_ERR_OUTPUT , ZXSD_ERR_UNSUPPORTED , ZXSD_ERR_INCOMPATIBLE_ABI
}
 Validation status and error codes. More...
 
enum  zxsd_type_t {
  ZXSD_T_STRING , ZXSD_T_BOOLEAN , ZXSD_T_INT , ZXSD_T_UNSIGNED_INT ,
  ZXSD_T_INTEGER , ZXSD_T_DECIMAL , ZXSD_T_FLOAT , ZXSD_T_DOUBLE ,
  ZXSD_T_LONG , ZXSD_T_SHORT , ZXSD_T_BYTE , ZXSD_T_NON_POSITIVE_INTEGER ,
  ZXSD_T_NEGATIVE_INTEGER , ZXSD_T_NON_NEGATIVE_INTEGER , ZXSD_T_POSITIVE_INTEGER , ZXSD_T_UNSIGNED_LONG ,
  ZXSD_T_UNSIGNED_SHORT , ZXSD_T_UNSIGNED_BYTE , ZXSD_T_NORMALIZED_STRING , ZXSD_T_TOKEN ,
  ZXSD_T_LANGUAGE , ZXSD_T_NAME , ZXSD_T_NCNAME , ZXSD_T_NMTOKEN ,
  ZXSD_T_QNAME , ZXSD_T_ANY_URI , ZXSD_T_DURATION , ZXSD_T_DATE ,
  ZXSD_T_DATE_TIME , ZXSD_T_TIME , ZXSD_T_GYEAR , ZXSD_T_GYEAR_MONTH ,
  ZXSD_T_GMONTH , ZXSD_T_GMONTH_DAY , ZXSD_T_GDAY , ZXSD_T_HEX_BINARY ,
  ZXSD_T_BASE64_BINARY , ZXSD_T_ID , ZXSD_T_IDREF , ZXSD_T_ENTITY ,
  ZXSD_T_NOTATION , ZXSD_T_COMPLEX
}
 Primitive and compound value kinds understood by the runtime. More...
 
enum  zxsd_whitespace_t { ZXSD_WS_PRESERVE = 0 , ZXSD_WS_REPLACE , ZXSD_WS_COLLAPSE }
 Whitespace treatment prescribed by an XML Schema simple type. More...
 
enum  zxsd_simple_variety_t { ZXSD_SIMPLE_ATOMIC = 0 , ZXSD_SIMPLE_LIST , ZXSD_SIMPLE_UNION }
 Variety of an XML Schema simple type. More...
 
enum  zxsd_model_t { ZXSD_SEQUENCE = 0 , ZXSD_CHOICE , ZXSD_ALL }
 Complex content model kind. More...
 
enum  zxsd_process_t { ZXSD_PROCESS_STRICT = 0 , ZXSD_PROCESS_LAX , ZXSD_PROCESS_SKIP }
 Wildcard validation behavior. More...
 
enum  zxsd_particle_kind_t {
  ZXSD_PARTICLE_ELEMENT = 0 , ZXSD_PARTICLE_SEQUENCE , ZXSD_PARTICLE_CHOICE , ZXSD_PARTICLE_ALL ,
  ZXSD_PARTICLE_ANY
}
 Compiled content-model particle kind. More...
 
enum  {
  ZXSD_F_LENGTH = 1u << 0 , ZXSD_F_MIN_LENGTH = 1u << 1 , ZXSD_F_MAX_LENGTH = 1u << 2 , ZXSD_F_MIN_INCLUSIVE = 1u << 3 ,
  ZXSD_F_MAX_INCLUSIVE = 1u << 4 , ZXSD_F_MIN_EXCLUSIVE = 1u << 5 , ZXSD_F_MAX_EXCLUSIVE = 1u << 6 , ZXSD_F_PATTERN = 1u << 7 ,
  ZXSD_F_TOTAL_DIGITS = 1u << 8 , ZXSD_F_FRACTION_DIGITS = 1u << 9
}
 Simple-type facet flags used by zxsd_simple_t. More...
 
enum  {
  ZXSD_DERIVATION_EXTENSION = 1u << 0 , ZXSD_DERIVATION_RESTRICTION = 1u << 1 , ZXSD_DERIVATION_SUBSTITUTION = 1u << 2 , ZXSD_DERIVATION_LIST = 1u << 3 ,
  ZXSD_DERIVATION_UNION = 1u << 4 , ZXSD_DERIVATION_ALL = 0x1fu
}
 Type-derivation methods used by block and final. More...
 
enum  zxsd_identity_kind_t { ZXSD_ID_UNIQUE = 0 , ZXSD_ID_KEY , ZXSD_ID_KEYREF }
 Identity-constraint category. More...
 
enum  zxsd_xml_event_t { ZXSD_XML_EVENT_START_ELEMENT , ZXSD_XML_EVENT_ATTRIBUTE , ZXSD_XML_EVENT_TEXT , ZXSD_XML_EVENT_END_ELEMENT }
 Decoded XML events exposed by the incremental raw-XML reader. More...
 

Functions

zxsd_result_t zxsd_check_runtime (const zxsd_runtime_config_t *expected)
 Check application limits and layouts before using runtime-owned code.
 
zxsd_result_t zxsd_validate (const zxsd_schema_t *schema, const char *xml)
 Validate an XML document against a generated schema descriptor.
 
zxsd_result_t zxsd_validate_with_allocator (const zxsd_schema_t *schema, const char *xml, const zxsd_allocator_t *allocator)
 Validate using an application-provided scratch allocator.
 
zxsd_result_t zxsd_stream_init (zxsd_stream_t *stream, const zxsd_schema_t *schema)
 Initialize an event-driven validation context.
 
zxsd_result_t zxsd_stream_init_with_allocator (zxsd_stream_t *stream, const zxsd_schema_t *schema, const zxsd_allocator_t *allocator)
 Initialize streaming validation with identity-constraint scratch allocation.
 
void zxsd_stream_dispose (zxsd_stream_t *stream)
 Release optional streaming scratch storage.
 
zxsd_result_t zxsd_start_element (zxsd_stream_t *stream, const char *namespace_uri, const char *local_name)
 Begin an element identified by its expanded name.
 
zxsd_result_t zxsd_namespace (zxsd_stream_t *stream, const char *prefix, const char *namespace_uri)
 Add an in-scope namespace declaration to the current start tag.
 
zxsd_result_t zxsd_attribute (zxsd_stream_t *stream, const char *namespace_uri, const char *local_name, const char *value)
 Add an attribute to the current start tag using its expanded name.
 
zxsd_result_t zxsd_xsi_type (zxsd_stream_t *stream, const char *type_namespace_uri, const char *type_local_name)
 Apply a namespace-resolved xsi:type to the current element.
 
zxsd_result_t zxsd_start_content (zxsd_stream_t *stream)
 Close the attribute phase of the current start tag.
 
zxsd_result_t zxsd_text (zxsd_stream_t *stream, const char *text, size_t length)
 Supply decoded character data for the current element.
 
zxsd_result_t zxsd_end_element (zxsd_stream_t *stream, const char *namespace_uri, const char *local_name)
 End the current element and check its expanded name and content.
 
zxsd_result_t zxsd_stream_finish (zxsd_stream_t *stream)
 Verify that exactly one complete root element was supplied.
 
zxsd_result_t zxsd_xml_reader_init (zxsd_xml_reader_t *reader, const zxsd_schema_t *schema)
 Initialize a raw, incrementally fed XML validator.
 
zxsd_result_t zxsd_xml_reader_init_with_allocator (zxsd_xml_reader_t *reader, const zxsd_schema_t *schema, const zxsd_allocator_t *allocator)
 Initialize a raw XML reader with identity-constraint scratch allocation.
 
void zxsd_xml_reader_set_event_callback (zxsd_xml_reader_t *reader, zxsd_xml_event_fn callback, void *user_data)
 Install an optional decoded-event observer.
 
zxsd_result_t zxsd_xml_reader_feed (zxsd_xml_reader_t *reader, const void *data, size_t length)
 Feed one arbitrary fragment of an XML document.
 
zxsd_result_t zxsd_xml_reader_finish (zxsd_xml_reader_t *reader)
 Finish an incrementally supplied XML document.
 
void zxsd_xml_reader_dispose (zxsd_xml_reader_t *reader)
 Release optional scratch storage owned by a raw XML reader.
 
const char * zxsd_error_string (zxsd_error_t error)
 Get a stable human-readable description of an error code.
 

Detailed Description

Public API for the zxsd XML validation runtime.

Definition in file zxsd.h.