exml 0.7.2

Pure Rust XML library based on libxml2
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
use std::{
    cell::{Cell, RefCell},
    ffi::c_char,
    fs::File,
    ptr::{addr_of_mut, null_mut},
    sync::Mutex,
};

#[cfg(feature = "catalog")]
use crate::libxml::catalog::{XmlCatalogAllow, XmlCatalogPrefer};
#[cfg(feature = "libxml_reader")]
use crate::libxml::xmlreader::XmlTextReaderLocatorPtr;
#[cfg(feature = "schema")]
use crate::xmlschemas::{
    context::{XmlSchemaParserCtxtPtr, XmlSchemaValidCtxtPtr},
    items::XmlSchemaTypePtr,
    schema::XmlSchemaPtr,
};
use crate::{
    libxml::{
        globals::xml_free,
        relaxng::XmlRelaxNGPtr,
        schemas_internals::{XmlSchemaFacetPtr, XmlSchemaValType},
        xmlschemastypes::{XmlSchemaValPtr, XmlSchemaWhitespaceValueType},
        xmlstring::XmlChar,
    },
    tree::{XmlAttr, XmlDoc, XmlDtd, XmlNode, XmlNs},
    xpath::XmlNodeSet,
};

pub(crate) static TEST_CATALOG_LOCK: Mutex<()> = Mutex::new(());

thread_local! {
    static CHARTAB: RefCell<[XmlChar; 1024]> = const { RefCell::new([0; 1024]) };
    static LONGTAB: RefCell<[u64; 1024]> = const { RefCell::new([0; 1024]) };
    static INTTAB: RefCell<[i32; 1024]> = const { RefCell::new([0; 1024]) };

    static API_DOC: Cell<*mut XmlDoc> = const { Cell::new(null_mut()) };
    static API_DTD: Cell<*mut XmlDtd> = const { Cell::new(null_mut()) };
    static API_ROOT: Cell<*mut XmlNode> = const { Cell::new(null_mut()) };
    static API_ATTR: Cell<*mut XmlAttr> = const { Cell::new(null_mut()) };
    static API_NS: Cell<*mut XmlNs> = const { Cell::new(null_mut()) };
}

pub(crate) const GEN_NB_CONST_CHAR_PTR: i32 = 4;
pub(crate) const GEN_NB_CONST_XML_CHAR_PTR: i32 = 5;
pub(crate) const GEN_NB_INT: i32 = 4;
pub(crate) const GEN_NB_CONST_XML_CHAR_PTR_PTR: i32 = 1;
pub(crate) const GEN_NB_FILE_PTR: i32 = 1;
#[cfg(feature = "xpath")]
pub(crate) const GEN_NB_XML_NODE_SET_PTR: i32 = 1;
#[cfg(feature = "catalog")]
pub(crate) const GEN_NB_XML_CATALOG_ALLOW: i32 = 4;
#[cfg(feature = "catalog")]
pub(crate) const GEN_NB_XML_CATALOG_PREFER: i32 = 3;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_RELAXNG_PTR: i32 = 1;
#[cfg(feature = "libxml_reader")]
pub(crate) const GEN_NB_XML_TEXT_READER_LOCATOR_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_VALID_CTXT_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_PARSER_CTXT_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_VAL_PTR_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_VAL_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_FACET_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_TYPE_PTR: i32 = 1;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_WHITESPACE_VALUE_TYPE: i32 = 4;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_XML_SCHEMA_VAL_TYPE: i32 = 4;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_UNSIGNED_LONG: i32 = 4;
#[cfg(feature = "schema")]
pub(crate) const GEN_NB_UNSIGNED_LONG_PTR: i32 = 2;
#[cfg(any(feature = "xpath", feature = "schema"))]
pub(crate) const GEN_NB_DOUBLE: i32 = 4;

#[cfg(feature = "xpath")]
pub(crate) fn desret_xml_node_set_ptr(val: Option<Box<crate::xpath::XmlNodeSet>>) {
    use crate::xpath::xml_xpath_free_node_set;

    xml_xpath_free_node_set(val);
}

#[cfg(any(feature = "xpath", feature = "schema"))]
pub(crate) unsafe fn gen_double(no: i32, _nr: i32) -> f64 {
    if no == 0 {
        return 0.0;
    }
    if no == 1 {
        return -1.1;
    }
    #[cfg(feature = "xpath")]
    if no == 2 {
        use crate::xpath::XML_XPATH_NAN;
        return XML_XPATH_NAN;
    }
    -1.0
}

