Skip to main content

libxml_rs/
lib.rs

1//! libxml-rs: Custodial native-Rust reimplementation of libxml2 and libxslt
2//!
3//! This is not an XML crate. This is not an XSLT crate. This is not a wrapper.
4//! This is a forensic reconstruction of the observable behavior of the libxml2 + libxslt
5//! ecosystem across its historical lifetime, implemented in native Rust.
6//!
7//! # Architecture
8//!
9//! The crate is organized into semantic modules corresponding to real ownership boundaries:
10//!
11//! - `abi` - C ABI compatibility layer: types, structs, constants, exports, callbacks, allocator, ownership, versioning
12//! - `xml` - libxml2 implementation: parser, SAX, tree, entities, namespaces, DTD, validation, reader, writer, encoding, I/O, catalog, URI, XPath, XPointer, XInclude, RELAX NG, schemas, Schematron, C14N, HTML, regex, automata, dictionary, hash, list, debug, globals, threads, errors, memory
13//! - `xslt` - libxslt implementation: stylesheet, compiler, transform, templates, patterns, variables, parameters, keys, attributes, namespace_alias, whitespace, sorting, numbering, documents, imports, extensions, serialization, security, errors
14//! - `exslt` - EXSLT modules: common, math, sets, strings, dynamic, functions, dates
15//! - `compatibility` - Historical profiles, quirks, platform-specific behavior
16//! - `bin` - CLI tools: xmllint, xmlcatalog, xsltproc
17//!
18//! # Safety
19//!
20//! This crate uses `unsafe` only where fundamentally required for C ABI export, raw-pointer
21//! compatibility, foreign allocator interoperability, public C structure layout, callbacks,
22//! variadic compatibility, OS interfaces, and dynamic-loader interaction.
23//!
24//! Every unsafe block documents:
25//! - What must be true
26//! - Who establishes it
27//! - How long it remains true
28//! - Which oracle/parity court exercises the assumption
29//! - What would constitute violation
30
31#![deny(
32    missing_docs,
33    missing_debug_implementations,
34    unconditional_recursion,
35    unused_lifetimes,
36    unused_qualifications,
37    while_true
38)]
39#![warn(
40    clippy::all,
41    clippy::pedantic,
42    clippy::nursery,
43    clippy::cargo,
44    clippy::missing_const_for_fn,
45    clippy::missing_inline_in_public_items
46)]
47#![allow(
48    clippy::module_name_repetitions,
49    clippy::multiple_crate_versions,
50    clippy::too_many_lines,
51    clippy::type_complexity
52)]
53
54// Public ABI compatibility layer
55pub mod abi;
56
57// libxml2 implementation
58pub mod xml;
59
60// libxslt implementation
61pub mod xslt;
62
63// EXSLT implementation
64pub mod exslt;
65
66// Compatibility profiles and historical behavior
67pub mod compatibility;
68
69// Binary entry points are defined as [[bin]] targets in Cargo.toml.
70// They are NOT library modules — they depend on libxml_rs as a library.
71// See src/bin/xmllint.rs, src/bin/xmlcatalog.rs, src/bin/xsltproc.rs
72
73// Phase 0: ABI re-exports will be populated when types are defined.
74// The `allow(unused_imports)` is intentional — these will be used in Phase 1+.
75#[allow(unused_imports)]
76use abi::allocator::*;
77#[allow(unused_imports)]
78use abi::callbacks::*;
79#[allow(unused_imports)]
80use abi::constants::*;
81#[allow(unused_imports)]
82use abi::ownership::*;
83#[allow(unused_imports)]
84use abi::structs::*;
85#[allow(unused_imports)]
86use abi::types::*;
87#[allow(unused_imports)]
88use abi::versioning::*;
89
90// Internal modules (not part of public C ABI)
91mod internal;
92
93/// The full version string of the libxml-rs crate (from Cargo.toml).
94pub const LIBXML_RS_VERSION: &str = env!("CARGO_PKG_VERSION");
95
96/// Major version number of libxml-rs.
97pub const LIBXML_RS_VERSION_MAJOR: u32 = 0;
98
99/// Minor version number of libxml-rs.
100pub const LIBXML_RS_VERSION_MINOR: u32 = 1;
101
102/// Micro version (patch) number of libxml-rs.
103pub const LIBXML_RS_VERSION_MICRO: u32 = 0;
104
105/// Initialize the library (libxml2 compatibility)
106///
107/// # Safety
108/// This function must be called before any other libxml2 functions.
109/// It is not thread-safe to call concurrently with other libxml2 functions.
110#[no_mangle]
111pub unsafe extern "C" fn xmlInitParser() {
112    internal::globals::init_parser();
113}
114
115/// Clean up the library (libxml2 compatibility)
116///
117/// # Safety
118/// This function should be called when the library is no longer needed.
119/// It is not thread-safe to call concurrently with other libxml2 functions.
120#[no_mangle]
121pub unsafe extern "C" fn xmlCleanupParser() {
122    internal::globals::cleanup_parser();
123}
124
125/// Initialize the library for threaded use (libxml2 compatibility)
126///
127/// # Safety
128/// This function must be called before any other libxml2 functions in a threaded program.
129#[no_mangle]
130pub unsafe extern "C" fn xmlInitThreads() -> std::os::raw::c_int {
131    internal::globals::init_threads()
132}
133
134/// Get the library version (libxml2 compatibility)
135#[no_mangle]
136pub extern "C" fn xmlLibxmlVersion() -> std::os::raw::c_int {
137    // Return version in format: major * 10000 + minor * 100 + micro
138    // We target libxml2 2.12.x compatibility
139    2 * 10000 + 12 * 100 + 0
140}
141
142/// Get the library version string (libxml2 compatibility)
143#[no_mangle]
144pub extern "C" fn xmlLibxmlVersionString() -> *const std::os::raw::c_char {
145    internal::versioning::version_string()
146}
147
148/// Check library version at runtime (libxml2 compatibility)
149#[no_mangle]
150pub extern "C" fn xmlCheckVersion(version: std::os::raw::c_int) -> std::os::raw::c_int {
151    internal::versioning::check_version(version)
152}