libxml-rs 0.1.0-alpha.2

Phase 1: Compatibility skeleton complete. Native-Rust forensic reimplementation of libxml2+libxslt with C ABI drop-in replacement. 62 tests passing, ABI courts verified, C headers compatible, Docker oracle built.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
//! C ABI exports for libxslt.so.1 — no_mangle extern "C" functions (§1, §16).
//!
//! This module contains all `#[no_mangle] pub extern "C"` function definitions
//! that form the public ABI of libxslt.so.1.
//!
//! # Phase 1 status
//!
//! Complete — all major XSLT ABI entry points are defined.
//! Most functions are stubs that will be filled in during Phase 8 (libxslt).

#![allow(non_snake_case)]
#![allow(unused_variables)]

use core::ffi::c_void;
use core::ptr;
use std::os::raw::{c_char, c_int};

use crate::abi::allocator::*;
use crate::abi::structs::*;
use crate::abi::types::*;

// ═══════════════════════════════════════════════════════════════════════════════
// 1. Version & Initialization
// ═══════════════════════════════════════════════════════════════════════════════

/// Get the libxslt version as an integer.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltLibxsltVersion(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltLibxsltVersion() -> c_int {
    crate::abi::versioning::LIBXSLT_VERSION_NUM
}

/// Get the libxslt version as a string.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// const char *xsltLibxsltVersionString(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltLibxsltVersionString() -> *const c_char {
    crate::abi::versioning::xsltLibxsltVersionString()
}

/// Check the libxslt version.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltCheckVersion(int version);
/// ```
#[no_mangle]
pub extern "C" fn xsltCheckVersion(version: c_int) -> c_int {
    crate::abi::versioning::xsltCheckVersion(version)
}

/// Initialize the XSLT library.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltInit(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltInit() {
    // Phase 1: STUB
}

/// Clean up the XSLT library.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltCleanupGlobals(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltCleanupGlobals() {
    // Phase 1: STUB
}

// ═══════════════════════════════════════════════════════════════════════════════
// 2. Stylesheet Compilation
// ═══════════════════════════════════════════════════════════════════════════════