#[cfg(any(feature = "xpath", feature = "schema"))]
pub(crate) fn des_double(_no: i32, _val: f64, _nr: i32) {}

#[cfg(feature = "xpath")]
pub(crate) fn desret_double(_val: f64) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_unsigned_long(no: i32, _nr: i32) -> u64 {
    if no == 0 {
        return 0;
    }
    if no == 1 {
        return 1;
    }
    if no == 2 {
        return 122;
    }
    u64::MAX
}

#[cfg(feature = "schema")]
pub(crate) fn des_unsigned_long(_no: i32, _val: u64, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) unsafe fn gen_unsigned_long_ptr(no: i32, nr: i32) -> *mut u64 {
    LONGTAB.with_borrow_mut(|table| {
        if no == 0 {
            return addr_of_mut!(table[nr as usize]);
        }
        null_mut()
    })
}

#[cfg(feature = "schema")]
pub(crate) fn des_unsigned_long_ptr(_no: i32, _val: *mut u64, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_val_type(no: i32, _nr: i32) -> XmlSchemaValType {
    if no == 1 {
        return XmlSchemaValType::XmlSchemasAnySimpletype;
    }
    if no == 2 {
        return XmlSchemaValType::XmlSchemasAnytype;
    }
    if no == 3 {
        return XmlSchemaValType::XmlSchemasAnyURI;
    }
    if no == 4 {
        return XmlSchemaValType::XmlSchemasBase64binary;
    }
    XmlSchemaValType::XmlSchemasUnknown
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_val_type(_no: i32, _val: XmlSchemaValType, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn desret_xml_schema_val_type(_val: XmlSchemaValType) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_whitespace_value_type(
    no: i32,
    _nr: i32,
) -> XmlSchemaWhitespaceValueType {
    if no == 1 {
        return XmlSchemaWhitespaceValueType::XmlSchemaWhitespaceCollapse;
    }
    if no == 2 {
        return XmlSchemaWhitespaceValueType::XmlSchemaWhitespacePreserve;
    }
    if no == 3 {
        return XmlSchemaWhitespaceValueType::XmlSchemaWhitespaceReplace;
    }
    if no == 4 {
        return XmlSchemaWhitespaceValueType::XmlSchemaWhitespaceUnknown;
    }
    XmlSchemaWhitespaceValueType::XmlSchemaWhitespaceUnknown
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_whitespace_value_type(
    _no: i32,
    _val: XmlSchemaWhitespaceValueType,
    _nr: i32,
) {
}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_facet_ptr(_no: i32, _nr: i32) -> XmlSchemaFacetPtr {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_facet_ptr(_no: i32, _val: XmlSchemaFacetPtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_type_ptr(_no: i32, _nr: i32) -> XmlSchemaTypePtr {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_type_ptr(_no: i32, _val: XmlSchemaTypePtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_val_ptr(_no: i32, _nr: i32) -> XmlSchemaValPtr {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_val_ptr(_no: i32, _val: XmlSchemaValPtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_val_ptr_ptr(_no: i32, _nr: i32) -> *mut XmlSchemaValPtr {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_val_ptr_ptr(_no: i32, _val: *mut XmlSchemaValPtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_parser_ctxt_ptr(
    _no: i32,
    _nr: i32,
) -> XmlSchemaParserCtxtPtr<'static> {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_parser_ctxt_ptr(_no: i32, _val: XmlSchemaParserCtxtPtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_ptr(_no: i32, _nr: i32) -> XmlSchemaPtr {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_ptr(_no: i32, _val: XmlSchemaPtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_schema_valid_ctxt_ptr(_no: i32, _nr: i32) -> XmlSchemaValidCtxtPtr<'static> {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_schema_valid_ctxt_ptr(_no: i32, _val: XmlSchemaValidCtxtPtr, _nr: i32) {}

#[cfg(feature = "libxml_reader")]
pub(crate) fn gen_xml_text_reader_locator_ptr(_no: i32, _nr: i32) -> XmlTextReaderLocatorPtr {
    null_mut()
}

#[cfg(feature = "libxml_reader")]
pub(crate) fn des_xml_text_reader_locator_ptr(_no: i32, _val: XmlTextReaderLocatorPtr, _nr: i32) {}

#[cfg(feature = "schema")]
pub(crate) unsafe fn desret_xml_schema_parser_ctxt_ptr(val: XmlSchemaParserCtxtPtr) {
    use crate::xmlschemas::context::xml_schema_free_parser_ctxt;

    unsafe {
        xml_schema_free_parser_ctxt(val);
    }
}

#[cfg(feature = "schema")]
pub(crate) fn desret_xml_schema_type_ptr(_val: XmlSchemaTypePtr) {}

#[cfg(feature = "schema")]
pub(crate) fn gen_xml_relaxng_ptr(_no: i32, _nr: i32) -> XmlRelaxNGPtr {
    null_mut()
}

#[cfg(feature = "schema")]
pub(crate) fn des_xml_relaxng_ptr(_no: i32, _val: XmlRelaxNGPtr, _nr: i32) {}

#[cfg(feature = "catalog")]
pub(crate) fn gen_xml_catalog_prefer(no: i32, _nr: i32) -> XmlCatalogPrefer {
    if no == 1 {
        return XmlCatalogPrefer::None;
    }
    if no == 2 {
        return XmlCatalogPrefer::Public;
    }
    if no == 3 {
        return XmlCatalogPrefer::System;
    }
    XmlCatalogPrefer::None
}

#[cfg(feature = "catalog")]
pub(crate) fn des_xml_catalog_prefer(_no: i32, _val: XmlCatalogPrefer, _nr: i32) {}

#[cfg(feature = "catalog")]
pub(crate) fn desret_xml_catalog_prefer(_val: XmlCatalogPrefer) {}

#[cfg(feature = "catalog")]
pub(crate) fn gen_xml_catalog_allow(no: i32, _nr: i32) -> XmlCatalogAllow {
    if no == 1 {
        return XmlCatalogAllow::All;
    }
    if no == 2 {
        return XmlCatalogAllow::Document;
    }
    if no == 3 {
        return XmlCatalogAllow::Global;
    }
    XmlCatalogAllow::None
}

#[cfg(feature = "catalog")]
pub(crate) fn des_xml_catalog_allow(_no: i32, _val: XmlCatalogAllow, _nr: i32) {}

#[cfg(feature = "catalog")]
pub(crate) fn desret_xml_catalog_allow(_val: XmlCatalogAllow) {}

pub(crate) unsafe fn desret_xml_char_ptr(val: *mut XmlChar) {
    unsafe {
        if !val.is_null() {
            xml_free(val as _);
        }
    }
}

#[cfg(feature = "xpath")]
pub(crate) fn gen_xml_node_set_ptr(_no: i32, _nr: i32) -> Option<Box<XmlNodeSet>> {
    None
}
#[cfg(feature = "xpath")]
pub(crate) fn des_xml_node_set_ptr(_no: i32, _val: Option<Box<XmlNodeSet>>, _nr: i32) {}

pub(crate) fn desret_int(_val: i32) {}

pub(crate) fn gen_const_xml_char_ptr_ptr(_no: i32, _nr: i32) -> *mut *mut XmlChar {
    null_mut()
}

pub(crate) fn gen_const_xml_char_ptr(no: i32, _nr: i32) -> *const XmlChar {
    if no == 0 {
        return c"foo".as_ptr() as _;
    }
    if no == 1 {
        return c"<foo/>".as_ptr() as _;
    }
    if no == 2 {
        static D: [u8; 5] = [b'n', 0xf8, b'n', b'e', 0];
        return D.as_ptr() as _;
    }
    if no == 3 {
        return c" 2ab ".as_ptr() as _;
    }
    null_mut()
}

pub(crate) fn des_const_xml_char_ptr(_no: i32, _val: *const XmlChar, _nr: i32) {}

pub(crate) fn gen_int(no: i32, _nr: i32) -> i32 {
    if no == 0 {
        return 0;
    }
    if no == 1 {
        return 1;
    }
    if no == 2 {
        return -1;
    }
    if no == 3 {
        return 122;
    }
    -1
}

pub(crate) fn des_int(_no: i32, _val: i32, _nr: i32) {}

pub(crate) fn gen_const_char_ptr(no: i32, _nr: i32) -> *mut c_char {
    if no == 0 {
        return c"foo".as_ptr() as _;
    }
    if no == 1 {
        return c"<foo/>".as_ptr() as _;
    }
    if no == 2 {
        return c"test/ent2".as_ptr() as _;
    }
    null_mut()
}

pub(crate) fn des_const_char_ptr(_no: i32, _val: *const c_char, _nr: i32) {}

pub(crate) fn desret_const_xml_char_ptr(_val: *const XmlChar) {}

pub(crate) fn des_const_xml_char_ptr_ptr(_no: i32, _val: *mut *const XmlChar, _nr: i32) {}

pub(crate) fn gen_file_ptr(_no: i32, _nr: i32) -> Option<File> {
    File::options()
        .append(true)
        .read(true)
        .create(true)
        .open("test.out")
        .ok()
}