/// Parse a stylesheet from a file.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xsltStylesheetPtr xsltParseStylesheetFile(const xmlChar *filename);
/// ```
///
/// Returns a newly allocated stylesheet. Caller must free with `xsltFreeStylesheet`.
#[no_mangle]
pub unsafe extern "C" fn xsltParseStylesheetFile(
    _filename: *const xmlChar,
) -> *mut _xsltStylesheet {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Parse a stylesheet from a document.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xsltStylesheetPtr xsltParseStylesheetDoc(xmlDocPtr doc);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltParseStylesheetDoc(_doc: *mut _xmlDoc) -> *mut _xsltStylesheet {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Parse a stylesheet from memory.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xsltStylesheetPtr xsltParseStylesheetMemory(const char *buf, int len,
///                                             const char *URL);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltParseStylesheetMemory(
    _buf: *const c_char,
    _len: c_int,
    _URL: *const c_char,
) -> *mut _xsltStylesheet {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Free a stylesheet.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltFreeStylesheet(xsltStylesheetPtr style);
/// ```
#[no_mangle]
pub extern "C" fn xsltFreeStylesheet(_style: *mut _xsltStylesheet) {
    // Phase 1: STUB
}

// ═══════════════════════════════════════════════════════════════════════════════
// 3. Transformation
// ═══════════════════════════════════════════════════════════════════════════════

/// Apply a stylesheet to a document.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xmlDocPtr xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
///                               const char **params);
/// ```
///
/// `params` is a NULL-terminated array of name=value strings.
/// Returns the result document (caller must free with `xmlFreeDoc`).
#[no_mangle]
pub unsafe extern "C" fn xsltApplyStylesheet(
    _style: *mut _xsltStylesheet,
    _doc: *mut _xmlDoc,
    _params: *mut *const c_char,
) -> *mut _xmlDoc {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Apply a stylesheet with a stack of params.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xmlDocPtr xsltApplyStylesheetStacked(xsltStylesheetPtr style, xmlDocPtr doc,
///                                      const char **params,
///                                      xsltTransformStackElemPtr stack);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltApplyStylesheetStacked(
    _style: *mut _xsltStylesheet,
    _doc: *mut _xmlDoc,
    _params: *mut *const c_char,
    _stack: *mut c_void,
) -> *mut _xmlDoc {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Apply a stylesheet with a user data context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xmlDocPtr xsltApplyStylesheetUser(xsltStylesheetPtr style, xmlDocPtr doc,
///                                   const char **params, const char *output,
///                                   FILE *profile, xsltTransformContextPtr userCtxt);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltApplyStylesheetUser(
    _style: *mut _xsltStylesheet,
    _doc: *mut _xmlDoc,
    _params: *mut *const c_char,
    _output: *const c_char,
    _profile: *mut c_void,
    _userCtxt: *mut _xsltTransformContext,
) -> *mut _xmlDoc {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Free the result of a transformation.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltFreeTransformResult(xmlDocPtr result);
/// ```
#[no_mangle]
pub extern "C" fn xsltFreeTransformResult(_result: *mut _xmlDoc) {
    // Phase 1: STUB
}

// ═══════════════════════════════════════════════════════════════════════════════
// 4. Transform Context
// ═══════════════════════════════════════════════════════════════════════════════

/// Create a transform context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xsltTransformContextPtr xsltNewTransformContext(xsltStylesheetPtr style,
///                                                  xmlDocPtr doc);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltNewTransformContext(
    _style: *mut _xsltStylesheet,
    _doc: *mut _xmlDoc,
) -> *mut _xsltTransformContext {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Free a transform context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltFreeTransformContext(xsltTransformContextPtr ctxt);
/// ```
#[no_mangle]
pub extern "C" fn xsltFreeTransformContext(_ctxt: *mut _xsltTransformContext) {
    // Phase 1: STUB
}

// ═══════════════════════════════════════════════════════════════════════════════
// 5. Security
// ═══════════════════════════════════════════════════════════════════════════════

/// Create a security preferences structure.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xsltSecurityPrefsPtr xsltNewSecurityPrefs(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltNewSecurityPrefs() -> *mut c_void {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Free a security preferences structure.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltFreeSecurityPrefs(xsltSecurityPrefsPtr sec);
/// ```
#[no_mangle]
pub extern "C" fn xsltFreeSecurityPrefs(_sec: *mut c_void) {
    // Phase 1: STUB
}

/// Set a security preference.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltSetSecurityPrefs(xsltSecurityPrefsPtr sec,
///                          xsltSecurityOption option, int value);
/// ```
#[no_mangle]
pub extern "C" fn xsltSetSecurityPrefs(_sec: *mut c_void, _option: c_int, _value: c_int) -> c_int {
    // Phase 1: STUB
    0
}

/// Get a security preference.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltGetSecurityPrefs(xsltSecurityPrefsPtr sec,
///                          xsltSecurityOption option);
/// ```
#[no_mangle]
pub extern "C" fn xsltGetSecurityPrefs(_sec: *mut c_void, _option: c_int) -> c_int {
    // Phase 1: STUB
    1
}

/// Set the default security preferences.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltSetDefaultSecurityPrefs(xsltSecurityPrefsPtr sec);
/// ```
#[no_mangle]
pub extern "C" fn xsltSetDefaultSecurityPrefs(_sec: *mut c_void) {
    // Phase 1: STUB
}

/// Get the default security preferences.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xsltSecurityPrefsPtr xsltGetDefaultSecurityPrefs(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltGetDefaultSecurityPrefs() -> *mut c_void {
    // Phase 1: STUB
    ptr::null_mut()
}

// ═══════════════════════════════════════════════════════════════════════════════
// 6. Extensions
// ═══════════════════════════════════════════════════════════════════════════════

/// Register an XSLT extension function.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltRegisterExtFunction(xsltTransformContextPtr ctxt,
///                             const xmlChar *name, const xmlChar *NS_uri,
///                             xmlXPathFunction f);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltRegisterExtFunction(
    _ctxt: *mut _xsltTransformContext,
    _name: *const xmlChar,
    _NS_uri: *const xmlChar,
    _f: Option<unsafe extern "C" fn(*mut c_void, c_int)>,
) -> c_int {
    // Phase 1: STUB
    0
}

/// Register an XSLT extension element.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltRegisterExtElement(xsltTransformContextPtr ctxt,
///                            const xmlChar *name, const xmlChar *NS_uri,
///                            xsltTransformFunction f);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltRegisterExtElement(
    _ctxt: *mut _xsltTransformContext,
    _name: *const xmlChar,
    _NS_uri: *const xmlChar,
    _f: Option<
        unsafe extern "C" fn(*mut c_void, *mut c_void, *mut _xmlNode, *mut c_void, *mut _xmlNode),
    >,
) -> c_int {
    // Phase 1: STUB
    0
}

/// Initialize the EXSLT module.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void exsltRegisterAll(void);
/// ```
#[no_mangle]
pub extern "C" fn exsltRegisterAll() {
    // Phase 1: STUB
}

// ═══════════════════════════════════════════════════════════════════════════════
// 7. Save Result to File
// ═══════════════════════════════════════════════════════════════════════════════

/// Save a result document to a file.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltSaveResultToFile(FILE *output, xmlDocPtr result,
///                          xsltStylesheetPtr style);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltSaveResultToFile(
    _output: *mut c_void,
    _result: *mut _xmlDoc,
    _style: *mut _xsltStylesheet,
) -> c_int {
    // Phase 1: STUB
    0
}

/// Save a result document to a file descriptor.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltSaveResultToFd(int fd, xmlDocPtr result,
///                        xsltStylesheetPtr style);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltSaveResultToFd(
    _fd: c_int,
    _result: *mut _xmlDoc,
    _style: *mut _xsltStylesheet,
) -> c_int {
    // Phase 1: STUB
    0
}

/// Save a result document to a buffer.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltSaveResultToString(xmlChar **doc_txt_ptr, int *doc_txt_len,
///                            xmlDocPtr result, xsltStylesheetPtr style);
/// ```
#[no_mangle]
pub unsafe extern "C" fn xsltSaveResultToString(
    _doc_txt_ptr: *mut *mut xmlChar,
    _doc_txt_len: *mut c_int,
    _result: *mut _xmlDoc,
    _style: *mut _xsltStylesheet,
) -> c_int {
    // Phase 1: STUB
    0
}

// ═══════════════════════════════════════════════════════════════════════════════
// 8. Debug/Utility
// ═══════════════════════════════════════════════════════════════════════════════

/// Get the stylesheet's document.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xmlDocPtr xsltGetStylesheetDoc(xsltStylesheetPtr style);
/// ```
#[no_mangle]
pub extern "C" fn xsltGetStylesheetDoc(_style: *mut _xsltStylesheet) -> *mut _xmlDoc {
    // Phase 1: STUB
    ptr::null_mut()
}

/// Set the stylesheet's document.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltSetStylesheetDoc(xsltStylesheetPtr style, xmlDocPtr doc);
/// ```
#[no_mangle]
pub extern "C" fn xsltSetStylesheetDoc(_style: *mut _xsltStylesheet, _doc: *mut _xmlDoc) {
    // Phase 1: STUB
}

/// Check whether a feature is available.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltCheckFeature(int feature);
/// ```
#[no_mangle]
pub extern "C" fn xsltCheckFeature(_feature: c_int) -> c_int {
    // Phase 1: STUB — all features reported as available
    1
}

/// Get the XSLT engine version.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// const char *xsltEngineVersion(void);
/// ```
#[no_mangle]
pub extern "C" fn xsltEngineVersion() -> *const c_char {
    // Phase 1: STUB
    crate::abi::versioning::xsltLibxsltVersionString()
}

/// Set loader function for XSLT.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltSetLoaderFunc(xsltLoaderFunc loader);
/// ```
#[no_mangle]
pub extern "C" fn xsltSetLoaderFunc(
    _loader: Option<
        unsafe extern "C" fn(
            *mut c_void,
            *const c_char,
            *const c_char,
            *const c_char,
            c_int,
        ) -> *mut _xmlParserInput,
    >,
) {
    // Phase 1: STUB
}

/// Set the transformer error handler.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xsltSetTransformErrorFunc(xsltTransformContextPtr ctxt,
///                                void *ctx, xmlGenericErrorFunc handler);
/// ```
#[no_mangle]
pub extern "C" fn xsltSetTransformErrorFunc(
    _ctxt: *mut _xsltTransformContext,
    _ctx: *mut c_void,
    _handler: Option<unsafe extern "C" fn(*mut c_void, *const c_char)>,
) {
    // Phase 1: STUB
}